* [PATCH] selftests/cgroup: test_zswap: use the total RAM in bytes
@ 2026-11-03 16:39 Sasha Levin
2026-11-04 13:22 ` Tao Cui
0 siblings, 1 reply; 3+ messages in thread
From: Sasha Levin @ 2026-11-03 16:39 UTC (permalink / raw)
To: Johannes Weiner, Yosry Ahmed, Nhat Pham, Tejun Heo, Michal Koutný
Cc: Chengming Zhou, Shuah Khan, linux-mm, cgroups, linux-kselftest,
linux-kernel
test_no_kmem_bypass() uses the totalram field of struct sysinfo as a
byte count, but it is in units of mem_unit, which can be larger than 1
on 32-bit architectures. There totalram also can't exceed GB(4), so the
size check never triggers:
test_zswap.c:609:24: warning: result of comparison of constant 4294967296 with expression of type '__kernel_ulong_t' (aka 'unsigned long') is always false [-Wtautological-constant-out-of-range-compare]
Multiply totalram by mem_unit as an unsigned long long and use that for
the check and the values derived from it. Nothing changes on 64-bit,
where mem_unit is 1.
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
Found with 32-bit builds of the selftests (gcc 16 and clang 21 with
-m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64);
KernelCI's 32-bit arm builds show the same warnings. The changed files
build without them now, and the x86_64 builds don't change.
tools/testing/selftests/cgroup/test_zswap.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c
index d50acc1b83ac8..223e2eb1329ab 100644
--- a/tools/testing/selftests/cgroup/test_zswap.c
+++ b/tools/testing/selftests/cgroup/test_zswap.c
@@ -597,6 +597,7 @@ static int test_no_kmem_bypass(const char *root)
size_t trigger_allocation_size;
int wait_child_iteration = 0;
long stored_pages_threshold;
+ unsigned long long totalram;
struct sysinfo sys_info;
int ret = KSFT_FAIL;
int child_status;
@@ -606,10 +607,11 @@ static int test_no_kmem_bypass(const char *root)
/* Read sys info and compute test values accordingly */
if (sysinfo(&sys_info) != 0)
return KSFT_FAIL;
- if (sys_info.totalram > GB(4)) {
+ totalram = (unsigned long long)sys_info.totalram * sys_info.mem_unit;
+ if (totalram > GB(4)) {
ksft_print_msg(
- "requires less than 4GB total ram, sys_info.totalram: %.1fGB\n",
- (double)sys_info.totalram / GB(1));
+ "requires less than 4GB total ram, total ram: %.1fGB\n",
+ (double)totalram / GB(1));
return KSFT_SKIP;
}
if (access(PATH_ZSWAP_STORED_PAGES, R_OK)) {
@@ -622,12 +624,12 @@ static int test_no_kmem_bypass(const char *root)
return KSFT_FAIL;
if (read_min_free_kb(&min_free_kb_original))
return KSFT_FAIL;
- min_free_kb_high = sys_info.totalram / 2000;
- min_free_kb_low = sys_info.totalram / 500000;
- values->target_alloc_bytes = (sys_info.totalram - min_free_kb_high * 1000) +
- sys_info.totalram * 5 / 100;
- stored_pages_threshold = sys_info.totalram / 5 / page_size;
- trigger_allocation_size = sys_info.totalram / 20;
+ min_free_kb_high = totalram / 2000;
+ min_free_kb_low = totalram / 500000;
+ values->target_alloc_bytes = (totalram - min_free_kb_high * 1000) +
+ totalram * 5 / 100;
+ stored_pages_threshold = totalram / 5 / page_size;
+ trigger_allocation_size = totalram / 20;
/* Set up test memcg */
test_group = cg_name(root, "kmem_bypass_test");
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] selftests/cgroup: test_zswap: use the total RAM in bytes
2026-11-03 16:39 [PATCH] selftests/cgroup: test_zswap: use the total RAM in bytes Sasha Levin
@ 2026-11-04 13:22 ` Tao Cui
2026-11-04 14:51 ` Sasha Levin
0 siblings, 1 reply; 3+ messages in thread
From: Tao Cui @ 2026-11-04 13:22 UTC (permalink / raw)
To: Sasha Levin, Johannes Weiner, Yosry Ahmed, Nhat Pham, Tejun Heo,
Michal Koutný
Cc: cui.tao, Chengming Zhou, Shuah Khan, linux-mm, cgroups,
linux-kselftest, linux-kernel
Hi Sasha,
在 2026/11/4 00:39, Sasha Levin 写道:
> test_no_kmem_bypass() uses the totalram field of struct sysinfo as a
> byte count, but it is in units of mem_unit, which can be larger than 1
> on 32-bit architectures. There totalram also can't exceed GB(4), so the
> size check never triggers:
>
> test_zswap.c:609:24: warning: result of comparison of constant 4294967296 with expression of type '__kernel_ulong_t' (aka 'unsigned long') is always false [-Wtautological-constant-out-of-range-compare]
>
> Multiply totalram by mem_unit as an unsigned long long and use that for
> the check and the values derived from it. Nothing changes on 64-bit,
> where mem_unit is 1.
>
Built test_zswap before and after on next-20261103 and ran both on a 4G
VM, identical results, no change on 64-bit as claimed.
One small thing: could you add a Fixes tag? The issue seems to date
back to a549f9f31561a ("selftests: cgroup: add test_zswap with no kmem
bypass test"), which introduced the sysinfo block, and 6f615890b848
later reshaped it into the current GB(4) comparison with the warning.
Reviewed-by: Tao Cui <cuitao@kylinos.cn>
Tested-by: Tao Cui <cuitao@kylinos.cn>
Thanks,
Tao
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> Found with 32-bit builds of the selftests (gcc 16 and clang 21 with
> -m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64);
> KernelCI's 32-bit arm builds show the same warnings. The changed files
> build without them now, and the x86_64 builds don't change.
>
> tools/testing/selftests/cgroup/test_zswap.c | 20 +++++++++++---------
> 1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c
> index d50acc1b83ac8..223e2eb1329ab 100644
> --- a/tools/testing/selftests/cgroup/test_zswap.c
> +++ b/tools/testing/selftests/cgroup/test_zswap.c
> @@ -597,6 +597,7 @@ static int test_no_kmem_bypass(const char *root)
> size_t trigger_allocation_size;
> int wait_child_iteration = 0;
> long stored_pages_threshold;
> + unsigned long long totalram;
> struct sysinfo sys_info;
> int ret = KSFT_FAIL;
> int child_status;
> @@ -606,10 +607,11 @@ static int test_no_kmem_bypass(const char *root)
> /* Read sys info and compute test values accordingly */
> if (sysinfo(&sys_info) != 0)
> return KSFT_FAIL;
> - if (sys_info.totalram > GB(4)) {
> + totalram = (unsigned long long)sys_info.totalram * sys_info.mem_unit;
> + if (totalram > GB(4)) {
> ksft_print_msg(
> - "requires less than 4GB total ram, sys_info.totalram: %.1fGB\n",
> - (double)sys_info.totalram / GB(1));
> + "requires less than 4GB total ram, total ram: %.1fGB\n",
> + (double)totalram / GB(1));
> return KSFT_SKIP;
> }
> if (access(PATH_ZSWAP_STORED_PAGES, R_OK)) {
> @@ -622,12 +624,12 @@ static int test_no_kmem_bypass(const char *root)
> return KSFT_FAIL;
> if (read_min_free_kb(&min_free_kb_original))
> return KSFT_FAIL;
> - min_free_kb_high = sys_info.totalram / 2000;
> - min_free_kb_low = sys_info.totalram / 500000;
> - values->target_alloc_bytes = (sys_info.totalram - min_free_kb_high * 1000) +
> - sys_info.totalram * 5 / 100;
> - stored_pages_threshold = sys_info.totalram / 5 / page_size;
> - trigger_allocation_size = sys_info.totalram / 20;
> + min_free_kb_high = totalram / 2000;
> + min_free_kb_low = totalram / 500000;
> + values->target_alloc_bytes = (totalram - min_free_kb_high * 1000) +
> + totalram * 5 / 100;
> + stored_pages_threshold = totalram / 5 / page_size;
> + trigger_allocation_size = totalram / 20;
>
> /* Set up test memcg */
> test_group = cg_name(root, "kmem_bypass_test");
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] selftests/cgroup: test_zswap: use the total RAM in bytes
2026-11-04 13:22 ` Tao Cui
@ 2026-11-04 14:51 ` Sasha Levin
0 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2026-11-04 14:51 UTC (permalink / raw)
To: Tao Cui
Cc: Johannes Weiner, Yosry Ahmed, Nhat Pham, Tejun Heo,
Michal Koutný,
Chengming Zhou, Shuah Khan, linux-mm, cgroups, linux-kselftest,
linux-kernel
On Wed, Nov 04, 2026 at 09:22:31PM +0800, Tao Cui wrote:
> One small thing: could you add a Fixes tag? The issue seems to date
> back to a549f9f31561a ("selftests: cgroup: add test_zswap with no kmem
> bypass test"), which introduced the sysinfo block, and 6f615890b848
> later reshaped it into the current GB(4) comparison with the warning.
Yes, the original check against 5000000000 could never be true on
32-bit either, and it already used totalram as bytes:
Fixes: a549f9f31561 ("selftests: cgroup: add test_zswap with no kmem bypass test")
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-04 14:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 16:39 [PATCH] selftests/cgroup: test_zswap: use the total RAM in bytes Sasha Levin
2026-11-04 13:22 ` Tao Cui
2026-11-04 14:51 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®