From nobody Fri Apr 3 01:22:51 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 675D13148A3 for ; Thu, 2 Apr 2026 06:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775111934; cv=none; b=od16JoTydvOk4SndE+KwnqEy1S921SERX5ud4xU10mx6c/7MLiwT5bG2ERMO8XK0uMHWTDyMO3U2D+mVW/D6z0KJxhipGQeyBOsZuTRASLr9z6UksSx6x2xUTmYV3Ua60bmJQOIyvCJCjw7M/tCaUtMmGFPONxvWBMNofq5c9Cc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775111934; c=relaxed/simple; bh=d2KyEvxG0OEVID+yXcJbfkjQUxkirM7/MyeezBNuyQw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tebap5997hm86AWun7tHuqO0ermFCSKza26KWdk2Ygkl6+bh0jdPo19GamxYKsCuue5TVYylTspl/LleMEIXu/FnPmUjhIuGp0Mx7QueaAUfaQBtbCArxD6Ds+ElPhFqV3ZgV1Zi9gJ7EwGy9CYkj/5vceTnZxvL3XVswHOh7rI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=J89dxMHn; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="J89dxMHn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775111932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WEqNhVsQrzJKuyttIZRIIhpYJGhdAwnhMqwpTFllafE=; b=J89dxMHn/6QbrN5p9XaL2bz98fRJwyygpk4oMM3TG3nxevGDu8mSzgDWKZOT6mkx7iNsMf o/+Fq9rAezI2ThnStySD6EOffFrHj6AO2UJ+fF53/xAhI+9kSJelGwy68wmDx5SWXiDI1E BSSynFglmwi3LzS1qtwv4ambY1KcDmw= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-E0pFoX1POSO0tnomLtchzA-1; Thu, 02 Apr 2026 02:38:47 -0400 X-MC-Unique: E0pFoX1POSO0tnomLtchzA-1 X-Mimecast-MFC-AGG-ID: E0pFoX1POSO0tnomLtchzA_1775111924 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F10E2195608D; Thu, 2 Apr 2026 06:38:43 +0000 (UTC) Received: from fedora-laptop-x1.redhat.com (unknown [10.72.112.158]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BC9491800361; Thu, 2 Apr 2026 06:38:34 +0000 (UTC) From: Li Wang To: akpm@linux-foundation.org, rppt@kernel.org, david@kernel.org, hannes@cmpxchg.org, yosry@kernel.org, ljs@kernel.org, Liam.Howlett@oracle.com, mhocko@suse.com, shuah@kernel.org, chengming.zhou@linux.dev, longman@redhat.com, nphamcs@gmail.com Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Michal Hocko , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Muchun Song , Tejun Heo , Roman Gushchin , Shakeel Butt , Yosry Ahmed Subject: [PATCH v6 8/8] selftests/cgroup: test_zswap: wait for asynchronous writeback Date: Thu, 2 Apr 2026 14:37:14 +0800 Message-ID: <20260402063714.55124-9-liwang@redhat.com> In-Reply-To: <20260402063714.55124-1-liwang@redhat.com> References: <20260402063714.55124-1-liwang@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 zswap writeback is asynchronous, but test_zswap.c checks writeback counters immediately after reclaim/trigger paths. On some platforms (e.g. ppc64le), this can race with background writeback and cause spurious failures even when behavior is correct. Add wait_for_writeback() to poll get_cg_wb_count() with a bounded timeout, and use it in: test_zswap_writeback_one() when writeback is expected test_no_invasive_cgroup_shrink() for the wb_group check This keeps the original before/after assertion style while making the tests robust against writeback completion latency. No test behavior change, selftest stability improvement only. Signed-off-by: Li Wang Cc: Johannes Weiner Cc: Michal Hocko Cc: Michal Koutn=C3=BD Cc: Muchun Song Cc: Nhat Pham Cc: Tejun Heo Cc: Roman Gushchin Cc: Shakeel Butt Cc: Yosry Ahmed --- Notes: v6: - Declear long type for elapsed and count variables. tools/testing/selftests/cgroup/test_zswap.c | 28 +++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/se= lftests/cgroup/test_zswap.c index ffc037922e1b..8656130961a3 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -118,6 +118,27 @@ static char *setup_test_group_1M(const char *root, con= st char *name) return NULL; } =20 +/* + * Writeback is asynchronous; poll until at least one writeback has + * been recorded for @cg, or until @timeout_ms has elapsed. + */ +static long wait_for_writeback(const char *cg, int timeout_ms) +{ + long elapsed, count; + for (elapsed =3D 0; elapsed < timeout_ms; elapsed +=3D 100) { + count =3D get_cg_wb_count(cg); + + if (count < 0) + return -1; + if (count > 0) + return count; + + usleep(100000); + } + + return 0; +} + /* * Sanity test to check that pages are written into zswap. */ @@ -343,7 +364,10 @@ static int test_zswap_writeback_one(const char *cgroup= , bool wb) return -1; =20 /* Verify that zswap writeback occurred only if writeback was enabled */ - zswpwb_after =3D get_cg_wb_count(cgroup); + if (wb) + zswpwb_after =3D wait_for_writeback(cgroup, 5000); + else + zswpwb_after =3D get_cg_wb_count(cgroup); if (zswpwb_after < 0) return -1; =20 @@ -474,7 +498,7 @@ static int test_no_invasive_cgroup_shrink(const char *r= oot) } =20 /* Verify that only zswapped memory from gwb_group has been written back = */ - if (get_cg_wb_count(wb_group) > 0 && get_cg_wb_count(zw_group) =3D=3D 0) + if (wait_for_writeback(wb_group, 5000) > 0 && get_cg_wb_count(zw_group) = =3D=3D 0) ret =3D KSFT_PASS; out: cg_enter_current(root); --=20 2.53.0