Linux Test Project
 help / color / mirror / Atom feed
From: Li Wang <li.wang@linux.dev>
To: Huaisheng Ye <yehuaisheng@open-hieco.net>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2 2/3] hugemmap10: Add private MAP_NORESERVE test mode
Date: Thu, 8 Oct 2026 17:09:50 +0800	[thread overview]
Message-ID: <asdd3iGIWDstN4lT@linux.dev> (raw)
In-Reply-To: <20260929072412.20979-3-yehuaisheng@open-hieco.net>

Huaisheng Ye wrote:

> 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. As a result, private_resv and its TDEBUG report describe whether
> the private mappings actually in use create a hugetlb reservation at
> mmap() time. This is true both for the kernel default and when -n forces
> fault-time reservations.
> 
> The option lets the test exercise the fault-time private reservation path
> used by upstream kernels without booting an older kernel.

The new mode is useful, but it should also be added to runtest/hugetlb,
otherwise the fault-time path is never exercised by the default test run:

--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -13,6 +13,7 @@ hugemmap07 hugemmap07
 hugemmap08 hugemmap08
 hugemmap09 hugemmap09
 hugemmap10 hugemmap10
+hugemmap10 hugemmap10 -n

> 
> Signed-off-by: Huaisheng Ye <yehuaisheng@open-hieco.net>
> ---
>  .../kernel/mem/hugetlb/hugemmap/hugemmap10.c  | 28 +++++++++++++++++--
>  1 file changed, 25 insertions(+), 3 deletions(-)
> 
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
> index b22e11f41..1a5b0fd2f 100644
> --- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
> @@ -31,6 +31,8 @@
>  
>  static long hpage_size;
>  static int private_resv;
> +static int private_noreserve;

The private_noreserve variable looks redundant. We can simply use
private_noreserve_opt directly, since it is already NULL when -n is
not given and non-NULL when it is.

	if (private_noreserve_opt && (flags & MAP_TYPE) == MAP_PRIVATE)
		return flags | MAP_NORESERVE;

> +static char *private_noreserve_opt;
>  
>  #define NR_SLOTS	2
>  #define SL_SETUP	0
> @@ -90,6 +92,16 @@ static int mapping_creates_reservation(int flags)
>  	return (flags & MAP_SHARED) || private_resv;
>  }
>  
> +/* Exercise the fault-time reservation path used by older kernels. */
> +static int private_mmap_flags(int flags)
> +{
> +	if (private_noreserve &&
> +	    (flags & MAP_TYPE) == MAP_PRIVATE)
> +		return flags | MAP_NORESERVE;
> +
> +	return flags;
> +}

We need to add the MAP_TYPE definition to lapi/mmap.h to avoid
compilation failures on systems where glibc (<sys/mman.h>)
doesn't support it.

#ifndef MAP_TYPE
#define MAP_TYPE 0x0f
#endif

> +
>  static unsigned long read_allowed_free_hugepages(void)
>  {
>  	char path[PATH_MAX];
> @@ -155,7 +167,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);
>  
> @@ -283,8 +296,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;
> @@ -533,7 +547,10 @@ static void setup(void)
>  {
>  	hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
>  	SAFE_FILE_PRINTF(PATH_VM_OVERCOMMIT_HPAGES, "%lu", tst_hugepages);

> +	private_noreserve = !!private_noreserve_opt;
Drop this line.

>  	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)
> @@ -543,6 +560,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
> 

-- 
Regards,
Li Wang

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

  reply	other threads:[~2026-10-08  9:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29  7:24 [LTP] [PATCH v2 0/3] hugemmap10: Account for memory policy in counter checks Huaisheng Ye
2026-09-29  7:24 ` [LTP] [PATCH v2 1/3] hugemmap10: Account for memory policy in mmap " Huaisheng Ye
2026-09-29 11:18   ` [LTP] " linuxtestproject.agent
2026-10-08  8:26   ` [LTP] [PATCH v2 1/3] " Li Wang
2026-09-29  7:24 ` [LTP] [PATCH v2 2/3] hugemmap10: Add private MAP_NORESERVE test mode Huaisheng Ye
2026-10-08  9:09   ` Li Wang [this message]
2026-09-29  7:24 ` [LTP] [PATCH v2 3/3] hugemmap10: Account for memory policy in private fault checks Huaisheng Ye
2026-10-08  9:40   ` Li Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=asdd3iGIWDstN4lT@linux.dev \
    --to=li.wang@linux.dev \
    --cc=ltp@lists.linux.it \
    --cc=yehuaisheng@open-hieco.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox