Skip to contentSkip to conversation

mmapstress06: TCONF on systems without swap space

PATCH In review Wei Gao via ltp 4 participants 30 messages Apr 27 – Jun 12

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmapstress06: TCONF on systems without swap space

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.

---
 testcases/kernel/mem/mmapstress/mmapstress06.c | 8 ++++++++
 1 file changed, 8 insertions(+)
testcases/kernel/mem/mmapstress/mmapstress06.c +8 -0
index 37b7edc84..54b5febbf 100644
@@ -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) {
Signature · 5 lines
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Wei,

Quoted 6 lines · Wei Gao via 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:

Quoted 8 lines

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.

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 15 lines

Hi Wei,

Quoted 10 lines · Wei Gao via 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

Quoted 7 lines
Quoted 4 lines

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?

Quoted 2 lines

And, it'd be appreciated if you can convert it into new LTP API.

No problem from my side.

Quoted 4 lines
Signature · 3 lines
-- 
Regards,
Li Wang
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by
#3 lore raw
Quoted 20 lines · Wei Gao via ltp
Quoted 20 lines

Hi Wei,

Quoted 14 lines · Wei Gao via 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.

Quoted 5 lines
Quoted 2 lines

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.

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by LTP AI Reviewer on v1 1/1
#4 lore raw
In reply to Wei Gao via ltp

Hi Wei,

Quoted 3 lines · Wei Gao

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.

testcases/kernel/mem/mmapstress/mmapstress06.c int main(int argc, char *argv[]) · line 83

Quoted 4 lines
testcases/kernel/mem/mmapstress/mmapstress06.c +4 -0
+	if (tst_available_swap() <= 0) {
+		tst_resm(TCONF, "Test requires swap space to exercise mfile_swap logic");
+		tst_exit();
+	}

---
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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw
In reply to Wei Gao via ltp

Hi all,

Quoted 34 lines

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.

---
 testcases/kernel/mem/mmapstress/mmapstress06.c | 8 ++++++++
 1 file changed, 8 insertions(+)
testcases/kernel/mem/mmapstress/mmapstress06.c +2 -0
index 37b7edc84..54b5febbf 100644
@@ -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 *);

testcases/kernel/mem/mmapstress/mmapstress06.c int main(int argc, char *argv[]) · line 81

Quoted 6 lines
testcases/kernel/mem/mmapstress/mmapstress06.c +3 -0
@@ -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?

testcases/kernel/mem/mmapstress/mmapstress06.c int main(int argc, char *argv[]) · line 82

Quoted 1 line
testcases/kernel/mem/mmapstress/mmapstress06.c +1 -0
+		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.

testcases/kernel/mem/mmapstress/mmapstress06.c int main(int argc, char *argv[]) · line 83

Quoted 1 line
testcases/kernel/mem/mmapstress/mmapstress06.c +1 -0
+	}

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);

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Hi all,

Quoted 3 lines

Hi all,

Quoted 1 line

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.

Quoted 4 lines
Quoted 4 lines

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

Quoted 12 lines
Quoted 12 lines

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.

---
 testcases/kernel/mem/mmapstress/mmapstress06.c | 8 ++++++++

...

Quoted 33 lines

testcases/kernel/mem/mmapstress/mmapstress06.c int main(int argc, char *argv[]) · line 81

Quoted 2 lines
testcases/kernel/mem/mmapstress/mmapstress06.c +2 -0
+	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?

testcases/kernel/mem/mmapstress/mmapstress06.c int main(int argc, char *argv[]) · line 82

Quoted 1 line
testcases/kernel/mem/mmapstress/mmapstress06.c +1 -0
+		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.

testcases/kernel/mem/mmapstress/mmapstress06.c int main(int argc, char *argv[]) · line 83

Quoted 1 line
testcases/kernel/mem/mmapstress/mmapstress06.c +1 -0
+	}

How about this? (with cleanup of ugly printf).

Kind regards,
Petr

+++ testcases/kernel/mem/mmapstress/mmapstress06.c

(quoted diff) +6 -4
@@ -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);
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw
Quoted 14 lines · Petr Vorel

Hi all,

Quoted 3 lines

Hi all,

Quoted 1 line

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.

Quoted 4 lines
Quoted 4 lines

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:

Quoted 5 lines

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?

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw
Quoted 21 lines · Petr Vorel
Quoted 14 lines

Hi all,

Quoted 3 lines

Hi all,

Quoted 1 line

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.

Quoted 4 lines
Quoted 4 lines

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:

Quoted 4 lines

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).

Quoted 6 lines

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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw
In reply to Wei Gao via ltp

Hi Wei, Petr,

Quoted 6 lines · Wei Gao via ltp

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

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#11 lore raw

PATCH v2 1/1 mmapstress06: Convert to new API

In reply to Wei Gao via 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.

---
 runtest/mm                                    |   2 +-
 .../kernel/mem/mmapstress/mmapstress06.c      | 200 ++++++++++--------
 2 files changed, 111 insertions(+), 91 deletions(-)
runtest/mm +1 -1
index 41d624ad8..7d75b65c8 100644
@@ -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
testcases/kernel/mem/mmapstress/mmapstress06.c +110 -90

226 lines not on this page · raw message

Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

Re: [LTP] mmapstress06: Convert to new API

Hi Wei,

Quoted 4 lines · Wei Gao

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.

testcases/kernel/mem/mmapstress/mmapstress06.c line 26

Quoted 2 lines
testcases/kernel/mem/mmapstress/mmapstress06.c +2 -0
+#include "tst_test.h"
+#include "tst_safe_macros.h"

tst_test.h already includes tst_safe_macros.h; the second include is redundant.

testcases/kernel/mem/mmapstress/mmapstress06.c line 82

Quoted 1 line
testcases/kernel/mem/mmapstress/mmapstress06.c +1 -0
+	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).

testcases/kernel/mem/mmapstress/mmapstress06.c line 104

Quoted 4 lines
testcases/kernel/mem/mmapstress/mmapstress06.c +4 -0
+	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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

Re: [LTP] mmapstress06: Convert to new API

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.

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw

Re: [LTP] [PATCH v2] mmapstress06: Convert to new API

In reply to Wei Gao via 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
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#15 lore raw

Re: [LTP] [PATCH v2] mmapstress06: Convert to new API

Quoted 5 lines · Andrea Cervesato

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.

Quoted 6 lines

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#16 lore raw

Re: [LTP] [PATCH v2] mmapstress06: Convert to new API

Quoted 3 lines

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
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#17 lore raw

Re: [LTP] [PATCH v2] mmapstress06: Convert to new API

Quoted 6 lines · Andrea Cervesato
Quoted 3 lines

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.

Quoted 8 lines

I updated the agent, make sure to run ./setup <agent> again before doing it.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#18 lore raw

PATCH v3 1/1 mmapstress06: Convert to new API

In reply to Wei Gao via 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.

---
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(-)
runtest/mm +1 -1
index 41d624ad8..7d75b65c8 100644
@@ -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
testcases/kernel/mem/mmapstress/mmapstress06.c +110 -90

226 lines not on this page · raw message

Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#19 lore raw

Re: [LTP] mmapstress06: Convert to new API

Hi Wei,

testcases/kernel/mem/mmapstress/mmapstress06.c line 93

Quoted 7 lines · Wei Gao

mmapstress06: Convert to new API

testcases/kernel/mem/mmapstress/mmapstress06.c +5 -0
+	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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#20 lore raw

PATCH v4 1/1 mmapstress06: Convert to new API

In reply to Wei Gao via 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.

---
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(-)
runtest/mm +1 -1
index 41d624ad8..7d75b65c8 100644
@@ -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
testcases/kernel/mem/mmapstress/mmapstress06.c +105 -90

221 lines not on this page · raw message

Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#21 lore raw

Re: [LTP] mmapstress06: Convert to new API

Hi Wei,

Quoted 4 lines · Wei Gao

mmapstress06: Convert to new API

testcases/kernel/mem/mmapstress/mmapstress06.c +2 -0
+static void cleanup(void)
+{

testcases/kernel/mem/mmapstress/mmapstress06.c

Quoted 10 lines
testcases/kernel/mem/mmapstress/mmapstress06.c +10 -0
+	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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#22 lore raw

PATCH v5 1/1 mmapstress06: Convert to new API

In reply to Wei Gao via 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.

---

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(-)
runtest/mm +1 -1
index 41d624ad8..7d75b65c8 100644
@@ -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
testcases/kernel/mem/mmapstress/mmapstress06.c +103 -90

219 lines not on this page · raw message

Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#23 lore raw

Re: [LTP] mmapstress06: Convert to new API

Hi Wei,

Quoted 1 line · Wei Gao

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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#24 lore raw

Re: [LTP] [PATCH v5] mmapstress06: Convert to new API

In reply to Wei Gao via ltp
Quoted 4 lines · Wei Gao
testcases/kernel/mem/mmapstress/mmapstress06.c +4 -0
+
+		mmapaddr = SAFE_MMAP(NULL, map_size, PROT_READ | PROT_WRITE,
+				     MAP_ANONYMOUS | MAP_SHARED, -1, 0);
+

testcases/kernel/mem/mmapstress/mmapstress06.c line 66

Quoted 10 lines
testcases/kernel/mem/mmapstress/mmapstress06.c +9 -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.

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#25 lore raw

PATCH v6 1/1 mmapstress06: Convert to new API

In reply to Wei Gao via 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.
- Rate limits page dirtying by introducing a page-size independent 1ms sleep every 64KB (i.e. usleep(1000) when i % 64KB == 0) to allow the kernel's asynchronous swap writeback to stably reclaim pages and prevent MemCG OOM-kills on all architectures (e.g. standard 4KB or 64KB page size).
- 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.

---
v5->v6:
* Removed MADV_NOHUGEPAGE.
* Added rate limit: Sleep 1ms every 64KB to limit dirtying speed, preventing MemCG OOM-kills.

 runtest/mm                                    |   2 +-
 .../kernel/mem/mmapstress/mmapstress06.c      | 186 +++++++++---------
 2 files changed, 97 insertions(+), 91 deletions(-)
runtest/mm +1 -1
index 41d624ad8..7d75b65c8 100644
@@ -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
testcases/kernel/mem/mmapstress/mmapstress06.c +96 -90

212 lines not on this page · raw message

Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#26 lore raw

Re: [LTP] mmapstress06: Convert to new API

Hi Wei,

Quoted 1 line · Wei Gao

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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#27 lore raw

PATCH v7 1/1 mmapstress06: Convert to new API

In reply to Wei Gao via 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.
- Rate limits page dirtying by introducing a page-size independent 1ms sleep every 2MB (i.e. usleep(1000) when i % 2MB == 0) to allow the kernel's asynchronous swap writeback to stably reclaim pages and prevent MemCG OOM-kills on all architectures (e.g. standard 4KB or 64KB page size) while optimizing execution speed.
- 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.

---

v6->v7:
- Change rate-limit sleep interval from 64KB to 2MB to optimize execution time.

 runtest/mm                                    |   2 +-
 .../kernel/mem/mmapstress/mmapstress06.c      | 186 +++++++++---------
 2 files changed, 97 insertions(+), 91 deletions(-)
runtest/mm +1 -1
index 41d624ad8..7d75b65c8 100644
@@ -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
testcases/kernel/mem/mmapstress/mmapstress06.c +96 -90

212 lines not on this page · raw message

Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#28 lore raw

Re: [LTP] mmapstress06: Convert to new API

Hi Wei,

Quoted 1 line · Wei Gao

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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#29 lore raw

Re: [LTP] [PATCH v7] mmapstress06: Convert to new API

In reply to Wei Gao via ltp

Patch merged, thanks!

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp