Skip to contentSkip to conversation

process_madvise01: running the test in mem_cg

PATCH In review Li Wang 2 participants 5 messages Nov 26, 2024 – Jan 3, 2025

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/1 process_madvise01: running the test in mem_cg

The MADV_PAGEOUT behavior in the kernel is advisory and may skip swapping if the system has sufficient free RAM, even when the advice is explicitly requested. This causes sporadic false positives in our CI, particularly on systems with large amounts of RAM:

process_madvise01.c:38: TINFO: Allocate memory: 1048576 bytes process_madvise01.c:99: TINFO: Reclaim memory using MADV_PAGEOUT process_madvise01.c:62: TFAIL: Expect: Most of the memory has been swapped out: 0kB out of 1024kB

To address this, the patch confines the test to a memory cgroup with configured limits for memory.max and memory.swap.max, improving control over memory and swap usage. This reduces the likelihood of false positives caused by system-wide memory conditions.

---
 .../syscalls/process_madvise/process_madvise01.c   | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/process_madvise/process_madvise01.c +12 -2
index 0fd3c1ef4..ca314c4da 100644
@@ -23,7 +23,9 @@
 #include "lapi/syscalls.h"
 #include "process_madvise.h"
 
-#define MEM_CHILD	(1 * TST_MB)
+#define MEM_LIMIT   (100 * TST_MB)
+#define MEMSW_LIMIT (200 * TST_MB)
+#define MEM_CHILD   (1   * TST_MB)
 
 static void **data_ptr;
 
@@ -67,6 +69,12 @@ static void child_alloc(void)
 
 static void setup(void)
 {
+	SAFE_CG_PRINTF(tst_cg, "memory.max", "%d", MEM_LIMIT);
+	if (SAFE_CG_HAS(tst_cg, "memory.swap.max"))
+		SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%d", MEMSW_LIMIT);
+
+	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
+
 	data_ptr = SAFE_MMAP(NULL, sizeof(void *),
 			PROT_READ | PROT_WRITE,
 			MAP_SHARED | MAP_ANONYMOUS, -1, 0);
@@ -123,7 +131,9 @@ static struct tst_test test = {
 	.min_kver = "5.10",
 	.needs_checkpoints = 1,
 	.needs_root = 1,
-	.min_swap_avail = MEM_CHILD / TST_MB,
+	.min_mem_avail = 2 * MEM_LIMIT / TST_MB,
+	.min_swap_avail = 2 * MEM_CHILD / TST_MB,
+	.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
 	.needs_kconfigs = (const char *[]) {
 		"CONFIG_SWAP=y",
 		NULL
Signature · 5 lines
2.47.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#1 lore raw

Hi Li,

Quoted 5 lines

The MADV_PAGEOUT behavior in the kernel is advisory and may skip swapping if the system has sufficient free RAM, even when the advice is explicitly requested. This causes sporadic false positives in our CI, particularly on systems with large amounts of RAM:

Quoted 8 lines

process_madvise01.c:38: TINFO: Allocate memory: 1048576 bytes process_madvise01.c:99: TINFO: Reclaim memory using MADV_PAGEOUT process_madvise01.c:62: TFAIL: Expect: Most of the memory has been swapped out: 0kB out of 1024kB

To address this, the patch confines the test to a memory cgroup with configured limits for memory.max and memory.swap.max, improving control over memory and swap usage. This reduces the likelihood of false positives caused by system-wide memory conditions.

Out of curiosity, on how many RAM does it fail? And is it arch specific?

...

Quoted 9 lines

+++ b/testcases/kernel/syscalls/process_madvise/process_madvise01.c

testcases/kernel/syscalls/process_madvise/process_madvise01.c +3 -1
@@ -23,7 +23,9 @@
 #include "lapi/syscalls.h"
 #include "process_madvise.h"
 
-#define MEM_CHILD	(1 * TST_MB)
+#define MEM_LIMIT   (100 * TST_MB)
+#define MEMSW_LIMIT (200 * TST_MB)
+#define MEM_CHILD   (1   * TST_MB)

...

testcases/kernel/syscalls/process_madvise/process_madvise01.c static struct tst_test test = { · line 134

Quoted 6 lines
testcases/kernel/syscalls/process_madvise/process_madvise01.c +1 -1
@@ -123,7 +131,9 @@ static struct tst_test test = {
 	.min_kver = "5.10",
 	.needs_checkpoints = 1,
 	.needs_root = 1,
-	.min_swap_avail = MEM_CHILD / TST_MB,
+	.min_mem_avail = 2 * MEM_LIMIT / TST_MB,

Requiring 200 MB for test looks LGTM.

Kind regards,
Petr

Quoted 2 lines
testcases/kernel/syscalls/process_madvise/process_madvise01.c +2 -0
+	.min_swap_avail = 2 * MEM_CHILD / TST_MB,
+	.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#2 lore raw
Quoted 10 lines · Petr Vorel

Hi Li,

Quoted 8 lines

The MADV_PAGEOUT behavior in the kernel is advisory and may skip swapping if the system has sufficient free RAM, even when the advice is explicitly requested. This causes sporadic false positives in our CI, particularly on systems with large amounts of RAM:

process_madvise01.c:38: TINFO: Allocate memory: 1048576 bytes process_madvise01.c:99: TINFO: Reclaim memory using MADV_PAGEOUT process_madvise01.c:62: TFAIL: Expect: Most of the memory has been

Quoted 10 lines

swapped out: 0kB out of 1024kB

Quoted 4 lines

To address this, the patch confines the test to a memory cgroup with configured limits for memory.max and memory.swap.max, improving control over memory and swap usage. This reduces the likelihood of false positives caused by system-wide memory conditions.

Out of curiosity, on how many RAM does it fail? And is it arch specific?

Ah, I completely forgot the context of this patch, my memory is bad now :/.

Quoted 19 lines

...

Quoted 9 lines

+++ b/testcases/kernel/syscalls/process_madvise/process_madvise01.c

testcases/kernel/syscalls/process_madvise/process_madvise01.c +3 -1
@@ -23,7 +23,9 @@
 #include "lapi/syscalls.h"
 #include "process_madvise.h"
 
-#define MEM_CHILD    (1 * TST_MB)
+#define MEM_LIMIT   (100 * TST_MB)
+#define MEMSW_LIMIT (200 * TST_MB)
+#define MEM_CHILD   (1   * TST_MB)

...

testcases/kernel/syscalls/process_madvise/process_madvise01.c static struct tst_test test = { · line 134

Quoted 6 lines
testcases/kernel/syscalls/process_madvise/process_madvise01.c +1 -1
@@ -123,7 +131,9 @@ static struct tst_test test = {
      .min_kver = "5.10",
      .needs_checkpoints = 1,
      .needs_root = 1,
-     .min_swap_avail = MEM_CHILD / TST_MB,
+     .min_mem_avail = 2 * MEM_LIMIT / TST_MB,

Requiring 200 MB for test looks LGTM.

Quoted 2 lines

Thanks for the review, after reading the patch summary I guess it still makes sense to apply it, since MADV_PAGEOUT is indeed not a mandatory option and still may ignored by kernel in the test.

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi Li,

...

Quoted 3 lines

Thanks for the review, after reading the patch summary I guess it still makes sense to apply it, since MADV_PAGEOUT is indeed not a mandatory option and still may ignored by kernel in the test.

Sure, please go ahead and merge the patchset.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author Applied
#4 lore raw
Quoted 9 lines · Petr Vorel

Hi Li,

...

Quoted 3 lines

Thanks for the review, after reading the patch summary I guess it still makes sense to apply it, since MADV_PAGEOUT is indeed not a mandatory option and still may ignored by kernel in the test.

Sure, please go ahead and merge the patchset.

Merged, thanks!

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp