[PATCH v2] malloc: Don't call __get_thp_mode/__get_thp_size twice
H.J. Lu
hjl.tools@gmail.com
Mon Jun 22 13:15:41 GMT 2026
This is identical to the first version. Now it can be applied
to master branch since its prerequisite has been merged into
master branch.
--
H.J.
---
Both ld.so and malloc track kernel THP mode and THP page size when THP
in ld.so is enabled by
GLIBC_TUNABLES=glibc.elf.thp=1
and THP in malloc is enabled by
GLIBC_TUNABLES=glibc.malloc.hugetlb=1
But DL_MAP_DEFAULT_THP_PAGESIZE and MALLOC_DEFAULT_THP_PAGESIZE may be
different when they are defined in <hugepages.h>.
If THP in ld.so is enabled, change malloc to use kernel THP mode from
ld.so, instead of calling __get_thp_mode, and use THP page size from
ld.so if it came from __get_thp_size. This avoids calling __get_thp_mode
and __get_thp_size again, which are quite expensive:
1. Initialize mp_.thp_mode and GL(dl_thp_mode) to thp_mode_unknown.
2. Set mp_.thp_mode to GL(dl_thp_mode) if GL(dl_thp_mode) isn't
thp_mode_unknown. Otherwise call __get_thp_mode to set mp_.thp_mode.
3. GL(dl_elf_thp_pagesize) is set to DL_MAP_DEFAULT_THP_PAGESIZE without
calling __get_thp_size and THP page size for malloc may be different from
THP page size for ld.so. Set mp_.thp_pagesize to GL(dl_elf_thp_pagesize)
if DL_MAP_DEFAULT_THP_PAGESIZE is defined. Otherwise call __get_thp_size
to set mp_.thp_pagesize.
This fixes BZ #34083.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2-0001-malloc-Don-t-call-__get_thp_mode-__get_thp_size-t.patch
Type: text/x-patch
Size: 4770 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20260622/bad6aa54/attachment.bin>
More information about the Libc-alpha
mailing list