* [LTP] [PATCH v1] madvise09: Scale cgroup memory/swap limits dynamically with page size
@ 2026-07-23 7:53 Wei Gao via ltp
2026-07-23 8:32 ` [LTP] " linuxtestproject.agent
2026-07-23 9:46 ` [LTP] [PATCH v2] " Wei Gao via ltp
0 siblings, 2 replies; 4+ messages in thread
From: Wei Gao via ltp @ 2026-07-23 7:53 UTC (permalink / raw)
To: ltp
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] madvise09: Scale cgroup memory/swap limits dynamically with page size
2026-07-23 7:53 [LTP] [PATCH v1] madvise09: Scale cgroup memory/swap limits dynamically with page size Wei Gao via ltp
@ 2026-07-23 8:32 ` linuxtestproject.agent
2026-07-23 9:46 ` [LTP] [PATCH v2] " Wei Gao via ltp
1 sibling, 0 replies; 4+ messages in thread
From: linuxtestproject.agent @ 2026-07-23 8:32 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
On 2026-07-23, Wei Gao wrote:
> madvise09: Scale cgroup memory/swap limits dynamically with page size
> * o Set memory limits
> * - memory.max = 8MB
> * - memory.swap.max = 16MB
Now that mem_limit and swap_limit are derived from page_size at
runtime, are these values still accurate for the description block?
On a 64KB page system mem_limit becomes 128MB and swap_limit 256MB,
but the doc comment still states the old fixed 8MB/16MB.
> + 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);
> + }
This check runs unconditionally in setup(), but swap_limit is only
ever written to memory.swap.max when swap_accounting_enabled is true;
otherwise child() takes the "running without SWAP_LIMIT" path and
never enforces it. Could this needlessly skip the test (TCONF) on
systems with swap accounting disabled but with less free swap than
swap_limit, even though swap_limit isn't used there?
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
* [LTP] [PATCH v2] madvise09: Scale cgroup memory/swap limits dynamically with page size
2026-07-23 7:53 [LTP] [PATCH v1] madvise09: Scale cgroup memory/swap limits dynamically with page size Wei Gao via ltp
2026-07-23 8:32 ` [LTP] " linuxtestproject.agent
@ 2026-07-23 9:46 ` Wei Gao via ltp
2026-07-23 11:12 ` [LTP] " linuxtestproject.agent
1 sibling, 1 reply; 4+ messages in thread
From: Wei Gao via ltp @ 2026-07-23 9:46 UTC (permalink / raw)
To: ltp
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, and update the swap pre-check and doc
comments to match.
Signed-off-by: Wei Gao <wegao@suse.com>
---
Changes v1 -> v2:
- Update doc comment to reflect page-size based limit calculation.
- Guard tst_available_swap() check with swap_accounting_enabled to avoid unnecessary TCONF when swap accounting is off.
testcases/kernel/syscalls/madvise/madvise09.c | 30 ++++++++++++-------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/testcases/kernel/syscalls/madvise/madvise09.c b/testcases/kernel/syscalls/madvise/madvise09.c
index 5453f9411..620805370 100644
--- a/testcases/kernel/syscalls/madvise/madvise09.c
+++ b/testcases/kernel/syscalls/madvise/madvise09.c
@@ -17,11 +17,11 @@
* o Write to some of the madvised pages again, these must not be freed
*
* o Set memory limits
- * - memory.max = 8MB
- * - memory.swap.max = 16MB
+ * - memory.max = 16 * PAGES * page_size (8MB on 4KB page size)
+ * - memory.swap.max = 2 * memory.max (16MB on 4KB page size)
*
* The reason for doubling the memory.max is to have safe margin
- * for forking the memory hungy child etc. And the reason to setting
+ * for forking the memory hungry child etc. And the reason to setting
* memory.swap.max to twice of that is to give the system chance
* to try to free some memory before cgroup OOM kicks in and kills
* the memory hungry child.
@@ -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 long mem_limit;
+static long 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", "%lld", mem_limit);
+ tst_res(TINFO, "Setting memory.max to %lld 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", "%lld", swap_limit);
+ tst_res(TINFO, "Setting memory.swap.max to %lld 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 (swap_accounting_enabled && (tst_available_swap() < swap_limit / 1024)) {
+ tst_brk(TCONF, "System needs at least %lldMB 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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] madvise09: Scale cgroup memory/swap limits dynamically with page size
2026-07-23 9:46 ` [LTP] [PATCH v2] " Wei Gao via ltp
@ 2026-07-23 11:12 ` linuxtestproject.agent
0 siblings, 0 replies; 4+ messages in thread
From: linuxtestproject.agent @ 2026-07-23 11:12 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
On Thu, 23 Jul 2026, Wei Gao wrote:
> madvise09: Scale cgroup memory/swap limits dynamically with page size
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-23 11:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23 7:53 [LTP] [PATCH v1] madvise09: Scale cgroup memory/swap limits dynamically with page size Wei Gao via ltp
2026-07-23 8:32 ` [LTP] " linuxtestproject.agent
2026-07-23 9:46 ` [LTP] [PATCH v2] " Wei Gao via ltp
2026-07-23 11:12 ` [LTP] " linuxtestproject.agent
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.