[Bug dynamic-link/34083] __get_thp_mode and __get_thp_size are called twice
"cvs-commit at gcc dot gnu.org via Glibc-bugs" <[email protected]> Fri, 26 Jun 2026 03:35:23 +0000
| Newsgroups | gmane.comp.lib.glibc.bugs |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://sourceware.org/bugzilla/show_bug.cgi?id=34083 --- Comment #2 from Sourceware Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by H.J. Lu <[email protected]>: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ccd4cd5324caaaea1bb12bc8cef073170da51a19 commit ccd4cd5324caaaea1bb12bc8cef073170da51a19 Author: H.J. Lu <[email protected]> Date: Sat Apr 18 11:36:41 2026 +0800 malloc: Don't call __get_thp_mode/__get_thp_size twice 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. 4. THP page size in malloc is capped to MAX_THP_PAGESIZE. If THP page size is above MAX_THP_PAGESIZE, THP in malloc is disabled. These result in when glibc.elf.thp is set to 1, malloc uses the actual kernel THP mode instead of defaulting to madvise mode and madvise_thp will stop issuing MADV_HUGEPAGE if kernel THP mode is always. This fixes BZ #34083. Signed-off-by: H.J. Lu <[email protected]> -- You are receiving this mail because: You are on the CC list for the bug.