* [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper
@ 2025-10-09 17:24 Usama Arif
2025-10-09 17:24 ` [PATCH v2 2/2] mm/hugetlb: allow overcommitting gigantic hugepages Usama Arif
` (5 more replies)
0 siblings, 6 replies; 12+ messages in thread
From: Usama Arif @ 2025-10-09 17:24 UTC (permalink / raw)
To: muchun.song, osalvador, david, Andrew Morton
Cc: shakeel.butt, linux-mm, hannes, riel, kas, linux-kernel,
kernel-team, Usama Arif
This is a common condition used to skip operations that cannot
be performed on gigantic pages when runtime support is disabled.
This helper is introduced as the condition will exist even more
when allowing "overcommit" of gigantic hugepages.
No functional change intended with this patch.
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Usama Arif <usamaarif642@gmail.com>
---
mm/hugetlb.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index c07b7192aff26..e74e41386b100 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -134,6 +134,17 @@ static void hugetlb_free_folio(struct folio *folio)
folio_put(folio);
}
+/*
+ * Check if the hstate represents gigantic pages but gigantic page
+ * runtime support is not available. This is a common condition used to
+ * skip operations that cannot be performed on gigantic pages when runtime
+ * support is disabled.
+ */
+static inline bool hstate_is_gigantic_no_runtime(struct hstate *h)
+{
+ return hstate_is_gigantic(h) && !gigantic_page_runtime_supported();
+}
+
static inline bool subpool_is_free(struct hugepage_subpool *spool)
{
if (spool->count)
@@ -1555,7 +1566,7 @@ static void remove_hugetlb_folio(struct hstate *h, struct folio *folio,
VM_BUG_ON_FOLIO(hugetlb_cgroup_from_folio_rsvd(folio), folio);
lockdep_assert_held(&hugetlb_lock);
- if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
+ if (hstate_is_gigantic_no_runtime(h))
return;
list_del(&folio->lru);
@@ -1617,7 +1628,7 @@ static void __update_and_free_hugetlb_folio(struct hstate *h,
{
bool clear_flag = folio_test_hugetlb_vmemmap_optimized(folio);
- if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
+ if (hstate_is_gigantic_no_runtime(h))
return;
/*
@@ -2511,7 +2522,7 @@ static void return_unused_surplus_pages(struct hstate *h,
/* Uncommit the reservation */
h->resv_huge_pages -= unused_resv_pages;
- if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
+ if (hstate_is_gigantic_no_runtime(h))
goto out;
/*
@@ -3725,7 +3736,7 @@ static void __init hugetlb_init_hstates(void)
* - If CMA allocation is possible, we can not demote
* HUGETLB_PAGE_ORDER or smaller size pages.
*/
- if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
+ if (hstate_is_gigantic_no_runtime(h))
continue;
if (hugetlb_cma_total_size() && h->order <= HUGETLB_PAGE_ORDER)
continue;
@@ -4202,7 +4213,7 @@ static ssize_t __nr_hugepages_store_common(bool obey_mempolicy,
int err;
nodemask_t nodes_allowed, *n_mask;
- if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
+ if (hstate_is_gigantic_no_runtime(h))
return -EINVAL;
if (nid == NUMA_NO_NODE) {
--
2.47.3
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 2/2] mm/hugetlb: allow overcommitting gigantic hugepages
2025-10-09 17:24 [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper Usama Arif
@ 2025-10-09 17:24 ` Usama Arif
2025-10-10 0:32 ` Shakeel Butt
2025-10-13 8:00 ` Oscar Salvador
2025-10-09 19:11 ` [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper SeongJae Park
` (4 subsequent siblings)
5 siblings, 2 replies; 12+ messages in thread
From: Usama Arif @ 2025-10-09 17:24 UTC (permalink / raw)
To: muchun.song, osalvador, david, Andrew Morton
Cc: shakeel.butt, linux-mm, hannes, riel, kas, linux-kernel,
kernel-team, Usama Arif
Currently, gigantic hugepages cannot use the overcommit mechanism
(nr_overcommit_hugepages), forcing users to permanently reserve memory via
nr_hugepages even when pages might not be actively used.
The restriction was added in 2011 [1], which was before there was support
for reserving 1G hugepages at runtime.
Remove this blanket restriction on gigantic hugepage overcommit.
This will bring the same benefits to gigantic pages as hugepages:
- Memory is only taken out of regular use when actually needed
- Unused surplus pages can be returned to the system
- Better memory utilization, especially with CMA backing which can
significantly increase the changes of hugepage allocation
Without this patch:
echo 3 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_overcommit_hugepages
bash: echo: write error: Invalid argument
With this patch:
echo 3 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_overcommit_hugepages
./mmap_hugetlb_test
Successfully allocated huge pages at address: 0x7f9d40000000
cat mmap_hugetlb_test.c
...
unsigned long ALLOC_SIZE = 3 * (unsigned long) HUGE_PAGE_SIZE;
addr = mmap(NULL,
ALLOC_SIZE, // 3GB
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_HUGE_1GB,
-1,
0);
if (addr == MAP_FAILED) {
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
return 1;
}
printf("Successfully allocated huge pages at address: %p\n", addr);
...
[1] https://git.zx2c4.com/linux-rng/commit/mm/hugetlb.c?id=adbe8726dc2a3805630d517270db17e3af86e526
Signed-off-by: Usama Arif <usamaarif642@gmail.com>
---
mm/hugetlb.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index e74e41386b100..c0036c0775d75 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2243,7 +2243,7 @@ static struct folio *alloc_surplus_hugetlb_folio(struct hstate *h,
{
struct folio *folio = NULL;
- if (hstate_is_gigantic(h))
+ if (hstate_is_gigantic_no_runtime(h))
return NULL;
spin_lock_irq(&hugetlb_lock);
@@ -4305,7 +4305,7 @@ static ssize_t nr_overcommit_hugepages_store(struct kobject *kobj,
unsigned long input;
struct hstate *h = kobj_to_hstate(kobj, NULL);
- if (hstate_is_gigantic(h))
+ if (hstate_is_gigantic_no_runtime(h))
return -EINVAL;
err = kstrtoul(buf, 10, &input);
@@ -5192,7 +5192,7 @@ static int hugetlb_overcommit_handler(const struct ctl_table *table, int write,
tmp = h->nr_overcommit_huge_pages;
- if (write && hstate_is_gigantic(h))
+ if (write && hstate_is_gigantic_no_runtime(h))
return -EINVAL;
ret = proc_hugetlb_doulongvec_minmax(table, write, buffer, length, ppos,
--
2.47.3
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper
2025-10-09 17:24 [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper Usama Arif
2025-10-09 17:24 ` [PATCH v2 2/2] mm/hugetlb: allow overcommitting gigantic hugepages Usama Arif
@ 2025-10-09 19:11 ` SeongJae Park
2025-10-09 19:24 ` SeongJae Park
2025-10-10 11:53 ` Usama Arif
2025-10-10 0:31 ` Shakeel Butt
` (3 subsequent siblings)
5 siblings, 2 replies; 12+ messages in thread
From: SeongJae Park @ 2025-10-09 19:11 UTC (permalink / raw)
To: Usama Arif
Cc: SeongJae Park, muchun.song, osalvador, david, Andrew Morton,
shakeel.butt, linux-mm, hannes, riel, kas, linux-kernel,
kernel-team
Hi Usama,
On Thu, 9 Oct 2025 18:24:30 +0100 Usama Arif <usamaarif642@gmail.com> wrote:
> This is a common condition used to skip operations that cannot
> be performed on gigantic pages when runtime support is disabled.
> This helper is introduced as the condition will exist even more
> when allowing "overcommit" of gigantic hugepages.
> No functional change intended with this patch.
The change looks good to me. I have a couple of trivial comments below.
>
> Suggested-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
> ---
I think adding a change log since v1 here, or adding a cover letter with it
would be nice.
> mm/hugetlb.c | 21 ++++++++++++++++-----
> 1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index c07b7192aff26..e74e41386b100 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -134,6 +134,17 @@ static void hugetlb_free_folio(struct folio *folio)
> folio_put(folio);
> }
>
> +/*
> + * Check if the hstate represents gigantic pages but gigantic page
> + * runtime support is not available. This is a common condition used to
> + * skip operations that cannot be performed on gigantic pages when runtime
> + * support is disabled.
> + */
> +static inline bool hstate_is_gigantic_no_runtime(struct hstate *h)
> +{
> + return hstate_is_gigantic(h) && !gigantic_page_runtime_supported();
> +}
> +
> static inline bool subpool_is_free(struct hugepage_subpool *spool)
> {
> if (spool->count)
> @@ -1555,7 +1566,7 @@ static void remove_hugetlb_folio(struct hstate *h, struct folio *folio,
> VM_BUG_ON_FOLIO(hugetlb_cgroup_from_folio_rsvd(folio), folio);
>
> lockdep_assert_held(&hugetlb_lock);
> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> + if (hstate_is_gigantic_no_runtime(h))
> return;
>
> list_del(&folio->lru);
> @@ -1617,7 +1628,7 @@ static void __update_and_free_hugetlb_folio(struct hstate *h,
> {
> bool clear_flag = folio_test_hugetlb_vmemmap_optimized(folio);
>
> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> + if (hstate_is_gigantic_no_runtime(h))
> return;
>
> /*
> @@ -2511,7 +2522,7 @@ static void return_unused_surplus_pages(struct hstate *h,
> /* Uncommit the reservation */
> h->resv_huge_pages -= unused_resv_pages;
>
> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> + if (hstate_is_gigantic_no_runtime(h))
> goto out;
>
> /*
> @@ -3725,7 +3736,7 @@ static void __init hugetlb_init_hstates(void)
> * - If CMA allocation is possible, we can not demote
> * HUGETLB_PAGE_ORDER or smaller size pages.
> */
> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> + if (hstate_is_gigantic_no_runtime(h))
> continue;
> if (hugetlb_cma_total_size() && h->order <= HUGETLB_PAGE_ORDER)
> continue;
> @@ -4202,7 +4213,7 @@ static ssize_t __nr_hugepages_store_common(bool obey_mempolicy,
> int err;
> nodemask_t nodes_allowed, *n_mask;
>
> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> + if (hstate_is_gigantic_no_runtime(h))
> return -EINVAL;
>
> if (nid == NUMA_NO_NODE) {
> --
> 2.47.3
It seems the new helper could be used for three more cases.
On mm-new:
$ git grep gigantic_page_runtime_supported mm/hugetlb.c
mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
mm/hugetlb.c: if (write && hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
After applying this patch on top of mm-new:
$ git grep gigantic_page_runtime_supported mm/hugetlb.c
mm/hugetlb.c: return hstate_is_gigantic(h) && !gigantic_page_runtime_supported();
mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
mm/hugetlb.c: if (write && hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
I'm curious if you are planning to do the conversion later, or there is a
reason why this patch is keeping those as is but I'm missing.
Thanks,
SJ
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper
2025-10-09 19:11 ` [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper SeongJae Park
@ 2025-10-09 19:24 ` SeongJae Park
2025-10-10 11:53 ` Usama Arif
1 sibling, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-10-09 19:24 UTC (permalink / raw)
To: SeongJae Park
Cc: Usama Arif, muchun.song, osalvador, david, Andrew Morton,
shakeel.butt, linux-mm, hannes, riel, kas, linux-kernel,
kernel-team
On Thu, 9 Oct 2025 12:11:49 -0700 SeongJae Park <sj@kernel.org> wrote:
> Hi Usama,
>
> On Thu, 9 Oct 2025 18:24:30 +0100 Usama Arif <usamaarif642@gmail.com> wrote:
>
> > This is a common condition used to skip operations that cannot
> > be performed on gigantic pages when runtime support is disabled.
> > This helper is introduced as the condition will exist even more
> > when allowing "overcommit" of gigantic hugepages.
> > No functional change intended with this patch.
[...]
> It seems the new helper could be used for three more cases.
>
> On mm-new:
>
> $ git grep gigantic_page_runtime_supported mm/hugetlb.c
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (write && hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
>
> After applying this patch on top of mm-new:
>
> $ git grep gigantic_page_runtime_supported mm/hugetlb.c
> mm/hugetlb.c: return hstate_is_gigantic(h) && !gigantic_page_runtime_supported();
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (write && hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
>
> I'm curious if you are planning to do the conversion later, or there is a
> reason why this patch is keeping those as is but I'm missing.
Ah, seems like that's because the v1 [1] of this series is already merged into
mm-new.
Please ignore the above question unless I'm wrong.
[1] https://patch.msgid.link/20251009172433.4158118-1-usamaarif642@gmail.com
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper
2025-10-09 17:24 [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper Usama Arif
2025-10-09 17:24 ` [PATCH v2 2/2] mm/hugetlb: allow overcommitting gigantic hugepages Usama Arif
2025-10-09 19:11 ` [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper SeongJae Park
@ 2025-10-10 0:31 ` Shakeel Butt
2025-10-13 7:56 ` Oscar Salvador
` (2 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Shakeel Butt @ 2025-10-10 0:31 UTC (permalink / raw)
To: Usama Arif
Cc: muchun.song, osalvador, david, Andrew Morton, linux-mm, hannes,
riel, kas, linux-kernel, kernel-team
On Thu, Oct 09, 2025 at 06:24:30PM +0100, Usama Arif wrote:
> This is a common condition used to skip operations that cannot
> be performed on gigantic pages when runtime support is disabled.
> This helper is introduced as the condition will exist even more
> when allowing "overcommit" of gigantic hugepages.
> No functional change intended with this patch.
>
> Suggested-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 2/2] mm/hugetlb: allow overcommitting gigantic hugepages
2025-10-09 17:24 ` [PATCH v2 2/2] mm/hugetlb: allow overcommitting gigantic hugepages Usama Arif
@ 2025-10-10 0:32 ` Shakeel Butt
2025-10-13 8:00 ` Oscar Salvador
1 sibling, 0 replies; 12+ messages in thread
From: Shakeel Butt @ 2025-10-10 0:32 UTC (permalink / raw)
To: Usama Arif
Cc: muchun.song, osalvador, david, Andrew Morton, linux-mm, hannes,
riel, kas, linux-kernel, kernel-team
On Thu, Oct 09, 2025 at 06:24:31PM +0100, Usama Arif wrote:
> Currently, gigantic hugepages cannot use the overcommit mechanism
> (nr_overcommit_hugepages), forcing users to permanently reserve memory via
> nr_hugepages even when pages might not be actively used.
>
> The restriction was added in 2011 [1], which was before there was support
> for reserving 1G hugepages at runtime.
> Remove this blanket restriction on gigantic hugepage overcommit.
> This will bring the same benefits to gigantic pages as hugepages:
>
> - Memory is only taken out of regular use when actually needed
> - Unused surplus pages can be returned to the system
> - Better memory utilization, especially with CMA backing which can
> significantly increase the changes of hugepage allocation
>
> Without this patch:
> echo 3 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_overcommit_hugepages
> bash: echo: write error: Invalid argument
>
> With this patch:
> echo 3 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_overcommit_hugepages
> ./mmap_hugetlb_test
> Successfully allocated huge pages at address: 0x7f9d40000000
>
> cat mmap_hugetlb_test.c
> ...
> unsigned long ALLOC_SIZE = 3 * (unsigned long) HUGE_PAGE_SIZE;
> addr = mmap(NULL,
> ALLOC_SIZE, // 3GB
> PROT_READ | PROT_WRITE,
> MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_HUGE_1GB,
> -1,
> 0);
>
> if (addr == MAP_FAILED) {
> fprintf(stderr, "mmap failed: %s\n", strerror(errno));
> return 1;
> }
> printf("Successfully allocated huge pages at address: %p\n", addr);
> ...
>
> [1] https://git.zx2c4.com/linux-rng/commit/mm/hugetlb.c?id=adbe8726dc2a3805630d517270db17e3af86e526
>
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper
2025-10-09 19:11 ` [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper SeongJae Park
2025-10-09 19:24 ` SeongJae Park
@ 2025-10-10 11:53 ` Usama Arif
1 sibling, 0 replies; 12+ messages in thread
From: Usama Arif @ 2025-10-10 11:53 UTC (permalink / raw)
To: SeongJae Park
Cc: muchun.song, osalvador, david, Andrew Morton, shakeel.butt,
linux-mm, hannes, riel, kas, linux-kernel, kernel-team
On 09/10/2025 20:11, SeongJae Park wrote:
> Hi Usama,
>
> On Thu, 9 Oct 2025 18:24:30 +0100 Usama Arif <usamaarif642@gmail.com> wrote:
>
>> This is a common condition used to skip operations that cannot
>> be performed on gigantic pages when runtime support is disabled.
>> This helper is introduced as the condition will exist even more
>> when allowing "overcommit" of gigantic hugepages.
>> No functional change intended with this patch.
>
> The change looks good to me. I have a couple of trivial comments below.
>
>>
>> Suggested-by: Andrew Morton <akpm@linux-foundation.org>
>> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
>> ---
>
> I think adding a change log since v1 here, or adding a cover letter with it
> would be nice.
>
I thought everything needed for the change is there in the commit message for patch 2,
and the first patch was trivial, so didnt add a cover letter. The change from v1 was
trivial as well.
>> mm/hugetlb.c | 21 ++++++++++++++++-----
>> 1 file changed, 16 insertions(+), 5 deletions(-)
>>
>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>> index c07b7192aff26..e74e41386b100 100644
>> --- a/mm/hugetlb.c
>> +++ b/mm/hugetlb.c
>> @@ -134,6 +134,17 @@ static void hugetlb_free_folio(struct folio *folio)
>> folio_put(folio);
>> }
>>
>> +/*
>> + * Check if the hstate represents gigantic pages but gigantic page
>> + * runtime support is not available. This is a common condition used to
>> + * skip operations that cannot be performed on gigantic pages when runtime
>> + * support is disabled.
>> + */
>> +static inline bool hstate_is_gigantic_no_runtime(struct hstate *h)
>> +{
>> + return hstate_is_gigantic(h) && !gigantic_page_runtime_supported();
>> +}
>> +
>> static inline bool subpool_is_free(struct hugepage_subpool *spool)
>> {
>> if (spool->count)
>> @@ -1555,7 +1566,7 @@ static void remove_hugetlb_folio(struct hstate *h, struct folio *folio,
>> VM_BUG_ON_FOLIO(hugetlb_cgroup_from_folio_rsvd(folio), folio);
>>
>> lockdep_assert_held(&hugetlb_lock);
>> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
>> + if (hstate_is_gigantic_no_runtime(h))
>> return;
>>
>> list_del(&folio->lru);
>> @@ -1617,7 +1628,7 @@ static void __update_and_free_hugetlb_folio(struct hstate *h,
>> {
>> bool clear_flag = folio_test_hugetlb_vmemmap_optimized(folio);
>>
>> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
>> + if (hstate_is_gigantic_no_runtime(h))
>> return;
>>
>> /*
>> @@ -2511,7 +2522,7 @@ static void return_unused_surplus_pages(struct hstate *h,
>> /* Uncommit the reservation */
>> h->resv_huge_pages -= unused_resv_pages;
>>
>> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
>> + if (hstate_is_gigantic_no_runtime(h))
>> goto out;
>>
>> /*
>> @@ -3725,7 +3736,7 @@ static void __init hugetlb_init_hstates(void)
>> * - If CMA allocation is possible, we can not demote
>> * HUGETLB_PAGE_ORDER or smaller size pages.
>> */
>> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
>> + if (hstate_is_gigantic_no_runtime(h))
>> continue;
>> if (hugetlb_cma_total_size() && h->order <= HUGETLB_PAGE_ORDER)
>> continue;
>> @@ -4202,7 +4213,7 @@ static ssize_t __nr_hugepages_store_common(bool obey_mempolicy,
>> int err;
>> nodemask_t nodes_allowed, *n_mask;
>>
>> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
>> + if (hstate_is_gigantic_no_runtime(h))
>> return -EINVAL;
>>
>> if (nid == NUMA_NO_NODE) {
>> --
>> 2.47.3
>
> It seems the new helper could be used for three more cases.
>
> On mm-new:
>
> $ git grep gigantic_page_runtime_supported mm/hugetlb.c
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (write && hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
>
> After applying this patch on top of mm-new:
>
> $ git grep gigantic_page_runtime_supported mm/hugetlb.c
> mm/hugetlb.c: return hstate_is_gigantic(h) && !gigantic_page_runtime_supported();
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> mm/hugetlb.c: if (write && hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
>
> I'm curious if you are planning to do the conversion later, or there is a
> reason why this patch is keeping those as is but I'm missing.
>
Yeah what you said in the followup email. I think should be ok now as Andrew has added v2
to mm-new.
Thanks!
Usama
>
> Thanks,
> SJ
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper
2025-10-09 17:24 [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper Usama Arif
` (2 preceding siblings ...)
2025-10-10 0:31 ` Shakeel Butt
@ 2025-10-13 7:56 ` Oscar Salvador
2025-10-13 8:04 ` David Hildenbrand
2025-10-13 12:49 ` Kefeng Wang
5 siblings, 0 replies; 12+ messages in thread
From: Oscar Salvador @ 2025-10-13 7:56 UTC (permalink / raw)
To: Usama Arif
Cc: muchun.song, david, Andrew Morton, shakeel.butt, linux-mm,
hannes, riel, kas, linux-kernel, kernel-team
On Thu, Oct 09, 2025 at 06:24:30PM +0100, Usama Arif wrote:
> This is a common condition used to skip operations that cannot
> be performed on gigantic pages when runtime support is disabled.
> This helper is introduced as the condition will exist even more
> when allowing "overcommit" of gigantic hugepages.
> No functional change intended with this patch.
>
> Suggested-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
Acked-by: Oscar Salvador <osalvador@suse.de>
--
Oscar Salvador
SUSE Labs
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 2/2] mm/hugetlb: allow overcommitting gigantic hugepages
2025-10-09 17:24 ` [PATCH v2 2/2] mm/hugetlb: allow overcommitting gigantic hugepages Usama Arif
2025-10-10 0:32 ` Shakeel Butt
@ 2025-10-13 8:00 ` Oscar Salvador
2025-10-13 12:56 ` Kefeng Wang
1 sibling, 1 reply; 12+ messages in thread
From: Oscar Salvador @ 2025-10-13 8:00 UTC (permalink / raw)
To: Usama Arif
Cc: muchun.song, david, Andrew Morton, shakeel.butt, linux-mm,
hannes, riel, kas, linux-kernel, kernel-team
On Thu, Oct 09, 2025 at 06:24:31PM +0100, Usama Arif wrote:
> Currently, gigantic hugepages cannot use the overcommit mechanism
> (nr_overcommit_hugepages), forcing users to permanently reserve memory via
> nr_hugepages even when pages might not be actively used.
>
> The restriction was added in 2011 [1], which was before there was support
> for reserving 1G hugepages at runtime.
> Remove this blanket restriction on gigantic hugepage overcommit.
> This will bring the same benefits to gigantic pages as hugepages:
>
> - Memory is only taken out of regular use when actually needed
> - Unused surplus pages can be returned to the system
> - Better memory utilization, especially with CMA backing which can
> significantly increase the changes of hugepage allocation
>
> Without this patch:
> echo 3 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_overcommit_hugepages
> bash: echo: write error: Invalid argument
>
> With this patch:
> echo 3 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_overcommit_hugepages
> ./mmap_hugetlb_test
> Successfully allocated huge pages at address: 0x7f9d40000000
>
> cat mmap_hugetlb_test.c
> ...
> unsigned long ALLOC_SIZE = 3 * (unsigned long) HUGE_PAGE_SIZE;
> addr = mmap(NULL,
> ALLOC_SIZE, // 3GB
> PROT_READ | PROT_WRITE,
> MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_HUGE_1GB,
> -1,
> 0);
>
> if (addr == MAP_FAILED) {
> fprintf(stderr, "mmap failed: %s\n", strerror(errno));
> return 1;
> }
> printf("Successfully allocated huge pages at address: %p\n", addr);
> ...
>
> [1] https://git.zx2c4.com/linux-rng/commit/mm/hugetlb.c?id=adbe8726dc2a3805630d517270db17e3af86e526
>
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
I guess nobody bothered to do this after we added support for 1GB hugepages because
creating those at runtime is tricky, and in my experience, almost everybody reserves
those at boot time.
But I do not have objections to make them behave as normal hugepages:
Acked-by: Oscar Salvador <osalvador@suse.de>
--
Oscar Salvador
SUSE Labs
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper
2025-10-09 17:24 [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper Usama Arif
` (3 preceding siblings ...)
2025-10-13 7:56 ` Oscar Salvador
@ 2025-10-13 8:04 ` David Hildenbrand
2025-10-13 12:49 ` Kefeng Wang
5 siblings, 0 replies; 12+ messages in thread
From: David Hildenbrand @ 2025-10-13 8:04 UTC (permalink / raw)
To: Usama Arif, muchun.song, osalvador, Andrew Morton
Cc: shakeel.butt, linux-mm, hannes, riel, kas, linux-kernel, kernel-team
On 09.10.25 19:24, Usama Arif wrote:
> This is a common condition used to skip operations that cannot
> be performed on gigantic pages when runtime support is disabled.
> This helper is introduced as the condition will exist even more
> when allowing "overcommit" of gigantic hugepages.
> No functional change intended with this patch.
>
Wondering, would "static" describe that we don't have the dynamic
runtime behavior?
hstate_is_static_gigantic()
hstate_is_gigantic_static()
Whatever you prefer
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper
2025-10-09 17:24 [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper Usama Arif
` (4 preceding siblings ...)
2025-10-13 8:04 ` David Hildenbrand
@ 2025-10-13 12:49 ` Kefeng Wang
5 siblings, 0 replies; 12+ messages in thread
From: Kefeng Wang @ 2025-10-13 12:49 UTC (permalink / raw)
To: Usama Arif, muchun.song, osalvador, david, Andrew Morton
Cc: shakeel.butt, linux-mm, hannes, riel, kas, linux-kernel, kernel-team
On 2025/10/10 1:24, Usama Arif wrote:
> This is a common condition used to skip operations that cannot
> be performed on gigantic pages when runtime support is disabled.
> This helper is introduced as the condition will exist even more
> when allowing "overcommit" of gigantic hugepages.
> No functional change intended with this patch.
>
> Suggested-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
> mm/hugetlb.c | 21 ++++++++++++++++-----
> 1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index c07b7192aff26..e74e41386b100 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -134,6 +134,17 @@ static void hugetlb_free_folio(struct folio *folio)
> folio_put(folio);
> }
>
> +/*
> + * Check if the hstate represents gigantic pages but gigantic page
> + * runtime support is not available. This is a common condition used to
> + * skip operations that cannot be performed on gigantic pages when runtime
> + * support is disabled.
> + */
> +static inline bool hstate_is_gigantic_no_runtime(struct hstate *h)
> +{
> + return hstate_is_gigantic(h) && !gigantic_page_runtime_supported();
> +}
> +
> static inline bool subpool_is_free(struct hugepage_subpool *spool)
> {
> if (spool->count)
> @@ -1555,7 +1566,7 @@ static void remove_hugetlb_folio(struct hstate *h, struct folio *folio,
> VM_BUG_ON_FOLIO(hugetlb_cgroup_from_folio_rsvd(folio), folio);
>
> lockdep_assert_held(&hugetlb_lock);
> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> + if (hstate_is_gigantic_no_runtime(h))
> return;
>
> list_del(&folio->lru);
> @@ -1617,7 +1628,7 @@ static void __update_and_free_hugetlb_folio(struct hstate *h,
> {
> bool clear_flag = folio_test_hugetlb_vmemmap_optimized(folio);
>
> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> + if (hstate_is_gigantic_no_runtime(h))
> return;
>
> /*
> @@ -2511,7 +2522,7 @@ static void return_unused_surplus_pages(struct hstate *h,
> /* Uncommit the reservation */
> h->resv_huge_pages -= unused_resv_pages;
>
> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> + if (hstate_is_gigantic_no_runtime(h))
> goto out;
>
> /*
> @@ -3725,7 +3736,7 @@ static void __init hugetlb_init_hstates(void)
> * - If CMA allocation is possible, we can not demote
> * HUGETLB_PAGE_ORDER or smaller size pages.
> */
> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> + if (hstate_is_gigantic_no_runtime(h))
> continue;
> if (hugetlb_cma_total_size() && h->order <= HUGETLB_PAGE_ORDER)
> continue;
> @@ -4202,7 +4213,7 @@ static ssize_t __nr_hugepages_store_common(bool obey_mempolicy,
> int err;
> nodemask_t nodes_allowed, *n_mask;
>
> - if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> + if (hstate_is_gigantic_no_runtime(h))
> return -EINVAL;
>
> if (nid == NUMA_NO_NODE) {
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 2/2] mm/hugetlb: allow overcommitting gigantic hugepages
2025-10-13 8:00 ` Oscar Salvador
@ 2025-10-13 12:56 ` Kefeng Wang
0 siblings, 0 replies; 12+ messages in thread
From: Kefeng Wang @ 2025-10-13 12:56 UTC (permalink / raw)
To: Oscar Salvador, Usama Arif
Cc: muchun.song, david, Andrew Morton, shakeel.butt, linux-mm,
hannes, riel, kas, linux-kernel, kernel-team
On 2025/10/13 16:00, Oscar Salvador wrote:
> On Thu, Oct 09, 2025 at 06:24:31PM +0100, Usama Arif wrote:
>> Currently, gigantic hugepages cannot use the overcommit mechanism
>> (nr_overcommit_hugepages), forcing users to permanently reserve memory via
>> nr_hugepages even when pages might not be actively used.
>>
>> The restriction was added in 2011 [1], which was before there was support
>> for reserving 1G hugepages at runtime.
>> Remove this blanket restriction on gigantic hugepage overcommit.
>> This will bring the same benefits to gigantic pages as hugepages:
>>
>> - Memory is only taken out of regular use when actually needed
>> - Unused surplus pages can be returned to the system
>> - Better memory utilization, especially with CMA backing which can
>> significantly increase the changes of hugepage allocation
>>
>> Without this patch:
>> echo 3 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_overcommit_hugepages
>> bash: echo: write error: Invalid argument
>>
>> With this patch:
>> echo 3 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_overcommit_hugepages
>> ./mmap_hugetlb_test
>> Successfully allocated huge pages at address: 0x7f9d40000000
>>
>> cat mmap_hugetlb_test.c
>> ...
>> unsigned long ALLOC_SIZE = 3 * (unsigned long) HUGE_PAGE_SIZE;
>> addr = mmap(NULL,
>> ALLOC_SIZE, // 3GB
>> PROT_READ | PROT_WRITE,
>> MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_HUGE_1GB,
>> -1,
>> 0);
>>
>> if (addr == MAP_FAILED) {
>> fprintf(stderr, "mmap failed: %s\n", strerror(errno));
>> return 1;
>> }
>> printf("Successfully allocated huge pages at address: %p\n", addr);
>> ...
>>
>> [1] https://git.zx2c4.com/linux-rng/commit/mm/hugetlb.c?id=adbe8726dc2a3805630d517270db17e3af86e526
>>
>> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>
> I guess nobody bothered to do this after we added support for 1GB hugepages because
> creating those at runtime is tricky, and in my experience, almost everybody reserves
> those at boot time.
> But I do not have objections to make them behave as normal hugepages:
We do have cases to allocate 1G hugepages at runtime and we enable
migrate 1G hugepages in alloc_migrate_hugetlb_folio() too :)
I will send a patch to enable gigantic pages migration based on this one.
>
> Acked-by: Oscar Salvador <osalvador@suse.de>
>
>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-10-13 12:56 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-09 17:24 [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper Usama Arif
2025-10-09 17:24 ` [PATCH v2 2/2] mm/hugetlb: allow overcommitting gigantic hugepages Usama Arif
2025-10-10 0:32 ` Shakeel Butt
2025-10-13 8:00 ` Oscar Salvador
2025-10-13 12:56 ` Kefeng Wang
2025-10-09 19:11 ` [PATCH v2 1/2] mm/hugetlb: create hstate_is_gigantic_no_runtime helper SeongJae Park
2025-10-09 19:24 ` SeongJae Park
2025-10-10 11:53 ` Usama Arif
2025-10-10 0:31 ` Shakeel Butt
2025-10-13 7:56 ` Oscar Salvador
2025-10-13 8:04 ` David Hildenbrand
2025-10-13 12:49 ` Kefeng Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox