* [LTP] [PATCH v1] mmap21.c: Test for new MAP_DROPPABLE flag for mmap @ 2024-12-28 13:32 Wei Gao via ltp 2024-12-31 10:04 ` Li Wang 2025-01-03 13:56 ` [LTP] [PATCH v2] " Wei Gao via ltp 0 siblings, 2 replies; 20+ messages in thread From: Wei Gao via ltp @ 2024-12-28 13:32 UTC (permalink / raw) To: ltp Signed-off-by: Wei Gao <wegao@suse.com> --- 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 diff --git a/include/lapi/mmap.h b/include/lapi/mmap.h index ea9730586..248b64564 100644 --- a/include/lapi/mmap.h +++ b/include/lapi/mmap.h @@ -87,6 +87,10 @@ # define MADV_PAGEOUT 21 #endif +#ifndef MAP_DROPPABLE +# define MAP_DROPPABLE 0x08 +#endif + #ifndef MAP_FIXED_NOREPLACE #ifdef __alpha__ diff --git a/runtest/syscalls b/runtest/syscalls index ded035ee8..7166e39a4 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -840,6 +840,7 @@ mmap17 mmap17 mmap18 mmap18 mmap19 mmap19 mmap20 mmap20 +mmap21 mmap21 modify_ldt01 modify_ldt01 modify_ldt02 modify_ldt02 diff --git a/testcases/kernel/syscalls/mmap/.gitignore b/testcases/kernel/syscalls/mmap/.gitignore index 4591fdbb9..87b23aaee 100644 --- a/testcases/kernel/syscalls/mmap/.gitignore +++ b/testcases/kernel/syscalls/mmap/.gitignore @@ -18,3 +18,4 @@ /mmap18 /mmap19 /mmap20 +/mmap21 diff --git a/testcases/kernel/syscalls/mmap/mmap21.c b/testcases/kernel/syscalls/mmap/mmap21.c new file mode 100644 index 000000000..e2b8c4551 --- /dev/null +++ b/testcases/kernel/syscalls/mmap/mmap21.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2024 Wei Gao <wegao@suse.com> + */ + +/*\ + * [Description] + * + * Test mmap(2) with MAP_DROPPABLE flag. + * + * Test base on kernel selftests/mm/droppable.c + */ + +#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; + 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, + 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); + } + } + + for (; !(*shared_var);) { + for (size_t i = 0; i < alloc_size; i += page_size) { + if (!*(uint8_t *)(alloc + i)) { + *shared_var = 1; + 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 struct tst_test test = { + .min_kver = "6.11", + .test_all = test_mmap, + .needs_tmpdir = 1, + .forks_child = 1, + .max_runtime = 180, +}; -- 2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v1] mmap21.c: Test for new MAP_DROPPABLE flag for mmap 2024-12-28 13:32 [LTP] [PATCH v1] mmap21.c: Test for new MAP_DROPPABLE flag for mmap Wei Gao via ltp @ 2024-12-31 10:04 ` Li Wang 2025-01-02 9:38 ` Cyril Hrubis ` (2 more replies) 2025-01-03 13:56 ` [LTP] [PATCH v2] " Wei Gao via ltp 1 sibling, 3 replies; 20+ messages in thread From: Li Wang @ 2024-12-31 10:04 UTC (permalink / raw) To: Wei Gao; +Cc: ltp On Sat, Dec 28, 2024 at 9:32 PM Wei Gao via ltp <ltp@lists.linux.it> wrote: > Signed-off-by: Wei Gao <wegao@suse.com> > --- > 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 > > diff --git a/include/lapi/mmap.h b/include/lapi/mmap.h > index ea9730586..248b64564 100644 > --- a/include/lapi/mmap.h > +++ b/include/lapi/mmap.h > @@ -87,6 +87,10 @@ > # define MADV_PAGEOUT 21 > #endif > > +#ifndef MAP_DROPPABLE > +# define MAP_DROPPABLE 0x08 > +#endif > + > #ifndef MAP_FIXED_NOREPLACE > > #ifdef __alpha__ > diff --git a/runtest/syscalls b/runtest/syscalls > index ded035ee8..7166e39a4 100644 > --- a/runtest/syscalls > +++ b/runtest/syscalls > @@ -840,6 +840,7 @@ mmap17 mmap17 > mmap18 mmap18 > mmap19 mmap19 > mmap20 mmap20 > +mmap21 mmap21 > > modify_ldt01 modify_ldt01 > modify_ldt02 modify_ldt02 > diff --git a/testcases/kernel/syscalls/mmap/.gitignore > b/testcases/kernel/syscalls/mmap/.gitignore > index 4591fdbb9..87b23aaee 100644 > --- a/testcases/kernel/syscalls/mmap/.gitignore > +++ b/testcases/kernel/syscalls/mmap/.gitignore > @@ -18,3 +18,4 @@ > /mmap18 > /mmap19 > /mmap20 > +/mmap21 > diff --git a/testcases/kernel/syscalls/mmap/mmap21.c > b/testcases/kernel/syscalls/mmap/mmap21.c > new file mode 100644 > index 000000000..e2b8c4551 > --- /dev/null > +++ b/testcases/kernel/syscalls/mmap/mmap21.c > @@ -0,0 +1,73 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2024 Wei Gao <wegao@suse.com> > + */ > + > +/*\ > + * [Description] > + * > + * Test mmap(2) with MAP_DROPPABLE flag. > + * > + * Test base on kernel selftests/mm/droppable.c > + */ > + > +#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; > + 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, > + 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. > + } > + } > + > + for (; !(*shared_var);) { > why not use while() loop. + for (size_t i = 0; i < alloc_size; i += page_size) { > + 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? > + > + 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. > + .test_all = test_mmap, > + .needs_tmpdir = 1, > add .min_mem_avail here. > + .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. > +}; > -- > 2.35.3 > > > -- > Mailing list info: https://lists.linux.it/listinfo/ltp > > -- Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v1] mmap21.c: Test for new MAP_DROPPABLE flag for mmap 2024-12-31 10:04 ` Li Wang @ 2025-01-02 9:38 ` Cyril Hrubis 2025-01-03 1:42 ` Wei Gao via ltp 2025-01-03 13:54 ` Wei Gao via ltp 2 siblings, 0 replies; 20+ messages in thread From: Cyril Hrubis @ 2025-01-02 9:38 UTC (permalink / raw) To: Li Wang; +Cc: ltp Hi! > > 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. -- Cyril Hrubis chrubis@suse.cz -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v1] mmap21.c: Test for new MAP_DROPPABLE flag for mmap 2024-12-31 10:04 ` Li Wang 2025-01-02 9:38 ` Cyril Hrubis @ 2025-01-03 1:42 ` Wei Gao via ltp 2025-01-03 13:54 ` Wei Gao via ltp 2 siblings, 0 replies; 20+ messages in thread From: Wei Gao via ltp @ 2025-01-03 1:42 UTC (permalink / raw) To: Li Wang; +Cc: ltp On Tue, Dec 31, 2024 at 06:04:54PM +0800, Li Wang wrote: > On Sat, Dec 28, 2024 at 9:32 PM Wei Gao via ltp <ltp@lists.linux.it> wrote: > > > Signed-off-by: Wei Gao <wegao@suse.com> > > --- > > + for (size_t i = 0; i < alloc_size; i += page_size) { > > + 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? 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 <Jason@zx2c4.com> 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() > > -- > Regards, > Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v1] mmap21.c: Test for new MAP_DROPPABLE flag for mmap 2024-12-31 10:04 ` Li Wang 2025-01-02 9:38 ` Cyril Hrubis 2025-01-03 1:42 ` Wei Gao via ltp @ 2025-01-03 13:54 ` Wei Gao via ltp 2 siblings, 0 replies; 20+ messages in thread From: Wei Gao via ltp @ 2025-01-03 13:54 UTC (permalink / raw) To: Li Wang; +Cc: ltp On Tue, Dec 31, 2024 at 06:04:54PM +0800, Li Wang wrote: > On Sat, Dec 28, 2024 at 9:32 PM Wei Gao via ltp <ltp@lists.linux.it> wrote: > > > + > > + 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 (;;) { > > + *(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. 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? > > 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. > > > > > +}; > > -- > > 2.35.3 > > > > > > -- > > Mailing list info: https://lists.linux.it/listinfo/ltp > > > > > > -- > Regards, > Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
* [LTP] [PATCH v2] mmap21.c: Test for new MAP_DROPPABLE flag for mmap 2024-12-28 13:32 [LTP] [PATCH v1] mmap21.c: Test for new MAP_DROPPABLE flag for mmap Wei Gao via ltp 2024-12-31 10:04 ` Li Wang @ 2025-01-03 13:56 ` Wei Gao via ltp 2025-03-10 16:18 ` Cyril Hrubis 2025-04-16 19:16 ` [LTP] [PATCH v3] mmap22.c: " Wei Gao via ltp 1 sibling, 2 replies; 20+ messages in thread From: Wei Gao via ltp @ 2025-01-03 13:56 UTC (permalink / raw) To: ltp Signed-off-by: Wei Gao <wegao@suse.com> --- 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 diff --git a/include/lapi/mmap.h b/include/lapi/mmap.h index ea9730586..248b64564 100644 --- a/include/lapi/mmap.h +++ b/include/lapi/mmap.h @@ -87,6 +87,10 @@ # define MADV_PAGEOUT 21 #endif +#ifndef MAP_DROPPABLE +# define MAP_DROPPABLE 0x08 +#endif + #ifndef MAP_FIXED_NOREPLACE #ifdef __alpha__ diff --git a/runtest/syscalls b/runtest/syscalls index ded035ee8..7166e39a4 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -840,6 +840,7 @@ mmap17 mmap17 mmap18 mmap18 mmap19 mmap19 mmap20 mmap20 +mmap21 mmap21 modify_ldt01 modify_ldt01 modify_ldt02 modify_ldt02 diff --git a/testcases/kernel/syscalls/mmap/.gitignore b/testcases/kernel/syscalls/mmap/.gitignore index 4591fdbb9..87b23aaee 100644 --- a/testcases/kernel/syscalls/mmap/.gitignore +++ b/testcases/kernel/syscalls/mmap/.gitignore @@ -18,3 +18,4 @@ /mmap18 /mmap19 /mmap20 +/mmap21 diff --git a/testcases/kernel/syscalls/mmap/mmap21.c b/testcases/kernel/syscalls/mmap/mmap21.c new file mode 100644 index 000000000..46f3ac7c5 --- /dev/null +++ b/testcases/kernel/syscalls/mmap/mmap21.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2024 Wei Gao <wegao@suse.com> + */ + +/*\ + * [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 (;;) { + *(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; + 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, +}; -- 2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v2] mmap21.c: Test for new MAP_DROPPABLE flag for mmap 2025-01-03 13:56 ` [LTP] [PATCH v2] " Wei Gao via ltp @ 2025-03-10 16:18 ` Cyril Hrubis 2025-04-16 19:16 ` [LTP] [PATCH v3] mmap22.c: " Wei Gao via ltp 1 sibling, 0 replies; 20+ messages in thread From: Cyril Hrubis @ 2025-03-10 16:18 UTC (permalink / raw) To: Wei Gao; +Cc: ltp Hi! > diff --git a/testcases/kernel/syscalls/mmap/mmap21.c b/testcases/kernel/syscalls/mmap/mmap21.c > new file mode 100644 > index 000000000..46f3ac7c5 > --- /dev/null > +++ b/testcases/kernel/syscalls/mmap/mmap21.c > @@ -0,0 +1,102 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2024 Wei Gao <wegao@suse.com> > + */ > + > +/*\ > + * [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 (;;) { > + *(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? > + 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, > +}; > -- > 2.35.3 > > > -- > Mailing list info: https://lists.linux.it/listinfo/ltp -- Cyril Hrubis chrubis@suse.cz -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
* [LTP] [PATCH v3] mmap22.c: Test for new MAP_DROPPABLE flag for mmap 2025-01-03 13:56 ` [LTP] [PATCH v2] " Wei Gao via ltp 2025-03-10 16:18 ` Cyril Hrubis @ 2025-04-16 19:16 ` Wei Gao via ltp 2025-04-25 11:40 ` Cyril Hrubis 2025-04-28 16:04 ` [LTP] [PATCH v4] " Wei Gao via ltp 1 sibling, 2 replies; 20+ messages in thread From: Wei Gao via ltp @ 2025-04-16 19:16 UTC (permalink / raw) To: ltp Signed-off-by: Wei Gao <wegao@suse.com> --- 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 diff --git a/include/lapi/mmap.h b/include/lapi/mmap.h index ea9730586..248b64564 100644 --- a/include/lapi/mmap.h +++ b/include/lapi/mmap.h @@ -87,6 +87,10 @@ # define MADV_PAGEOUT 21 #endif +#ifndef MAP_DROPPABLE +# define MAP_DROPPABLE 0x08 +#endif + #ifndef MAP_FIXED_NOREPLACE #ifdef __alpha__ diff --git a/runtest/syscalls b/runtest/syscalls index 932b7030c..e369536ea 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -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 diff --git a/testcases/kernel/syscalls/mmap/.gitignore b/testcases/kernel/syscalls/mmap/.gitignore index 850284d86..075be933d 100644 --- a/testcases/kernel/syscalls/mmap/.gitignore +++ b/testcases/kernel/syscalls/mmap/.gitignore @@ -18,3 +18,4 @@ /mmap19 /mmap20 /mmap21 +/mmap22 diff --git a/testcases/kernel/syscalls/mmap/mmap22.c b/testcases/kernel/syscalls/mmap/mmap22.c new file mode 100644 index 000000000..31414896c --- /dev/null +++ b/testcases/kernel/syscalls/mmap/mmap22.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2025 Wei Gao <wegao@suse.com> + */ + +/*\ + * [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"); + } + + 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."); + if (!*(uint8_t *)(alloc + i)) { + tst_res(TPASS, "MAP_DROPPABLE test pass."); + goto kill_child; + } + } + } + +kill_child: + SAFE_KILL(child, SIGKILL); + 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"); +} + +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, + .runtime = 30, + .min_mem_avail = 300, +}; -- 2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v3] mmap22.c: Test for new MAP_DROPPABLE flag for mmap 2025-04-16 19:16 ` [LTP] [PATCH v3] mmap22.c: " Wei Gao via ltp @ 2025-04-25 11:40 ` Cyril Hrubis 2025-04-28 16:04 ` [LTP] [PATCH v4] " Wei Gao via ltp 1 sibling, 0 replies; 20+ messages in thread From: Cyril Hrubis @ 2025-04-25 11:40 UTC (permalink / raw) To: Wei Gao; +Cc: ltp Hi! > +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"); > + } > + > + 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; > + 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. > + tst_res(TPASS, "MAP_DROPPABLE test pass."); > + goto kill_child; > + } > + } > + } > + > +kill_child: > + SAFE_KILL(child, SIGKILL); > + 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. -- Cyril Hrubis chrubis@suse.cz -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
* [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap 2025-04-16 19:16 ` [LTP] [PATCH v3] mmap22.c: " Wei Gao via ltp 2025-04-25 11:40 ` Cyril Hrubis @ 2025-04-28 16:04 ` Wei Gao via ltp 2025-05-07 15:25 ` Cyril Hrubis 1 sibling, 1 reply; 20+ messages in thread From: Wei Gao via ltp @ 2025-04-28 16:04 UTC (permalink / raw) To: ltp Signed-off-by: Wei Gao <wegao@suse.com> --- 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 diff --git a/include/lapi/mmap.h b/include/lapi/mmap.h index ea9730586..248b64564 100644 --- a/include/lapi/mmap.h +++ b/include/lapi/mmap.h @@ -87,6 +87,10 @@ # define MADV_PAGEOUT 21 #endif +#ifndef MAP_DROPPABLE +# define MAP_DROPPABLE 0x08 +#endif + #ifndef MAP_FIXED_NOREPLACE #ifdef __alpha__ diff --git a/runtest/syscalls b/runtest/syscalls index 932b7030c..e369536ea 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -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 diff --git a/testcases/kernel/syscalls/mmap/.gitignore b/testcases/kernel/syscalls/mmap/.gitignore index 850284d86..075be933d 100644 --- a/testcases/kernel/syscalls/mmap/.gitignore +++ b/testcases/kernel/syscalls/mmap/.gitignore @@ -18,3 +18,4 @@ /mmap19 /mmap20 /mmap21 +/mmap22 diff --git a/testcases/kernel/syscalls/mmap/mmap22.c b/testcases/kernel/syscalls/mmap/mmap22.c new file mode 100644 index 000000000..bfef559e4 --- /dev/null +++ b/testcases/kernel/syscalls/mmap/mmap22.c @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2025 Wei Gao <wegao@suse.com> + */ + +/*\ + * [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(); + char *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 (alloc[i] != 'A') + tst_res(TFAIL, "memset failed"); + } + + 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_res(TFAIL, "MAP_DROPPABLE did not drop memory within the timeout period."); + goto kill_child; + } + if (!alloc[i]) { + tst_res(TPASS, "MAP_DROPPABLE test pass."); + goto kill_child; + } + } + } + +kill_child: + SAFE_KILL(child, SIGKILL); + 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"); + SAFE_MUNMAP(addr, 1); +} + +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, + .runtime = 30, + .min_mem_avail = 300, +}; -- 2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap 2025-04-28 16:04 ` [LTP] [PATCH v4] " Wei Gao via ltp @ 2025-05-07 15:25 ` Cyril Hrubis 2025-05-12 8:43 ` Jan Stancek via ltp 0 siblings, 1 reply; 20+ messages in thread From: Cyril Hrubis @ 2025-05-07 15:25 UTC (permalink / raw) To: Wei Gao; +Cc: ltp 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: diff --git a/testcases/kernel/syscalls/mmap/mmap22.c b/testcases/kernel/syscalls/mmap/mmap22.c index bfef559e4..0e589dfab 100644 --- a/testcases/kernel/syscalls/mmap/mmap22.c +++ b/testcases/kernel/syscalls/mmap/mmap22.c @@ -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 chrubis@suse.cz -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap 2025-05-07 15:25 ` Cyril Hrubis @ 2025-05-12 8:43 ` Jan Stancek via ltp 2025-05-13 15:44 ` Wei Gao via ltp 0 siblings, 1 reply; 20+ messages in thread From: Jan Stancek via ltp @ 2025-05-12 8:43 UTC (permalink / raw) To: Cyril Hrubis; +Cc: ltp 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. On Wed, May 7, 2025 at 5:25 PM Cyril Hrubis <chrubis@suse.cz> wrote: > > 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: > > diff --git a/testcases/kernel/syscalls/mmap/mmap22.c b/testcases/kernel/syscalls/mmap/mmap22.c > index bfef559e4..0e589dfab 100644 > --- a/testcases/kernel/syscalls/mmap/mmap22.c > +++ b/testcases/kernel/syscalls/mmap/mmap22.c > @@ -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 > chrubis@suse.cz > > -- > Mailing list info: https://lists.linux.it/listinfo/ltp > -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap 2025-05-12 8:43 ` Jan Stancek via ltp @ 2025-05-13 15:44 ` Wei Gao via ltp 2025-05-14 8:51 ` Jan Stancek via ltp 0 siblings, 1 reply; 20+ messages in thread From: Wei Gao via ltp @ 2025-05-13 15:44 UTC (permalink / raw) To: Jan Stancek; +Cc: ltp On Mon, May 12, 2025 at 10:43:55AM +0200, Jan Stancek wrote: > 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. > > > On Wed, May 7, 2025 at 5:25 PM Cyril Hrubis <chrubis@suse.cz> wrote: > > > > 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: > > > > diff --git a/testcases/kernel/syscalls/mmap/mmap22.c b/testcases/kernel/syscalls/mmap/mmap22.c > > index bfef559e4..0e589dfab 100644 > > --- a/testcases/kernel/syscalls/mmap/mmap22.c > > +++ b/testcases/kernel/syscalls/mmap/mmap22.c > > @@ -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 > > chrubis@suse.cz > > > > -- > > Mailing list info: https://lists.linux.it/listinfo/ltp > > > -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap 2025-05-13 15:44 ` Wei Gao via ltp @ 2025-05-14 8:51 ` Jan Stancek via ltp 2025-05-14 9:04 ` Li Wang via ltp 0 siblings, 1 reply; 20+ messages in thread From: Jan Stancek via ltp @ 2025-05-14 8:51 UTC (permalink / raw) To: Wei Gao; +Cc: ltp On Tue, May 13, 2025 at 5:44 AM Wei Gao <wegao@suse.com> wrote: > > On Mon, May 12, 2025 at 10:43:55AM +0200, Jan Stancek wrote: > > 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. 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. > > 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. > > > > > > > > On Wed, May 7, 2025 at 5:25 PM Cyril Hrubis <chrubis@suse.cz> wrote: > > > > > > 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: > > > > > > diff --git a/testcases/kernel/syscalls/mmap/mmap22.c b/testcases/kernel/syscalls/mmap/mmap22.c > > > index bfef559e4..0e589dfab 100644 > > > --- a/testcases/kernel/syscalls/mmap/mmap22.c > > > +++ b/testcases/kernel/syscalls/mmap/mmap22.c > > > @@ -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 > > > chrubis@suse.cz > > > > > > -- > > > Mailing list info: https://lists.linux.it/listinfo/ltp > > > > > > -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap 2025-05-14 8:51 ` Jan Stancek via ltp @ 2025-05-14 9:04 ` Li Wang via ltp 2025-05-14 9:10 ` Jan Stancek via ltp 0 siblings, 1 reply; 20+ messages in thread From: Li Wang via ltp @ 2025-05-14 9:04 UTC (permalink / raw) To: Jan Stancek; +Cc: ltp On Wed, May 14, 2025 at 4:52 PM Jan Stancek via ltp <ltp@lists.linux.it> wrote: > > On Tue, May 13, 2025 at 5:44 AM Wei Gao <wegao@suse.com> wrote: > > > > On Mon, May 12, 2025 at 10:43:55AM +0200, Jan Stancek wrote: > > > 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. > > 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. -- Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap 2025-05-14 9:04 ` Li Wang via ltp @ 2025-05-14 9:10 ` Jan Stancek via ltp 2025-05-14 9:14 ` Li Wang via ltp 0 siblings, 1 reply; 20+ messages in thread From: Jan Stancek via ltp @ 2025-05-14 9:10 UTC (permalink / raw) To: Li Wang; +Cc: ltp On Wed, May 14, 2025 at 11:04 AM Li Wang <liwang@redhat.com> wrote: > > On Wed, May 14, 2025 at 4:52 PM Jan Stancek via ltp <ltp@lists.linux.it> wrote: > > > > On Tue, May 13, 2025 at 5:44 AM Wei Gao <wegao@suse.com> wrote: > > > > > > On Mon, May 12, 2025 at 10:43:55AM +0200, Jan Stancek wrote: > > > > 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. > > > > 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'; > > -- > Regards, > Li Wang > -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap 2025-05-14 9:10 ` Jan Stancek via ltp @ 2025-05-14 9:14 ` Li Wang via ltp 2025-05-14 11:15 ` Jan Stancek via ltp 0 siblings, 1 reply; 20+ messages in thread From: Li Wang via ltp @ 2025-05-14 9:14 UTC (permalink / raw) To: Jan Stancek; +Cc: ltp On Wed, May 14, 2025 at 5:10 PM Jan Stancek <jstancek@redhat.com> wrote: > > On Wed, May 14, 2025 at 11:04 AM Li Wang <liwang@redhat.com> wrote: > > > > On Wed, May 14, 2025 at 4:52 PM Jan Stancek via ltp <ltp@lists.linux.it> wrote: > > > > > > On Tue, May 13, 2025 at 5:44 AM Wei Gao <wegao@suse.com> wrote: > > > > > > > > On Mon, May 12, 2025 at 10:43:55AM +0200, Jan Stancek wrote: > > > > > 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. > > > > > > 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'; Probably, -O2 is the default in LTP compiling. Or, you could also try disabling KSM when testing mmap22.c to see if it helps. -- Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap 2025-05-14 9:14 ` Li Wang via ltp @ 2025-05-14 11:15 ` Jan Stancek via ltp 2025-05-14 12:44 ` Li Wang via ltp 0 siblings, 1 reply; 20+ messages in thread From: Jan Stancek via ltp @ 2025-05-14 11:15 UTC (permalink / raw) To: Li Wang; +Cc: ltp On Wed, May 14, 2025 at 11:14 AM Li Wang <liwang@redhat.com> wrote: > > On Wed, May 14, 2025 at 5:10 PM Jan Stancek <jstancek@redhat.com> wrote: > > > > On Wed, May 14, 2025 at 11:04 AM Li Wang <liwang@redhat.com> wrote: > > > > > > On Wed, May 14, 2025 at 4:52 PM Jan Stancek via ltp <ltp@lists.linux.it> wrote: > > > > > > > > On Tue, May 13, 2025 at 5:44 AM Wei Gao <wegao@suse.com> wrote: > > > > > > > > > > On Mon, May 12, 2025 at 10:43:55AM +0200, Jan Stancek wrote: > > > > > > 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. > > > > > > > > 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'; > > 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: diff --git a/testcases/kernel/syscalls/mmap/mmap22.c b/testcases/kernel/syscalls/mmap/mmap22.c index 0e589dfab..56fe412d1 100644 --- a/testcases/kernel/syscalls/mmap/mmap22.c +++ b/testcases/kernel/syscalls/mmap/mmap22.c @@ -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, -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap 2025-05-14 11:15 ` Jan Stancek via ltp @ 2025-05-14 12:44 ` Li Wang via ltp 2025-05-14 12:54 ` Jan Stancek via ltp 0 siblings, 1 reply; 20+ messages in thread From: Li Wang via ltp @ 2025-05-14 12:44 UTC (permalink / raw) To: Jan Stancek; +Cc: ltp Jan Stancek <jstancek@redhat.com> wrote: > > > 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: > > diff --git a/testcases/kernel/syscalls/mmap/mmap22.c > b/testcases/kernel/syscalls/mmap/mmap22.c > index 0e589dfab..56fe412d1 100644 > --- a/testcases/kernel/syscalls/mmap/mmap22.c > +++ b/testcases/kernel/syscalls/mmap/mmap22.c > @@ -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 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [LTP] [PATCH v4] mmap22.c: Test for new MAP_DROPPABLE flag for mmap 2025-05-14 12:44 ` Li Wang via ltp @ 2025-05-14 12:54 ` Jan Stancek via ltp 0 siblings, 0 replies; 20+ messages in thread From: Jan Stancek via ltp @ 2025-05-14 12:54 UTC (permalink / raw) To: Li Wang; +Cc: ltp On Wed, May 14, 2025 at 2:44 PM Li Wang <liwang@redhat.com> wrote: > > Jan Stancek <jstancek@redhat.com> wrote: > > > > > 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: > > > > diff --git a/testcases/kernel/syscalls/mmap/mmap22.c > > b/testcases/kernel/syscalls/mmap/mmap22.c > > index 0e589dfab..56fe412d1 100644 > > --- a/testcases/kernel/syscalls/mmap/mmap22.c > > +++ b/testcases/kernel/syscalls/mmap/mmap22.c > > @@ -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? Yes, I realized that when I was preparing the patch :-). > > 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. > > Anyway, testing will be much faster with this patch. > > -- > Regards, > Li Wang > -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2025-05-14 12:55 UTC | newest] Thread overview: 20+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-12-28 13:32 [LTP] [PATCH v1] mmap21.c: Test for new MAP_DROPPABLE flag for mmap Wei Gao via ltp 2024-12-31 10:04 ` Li Wang 2025-01-02 9:38 ` Cyril Hrubis 2025-01-03 1:42 ` Wei Gao via ltp 2025-01-03 13:54 ` Wei Gao via ltp 2025-01-03 13:56 ` [LTP] [PATCH v2] " Wei Gao via ltp 2025-03-10 16:18 ` Cyril Hrubis 2025-04-16 19:16 ` [LTP] [PATCH v3] mmap22.c: " Wei Gao via ltp 2025-04-25 11:40 ` Cyril Hrubis 2025-04-28 16:04 ` [LTP] [PATCH v4] " Wei Gao via ltp 2025-05-07 15:25 ` Cyril Hrubis 2025-05-12 8:43 ` Jan Stancek via ltp 2025-05-13 15:44 ` Wei Gao via ltp 2025-05-14 8:51 ` Jan Stancek via ltp 2025-05-14 9:04 ` Li Wang via ltp 2025-05-14 9:10 ` Jan Stancek via ltp 2025-05-14 9:14 ` Li Wang via ltp 2025-05-14 11:15 ` Jan Stancek via ltp 2025-05-14 12:44 ` Li Wang via ltp 2025-05-14 12:54 ` Jan Stancek via ltp
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox