From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v1] madvise09: Scale cgroup memory/swap limits dynamically with page size
Date: Thu, 23 Jul 2026 07:53:15 +0000 [thread overview]
Message-ID: <20260723075319.4920-1-wegao@suse.com> (raw)
On systems with 64KB page size (such as ppc64le), the mapped footprint
of PAGES (128) is 128 * 64KB = 8MB. Since the cgroup MEM_LIMIT was
hardcoded to 8MB, there was zero headroom left for the parent's process
overhead, resulting in OOM when trying to fork the memory pressure
process.
This caused the test to enter an infinite "Both children killed,
retrying..." loop.
Fix this by scaling mem_limit and swap_limit dynamically based on the
system page size at runtime. Also add a dynamic swap availability check
in setup() using tst_available_swap() to skip gracefully on machines
lacking sufficient swap space, and define BASE_SWAP_LIMIT for the static
.min_swap_avail check.
Signed-off-by: Wei Gao <wegao@suse.com>
---
testcases/kernel/syscalls/madvise/madvise09.c | 24 +++++++++++++------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/testcases/kernel/syscalls/madvise/madvise09.c b/testcases/kernel/syscalls/madvise/madvise09.c
index 5453f9411..567782896 100644
--- a/testcases/kernel/syscalls/madvise/madvise09.c
+++ b/testcases/kernel/syscalls/madvise/madvise09.c
@@ -54,8 +54,10 @@ static int swap_accounting_enabled;
#define TOUCHED_PAGE1 0
#define TOUCHED_PAGE2 10
-#define MEM_LIMIT (8 * 1024 * 1024)
-#define SWAP_LIMIT (2 * MEM_LIMIT)
+#define BASE_SWAP_LIMIT (16 * 1024 * 1024)
+
+static long mem_limit;
+static long swap_limit;
static void memory_pressure_child(void)
{
@@ -176,12 +178,12 @@ static void child(void)
ptr[TOUCHED_PAGE1 * page_size] = 'b';
ptr[TOUCHED_PAGE2 * page_size] = 'b';
- SAFE_CG_PRINTF(tst_cg, "memory.max", "%d", MEM_LIMIT);
- tst_res(TINFO, "Setting memory.max to %d bytes", MEM_LIMIT);
+ SAFE_CG_PRINTF(tst_cg, "memory.max", "%ld", mem_limit);
+ tst_res(TINFO, "Setting memory.max to %ld bytes", mem_limit);
if (swap_accounting_enabled) {
- SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%d", SWAP_LIMIT);
- tst_res(TINFO, "Setting memory.swap.max to %d bytes", SWAP_LIMIT);
+ SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%ld", swap_limit);
+ tst_res(TINFO, "Setting memory.swap.max to %ld bytes", swap_limit);
} else {
tst_res(TINFO, "memory.swap.max is unavailable, running without SWAP_LIMIT");
}
@@ -284,6 +286,14 @@ static void setup(void)
tst_res(TINFO, "Swap accounting is disabled");
page_size = getpagesize();
+
+ mem_limit = 16 * PAGES * page_size;
+ swap_limit = 2 * mem_limit;
+
+ if (tst_available_swap() < swap_limit / 1024) {
+ tst_brk(TCONF, "System needs at least %ldMB free swap to run this test",
+ swap_limit / TST_MB);
+ }
}
static struct tst_test test = {
@@ -291,6 +301,6 @@ static struct tst_test test = {
.test_all = run,
.needs_root = 1,
.forks_child = 1,
- .min_swap_avail = SWAP_LIMIT / TST_MB,
+ .min_swap_avail = BASE_SWAP_LIMIT / TST_MB,
.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
};
--
2.54.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2026-07-23 7:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 7:53 Wei Gao via ltp [this message]
2026-07-23 8:32 ` [LTP] madvise09: Scale cgroup memory/swap limits dynamically with page size linuxtestproject.agent
2026-07-23 9:46 ` [LTP] [PATCH v2] " Wei Gao via ltp
2026-07-23 11:12 ` [LTP] " linuxtestproject.agent
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=20260723075319.4920-1-wegao@suse.com \
--to=ltp@lists.linux.it \
--cc=wegao@suse.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.