[LTP] [PATCH v5] mmapstress06: Convert to new API
Li Wang
li.wang@linux.dev
Wed Jun 10 04:26:57 CEST 2026
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
More information about the ltp
mailing list