malloc: Add madvise support for Transparent Huge Pages

System Internals / glibc - Adhemerval Zanella [] - 15 December 2021 20:35 UTC

Linux Transparent Huge Pages (THP) current supports three different states: 'never', 'madvise', and 'always'. The 'never' is self-explanatory and 'always' will enable THP for all anonymous pages. However, 'madvise' is still the default for some system and for such case THP will be only used if the memory range is explicity advertise by the program through a madvise(MADV_HUGEPAGE) call.

To enable it a new tunable is provided, 'glibc.malloc.hugetlb', where setting to a value diffent than 0 enables the madvise call.

This patch issues the madvise(MADV_HUGEPAGE) call after a successful mmap() call at sysmalloc() with sizes larger than the default huge page size. The madvise() call is disable is system does not support THP or if it has the mode set to "never" and on Linux only support one page size for THP, even if the architecture supports multiple sizes.

To test is a new rule is added tests-malloc-hugetlb1, which run the addes tests with the required GLIBC_TUNABLE setting.

Checked on x86_64-linux-gnu.

5f6d8d97c6 malloc: Add madvise support for Transparent Huge Pages
NEWS | 5 ++
Rules | 19 ++++++++
elf/dl-tunables.list | 5 ++
elf/tst-rtld-list-tunables.exp | 1 +
malloc/Makefile | 16 +++++++
malloc/arena.c | 5 ++
malloc/malloc-internal.h | 1 +
malloc/malloc.c | 47 +++++++++++++++++++
manual/tunables.texi | 10 ++++
sysdeps/generic/Makefile | 8 ++++
sysdeps/generic/malloc-hugepages.c | 31 +++++++++++++
sysdeps/generic/malloc-hugepages.h | 37 +++++++++++++++
sysdeps/unix/sysv/linux/malloc-hugepages.c | 74 ++++++++++++++++++++++++++++++
13 files changed, 259 insertions(+)


  • Share