From nobody Thu Apr 2 23:54:10 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 EEAE63932E7 for ; Thu, 26 Mar 2026 03:27:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774495646; cv=none; b=m8aHclltxrGHAM697GTgaKSb29Ia6RseTx/Y+2L02h/wiHFwNddaaK53YTzD9Gm0fjczPzXVJjmwPBTcEXbm8T1+f5chaogG6L9MX4WeB6yfoSTgcpmEjTPvxW5QoaO9A4LdYmGp3tKxNOuFyEmNIWQPbv4TS8a7nUDE52pm74I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774495646; c=relaxed/simple; bh=5wzz7kvS0zQVegUJoLaUFrwU9nl+d5YkubbMoUQqjgs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rl/h42QPThP/W6vJtnO8dQH2Vvow9CM9eJzUaC2C827mFLkcnb7Sc7RRzfWhbaDefCz9XhIQ83OOvEsEfxGfJom/nV2Ktn/PetXjkyLvMswQB0p7n0hkZb/H/RYk6RILbIc3C3iTaU11k52TnGW3e8W0iReLzFrpTYQU+5xvWds= 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=IJcwFrkO; arc=none smtp.client-ip=170.10.133.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="IJcwFrkO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774495643; 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=rm08wFIpEzqugJakKtYzJk4JxE4UZWy40rHnN9fIsUk=; b=IJcwFrkOybbV3Gqcp8WfUYOWAdmLXPPthjRtQdAgLz/ywE5WhaDsnvGEqWKat/jfBHPpDM 2o5RAxmgMYwoDGiUdAwPRI/3HKGxfUTOAsPXW8KtiLGwx9AhVTD2ZABoIoqTllv1LJ+HdL 06dEqIrLs1TFUvKa2gu8SGdURRIeftw= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-Uxu5qyjuPKa0dTexp-HmkA-1; Wed, 25 Mar 2026 23:27:19 -0400 X-MC-Unique: Uxu5qyjuPKa0dTexp-HmkA-1 X-Mimecast-MFC-AGG-ID: Uxu5qyjuPKa0dTexp-HmkA_1774495637 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 708B71800365; Thu, 26 Mar 2026 03:27:17 +0000 (UTC) Received: from fedora-laptop-x1.redhat.com (unknown [10.72.112.83]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B45021955D84; Thu, 26 Mar 2026 03:27:10 +0000 (UTC) From: Li Wang To: akpm@linux-foundation.org, yosry@kernel.org, nphamcs@gmail.com, hannes@cmpxchg.org, mhocko@kernel.org, mkoutny@suse.com, muchun.song@linux.dev, tj@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev Cc: longman@redhat.com, liwang@redhat.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed Subject: [PATCH v5 1/8] selftests/cgroup: skip test_zswap if zswap is globally disabled Date: Thu, 26 Mar 2026 11:26:51 +0800 Message-ID: <20260326032658.96819-2-liwang@redhat.com> In-Reply-To: <20260326032658.96819-1-liwang@redhat.com> References: <20260326032658.96819-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.0 on 10.30.177.17 test_zswap currently only checks whether zswap is present by testing /sys/module/zswap. This misses the runtime global state exposed in /sys/module/zswap/parameters/enabled. When zswap is built/loaded but globally disabled, the zswap cgroup selftests run in an invalid environment and may fail spuriously. Check the runtime enabled state before running the tests: - skip if zswap is not configured, - fail if the enabled knob cannot be read, - skip if zswap is globally disabled. Also print a hint in the skip message on how to enable zswap. 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 Acked-by: Yosry Ahmed --- Notes: v5: - Defined PATH_ZSWAP and PATH_ZSWAP_ENABLED macros to avoid line b= reaks v4: - No changes. =20 v3: - Replace tri-state zswap_enabled() with check_zswap_enabled() for= clearer flow. - Move skip/fail decisions into the helper instead of branching in= main(). - Make read failure reporting more explicit by naming `/sys/module/zswap/parameters/enabled`. - Keep skip hint for enabling zswap: `echo 1 > /sys/module/zswap/parameters/enabled`. =20 v2: - remove enable/disable_zswap functions - skip the test if zswap is not enabled - reporting fail when zswap_enabled return -1 tools/testing/selftests/cgroup/test_zswap.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/se= lftests/cgroup/test_zswap.c index 64ebc3f3f203..44fa81ef6157 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -13,6 +13,9 @@ #include "kselftest.h" #include "cgroup_util.h" =20 +#define PATH_ZSWAP "/sys/module/zswap" +#define PATH_ZSWAP_ENABLED "/sys/module/zswap/parameters/enabled" + static int read_int(const char *path, size_t *value) { FILE *file; @@ -589,9 +592,18 @@ struct zswap_test { }; #undef T =20 -static bool zswap_configured(void) +static void check_zswap_enabled(void) { - return access("/sys/module/zswap", F_OK) =3D=3D 0; + char value[2]; + + if (access(PATH_ZSWAP, F_OK)) + ksft_exit_skip("zswap isn't configured\n"); + + if (read_text(PATH_ZSWAP_ENABLED, value, sizeof(value)) <=3D 0) + ksft_exit_fail_msg("Failed to read " PATH_ZSWAP_ENABLED "\n"); + + if (value[0] =3D=3D 'N') + ksft_exit_skip("zswap is disabled (hint: echo 1 > " PATH_ZSWAP_ENABLED "= )\n"); } =20 int main(int argc, char **argv) @@ -604,8 +616,7 @@ int main(int argc, char **argv) if (cg_find_unified_root(root, sizeof(root), NULL)) ksft_exit_skip("cgroup v2 isn't mounted\n"); =20 - if (!zswap_configured()) - ksft_exit_skip("zswap isn't configured\n"); + check_zswap_enabled(); =20 /* * Check that memory controller is available: --=20 2.53.0 From nobody Thu Apr 2 23:54:10 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 132A828E00 for ; Thu, 26 Mar 2026 03:27:31 +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=1774495654; cv=none; b=ScWhYLN6hCuzaCL7h/n+JvCQfOf752FqFxNgmAXvD2pfnhmO4dp+qBBJC69Q7+HDK//zhdwMaMzA82Cy60/CHqQtOnaYduTrY6qQKpRO4gyiUhuyuvyubXi2Y2wQNNMyw6T7/PWB1S23qwgT+xDovc1inbaaQGsmJHNnqdtCZ0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774495654; c=relaxed/simple; bh=/5Ho1hLuP6Yn+Y9x/aZL/aeh/iGIbV+SpGsQfvUUEqM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oaS9hawv6Y858YeZcHIpbKBZz3Sopx2XsJAf8OVAonIdy5O6osFn/9mKCkWouyt6X63LjV1KKODOqX1y5+rVuiFqufIWXqYdSz4StU3zJrTYWZ0/9jJahcDEzft97KDOPh+ohUAXEArySt7jgfiVhO0MM7V19TO1c2ceufcsRCM= 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=FPM7oNfq; 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="FPM7oNfq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774495651; 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=riRX/G54k0buVLVoARmr3GpOP9R848ATdW4K3IUdxAU=; b=FPM7oNfqQoH1Z2ASs3iGEapdWmcaupi/KQ4/mUvI9OZgyQ7mf9Cm1T8+is+wCmtK4hUo4e IMpCzuaJgJBcV1lOQ5J3dH/gQCCrO19P/+TYCCSqkRhry7OMyCUO/CBamJjAJLBtHV1lad xyVl37AfSnQEIYzO8BaOD8bu2BW3Evw= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-147-JMFJPb-wMjiHgOZhQyLkWw-1; Wed, 25 Mar 2026 23:27:27 -0400 X-MC-Unique: JMFJPb-wMjiHgOZhQyLkWw-1 X-Mimecast-MFC-AGG-ID: JMFJPb-wMjiHgOZhQyLkWw_1774495645 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 02A1C1800281; Thu, 26 Mar 2026 03:27:25 +0000 (UTC) Received: from fedora-laptop-x1.redhat.com (unknown [10.72.112.83]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1CDCE1955D84; Thu, 26 Mar 2026 03:27:17 +0000 (UTC) From: Li Wang To: akpm@linux-foundation.org, yosry@kernel.org, nphamcs@gmail.com, hannes@cmpxchg.org, mhocko@kernel.org, mkoutny@suse.com, muchun.song@linux.dev, tj@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev Cc: longman@redhat.com, liwang@redhat.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v5 2/8] selftests/cgroup: avoid OOM in test_swapin_nozswap Date: Thu, 26 Mar 2026 11:26:52 +0800 Message-ID: <20260326032658.96819-3-liwang@redhat.com> In-Reply-To: <20260326032658.96819-1-liwang@redhat.com> References: <20260326032658.96819-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.0 on 10.30.177.17 test_swapin_nozswap can hit OOM before reaching its assertions on some setups. The test currently sets memory.max=3D8M and then allocates/reads 32M with memory.zswap.max=3D0, which may over-constrain reclaim and kill the workload process. Replace hardcoded sizes with PAGE_SIZE-based values: - control_allocation_size =3D PAGE_SIZE * 512 - memory.max =3D control_allocation_size * 3 / 4 - minimum expected swap =3D control_allocation_size / 4 This keeps the test pressure model intact (allocate/read beyond memory.max = to force swap-in/out) while making it more robust across different environment= s. The test intent is unchanged: confirm that swapping occurs while zswap rema= ins unused when memory.zswap.max=3D0. =3D=3D=3D Error Logs =3D=3D=3D # ./test_zswap TAP version 13 1..7 ok 1 test_zswap_usage not ok 2 test_swapin_nozswap ... # dmesg [271641.879153] test_zswap invoked oom-killer: gfp_mask=3D0xcc0(GFP_KERNE= L), order=3D0, oom_score_adj=3D0 [271641.879168] CPU: 1 UID: 0 PID: 177372 Comm: test_zswap Kdump: loaded = Not tainted 6.12.0-211.el10.ppc64le #1 VOLUNTARY [271641.879171] Hardware name: IBM,9009-41A POWER9 (architected) 0x4e0202= 0xf000005 of:IBM,FW940.02 (UL940_041) hv:phyp pSeries [271641.879173] Call Trace: [271641.879174] [c00000037540f730] [c00000000127ec44] dump_stack_lvl+0x88= /0xc4 (unreliable) [271641.879184] [c00000037540f760] [c0000000005cc594] dump_header+0x5c/0x= 1e4 [271641.879188] [c00000037540f7e0] [c0000000005cb464] oom_kill_process+0x= 324/0x3b0 [271641.879192] [c00000037540f860] [c0000000005cbe48] out_of_memory+0x118= /0x420 [271641.879196] [c00000037540f8f0] [c00000000070d8ec] mem_cgroup_out_of_m= emory+0x18c/0x1b0 [271641.879200] [c00000037540f990] [c000000000713888] try_charge_memcg+0x= 598/0x890 [271641.879204] [c00000037540fa70] [c000000000713dbc] charge_memcg+0x5c/0= x110 [271641.879207] [c00000037540faa0] [c0000000007159f8] __mem_cgroup_charge= +0x48/0x120 [271641.879211] [c00000037540fae0] [c000000000641914] alloc_anon_folio+0x= 2b4/0x5a0 [271641.879215] [c00000037540fb60] [c000000000641d58] do_anonymous_page+0= x158/0x6b0 [271641.879218] [c00000037540fbd0] [c000000000642f8c] __handle_mm_fault+0= x4bc/0x910 [271641.879221] [c00000037540fcf0] [c000000000643500] handle_mm_fault+0x1= 20/0x3c0 [271641.879224] [c00000037540fd40] [c00000000014bba0] ___do_page_fault+0x= 1c0/0x980 [271641.879228] [c00000037540fdf0] [c00000000014c44c] hash__do_page_fault= +0x2c/0xc0 [271641.879232] [c00000037540fe20] [c0000000001565d8] do_hash_fault+0x128= /0x1d0 [271641.879236] [c00000037540fe50] [c000000000008be0] data_access_common_= virt+0x210/0x220 [271641.879548] Tasks state (memory values in pages): ... [271641.879550] [ pid ] uid tgid total_vm rss rss_anon rss_file= rss_shmem pgtables_bytes swapents oom_score_adj name [271641.879555] [ 177372] 0 177372 571 0 0 = 0 0 51200 96 0 test_zswap [271641.879562] oom-kill:constraint=3DCONSTRAINT_MEMCG,nodemask=3D(null),= cpuset=3D/,mems_allowed=3D0,oom_memcg=3D/no_zswap_test,task_memcg=3D/no_zsw= ap_test,task=3Dtest_zswap,pid=3D177372,uid=3D0 [271641.879578] Memory cgroup out of memory: Killed process 177372 (test_= zswap) total-vm:36544kB, anon-rss:0kB, file-rss:0kB, shmem-rss:0kB, UID:0 p= gtables:50kB oom_score_adj:0 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 Acked-by: Yosry Ahmed Acked-by: Nhat Pham --- Notes: v4: - print the expected swap amount in KB but not MB. v3: - Replace fixed 8M/32M sizing with PAGE_SIZE-based sizing in test_swapin_nozswap. - Set memory.max to 3/4 of workload size to reduce OOM risk while still forcing reclaim/swap activity. - Derive minimum swap expectation from workload size (1/4) instead of a fixed 8M threshold. v2: - No change. tools/testing/selftests/cgroup/test_zswap.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/se= lftests/cgroup/test_zswap.c index 44fa81ef6157..ed257d464bd6 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -163,21 +163,25 @@ static int test_zswap_usage(const char *root) static int test_swapin_nozswap(const char *root) { int ret =3D KSFT_FAIL; - char *test_group; - long swap_peak, zswpout; + char *test_group, mem_max_buf[32]; + long swap_peak, zswpout, min_swap; + size_t allocation_size =3D sysconf(_SC_PAGESIZE) * 512; + + min_swap =3D allocation_size / 4; + snprintf(mem_max_buf, sizeof(mem_max_buf), "%zu", allocation_size * 3/4); =20 test_group =3D cg_name(root, "no_zswap_test"); if (!test_group) goto out; if (cg_create(test_group)) goto out; - if (cg_write(test_group, "memory.max", "8M")) + if (cg_write(test_group, "memory.max", mem_max_buf)) goto out; if (cg_write(test_group, "memory.zswap.max", "0")) goto out; =20 /* Allocate and read more than memory.max to trigger swapin */ - if (cg_run(test_group, allocate_and_read_bytes, (void *)MB(32))) + if (cg_run(test_group, allocate_and_read_bytes, (void *)allocation_size)) goto out; =20 /* Verify that pages are swapped out, but no zswap happened */ @@ -187,8 +191,9 @@ static int test_swapin_nozswap(const char *root) goto out; } =20 - if (swap_peak < MB(24)) { - ksft_print_msg("at least 24MB of memory should be swapped out\n"); + if (swap_peak < min_swap) { + ksft_print_msg("at least %ldKB of memory should be swapped out\n", + min_swap / 1024); goto out; } =20 --=20 2.53.0 From nobody Thu Apr 2 23:54:10 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 15BFE3932D4 for ; Thu, 26 Mar 2026 03:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774495659; cv=none; b=Ad4cxXNmwSiUysALE2Gq4QdtnA6oitWD4Ek4mf7qlSGCGB6Cx2ikVUuEjgczsgcIL80CkULPp51tvvmxh3DKNMfQoR2qBg/V6CaWqpbvZ14WwNADaiRRYSk650VJQksU39PGhfVEDwt7t1NpoUxGqDb0zyu5/L9nqDpJD22MQuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774495659; c=relaxed/simple; bh=etMNLgsAqgXT7GNsz5mVXZFt1m1s+ZnbfehPyo/QgrQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OBnoU6W++xi2Bovvs1EgRSkzx4U+jL/k6CiSTQi4HCu3pJe1VB1vCa0FtdTI1lGHs87kJw4+C6dNR98hamctj8OTmm/uoPYU1VJad+kBJQHQO7ui5iyzcaoISEXtwQ7hqSwpgty9+BTYq6/gGWC7LDTshcy+TiG0SeEnU9d2lA0= 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=de4xc4Ku; arc=none smtp.client-ip=170.10.133.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="de4xc4Ku" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774495657; 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=mpe5+6BEENtzobjSR9FLGbgq/dfpUrP+sg7IFVwkji8=; b=de4xc4Kuc2F/t4nfDEaVaeXdUUlsvVB0TSzQXbIY3aGyr5yX2f+lOMP9OCWKYTAPzuwjnl vsMt8J2YYMFJTK9/Mjdlqbz1/YDP3sNUtu+eI+emN45EZaJMDCw+K08Uf4cpw24UlZwebN C7B6i4tk8zW5RDMCJCtrZyecbW4mTFE= 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-606-f-2A5cPvMGCNGCUaiYzyXA-1; Wed, 25 Mar 2026 23:27:33 -0400 X-MC-Unique: f-2A5cPvMGCNGCUaiYzyXA-1 X-Mimecast-MFC-AGG-ID: f-2A5cPvMGCNGCUaiYzyXA_1774495652 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 D4AAD195608D; Thu, 26 Mar 2026 03:27:31 +0000 (UTC) Received: from fedora-laptop-x1.redhat.com (unknown [10.72.112.83]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B61DD1955D84; Thu, 26 Mar 2026 03:27:25 +0000 (UTC) From: Li Wang To: akpm@linux-foundation.org, yosry@kernel.org, nphamcs@gmail.com, hannes@cmpxchg.org, mhocko@kernel.org, mkoutny@suse.com, muchun.song@linux.dev, tj@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev Cc: longman@redhat.com, liwang@redhat.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v5 3/8] selftests/cgroup: use runtime page size for zswpin check Date: Thu, 26 Mar 2026 11:26:53 +0800 Message-ID: <20260326032658.96819-4-liwang@redhat.com> In-Reply-To: <20260326032658.96819-1-liwang@redhat.com> References: <20260326032658.96819-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.0 on 10.30.177.17 test_zswapin compares memory.stat:zswpin (counted in pages) against a byte threshold converted with PAGE_SIZE. In cgroup selftests, PAGE_SIZE is hardcoded to 4096, which makes the conversion wrong on systems with non-4K base pages (e.g. 64K). As a result, the test requires too many pages to pass and fails spuriously even when zswap is working. Use sysconf(_SC_PAGESIZE) for the zswpin threshold conversion so the check matches the actual system page size. 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 Reviewed-by: Yosry Ahmed --- tools/testing/selftests/cgroup/test_zswap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/se= lftests/cgroup/test_zswap.c index ed257d464bd6..516da5d52bfd 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -243,7 +243,7 @@ static int test_zswapin(const char *root) goto out; } =20 - if (zswpin < MB(24) / PAGE_SIZE) { + if (zswpin < MB(24) / sysconf(_SC_PAGESIZE)) { ksft_print_msg("at least 24MB should be brought back from zswap\n"); goto out; } --=20 2.53.0 From nobody Thu Apr 2 23:54:10 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 C66D339281E for ; Thu, 26 Mar 2026 03:27:46 +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=1774495668; cv=none; b=lB/CQOH3G3e+9BLfn0fVDJsQocbAPUoL1psgOxYwnBOLUYfrXJVgjMabqEckKWpV9YGqyTMk45i44azHuqP8rmYxP63AvBYKzcYYlnBlLbdW7URcU+HXgnJeqbsi7LLhPu0gWnQB28tS16auvVGQSi1k848P7S0cQrHb95dAuyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774495668; c=relaxed/simple; bh=oLmn6soIa0ftSBIMNXLqHCpudrtsAdVMss3tnUWW16U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pWOLJT3QPtwmHadH1hc+2eWD4ScKAcFK5OpsvnfntfYZslxaVdbICNAH1ZYgAWfgrDAWlC+bA2JKA9kARI4PHl+kIi1044Z2hbTur7R/CxKOoq2fIaomWWeFkGx2rvP4Ch0wkFFafHxXK2ITDryfh1fnz2buHcD52GIkPg5mBZA= 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=C75I5VSI; 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="C75I5VSI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774495665; 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=lRnxTPWpAQYJ1HE6KZj4d+ShQv4DEVn8EUx0vr44r/E=; b=C75I5VSI3wHltc5xSJeRjMjVi9XuI/zIDin6rmNWVLhFiHUnw0T7KLZsVtWrAxtpcAF643 kcLZQs1iXKnvMNi/4qKJtOA5M0anadWl4NeVYZOp+rJAbwnUEW71hmbMXWobJmUW51/9bS XMlfdilbDgAobtDOUPw/F/RoUiMXICk= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-591-R6a8-Oo6N6WpjTAbUIP45Q-1; Wed, 25 Mar 2026 23:27:41 -0400 X-MC-Unique: R6a8-Oo6N6WpjTAbUIP45Q-1 X-Mimecast-MFC-AGG-ID: R6a8-Oo6N6WpjTAbUIP45Q_1774495659 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 026E718005BE; Thu, 26 Mar 2026 03:27:39 +0000 (UTC) Received: from fedora-laptop-x1.redhat.com (unknown [10.72.112.83]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 801321955D84; Thu, 26 Mar 2026 03:27:32 +0000 (UTC) From: Li Wang To: akpm@linux-foundation.org, yosry@kernel.org, nphamcs@gmail.com, hannes@cmpxchg.org, mhocko@kernel.org, mkoutny@suse.com, muchun.song@linux.dev, tj@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev Cc: longman@redhat.com, liwang@redhat.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed Subject: [PATCH v5 4/8] selftests/cgroup: rename PAGE_SIZE to BUF_SIZE in cgroup_util Date: Thu, 26 Mar 2026 11:26:54 +0800 Message-ID: <20260326032658.96819-5-liwang@redhat.com> In-Reply-To: <20260326032658.96819-1-liwang@redhat.com> References: <20260326032658.96819-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.0 on 10.30.177.17 The cgroup utility code defines a local PAGE_SIZE macro hardcoded to 4096, which is used primarily as a generic buffer size for reading cgroup and proc files. This naming is misleading because the value has nothing to do with the actual page size of the system. On architectures with larger pages (e.g., 64K on arm64 or ppc64), the name suggests a relationship that does not exist. Additionally, the name can shadow or conflict with PAGE_SIZE definitions from system headers, leading to confusion or subtle bugs. To resolve this, rename the macro to BUF_SIZE to accurately reflect its purpose as a general I/O buffer size. Furthermore, test_memcontrol currently relies on this hardcoded 4K value to stride through memory and trigger page faults. Update this logic to use the actual system page size dynamically. This micro-optimizes the memory faulting process by ensuring it iterates correctly and efficiently based on the underlying architecture's true page size. (This part from Waim= an) Signed-off-by: Li Wang Signed-off-by: Waiman Long 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: v5: - Merge Waiman's work into this patch (use page_size) v4: - Use page_size instead of BUF_SIZE in test_memcontrol.c =20 v3, v2, v1: - No changes. .../selftests/cgroup/lib/cgroup_util.c | 18 +++++++++--------- .../cgroup/lib/include/cgroup_util.h | 4 ++-- tools/testing/selftests/cgroup/test_core.c | 2 +- tools/testing/selftests/cgroup/test_freezer.c | 2 +- .../selftests/cgroup/test_memcontrol.c | 19 ++++++++++++------- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/cgroup/lib/cgroup_util.c b/tools/testi= ng/selftests/cgroup/lib/cgroup_util.c index ce6c2642fd9b..0be525ed11db 100644 --- a/tools/testing/selftests/cgroup/lib/cgroup_util.c +++ b/tools/testing/selftests/cgroup/lib/cgroup_util.c @@ -125,7 +125,7 @@ int cg_read_strcmp(const char *cgroup, const char *cont= rol, =20 int cg_read_strstr(const char *cgroup, const char *control, const char *ne= edle) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; =20 if (cg_read(cgroup, control, buf, sizeof(buf))) return -1; @@ -155,7 +155,7 @@ long cg_read_long_fd(int fd) =20 long cg_read_key_long(const char *cgroup, const char *control, const char = *key) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; char *ptr; =20 if (cg_read(cgroup, control, buf, sizeof(buf))) @@ -191,7 +191,7 @@ long cg_read_key_long_poll(const char *cgroup, const ch= ar *control, =20 long cg_read_lc(const char *cgroup, const char *control) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; const char delim[] =3D "\n"; char *line; long cnt =3D 0; @@ -243,7 +243,7 @@ int cg_write_numeric(const char *cgroup, const char *co= ntrol, long value) static int cg_find_root(char *root, size_t len, const char *controller, bool *nsdelegate) { - char buf[10 * PAGE_SIZE]; + char buf[10 * BUF_SIZE]; char *fs, *mount, *type, *options; const char delim[] =3D "\n\t "; =20 @@ -298,7 +298,7 @@ int cg_create(const char *cgroup) =20 int cg_wait_for_proc_count(const char *cgroup, int count) { - char buf[10 * PAGE_SIZE] =3D {0}; + char buf[10 * BUF_SIZE] =3D {0}; int attempts; char *ptr; =20 @@ -323,7 +323,7 @@ int cg_wait_for_proc_count(const char *cgroup, int coun= t) =20 int cg_killall(const char *cgroup) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; char *ptr =3D buf; =20 /* If cgroup.kill exists use it. */ @@ -533,7 +533,7 @@ int cg_run_nowait(const char *cgroup, =20 int proc_mount_contains(const char *option) { - char buf[4 * PAGE_SIZE]; + char buf[4 * BUF_SIZE]; ssize_t read; =20 read =3D read_text("/proc/mounts", buf, sizeof(buf)); @@ -545,7 +545,7 @@ int proc_mount_contains(const char *option) =20 int cgroup_feature(const char *feature) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; ssize_t read; =20 read =3D read_text("/sys/kernel/cgroup/features", buf, sizeof(buf)); @@ -572,7 +572,7 @@ ssize_t proc_read_text(int pid, bool thread, const char= *item, char *buf, size_t =20 int proc_read_strstr(int pid, bool thread, const char *item, const char *n= eedle) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; =20 if (proc_read_text(pid, thread, item, buf, sizeof(buf)) < 0) return -1; diff --git a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h b/too= ls/testing/selftests/cgroup/lib/include/cgroup_util.h index 77f386dab5e8..ca4a161c17a4 100644 --- a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h +++ b/tools/testing/selftests/cgroup/lib/include/cgroup_util.h @@ -2,8 +2,8 @@ #include #include =20 -#ifndef PAGE_SIZE -#define PAGE_SIZE 4096 +#ifndef BUF_SIZE +#define BUF_SIZE 4096 #endif =20 #define MB(x) (x << 20) diff --git a/tools/testing/selftests/cgroup/test_core.c b/tools/testing/sel= ftests/cgroup/test_core.c index 102262555a59..df7fac7e5554 100644 --- a/tools/testing/selftests/cgroup/test_core.c +++ b/tools/testing/selftests/cgroup/test_core.c @@ -87,7 +87,7 @@ static int test_cgcore_destroy(const char *root) int ret =3D KSFT_FAIL; char *cg_test =3D NULL; int child_pid; - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; =20 cg_test =3D cg_name(root, "cg_test"); =20 diff --git a/tools/testing/selftests/cgroup/test_freezer.c b/tools/testing/= selftests/cgroup/test_freezer.c index 97fae92c8387..160a9e6ad277 100644 --- a/tools/testing/selftests/cgroup/test_freezer.c +++ b/tools/testing/selftests/cgroup/test_freezer.c @@ -642,7 +642,7 @@ static int test_cgfreezer_ptrace(const char *root) */ static int proc_check_stopped(int pid) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; int len; =20 len =3D proc_read_text(pid, 0, "stat", buf, sizeof(buf)); diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testi= ng/selftests/cgroup/test_memcontrol.c index 2fb096a2a9f9..94d7b9de978c 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -25,6 +25,7 @@ =20 static bool has_localevents; static bool has_recursiveprot; +static size_t page_size; =20 int get_temp_fd(void) { @@ -33,7 +34,7 @@ int get_temp_fd(void) =20 int alloc_pagecache(int fd, size_t size) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; struct stat st; int i; =20 @@ -60,7 +61,7 @@ int alloc_anon(const char *cgroup, void *arg) char *buf, *ptr; =20 buf =3D malloc(size); - for (ptr =3D buf; ptr < buf + size; ptr +=3D PAGE_SIZE) + for (ptr =3D buf; ptr < buf + size; ptr +=3D BUF_SIZE) *ptr =3D 0; =20 free(buf); @@ -69,7 +70,7 @@ int alloc_anon(const char *cgroup, void *arg) =20 int is_swap_enabled(void) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; const char delim[] =3D "\n"; int cnt =3D 0; char *line; @@ -112,7 +113,7 @@ static int test_memcg_subtree_control(const char *root) { char *parent, *child, *parent2 =3D NULL, *child2 =3D NULL; int ret =3D KSFT_FAIL; - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; =20 /* Create two nested cgroups with the memory controller enabled */ parent =3D cg_name(root, "memcg_test_0"); @@ -183,7 +184,7 @@ static int alloc_anon_50M_check(const char *cgroup, voi= d *arg) return -1; } =20 - for (ptr =3D buf; ptr < buf + size; ptr +=3D PAGE_SIZE) + for (ptr =3D buf; ptr < buf + size; ptr +=3D page_size) *ptr =3D 0; =20 current =3D cg_read_long(cgroup, "memory.current"); @@ -413,7 +414,7 @@ static int alloc_anon_noexit(const char *cgroup, void *= arg) return -1; } =20 - for (ptr =3D buf; ptr < buf + size; ptr +=3D PAGE_SIZE) + for (ptr =3D buf; ptr < buf + size; ptr +=3D page_size) *ptr =3D 0; =20 while (getppid() =3D=3D ppid) @@ -999,7 +1000,7 @@ static int alloc_anon_50M_check_swap(const char *cgrou= p, void *arg) return -1; } =20 - for (ptr =3D buf; ptr < buf + size; ptr +=3D PAGE_SIZE) + for (ptr =3D buf; ptr < buf + size; ptr +=3D page_size) *ptr =3D 0; =20 mem_current =3D cg_read_long(cgroup, "memory.current"); @@ -1670,6 +1671,10 @@ int main(int argc, char **argv) char root[PATH_MAX]; int i, proc_status; =20 + page_size =3D sysconf(_SC_PAGE_SIZE); + if (page_size <=3D 0) + page_size =3D BUF_SIZE; + ksft_print_header(); ksft_set_plan(ARRAY_SIZE(tests)); if (cg_find_unified_root(root, sizeof(root), NULL)) --=20 2.53.0 From nobody Thu Apr 2 23:54:10 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 0618F3932E9 for ; Thu, 26 Mar 2026 03:27: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=1774495673; cv=none; b=md7BzDQ0CZcZmvgsLgp1204QlIWnmP9w1rrjpv4PAH7zbRH0zdESftJDvD3Gki/qu795wXKaaNNYhmV6gMucROzGSpQyOWxr9YQbIFTbYVBLaRHoUQnCKm+VHsmUwqQ96aefOWvxvoky+g41kXXlC2sxDI1kXoa4PuNdrH03gU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774495673; c=relaxed/simple; bh=M/dBkrFqFtzEbwnDt5YHwuuZoz30Zq434E5lC5koaaE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bPDZNprFgn9ygWcyN9jI7PAEUml1KwyePId97hfN6GpJppgq7wj7S4L01EQ8Svejr1ZClG8N5AIBGXK2AOUl3sh9R1TsGOiz/P3hNXybh0SJdi8WUT8ptLLcLDTQ2K9yywXeBEItRQo1X+w68NnS43JjDAITxmJKAgkMD6nnfL0= 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=QC8pWvKl; 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="QC8pWvKl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774495671; 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=cPJkc7Lk4qI4ZA2OHZYE0osYDu+lYGmpcUChp6ka55s=; b=QC8pWvKlC56WZQZM4AwX/pmDpH6smJvXq/tmpCYQWb66lMRRX2t7Ni2W4maWVAjc48voeY PbXuc5kOqvC2kNsdWhDaS4U5gB3TFt3EMBE2/Df7SyQao39Iyz12NQdZ6tNPhFqFtzmDPa H6GA23NUkSLrLjUp3gL7+ajf9DtN0VU= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659--zYwZqH-OqCHBGKG4GzQeg-1; Wed, 25 Mar 2026 23:27:47 -0400 X-MC-Unique: -zYwZqH-OqCHBGKG4GzQeg-1 X-Mimecast-MFC-AGG-ID: -zYwZqH-OqCHBGKG4GzQeg_1774495665 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7E7781800344; Thu, 26 Mar 2026 03:27:45 +0000 (UTC) Received: from fedora-laptop-x1.redhat.com (unknown [10.72.112.83]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A2EA61955D84; Thu, 26 Mar 2026 03:27:39 +0000 (UTC) From: Li Wang To: akpm@linux-foundation.org, yosry@kernel.org, nphamcs@gmail.com, hannes@cmpxchg.org, mhocko@kernel.org, mkoutny@suse.com, muchun.song@linux.dev, tj@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev Cc: longman@redhat.com, liwang@redhat.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v5 5/8] selftests/cgroup: replace hardcoded page size values in test_zswap Date: Thu, 26 Mar 2026 11:26:55 +0800 Message-ID: <20260326032658.96819-6-liwang@redhat.com> In-Reply-To: <20260326032658.96819-1-liwang@redhat.com> References: <20260326032658.96819-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.0 on 10.30.177.17 test_zswap uses hardcoded values of 4095 and 4096 throughout as page stride and page size, which are only correct on systems with a 4K page size. On architectures with larger pages (e.g., 64K on arm64 or ppc64), these constants cause memory to be touched at sub-page granularity, leading to inefficient access patterns and incorrect page count calculations, which can cause test failures. Replace all hardcoded 4095 and 4096 values with a global pagesize variable initialized from sysconf(_SC_PAGESIZE) at startup, and remove the redundant local sysconf() calls scattered across individual functions. No functional change on 4K page size systems. 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 Acked-by: Yosry Ahmed --- Notes: v5: - Change pagesize by the global page_size. v1-4: - No changes. tools/testing/selftests/cgroup/test_zswap.c | 39 ++++++++++++--------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/se= lftests/cgroup/test_zswap.c index 516da5d52bfd..fc7a9aa27e27 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -13,6 +13,8 @@ #include "kselftest.h" #include "cgroup_util.h" =20 +static size_t page_size; + #define PATH_ZSWAP "/sys/module/zswap" #define PATH_ZSWAP_ENABLED "/sys/module/zswap/parameters/enabled" =20 @@ -71,11 +73,11 @@ static int allocate_and_read_bytes(const char *cgroup, = void *arg) =20 if (!mem) return -1; - for (int i =3D 0; i < size; i +=3D 4095) + for (int i =3D 0; i < size; i +=3D page_size) mem[i] =3D 'a'; =20 /* Go through the allocated memory to (z)swap in and out pages */ - for (int i =3D 0; i < size; i +=3D 4095) { + for (int i =3D 0; i < size; i +=3D page_size) { if (mem[i] !=3D 'a') ret =3D -1; } @@ -91,7 +93,7 @@ static int allocate_bytes(const char *cgroup, void *arg) =20 if (!mem) return -1; - for (int i =3D 0; i < size; i +=3D 4095) + for (int i =3D 0; i < size; i +=3D page_size) mem[i] =3D 'a'; free(mem); return 0; @@ -270,9 +272,8 @@ static int test_zswapin(const char *root) */ static int attempt_writeback(const char *cgroup, void *arg) { - long pagesize =3D sysconf(_SC_PAGESIZE); size_t memsize =3D MB(4); - char buf[pagesize]; + char buf[page_size]; long zswap_usage; bool wb_enabled =3D *(bool *) arg; int ret =3D -1; @@ -287,11 +288,11 @@ static int attempt_writeback(const char *cgroup, void= *arg) * half empty, this will result in data that is still compressible * and ends up in zswap, with material zswap usage. */ - for (int i =3D 0; i < pagesize; i++) - buf[i] =3D i < pagesize/2 ? (char) i : 0; + for (int i =3D 0; i < page_size; i++) + buf[i] =3D i < page_size/2 ? (char) i : 0; =20 - for (int i =3D 0; i < memsize; i +=3D pagesize) - memcpy(&mem[i], buf, pagesize); + for (int i =3D 0; i < memsize; i +=3D page_size) + memcpy(&mem[i], buf, page_size); =20 /* Try and reclaim allocated memory */ if (cg_write_numeric(cgroup, "memory.reclaim", memsize)) { @@ -302,8 +303,8 @@ static int attempt_writeback(const char *cgroup, void *= arg) zswap_usage =3D cg_read_long(cgroup, "memory.zswap.current"); =20 /* zswpin */ - for (int i =3D 0; i < memsize; i +=3D pagesize) { - if (memcmp(&mem[i], buf, pagesize)) { + for (int i =3D 0; i < memsize; i +=3D page_size) { + if (memcmp(&mem[i], buf, page_size)) { ksft_print_msg("invalid memory\n"); goto out; } @@ -439,7 +440,7 @@ static int test_no_invasive_cgroup_shrink(const char *r= oot) if (cg_enter_current(control_group)) goto out; control_allocation =3D malloc(control_allocation_size); - for (int i =3D 0; i < control_allocation_size; i +=3D 4095) + for (int i =3D 0; i < control_allocation_size; i +=3D page_size) control_allocation[i] =3D 'a'; if (cg_read_key_long(control_group, "memory.stat", "zswapped") < 1) goto out; @@ -479,7 +480,7 @@ static int no_kmem_bypass_child(const char *cgroup, voi= d *arg) values->child_allocated =3D true; return -1; } - for (long i =3D 0; i < values->target_alloc_bytes; i +=3D 4095) + for (long i =3D 0; i < values->target_alloc_bytes; i +=3D page_size) ((char *)allocation)[i] =3D 'a'; values->child_allocated =3D true; pause(); @@ -527,7 +528,7 @@ static int test_no_kmem_bypass(const char *root) min_free_kb_low =3D sys_info.totalram / 500000; values->target_alloc_bytes =3D (sys_info.totalram - min_free_kb_high * 10= 00) + sys_info.totalram * 5 / 100; - stored_pages_threshold =3D sys_info.totalram / 5 / 4096; + stored_pages_threshold =3D sys_info.totalram / 5 / page_size; trigger_allocation_size =3D sys_info.totalram / 20; =20 /* Set up test memcg */ @@ -554,7 +555,7 @@ static int test_no_kmem_bypass(const char *root) =20 if (!trigger_allocation) break; - for (int i =3D 0; i < trigger_allocation_size; i +=3D 4095) + for (int i =3D 0; i < trigger_allocation_size; i +=3D page_size) trigger_allocation[i] =3D 'b'; usleep(100000); free(trigger_allocation); @@ -565,8 +566,8 @@ static int test_no_kmem_bypass(const char *root) /* If memory was pushed to zswap, verify it belongs to memcg */ if (stored_pages > stored_pages_threshold) { int zswapped =3D cg_read_key_long(test_group, "memory.stat", "zswapped = "); - int delta =3D stored_pages * 4096 - zswapped; - int result_ok =3D delta < stored_pages * 4096 / 4; + int delta =3D stored_pages * page_size - zswapped; + int result_ok =3D delta < stored_pages * page_size / 4; =20 ret =3D result_ok ? KSFT_PASS : KSFT_FAIL; break; @@ -616,6 +617,10 @@ int main(int argc, char **argv) char root[PATH_MAX]; int i; =20 + page_size =3D sysconf(_SC_PAGE_SIZE); + if (page_size <=3D 0) + page_size =3D BUF_SIZE; + ksft_print_header(); ksft_set_plan(ARRAY_SIZE(tests)); if (cg_find_unified_root(root, sizeof(root), NULL)) --=20 2.53.0 From nobody Thu Apr 2 23:54:10 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 0ACB539281E for ; Thu, 26 Mar 2026 03:28:00 +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=1774495682; cv=none; b=MhLAe7fqlVCb5IAKs73VzJlVUYB/O8aTKbI5rZw47P/odXBXifhLe0UFOlCcEJXpphezRtY6+tr0Ijcoeynp+qQ21AORwB+EXHIPn1zoqSy+VM8ty3+obsL8WAlLWjwyIYyc5zYOpRAQf35OhQYKLRSktxL7jhrk7qRDy+Iu87c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774495682; c=relaxed/simple; bh=pgUe2+vPeFtlGsxEtJR+FNgqz0DO3XioPWYd4OIw4bQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Zi33G6cPbcyMSm3F2sIqxMSP4DrrN5CArKwYceCr/kiZ0JO5OF2ERWi/xzyB3HgEVMgn2QQ3QYdF38VrHRnsqgz3ff/04kudO0HIuC2wbbkOB8gjNnQPmDorJUK3ECEFwx0vtgYcpLBtSXhQ3VJd+tIIi4mjrdOiyCAWuWLAc2Y= 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=blxMQXhC; 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="blxMQXhC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774495680; 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=NkrZmV+ciJiAg2eJxu0EA95Ha45gXSvLLHXumh7zBiQ=; b=blxMQXhC9rdvrU5l8tBTltH2SDfeWVWYCLxRvSk1uZvTAAxu3MNWJmTC+rXO3hfF8Az6CA HR5j3khRtsK37U2RHYJbr0LrAQK5dW3QyJMwjdfx9Nxnz9+TKv6HCm7ZMUhrWjuTLbND0K RZ16Rt2zOGBZEfzwpJOUrYYHixuuTy8= 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-629-BtFk9MNAPCK8rq26DfrzFA-1; Wed, 25 Mar 2026 23:27:54 -0400 X-MC-Unique: BtFk9MNAPCK8rq26DfrzFA-1 X-Mimecast-MFC-AGG-ID: BtFk9MNAPCK8rq26DfrzFA_1774495672 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 6A98C19560A6; Thu, 26 Mar 2026 03:27:52 +0000 (UTC) Received: from fedora-laptop-x1.redhat.com (unknown [10.72.112.83]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 15A8E1955D84; Thu, 26 Mar 2026 03:27:45 +0000 (UTC) From: Li Wang To: akpm@linux-foundation.org, yosry@kernel.org, nphamcs@gmail.com, hannes@cmpxchg.org, mhocko@kernel.org, mkoutny@suse.com, muchun.song@linux.dev, tj@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev Cc: longman@redhat.com, liwang@redhat.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed Subject: [PATCH v5 6/8] selftest/cgroup: fix zswap test_no_invasive_cgroup_shrink on large pagesize system Date: Thu, 26 Mar 2026 11:26:56 +0800 Message-ID: <20260326032658.96819-7-liwang@redhat.com> In-Reply-To: <20260326032658.96819-1-liwang@redhat.com> References: <20260326032658.96819-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.0 on 10.30.177.17 test_no_invasive_cgroup_shrink sets up two cgroups: wb_group, which is expected to trigger zswap writeback, and a control group (renamed to zw_group), which should only have pages sitting in zswap without any writeback. There are two problems with the current test: 1) The data patterns are reversed. wb_group uses allocate_bytes(), which writes only a single byte per page =E2=80=94 trivially compressible, especially by zstd =E2=80=94 so compressed pages fit within zswap.max and writeback is never triggered. Meanwhile, the control group uses getrandom() to produce hard-to-compress data, but it is the group that does *not* need writeback. 2) The test uses fixed sizes (10K zswap.max, 10MB allocation) that are too small on systems with large PAGE_SIZE (e.g. 64K), failing to build enough memory pressure to trigger writeback reliably. Fix both issues by: - Swapping the data patterns: fill wb_group pages with partially random data (getrandom for page_size/4 bytes) to resist compression and trigger writeback, and fill zw_group pages with simple repeated data to stay compressed in zswap. - Making all size parameters PAGE_SIZE-aware: set allocation size to PAGE_SIZE * 1024, memory.zswap.max to PAGE_SIZE, and memory.max to allocation_size / 2 for both cgroups. - Allocating memory inline instead of via cg_run() so the pages remain resident throughout the test. =3D=3D=3D Error Log =3D=3D=3D # getconf PAGESIZE 65536 # ./test_zswap TAP version 13 ... ok 5 test_zswap_writeback_disabled ok 6 # SKIP test_no_kmem_bypass not ok 7 test_no_invasive_cgroup_shrink 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: v5: - Swap data patterns: use getrandom() for wb_group and simple memset for zw_group to fix the reversed allocation logic. - Rename control_group to zw_group for clarity. - Allocate memory inline instead of via cg_run() so pages remain resident throughout the test. tools/testing/selftests/cgroup/test_zswap.c | 69 ++++++++++++++------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/se= lftests/cgroup/test_zswap.c index fc7a9aa27e27..72082e5d4725 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -9,6 +9,7 @@ #include #include #include +#include =20 #include "kselftest.h" #include "cgroup_util.h" @@ -424,44 +425,70 @@ static int test_zswap_writeback_disabled(const char *= root) static int test_no_invasive_cgroup_shrink(const char *root) { int ret =3D KSFT_FAIL; - size_t control_allocation_size =3D MB(10); - char *control_allocation =3D NULL, *wb_group =3D NULL, *control_group =3D= NULL; + unsigned int off; + size_t allocation_size =3D page_size * 1024; + unsigned int nr_pages =3D allocation_size / page_size; + char zswap_max_buf[32], mem_max_buf[32]; + char *zw_allocation =3D NULL, *wb_allocation =3D NULL; + char *zw_group =3D NULL, *wb_group =3D NULL; + + snprintf(zswap_max_buf, sizeof(zswap_max_buf), "%zu", page_size); + snprintf(mem_max_buf, sizeof(mem_max_buf), "%zu", allocation_size / 2); =20 wb_group =3D setup_test_group_1M(root, "per_memcg_wb_test1"); if (!wb_group) return KSFT_FAIL; - if (cg_write(wb_group, "memory.zswap.max", "10K")) + if (cg_write(wb_group, "memory.zswap.max", zswap_max_buf)) + goto out; + if (cg_write(wb_group, "memory.max", mem_max_buf)) + goto out; + + zw_group =3D setup_test_group_1M(root, "per_memcg_wb_test2"); + if (!zw_group) goto out; - control_group =3D setup_test_group_1M(root, "per_memcg_wb_test2"); - if (!control_group) + if (cg_write(zw_group, "memory.max", mem_max_buf)) goto out; =20 - /* Push some test_group2 memory into zswap */ - if (cg_enter_current(control_group)) + /* Push some zw_group memory into zswap (simple data, easy to compress) */ + if (cg_enter_current(zw_group)) goto out; - control_allocation =3D malloc(control_allocation_size); - for (int i =3D 0; i < control_allocation_size; i +=3D page_size) - control_allocation[i] =3D 'a'; - if (cg_read_key_long(control_group, "memory.stat", "zswapped") < 1) + zw_allocation =3D malloc(allocation_size); + for (int i =3D 0; i < nr_pages; i++) { + off =3D (unsigned long)i * page_size; + memset(&zw_allocation[off], 'a', page_size/4); + } + if (cg_read_key_long(zw_group, "memory.stat", "zswapped") < 1) goto out; =20 - /* Allocate 10x memory.max to push wb_group memory into zswap and trigger= wb */ - if (cg_run(wb_group, allocate_bytes, (void *)MB(10))) + /* Push wb_group memory into zswap with hard-to-compress data to trigger = wb */ + if (cg_enter_current(wb_group)) + goto out; + wb_allocation =3D malloc(allocation_size); + if (!wb_allocation) goto out; + for (int i =3D 0; i < nr_pages; i++) { + off =3D (unsigned long)i * page_size; + memset(&wb_allocation[off], 0, page_size); + getrandom(&wb_allocation[off], page_size/4, 0); + } =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(control_group) =3D= =3D 0) + if (get_cg_wb_count(wb_group) > 0 && get_cg_wb_count(zw_group) =3D=3D 0) ret =3D KSFT_PASS; out: cg_enter_current(root); - if (control_group) { - cg_destroy(control_group); - free(control_group); + if (zw_group) { + cg_destroy(zw_group); + free(zw_group); + } + if (wb_group) { + cg_destroy(wb_group); + free(wb_group); } - cg_destroy(wb_group); - free(wb_group); - if (control_allocation) - free(control_allocation); + if (zw_allocation) + free(zw_allocation); + if (wb_allocation) + free(wb_allocation); return ret; } =20 --=20 2.53.0 From nobody Thu Apr 2 23:54:10 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 CF82C39281E for ; Thu, 26 Mar 2026 03:28:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774495687; cv=none; b=Ryk19VhpnB6l2kkYC5YVhSTIlX7sUQwZyRBMn18oOs+qwDZ3vuu9KkzC596DCh7wxA5xcH2AxQl4TvLfBayW4QWIsSUOWp1cYd0AVg9rWhAfOPpEL6K/rJaLslOn0EjIvqb8VlywHdsT7dWktVG1/UIk+Xh7n7KOGrfGTs7nPds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774495687; c=relaxed/simple; bh=o/w7TQliWDhKNWU6CNP5i3AA/k45gK0jKqDtWaqSPOs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=awOrqADC74XiCPFKOktV88nnu+4iHdkYOTlgzKfmXrZOwSIlo2kqxueIWpIYbWO0YksOPWoFHyUQ/Oe6aCfHLGbhx8Qi8gSGZyvJDeZdjng5d08mjDrl9hEmpzZUkl66PvWg8i61LIiI02j0oIwgZK+up+lNkuxQG7ql3ieCrHY= 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=SEzIsl20; arc=none smtp.client-ip=170.10.133.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="SEzIsl20" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774495684; 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=5FEF4PcMxcimzj0nghaejrMWC+mQHsYsFdwp2v61C34=; b=SEzIsl20EhLffOW6EfrCqxwKYOyz/cl9TBFd1lPwn4V4zRvcXbYBrdVRUowZhQ8RcvT6oD KeUB6jcrBwkRiO8QZCcOrxi7M4tImNXvUnAaWLVBo1cx+4YDKJxsF2EGzcdUmDlOmP7nM4 Opor4aIioQbTL3EB5axtEsTX13vUaL4= Received: from mx-prod-mc-03.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-318-Zk5XMdgqMyqNHJrO1O5hKg-1; Wed, 25 Mar 2026 23:28:00 -0400 X-MC-Unique: Zk5XMdgqMyqNHJrO1O5hKg-1 X-Mimecast-MFC-AGG-ID: Zk5XMdgqMyqNHJrO1O5hKg_1774495679 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CF6DD1944EB8; Thu, 26 Mar 2026 03:27:58 +0000 (UTC) Received: from fedora-laptop-x1.redhat.com (unknown [10.72.112.83]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 160451955D84; Thu, 26 Mar 2026 03:27:52 +0000 (UTC) From: Li Wang To: akpm@linux-foundation.org, yosry@kernel.org, nphamcs@gmail.com, hannes@cmpxchg.org, mhocko@kernel.org, mkoutny@suse.com, muchun.song@linux.dev, tj@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev Cc: longman@redhat.com, liwang@redhat.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v5 7/8] selftest/cgroup: fix zswap attempt_writeback() on 64K pagesize system Date: Thu, 26 Mar 2026 11:26:57 +0800 Message-ID: <20260326032658.96819-8-liwang@redhat.com> In-Reply-To: <20260326032658.96819-1-liwang@redhat.com> References: <20260326032658.96819-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.0 on 10.30.177.17 In attempt_writeback(), a memsize of 4M only covers 64 pages on 64K page size systems. When memory.reclaim is called, the kernel prefers reclaiming clean file pages (binary, libc, linker, etc.) over swapping anonymous pages. With only 64 pages of anonymous memory, the reclaim target can be largely or entirely satisfied by dropping file pages, resulting in very few or zero anonymous pages being pushed into zswap. This causes zswap_usage to be extremely small or zero, making zswap_usage/2 insufficient to create meaningful writeback pressure. The test then fails because no writeback is triggered. On 4K page size systems this is not an issue because 4M covers 1024 pages, and file pages are a small fraction of the reclaim target. Fix this by: - Always allocating 1024 pages regardless of page size. This ensures enough anonymous pages to reliably populate zswap and trigger writeback, while keeping the original 4M allocation on 4K systems. - Setting zswap.max to zswap_usage/4 instead of zswap_usage/2 to create stronger writeback pressure, ensuring reclaim reliably triggers writeback even on large page size systems. =3D=3D=3D Error Log =3D=3D=3D # uname -rm 6.12.0-211.el10.ppc64le ppc64le # getconf PAGESIZE 65536 # ./test_zswap TAP version 13 1..7 ok 1 test_zswap_usage ok 2 test_swapin_nozswap ok 3 test_zswapin not ok 4 test_zswap_writeback_enabled ... 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 Acked-by: Yosry Ahmed --- Notes: v5: - Setting zswap.max to zswap_usage/4 to create stronger writeback pres= sure. v3-4: - No changes. v2: - use pagesize * 1024 which clearly shows the page numbers. tools/testing/selftests/cgroup/test_zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/se= lftests/cgroup/test_zswap.c index 72082e5d4725..e96e316f7c47 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -273,7 +273,7 @@ static int test_zswapin(const char *root) */ static int attempt_writeback(const char *cgroup, void *arg) { - size_t memsize =3D MB(4); + size_t memsize =3D page_size * 1024; char buf[page_size]; long zswap_usage; bool wb_enabled =3D *(bool *) arg; @@ -311,7 +311,7 @@ static int attempt_writeback(const char *cgroup, void *= arg) } } =20 - if (cg_write_numeric(cgroup, "memory.zswap.max", zswap_usage/2)) + if (cg_write_numeric(cgroup, "memory.zswap.max", zswap_usage/4)) goto out; =20 /* --=20 2.53.0 From nobody Thu Apr 2 23:54:10 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 411C2355F49 for ; Thu, 26 Mar 2026 03:28:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774495695; cv=none; b=ipwC6ZTfKhK5vdlKIXYYrvSnx18XDgT8VvCgzEdnrYHLCOyx/B2sQismLV1K6fC9/2ibTW4qDCQgpc5O3U/qOC8YCyDrwBocs59JcZnnWS8eKzmKa7O6CYtiqrvjqJaPz1GbBLFUrAcQ6zqoKpDoPFcef+heu+Leenv0BfO7okE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774495695; c=relaxed/simple; bh=Db9FpGjMEsnfOujo+Rx3taOhK7m8n2Zf3BPQRSbWgPE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H22oEJluCk1YbdsjYhuSYU/LxfchRNtdDT0PytD/+UtVeGNrVhW4Dpz3tXBlQqy480/rmWtOJvNgX5AhhyI8tTA2EZpDkYJLJpHEL1PPrbAiJ7QryO1ybqq+b6avWvih2AC1czVa7gUz0OJK+zCZQZaWlwvQ6ymIgxtc0hvVUpU= 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=RhXcB9NE; arc=none smtp.client-ip=170.10.133.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="RhXcB9NE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774495693; 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=z7qTVQy4P3P+tWAwnSkI8eaROMeV/uij3L4ybuXlnco=; b=RhXcB9NEEOFahXwNrC+BhowL2bgISWiEXa6J4G1p5DlvwujkKZu59a9bLdHGn8fUeucTB1 fmGa1e7RgGI87nUVOLnQgi2Xwl43eSdu3dUsio4V7l+FhcUdhcIb6/BD6BQemDJx3iftTz MYSQ2Xf8lS9CZ+eRgxA6i6aQleGMiL8= 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-390-g6BzXI2gPqOlcblx0mevOA-1; Wed, 25 Mar 2026 23:28:08 -0400 X-MC-Unique: g6BzXI2gPqOlcblx0mevOA-1 X-Mimecast-MFC-AGG-ID: g6BzXI2gPqOlcblx0mevOA_1774495685 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 C8BD819560A7; Thu, 26 Mar 2026 03:28:05 +0000 (UTC) Received: from fedora-laptop-x1.redhat.com (unknown [10.72.112.83]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7C0731955D84; Thu, 26 Mar 2026 03:27:59 +0000 (UTC) From: Li Wang To: akpm@linux-foundation.org, yosry@kernel.org, nphamcs@gmail.com, hannes@cmpxchg.org, mhocko@kernel.org, mkoutny@suse.com, muchun.song@linux.dev, tj@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev Cc: longman@redhat.com, liwang@redhat.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed Subject: [PATCH v5 8/8] selftests/cgroup: test_zswap: wait for asynchronous writeback Date: Thu, 26 Mar 2026 11:26:58 +0800 Message-ID: <20260326032658.96819-9-liwang@redhat.com> In-Reply-To: <20260326032658.96819-1-liwang@redhat.com> References: <20260326032658.96819-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.0 on 10.30.177.17 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 --- 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 e96e316f7c47..e7d5dbc1ef7f 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) +{ + int 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 @@ -473,7 +497,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