Skip to contentSkip to conversation

mmap21.c: Test for new MAP_DROPPABLE flag for mmap

PATCH Superseded Wei Gao via ltp 3 participants 20 messages Dec 28, 2024 – May 14, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmap21.c: Test for new MAP_DROPPABLE flag for mmap

---
 include/lapi/mmap.h                       |  4 ++
 runtest/syscalls                          |  1 +
 testcases/kernel/syscalls/mmap/.gitignore |  1 +
 testcases/kernel/syscalls/mmap/mmap21.c   | 73 +++++++++++++++++++++++
 4 files changed, 79 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mmap/mmap21.c
include/lapi/mmap.h +4 -0
index ea9730586..248b64564 100644
@@ -87,6 +87,10 @@
 # define MADV_PAGEOUT	21
 #endif
 
+#ifndef MAP_DROPPABLE
+# define MAP_DROPPABLE 0x08
+#endif
+
 #ifndef MAP_FIXED_NOREPLACE
 
 #ifdef __alpha__
runtest/syscalls +1 -0
index ded035ee8..7166e39a4 100644
@@ -840,6 +840,7 @@ mmap17 mmap17
 mmap18 mmap18
 mmap19 mmap19
 mmap20 mmap20
+mmap21 mmap21
 
 modify_ldt01 modify_ldt01
 modify_ldt02 modify_ldt02
testcases/kernel/syscalls/mmap/.gitignore +1 -0
index 4591fdbb9..87b23aaee 100644
@@ -18,3 +18,4 @@
 /mmap18
 /mmap19
 /mmap20
+/mmap21
testcases/kernel/syscalls/mmap/mmap21.c new file +73 -0

73 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw
Quoted 66 lines · Wei Gao via ltp
---
 include/lapi/mmap.h                       |  4 ++
 runtest/syscalls                          |  1 +
 testcases/kernel/syscalls/mmap/.gitignore |  1 +
 testcases/kernel/syscalls/mmap/mmap21.c   | 73 +++++++++++++++++++++++
 4 files changed, 79 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mmap/mmap21.c
include/lapi/mmap.h +4 -0
index ea9730586..248b64564 100644
@@ -87,6 +87,10 @@
 # define MADV_PAGEOUT  21
 #endif
 
+#ifndef MAP_DROPPABLE
+# define MAP_DROPPABLE 0x08
+#endif
+
 #ifndef MAP_FIXED_NOREPLACE
 
 #ifdef __alpha__
runtest/syscalls +1 -0
index ded035ee8..7166e39a4 100644
@@ -840,6 +840,7 @@ mmap17 mmap17
 mmap18 mmap18
 mmap19 mmap19
 mmap20 mmap20
+mmap21 mmap21
 
 modify_ldt01 modify_ldt01
 modify_ldt02 modify_ldt02
testcases/kernel/syscalls/mmap/.gitignore +1 -0
index 4591fdbb9..87b23aaee 100644
@@ -18,3 +18,4 @@
 /mmap18
 /mmap19
 /mmap20
+/mmap21
testcases/kernel/syscalls/mmap/mmap21.c new file +12 -0
new file mode 100644
index 000000000..e2b8c4551
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2024 Wei Gao <[email protected]>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test mmap(2) with MAP_DROPPABLE flag.
+ *
+ * Test base on kernel selftests/mm/droppable.c
+ */

testcases/kernel/syscalls/mmap/mmap21.c line 22

Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap21.c new file +10 -0
+
+#include <errno.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include "tst_test.h"
+#include "lapi/mmap.h"
+
+static void test_mmap(void)
+{
+       size_t alloc_size = 134217728;

Maybe define MB as 1024 * 1024 then,
size_t alloc_size = 128*MB;

Quoted 16 lines
testcases/kernel/syscalls/mmap/mmap21.c new file +14 -0
+       size_t page_size = getpagesize();
+       void *alloc;
+       pid_t child;
+
+       alloc = SAFE_MMAP(0, alloc_size, PROT_READ | PROT_WRITE,
+                       MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
+
+       memset(alloc, 'A', alloc_size);
+       for (size_t i = 0; i < alloc_size; i += page_size) {
+               if (*(char *)(alloc + i) != 'A')
+                       tst_res(TFAIL, "memset failed");
+       }
+
+       int *shared_var = SAFE_MMAP(NULL, sizeof(int), PROT_READ |

PROT_WRITE,

testcases/kernel/syscalls/mmap/mmap21.c line 46

Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap21.c new file +10 -0
+                       MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+
+       *shared_var = 0;
+
+       child = SAFE_FORK();
+       if (!child) {
+               for (;;) {
+                       *(char *)malloc(page_size) = 'B';
+                       if ((*shared_var) == 1)
+                               exit(0);

If the parent process crashes, hangs, or fails to detect reclaimed pages, the child process will run indefinitely, potentially consuming system resources.

If it runs too long, add a timeout mechanism to terminate the child process.

testcases/kernel/syscalls/mmap/mmap21.c line 50

Quoted 5 lines
testcases/kernel/syscalls/mmap/mmap21.c new file +4 -0
+               }
+       }
+
+       for (; !(*shared_var);) {

why not use while() loop.

+ for (size_t i = 0; i < alloc_size; i += page_size) {

testcases/kernel/syscalls/mmap/mmap21.c line 59

Quoted 9 lines
testcases/kernel/syscalls/mmap/mmap21.c new file +8 -0
+                       if (!*(uint8_t *)(alloc + i)) {
+                               *shared_var = 1;
+                               break;
+                       }
+               }
+       }
+
+       TST_EXP_EQ_LI((*shared_var), 1);

The test assumes that reclaimed MAP_DROPPABLE pages will be zeroed out when accessed. While this behavior is plausible, it depends on how MAP_DROPPABLE is implemented in the kernel.

Do you have any clue (documents or code) that indicates this is true?

testcases/kernel/syscalls/mmap/mmap21.c line 68

Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap21.c new file +9 -0
+
+       SAFE_WAITPID(child, NULL, 0);
+
+       SAFE_MUNMAP(alloc, alloc_size);
+       SAFE_MUNMAP(shared_var, sizeof(int));
+}
+
+static struct tst_test test = {
+       .min_kver = "6.11",

I would suggest removing this line because some distros might backport the syscall to their old enterprise version.

Then before running this test, the presence of MAP_DROPPABLE in the kernel should be verified, or the test should gracefully skip if the feature is
not supported.

testcases/kernel/syscalls/mmap/mmap21.c line 70

Quoted 3 lines
testcases/kernel/syscalls/mmap/mmap21.c new file +2 -0
+       .test_all = test_mmap,
+       .needs_tmpdir = 1,

add .min_mem_avail here.

testcases/kernel/syscalls/mmap/mmap21.c line 72

Quoted 3 lines
testcases/kernel/syscalls/mmap/mmap21.c new file +2 -0
+       .forks_child = 1,
+       .max_runtime = 180,

This max_runtime is useless if we run the test on a large RAM system which likely takes too long to simulate the memory pressure.

We could limit the test to an CGroup and set the memory.max to 256MB, which can complete the mem hog quickly to finish.

Quoted 9 lines

+};
--
2.35.3

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

Signature · 5 lines
Regards,
Li Wang

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

Hi!

Quoted 3 lines

Maybe define MB as 1024 * 1024 then,
size_t alloc_size = 128*MB;

We have TST_KB, TST_MB and TST_GB defined in the test library headers already.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Li Wang
Quoted 16 lines · Li Wang
Quoted 2 lines · Wei Gao via ltp

---

+ for (size_t i = 0; i < alloc_size; i += page_size) {

testcases/kernel/syscalls/mmap/mmap21.c line 59

Quoted 9 lines
testcases/kernel/syscalls/mmap/mmap21.c new file +8 -0
+                       if (!*(uint8_t *)(alloc + i)) {
+                               *shared_var = 1;
+                               break;
+                       }
+               }
+       }
+
+       TST_EXP_EQ_LI((*shared_var), 1);
Quoted 5 lines

The test assumes that reclaimed MAP_DROPPABLE pages will be zeroed out when accessed. While this behavior is plausible, it depends on how MAP_DROPPABLE is implemented in the kernel.

Do you have any clue (documents or code) that indicates this is true?

Thanks for your quick feedback , i will try to give clue for this:

1) Base the kernel commit message indicate memory will be zero.

commit 9651fcedf7b92d3f7f1ab179e8ab55b85ee10fc1

Author: Jason A. Donenfeld <[email protected]>
Date:   Thu Dec 8 17:55:04 2022 +0100

These characteristics mean that we can introduce VM_DROPPABLE, which has the following semantics:

a) It never is written out to swap.
b) Under memory pressure, mm can just drop the pages (so that they're zero when read back again). <<<<<<<<<<<<<<<<<
c) It is inherited by fork.
d) It doesn't count against the mlock budget, since nothing is locked.
e) If there's not enough memory to service a page fault, it's not fatal, and no signal is sent.

2) When kernel read back the dropped anonymous memory will trigger do_page_fault(), finally it will reach do_anonymous_page() and hit following line:
https://elixir.bootlin.com/linux/v4.6/source/mm/memory.c#L2750
So normally you will read zeroed memory.

Call stack happen when read back:

do_page_fault()
↓
handle_mm_fault()
↓
__handle_mm_fault()
↓
handle_pte_fault()
↓
do_pte_missing()
↓
do_anonymous_page()

Quoted 4 lines
Signature · 3 lines
-- 
Regards,
Li Wang
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
In reply to Li Wang
Quoted 21 lines · Li Wang
Quoted 4 lines · Wei Gao via ltp
(quoted diff) +2 -0
+
+       int *shared_var = SAFE_MMAP(NULL, sizeof(int), PROT_READ |

PROT_WRITE,

testcases/kernel/syscalls/mmap/mmap21.c line 46

Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap21.c new file +10 -0
+                       MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+
+       *shared_var = 0;
+
+       child = SAFE_FORK();
+       if (!child) {
+               for (;;) {
+                       *(char *)malloc(page_size) = 'B';
+                       if ((*shared_var) == 1)
+                               exit(0);

If the parent process crashes, hangs, or fails to detect reclaimed pages, the child process will run indefinitely, potentially consuming system resources.

Quoted 1 line

If it runs too long, add a timeout mechanism to terminate the child process.

After limit the test to an CGroup and set the memory.max = 256M(base your suggestion), i suppose we do not need this timeout mechanism, since after i test in my env, when the child run for ~3s, the system will trigger oom_memcg and kill the child. What's your opinion?

Quoted 22 lines

This max_runtime is useless if we run the test on a large RAM system which likely takes too long to simulate the memory pressure.

We could limit the test to an CGroup and set the memory.max to 256MB, which can complete the mem hog quickly to finish.

Quoted 9 lines

+};
--
2.35.3

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

Signature · 2 lines
Regards,
Li Wang
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

PATCH v2 1/1 mmap21.c: Test for new MAP_DROPPABLE flag for mmap

In reply to Wei Gao via ltp
---
 include/lapi/mmap.h                       |   4 +
 runtest/syscalls                          |   1 +
 testcases/kernel/syscalls/mmap/.gitignore |   1 +
 testcases/kernel/syscalls/mmap/mmap21.c   | 102 ++++++++++++++++++++++
 4 files changed, 108 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mmap/mmap21.c
include/lapi/mmap.h +4 -0
index ea9730586..248b64564 100644
@@ -87,6 +87,10 @@
 # define MADV_PAGEOUT	21
 #endif
 
+#ifndef MAP_DROPPABLE
+# define MAP_DROPPABLE 0x08
+#endif
+
 #ifndef MAP_FIXED_NOREPLACE
 
 #ifdef __alpha__
runtest/syscalls +1 -0
index ded035ee8..7166e39a4 100644
@@ -840,6 +840,7 @@ mmap17 mmap17
 mmap18 mmap18
 mmap19 mmap19
 mmap20 mmap20
+mmap21 mmap21
 
 modify_ldt01 modify_ldt01
 modify_ldt02 modify_ldt02
testcases/kernel/syscalls/mmap/.gitignore +1 -0
index 4591fdbb9..87b23aaee 100644
@@ -18,3 +18,4 @@
 /mmap18
 /mmap19
 /mmap20
+/mmap21
testcases/kernel/syscalls/mmap/mmap21.c new file +102 -0

102 lines not on this page · raw message

Signature · 5 lines
2.35.3


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

Hi!

Quoted 59 lines
testcases/kernel/syscalls/mmap/mmap21.c new file +53 -0
new file mode 100644
index 000000000..46f3ac7c5
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2024 Wei Gao <[email protected]>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test mmap(2) with MAP_DROPPABLE flag.
+ *
+ * Test base on kernel selftests/mm/droppable.c
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include "tst_test.h"
+#include "lapi/mmap.h"
+
+#define MEM_LIMIT (256 * TST_MB)
+#define ALLOC_SIZE (128 * TST_MB)
+
+static struct tst_cg_group *cg_child;
+
+static void test_mmap(void)
+{
+	size_t alloc_size = ALLOC_SIZE;
+	size_t page_size = getpagesize();
+	void *alloc;
+	pid_t child;
+
+	cg_child = tst_cg_group_mk(tst_cg, "child");
+	SAFE_CG_PRINTF(tst_cg, "memory.max", "%d", MEM_LIMIT);
+	SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid());
+
+	alloc = SAFE_MMAP(0, alloc_size, PROT_READ | PROT_WRITE,
+			MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
+
+	memset(alloc, 'A', alloc_size);
+	for (size_t i = 0; i < alloc_size; i += page_size) {
+		if (*(char *)(alloc + i) != 'A')
+			tst_res(TFAIL, "memset failed");
+	}
+
+	int *shared_var = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE,
+			MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+
+	*shared_var = 0;
+
+	child = SAFE_FORK();
+	if (!child) {
+		for (;;) {

testcases/kernel/syscalls/mmap/mmap21.c line 63

Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap21.c new file +10 -0
+			*(char *)malloc(page_size) = 'B';
+			if ((*shared_var) == 1)
+				exit(0);
+		}
+	}
+
+	while (!(*shared_var)) {
+		for (size_t i = 0; i < alloc_size; i += page_size) {
+			if (!*(uint8_t *)(alloc + i)) {
+				*shared_var = 1;

Why do we need the shared_var at all? Why can't we just SIGKILL the child at this point the same way the selftest does it?

Quoted 45 lines
testcases/kernel/syscalls/mmap/mmap21.c new file +39 -0
+				break;
+			}
+		}
+	}
+
+	TST_EXP_EQ_LI((*shared_var), 1);
+
+	SAFE_WAITPID(child, NULL, 0);
+
+	SAFE_MUNMAP(alloc, alloc_size);
+	SAFE_MUNMAP(shared_var, sizeof(int));
+}
+
+static void setup(void)
+{
+	void *addr = mmap(0, 1, PROT_READ | PROT_WRITE,
+			MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
+	if (addr == MAP_FAILED && errno == EINVAL)
+		tst_brk(TCONF, "MAP_DROPPABLE not support");
+}
+
+static void cleanup(void)
+{
+	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 = {
+	.test_all = test_mmap,
+	.needs_tmpdir = 1,
+	.forks_child = 1,
+	.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
+	.needs_root = 1,
+	.cleanup = cleanup,
+	.setup = setup,
+	.min_mem_avail = 300,
+};
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

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

PATCH v3 1/1 mmap22.c: Test for new MAP_DROPPABLE flag for mmap

In reply to Wei Gao via ltp
---
 include/lapi/mmap.h                       |  4 +
 runtest/syscalls                          |  1 +
 testcases/kernel/syscalls/mmap/.gitignore |  1 +
 testcases/kernel/syscalls/mmap/mmap22.c   | 95 +++++++++++++++++++++++
 4 files changed, 101 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mmap/mmap22.c
include/lapi/mmap.h +4 -0
index ea9730586..248b64564 100644
@@ -87,6 +87,10 @@
 # define MADV_PAGEOUT	21
 #endif
 
+#ifndef MAP_DROPPABLE
+# define MAP_DROPPABLE 0x08
+#endif
+
 #ifndef MAP_FIXED_NOREPLACE
 
 #ifdef __alpha__
runtest/syscalls +1 -0
index 932b7030c..e369536ea 100644
@@ -844,6 +844,7 @@ mmap19 mmap19
 mmap20 mmap20
 mmap21_01 mmap21 -m 1
 mmap21_02 mmap21
+mmap22 mmap22
 
 modify_ldt01 modify_ldt01
 modify_ldt02 modify_ldt02
testcases/kernel/syscalls/mmap/.gitignore +1 -0
index 850284d86..075be933d 100644
@@ -18,3 +18,4 @@
 /mmap19
 /mmap20
 /mmap21
+/mmap22
testcases/kernel/syscalls/mmap/mmap22.c new file +95 -0

95 lines not on this page · raw message

Signature · 5 lines
2.49.0


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

Re: [LTP] [PATCH v3] mmap22.c: Test for new MAP_DROPPABLE flag for mmap

Hi!

Quoted 20 lines
testcases/kernel/syscalls/mmap/mmap22.c new file +20 -0
+static void test_mmap(void)
+{
+	size_t alloc_size = ALLOC_SIZE;
+	size_t page_size = getpagesize();
+	void *alloc;
+	pid_t child;
+
+	cg_child = tst_cg_group_mk(tst_cg, "child");
+	SAFE_CG_PRINTF(tst_cg, "memory.max", "%d", MEM_LIMIT);
+	SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid());
+
+	alloc = SAFE_MMAP(0, alloc_size, PROT_READ | PROT_WRITE,
+			MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
+
+	memset(alloc, 'A', alloc_size);
+	for (size_t i = 0; i < alloc_size; i += page_size) {
+		if (*(char *)(alloc + i) != 'A')
+			tst_res(TFAIL, "memset failed");
+	}
+

testcases/kernel/syscalls/mmap/mmap22.c line 55

Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap22.c new file +10 -0
+	child = SAFE_FORK();
+	if (!child) {
+		for (;;)
+			*(char *)malloc(page_size) = 'B';
+	}
+
+	while (1) {
+		for (size_t i = 0; i < alloc_size; i += page_size) {
+			if (!tst_remaining_runtime())
+				tst_brk(TBROK, "MAP_DROPPABLE did not drop memory within the timeout period.");

This should rather be tst_res(TFAIL, ...) followed by goto kill_child;

testcases/kernel/syscalls/mmap/mmap22.c line 56

Quoted 1 line
testcases/kernel/syscalls/mmap/mmap22.c new file +1 -0
+			if (!*(uint8_t *)(alloc + i)) {

We are casting the alloc pointer on each access, it would probably be more reasonable to defined it as char * instead of void * and drop the casts from the code.

Quoted 8 lines
testcases/kernel/syscalls/mmap/mmap22.c new file +8 -0
+				tst_res(TPASS, "MAP_DROPPABLE test pass.");
+				goto kill_child;
+			}
+		}
+	}
+
+kill_child:
+	SAFE_KILL(child, SIGKILL);

testcases/kernel/syscalls/mmap/mmap22.c line 74

Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap22.c new file +10 -0
+	SAFE_WAITPID(child, NULL, 0);
+	SAFE_MUNMAP(alloc, alloc_size);
+}
+
+static void setup(void)
+{
+	void *addr = mmap(0, 1, PROT_READ | PROT_WRITE,
+			MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
+	if (addr == MAP_FAILED && errno == EINVAL)
+		tst_brk(TCONF, "MAP_DROPPABLE not support");

We are missing munmap() here in the case that addr != MAP_FAILED.

Other than these minor points the rest of the code looks good to me.

Signature · 5 lines
Cyril Hrubis
[email protected]

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

PATCH v4 1/1 mmap22.c: Test for new MAP_DROPPABLE flag for mmap

In reply to Wei Gao via ltp
---
 include/lapi/mmap.h                       |  4 +
 runtest/syscalls                          |  1 +
 testcases/kernel/syscalls/mmap/.gitignore |  1 +
 testcases/kernel/syscalls/mmap/mmap22.c   | 98 +++++++++++++++++++++++
 4 files changed, 104 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mmap/mmap22.c
include/lapi/mmap.h +4 -0
index ea9730586..248b64564 100644
@@ -87,6 +87,10 @@
 # define MADV_PAGEOUT	21
 #endif
 
+#ifndef MAP_DROPPABLE
+# define MAP_DROPPABLE 0x08
+#endif
+
 #ifndef MAP_FIXED_NOREPLACE
 
 #ifdef __alpha__
runtest/syscalls +1 -0
index 932b7030c..e369536ea 100644
@@ -844,6 +844,7 @@ mmap19 mmap19
 mmap20 mmap20
 mmap21_01 mmap21 -m 1
 mmap21_02 mmap21
+mmap22 mmap22
 
 modify_ldt01 modify_ldt01
 modify_ldt02 modify_ldt02
testcases/kernel/syscalls/mmap/.gitignore +1 -0
index 850284d86..075be933d 100644
@@ -18,3 +18,4 @@
 /mmap19
 /mmap20
 /mmap21
+/mmap22
testcases/kernel/syscalls/mmap/mmap22.c new file +98 -0

98 lines not on this page · raw message

Signature · 5 lines
2.49.0


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

Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap

Hi!
Pushed with a minor change, thanks.

We should check if the addr is valid before we attemp to unmap it in the setup() so I've added:

testcases/kernel/syscalls/mmap/mmap22.c +6 -1
index bfef559e4..0e589dfab 100644
@@ -72,8 +72,13 @@ static void setup(void)
 {
        void *addr = mmap(0, 1, PROT_READ | PROT_WRITE,
                        MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
+
        if (addr == MAP_FAILED && errno == EINVAL)
-               tst_brk(TCONF, "MAP_DROPPABLE not support");
+               tst_brk(TCONF, "MAP_DROPPABLE not supported");
+
+       if (addr == MAP_FAILED)
+               tst_brk(TBROK | TERRNO, "mmap() MAP_DROPPABLE failed");
+
        SAFE_MUNMAP(addr, 1);
 }
 
Signature · 5 lines
Cyril Hrubis
[email protected]

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

Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap

Is anyone else seeing this test failing on recent 6.15-rc5 kernels?

==== mmap22 ====
command: mmap22
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_mmazCULNN as tmpdir (tmpfs filesystem) tst_test.c:1938: TINFO: LTP version: 20250130-253-g4a0e3a8fa tst_test.c:1942: TINFO: Tested kernel:
6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64 #1 SMP PREEMPT_DYNAMIC Fri May 9 15:17:31 UTC 2025 x86_64 tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64/build/.config' tst_test.c:1758: TINFO: Overall timeout per run is 0h 05m 54s mmap22.c:55: TFAIL: MAP_DROPPABLE did not drop memory within the timeout period.

Quoted 34 lines · Cyril Hrubis

Hi!
Pushed with a minor change, thanks.

We should check if the addr is valid before we attemp to unmap it in the setup() so I've added:

testcases/kernel/syscalls/mmap/mmap22.c +6 -2
index bfef559e4..0e589dfab 100644
@@ -72,8 +72,13 @@ static void setup(void)
 {
        void *addr = mmap(0, 1, PROT_READ | PROT_WRITE,
                        MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
+
        if (addr == MAP_FAILED && errno == EINVAL)
-               tst_brk(TCONF, "MAP_DROPPABLE not support");
+               tst_brk(TCONF, "MAP_DROPPABLE not supported");
+
+       if (addr == MAP_FAILED)
+               tst_brk(TBROK | TERRNO, "mmap() MAP_DROPPABLE failed");
+
        SAFE_MUNMAP(addr, 1);
 }
 
 
--

Cyril Hrubis
[email protected]

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

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

Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap

Quoted 14 lines · Jan Stancek

Is anyone else seeing this test failing on recent 6.15-rc5 kernels?

==== mmap22 ====
command: mmap22
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_mmazCULNN as tmpdir (tmpfs filesystem) tst_test.c:1938: TINFO: LTP version: 20250130-253-g4a0e3a8fa tst_test.c:1942: TINFO: Tested kernel:
6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64 #1 SMP PREEMPT_DYNAMIC Fri May 9 15:17:31 UTC 2025 x86_64 tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64/build/.config' tst_test.c:1758: TINFO: Overall timeout per run is 0h 05m 54s mmap22.c:55: TFAIL: MAP_DROPPABLE did not drop memory within the timeout period.

I have tested rc5/6 and both give pass result.

uname -r
6.15.0-rc6-g627277ba7c23
./mmap22
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_mmaLHJK4T as tmpdir (tmpfs filesystem)
tst_test.c:1941: TINFO: LTP version: 20250130-256-gb987b8ac5
tst_test.c:1945: TINFO: Tested kernel: 6.15.0-rc6-g627277ba7c23 #3 SMP PREEMPT_DYNAMIC Tue May 13 11:15:39 EDT 2025 x86_64 tst_kconfig.c:71: TINFO: Couldn't locate kernel config!
tst_test.c:1761: TINFO: Overall timeout per run is 0h 01m 00s
mmap22.c:59: TPASS: MAP_DROPPABLE test pass.

Summary:

passed   1
failed   0
broken   0
skipped  0

warnings 0

uname -r
6.15.0-rc5
./mmap22
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_mmauLlsmi as tmpdir (tmpfs filesystem) tst_test.c:1941: TINFO: LTP version: 20250130-256-gb987b8ac5
tst_test.c:1945: TINFO: Tested kernel: 6.15.0-rc5 #4 SMP PREEMPT_DYNAMIC Tue May 13 11:38:14 EDT 2025 x86_64 tst_kconfig.c:71: TINFO: Couldn't locate kernel config!
tst_test.c:1761: TINFO: Overall timeout per run is 0h 01m 00s
mmap22.c:59: TPASS: MAP_DROPPABLE test pass.

Quoted 38 lines · Cyril Hrubis
Quoted 34 lines

Hi!
Pushed with a minor change, thanks.

We should check if the addr is valid before we attemp to unmap it in the setup() so I've added:

testcases/kernel/syscalls/mmap/mmap22.c +6 -2
index bfef559e4..0e589dfab 100644
@@ -72,8 +72,13 @@ static void setup(void)
 {
        void *addr = mmap(0, 1, PROT_READ | PROT_WRITE,
                        MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
+
        if (addr == MAP_FAILED && errno == EINVAL)
-               tst_brk(TCONF, "MAP_DROPPABLE not support");
+               tst_brk(TCONF, "MAP_DROPPABLE not supported");
+
+       if (addr == MAP_FAILED)
+               tst_brk(TBROK | TERRNO, "mmap() MAP_DROPPABLE failed");
+
        SAFE_MUNMAP(addr, 1);
 }
 
 
--

Cyril Hrubis
[email protected]

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

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

Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap

Quoted 17 lines · Wei Gao
Quoted 14 lines · Jan Stancek

Is anyone else seeing this test failing on recent 6.15-rc5 kernels?

==== mmap22 ====
command: mmap22
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_mmazCULNN as tmpdir (tmpfs filesystem) tst_test.c:1938: TINFO: LTP version: 20250130-253-g4a0e3a8fa tst_test.c:1942: TINFO: Tested kernel:
6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64 #1 SMP PREEMPT_DYNAMIC Fri May 9 15:17:31 UTC 2025 x86_64 tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64/build/.config' tst_test.c:1758: TINFO: Overall timeout per run is 0h 05m 54s mmap22.c:55: TFAIL: MAP_DROPPABLE did not drop memory within the timeout period.

Quoted 1 line

I have tested rc5/6 and both give pass result.

I do see it fail almost daily on multiple arches (VMs and baremetal), maybe some difference in our config.

command: mmap22
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_mmaYU95zb as tmpdir (tmpfs filesystem) tst_test.c:1941: TINFO: LTP version: 20250130-256-gb987b8ac5 tst_test.c:1945: TINFO: Tested kernel: 6.15.0-0.rc6.49.eln148.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 13 14:30:53 UTC 2025 x86_64 tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.15.0-0.rc6.49.eln148.x86_64/build/.config' tst_test.c:1761: TINFO: Overall timeout per run is 0h 05m 54s mmap22.c:55: TFAIL: MAP_DROPPABLE did not drop memory within the timeout period.

Quoted 70 lines

uname -r
6.15.0-rc6-g627277ba7c23
./mmap22
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_mmaLHJK4T as tmpdir (tmpfs filesystem)
tst_test.c:1941: TINFO: LTP version: 20250130-256-gb987b8ac5
tst_test.c:1945: TINFO: Tested kernel: 6.15.0-rc6-g627277ba7c23 #3 SMP PREEMPT_DYNAMIC Tue May 13 11:15:39 EDT 2025 x86_64 tst_kconfig.c:71: TINFO: Couldn't locate kernel config!
tst_test.c:1761: TINFO: Overall timeout per run is 0h 01m 00s
mmap22.c:59: TPASS: MAP_DROPPABLE test pass.

Summary:

passed   1
failed   0
broken   0
skipped  0

warnings 0

uname -r
6.15.0-rc5
./mmap22
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_mmauLlsmi as tmpdir (tmpfs filesystem) tst_test.c:1941: TINFO: LTP version: 20250130-256-gb987b8ac5
tst_test.c:1945: TINFO: Tested kernel: 6.15.0-rc5 #4 SMP PREEMPT_DYNAMIC Tue May 13 11:38:14 EDT 2025 x86_64 tst_kconfig.c:71: TINFO: Couldn't locate kernel config!
tst_test.c:1761: TINFO: Overall timeout per run is 0h 01m 00s
mmap22.c:59: TPASS: MAP_DROPPABLE test pass.

Quoted 38 lines · Cyril Hrubis
Quoted 34 lines

Hi!
Pushed with a minor change, thanks.

We should check if the addr is valid before we attemp to unmap it in the setup() so I've added:

testcases/kernel/syscalls/mmap/mmap22.c +6 -2
index bfef559e4..0e589dfab 100644
@@ -72,8 +72,13 @@ static void setup(void)
 {
        void *addr = mmap(0, 1, PROT_READ | PROT_WRITE,
                        MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
+
        if (addr == MAP_FAILED && errno == EINVAL)
-               tst_brk(TCONF, "MAP_DROPPABLE not support");
+               tst_brk(TCONF, "MAP_DROPPABLE not supported");
+
+       if (addr == MAP_FAILED)
+               tst_brk(TBROK | TERRNO, "mmap() MAP_DROPPABLE failed");
+
        SAFE_MUNMAP(addr, 1);
 }
 
 
--

Cyril Hrubis
[email protected]

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

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

Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap

Quoted 19 lines · Jan Stancek via ltp
Quoted 17 lines · Wei Gao
Quoted 14 lines · Jan Stancek

Is anyone else seeing this test failing on recent 6.15-rc5 kernels?

==== mmap22 ====
command: mmap22
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_mmazCULNN as tmpdir (tmpfs filesystem) tst_test.c:1938: TINFO: LTP version: 20250130-253-g4a0e3a8fa tst_test.c:1942: TINFO: Tested kernel:
6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64 #1 SMP PREEMPT_DYNAMIC Fri May 9 15:17:31 UTC 2025 x86_64 tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64/build/.config' tst_test.c:1758: TINFO: Overall timeout per run is 0h 05m 54s mmap22.c:55: TFAIL: MAP_DROPPABLE did not drop memory within the timeout period.

Quoted 4 lines
Quoted 1 line

I have tested rc5/6 and both give pass result.

I do see it fail almost daily on multiple arches (VMs and baremetal), maybe some difference in our config.

Have you tried the original self-test (without using Cgroup)? If it still fails, consider it a kernel issue.

Signature · 6 lines
Regards,
Li Wang


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

Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap

Quoted 21 lines · Li Wang
Quoted 19 lines · Jan Stancek via ltp
Quoted 17 lines · Wei Gao
Quoted 14 lines · Jan Stancek

Is anyone else seeing this test failing on recent 6.15-rc5 kernels?

==== mmap22 ====
command: mmap22
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_mmazCULNN as tmpdir (tmpfs filesystem) tst_test.c:1938: TINFO: LTP version: 20250130-253-g4a0e3a8fa tst_test.c:1942: TINFO: Tested kernel:
6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64 #1 SMP PREEMPT_DYNAMIC Fri May 9 15:17:31 UTC 2025 x86_64 tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64/build/.config' tst_test.c:1758: TINFO: Overall timeout per run is 0h 05m 54s mmap22.c:55: TFAIL: MAP_DROPPABLE did not drop memory within the timeout period.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

I have tested rc5/6 and both give pass result.

I do see it fail almost daily on multiple arches (VMs and baremetal), maybe some difference in our config.

Have you tried the original self-test (without using Cgroup)? If it still fails, consider it a kernel issue.

I'll have a closer look and try manually. At first glance at test, I suspect compiler
doing something clever for:

                for (;;)
                        *(char *)malloc(page_size) = 'B';
Quoted 5 lines

--
Regards,
Li Wang

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

Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap

Quoted 28 lines · Jan Stancek
Quoted 26 lines · Li Wang
Quoted 23 lines · Jan Stancek via ltp
Quoted 17 lines · Wei Gao
Quoted 14 lines · Jan Stancek

Is anyone else seeing this test failing on recent 6.15-rc5 kernels?

==== mmap22 ====
command: mmap22
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_mmazCULNN as tmpdir (tmpfs filesystem) tst_test.c:1938: TINFO: LTP version: 20250130-253-g4a0e3a8fa tst_test.c:1942: TINFO: Tested kernel:
6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64 #1 SMP PREEMPT_DYNAMIC Fri May 9 15:17:31 UTC 2025 x86_64 tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64/build/.config' tst_test.c:1758: TINFO: Overall timeout per run is 0h 05m 54s mmap22.c:55: TFAIL: MAP_DROPPABLE did not drop memory within the timeout period.

Quoted 1 line

I have tested rc5/6 and both give pass result.

I do see it fail almost daily on multiple arches (VMs and baremetal), maybe some difference in our config.

Quoted 8 lines
Quoted 2 lines

Have you tried the original self-test (without using Cgroup)? If it still fails, consider it a kernel issue.

I'll have a closer look and try manually. At first glance at test, I suspect compiler
doing something clever for:

                for (;;)
                        *(char *)malloc(page_size) = 'B';

Probably, -O2 is the default in LTP compiling.

Or, you could also try disabling KSM when testing mmap22.c to see if it helps.

Signature · 6 lines
Regards,
Li Wang


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

Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap

Quoted 39 lines · Li Wang
Quoted 28 lines · Jan Stancek
Quoted 26 lines · Li Wang
Quoted 23 lines · Jan Stancek via ltp
Quoted 17 lines · Wei Gao
Quoted 14 lines · Jan Stancek

Is anyone else seeing this test failing on recent 6.15-rc5 kernels?

==== mmap22 ====
command: mmap22
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_mmazCULNN as tmpdir (tmpfs filesystem) tst_test.c:1938: TINFO: LTP version: 20250130-253-g4a0e3a8fa tst_test.c:1942: TINFO: Tested kernel:
6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64 #1 SMP PREEMPT_DYNAMIC Fri May 9 15:17:31 UTC 2025 x86_64 tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.15.0-0.rc5.250509g9c69f8884904.47.eln148.x86_64/build/.config' tst_test.c:1758: TINFO: Overall timeout per run is 0h 05m 54s mmap22.c:55: TFAIL: MAP_DROPPABLE did not drop memory within the timeout period.

Quoted 1 line

I have tested rc5/6 and both give pass result.

I do see it fail almost daily on multiple arches (VMs and baremetal), maybe some difference in our config.

Quoted 8 lines
Quoted 2 lines

Have you tried the original self-test (without using Cgroup)? If it still fails, consider it a kernel issue.

I'll have a closer look and try manually. At first glance at test, I suspect compiler
doing something clever for:

                for (;;)
                        *(char *)malloc(page_size) = 'B';
Quoted 3 lines

Probably, -O2 is the default in LTP compiling.

Or, you could also try disabling KSM when testing mmap22.c to see if it helps.

In case of my VM, it looks like it's able to swap faster than what's needed to drop the allocation.
With this I get PASS right away:

(quoted diff) +0 -0

b/testcases/kernel/syscalls/mmap/mmap22.c
index 0e589dfab..56fe412d1 100644

testcases/kernel/syscalls/mmap/mmap22.c +1 -0
@@ -32,6 +32,7 @@ static void test_mmap(void)
 
        cg_child = tst_cg_group_mk(tst_cg, "child");
        SAFE_CG_PRINTF(tst_cg, "memory.max", "%d", MEM_LIMIT);
+       SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%d", 1);
        SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid());
 
        alloc = SAFE_MMAP(0, alloc_size, PROT_READ | PROT_WRITE,
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#18 lore raw

Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap

Quoted 20 lines · Jan Stancek
Quoted 9 lines
Quoted 5 lines

I'll have a closer look and try manually. At first glance at test, I suspect compiler
doing something clever for:

                for (;;)
                        *(char *)malloc(page_size) = 'B';

Probably, -O2 is the default in LTP compiling.

Or, you could also try disabling KSM when testing mmap22.c to see if it helps.

In case of my VM, it looks like it's able to swap faster than what's needed to drop the allocation.
With this I get PASS right away:

testcases/kernel/syscalls/mmap/mmap22.c +0 -0
index 0e589dfab..56fe412d1 100644

testcases/kernel/syscalls/mmap/mmap22.c static void test_mmap(void) · line 35

Quoted 4 lines
testcases/kernel/syscalls/mmap/mmap22.c +1 -0
@@ -32,6 +32,7 @@ static void test_mmap(void)
 
        cg_child = tst_cg_group_mk(tst_cg, "child");
        SAFE_CG_PRINTF(tst_cg, "memory.max", "%d", MEM_LIMIT);
+       SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%d", 1);

Why not set it to 0 to disable it completely?

I guess we need to do it separately for both Cgroup v1 and v2.
- Cgroup-v1: set it to MEM_LIMIT.
- Cgroup-v2: set it to 0.
FYI: https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/mem/oom/oom03.c#L33

Anyway, testing will be much faster with this patch.

--
Regards,
Li Wang

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

Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap

Quoted 24 lines · Li Wang
Quoted 21 lines · Jan Stancek
Quoted 9 lines
Quoted 5 lines

I'll have a closer look and try manually. At first glance at test, I suspect compiler
doing something clever for:

                for (;;)
                        *(char *)malloc(page_size) = 'B';

Probably, -O2 is the default in LTP compiling.

Or, you could also try disabling KSM when testing mmap22.c to see if it helps.

In case of my VM, it looks like it's able to swap faster than what's needed to drop the allocation.
With this I get PASS right away:

testcases/kernel/syscalls/mmap/mmap22.c +0 -0
index 0e589dfab..56fe412d1 100644
@@ -32,6 +32,7 @@ static void test_mmap(void)
 
Quoted 5 lines

testcases/kernel/syscalls/mmap/mmap22.c static void test_mmap(void) · line 35

Quoted 3 lines
testcases/kernel/syscalls/mmap/mmap22.c +1 -0
        cg_child = tst_cg_group_mk(tst_cg, "child");
        SAFE_CG_PRINTF(tst_cg, "memory.max", "%d", MEM_LIMIT);
+       SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%d", 1);

Why not set it to 0 to disable it completely?

Yes, I realized that when I was preparing the patch :-).

Quoted 5 lines

I guess we need to do it separately for both Cgroup v1 and v2.
- Cgroup-v1: set it to MEM_LIMIT.
- Cgroup-v2: set it to 0.
FYI: https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/mem/oom/oom03.c#L33

Thanks for pointer, I'll add it also for cgroup v1.

Quoted 7 lines

Anyway, testing will be much faster with this patch.

--
Regards,
Li Wang

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