mmap22: Bound child memory allocation to avoid OOM
PATCH v2 1/1 mmap22: Bound child memory allocation to avoid OOM
Currently, stress_child() allocates memory in an infinite loop without bounds. Under memory pressure, once the cgroup memory limit is reached and the parent's droppable pages are reclaimed, the child continues allocating non-droppable heap memory. This eventually exhausts the cgroup limit and triggers the cgroup OOM killer, terminating either the child or the test parent process.
Fix this by bounding the child's allocation to CHILD_ALLOC_MAX. The total requested memory (128MB parent + 160MB
child = 288MB) exceeds the 256MB cgroup limit by 32MB, which reliably forces the kernel to reclaim MAP_DROPPABLE pages. Once CHILD_ALLOC_MAX is reached, the child calls pause() to keep memory resident. Since 160MB is well below the 256MB cgroup limit, non-droppable memory alone cannot trigger an OOM.
--- testcases/kernel/syscalls/mmap/mmap22.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/mmap/mmap22.c +5 -2
@@ -26,6 +26,7 @@#define MEM_LIMIT (256 * TST_MB)#define ALLOC_SIZE (128 * TST_MB) +#define CHILD_ALLOC_MAX (MEM_LIMIT - ALLOC_SIZE + 32 * TST_MB)static struct tst_cg_group *cg_child;static pid_t child;
@@ -33,13 +34,15 @@ static int page_size;static void stress_child (void ) { -for (;;) { +for (size_t sz =0 ; sz <CHILD_ALLOC_MAX ; sz += page_size) {char *buf =malloc (page_size);if (!buf) -exit (1 ); +break ;memset (buf,'B' , page_size); } + +pause (); }static void test_mmap (void )
Signature · 5 lines
2.56.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Attila,
Quoted 1 line · Attila Fazekas
mmap22: Bound child memory allocation to avoid OOM
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
Hi!
I am wondering when the merge train will arrive for this change if it is coming.
Do you need any action from me?
Best Regards,
Attila
Quoted 19 lines · On Thu, Nov 5, 2026 at 4:54 PM <[email protected]> wrote:
Hi Attila,
Quoted 1 line · Attila Fazekas
mmap22: Bound child memory allocation to avoid OOM
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
Hi!
Quoted 3 lines
I am wondering when the merge train will arrive for this change if it is coming.
Do you need any action from me?
Sorry, at the moment it's mostly just me doing the reviews and I'm overloaded with other tasks as well...
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Applied, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp