public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] process_madvise01: running the test in mem_cg
Date: Tue, 26 Nov 2024 16:58:08 +0800	[thread overview]
Message-ID: <20241126085808.14616-1-liwang@redhat.com> (raw)

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.

Signed-off-by: Li Wang <liwang@redhat.com>
---
 .../syscalls/process_madvise/process_madvise01.c   | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/process_madvise/process_madvise01.c b/testcases/kernel/syscalls/process_madvise/process_madvise01.c
index 0fd3c1ef4..ca314c4da 100644
--- a/testcases/kernel/syscalls/process_madvise/process_madvise01.c
+++ b/testcases/kernel/syscalls/process_madvise/process_madvise01.c
@@ -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
-- 
2.47.0


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

             reply	other threads:[~2024-11-26  8:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-26  8:58 Li Wang [this message]
2025-01-02 14:59 ` [LTP] [PATCH] process_madvise01: running the test in mem_cg Petr Vorel
2025-01-03  8:35   ` Li Wang
2025-01-03  8:50     ` Petr Vorel
2025-01-03  9:36       ` Li Wang

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=20241126085808.14616-1-liwang@redhat.com \
    --to=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /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