[LTP] [PATCH v4 2/3] hugemmap10: Add private MAP_NORESERVE test mode
Huaisheng Ye
yehuaisheng@open-hieco.net
Mon Oct 26 08:07:31 CET 2026
Add -n to apply MAP_NORESERVE only to private mappings. Shared
mappings retain their original flags and reservation behavior.
Use the private mapping flags for both the reservation probe and test
mappings. This makes private_resv and its TDEBUG report reflect whether
the mappings in use create a hugetlb reservation at mmap() time.
The option lets the test exercise fault-time allocation for unreserved
private mappings without booting a kernel that lacks private mmap-time
reservations. MAP_NORESERVE faults allocate unreserved hugepages without
creating a mapping reservation, so HugePages_Rsvd remains unchanged.
Add hugemmap10 -n to runtest/hugetlb with the distinct identifier
hugemmap10_noreserve so session restore and reboot recovery can track
both invocations independently.
Use private_noreserve_opt directly as the option presence flag. Define
MAP_TYPE in lapi/mmap.h for libc implementations that lack it.
Signed-off-by: Huaisheng Ye <yehuaisheng@open-hieco.net>
Reviewed-by: Li Wang (Hieco) <li.wang@linux.dev>
---
include/lapi/mmap.h | 4 +++
runtest/hugetlb | 1 +
.../kernel/mem/hugetlb/hugemmap/hugemmap10.c | 27 ++++++++++++++++---
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/include/lapi/mmap.h b/include/lapi/mmap.h
index f20eb3bd5..12085ae27 100644
--- a/include/lapi/mmap.h
+++ b/include/lapi/mmap.h
@@ -14,6 +14,10 @@
# define MAP_SHARED_VALIDATE 0x03
#endif
+#ifndef MAP_TYPE
+# define MAP_TYPE 0x0f
+#endif
+
#ifndef MAP_HUGETLB
# define MAP_HUGETLB 0x40000
#endif
diff --git a/runtest/hugetlb b/runtest/hugetlb
index 621c9718a..5288449b7 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -13,6 +13,7 @@ hugemmap07 hugemmap07
hugemmap08 hugemmap08
hugemmap09 hugemmap09
hugemmap10 hugemmap10
+hugemmap10_noreserve hugemmap10 -n
hugemmap11 hugemmap11
hugemmap12 hugemmap12
hugemmap13 hugemmap13
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
index 7abda1182..08597049d 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
@@ -25,6 +25,7 @@
#include <sys/types.h>
#include "hugetlb.h"
+#include "lapi/mmap.h"
#include "lapi/syscalls.h"
#define MNTPOINT "hugetlbfs/"
@@ -32,6 +33,7 @@
static long hpage_size;
static int private_resv;
+static char *private_noreserve_opt;
#define NR_SLOTS 2
#define SL_SETUP 0
@@ -125,6 +127,16 @@ static int mapping_creates_reservation(int flags)
return (flags & MAP_SHARED) || private_resv;
}
+/* Exercise fault-time allocation for unreserved private mappings. */
+static int private_mmap_flags(int flags)
+{
+ if (private_noreserve_opt &&
+ (flags & MAP_TYPE) == MAP_PRIVATE)
+ return flags | MAP_NORESERVE;
+
+ return flags;
+}
+
static unsigned long read_allowed_free_hugepages(void)
{
char path[PATH_MAX];
@@ -194,7 +206,8 @@ static int kernel_has_private_reservations(void)
read_meminfo_huge(&t, &f, &r, &s);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
- p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+ p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE,
+ private_mmap_flags(MAP_PRIVATE), fd, 0);
read_meminfo_huge(&nt, &nf, &nr, &ns);
@@ -322,8 +335,9 @@ static int map_(int s, int hpages, int flags, char *desc, int line)
map_size[s] = hpages * hpage_size;
if (creates_reservation)
allowed_free = read_allowed_free_hugepages();
- map_addr[s] = SAFE_MMAP(NULL, map_size[s], PROT_READ|PROT_WRITE, flags,
- map_fd[s], 0);
+ map_addr[s] = SAFE_MMAP(NULL, map_size[s], PROT_READ|PROT_WRITE,
+ private_mmap_flags(flags),
+ map_fd[s], 0);
touched[s] = 0;
et = prev_total;
@@ -573,6 +587,8 @@ static void setup(void)
hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
SAFE_FILE_PRINTF(PATH_VM_OVERCOMMIT_HPAGES, "%lu", tst_hugepages);
private_resv = kernel_has_private_reservations();
+ tst_res(TDEBUG, "MAP_PRIVATE mmap() %s a hugetlb reservation",
+ private_resv ? "creates" : "does not create");
}
static void cleanup(void)
@@ -582,6 +598,11 @@ static void cleanup(void)
static struct tst_test test = {
.needs_root = 1,
+ .options = (struct tst_option[]) {
+ {"n", &private_noreserve_opt,
+ "Map private VMAs with MAP_NORESERVE"},
+ {}
+ },
.mntpoint = MNTPOINT,
.needs_hugetlbfs = 1,
.save_restore = (const struct tst_path_val[]) {
--
2.52.0
More information about the ltp
mailing list