Re: [RFC PATCH] binfmt_elf: Align eligible read-only PT_LOAD segments to PMD_SIZE for THP
From: Matthew Wilcox
Date: Mon Mar 02 2026 - 12:04:22 EST
On Mon, Mar 02, 2026 at 11:50:46PM +0800, WANG Rui wrote:
> +config ELF_RO_LOAD_THP_ALIGNMENT
> + bool "Align read-only ELF load segments for THP (EXPERIMENTAL)"
> + depends on READ_ONLY_THP_FOR_FS
This doesn't deserve a config option.
> +#if defined(CONFIG_ELF_RO_LOAD_THP_ALIGNMENT) && PMD_SIZE <= SZ_32M
Why 32MB? This is weird and not justified anywhere.
> + if (hugepage_global_always() && !(cmds[i].p_flags & PF_W)
> + && IS_ALIGNED(cmds[i].p_vaddr | cmds[i].p_offset, PMD_SIZE)
> + && cmds[i].p_filesz >= PMD_SIZE && p_align < PMD_SIZE)
> + p_align = PMD_SIZE;
Normal style is to put the '&&' at the end of the line:
if (!(cmds[i].p_flags & PF_W) &&
IS_ALIGNED(cmds[i].p_vaddr | cmds[i].p_offset, PMD_SIZE) &&
cmds[i].p_filesz >= PMD_SIZE && p_align < PMD_SIZE))
p_align = PMD_SIZE;
But this conditional is too complex to be at this level of indentation.
Factor it out into a helper:
if (align_to_pmd(cmds) && p_align < PMD_SIZE)
p_align = PMD_SIZE;