lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <34281230-c54e-4e2a-a872-c7ec6e9ed05a@lucifer.local>
Date: Fri, 24 Oct 2025 20:54:49 +0100
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
To: Dmitry Ilvokhin <d@...okhin.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
        David Hildenbrand <david@...hat.com>,
        "Liam R. Howlett" <Liam.Howlett@...cle.com>,
        Vlastimil Babka <vbabka@...e.cz>, Mike Rapoport <rppt@...nel.org>,
        Suren Baghdasaryan <surenb@...gle.com>, Michal Hocko <mhocko@...e.com>,
        Hugh Dickins <hughd@...gle.com>,
        Baolin Wang <baolin.wang@...ux.alibaba.com>,
        Kiryl Shutsemau <kas@...nel.org>, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org, kernel-team@...a.com
Subject: Re: [PATCH] mm: shmem/tmpfs hugepage defaults config choice

On Thu, Oct 23, 2025 at 06:12:02PM +0000, Dmitry Ilvokhin wrote:
> Allow to override defaults for shemem and tmpfs at config time. This is
> consistent with how transparent hugepages can be configured.
>
> Same results can be achieved with the existing
> 'transparent_hugepage_shmem' and 'transparent_hugepage_tmpfs' settings
> in the kernel command line, but it is more convenient to define basic
> settings at config time instead of changing kernel command line later.
>
> Defaults for shmem and tmpfs were not changed. They are remained the
> same as before: 'never' for both cases. Options 'deny' and 'force' are
> omitted intentionally since these are special values and supposed to be
> used for emergencies or testing and are not expected to be permanent
> ones.
>
> Signed-off-by: Dmitry Ilvokhin <d@...okhin.com>

This looks reasonable, thanks.

I guess one fly in the ointment is that these settings are only applicable
for those THP page sizes (both for anon and shmem) that are set to inherit,
but of course we default to this at startup so that's fine, just an
annoying point of confusion in THP generally :)

Based on your response to Michal, whose question is really at the crux of
this, LGTM, so:

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>

> ---
>  mm/Kconfig | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  mm/shmem.c | 33 ++++++++++++++++++--
>  2 files changed, 122 insertions(+), 2 deletions(-)
>
> diff --git a/mm/Kconfig b/mm/Kconfig
> index e47321051d76..5ceea38edbe1 100644
> --- a/mm/Kconfig
> +++ b/mm/Kconfig
> @@ -853,6 +853,97 @@ choice
>  	  enabled at runtime via sysfs.
>  endchoice
>
> +choice
> +	prompt "Shmem hugepage allocation defaults"
> +	depends on TRANSPARENT_HUGEPAGE
> +	default TRANSPARENT_HUGEPAGE_SHMEM_HUGE_NEVER
> +	help
> +	  Selects the hugepage allocation policy defaults for
> +	  the internal shmem mount.
> +
> +	  The selection made here can be overridden by using the kernel
> +	  command line 'transparent_hugepage_shmem=' option.
> +
> +	config TRANSPARENT_HUGEPAGE_SHMEM_HUGE_NEVER
> +		bool "never"
> +	help
> +	  Disable hugepage allocation for shmem mount by default. It can
> +	  still be enabled with the kernel command line
> +	  'transparent_hugepage_shmem=' option or at runtime via sysfs
> +	  knob. Note that madvise(MADV_COLLAPSE) can still cause
> +	  transparent huge pages to be obtained even if this mode is
> +	  specified.
> +
> +	config TRANSPARENT_HUGEPAGE_SHMEM_HUGE_ALWAYS
> +		bool "always"
> +	help
> +	  Always attempt to allocate hugepage for shmem mount, can
> +	  increase the memory footprint of applications without a
> +	  guaranteed benefit but it will work automatically for all
> +	  applications.
> +
> +	config TRANSPARENT_HUGEPAGE_SHMEM_HUGE_WITHIN_SIZE
> +		bool "within_size"
> +	help
> +	  Enable hugepage allocation for shmem mount if the allocation
> +	  will be fully within the i_size. This configuration also takes
> +	  into account any madvise(MADV_HUGEPAGE) hints that may be
> +	  provided by the applications.
> +
> +	config TRANSPARENT_HUGEPAGE_SHMEM_HUGE_ADVISE
> +		bool "advise"
> +	help
> +	  Enable hugepage allocation for the shmem mount exclusively when
> +	  applications supply the madvise(MADV_HUGEPAGE) hint.
> +	  This ensures that hugepages are used only in response to explicit
> +	  requests from applications.
> +endchoice
> +
> +choice
> +	prompt "Tmpfs hugepage allocation defaults"
> +	depends on TRANSPARENT_HUGEPAGE
> +	default TRANSPARENT_HUGEPAGE_TMPFS_HUGE_NEVER
> +	help
> +	  Selects the hugepage allocation policy defaults for
> +	  the tmpfs mount.
> +
> +	  The selection made here can be overridden by using the kernel
> +	  command line 'transparent_hugepage_tmpfs=' option.
> +
> +	config TRANSPARENT_HUGEPAGE_TMPFS_HUGE_NEVER
> +		bool "never"
> +	help
> +	  Disable hugepage allocation for tmpfs mount by default. It can
> +	  still be enabled with the kernel command line
> +	  'transparent_hugepage_tmpfs=' option. Note that
> +	  madvise(MADV_COLLAPSE) can still cause transparent huge pages
> +	  to be obtained even if this mode is specified.
> +
> +	config TRANSPARENT_HUGEPAGE_TMPFS_HUGE_ALWAYS
> +		bool "always"
> +	help
> +	  Always attempt to allocate hugepage for tmpfs mount, can
> +	  increase the memory footprint of applications without a
> +	  guaranteed benefit but it will work automatically for all
> +	  applications.
> +
> +	config TRANSPARENT_HUGEPAGE_TMPFS_HUGE_WITHIN_SIZE
> +		bool "within_size"
> +	help
> +	  Enable hugepage allocation for tmpfs mount if the allocation
> +	  will be fully within the i_size. This configuration also takes
> +	  into account any madvise(MADV_HUGEPAGE) hints that may be
> +	  provided by the applications.
> +
> +	config TRANSPARENT_HUGEPAGE_TMPFS_HUGE_ADVISE
> +		bool "advise"
> +	help
> +	  Enable hugepage allocation for the tmpfs mount exclusively when
> +	  applications supply the madvise(MADV_HUGEPAGE) hint.
> +	  This ensures that hugepages are used only in response to explicit
> +	  requests from applications.
> +endchoice
> +
>  config THP_SWAP
>  	def_bool y
>  	depends on TRANSPARENT_HUGEPAGE && ARCH_WANTS_THP_SWAP && SWAP && 64BIT
> diff --git a/mm/shmem.c b/mm/shmem.c
> index eb8161136a7f..a411d7fb6e5a 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -570,8 +570,37 @@ static int shmem_confirm_swap(struct address_space *mapping, pgoff_t index,
>  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>  /* ifdef here to avoid bloating shmem.o when not necessary */
>
> -static int shmem_huge __read_mostly = SHMEM_HUGE_NEVER;
> -static int tmpfs_huge __read_mostly = SHMEM_HUGE_NEVER;
> +#if defined(CONFIG_TRANSPARENT_HUGEPAGE_SHMEM_HUGE_NEVER)
> +#define SHMEM_HUGE_DEFAULT SHMEM_HUGE_NEVER
> +#elif defined(CONFIG_TRANSPARENT_HUGEPAGE_SHMEM_HUGE_ALWAYS)
> +#define SHMEM_HUGE_DEFAULT SHMEM_HUGE_ALWAYS
> +#elif defined(CONFIG_TRANSPARENT_HUGEPAGE_SHMEM_HUGE_WITHIN_SIZE)
> +#define SHMEM_HUGE_DEFAULT SHMEM_HUGE_WITHIN_SIZE
> +#elif defined(CONFIG_TRANSPARENT_HUGEPAGE_SHMEM_HUGE_ADVISE)
> +#define SHMEM_HUGE_DEFAULT SHMEM_HUGE_ADVISE
> +#else
> +#define SHMEM_HUGE_DEFAULT SHMEM_HUGE_NEVER
> +#endif
> +
> +static int shmem_huge __read_mostly = SHMEM_HUGE_DEFAULT;
> +
> +#undef SHMEM_HUGE_DEFAULT
> +
> +#if defined(CONFIG_TRANSPARENT_HUGEPAGE_TMPFS_HUGE_NEVER)
> +#define TMPFS_HUGE_DEFAULT SHMEM_HUGE_NEVER
> +#elif defined(CONFIG_TRANSPARENT_HUGEPAGE_TMPFS_HUGE_ALWAYS)
> +#define TMPFS_HUGE_DEFAULT SHMEM_HUGE_ALWAYS
> +#elif defined(CONFIG_TRANSPARENT_HUGEPAGE_TMPFS_HUGE_WITHIN_SIZE)
> +#define TMPFS_HUGE_DEFAULT SHMEM_HUGE_WITHIN_SIZE
> +#elif defined(CONFIG_TRANSPARENT_HUGEPAGE_TMPFS_HUGE_ADVISE)
> +#define TMPFS_HUGE_DEFAULT SHMEM_HUGE_ADVISE
> +#else
> +#define TMPFS_HUGE_DEFAULT SHMEM_HUGE_NEVER
> +#endif
> +
> +static int tmpfs_huge __read_mostly = TMPFS_HUGE_DEFAULT;
> +
> +#undef TMPFS_HUGE_DEFAULT
>
>  static unsigned int shmem_get_orders_within_size(struct inode *inode,
>  		unsigned long within_size_orders, pgoff_t index,
> --
> 2.47.3
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ