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

Li Wang <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <[email protected]>
Wei Gao wrote:

> +
> +		mmapaddr = SAFE_MMAP(NULL, map_size, PROT_READ | PROT_WRITE,
> +				     MAP_ANONYMOUS | MAP_SHARED, -1, 0);
> +

> +		/*
> +		 * Disable Transparent Huge Pages (THP) for this mapping.
> +		 * Under tight cgroup memory limits (128 MB), allocating huge
> +		 * pages can easily trigger MemCG OOM-kills. Disabling THP forces
> +		 * standard 4 KB pages, ensuring stable swapping and avoiding
> +		 * premature OOM.
> +		 */
> +		if (madvise(mmapaddr, map_size, MADV_NOHUGEPAGE) < 0)
> +			tst_res(TWARN | TERRNO, "madvise(MADV_NOHUGEPAGE) failed");

The key point is that this is a MAP_ANONYMOUS | MAP_SHARED mapping.
Shared anonymous memory isn't backed by the normal anonymous-THP machinery,
it's backed internally by shmem/tmpfs.

THP behavior for shmem is governed by a separate knob:

  # cat /sys/kernel/mm/transparent_hugepage/shmem_enabled
  always within_size advise [never] deny force

basically all distro kernels this defaults to never.

So in the default configuration, no huge pages would ever be allocated for
this mapping, and the madvise(MADV_NOHUGEPAGE) is effectively a no-op.

-- 
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.