* [PATCH v2] selftests: cgroup: fix test_kmem_memcg_deletion kernel mem check
@ 2023-08-17 12:47 Lucas Karpinski
2023-08-17 17:07 ` Shakeel Butt
0 siblings, 1 reply; 3+ messages in thread
From: Lucas Karpinski @ 2023-08-17 12:47 UTC (permalink / raw)
To: Andrew Morton, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, Tejun Heo, Zefan Li, Shuah Khan
Cc: Muchun Song, cgroups, linux-mm, linux-kselftest, linux-kernel
The combination of using slab, anon, file, kernel_stack, and percpu is
not accurate for total kernel memory utilization. Checking kernel within
memory.stat provides a more accurate measurement.
Signed-off-by: Lucas Karpinski <lkarpins@redhat.com>
---
v1: https://lore.kernel.org/all/eex2vdlg4ow2j5bybmav73nbfzuspkk4zobnk7svua4jaypqb5@7ie6e4mci43t/
tools/testing/selftests/cgroup/test_kmem.c | 25 +++++-----------------
1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/tools/testing/selftests/cgroup/test_kmem.c b/tools/testing/selftests/cgroup/test_kmem.c
index ed2e50bb1e76..3ef979ee0edf 100644
--- a/tools/testing/selftests/cgroup/test_kmem.c
+++ b/tools/testing/selftests/cgroup/test_kmem.c
@@ -166,7 +166,7 @@ static int cg_run_in_subcgroups(const char *parent,
*/
static int test_kmem_memcg_deletion(const char *root)
{
- long current, slab, anon, file, kernel_stack, pagetables, percpu, sock, sum;
+ long current, kernel;
int ret = KSFT_FAIL;
char *parent;
@@ -184,30 +184,15 @@ static int test_kmem_memcg_deletion(const char *root)
goto cleanup;
current = cg_read_long(parent, "memory.current");
- slab = cg_read_key_long(parent, "memory.stat", "slab ");
- anon = cg_read_key_long(parent, "memory.stat", "anon ");
- file = cg_read_key_long(parent, "memory.stat", "file ");
- kernel_stack = cg_read_key_long(parent, "memory.stat", "kernel_stack ");
- pagetables = cg_read_key_long(parent, "memory.stat", "pagetables ");
- percpu = cg_read_key_long(parent, "memory.stat", "percpu ");
- sock = cg_read_key_long(parent, "memory.stat", "sock ");
- if (current < 0 || slab < 0 || anon < 0 || file < 0 ||
- kernel_stack < 0 || pagetables < 0 || percpu < 0 || sock < 0)
+ kernel = cg_read_key_long(parent, "memory.stat", "kernel ");
+ if (current < 0 || kernel < 0)
goto cleanup;
- sum = slab + anon + file + kernel_stack + pagetables + percpu + sock;
- if (abs(sum - current) < MAX_VMSTAT_ERROR) {
+ if (abs(kernel - current) < MAX_VMSTAT_ERROR) {
ret = KSFT_PASS;
} else {
printf("memory.current = %ld\n", current);
- printf("slab + anon + file + kernel_stack = %ld\n", sum);
- printf("slab = %ld\n", slab);
- printf("anon = %ld\n", anon);
- printf("file = %ld\n", file);
- printf("kernel_stack = %ld\n", kernel_stack);
- printf("pagetables = %ld\n", pagetables);
- printf("percpu = %ld\n", percpu);
- printf("sock = %ld\n", sock);
+ printf("kernel = %ld\n", kernel);
}
cleanup:
--
2.41.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] selftests: cgroup: fix test_kmem_memcg_deletion kernel mem check
2023-08-17 12:47 [PATCH v2] selftests: cgroup: fix test_kmem_memcg_deletion kernel mem check Lucas Karpinski
@ 2023-08-17 17:07 ` Shakeel Butt
2023-08-17 18:11 ` Lucas Karpinski
0 siblings, 1 reply; 3+ messages in thread
From: Shakeel Butt @ 2023-08-17 17:07 UTC (permalink / raw)
To: Lucas Karpinski
Cc: Andrew Morton, Johannes Weiner, Michal Hocko, Roman Gushchin,
Muchun Song, Tejun Heo, Zefan Li, Shuah Khan, cgroups, linux-mm,
linux-kselftest, linux-kernel
On Thu, Aug 17, 2023 at 08:47:26AM -0400, Lucas Karpinski wrote:
> The combination of using slab, anon, file, kernel_stack, and percpu is
> not accurate for total kernel memory utilization. Checking kernel within
> memory.stat provides a more accurate measurement.
>
> Signed-off-by: Lucas Karpinski <lkarpins@redhat.com>
> ---
> v1: https://lore.kernel.org/all/eex2vdlg4ow2j5bybmav73nbfzuspkk4zobnk7svua4jaypqb5@7ie6e4mci43t/
>
> tools/testing/selftests/cgroup/test_kmem.c | 25 +++++-----------------
> 1 file changed, 5 insertions(+), 20 deletions(-)
>
> diff --git a/tools/testing/selftests/cgroup/test_kmem.c b/tools/testing/selftests/cgroup/test_kmem.c
> index ed2e50bb1e76..3ef979ee0edf 100644
> --- a/tools/testing/selftests/cgroup/test_kmem.c
> +++ b/tools/testing/selftests/cgroup/test_kmem.c
> @@ -166,7 +166,7 @@ static int cg_run_in_subcgroups(const char *parent,
> */
> static int test_kmem_memcg_deletion(const char *root)
> {
> - long current, slab, anon, file, kernel_stack, pagetables, percpu, sock, sum;
> + long current, kernel;
> int ret = KSFT_FAIL;
> char *parent;
>
> @@ -184,30 +184,15 @@ static int test_kmem_memcg_deletion(const char *root)
> goto cleanup;
>
> current = cg_read_long(parent, "memory.current");
> - slab = cg_read_key_long(parent, "memory.stat", "slab ");
> - anon = cg_read_key_long(parent, "memory.stat", "anon ");
> - file = cg_read_key_long(parent, "memory.stat", "file ");
> - kernel_stack = cg_read_key_long(parent, "memory.stat", "kernel_stack ");
> - pagetables = cg_read_key_long(parent, "memory.stat", "pagetables ");
> - percpu = cg_read_key_long(parent, "memory.stat", "percpu ");
> - sock = cg_read_key_long(parent, "memory.stat", "sock ");
> - if (current < 0 || slab < 0 || anon < 0 || file < 0 ||
> - kernel_stack < 0 || pagetables < 0 || percpu < 0 || sock < 0)
> + kernel = cg_read_key_long(parent, "memory.stat", "kernel ");
> + if (current < 0 || kernel < 0)
> goto cleanup;
>
> - sum = slab + anon + file + kernel_stack + pagetables + percpu + sock;
> - if (abs(sum - current) < MAX_VMSTAT_ERROR) {
> + if (abs(kernel - current) < MAX_VMSTAT_ERROR) {
I don't think this is what you want. Since slab, kernel_stack,
pagetables and percpu are included in the kmem stats, you just want to
replace those with kmem. Basically keep the anon, file and sock stats.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] selftests: cgroup: fix test_kmem_memcg_deletion kernel mem check
2023-08-17 17:07 ` Shakeel Butt
@ 2023-08-17 18:11 ` Lucas Karpinski
0 siblings, 0 replies; 3+ messages in thread
From: Lucas Karpinski @ 2023-08-17 18:11 UTC (permalink / raw)
To: Shakeel Butt
Cc: Andrew Morton, Johannes Weiner, Michal Hocko, Roman Gushchin,
Muchun Song, Tejun Heo, Zefan Li, Shuah Khan, cgroups, linux-mm,
linux-kselftest, linux-kernel
On Thu, Aug 17, 2023 at 05:07:02PM +0000, Shakeel Butt wrote:
> On Thu, Aug 17, 2023 at 08:47:26AM -0400, Lucas Karpinski wrote:
> > The combination of using slab, anon, file, kernel_stack, and percpu is
> > not accurate for total kernel memory utilization. Checking kernel within
> > memory.stat provides a more accurate measurement.
> >
> > Signed-off-by: Lucas Karpinski <lkarpins@redhat.com>
> > ---
> > v1: https://lore.kernel.org/all/eex2vdlg4ow2j5bybmav73nbfzuspkk4zobnk7svua4jaypqb5@7ie6e4mci43t/
> >
> > tools/testing/selftests/cgroup/test_kmem.c | 25 +++++-----------------
> > 1 file changed, 5 insertions(+), 20 deletions(-)
> >
> > diff --git a/tools/testing/selftests/cgroup/test_kmem.c b/tools/testing/selftests/cgroup/test_kmem.c
> > index ed2e50bb1e76..3ef979ee0edf 100644
> > --- a/tools/testing/selftests/cgroup/test_kmem.c
> > +++ b/tools/testing/selftests/cgroup/test_kmem.c
> > @@ -166,7 +166,7 @@ static int cg_run_in_subcgroups(const char *parent,
> > */
> > static int test_kmem_memcg_deletion(const char *root)
> > {
> > - long current, slab, anon, file, kernel_stack, pagetables, percpu, sock, sum;
> > + long current, kernel;
> > int ret = KSFT_FAIL;
> > char *parent;
> >
> > @@ -184,30 +184,15 @@ static int test_kmem_memcg_deletion(const char *root)
> > goto cleanup;
> >
> > current = cg_read_long(parent, "memory.current");
> > - slab = cg_read_key_long(parent, "memory.stat", "slab ");
> > - anon = cg_read_key_long(parent, "memory.stat", "anon ");
> > - file = cg_read_key_long(parent, "memory.stat", "file ");
> > - kernel_stack = cg_read_key_long(parent, "memory.stat", "kernel_stack ");
> > - pagetables = cg_read_key_long(parent, "memory.stat", "pagetables ");
> > - percpu = cg_read_key_long(parent, "memory.stat", "percpu ");
> > - sock = cg_read_key_long(parent, "memory.stat", "sock ");
> > - if (current < 0 || slab < 0 || anon < 0 || file < 0 ||
> > - kernel_stack < 0 || pagetables < 0 || percpu < 0 || sock < 0)
> > + kernel = cg_read_key_long(parent, "memory.stat", "kernel ");
> > + if (current < 0 || kernel < 0)
> > goto cleanup;
> >
> > - sum = slab + anon + file + kernel_stack + pagetables + percpu + sock;
> > - if (abs(sum - current) < MAX_VMSTAT_ERROR) {
> > + if (abs(kernel - current) < MAX_VMSTAT_ERROR) {
>
> I don't think this is what you want. Since slab, kernel_stack,
> pagetables and percpu are included in the kmem stats, you just want to
> replace those with kmem. Basically keep the anon, file and sock stats.
>
Will fix and send new patch version.
Thanks,
Lucas
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-17 18:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-17 12:47 [PATCH v2] selftests: cgroup: fix test_kmem_memcg_deletion kernel mem check Lucas Karpinski
2023-08-17 17:07 ` Shakeel Butt
2023-08-17 18:11 ` Lucas Karpinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox