* [LTP] [PATCH v2] memcg/functional: fix memcg_failcnt intermittent timeout by disabling swap
@ 2026-08-05 6:40 Xuewen Wang
2026-08-05 7:34 ` Li Wang
2026-08-05 7:40 ` [LTP] " linuxtestproject.agent
0 siblings, 2 replies; 4+ messages in thread
From: Xuewen Wang @ 2026-08-05 6:40 UTC (permalink / raw)
To: ltp; +Cc: liwang, Xuewen Wang, rpalethorpe
memcg_failcnt.sh tests the memory.failcnt counter by allocating
reclaimable memory (mmap-anon/mmap-file/shm) beyond a tiny cgroup
limit (1 page). It relies on the process being OOM-killed so that
signal_memcg_process()'s wait loop exits.
With swap enabled the kernel usually still OOM-kills the process,
but on arm64 reclaim (swap out) sometimes succeeds instead:
usage_in_bytes stays at the limit and the process keeps running,
so the wait loop times out (TBROK) intermittently.
Example failure on arm64 (kernel 6.6):
memcg_failcnt 2 TBROK: timed out on memory.usage_in_bytes 4096 0 8192
Disable swap around the allocation and re-enable it afterwards,
mirroring what memcg_limit_in_bytes.sh already does for the same
reclaimable memory types.
Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn>
---
Changes in v2:
- Drop "2>/dev/null" from swapoff/swapon so that a failure to disable
swap (or a missing swapoff binary) stays visible, instead of silently
letting the intermittent timeout recur. Per the LTP AI review, the
redirect hid the very error this fix relies on, and
memcg_limit_in_bytes.sh does not redirect stderr either.
---
.../controllers/memcg/functional/memcg_failcnt.sh | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_failcnt.sh b/testcases/kernel/controllers/memcg/functional/memcg_failcnt.sh
index 3a02d16c2..9ac3880f6 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_failcnt.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_failcnt.sh
@@ -11,11 +11,20 @@
MEMCG_TESTFUNC=do_test
MEMCG_SHMMAX=1
TST_TEST_DATA="--mmap-anon --mmap-file --shm"
+TST_CLEANUP=do_cleanup
+
+do_cleanup()
+{
+ memcg_cleanup
+ swapon -a
+}
do_test()
{
ROD echo $MEMORY_LIMIT \> memory.limit_in_bytes
+ swapoff -a
+
start_memcg_process $2 -s ${MEMORY_TO_ALLOCATE}
ROD echo $MEMCG_PROCESS_PID \> tasks
@@ -24,6 +33,8 @@ do_test()
stop_memcg_process
+ swapon -a
+
failcnt=$(cat memory.failcnt)
if [ $failcnt -gt 0 ]; then
tst_res TPASS "memory.failcnt is $failcnt, > 0 as expected"
--
2.25.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [LTP] [PATCH v2] memcg/functional: fix memcg_failcnt intermittent timeout by disabling swap
2026-08-05 6:40 [LTP] [PATCH v2] memcg/functional: fix memcg_failcnt intermittent timeout by disabling swap Xuewen Wang
@ 2026-08-05 7:34 ` Li Wang
2026-08-07 2:00 ` Xuewen Wang
2026-08-05 7:40 ` [LTP] " linuxtestproject.agent
1 sibling, 1 reply; 4+ messages in thread
From: Li Wang @ 2026-08-05 7:34 UTC (permalink / raw)
To: Xuewen Wang; +Cc: ltp, liwang
Hi Xuewen,
Xuewen Wang wrote:
> memcg_failcnt.sh tests the memory.failcnt counter by allocating
> reclaimable memory (mmap-anon/mmap-file/shm) beyond a tiny cgroup
> limit (1 page). It relies on the process being OOM-killed so that
> signal_memcg_process()'s wait loop exits.
>
> With swap enabled the kernel usually still OOM-kills the process,
> but on arm64 reclaim (swap out) sometimes succeeds instead:
> usage_in_bytes stays at the limit and the process keeps running,
> so the wait loop times out (TBROK) intermittently.
>
> Example failure on arm64 (kernel 6.6):
> memcg_failcnt 2 TBROK: timed out on memory.usage_in_bytes 4096 0 8192
>
> Disable swap around the allocation and re-enable it afterwards,
> mirroring what memcg_limit_in_bytes.sh already does for the same
> reclaimable memory types.
This fix make sense, but I'd rather go with a tidy way:
...
TST_SETUP=do_setup
TST_CLEANUP=do_cleanup
do_setup()
{
memcg_setup
swapoff -a
}
do_cleanup()
{
swapon -a
memcg_cleanup
}
...
My Red Hat email address is no longer used. Please CC my new
address for future versions:
li.wang@linux.dev
or:
liwang@hygon.cn
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [LTP] [PATCH v2] memcg/functional: fix memcg_failcnt intermittent timeout by disabling swap
2026-08-05 7:34 ` Li Wang
@ 2026-08-07 2:00 ` Xuewen Wang
0 siblings, 0 replies; 4+ messages in thread
From: Xuewen Wang @ 2026-08-07 2:00 UTC (permalink / raw)
To: ltp, liwang
Hi Li Wang,
Thank you for the review and the suggestions. I've sent v3 with the changes you proposed:
- Move swapoff to do_setup() and swapon to do_cleanup()
- Adjust the order in do_cleanup() to swapon first, then memcg_cleanup
Please take a look when you have time.
Best regards,
Xuewen Wang
在 2026/8/5 15:34, Li Wang 写道:
> Hi Xuewen,
>
> Xuewen Wang wrote:
>
>> memcg_failcnt.sh tests the memory.failcnt counter by allocating
>> reclaimable memory (mmap-anon/mmap-file/shm) beyond a tiny cgroup
>> limit (1 page). It relies on the process being OOM-killed so that
>> signal_memcg_process()'s wait loop exits.
>>
>> With swap enabled the kernel usually still OOM-kills the process,
>> but on arm64 reclaim (swap out) sometimes succeeds instead:
>> usage_in_bytes stays at the limit and the process keeps running,
>> so the wait loop times out (TBROK) intermittently.
>>
>> Example failure on arm64 (kernel 6.6):
>> memcg_failcnt 2 TBROK: timed out on memory.usage_in_bytes 4096 0 8192
>>
>> Disable swap around the allocation and re-enable it afterwards,
>> mirroring what memcg_limit_in_bytes.sh already does for the same
>> reclaimable memory types.
>
> This fix make sense, but I'd rather go with a tidy way:
>
> ...
> TST_SETUP=do_setup
> TST_CLEANUP=do_cleanup
>
> do_setup()
> {
> memcg_setup
> swapoff -a
> }
>
> do_cleanup()
> {
> swapon -a
> memcg_cleanup
> }
>
> ...
>
> My Red Hat email address is no longer used. Please CC my new
> address for future versions:
>
> li.wang@linux.dev
> or:
> liwang@hygon.cn
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] memcg/functional: fix memcg_failcnt intermittent timeout by disabling swap
2026-08-05 6:40 [LTP] [PATCH v2] memcg/functional: fix memcg_failcnt intermittent timeout by disabling swap Xuewen Wang
2026-08-05 7:34 ` Li Wang
@ 2026-08-05 7:40 ` linuxtestproject.agent
1 sibling, 0 replies; 4+ messages in thread
From: linuxtestproject.agent @ 2026-08-05 7:40 UTC (permalink / raw)
To: Xuewen Wang; +Cc: ltp
Hi Xuewen,
On Aug 5, 2026, Xuewen Wang wrote:
> memcg/functional: fix memcg_failcnt intermittent timeout by disabling swap
> +TST_CLEANUP=do_cleanup
> +
> +do_cleanup()
> +{
> + memcg_cleanup
> + swapon -a
> +}
Could the test save and restore the initially active swap areas instead?
`swapon -a` does not restore the original state: an active area absent from
fstab, such as zram, remains disabled, while an fstab area that was initially
disabled may be enabled. The cleanup also runs if setup exits before
`swapoff -a`, so that path can enable swap without the test disabling it.
> + swapoff -a
Could `swapon` and `swapoff` be declared in `TST_NEEDS_CMDS`, and could this
invocation abort on failure? A bare command failure is ignored by the shell
library, so a missing command or a failure to move swapped pages back to RAM
allows the allocation to proceed with swap still active and preserves the
timeout this patch is intended to fix. Failures while restoring swap should
also be reported.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-07 2:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05 6:40 [LTP] [PATCH v2] memcg/functional: fix memcg_failcnt intermittent timeout by disabling swap Xuewen Wang
2026-08-05 7:34 ` Li Wang
2026-08-07 2:00 ` Xuewen Wang
2026-08-05 7:40 ` [LTP] " linuxtestproject.agent
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox