For binaries that are compiled with '--pie -fPIC' and with LOAD alignment smaller than 2M (typically 4K, 64K), the load address is least likely to be 2M aligned. This changes the maximum_alignment of such binaries to 2M to facilitate file THP for .text section as far as possible. Signed-off-by: Gang Deng <gavin.dg@xxxxxxxxxxxxxxxxx> Signed-off-by: Xu Yu <xuyu@xxxxxxxxxxxxxxxxx> Signed-off-by: Rongwei Wang <rongwei.wang@xxxxxxxxxxxxxxxxx> --- fs/binfmt_elf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index a813b70f594e..78795572d877 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1136,6 +1136,11 @@ static int load_elf_binary(struct linux_binprm *bprm) retval = -EINVAL; goto out_free_dentry; } +#ifdef CONFIG_HUGETEXT + if (hugetext_enabled() && interpreter && + total_size >= HPAGE_PMD_SIZE) + load_bias &= HPAGE_PMD_MASK; +#endif } error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt, -- 2.27.0