madvise09: restore cgroup v1 memory limits with numeric values
PATCH v2 1/2 madvise09: restore cgroup v1 memory limits with numeric values
From: Li Wang <[email protected]>
madvise09 resets memory.max and memory.swap.max to "max" before retrying the child process, so the retried child does not inherit the strict memory limits from the previous run.
This works for cgroup v2, where "max" is the valid unlimited value. However, cgroup v1 memory.limit_in_bytes does not accept the string "max". When the LTP cgroup abstraction maps memory.max to the v1 memory limit knob, writing "max" can fail with EINVAL:
tst_test.c:1875: TINFO: Overall timeout per run is 0h 00m 30s madvise09.c:154: TBROK: vdprintf(18</sys/fs/cgroup/memory/ltp/test-27493>,
'memory.limit_in_bytes', '%s'<max>): EINVAL (22)
tst_test.c:478: TINFO: Child process reported TBROK killing the test tst_test.c:1938: TINFO: Killed the leftover descendant processes
Save the original cgroup v1 memory and swap limits during setup and restore those numeric values on retry. Keep using "max" for cgroup v2.
---
Notes:
v1 -> v2:
- Rename saved limit variables from ori_* to orig_*.
- Restore v1 memsw limit before memory limit when raising limits on retry.
- Update the retry reset comment for both v1 and v2.
testcases/kernel/syscalls/madvise/madvise09.c | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/madvise/madvise09.c +27 -8
@@ -54,8 +54,8 @@ static int swap_accounting_enabled;#define TOUCHED_PAGE1 0#define TOUCHED_PAGE2 10 -static long long mem_limit; -static long long swap_limit; +static long long mem_limit, orig_mem_limit; +static long long swap_limit, orig_swap_limit;static void memory_pressure_child (void ) {
@@ -147,13 +147,25 @@ static void child(void)SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ());/* -* Reset cgroup memory limits to default ("max") in case this is a retry run. +* Reset cgroup memory limits in case this is a retry run. +* For cgroup v2, restore the default "max". For cgroup v1, restore the +* saved numeric limits, raising memsw before memory to keep the v1 +* memory <= memsw invariant. +* * Otherwise, the retried child inherits the strict MEM_LIMIT from the previous * run, causing MADV_FREE pages to be dropped immediately before we touch them. */ -SAFE_CG_PRINT (tst_cg,"memory.max" ,"max" ); -if (swap_accounting_enabled) -SAFE_CG_PRINT (tst_cg,"memory.swap.max" ,"max" ); +if (TST_CG_VER_IS_V1 (tst_cg,"memory" )) { +if (swap_accounting_enabled) +SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lld" , orig_swap_limit); + +SAFE_CG_PRINTF (tst_cg,"memory.max" ,"%lld" , orig_mem_limit); + }else { +SAFE_CG_PRINT (tst_cg,"memory.max" ,"max" ); + +if (swap_accounting_enabled) +SAFE_CG_PRINT (tst_cg,"memory.swap.max" ,"max" ); + } ptr =SAFE_MMAP (NULL ,PAGES * page_size,PROT_READ |PROT_WRITE ,MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 );
@@ -278,10 +290,17 @@ retry:static void setup (void ) { -if (SAFE_CG_HAS (tst_cg,"memory.swap.max" )) +if (TST_CG_VER_IS_V1 (tst_cg,"memory" )) +SAFE_CG_SCANF (tst_cg,"memory.max" ,"%lld" , &orig_mem_limit); + +if (SAFE_CG_HAS (tst_cg,"memory.swap.max" )) { swap_accounting_enabled =1 ; -else + +if (TST_CG_VER_IS_V1 (tst_cg,"memory" )) +SAFE_CG_SCANF (tst_cg,"memory.swap.max" ,"%lld" , &orig_swap_limit); + }else {tst_res (TINFO ,"Swap accounting is disabled" ); + } page_size =getpagesize ();
Signature · 5 lines
2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/2 mailmap: map [email protected] to my primary address
From: Li Wang <[email protected]>
Add [email protected], my new company email address at Hygon, to .mailmap and map it to my primary address, [email protected].
I may use the Hygon address for Signed-off-by tags to give credit to the company, while continuing to use [email protected] as my primary address for Linux/LTP communication and reviews.
--- .mailmap | 1 + 1 file changed, 1 insertion(+)
.mailmap +1 -0
@@ -1,3 +1,4 @@ +Li Wang <[email protected]> <[email protected]> Li Wang <[email protected]> <[email protected]> Li Wang <[email protected]> <[email protected]> Petr Vorel <[email protected]> <[email protected]>
Signature · 5 lines
2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Li,
Quoted 1 line · Li Wang
madvise09: restore cgroup v1 memory limits with numeric values
Verdict - Reviewed
---
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
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Patch set merged, thanks!
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp