* [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space
@ 2026-04-27 11:59 Wei Gao via ltp
2026-04-27 12:26 ` Li Wang
` (4 more replies)
0 siblings, 5 replies; 25+ messages in thread
From: Wei Gao via ltp @ 2026-04-27 11:59 UTC (permalink / raw)
To: ltp
mmapstress06 is designed to stress the mfile_swap kernel primitive, which
manages shared anonymous memory. On architectures with large pages (like
64KB on ppc64le), the test's hardcoded request for 32769 pages results
in a ~2GB mapping. So in suse test system configured with 2GB of RAM and
no swap space, the test will fails with following information:
mmapstress06: errno = 12; large mmap failed
for this test to run, it needs a mmap space of
32769 pages
The failure occurs because the 2GB request cannot be fulfilled within
the 2GB RAM limit without swap backing. Since the test specifically
intends to exercise swap-related logic (mfile_swap), it should be skipped
with TCONF when the system lacks swap space.
Signed-off-by: Wei Gao <wegao@suse.com>
---
testcases/kernel/mem/mmapstress/mmapstress06.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/testcases/kernel/mem/mmapstress/mmapstress06.c b/testcases/kernel/mem/mmapstress/mmapstress06.c
index 37b7edc84..54b5febbf 100644
--- a/testcases/kernel/mem/mmapstress/mmapstress06.c
+++ b/testcases/kernel/mem/mmapstress/mmapstress06.c
@@ -51,6 +51,8 @@ void ok_exit();
#define ANON_GRAN_PAGES_MAX (32U)
+#include "tst_memutils.h"
+
extern time_t time(time_t *);
extern char *ctime(const time_t *);
extern int atoi(const char *);
@@ -74,6 +76,12 @@ int main(int argc, char *argv[])
(void)fprintf(stderr, "usage: %s sleep_time\n", argv[0]);
anyfail();
}
+
+ if (tst_available_swap() <= 0) {
+ tst_resm(TCONF, "Test requires swap space to exercise mfile_swap logic");
+ tst_exit();
+ }
+
(void)time(&t);
// (void)printf("%s: Started %s", argv[0], ctime(&t)); LTP Port
if (sbrk(pagesize - ((ulong) sbrk(0) & (pagesize - 1))) == (char *)-1) {
--
2.52.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 25+ messages in thread* Re: [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space 2026-04-27 11:59 [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space Wei Gao via ltp @ 2026-04-27 12:26 ` Li Wang 2026-04-27 13:57 ` Wei Gao via ltp 2026-04-27 13:57 ` [LTP] " linuxtestproject.agent ` (3 subsequent siblings) 4 siblings, 1 reply; 25+ messages in thread From: Li Wang @ 2026-04-27 12:26 UTC (permalink / raw) To: Wei Gao; +Cc: ltp Hi Wei, Wei Gao via ltp wrote: > mmapstress06 is designed to stress the mfile_swap kernel primitive, which > manages shared anonymous memory. On architectures with large pages (like > 64KB on ppc64le), the test's hardcoded request for 32769 pages results > in a ~2GB mapping. So in suse test system configured with 2GB of RAM and > no swap space, the test will fails with following information: > > mmapstress06: errno = 12; large mmap failed > for this test to run, it needs a mmap space of > 32769 pages > > The failure occurs because the 2GB request cannot be fulfilled within > the 2GB RAM limit without swap backing. Since the test specifically > intends to exercise swap-related logic (mfile_swap), it should be skipped > with TCONF when the system lacks swap space. Since we do have MAKE_SWAPFILE_SIZE macros, I guess we could create a dedicated swap-file for the testing on those system? And, it'd be appreciated if you can convert it into new LTP API. -- Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space 2026-04-27 12:26 ` Li Wang @ 2026-04-27 13:57 ` Wei Gao via ltp 2026-04-28 1:39 ` Li Wang 0 siblings, 1 reply; 25+ messages in thread From: Wei Gao via ltp @ 2026-04-27 13:57 UTC (permalink / raw) To: ltp > Hi Wei, > > Wei Gao via ltp wrote: > > > mmapstress06 is designed to stress the mfile_swap kernel primitive, which > > manages shared anonymous memory. On architectures with large pages (like > > 64KB on ppc64le), the test's hardcoded request for 32769 pages results > > in a ~2GB mapping. So in suse test system configured with 2GB of RAM and > > no swap space, the test will fails with following information: > > > > mmapstress06: errno = 12; large mmap failed > > for this test to run, it needs a mmap space of > > 32769 pages > > > > The failure occurs because the 2GB request cannot be fulfilled within > > the 2GB RAM limit without swap backing. Since the test specifically > > intends to exercise swap-related logic (mfile_swap), it should be skipped > > with TCONF when the system lacks swap space. > > Since we do have MAKE_SWAPFILE_SIZE macros, I guess we could create > a dedicated swap-file for the testing on those system? Sorry forget mention this failure happen in our Immutable/Transactional systems test (default disable swap), i am not sure enable swap force do test is make sense or not. @Petr Should we skip this test for transactional system? > > And, it'd be appreciated if you can convert it into new LTP API. No problem from my side. > > -- > Regards, > Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space 2026-04-27 13:57 ` Wei Gao via ltp @ 2026-04-28 1:39 ` Li Wang 0 siblings, 0 replies; 25+ messages in thread From: Li Wang @ 2026-04-28 1:39 UTC (permalink / raw) To: Wei Gao; +Cc: ltp On Mon, Apr 27, 2026 at 01:57:28PM +0000, Wei Gao via ltp wrote: > > > Hi Wei, > > > > Wei Gao via ltp wrote: > > > > > mmapstress06 is designed to stress the mfile_swap kernel primitive, which > > > manages shared anonymous memory. On architectures with large pages (like > > > 64KB on ppc64le), the test's hardcoded request for 32769 pages results > > > in a ~2GB mapping. So in suse test system configured with 2GB of RAM and > > > no swap space, the test will fails with following information: > > > > > > mmapstress06: errno = 12; large mmap failed > > > for this test to run, it needs a mmap space of > > > 32769 pages > > > > > > The failure occurs because the 2GB request cannot be fulfilled within > > > the 2GB RAM limit without swap backing. Since the test specifically > > > intends to exercise swap-related logic (mfile_swap), it should be skipped > > > with TCONF when the system lacks swap space. > > > > Since we do have MAKE_SWAPFILE_SIZE macros, I guess we could create > > a dedicated swap-file for the testing on those system? > Sorry forget mention this failure happen in our Immutable/Transactional > systems test (default disable swap), i am not sure enable swap force do > test is make sense or not. Ok, if that system does not support swap on purpose, that we can do the skip. Reviewed-by: Li Wang <li.wang@linux.dev> -- Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [LTP] mmapstress06: TCONF on systems without swap space 2026-04-27 11:59 [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space Wei Gao via ltp 2026-04-27 12:26 ` Li Wang @ 2026-04-27 13:57 ` linuxtestproject.agent 2026-04-28 11:52 ` [LTP] [PATCH v1] " Andrea Cervesato via ltp ` (2 subsequent siblings) 4 siblings, 0 replies; 25+ messages in thread From: linuxtestproject.agent @ 2026-04-27 13:57 UTC (permalink / raw) To: Wei Gao; +Cc: ltp, LTP AI Reviewer Hi Wei, On Mon, 27 Apr 2026, Wei Gao wrote: > mmapstress06: TCONF on systems without swap space > +#include "tst_memutils.h" Minor nit: the include lands after the #define ANON_GRAN_PAGES_MAX block rather than with the other #includes at the top. Consider moving it into the existing LTP include block for consistency. > + if (tst_available_swap() <= 0) { > + tst_resm(TCONF, "Test requires swap space to exercise mfile_swap logic"); > + tst_exit(); > + } Reviewed-by: LTP AI Reviewer <ltp-ai@noreply.github.com> --- Note: Our agent completed the review of the patch. The full review can be found at: https://github.com/linux-test-project/ltp-agent/actions/runs/24999033042 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] 25+ messages in thread
* Re: [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space 2026-04-27 11:59 [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space Wei Gao via ltp 2026-04-27 12:26 ` Li Wang 2026-04-27 13:57 ` [LTP] " linuxtestproject.agent @ 2026-04-28 11:52 ` Andrea Cervesato via ltp 2026-04-28 12:58 ` Petr Vorel 2026-06-05 4:29 ` [LTP] [PATCH v2] mmapstress06: Convert to new API Wei Gao via ltp 4 siblings, 0 replies; 25+ messages in thread From: Andrea Cervesato via ltp @ 2026-04-28 11:52 UTC (permalink / raw) To: Wei Gao via ltp; +Cc: ltp Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com> -- Andrea Cervesato SUSE QE Automation Engineer Linux andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space 2026-04-27 11:59 [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space Wei Gao via ltp ` (2 preceding siblings ...) 2026-04-28 11:52 ` [LTP] [PATCH v1] " Andrea Cervesato via ltp @ 2026-04-28 12:58 ` Petr Vorel 2026-04-28 16:34 ` Petr Vorel 2026-06-05 4:29 ` [LTP] [PATCH v2] mmapstress06: Convert to new API Wei Gao via ltp 4 siblings, 1 reply; 25+ messages in thread From: Petr Vorel @ 2026-04-28 12:58 UTC (permalink / raw) To: Wei Gao; +Cc: Li Wang, ltp Hi all, > mmapstress06 is designed to stress the mfile_swap kernel primitive, which > manages shared anonymous memory. On architectures with large pages (like > 64KB on ppc64le), the test's hardcoded request for 32769 pages results > in a ~2GB mapping. So in suse test system configured with 2GB of RAM and > no swap space, the test will fails with following information: > mmapstress06: errno = 12; large mmap failed > for this test to run, it needs a mmap space of > 32769 pages > The failure occurs because the 2GB request cannot be fulfilled within > the 2GB RAM limit without swap backing. Since the test specifically > intends to exercise swap-related logic (mfile_swap), it should be skipped > with TCONF when the system lacks swap space. > Signed-off-by: Wei Gao <wegao@suse.com> > --- > testcases/kernel/mem/mmapstress/mmapstress06.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > diff --git a/testcases/kernel/mem/mmapstress/mmapstress06.c b/testcases/kernel/mem/mmapstress/mmapstress06.c > index 37b7edc84..54b5febbf 100644 > --- a/testcases/kernel/mem/mmapstress/mmapstress06.c > +++ b/testcases/kernel/mem/mmapstress/mmapstress06.c > @@ -51,6 +51,8 @@ void ok_exit(); > #define ANON_GRAN_PAGES_MAX (32U) > +#include "tst_memutils.h" > + > extern time_t time(time_t *); > extern char *ctime(const time_t *); > extern int atoi(const char *); > @@ -74,6 +76,12 @@ int main(int argc, char *argv[]) > (void)fprintf(stderr, "usage: %s sleep_time\n", argv[0]); > anyfail(); > } > + > + if (tst_available_swap() <= 0) { > + tst_resm(TCONF, "Test requires swap space to exercise mfile_swap logic"); Why to require swap for the test instead of checking for ENOMEM later? > + tst_exit(); nit: I'd use tst_brkm() although it has ugly "Remaining cases broken" message as it will be more obvious when doing rewrite. > + } How about this? (with cleanup of ugly printf). Kind regards, Petr +++ testcases/kernel/mem/mmapstress/mmapstress06.c @@ -89,10 +89,12 @@ int main(int argc, char *argv[]) (mmapaddr, (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1) * pagesize, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0) == (caddr_t) - 1) { - ERROR("large mmap failed"); - printf("for this test to run, it needs a mmap space of\n"); - printf("%d pages\n", (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1)); - return 1; + if (errno == ENOMEM) { + tst_brkm(TCONF, NULL, "not enough memory or swap for mmap() %d pages", + ANON_GRAN_PAGES_MAX * NMFPTEPG + 1); + } + + tst_brkm(TBROK | TERRNO, NULL, "mmap() failed"); } (void)sleep(sleep_time); (void)time(&t); -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space 2026-04-28 12:58 ` Petr Vorel @ 2026-04-28 16:34 ` Petr Vorel 2026-04-29 2:22 ` Wei Gao via ltp 0 siblings, 1 reply; 25+ messages in thread From: Petr Vorel @ 2026-04-28 16:34 UTC (permalink / raw) To: Wei Gao, Li Wang, ltp Hi all, > Hi all, > > mmapstress06 is designed to stress the mfile_swap kernel primitive, which Uh, I overlooked "mfile_swap kernel primitive". Then the approach would make sense, but is it really true? mfile_swap does not exist any more, not even in a git log. Test was added in January 2003, e.g. even before 2.6. > > manages shared anonymous memory. On architectures with large pages (like > > 64KB on ppc64le), the test's hardcoded request for 32769 pages results > > in a ~2GB mapping. So in suse test system configured with 2GB of RAM and > > no swap space, the test will fails with following information: I'm not really sure. if that's caused by missing swap or would it work on machine with RAM big enough which has swap disabled (I guess you retest with e.g. 8 GB RAM). Otherwise I'd prefer prefer to deal with errno ENOMEM (12) instead (as I pointed out previously). Kind regards, Petr > > mmapstress06: errno = 12; large mmap failed > > for this test to run, it needs a mmap space of > > 32769 pages > > The failure occurs because the 2GB request cannot be fulfilled within > > the 2GB RAM limit without swap backing. Since the test specifically > > intends to exercise swap-related logic (mfile_swap), it should be skipped > > with TCONF when the system lacks swap space. > > Signed-off-by: Wei Gao <wegao@suse.com> > > --- > > testcases/kernel/mem/mmapstress/mmapstress06.c | 8 ++++++++ ... > > + if (tst_available_swap() <= 0) { > > + tst_resm(TCONF, "Test requires swap space to exercise mfile_swap logic"); > Why to require swap for the test instead of checking for ENOMEM later? > > + tst_exit(); > nit: I'd use tst_brkm() although it has ugly "Remaining cases broken" message as > it will be more obvious when doing rewrite. > > + } > How about this? (with cleanup of ugly printf). > Kind regards, > Petr > +++ testcases/kernel/mem/mmapstress/mmapstress06.c > @@ -89,10 +89,12 @@ int main(int argc, char *argv[]) > (mmapaddr, (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1) * pagesize, > PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, > 0) == (caddr_t) - 1) { > - ERROR("large mmap failed"); > - printf("for this test to run, it needs a mmap space of\n"); > - printf("%d pages\n", (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1)); > - return 1; > + if (errno == ENOMEM) { > + tst_brkm(TCONF, NULL, "not enough memory or swap for mmap() %d pages", > + ANON_GRAN_PAGES_MAX * NMFPTEPG + 1); > + } > + > + tst_brkm(TBROK | TERRNO, NULL, "mmap() failed"); > } > (void)sleep(sleep_time); > (void)time(&t); -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space 2026-04-28 16:34 ` Petr Vorel @ 2026-04-29 2:22 ` Wei Gao via ltp 2026-04-29 6:10 ` Petr Vorel 2026-04-30 8:01 ` Li Wang 0 siblings, 2 replies; 25+ messages in thread From: Wei Gao via ltp @ 2026-04-29 2:22 UTC (permalink / raw) To: Petr Vorel; +Cc: Li Wang, ltp On Tue, Apr 28, 2026 at 06:34:15PM +0200, Petr Vorel wrote: > Hi all, > > > Hi all, > > > > mmapstress06 is designed to stress the mfile_swap kernel primitive, which > Uh, I overlooked "mfile_swap kernel primitive". Then the approach would make > sense, but is it really true? mfile_swap does not exist any more, not even in a > git log. Test was added in January 2003, e.g. even before 2.6. > > > > manages shared anonymous memory. On architectures with large pages (like > > > 64KB on ppc64le), the test's hardcoded request for 32769 pages results > > > in a ~2GB mapping. So in suse test system configured with 2GB of RAM and > > > no swap space, the test will fails with following information: > > I'm not really sure. if that's caused by missing swap or would it work on > machine with RAM big enough which has swap disabled (I guess you retest with > e.g. 8 GB RAM). Otherwise I'd prefer prefer to deal with errno ENOMEM (12) > instead (as I pointed out previously). > Base description/implementation of test case, The original test is "passive," merely creating a mapping and relying on external processes to trigger swapping(case has sleep_time parameter). Further more, this case is "ghost test" for current kernel, it do mmap but never writes to it, so kernel never actually allocated memory, Together with current obsolete logic(test targets legcy mfile_swap) i suggest just delete it instead of wasting time patching(refactor) it. What do you think? @Petr @wang li? -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space 2026-04-29 2:22 ` Wei Gao via ltp @ 2026-04-29 6:10 ` Petr Vorel 2026-04-30 8:01 ` Li Wang 1 sibling, 0 replies; 25+ messages in thread From: Petr Vorel @ 2026-04-29 6:10 UTC (permalink / raw) To: Wei Gao; +Cc: Li Wang, ltp > On Tue, Apr 28, 2026 at 06:34:15PM +0200, Petr Vorel wrote: > > Hi all, > > > Hi all, > > > > mmapstress06 is designed to stress the mfile_swap kernel primitive, which > > Uh, I overlooked "mfile_swap kernel primitive". Then the approach would make > > sense, but is it really true? mfile_swap does not exist any more, not even in a > > git log. Test was added in January 2003, e.g. even before 2.6. > > > > manages shared anonymous memory. On architectures with large pages (like > > > > 64KB on ppc64le), the test's hardcoded request for 32769 pages results > > > > in a ~2GB mapping. So in suse test system configured with 2GB of RAM and > > > > no swap space, the test will fails with following information: > > I'm not really sure. if that's caused by missing swap or would it work on > > machine with RAM big enough which has swap disabled (I guess you retest with > > e.g. 8 GB RAM). Otherwise I'd prefer prefer to deal with errno ENOMEM (12) > > instead (as I pointed out previously). > Base description/implementation of test case, The original test is "passive," merely creating a > mapping and relying on external processes to trigger swapping(case has sleep_time parameter). > Further more, this case is "ghost test" for current kernel, it do mmap but never > writes to it, so kernel never actually allocated memory, > Together with current obsolete logic(test targets legcy mfile_swap) i suggest just delete > it instead of wasting time patching(refactor) it. What do you think? @Petr @wang li? I'm ok with deleting, but i hope others will have look on it as well. Kind regards, Petr -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space 2026-04-29 2:22 ` Wei Gao via ltp 2026-04-29 6:10 ` Petr Vorel @ 2026-04-30 8:01 ` Li Wang 1 sibling, 0 replies; 25+ messages in thread From: Li Wang @ 2026-04-30 8:01 UTC (permalink / raw) To: Wei Gao; +Cc: ltp Hi Wei, Petr, Wei Gao via ltp wrote: > Base description/implementation of test case, The original test is "passive," merely creating a > mapping and relying on external processes to trigger swapping(case has sleep_time parameter). > Further more, this case is "ghost test" for current kernel, it do mmap but never > writes to it, so kernel never actually allocated memory, > Together with current obsolete logic(test targets legcy mfile_swap) i suggest just delete > it instead of wasting time patching(refactor) it. What do you think? @Petr @wang li? After looking into the details of mmapstress06, I agree that this test only simulates progress and still requires another stress tester to create memory pressure and trigger swapping. Instead of removing this test, I prefer to refactor it into a new API and encapsulate the orignial method within Cgroups. e.g. 1. Check system swap availability 2. Create cgroup with memory.max and memory.swap.max limits 3. Create large anonymous shared mapping (original size) 4. Allocate stress region: size > memory.max in child 5. Ditry every page in stress region 6. Check process VmSwap increase 7. Cleanup -- Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* [LTP] [PATCH v2] mmapstress06: Convert to new API 2026-04-27 11:59 [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space Wei Gao via ltp ` (3 preceding siblings ...) 2026-04-28 12:58 ` Petr Vorel @ 2026-06-05 4:29 ` Wei Gao via ltp 2026-06-05 5:28 ` [LTP] " linuxtestproject.agent ` (2 more replies) 4 siblings, 3 replies; 25+ messages in thread From: Wei Gao via ltp @ 2026-06-05 4:29 UTC (permalink / raw) To: ltp Convert the mmapstress06 test case from the legacy LTP API to the new tst_test API. Refactor and redesign the test to be active instead of passive: - Replaced the passive sleep-based synchronization with an active cgroup constrained memory stress test under cgroup v2. - Dirties all pages of the 1GB shared anonymous mapping inside the child cgroup, forcing the kernel to swap out exactly 500MB of memory. This large page pool avoids premature cgroup OOM-kills on systems with larger page sizes (like 64KB on ppc64le), while keeping the total swap usage lightweight and safe. - Added CONFIG_SWAP=y and CONFIG_MEMCG=y kernel configuration checks. Signed-off-by: Wei Gao <wegao@suse.com> --- runtest/mm | 2 +- .../kernel/mem/mmapstress/mmapstress06.c | 200 ++++++++++-------- 2 files changed, 111 insertions(+), 91 deletions(-) diff --git a/runtest/mm b/runtest/mm index 41d624ad8..7d75b65c8 100644 --- a/runtest/mm +++ b/runtest/mm @@ -41,7 +41,7 @@ mmapstress02 mmapstress02 mmapstress03 mmapstress03 mmapstress04 mmapstress04 mmapstress05 mmapstress05 -mmapstress06 mmapstress06 20 +mmapstress06 mmapstress06 mmapstress07 TMPFILE=`mktemp $TMPDIR/example.XXXXXXXXXXXX`; mmapstress07 $TMPFILE mmapstress08 mmapstress08 mmapstress09 mmapstress09 -p 20 -t 0.2 diff --git a/testcases/kernel/mem/mmapstress/mmapstress06.c b/testcases/kernel/mem/mmapstress/mmapstress06.c index 37b7edc84..f1500eb6c 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress06.c +++ b/testcases/kernel/mem/mmapstress/mmapstress06.c @@ -1,116 +1,136 @@ -/* IBM Corporation */ -/* 01/02/2003 Port to LTP avenkat@us.ibm.com */ -/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (c) International Business Machines Corp., 2003 - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) International Business Machines Corp., 2003 + * Copyright (c) 2026 Linux Test Project + */ + +/*\ + * Test ``:manpage:`mmap(2)``` with swap behavior. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * Mmap a large anonymous shared region and force it to be swapped out + * by setting memory limits using Cgroups and dirtying all pages. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * This test requires root privileges because configuring cgroup memory + * limits requires administrative access. */ -/* - * mfile_swap: - * Mmap a large (> ANON_GRAN_PAGES_MAX) shared, anonymous region before - * swapping to use the second half of the kernel primitive mfile_swap. - * However, this test does _NOT_ cause swapping to occur. Instead it should be - * run with waves or at the same time as a test which does cause swapping (i.e. - * vsswapin or vfork_swap) - */ -#define _KMEMUSER +#define _GNU_SOURCE #include <sys/types.h> #include <sys/mman.h> +#include <sys/sysinfo.h> #include <unistd.h> #include <stdio.h> #include <errno.h> +#include <stdlib.h> +#include "tst_test.h" +#include "tst_safe_macros.h" -/***** LTP Port *****/ -#include "test.h" -#define FAILED 0 -#define PASSED 1 +static struct tst_cg_group *cg_child; +static int page_size; +static size_t map_size; +static size_t mem_limit; +static pid_t child_pid = -1; -int local_flag = PASSED; -char *TCID = "mmapstress06"; //mfile_swap -FILE *temp; -int TST_TOTAL = 1; +static void run_test(void) +{ + int status; -int anyfail(); -void ok_exit(); -/***** ** ** *****/ + cg_child = tst_cg_group_mk(tst_cg, "child"); -#define ANON_GRAN_PAGES_MAX (32U) + /* Set memory limit to force swapping of the mapping */ + SAFE_CG_PRINTF(cg_child, "memory.max", "%lu", (unsigned long)mem_limit); + SAFE_CG_PRINT(cg_child, "memory.swap.max", "max"); -extern time_t time(time_t *); -extern char *ctime(const time_t *); -extern int atoi(const char *); + child_pid = SAFE_FORK(); + if (!child_pid) { + char *mmapaddr; + unsigned long cg_swap_before = 0, cg_swap_after = 0; -#define NMFPTEPG (1024) -#define ERROR(M) (void)fprintf(stderr, "%s: errno = %d; " M "\n", \ - argv[0], errno); + /* Move child to the constrained cgroup */ + SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid()); -int main(int argc, char *argv[]) -{ - caddr_t mmapaddr; - size_t pagesize = sysconf(_SC_PAGE_SIZE); - time_t t; - int sleep_time = 0; - - if (!argc) { - (void)fprintf(stderr, "argc == 0\n"); - anyfail(); - } - if (argc != 2 || !(sleep_time = atoi(argv[1]))) { - (void)fprintf(stderr, "usage: %s sleep_time\n", argv[0]); - anyfail(); - } - (void)time(&t); -// (void)printf("%s: Started %s", argv[0], ctime(&t)); LTP Port - if (sbrk(pagesize - ((ulong) sbrk(0) & (pagesize - 1))) == (char *)-1) { - ERROR("couldn't round up brk"); - anyfail(); - } - if ((mmapaddr = sbrk(0)) == (char *)-1) { - ERROR("couldn't find top of brk"); - anyfail(); - } - /* mmapaddr is now on a page boundary after the brk segment */ - if (mmap - (mmapaddr, (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1) * pagesize, - PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, - 0) == (caddr_t) - 1) { - ERROR("large mmap failed"); - printf("for this test to run, it needs a mmap space of\n"); - printf("%d pages\n", (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1)); - return 1; + SAFE_CG_SCANF(cg_child, "memory.swap.current", "%lu", &cg_swap_before); + + mmapaddr = SAFE_MMAP(NULL, map_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_SHARED, -1, 0); + + tst_res(TINFO, "Dirtying %zu bytes in child", map_size); + + for (size_t i = 0; i < map_size; i += page_size) + mmapaddr[i] = 'a'; + + SAFE_CG_SCANF(cg_child, "memory.swap.current", "%lu", &cg_swap_after); + + tst_res(TINFO, "Cgroup swap: %lu MB -> %lu MB", + cg_swap_before / TST_MB, cg_swap_after / TST_MB); + + if (cg_swap_after > cg_swap_before) { + tst_res(TPASS, "Cgroup swap usage increased from %lu MB to %lu MB", + cg_swap_before / TST_MB, cg_swap_after / TST_MB); + } else { + tst_res(TFAIL, "Cgroup swap usage did not increase (before: %lu B, after: %lu B)", + cg_swap_before, cg_swap_after); + } + + SAFE_MUNMAP(mmapaddr, map_size); + exit(0); } - (void)sleep(sleep_time); - (void)time(&t); -// (void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP Port - ok_exit(); - tst_exit(); + + SAFE_WAITPID(child_pid, &status, 0); + child_pid = -1; + + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) + tst_res(TFAIL, "Child process failed (status: %d)", status); + + cg_child = tst_cg_group_rm(cg_child); } -/***** LTP Port *****/ -void ok_exit(void) +static void setup(void) { - tst_resm(TPASS, "Test passed"); - tst_exit(); + struct sysinfo s; + unsigned long long total_swap; + + if (!SAFE_CG_HAS(tst_cg, "memory.swap.max")) + tst_brk(TCONF, "Cgroup swap controller is not enabled/supported"); + + page_size = getpagesize(); + + mem_limit = 500 * TST_MB; + map_size = 1000 * TST_MB; + + sysinfo(&s); + total_swap = (unsigned long long)s.totalswap * s.mem_unit; + + if (total_swap < map_size) { + tst_brk(TCONF, "System swap size (%llu MB) is too small, need %llu MB", + total_swap / TST_MB, (unsigned long long)map_size / TST_MB); + } } -int anyfail(void) +static void cleanup(void) { - tst_brkm(TFAIL, NULL, "Test failed"); + if (child_pid > 0) { + SAFE_KILL(child_pid, SIGKILL); + SAFE_WAITPID(child_pid, NULL, 0); + } + + if (cg_child) { + SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid()); + cg_child = tst_cg_group_rm(cg_child); + } } -/***** ** ** *****/ +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .forks_child = 1, + .needs_root = 1, + .needs_cgroup_ctrls = (const char *const []){ "memory", NULL }, + .needs_cgroup_ver = TST_CG_V2, + .needs_kconfigs = (const char *[]) { + "CONFIG_SWAP=y", + "CONFIG_MEMCG=y", + NULL + }, +}; -- 2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [LTP] mmapstress06: Convert to new API 2026-06-05 4:29 ` [LTP] [PATCH v2] mmapstress06: Convert to new API Wei Gao via ltp @ 2026-06-05 5:28 ` linuxtestproject.agent 2026-06-05 7:11 ` Li Wang 2026-06-05 7:17 ` [LTP] [PATCH v2] " Andrea Cervesato via ltp 2026-06-06 10:08 ` [LTP] [PATCH v3] " Wei Gao via ltp 2 siblings, 1 reply; 25+ messages in thread From: linuxtestproject.agent @ 2026-06-05 5:28 UTC (permalink / raw) To: Wei Gao; +Cc: ltp Hi Wei, On Fri, 05 Jun 2026, Wei Gao wrote: > mmapstress06: Convert to new API > +/*\ > + * Test ``:manpage:`mmap(2)``` with swap behavior. The RST role is malformed. Other tests in the tree use it without the surrounding double-backticks, e.g.: * Test :manpage:`mmap(2)` with swap behavior. > +#include "tst_test.h" > +#include "tst_safe_macros.h" tst_test.h already includes tst_safe_macros.h; the second include is redundant. > + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) WIFEXITED() and WEXITSTATUS() require <sys/wait.h>. That header is not included, and nothing in the include chain pulls it in. Every other test in testcases/kernel/mem/ that uses these macros includes <sys/wait.h> explicitly (ksm05.c, vma01.c, mmapstress09.c). > + sysinfo(&s); > + total_swap = (unsigned long long)s.totalswap * s.mem_unit; > + > + if (total_swap < map_size) { This checks total (configured) swap, not available (free) swap. On a system with 1 GB of total swap where 800 MB is already in use, the check passes but the test would fail at runtime when only 200 MB of free swap remains. The tst_test framework provides .min_swap_avail (in megabytes) in struct tst_test to guard against this; that field also removes the need for the hand-rolled sysinfo() block. The swap check should also test against the amount actually needed (map_size - mem_limit, around 500 MB), not against map_size (1000 MB). The commit message also says "forcing the kernel to swap out exactly 500MB of memory", but the test only checks that cg_swap_after is larger than cg_swap_before -- any non-zero increase would pass. The word "exactly" is inaccurate. 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] 25+ messages in thread
* Re: [LTP] mmapstress06: Convert to new API 2026-06-05 5:28 ` [LTP] " linuxtestproject.agent @ 2026-06-05 7:11 ` Li Wang 0 siblings, 0 replies; 25+ messages in thread From: Li Wang @ 2026-06-05 7:11 UTC (permalink / raw) To: Wei Gao; +Cc: ltp Hi Wei, The refactoring generally looks good, but have minor issues: 1. We can remove the strict requirement for Cgroup V2. 2. Check gloabl RAM size, in Cgroup v2, memory.max limits physical RAM usage. If the system only has 256MB of physical RAM, the process can never reach the 500MB memory.max limit. 3. Set mem_limit/map_size to small values e.g. 128MB/256MB to make the test widely run. -- Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [LTP] [PATCH v2] mmapstress06: Convert to new API 2026-06-05 4:29 ` [LTP] [PATCH v2] mmapstress06: Convert to new API Wei Gao via ltp 2026-06-05 5:28 ` [LTP] " linuxtestproject.agent @ 2026-06-05 7:17 ` Andrea Cervesato via ltp 2026-06-05 9:35 ` Wei Gao via ltp 2026-06-06 10:08 ` [LTP] [PATCH v3] " Wei Gao via ltp 2 siblings, 1 reply; 25+ messages in thread From: Andrea Cervesato via ltp @ 2026-06-05 7:17 UTC (permalink / raw) To: Wei Gao; +Cc: ltp Hi Wei, did you use the ltp-convert skill from the agent to generate the first draft? If you have any suggestion please let me know, so we can fine tuning the configuration to make it more accurate. Regards, -- Andrea Cervesato SUSE QE Automation Engineer Linux andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [LTP] [PATCH v2] mmapstress06: Convert to new API 2026-06-05 7:17 ` [LTP] [PATCH v2] " Andrea Cervesato via ltp @ 2026-06-05 9:35 ` Wei Gao via ltp 2026-06-05 9:42 ` Andrea Cervesato via ltp 0 siblings, 1 reply; 25+ messages in thread From: Wei Gao via ltp @ 2026-06-05 9:35 UTC (permalink / raw) To: Andrea Cervesato; +Cc: ltp On Fri, Jun 05, 2026 at 07:17:29AM +0000, Andrea Cervesato wrote: > Hi Wei, > > did you use the ltp-convert skill from the agent to generate the first > draft? If you have any suggestion please let me know, so we can fine > tuning the configuration to make it more accurate. Yes, v2 first draft is created by latest ltp-convert skill(gemini). I have done some test on power/x86 and give feedback to AI then finally we have v2. Most of the v2 code are directly created by AI. It looks good from now. Some error happen i have not noticed such as "manpage:`mmap(2)" format is also created by ltp-convert skill, you can check AI feedback on v2. I have no idea why this kind of simple issue still happen. > > Regards, > -- > Andrea Cervesato > SUSE QE Automation Engineer Linux > andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [LTP] [PATCH v2] mmapstress06: Convert to new API 2026-06-05 9:35 ` Wei Gao via ltp @ 2026-06-05 9:42 ` Andrea Cervesato via ltp 2026-06-05 10:02 ` Wei Gao via ltp 0 siblings, 1 reply; 25+ messages in thread From: Andrea Cervesato via ltp @ 2026-06-05 9:42 UTC (permalink / raw) To: Wei Gao; +Cc: ltp > Some error happen i have not noticed such as "manpage:`mmap(2)" format > is also created by ltp-convert skill, you can check AI feedback on v2. I > have no idea why this kind of simple issue still happen. You can probably run /ltp-review after converting the test to spot the errors on the commit. You should have quite a similar CI review. I updated the agent, make sure to run ./setup <agent> again before doing it. -- Andrea Cervesato SUSE QE Automation Engineer Linux andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [LTP] [PATCH v2] mmapstress06: Convert to new API 2026-06-05 9:42 ` Andrea Cervesato via ltp @ 2026-06-05 10:02 ` Wei Gao via ltp 0 siblings, 0 replies; 25+ messages in thread From: Wei Gao via ltp @ 2026-06-05 10:02 UTC (permalink / raw) To: Andrea Cervesato; +Cc: ltp On Fri, Jun 05, 2026 at 09:42:14AM +0000, Andrea Cervesato wrote: > > Some error happen i have not noticed such as "manpage:`mmap(2)" format > > is also created by ltp-convert skill, you can check AI feedback on v2. I > > have no idea why this kind of simple issue still happen. > > You can probably run /ltp-review after converting the test to spot the > errors on the commit. You should have quite a similar CI review. I have run ltp-review locally before send patch but not help. Maybe different AI agent can get different result. > > I updated the agent, make sure to run ./setup <agent> again before > doing it. > > -- > Andrea Cervesato > SUSE QE Automation Engineer Linux > andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
* [LTP] [PATCH v3] mmapstress06: Convert to new API 2026-06-05 4:29 ` [LTP] [PATCH v2] mmapstress06: Convert to new API Wei Gao via ltp 2026-06-05 5:28 ` [LTP] " linuxtestproject.agent 2026-06-05 7:17 ` [LTP] [PATCH v2] " Andrea Cervesato via ltp @ 2026-06-06 10:08 ` Wei Gao via ltp 2026-06-06 11:32 ` [LTP] " linuxtestproject.agent 2026-06-07 4:52 ` [LTP] [PATCH v4] " Wei Gao via ltp 2 siblings, 2 replies; 25+ messages in thread From: Wei Gao via ltp @ 2026-06-06 10:08 UTC (permalink / raw) To: ltp; +Cc: Li Wang Convert the mmapstress06 test case from the legacy LTP API to the new tst_test API. Refactor and redesign the test to be active instead of passive: - Replaced the passive sleep-based synchronization with an active cgroup constrained memory stress test compatible with both cgroups v1 and v2. - Dirties all pages of a 256MB shared anonymous mapping inside the child cgroup, forcing the kernel to swap out memory when hitting the 128MB limit. - Disables Transparent Huge Pages (THP) on the mapping using madvise(..., MADV_NOHUGEPAGE) to avoid triggering cgroup OOM-kills. - Added CONFIG_SWAP=y and CONFIG_MEMCG=y kernel configuration checks. - Utilized declarative .min_mem_avail and .min_swap_avail for framework-level resource validation. Signed-off-by: Wei Gao <wegao@suse.com> --- v2->v3: - Reduced map_size from 1000MB to 256MB, and mem_limit from 500MB to 128MB. - Enabled compatibility with both Cgroups v1 and v2: - Replaced the manual sysinfo-based swap space check in setup() with declarative .min_mem_avail and .min_swap_avail structure members. - Added madvise(..., MADV_NOHUGEPAGE) to disable Transparent Huge Pages (THP) on the mapped region to avoid premature MemCG OOM-kills under tight cgroup limits. - Included <sys/wait.h> header for WIFEXITED/WEXITSTATUS and cleaned up unused headers (<sys/sysinfo.h> and tst_safe_macros.h). runtest/mm | 2 +- .../kernel/mem/mmapstress/mmapstress06.c | 200 ++++++++++-------- 2 files changed, 111 insertions(+), 91 deletions(-) diff --git a/runtest/mm b/runtest/mm index 41d624ad8..7d75b65c8 100644 --- a/runtest/mm +++ b/runtest/mm @@ -41,7 +41,7 @@ mmapstress02 mmapstress02 mmapstress03 mmapstress03 mmapstress04 mmapstress04 mmapstress05 mmapstress05 -mmapstress06 mmapstress06 20 +mmapstress06 mmapstress06 mmapstress07 TMPFILE=`mktemp $TMPDIR/example.XXXXXXXXXXXX`; mmapstress07 $TMPFILE mmapstress08 mmapstress08 mmapstress09 mmapstress09 -p 20 -t 0.2 diff --git a/testcases/kernel/mem/mmapstress/mmapstress06.c b/testcases/kernel/mem/mmapstress/mmapstress06.c index 37b7edc84..ca2e856d8 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress06.c +++ b/testcases/kernel/mem/mmapstress/mmapstress06.c @@ -1,116 +1,136 @@ -/* IBM Corporation */ -/* 01/02/2003 Port to LTP avenkat@us.ibm.com */ -/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (c) International Business Machines Corp., 2003 - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) International Business Machines Corp., 2003 + * Copyright (c) 2026 Linux Test Project + */ + +/*\ + * Test :manpage:`mmap(2)` with swap behavior. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * Mmap a large anonymous shared region and force it to be swapped out + * by setting memory limits using Cgroups and dirtying all pages. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * This test requires root privileges because configuring cgroup memory + * limits requires administrative access. */ -/* - * mfile_swap: - * Mmap a large (> ANON_GRAN_PAGES_MAX) shared, anonymous region before - * swapping to use the second half of the kernel primitive mfile_swap. - * However, this test does _NOT_ cause swapping to occur. Instead it should be - * run with waves or at the same time as a test which does cause swapping (i.e. - * vsswapin or vfork_swap) - */ -#define _KMEMUSER +#define _GNU_SOURCE #include <sys/types.h> #include <sys/mman.h> +#include <sys/wait.h> #include <unistd.h> #include <stdio.h> #include <errno.h> +#include <stdlib.h> +#include "tst_test.h" + +static struct tst_cg_group *cg_child; +static int page_size; +static size_t map_size; +static size_t mem_limit; +static pid_t child_pid = -1; -/***** LTP Port *****/ -#include "test.h" -#define FAILED 0 -#define PASSED 1 +static void run_test(void) +{ + int status; -int local_flag = PASSED; -char *TCID = "mmapstress06"; //mfile_swap -FILE *temp; -int TST_TOTAL = 1; + cg_child = tst_cg_group_mk(tst_cg, "child"); -int anyfail(); -void ok_exit(); -/***** ** ** *****/ + /* Set memory limit to force swapping of the mapping */ + SAFE_CG_PRINTF(cg_child, "memory.max", "%lu", (unsigned long)mem_limit); -#define ANON_GRAN_PAGES_MAX (32U) + if (TST_CG_VER_IS_V1(cg_child, "memory")) + SAFE_CG_PRINT(cg_child, "memory.swap.max", "-1"); + else + SAFE_CG_PRINT(cg_child, "memory.swap.max", "max"); -extern time_t time(time_t *); -extern char *ctime(const time_t *); -extern int atoi(const char *); + child_pid = SAFE_FORK(); + if (!child_pid) { + char *mmapaddr; + unsigned long cg_swap_before = 0, cg_swap_after = 0; -#define NMFPTEPG (1024) -#define ERROR(M) (void)fprintf(stderr, "%s: errno = %d; " M "\n", \ - argv[0], errno); + /* Move child to the constrained cgroup */ + SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid()); -int main(int argc, char *argv[]) -{ - caddr_t mmapaddr; - size_t pagesize = sysconf(_SC_PAGE_SIZE); - time_t t; - int sleep_time = 0; - - if (!argc) { - (void)fprintf(stderr, "argc == 0\n"); - anyfail(); - } - if (argc != 2 || !(sleep_time = atoi(argv[1]))) { - (void)fprintf(stderr, "usage: %s sleep_time\n", argv[0]); - anyfail(); - } - (void)time(&t); -// (void)printf("%s: Started %s", argv[0], ctime(&t)); LTP Port - if (sbrk(pagesize - ((ulong) sbrk(0) & (pagesize - 1))) == (char *)-1) { - ERROR("couldn't round up brk"); - anyfail(); - } - if ((mmapaddr = sbrk(0)) == (char *)-1) { - ERROR("couldn't find top of brk"); - anyfail(); - } - /* mmapaddr is now on a page boundary after the brk segment */ - if (mmap - (mmapaddr, (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1) * pagesize, - PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, - 0) == (caddr_t) - 1) { - ERROR("large mmap failed"); - printf("for this test to run, it needs a mmap space of\n"); - printf("%d pages\n", (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1)); - return 1; + SAFE_CG_SCANF(cg_child, "memory.swap.current", "%lu", &cg_swap_before); + + mmapaddr = SAFE_MMAP(NULL, map_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_SHARED, -1, 0); + + /* + * Disable Transparent Huge Pages (THP) for this mapping. + * Under tight cgroup memory limits (128 MB), allocating huge + * pages can easily trigger MemCG OOM-kills. Disabling THP forces + * standard 4 KB pages, ensuring stable swapping and avoiding + * premature OOM. + */ + if (madvise(mmapaddr, map_size, MADV_NOHUGEPAGE) < 0) + tst_res(TWARN | TERRNO, "madvise(MADV_NOHUGEPAGE) failed"); + + tst_res(TINFO, "Dirtying %zu bytes in child", map_size); + + for (size_t i = 0; i < map_size; i += page_size) + mmapaddr[i] = 'a'; + + SAFE_CG_SCANF(cg_child, "memory.swap.current", "%lu", &cg_swap_after); + + if (cg_swap_after > cg_swap_before) { + tst_res(TPASS, "Cgroup swap usage increased from %lu MB to %lu MB", + cg_swap_before / TST_MB, cg_swap_after / TST_MB); + } else { + tst_res(TFAIL, "Cgroup swap usage did not increase (before: %lu B, after: %lu B)", + cg_swap_before, cg_swap_after); + } + + SAFE_MUNMAP(mmapaddr, map_size); + exit(0); } - (void)sleep(sleep_time); - (void)time(&t); -// (void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP Port - ok_exit(); - tst_exit(); + + SAFE_WAITPID(child_pid, &status, 0); + child_pid = -1; + + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) + tst_res(TFAIL, "Child process failed (status: %d)", status); + + cg_child = tst_cg_group_rm(cg_child); } -/***** LTP Port *****/ -void ok_exit(void) +static void setup(void) { - tst_resm(TPASS, "Test passed"); - tst_exit(); + if (!SAFE_CG_HAS(tst_cg, "memory.swap.max")) + tst_brk(TCONF, "Cgroup swap controller is not enabled/supported"); + + page_size = getpagesize(); + + mem_limit = 128 * TST_MB; + map_size = 256 * TST_MB; } -int anyfail(void) +static void cleanup(void) { - tst_brkm(TFAIL, NULL, "Test failed"); + if (child_pid > 0) { + SAFE_KILL(child_pid, SIGKILL); + SAFE_WAITPID(child_pid, NULL, 0); + } + + if (cg_child) { + SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid()); + cg_child = tst_cg_group_rm(cg_child); + } } -/***** ** ** *****/ +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .forks_child = 1, + .needs_root = 1, + .needs_cgroup_ctrls = (const char *const []){ "memory", NULL }, + .min_mem_avail = 256, + .min_swap_avail = 128, + .needs_kconfigs = (const char *[]) { + "CONFIG_SWAP=y", + "CONFIG_MEMCG=y", + NULL + }, +}; -- 2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [LTP] mmapstress06: Convert to new API 2026-06-06 10:08 ` [LTP] [PATCH v3] " Wei Gao via ltp @ 2026-06-06 11:32 ` linuxtestproject.agent 2026-06-07 4:52 ` [LTP] [PATCH v4] " Wei Gao via ltp 1 sibling, 0 replies; 25+ messages in thread From: linuxtestproject.agent @ 2026-06-06 11:32 UTC (permalink / raw) To: Wei Gao; +Cc: ltp Hi Wei, On Sat, 06 Jun 2026 10:08:05 +0000, Wei Gao wrote: > mmapstress06: Convert to new API > + SAFE_WAITPID(child_pid, &status, 0); > + child_pid = -1; > + > + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) > + tst_res(TFAIL, "Child process failed (status: %d)", status); The child already calls tst_res(TPASS/TFAIL, ...) directly, and .forks_child = 1 tells the framework to propagate those results to the parent. Checking WEXITSTATUS on top of that risks double-reporting: if a SAFE_* macro in the child triggers tst_brk(), the framework records the TBROK from the child and the parent then logs an additional TFAIL. The correct pattern (per the LTP rules on child result reporting) is to rely on tst_res() in the child and drop the exit-code check in the parent. SAFE_WAITPID() is still needed to reap the child, but the result is already reported: SAFE_WAITPID(child_pid, &status, 0); child_pid = -1; 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] 25+ messages in thread
* [LTP] [PATCH v4] mmapstress06: Convert to new API 2026-06-06 10:08 ` [LTP] [PATCH v3] " Wei Gao via ltp 2026-06-06 11:32 ` [LTP] " linuxtestproject.agent @ 2026-06-07 4:52 ` Wei Gao via ltp 2026-06-07 8:02 ` [LTP] " linuxtestproject.agent 2026-06-08 2:52 ` [LTP] [PATCH v5] " Wei Gao via ltp 1 sibling, 2 replies; 25+ messages in thread From: Wei Gao via ltp @ 2026-06-07 4:52 UTC (permalink / raw) To: ltp Convert the mmapstress06 test case from the legacy LTP API to the new tst_test API. Refactor and redesign the test to be active instead of passive: - Replaced the passive sleep-based synchronization with an active cgroup constrained memory stress test compatible with both cgroups v1 and v2. - Dirties all pages of a 256MB shared anonymous mapping inside the child cgroup, forcing the kernel to swap out memory when hitting the 128MB limit. - Disables Transparent Huge Pages (THP) on the mapping using madvise(..., MADV_NOHUGEPAGE) to avoid triggering cgroup OOM-kills. - Added CONFIG_SWAP=y and CONFIG_MEMCG=y kernel configuration checks. - Utilized declarative .min_mem_avail and .min_swap_avail for framework-level resource validation. Signed-off-by: Wei Gao <wegao@suse.com> --- v3->v4: - removes duplicate failure checks in the parent runtest/mm | 2 +- .../kernel/mem/mmapstress/mmapstress06.c | 195 ++++++++++-------- 2 files changed, 106 insertions(+), 91 deletions(-) diff --git a/runtest/mm b/runtest/mm index 41d624ad8..7d75b65c8 100644 --- a/runtest/mm +++ b/runtest/mm @@ -41,7 +41,7 @@ mmapstress02 mmapstress02 mmapstress03 mmapstress03 mmapstress04 mmapstress04 mmapstress05 mmapstress05 -mmapstress06 mmapstress06 20 +mmapstress06 mmapstress06 mmapstress07 TMPFILE=`mktemp $TMPDIR/example.XXXXXXXXXXXX`; mmapstress07 $TMPFILE mmapstress08 mmapstress08 mmapstress09 mmapstress09 -p 20 -t 0.2 diff --git a/testcases/kernel/mem/mmapstress/mmapstress06.c b/testcases/kernel/mem/mmapstress/mmapstress06.c index 37b7edc84..a4fda9683 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress06.c +++ b/testcases/kernel/mem/mmapstress/mmapstress06.c @@ -1,116 +1,131 @@ -/* IBM Corporation */ -/* 01/02/2003 Port to LTP avenkat@us.ibm.com */ -/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (c) International Business Machines Corp., 2003 - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) International Business Machines Corp., 2003 + * Copyright (c) 2026 Linux Test Project + */ + +/*\ + * Test :manpage:`mmap(2)` with swap behavior. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * Mmap a large anonymous shared region and force it to be swapped out + * by setting memory limits using Cgroups and dirtying all pages. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * This test requires root privileges because configuring cgroup memory + * limits requires administrative access. */ -/* - * mfile_swap: - * Mmap a large (> ANON_GRAN_PAGES_MAX) shared, anonymous region before - * swapping to use the second half of the kernel primitive mfile_swap. - * However, this test does _NOT_ cause swapping to occur. Instead it should be - * run with waves or at the same time as a test which does cause swapping (i.e. - * vsswapin or vfork_swap) - */ -#define _KMEMUSER +#define _GNU_SOURCE #include <sys/types.h> #include <sys/mman.h> +#include <sys/wait.h> #include <unistd.h> #include <stdio.h> #include <errno.h> +#include <stdlib.h> +#include "tst_test.h" -/***** LTP Port *****/ -#include "test.h" -#define FAILED 0 -#define PASSED 1 +static struct tst_cg_group *cg_child; +static int page_size; +static size_t map_size; +static size_t mem_limit; +static pid_t child_pid = -1; -int local_flag = PASSED; -char *TCID = "mmapstress06"; //mfile_swap -FILE *temp; -int TST_TOTAL = 1; +static void run_test(void) +{ + cg_child = tst_cg_group_mk(tst_cg, "child"); -int anyfail(); -void ok_exit(); -/***** ** ** *****/ + /* Set memory limit to force swapping of the mapping */ + SAFE_CG_PRINTF(cg_child, "memory.max", "%lu", (unsigned long)mem_limit); -#define ANON_GRAN_PAGES_MAX (32U) + if (TST_CG_VER_IS_V1(cg_child, "memory")) + SAFE_CG_PRINT(cg_child, "memory.swap.max", "-1"); + else + SAFE_CG_PRINT(cg_child, "memory.swap.max", "max"); -extern time_t time(time_t *); -extern char *ctime(const time_t *); -extern int atoi(const char *); + child_pid = SAFE_FORK(); + if (!child_pid) { + char *mmapaddr; + unsigned long cg_swap_before = 0, cg_swap_after = 0; -#define NMFPTEPG (1024) -#define ERROR(M) (void)fprintf(stderr, "%s: errno = %d; " M "\n", \ - argv[0], errno); + /* Move child to the constrained cgroup */ + SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid()); -int main(int argc, char *argv[]) -{ - caddr_t mmapaddr; - size_t pagesize = sysconf(_SC_PAGE_SIZE); - time_t t; - int sleep_time = 0; - - if (!argc) { - (void)fprintf(stderr, "argc == 0\n"); - anyfail(); - } - if (argc != 2 || !(sleep_time = atoi(argv[1]))) { - (void)fprintf(stderr, "usage: %s sleep_time\n", argv[0]); - anyfail(); - } - (void)time(&t); -// (void)printf("%s: Started %s", argv[0], ctime(&t)); LTP Port - if (sbrk(pagesize - ((ulong) sbrk(0) & (pagesize - 1))) == (char *)-1) { - ERROR("couldn't round up brk"); - anyfail(); - } - if ((mmapaddr = sbrk(0)) == (char *)-1) { - ERROR("couldn't find top of brk"); - anyfail(); - } - /* mmapaddr is now on a page boundary after the brk segment */ - if (mmap - (mmapaddr, (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1) * pagesize, - PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, - 0) == (caddr_t) - 1) { - ERROR("large mmap failed"); - printf("for this test to run, it needs a mmap space of\n"); - printf("%d pages\n", (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1)); - return 1; + SAFE_CG_SCANF(cg_child, "memory.swap.current", "%lu", &cg_swap_before); + + mmapaddr = SAFE_MMAP(NULL, map_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_SHARED, -1, 0); + + /* + * Disable Transparent Huge Pages (THP) for this mapping. + * Under tight cgroup memory limits (128 MB), allocating huge + * pages can easily trigger MemCG OOM-kills. Disabling THP forces + * standard 4 KB pages, ensuring stable swapping and avoiding + * premature OOM. + */ + if (madvise(mmapaddr, map_size, MADV_NOHUGEPAGE) < 0) + tst_res(TWARN | TERRNO, "madvise(MADV_NOHUGEPAGE) failed"); + + tst_res(TINFO, "Dirtying %zu bytes in child", map_size); + + for (size_t i = 0; i < map_size; i += page_size) + mmapaddr[i] = 'a'; + + SAFE_CG_SCANF(cg_child, "memory.swap.current", "%lu", &cg_swap_after); + + if (cg_swap_after > cg_swap_before) { + tst_res(TPASS, "Cgroup swap usage increased from %lu MB to %lu MB", + cg_swap_before / TST_MB, cg_swap_after / TST_MB); + } else { + tst_res(TFAIL, "Cgroup swap usage did not increase (before: %lu B, after: %lu B)", + cg_swap_before, cg_swap_after); + } + + SAFE_MUNMAP(mmapaddr, map_size); + exit(0); } - (void)sleep(sleep_time); - (void)time(&t); -// (void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP Port - ok_exit(); - tst_exit(); + + SAFE_WAITPID(child_pid, NULL, 0); + child_pid = -1; + + cg_child = tst_cg_group_rm(cg_child); } -/***** LTP Port *****/ -void ok_exit(void) +static void setup(void) { - tst_resm(TPASS, "Test passed"); - tst_exit(); + if (!SAFE_CG_HAS(tst_cg, "memory.swap.max")) + tst_brk(TCONF, "Cgroup swap controller is not enabled/supported"); + + page_size = getpagesize(); + + mem_limit = 128 * TST_MB; + map_size = 256 * TST_MB; } -int anyfail(void) +static void cleanup(void) { - tst_brkm(TFAIL, NULL, "Test failed"); + if (child_pid > 0) { + SAFE_KILL(child_pid, SIGKILL); + SAFE_WAITPID(child_pid, NULL, 0); + } + + if (cg_child) { + SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid()); + cg_child = tst_cg_group_rm(cg_child); + } } -/***** ** ** *****/ +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .forks_child = 1, + .needs_root = 1, + .needs_cgroup_ctrls = (const char *const []){ "memory", NULL }, + .min_mem_avail = 256, + .min_swap_avail = 128, + .needs_kconfigs = (const char *[]) { + "CONFIG_SWAP=y", + "CONFIG_MEMCG=y", + NULL + }, +}; -- 2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [LTP] mmapstress06: Convert to new API 2026-06-07 4:52 ` [LTP] [PATCH v4] " Wei Gao via ltp @ 2026-06-07 8:02 ` linuxtestproject.agent 2026-06-08 2:52 ` [LTP] [PATCH v5] " Wei Gao via ltp 1 sibling, 0 replies; 25+ messages in thread From: linuxtestproject.agent @ 2026-06-07 8:02 UTC (permalink / raw) To: Wei Gao; +Cc: ltp Hi Wei, On Sun, 07 Jun 2026 04:52:06 +0000, Wei Gao wrote: > mmapstress06: Convert to new API > +static void cleanup(void) > +{ > + if (child_pid > 0) { > + SAFE_KILL(child_pid, SIGKILL); > + SAFE_WAITPID(child_pid, NULL, 0); > + } > + > + if (cg_child) { > + SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid()); > + cg_child = tst_cg_group_rm(cg_child); > + } > +} The drain step moves the parent process into tst_cg_drain, but the parent was never placed into cg_child -- only the forked child was (via SAFE_CG_PRINTF(cg_child, "cgroup.procs", ...) inside the child block). After SAFE_KILL + SAFE_WAITPID, the child has exited and the kernel has already removed it from cg_child, so the cgroup is empty and tst_cg_group_rm() can be called directly. Draining the parent out of its current cgroup (tst_cg, managed by the framework) into tst_cg_drain leaves the test process in the wrong cgroup after cleanup. Compare with ksm02.c, where the drain is correct because the parent explicitly moves itself into a child cgroup first. The fix is to drop the SAFE_CG_PRINTF(tst_cg_drain, ...) line: if (cg_child) cg_child = tst_cg_group_rm(cg_child); 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] 25+ messages in thread
* [LTP] [PATCH v5] mmapstress06: Convert to new API 2026-06-07 4:52 ` [LTP] [PATCH v4] " Wei Gao via ltp 2026-06-07 8:02 ` [LTP] " linuxtestproject.agent @ 2026-06-08 2:52 ` Wei Gao via ltp 2026-06-08 4:51 ` [LTP] " linuxtestproject.agent 2026-06-10 2:26 ` [LTP] [PATCH v5] " Li Wang 1 sibling, 2 replies; 25+ messages in thread From: Wei Gao via ltp @ 2026-06-08 2:52 UTC (permalink / raw) To: ltp Convert the mmapstress06 test case from the legacy LTP API to the new tst_test API. Refactor and redesign the test to be active instead of passive: - Replaced the passive sleep-based synchronization with an active cgroup constrained memory stress test compatible with both cgroups v1 and v2. - Dirties all pages of a 256MB shared anonymous mapping inside the child cgroup, forcing the kernel to swap out memory when hitting the 128MB limit. - Disables Transparent Huge Pages (THP) on the mapping using madvise(..., MADV_NOHUGEPAGE) to avoid triggering cgroup OOM-kills. - Added CONFIG_SWAP=y and CONFIG_MEMCG=y kernel configuration checks. - Utilized declarative .min_mem_avail and .min_swap_avail for framework-level resource validation. Signed-off-by: Wei Gao <wegao@suse.com> --- v4->v5: - Dropping the redundant SAFE_CG_PRINTF(tst_cg_drain, ...) runtest/mm | 2 +- .../kernel/mem/mmapstress/mmapstress06.c | 193 ++++++++++-------- 2 files changed, 104 insertions(+), 91 deletions(-) diff --git a/runtest/mm b/runtest/mm index 41d624ad8..7d75b65c8 100644 --- a/runtest/mm +++ b/runtest/mm @@ -41,7 +41,7 @@ mmapstress02 mmapstress02 mmapstress03 mmapstress03 mmapstress04 mmapstress04 mmapstress05 mmapstress05 -mmapstress06 mmapstress06 20 +mmapstress06 mmapstress06 mmapstress07 TMPFILE=`mktemp $TMPDIR/example.XXXXXXXXXXXX`; mmapstress07 $TMPFILE mmapstress08 mmapstress08 mmapstress09 mmapstress09 -p 20 -t 0.2 diff --git a/testcases/kernel/mem/mmapstress/mmapstress06.c b/testcases/kernel/mem/mmapstress/mmapstress06.c index 37b7edc84..56f562139 100644 --- a/testcases/kernel/mem/mmapstress/mmapstress06.c +++ b/testcases/kernel/mem/mmapstress/mmapstress06.c @@ -1,116 +1,129 @@ -/* IBM Corporation */ -/* 01/02/2003 Port to LTP avenkat@us.ibm.com */ -/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (c) International Business Machines Corp., 2003 - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) International Business Machines Corp., 2003 + * Copyright (c) 2026 Linux Test Project + */ + +/*\ + * Test :manpage:`mmap(2)` with swap behavior. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * Mmap a large anonymous shared region and force it to be swapped out + * by setting memory limits using Cgroups and dirtying all pages. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * This test requires root privileges because configuring cgroup memory + * limits requires administrative access. */ -/* - * mfile_swap: - * Mmap a large (> ANON_GRAN_PAGES_MAX) shared, anonymous region before - * swapping to use the second half of the kernel primitive mfile_swap. - * However, this test does _NOT_ cause swapping to occur. Instead it should be - * run with waves or at the same time as a test which does cause swapping (i.e. - * vsswapin or vfork_swap) - */ -#define _KMEMUSER +#define _GNU_SOURCE #include <sys/types.h> #include <sys/mman.h> +#include <sys/wait.h> #include <unistd.h> #include <stdio.h> #include <errno.h> +#include <stdlib.h> +#include "tst_test.h" -/***** LTP Port *****/ -#include "test.h" -#define FAILED 0 -#define PASSED 1 +static struct tst_cg_group *cg_child; +static int page_size; +static size_t map_size; +static size_t mem_limit; +static pid_t child_pid = -1; -int local_flag = PASSED; -char *TCID = "mmapstress06"; //mfile_swap -FILE *temp; -int TST_TOTAL = 1; +static void run_test(void) +{ + cg_child = tst_cg_group_mk(tst_cg, "child"); -int anyfail(); -void ok_exit(); -/***** ** ** *****/ + /* Set memory limit to force swapping of the mapping */ + SAFE_CG_PRINTF(cg_child, "memory.max", "%lu", (unsigned long)mem_limit); -#define ANON_GRAN_PAGES_MAX (32U) + if (TST_CG_VER_IS_V1(cg_child, "memory")) + SAFE_CG_PRINT(cg_child, "memory.swap.max", "-1"); + else + SAFE_CG_PRINT(cg_child, "memory.swap.max", "max"); -extern time_t time(time_t *); -extern char *ctime(const time_t *); -extern int atoi(const char *); + child_pid = SAFE_FORK(); + if (!child_pid) { + char *mmapaddr; + unsigned long cg_swap_before = 0, cg_swap_after = 0; -#define NMFPTEPG (1024) -#define ERROR(M) (void)fprintf(stderr, "%s: errno = %d; " M "\n", \ - argv[0], errno); + /* Move child to the constrained cgroup */ + SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid()); -int main(int argc, char *argv[]) -{ - caddr_t mmapaddr; - size_t pagesize = sysconf(_SC_PAGE_SIZE); - time_t t; - int sleep_time = 0; - - if (!argc) { - (void)fprintf(stderr, "argc == 0\n"); - anyfail(); - } - if (argc != 2 || !(sleep_time = atoi(argv[1]))) { - (void)fprintf(stderr, "usage: %s sleep_time\n", argv[0]); - anyfail(); - } - (void)time(&t); -// (void)printf("%s: Started %s", argv[0], ctime(&t)); LTP Port - if (sbrk(pagesize - ((ulong) sbrk(0) & (pagesize - 1))) == (char *)-1) { - ERROR("couldn't round up brk"); - anyfail(); - } - if ((mmapaddr = sbrk(0)) == (char *)-1) { - ERROR("couldn't find top of brk"); - anyfail(); - } - /* mmapaddr is now on a page boundary after the brk segment */ - if (mmap - (mmapaddr, (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1) * pagesize, - PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, - 0) == (caddr_t) - 1) { - ERROR("large mmap failed"); - printf("for this test to run, it needs a mmap space of\n"); - printf("%d pages\n", (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1)); - return 1; + SAFE_CG_SCANF(cg_child, "memory.swap.current", "%lu", &cg_swap_before); + + mmapaddr = SAFE_MMAP(NULL, map_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_SHARED, -1, 0); + + /* + * Disable Transparent Huge Pages (THP) for this mapping. + * Under tight cgroup memory limits (128 MB), allocating huge + * pages can easily trigger MemCG OOM-kills. Disabling THP forces + * standard 4 KB pages, ensuring stable swapping and avoiding + * premature OOM. + */ + if (madvise(mmapaddr, map_size, MADV_NOHUGEPAGE) < 0) + tst_res(TWARN | TERRNO, "madvise(MADV_NOHUGEPAGE) failed"); + + tst_res(TINFO, "Dirtying %zu bytes in child", map_size); + + for (size_t i = 0; i < map_size; i += page_size) + mmapaddr[i] = 'a'; + + SAFE_CG_SCANF(cg_child, "memory.swap.current", "%lu", &cg_swap_after); + + if (cg_swap_after > cg_swap_before) { + tst_res(TPASS, "Cgroup swap usage increased from %lu MB to %lu MB", + cg_swap_before / TST_MB, cg_swap_after / TST_MB); + } else { + tst_res(TFAIL, "Cgroup swap usage did not increase (before: %lu B, after: %lu B)", + cg_swap_before, cg_swap_after); + } + + SAFE_MUNMAP(mmapaddr, map_size); + exit(0); } - (void)sleep(sleep_time); - (void)time(&t); -// (void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP Port - ok_exit(); - tst_exit(); + + SAFE_WAITPID(child_pid, NULL, 0); + child_pid = -1; + + cg_child = tst_cg_group_rm(cg_child); } -/***** LTP Port *****/ -void ok_exit(void) +static void setup(void) { - tst_resm(TPASS, "Test passed"); - tst_exit(); + if (!SAFE_CG_HAS(tst_cg, "memory.swap.max")) + tst_brk(TCONF, "Cgroup swap controller is not enabled/supported"); + + page_size = getpagesize(); + + mem_limit = 128 * TST_MB; + map_size = 256 * TST_MB; } -int anyfail(void) +static void cleanup(void) { - tst_brkm(TFAIL, NULL, "Test failed"); + if (child_pid > 0) { + SAFE_KILL(child_pid, SIGKILL); + SAFE_WAITPID(child_pid, NULL, 0); + } + + if (cg_child) + cg_child = tst_cg_group_rm(cg_child); } -/***** ** ** *****/ +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .forks_child = 1, + .needs_root = 1, + .needs_cgroup_ctrls = (const char *const []){ "memory", NULL }, + .min_mem_avail = 256, + .min_swap_avail = 128, + .needs_kconfigs = (const char *[]) { + "CONFIG_SWAP=y", + "CONFIG_MEMCG=y", + NULL + }, +}; -- 2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [LTP] mmapstress06: Convert to new API 2026-06-08 2:52 ` [LTP] [PATCH v5] " Wei Gao via ltp @ 2026-06-08 4:51 ` linuxtestproject.agent 2026-06-10 2:26 ` [LTP] [PATCH v5] " Li Wang 1 sibling, 0 replies; 25+ messages in thread From: linuxtestproject.agent @ 2026-06-08 4:51 UTC (permalink / raw) To: Wei Gao; +Cc: ltp Hi Wei, On Mon, Jun 8, 2026 at 02:52:05AM +0000, Wei Gao wrote: > mmapstress06: Convert to new API 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] 25+ messages in thread
* Re: [LTP] [PATCH v5] mmapstress06: Convert to new API 2026-06-08 2:52 ` [LTP] [PATCH v5] " Wei Gao via ltp 2026-06-08 4:51 ` [LTP] " linuxtestproject.agent @ 2026-06-10 2:26 ` Li Wang 1 sibling, 0 replies; 25+ messages in thread From: Li Wang @ 2026-06-10 2:26 UTC (permalink / raw) To: Wei Gao; +Cc: ltp Wei Gao wrote: > + > + mmapaddr = SAFE_MMAP(NULL, map_size, PROT_READ | PROT_WRITE, > + MAP_ANONYMOUS | MAP_SHARED, -1, 0); > + > + /* > + * Disable Transparent Huge Pages (THP) for this mapping. > + * Under tight cgroup memory limits (128 MB), allocating huge > + * pages can easily trigger MemCG OOM-kills. Disabling THP forces > + * standard 4 KB pages, ensuring stable swapping and avoiding > + * premature OOM. > + */ > + if (madvise(mmapaddr, map_size, MADV_NOHUGEPAGE) < 0) > + tst_res(TWARN | TERRNO, "madvise(MADV_NOHUGEPAGE) failed"); The key point is that this is a MAP_ANONYMOUS | MAP_SHARED mapping. Shared anonymous memory isn't backed by the normal anonymous-THP machinery, it's backed internally by shmem/tmpfs. THP behavior for shmem is governed by a separate knob: # cat /sys/kernel/mm/transparent_hugepage/shmem_enabled always within_size advise [never] deny force basically all distro kernels this defaults to never. So in the default configuration, no huge pages would ever be allocated for this mapping, and the madvise(MADV_NOHUGEPAGE) is effectively a no-op. -- Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2026-06-10 2:27 UTC | newest] Thread overview: 25+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-04-27 11:59 [LTP] [PATCH v1] mmapstress06: TCONF on systems without swap space Wei Gao via ltp 2026-04-27 12:26 ` Li Wang 2026-04-27 13:57 ` Wei Gao via ltp 2026-04-28 1:39 ` Li Wang 2026-04-27 13:57 ` [LTP] " linuxtestproject.agent 2026-04-28 11:52 ` [LTP] [PATCH v1] " Andrea Cervesato via ltp 2026-04-28 12:58 ` Petr Vorel 2026-04-28 16:34 ` Petr Vorel 2026-04-29 2:22 ` Wei Gao via ltp 2026-04-29 6:10 ` Petr Vorel 2026-04-30 8:01 ` Li Wang 2026-06-05 4:29 ` [LTP] [PATCH v2] mmapstress06: Convert to new API Wei Gao via ltp 2026-06-05 5:28 ` [LTP] " linuxtestproject.agent 2026-06-05 7:11 ` Li Wang 2026-06-05 7:17 ` [LTP] [PATCH v2] " Andrea Cervesato via ltp 2026-06-05 9:35 ` Wei Gao via ltp 2026-06-05 9:42 ` Andrea Cervesato via ltp 2026-06-05 10:02 ` Wei Gao via ltp 2026-06-06 10:08 ` [LTP] [PATCH v3] " Wei Gao via ltp 2026-06-06 11:32 ` [LTP] " linuxtestproject.agent 2026-06-07 4:52 ` [LTP] [PATCH v4] " Wei Gao via ltp 2026-06-07 8:02 ` [LTP] " linuxtestproject.agent 2026-06-08 2:52 ` [LTP] [PATCH v5] " Wei Gao via ltp 2026-06-08 4:51 ` [LTP] " linuxtestproject.agent 2026-06-10 2:26 ` [LTP] [PATCH v5] " Li Wang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox