* [LTP] [PATCH] mmap22: Bound child memory allocation to avoid OOM
@ 2026-11-02 10:57 Attila Fazekas via ltp
2026-11-02 18:54 ` [LTP] " linuxtestproject.agent
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Attila Fazekas via ltp @ 2026-11-02 10:57 UTC (permalink / raw)
To: ltp; +Cc: Attila Fazekas
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
(ALLOC_SIZE + 32MB). 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.
Assisted-by: Gemini CLI
Signed-off-by: Attila Fazekas <afazekas@redhat.com>
---
testcases/kernel/syscalls/mmap/mmap22.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/testcases/kernel/syscalls/mmap/mmap22.c b/testcases/kernel/syscalls/mmap/mmap22.c
index 0b95c578f..16fcb6dd8 100644
--- a/testcases/kernel/syscalls/mmap/mmap22.c
+++ b/testcases/kernel/syscalls/mmap/mmap22.c
@@ -26,6 +26,7 @@
#define MEM_LIMIT (256 * TST_MB)
#define ALLOC_SIZE (128 * TST_MB)
+#define CHILD_ALLOC_MAX (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)
--
2.56.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [LTP] mmap22: Bound child memory allocation to avoid OOM
2026-11-02 10:57 [LTP] [PATCH] mmap22: Bound child memory allocation to avoid OOM Attila Fazekas via ltp
@ 2026-11-02 18:54 ` linuxtestproject.agent
2026-11-03 20:14 ` [LTP] [PATCH] " Petr Vorel
2026-11-04 16:32 ` Cyril Hrubis
2 siblings, 0 replies; 6+ messages in thread
From: linuxtestproject.agent @ 2026-11-02 18:54 UTC (permalink / raw)
To: Attila Fazekas; +Cc: ltp
Hi Attila,
On Mon Nov 2 11:57:04 2026 +0100, Attila Fazekas wrote:
> 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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] mmap22: Bound child memory allocation to avoid OOM
2026-11-02 10:57 [LTP] [PATCH] mmap22: Bound child memory allocation to avoid OOM Attila Fazekas via ltp
2026-11-02 18:54 ` [LTP] " linuxtestproject.agent
@ 2026-11-03 20:14 ` Petr Vorel
2026-11-04 16:32 ` Cyril Hrubis
2 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2026-11-03 20:14 UTC (permalink / raw)
To: Attila Fazekas; +Cc: ltp
Hi Attila,
> 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
> (ALLOC_SIZE + 32MB). 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.
LGTM, but it'd be nice if somebody else double check.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
> Assisted-by: Gemini CLI
> Signed-off-by: Attila Fazekas <afazekas@redhat.com>
> ---
> testcases/kernel/syscalls/mmap/mmap22.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
> diff --git a/testcases/kernel/syscalls/mmap/mmap22.c b/testcases/kernel/syscalls/mmap/mmap22.c
> index 0b95c578f..16fcb6dd8 100644
> --- a/testcases/kernel/syscalls/mmap/mmap22.c
> +++ b/testcases/kernel/syscalls/mmap/mmap22.c
> @@ -26,6 +26,7 @@
> #define MEM_LIMIT (256 * TST_MB)
> #define ALLOC_SIZE (128 * TST_MB)
> +#define CHILD_ALLOC_MAX (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();
> }
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] mmap22: Bound child memory allocation to avoid OOM
2026-11-02 10:57 [LTP] [PATCH] mmap22: Bound child memory allocation to avoid OOM Attila Fazekas via ltp
2026-11-02 18:54 ` [LTP] " linuxtestproject.agent
2026-11-03 20:14 ` [LTP] [PATCH] " Petr Vorel
@ 2026-11-04 16:32 ` Cyril Hrubis
2026-11-05 8:04 ` Attila Fazekas via ltp
2 siblings, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2026-11-04 16:32 UTC (permalink / raw)
To: Attila Fazekas; +Cc: ltp
Hi!
> Assisted-by: Gemini CLI
> Signed-off-by: Attila Fazekas <afazekas@redhat.com>
> ---
> testcases/kernel/syscalls/mmap/mmap22.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/mmap/mmap22.c b/testcases/kernel/syscalls/mmap/mmap22.c
> index 0b95c578f..16fcb6dd8 100644
> --- a/testcases/kernel/syscalls/mmap/mmap22.c
> +++ b/testcases/kernel/syscalls/mmap/mmap22.c
> @@ -26,6 +26,7 @@
>
> #define MEM_LIMIT (256 * TST_MB)
> #define ALLOC_SIZE (128 * TST_MB)
> +#define CHILD_ALLOC_MAX (ALLOC_SIZE + 32 * TST_MB)
^
Wouldn't this be better:
(MEM_LIMIT - ALLOC_SIZE + 32*TST_MB)
That way this would stil work if we change either MEM_LIMIT or
ALLOC_SIZE.
Otherwise the change looks good.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] mmap22: Bound child memory allocation to avoid OOM
2026-11-04 16:32 ` Cyril Hrubis
@ 2026-11-05 8:04 ` Attila Fazekas via ltp
0 siblings, 0 replies; 6+ messages in thread
From: Attila Fazekas via ltp @ 2026-11-05 8:04 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
On Wed, Nov 4, 2026 at 5:41 PM Cyril Hrubis <chrubis@suse.cz> wrote:
> Hi!
> > Assisted-by: Gemini CLI
> > Signed-off-by: Attila Fazekas <afazekas@redhat.com>
> > ---
> > testcases/kernel/syscalls/mmap/mmap22.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/testcases/kernel/syscalls/mmap/mmap22.c
> b/testcases/kernel/syscalls/mmap/mmap22.c
> > index 0b95c578f..16fcb6dd8 100644
> > --- a/testcases/kernel/syscalls/mmap/mmap22.c
> > +++ b/testcases/kernel/syscalls/mmap/mmap22.c
> > @@ -26,6 +26,7 @@
> >
> > #define MEM_LIMIT (256 * TST_MB)
> > #define ALLOC_SIZE (128 * TST_MB)
> > +#define CHILD_ALLOC_MAX (ALLOC_SIZE + 32 * TST_MB)
> ^
> Wouldn't this be better:
> (MEM_LIMIT - ALLOC_SIZE + 32*TST_MB)
>
> This is better, I sent v2.
Thanks for the review.
> That way this would stil work if we change either MEM_LIMIT or
> ALLOC_SIZE.
>
> Otherwise the change looks good.
>
> --
> Cyril Hrubis
> chrubis@suse.cz
>
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] mmap22: Bound child memory allocation to avoid OOM
2026-11-05 8:02 [LTP] [PATCH v2] " Attila Fazekas via ltp
@ 2026-11-05 15:54 ` linuxtestproject.agent
0 siblings, 0 replies; 6+ messages in thread
From: linuxtestproject.agent @ 2026-11-05 15:54 UTC (permalink / raw)
To: Attila Fazekas; +Cc: ltp
Hi Attila,
On Thu Nov 5 09:02:45 2026 +0100, Attila Fazekas <afazekas@redhat.com> wrote:
> 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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-05 15:54 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-02 10:57 [LTP] [PATCH] mmap22: Bound child memory allocation to avoid OOM Attila Fazekas via ltp
2026-11-02 18:54 ` [LTP] " linuxtestproject.agent
2026-11-03 20:14 ` [LTP] [PATCH] " Petr Vorel
2026-11-04 16:32 ` Cyril Hrubis
2026-11-05 8:04 ` Attila Fazekas via ltp
-- strict thread matches above, loose matches on Subject: below --
2026-11-05 8:02 [LTP] [PATCH v2] " Attila Fazekas via ltp
2026-11-05 15:54 ` [LTP] " linuxtestproject.agent
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox