[PATCH v2] mm, hugetlb: implement movable_gigantic_pages sysctl

Gregory Price posted 1 patch 1 week, 3 days ago
Documentation/admin-guide/sysctl/vm.rst | 17 +++++++++++++++++
include/linux/hugetlb.h                 |  3 ++-
mm/hugetlb.c                            | 11 +++++++++++
3 files changed, 30 insertions(+), 1 deletion(-)
[PATCH v2] mm, hugetlb: implement movable_gigantic_pages sysctl
Posted by Gregory Price 1 week, 3 days ago
This reintroduces a concept removed by 
commit d6cb41cc44c6 ("mm, hugetlb: remove hugepages_treat_as_movable sysctl")

This sysctl provides some flexibility between multiple ZONE_MOVABLE
use cases

1) onlining memory in ZONE_MOVABLE to maintain hotplug compatibility
2) onlining memory in ZONE_MOVABLE to make hugepage allocate reliable

When ZONE_MOVABLE is used to make huge page allocation more reliable,
disallowing gigantic pages memory in this region is pointless.  If
hotplug is not a requirement, we can loosen the restrictions to allow
1GB gigantic pages in ZONE_MOVABLE.

Since 1GB can be difficult to migrate / has impacts on compaction /
defragmentation, we don't enable this by default. Notably, 1GB pages
can only be migrated if another 1GB page is available - so hot-unplug
will fail if such a page cannot be found.

However, since there are scenarios where gigantic pages are migratable,
we should allow use of these on movable regions.

Note: Boot-time CMA is not possible for driver-managed hotplug memory,
as CMA requires the memory to be registered as SystemRAM at boot time.
Additionally, 1GB huge pages are not supported by THP.

Cc: David Hildenbrand <david@redhat.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Alexandru Moise <00moses.alexander00@gmail.com>
Suggested-by: David Rientjes <rientjes@google.com>
Signed-off-by: Gregory Price <gourry@gourry.net>
Link: https://lore.kernel.org/all/20180201193132.Hk7vI_xaU%25akpm@linux-foundation.org/
---
 Documentation/admin-guide/sysctl/vm.rst | 17 +++++++++++++++++
 include/linux/hugetlb.h                 |  3 ++-
 mm/hugetlb.c                            | 11 +++++++++++
 3 files changed, 30 insertions(+), 1 deletion(-)

---
v2: changelog updates


diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst
index b325bfbc2611..fe3982604b1f 100644
--- a/Documentation/admin-guide/sysctl/vm.rst
+++ b/Documentation/admin-guide/sysctl/vm.rst
@@ -54,6 +54,7 @@ Currently, these files are in /proc/sys/vm:
 - mmap_min_addr
 - mmap_rnd_bits
 - mmap_rnd_compat_bits
+- movable_gigantic_pages
 - nr_hugepages
 - nr_hugepages_mempolicy
 - nr_overcommit_hugepages
@@ -623,6 +624,22 @@ This value can be changed after boot using the
 /proc/sys/vm/mmap_rnd_compat_bits tunable
 
 
+movable_gigantic_pages
+======================
+
+This parameter controls whether gigantic pages may be allocated from
+ZONE_MOVABLE. If set to non-zero, gigantic hugepages can be allocated
+from ZONE_MOVABLE. ZONE_MOVABLE memory may be created via the kernel
+boot parameter `kernelcore` or via memory hotplug as discussed in
+Documentation/admin-guide/mm/memory-hotplug.rst.
+
+Support may depend on specific architecture.
+
+Note that using ZONE_MOVABLE gigantic pages may make features like
+memory hotremove more unreliable, as migrating gigantic pages is more
+difficult due to needing larger amounts of phyiscally contiguous memory.
+
+
 nr_hugepages
 ============
 
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index eb21619206af..451ede7b97dd 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -172,6 +172,7 @@ bool hugetlbfs_pagecache_present(struct hstate *h,
 
 struct address_space *hugetlb_folio_mapping_lock_write(struct folio *folio);
 
+extern int movable_gigantic_pages __read_mostly;
 extern int sysctl_hugetlb_shm_group;
 extern struct list_head huge_boot_pages[MAX_NUMNODES];
 
@@ -916,7 +917,7 @@ static inline bool hugepage_movable_supported(struct hstate *h)
 	if (!hugepage_migration_supported(h))
 		return false;
 
-	if (hstate_is_gigantic(h))
+	if (hstate_is_gigantic(h) && !movable_gigantic_pages)
 		return false;
 	return true;
 }
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 5b77fef5c4fd..c6363dad1e92 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -54,6 +54,8 @@
 #include "hugetlb_cma.h"
 #include <linux/page-isolation.h>
 
+int movable_gigantic_pages;
+
 int hugetlb_max_hstate __read_mostly;
 unsigned int default_hstate_idx;
 struct hstate hstates[HUGE_MAX_HSTATE];
@@ -5208,6 +5210,15 @@ static const struct ctl_table hugetlb_table[] = {
 		.mode		= 0644,
 		.proc_handler	= hugetlb_overcommit_handler,
 	},
+#ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION
+	{
+		.procname	= "movable_gigantic_pages",
+		.data		= &movable_gigantic_pages,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
+#endif
 };
 
 static void __init hugetlb_sysctl_init(void)
-- 
2.51.1
Re: [PATCH v2] mm, hugetlb: implement movable_gigantic_pages sysctl
Posted by David Hildenbrand (Red Hat) 6 days, 14 hours ago
On 11/21/25 20:27, Gregory Price wrote:
> This reintroduces a concept removed by
> commit d6cb41cc44c6 ("mm, hugetlb: remove hugepages_treat_as_movable sysctl")
> 
> This sysctl provides some flexibility between multiple ZONE_MOVABLE
> use cases
> 
> 1) onlining memory in ZONE_MOVABLE to maintain hotplug compatibility
> 2) onlining memory in ZONE_MOVABLE to make hugepage allocate reliable
> 
> When ZONE_MOVABLE is used to make huge page allocation more reliable,
> disallowing gigantic pages memory in this region is pointless.  If
> hotplug is not a requirement, we can loosen the restrictions to allow
> 1GB gigantic pages in ZONE_MOVABLE.
> 
> Since 1GB can be difficult to migrate / has impacts on compaction /
> defragmentation, we don't enable this by default. Notably, 1GB pages
> can only be migrated if another 1GB page is available - so hot-unplug
> will fail if such a page cannot be found.
> 
> However, since there are scenarios where gigantic pages are migratable,
> we should allow use of these on movable regions.
> 
> Note: Boot-time CMA is not possible for driver-managed hotplug memory,
> as CMA requires the memory to be registered as SystemRAM at boot time.
> Additionally, 1GB huge pages are not supported by THP.
> 
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Mel Gorman <mgorman@suse.de>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Alexandru Moise <00moses.alexander00@gmail.com>
> Suggested-by: David Rientjes <rientjes@google.com>
> Signed-off-by: Gregory Price <gourry@gourry.net>
> Link: https://lore.kernel.org/all/20180201193132.Hk7vI_xaU%25akpm@linux-foundation.org/
> ---
>   Documentation/admin-guide/sysctl/vm.rst | 17 +++++++++++++++++
>   include/linux/hugetlb.h                 |  3 ++-
>   mm/hugetlb.c                            | 11 +++++++++++
>   3 files changed, 30 insertions(+), 1 deletion(-)
> 
> ---
> v2: changelog updates
> 
> 
> diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst
> index b325bfbc2611..fe3982604b1f 100644
> --- a/Documentation/admin-guide/sysctl/vm.rst
> +++ b/Documentation/admin-guide/sysctl/vm.rst
> @@ -54,6 +54,7 @@ Currently, these files are in /proc/sys/vm:
>   - mmap_min_addr
>   - mmap_rnd_bits
>   - mmap_rnd_compat_bits
> +- movable_gigantic_pages
>   - nr_hugepages
>   - nr_hugepages_mempolicy
>   - nr_overcommit_hugepages
> @@ -623,6 +624,22 @@ This value can be changed after boot using the
>   /proc/sys/vm/mmap_rnd_compat_bits tunable
>   
>   
> +movable_gigantic_pages
> +======================
> +
> +This parameter controls whether gigantic pages may be allocated from
> +ZONE_MOVABLE. If set to non-zero, gigantic hugepages can be allocated

"gigantic pages" or "gigantic hugetlb pages"

> +from ZONE_MOVABLE. ZONE_MOVABLE memory may be created via the kernel
> +boot parameter `kernelcore` or via memory hotplug as discussed in
> +Documentation/admin-guide/mm/memory-hotplug.rst.
> +
> +Support may depend on specific architecture.
> +
> +Note that using ZONE_MOVABLE gigantic pages may make features like
> +memory hotremove more unreliable, as migrating gigantic pages is more
> +difficult due to needing larger amounts of phyiscally contiguous memory.

s/phyiscally/physically/ ?

Can we also reference this parameter here from 
Documentation/admin-guide/mm/memory-hotplug.rst?

In particular, there we also talk about gigantic pages and the 
interaction with ZONE_MOVABLE:

"
- Gigantic pages are unmovable, resulting in user space consuming a
   lot of unmovable memory.

- Huge pages are unmovable when an architectures does not support huge
   page migration, resulting in a similar issue as with gigantic pages.
"

And then later, we talk about "Even with ZONE_MOVABLE, there are some 
corner cases where offlining a memory
block might fail:" where this should be spelled out as well.

-- 
Cheers

David
Re: [PATCH v2] mm, hugetlb: implement movable_gigantic_pages sysctl
Posted by Gregory Price 6 days, 11 hours ago
On Tue, Nov 25, 2025 at 11:24:24AM +0100, David Hildenbrand (Red Hat) wrote:
> On 11/21/25 20:27, Gregory Price wrote:
> 
> Can we also reference this parameter here from
> Documentation/admin-guide/mm/memory-hotplug.rst?
> 

Good call

> In particular, there we also talk about gigantic pages and the interaction
> with ZONE_MOVABLE:
> 
> "
> - Gigantic pages are unmovable, resulting in user space consuming a
>   lot of unmovable memory.
> 
> - Huge pages are unmovable when an architectures does not support huge
>   page migration, resulting in a similar issue as with gigantic pages.
> "
> 
> And then later, we talk about "Even with ZONE_MOVABLE, there are some corner
> cases where offlining a memory
> block might fail:" where this should be spelled out as well.
> 

I will take a look, thank you!

> -- 
> Cheers
> 
> David