From mboxrd@z Thu Jan 1 00:00:00 1970 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 64E181E47CC for ; Thu, 2 Apr 2026 06:38:51 +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=1775111932; cv=none; b=YP3ZdXKXzmrj1b8zNju45uMmr215bJjf2gx5lVFLyxUXBBJvpJlOI7VumNfEpTxaubQLscNTgMBOEFpG0YBJCiZyuIIa/8XozsIw0VVlsvNhrt8Y3jYx/5TytvOveglq/md3c6F2pOS3/bY/ylZk6QWOl9ePch1H9E6Zd+40R4U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775111932; c=relaxed/simple; bh=d2KyEvxG0OEVID+yXcJbfkjQUxkirM7/MyeezBNuyQw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=amZeJ/zE9lOzAYezf7k5NekeHCm6elS820PdyLjim7jkSSYZHBv2QR2IpakIOqUH96AJpV7+cttHffI4kvJvbrfMgvGYZ23iK0z0v5D5kH+VGLR0unYGmTtuzF/OdyAbN6cqr/E0tpToo6Ou9IpFgvB1dhU9Qt3V7sazVkH/xpc= 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=PWaF/hG5; 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="PWaF/hG5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775111930; 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=PWaF/hG5TI/+eCG70TRrKeW8r85eeAxAF+gDiCE+kpbRiZScHySgPSygz12yMtHo/kTMpX zWPXG1v6W2+w6XSM+8d2eu5+wYdhGrRJgXHe4ahqEFKH1A1P9uwKMAuwYVJE+iTUJ7qQOV sFVGp9EMG9PFIZGExIUgOgIkhabupes= 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-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ý 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/selftests/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, const char *name) return NULL; } +/* + * 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 = 0; elapsed < timeout_ms; elapsed += 100) { + count = 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; /* Verify that zswap writeback occurred only if writeback was enabled */ - zswpwb_after = get_cg_wb_count(cgroup); + if (wb) + zswpwb_after = wait_for_writeback(cgroup, 5000); + else + zswpwb_after = get_cg_wb_count(cgroup); if (zswpwb_after < 0) return -1; @@ -474,7 +498,7 @@ static int test_no_invasive_cgroup_shrink(const char *root) } /* 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) == 0) + if (wait_for_writeback(wb_group, 5000) > 0 && get_cg_wb_count(zw_group) == 0) ret = KSFT_PASS; out: cg_enter_current(root); -- 2.53.0