From: Sebastian Chlad <sebastianchlad@gmail.com>
To: "Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Shuah Khan" <shuah@kernel.org>
Cc: Sebastian Chlad <sebastian.chlad@suse.com>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
cgroups@vger.kernel.org, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/2] selftests: cgroup: Use values_close_report in test_memcontrol
Date: Sat, 26 Sep 2026 07:51:47 +0200 [thread overview]
Message-ID: <20260926055152.1684-2-sebastian.chlad@suse.com> (raw)
In-Reply-To: <20260926055152.1684-1-sebastian.chlad@suse.com>
Convert the terminal tolerance checks in test_memcontrol to
values_close_report() so that a failure prints the observed and
expected values instead of failing silently. Also report the
"memory.current < size" check in alloc_anon_50M_check().
values_close() is kept where it is used as a loop or retry condition
(waiting for usage to settle in test_memcg_protection(), reclaim_until(),
the reclaim retry loop and the socket test), since a mismatch there is
expected and reporting it would print spurious failures.
Assisted-by: claude-opus-5-5
Signed-off-by: Sebastian Chlad <sebastian.chlad@suse.com>
---
.../selftests/cgroup/test_memcontrol.c | 25 +++++++++++--------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c
index 0ed82347044e..8882c7faeb32 100644
--- a/tools/testing/selftests/cgroup/test_memcontrol.c
+++ b/tools/testing/selftests/cgroup/test_memcontrol.c
@@ -200,17 +200,20 @@ static int alloc_anon_50M_check(const char *cgroup, void *arg)
return -1;
current = cg_read_long(cgroup, "memory.current");
- if (current < size)
+ if (current < size) {
+ fprintf(stderr, "memory.current %ld < expected %zu\n",
+ current, size);
goto cleanup;
+ }
- if (!values_close(size, current, 3))
+ if (!values_close_report(current, size, 3))
goto cleanup;
anon = cg_read_key_long(cgroup, "memory.stat", "anon ");
if (anon < 0)
goto cleanup;
- if (!values_close(anon, current, 3))
+ if (!values_close_report(anon, current, 3))
goto cleanup;
ret = 0;
@@ -241,7 +244,7 @@ static int alloc_pagecache_50M_check(const char *cgroup, void *arg)
if (file < 0)
goto cleanup;
- if (!values_close(file, current, 10))
+ if (!values_close_report(file, current, 10))
goto cleanup;
ret = 0;
@@ -578,16 +581,16 @@ static int test_memcg_protection(const char *root, bool min)
if (cg_run(parent[2], alloc_anon, (void *)MB(148)))
goto cleanup;
- if (!values_close(cg_read_long(parent[1], "memory.current"), MB(50), 3))
+ if (!values_close_report(cg_read_long(parent[1], "memory.current"), MB(50), 3))
goto cleanup;
for (i = 0; i < ARRAY_SIZE(children); i++)
c[i] = cg_read_long(children[i], "memory.current");
- if (!values_close(c[0], MB(29), 15))
+ if (!values_close_report(c[0], MB(29), 15))
goto cleanup;
- if (!values_close(c[1], MB(21), 20))
+ if (!values_close_report(c[1], MB(21), 20))
goto cleanup;
if (c[3] != 0)
@@ -603,7 +606,7 @@ static int test_memcg_protection(const char *root, bool min)
}
current = min ? MB(50) : MB(30);
- if (!values_close(cg_read_long(parent[1], "memory.current"), current, 3))
+ if (!values_close_report(cg_read_long(parent[1], "memory.current"), current, 3))
goto cleanup;
if (!reclaim_until(children[0], MB(10)))
@@ -691,7 +694,7 @@ static int alloc_pagecache_max_30M(const char *cgroup, void *arg)
goto cleanup;
current = cg_read_long(cgroup, "memory.current");
- if (!values_close(current, MB(30), 5))
+ if (!values_close_report(current, MB(30), 5))
goto cleanup;
ret = 0;
@@ -1006,12 +1009,12 @@ static int alloc_anon_50M_check_swap(const char *cgroup, void *arg)
return -1;
mem_current = cg_read_long(cgroup, "memory.current");
- if (!mem_current || !values_close(mem_current, mem_max, 3))
+ if (!mem_current || !values_close_report(mem_current, mem_max, 3))
goto cleanup;
swap_current = cg_read_long(cgroup, "memory.swap.current");
if (!swap_current ||
- !values_close(mem_current + swap_current, size, 3))
+ !values_close_report(mem_current + swap_current, size, 3))
goto cleanup;
ret = 0;
--
2.51.0
next prev parent reply other threads:[~2026-09-26 5:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 5:51 [PATCH v2 0/2] selftests: cgroup: Report failed checks " Sebastian Chlad
2026-09-26 5:51 ` Sebastian Chlad [this message]
2026-09-26 5:51 ` [PATCH v2 2/2] selftests: cgroup: Report memory.current shortfall in alloc_pagecache_50M_check Sebastian Chlad
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260926055152.1684-2-sebastian.chlad@suse.com \
--to=sebastianchlad@gmail.com \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=sebastian.chlad@suse.com \
--cc=shakeel.butt@linux.dev \
--cc=shuah@kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®