* [PATCH 1/2] selftests/cgroup: Fix hardcoded page size in test_percpu_basic
@ 2026-03-06 7:18 Li Wang
2026-03-06 7:18 ` [PATCH 2/2] selftests/cgroup: include slab in test_percpu_basic memory check Li Wang
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Li Wang @ 2026-03-06 7:18 UTC (permalink / raw)
To: linux-kselftest, linux-kernel, akpm
Cc: Waiman Long, Christoph Lameter, Johannes Weiner, Michal Hocko,
Shakeel Butt, Tejun Heo, Vlastimil Babka
MAX_VMSTAT_ERROR uses a hardcoded page size of 4096, which assumes
4K pages. This causes test_percpu_basic to fail on systems where
the kernel is configured with a larger page size, such as aarch64
systems using 16K or 64K pages, where the maximum permissible
discrepancy between memory.current and percpu charges is
proportionally larger.
Replace the hardcoded 4096 with sysconf(_SC_PAGESIZE) to correctly
derive the page size at runtime regardless of the underlying
architecture or kernel configuration.
Signed-off-by: Li Wang <liwang@redhat.com>
Cc: Waiman Long <longman@redhat.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
---
tools/testing/selftests/cgroup/test_kmem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/cgroup/test_kmem.c b/tools/testing/selftests/cgroup/test_kmem.c
index eeabd34bf083..249d79113067 100644
--- a/tools/testing/selftests/cgroup/test_kmem.c
+++ b/tools/testing/selftests/cgroup/test_kmem.c
@@ -24,7 +24,7 @@
* the maximum discrepancy between charge and vmstat entries is number
* of cpus multiplied by 64 pages.
*/
-#define MAX_VMSTAT_ERROR (4096 * 64 * get_nprocs())
+#define MAX_VMSTAT_ERROR (sysconf(_SC_PAGESIZE) * 64 * get_nprocs())
#define KMEM_DEAD_WAIT_RETRIES 80
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/2] selftests/cgroup: include slab in test_percpu_basic memory check 2026-03-06 7:18 [PATCH 1/2] selftests/cgroup: Fix hardcoded page size in test_percpu_basic Li Wang @ 2026-03-06 7:18 ` Li Wang 2026-03-19 19:38 ` Waiman Long 2026-03-19 19:37 ` [PATCH 1/2] selftests/cgroup: Fix hardcoded page size in test_percpu_basic Waiman Long 2026-04-02 6:46 ` Li Wang 2 siblings, 1 reply; 5+ messages in thread From: Li Wang @ 2026-03-06 7:18 UTC (permalink / raw) To: linux-kselftest, linux-kernel, akpm Cc: Waiman Long, Christoph Lameter, Johannes Weiner, Michal Hocko, Shakeel Butt, Tejun Heo, Vlastimil Babka test_percpu_basic() currently compares memory.current against only memory.stat:percpu after creating 1000 child cgroups. Observed failure: #./test_kmem ok 1 test_kmem_basic ok 2 test_kmem_memcg_deletion ok 3 test_kmem_proc_kpagecgroup ok 4 test_kmem_kernel_stacks ok 5 test_kmem_dead_cgroups memory.current 11530240 percpu 8440000 not ok 6 test_percpu_basic That assumption is too strict: child cgroup creation also allocates slab-backed metadata, so memory.current is expected to be larger than percpu alone. One visible path is: cgroup_mkdir() cgroup_create() cgroup_addrm_file() cgroup_add_file() __kernfs_create_file() __kernfs_new_node() kmem_cache_zalloc() These kernfs allocations are charged as slab and show up in memory.stat:slab. Update the check to compare memory.current against (percpu + slab) within MAX_VMSTAT_ERROR, and print slab/delta in the failure message to improve diagnostics. Signed-off-by: Li Wang <liwang@redhat.com> Cc: Waiman Long <longman@redhat.com> Cc: Christoph Lameter <cl@linux.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Shakeel Butt <shakeelb@google.com> Cc: Tejun Heo <tj@kernel.org> Cc: Vlastimil Babka <vbabka@suse.cz> --- tools/testing/selftests/cgroup/test_kmem.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_kmem.c b/tools/testing/selftests/cgroup/test_kmem.c index 249d79113067..4b5799698893 100644 --- a/tools/testing/selftests/cgroup/test_kmem.c +++ b/tools/testing/selftests/cgroup/test_kmem.c @@ -353,7 +353,7 @@ static int test_percpu_basic(const char *root) { int ret = KSFT_FAIL; char *parent, *child; - long current, percpu; + long current, percpu, slab; int i; parent = cg_name(root, "percpu_basic_test"); @@ -379,13 +379,14 @@ static int test_percpu_basic(const char *root) current = cg_read_long(parent, "memory.current"); percpu = cg_read_key_long(parent, "memory.stat", "percpu "); + slab = cg_read_key_long(parent, "memory.stat", "slab "); - if (current > 0 && percpu > 0 && labs(current - percpu) < - MAX_VMSTAT_ERROR) + if (current > 0 && percpu > 0 && slab >= 0 && + labs(current - (percpu + slab)) < MAX_VMSTAT_ERROR) ret = KSFT_PASS; else - printf("memory.current %ld\npercpu %ld\n", - current, percpu); + printf("memory.current %ld\npercpu %ld\nslab %ld\ndelta %ld\n", + current, percpu, slab, current - (percpu + slab)); cleanup_children: for (i = 0; i < 1000; i++) { -- 2.53.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] selftests/cgroup: include slab in test_percpu_basic memory check 2026-03-06 7:18 ` [PATCH 2/2] selftests/cgroup: include slab in test_percpu_basic memory check Li Wang @ 2026-03-19 19:38 ` Waiman Long 0 siblings, 0 replies; 5+ messages in thread From: Waiman Long @ 2026-03-19 19:38 UTC (permalink / raw) To: Li Wang, linux-kselftest, linux-kernel, akpm Cc: Christoph Lameter, Johannes Weiner, Michal Hocko, Shakeel Butt, Tejun Heo, Vlastimil Babka On 3/6/26 2:18 AM, Li Wang wrote: > test_percpu_basic() currently compares memory.current against only > memory.stat:percpu after creating 1000 child cgroups. > > Observed failure: > #./test_kmem > ok 1 test_kmem_basic > ok 2 test_kmem_memcg_deletion > ok 3 test_kmem_proc_kpagecgroup > ok 4 test_kmem_kernel_stacks > ok 5 test_kmem_dead_cgroups > memory.current 11530240 > percpu 8440000 > not ok 6 test_percpu_basic > > That assumption is too strict: child cgroup creation also allocates > slab-backed metadata, so memory.current is expected to be larger than > percpu alone. One visible path is: > > cgroup_mkdir() > cgroup_create() > cgroup_addrm_file() > cgroup_add_file() > __kernfs_create_file() > __kernfs_new_node() > kmem_cache_zalloc() > > These kernfs allocations are charged as slab and show up in > memory.stat:slab. > > Update the check to compare memory.current against (percpu + slab) > within MAX_VMSTAT_ERROR, and print slab/delta in the failure message to > improve diagnostics. > > Signed-off-by: Li Wang <liwang@redhat.com> > Cc: Waiman Long <longman@redhat.com> > Cc: Christoph Lameter <cl@linux.com> > Cc: Johannes Weiner <hannes@cmpxchg.org> > Cc: Michal Hocko <mhocko@kernel.org> > Cc: Shakeel Butt <shakeelb@google.com> > Cc: Tejun Heo <tj@kernel.org> > Cc: Vlastimil Babka <vbabka@suse.cz> > --- > tools/testing/selftests/cgroup/test_kmem.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/tools/testing/selftests/cgroup/test_kmem.c b/tools/testing/selftests/cgroup/test_kmem.c > index 249d79113067..4b5799698893 100644 > --- a/tools/testing/selftests/cgroup/test_kmem.c > +++ b/tools/testing/selftests/cgroup/test_kmem.c > @@ -353,7 +353,7 @@ static int test_percpu_basic(const char *root) > { > int ret = KSFT_FAIL; > char *parent, *child; > - long current, percpu; > + long current, percpu, slab; > int i; > > parent = cg_name(root, "percpu_basic_test"); > @@ -379,13 +379,14 @@ static int test_percpu_basic(const char *root) > > current = cg_read_long(parent, "memory.current"); > percpu = cg_read_key_long(parent, "memory.stat", "percpu "); > + slab = cg_read_key_long(parent, "memory.stat", "slab "); > > - if (current > 0 && percpu > 0 && labs(current - percpu) < > - MAX_VMSTAT_ERROR) > + if (current > 0 && percpu > 0 && slab >= 0 && > + labs(current - (percpu + slab)) < MAX_VMSTAT_ERROR) > ret = KSFT_PASS; > else > - printf("memory.current %ld\npercpu %ld\n", > - current, percpu); > + printf("memory.current %ld\npercpu %ld\nslab %ld\ndelta %ld\n", > + current, percpu, slab, current - (percpu + slab)); > > cleanup_children: > for (i = 0; i < 1000; i++) { Reviewed-by: Waiman Long <longman@redhat.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] selftests/cgroup: Fix hardcoded page size in test_percpu_basic 2026-03-06 7:18 [PATCH 1/2] selftests/cgroup: Fix hardcoded page size in test_percpu_basic Li Wang 2026-03-06 7:18 ` [PATCH 2/2] selftests/cgroup: include slab in test_percpu_basic memory check Li Wang @ 2026-03-19 19:37 ` Waiman Long 2026-04-02 6:46 ` Li Wang 2 siblings, 0 replies; 5+ messages in thread From: Waiman Long @ 2026-03-19 19:37 UTC (permalink / raw) To: Li Wang, linux-kselftest, linux-kernel, akpm Cc: Christoph Lameter, Johannes Weiner, Michal Hocko, Shakeel Butt, Tejun Heo, Vlastimil Babka On 3/6/26 2:18 AM, Li Wang wrote: > MAX_VMSTAT_ERROR uses a hardcoded page size of 4096, which assumes > 4K pages. This causes test_percpu_basic to fail on systems where > the kernel is configured with a larger page size, such as aarch64 > systems using 16K or 64K pages, where the maximum permissible > discrepancy between memory.current and percpu charges is > proportionally larger. > > Replace the hardcoded 4096 with sysconf(_SC_PAGESIZE) to correctly > derive the page size at runtime regardless of the underlying > architecture or kernel configuration. > > Signed-off-by: Li Wang <liwang@redhat.com> > Cc: Waiman Long <longman@redhat.com> > Cc: Christoph Lameter <cl@linux.com> > Cc: Johannes Weiner <hannes@cmpxchg.org> > Cc: Michal Hocko <mhocko@kernel.org> > Cc: Shakeel Butt <shakeelb@google.com> > Cc: Tejun Heo <tj@kernel.org> > Cc: Vlastimil Babka <vbabka@suse.cz> > --- > tools/testing/selftests/cgroup/test_kmem.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/cgroup/test_kmem.c b/tools/testing/selftests/cgroup/test_kmem.c > index eeabd34bf083..249d79113067 100644 > --- a/tools/testing/selftests/cgroup/test_kmem.c > +++ b/tools/testing/selftests/cgroup/test_kmem.c > @@ -24,7 +24,7 @@ > * the maximum discrepancy between charge and vmstat entries is number > * of cpus multiplied by 64 pages. > */ > -#define MAX_VMSTAT_ERROR (4096 * 64 * get_nprocs()) > +#define MAX_VMSTAT_ERROR (sysconf(_SC_PAGESIZE) * 64 * get_nprocs()) > > #define KMEM_DEAD_WAIT_RETRIES 80 > That is the right change for now. However, I have sent out patches that change the way vmstats flush threshold is being computed, so it may need to be changed again in the future if the threshold is indeed updated. Anyway, Acked-by: Waiman Long <longman@redhat.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] selftests/cgroup: Fix hardcoded page size in test_percpu_basic 2026-03-06 7:18 [PATCH 1/2] selftests/cgroup: Fix hardcoded page size in test_percpu_basic Li Wang 2026-03-06 7:18 ` [PATCH 2/2] selftests/cgroup: include slab in test_percpu_basic memory check Li Wang 2026-03-19 19:37 ` [PATCH 1/2] selftests/cgroup: Fix hardcoded page size in test_percpu_basic Waiman Long @ 2026-04-02 6:46 ` Li Wang 2 siblings, 0 replies; 5+ messages in thread From: Li Wang @ 2026-04-02 6:46 UTC (permalink / raw) To: linux-kselftest, linux-kernel, akpm, mkoutny Cc: Waiman Long, Christoph Lameter, Johannes Weiner, Michal Hocko, Shakeel Butt, Tejun Heo, Vlastimil Babka Hello All, Gental ping~ Any more review comments will be appreciated! -- Regards, Li Wang ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-02 6:46 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-03-06 7:18 [PATCH 1/2] selftests/cgroup: Fix hardcoded page size in test_percpu_basic Li Wang 2026-03-06 7:18 ` [PATCH 2/2] selftests/cgroup: include slab in test_percpu_basic memory check Li Wang 2026-03-19 19:38 ` Waiman Long 2026-03-19 19:37 ` [PATCH 1/2] selftests/cgroup: Fix hardcoded page size in test_percpu_basic Waiman Long 2026-04-02 6:46 ` Li Wang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox