mm: fix MAX_FOLIO_ORDER on powerpc configs with hugetlb
Subsystems (3)
David Hildenbrand (Red Hat)
maintainerPATCH 1/1 mm: fix MAX_FOLIO_ORDER on powerpc configs with hugetlb
In the past, CONFIG_ARCH_HAS_GIGANTIC_PAGE indicated that we support runtime allocation of gigantic hugetlb folios. In the meantime it evolved into a generic way for the architecture to state that it supports gigantic hugetlb folios.
In commit fae7d834c43c ("mm: add __dump_folio()") we started using CONFIG_ARCH_HAS_GIGANTIC_PAGE to decide MAX_FOLIO_ORDER: whether we could have folios larger than what the buddy can handle. In the context of that commit, we started using MAX_FOLIO_ORDER to detect page corruptions when dumping tail pages of folios. Before that commit, we assumed that we cannot have folios larger than the highest buddy order, which was obviously wrong.
In commit 7b4f21f5e038 ("mm/hugetlb: check for unreasonable folio sizes when registering hstate"), we used MAX_FOLIO_ORDER to detect inconsistencies, and in fact, we found some now.
Powerpc allows for configs that can allocate gigantic folio during boot (not at runtime), that do not set CONFIG_ARCH_HAS_GIGANTIC_PAGE and can exceed PUD_ORDER.
To fix it, let's make powerpc select CONFIG_ARCH_HAS_GIGANTIC_PAGE with hugetlb on powerpc, and increase the maximum folio size with hugetlb to 16 GiB (possible on arm64 and powerpc). Note that on some powerpc configurations, whether we actually have gigantic pages
depends on the setting of CONFIG_ARCH_FORCE_MAX_ORDER, but there is nothing really problematic about setting it unconditionally: we just try to keep the value small so we can better detect problems in __dump_folio() and inconsistencies around the expected largest folio in the system.
Ideally, we'd have a better way to obtain the maximum hugetlb folio size and detect ourselves whether we really end up with gigantic folios. Let's defer bigger changes and fix the warnings first.
While at it, handle gigantic DAX folios more clearly: DAX can only end up creating gigantic folios with HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD.
Add a new Kconfig option HAVE_GIGANTIC_FOLIOS to make both cases clearer. In particular, worry about ARCH_HAS_GIGANTIC_PAGE only with HUGETLB_PAGE.
Note: with enabling CONFIG_ARCH_HAS_GIGANTIC_PAGE on powerpc, we will now also allow for runtime allocations of folios in some more powerpc configs. I don't think this is a problem, but if it is we could handle it through __HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED.
While __dump_page()/__dump_folio was also problematic (not handling dumping of tail pages of such gigantic folios correctly), it doesn't relevant critical enough to mark it as a fix.
--- arch/powerpc/Kconfig | 1 + include/linux/mm.h | 12 +++++++++--- mm/Kconfig | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-)
arch/powerpc/Kconfig +1 -0
@@ -137,6 +137,7 @@ config PPC select ARCH_HAS_DMA_OPS if PPC64 select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_GIGANTIC_PAGE if ARCH_SUPPORTS_HUGETLBFS select ARCH_HAS_KCOV select ARCH_HAS_KERNEL_FPU_SUPPORT if PPC64 && PPC_FPU select ARCH_HAS_MEMBARRIER_CALLBACKS
include/linux/mm.h +9 -3
@@ -2074,7 +2074,7 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)return folio_large_nr_pages (folio); } -#if !defined(CONFIG_ARCH_HAS_GIGANTIC_PAGE ) +#if !defined(CONFIG_HAVE_GIGANTIC_FOLIOS )/* * We don't expect any folios that exceed buddy sizes (and consequently * memory sections).
@@ -2087,10 +2087,16 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)* pages are guaranteed to be contiguous. */ #define MAX_FOLIO_ORDER PFN_SECTION_SHIFT -#else +#elif defined(CONFIG_HUGETLB_PAGE )/* * There is no real limit on the folio size. We limit them to the maximum we -* currently expect (e.g., hugetlb, dax). +* currently expect: with hugetlb, we expect no folios larger than 16 GiB. +*/ +#define MAX_FOLIO_ORDER get_order(SZ_16G) +#else +/* +* Without hugetlb, gigantic folios that are bigger than a single PUD are +* currently impossible. */ #define MAX_FOLIO_ORDER PUD_ORDER#endif
mm/Kconfig +7 -0
@@ -908,6 +908,13 @@ config PAGE_MAPCOUNT config PGTABLE_HAS_HUGE_LEAVES def_bool TRANSPARENT_HUGEPAGE || HUGETLB_PAGE +# +# We can end up creating gigantic folio. +# +config HAVE_GIGANTIC_FOLIOS + def_bool (HUGETLB_PAGE && ARCH_HAS_GIGANTIC_PAGE) || \ + (ZONE_DEVICE && HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) + # TODO: Allow to be enabled without THP config ARCH_SUPPORTS_HUGE_PFNMAP def_bool n
Signature · 1 line
2.51.0
FYI, trivial to fix but a conflict on mm/Kconfig for mm-new:
<<<<<<< HEAD
config ASYNC_KERNEL_PGTABLE_FREE
def_bool n
=======
#
# We can end up creating gigantic folio.
#
config HAVE_GIGANTIC_FOLIOS
def_bool (HUGETLB_PAGE && ARCH_HAS_GIGANTIC_PAGE) || \ (ZONE_DEVICE && HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
mm: fix
MAX_FOLIO_ORDERon powerpc configs with hugetlb
Quoted 7 lines · David Hildenbrand (Red Hat)
In the past,
CONFIG_ARCH_HAS_GIGANTIC_PAGEindicated that we support runtime allocation of gigantic hugetlb folios. In the meantime it evolved into a generic way for the architecture to state that it supports gigantic hugetlb folios.In commit
fae7d834c43c("mm: add__dump_folio()") we started usingCONFIG_ARCH_HAS_GIGANTIC_PAGEto decideMAX_FOLIO_ORDER: whether we could
Hm strange commit to introduce this :)
Quoted 9 lines
have folios larger than what the buddy can handle. In the context of that commit, we started using
MAX_FOLIO_ORDERto detect page corruptions when dumping tail pages of folios. Before that commit, we assumed that we cannot have folios larger than the highest buddy order, which was obviously wrong.In commit
7b4f21f5e038("mm/hugetlb: check for unreasonable folio sizes when registering hstate"), we usedMAX_FOLIO_ORDERto detect inconsistencies, and in fact, we found some now.
Makes sense. And this is what the report bisects the issue to.
Quoted 4 lines
Powerpc allows for configs that can allocate gigantic folio during boot (not at runtime), that do not set
CONFIG_ARCH_HAS_GIGANTIC_PAGEand can exceedPUD_ORDER.
God...
Quoted 4 lines
To fix it, let's make powerpc select
CONFIG_ARCH_HAS_GIGANTIC_PAGEwith hugetlb on powerpc, and increase the maximum folio size with hugetlb to 16 GiB (possible on arm64 and powerpc). Note that on some powerpc
I guess this is due to 64 KiB base page possibilities. Fun :)
Will this cause powerpc to now support gigantic hugetlb pages when it didn't before?
Quoted 9 lines
configurations, whether we actually have gigantic pages
depends on the setting ofCONFIG_ARCH_FORCE_MAX_ORDER, but there is nothing really problematic about setting it unconditionally: we just try to keep the value small so we can better detect problems in__dump_folio()and inconsistencies around the expected largest folio in the system.Ideally, we'd have a better way to obtain the maximum hugetlb folio size and detect ourselves whether we really end up with gigantic folios. Let's defer bigger changes and fix the warnings first.
Right.
Quoted 3 lines
While at it, handle gigantic DAX folios more clearly: DAX can only end up creating gigantic folios with
HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD.
Yes, this is... quite something. Config implying gigantic THP possible but actually only relevant to DAX...
Quoted 4 lines
Add a new
KconfigoptionHAVE_GIGANTIC_FOLIOSto make both cases clearer. In particular, worry aboutARCH_HAS_GIGANTIC_PAGEonly withHUGETLB_PAGE.
Hm, I see:
config HUGETLB_PAGE
def_bool HUGETLBFS
select XARRAY_MULTI
Which means (unless I misunderstand Kconfig, very possible :) that this is always set if HUGETLBFS is specified. Would it be clearer to just check for CONFIG_HUGETLBFS?
Quoted 3 lines
Note: with enabling
CONFIG_ARCH_HAS_GIGANTIC_PAGEon powerpc, we will now also allow for runtime allocations of folios in some more powerpc configs.
Ah OK you're answering the above. I mean I don't think it'll be a problem either.
Quoted 6 lines
I don't think this is a problem, but if it is we could handle it through
__HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED.While __dump_page()/__dump_folio was also problematic (not handling dumping of tail pages of such gigantic folios correctly), it doesn't relevant critical enough to mark it as a fix.
Small typo 'it doesn't relevant critical enough' -> 'it doesn't seem critical enough' perhaps? Doesn't really matter, only fixup if respin or easy for Andrew to fix.
Are you planning to do follow ups then I guess?
Quoted 31 lines
Fixes 7b4f21f5e038 ("mm/hugetlb: check for unreasonable folio sizes when registering hstate")Reported-by Christophe Leroy <[email protected]>Reported-by Sourabh Jain <[email protected]>Cc Andrew Morton <[email protected]>Cc Ritesh Harjani (IBM) <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Donet Tom <[email protected]>Cc Michael Ellerman <[email protected]>Cc Nicholas Piggin <[email protected]>Cc Christophe Leroy <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Signed-off-by David Hildenbrand (Red Hat) <[email protected]>--- arch/powerpc/Kconfig | 1 + include/linux/mm.h | 12 +++++++++--- mm/Kconfig | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-)arch/powerpc/Kconfig +0
-0
arch/powerpc/Kconfig config PPC · line 140
Quoted 4 lines
arch/powerpc/Kconfig +1
-0@@ -137,6 +137,7 @@ config PPC select ARCH_HAS_DMA_OPS if PPC64 select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_GIGANTIC_PAGE if ARCH_SUPPORTS_HUGETLBFS
Given we know the architecture can support it (presumably all powerpc arches or all that can support hugetlbfs anyway?), this seems reasonable.
Quoted 17 lines
arch/powerpc/Kconfig +0
-0select ARCH_HAS_KCOV select ARCH_HAS_KERNEL_FPU_SUPPORT if PPC64 && PPC_FPU select ARCH_HAS_MEMBARRIER_CALLBACKSinclude/linux/mm.h +1
-1@@ -2074,7 +2074,7 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)return folio_large_nr_pages (folio); } -#if !defined(CONFIG_ARCH_HAS_GIGANTIC_PAGE ) +#if !defined(CONFIG_HAVE_GIGANTIC_FOLIOS )/* * We don't expect any folios that exceed buddy sizes (and consequently * memory sections).
include/linux/mm.h static inline unsigned long folio_nr_pages(const struct folio *folio) · line 2093
Quoted 9 lines
include/linux/mm.h +2
-2@@ -2087,10 +2087,16 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)* pages are guaranteed to be contiguous. */ #define MAX_FOLIO_ORDER PFN_SECTION_SHIFT -#else +#elif defined(CONFIG_HUGETLB_PAGE )/* * There is no real limit on the folio size. We limit them to the maximum we -* currently expect (e.g., hugetlb, dax). +* currently expect: with hugetlb, we expect no folios larger than 16 GiB.
Maybe worth saying 'see CONFIG_HAVE_GIGANTIC_FOLIOS definition' or something?
include/linux/mm.h static inline unsigned long folio_nr_pages(const struct folio *folio) · line 2095
Quoted 2 lines
include/linux/mm.h +2
-0+*/ +#define MAX_FOLIO_ORDER get_order(SZ_16G)
Hmm, is the base page size somehow runtime adjustable on powerpc? Why isn't PUD_ORDER good enough here?
Or does powerpc have some way of getting 16 GiB gigantic pages even with 4 KiB base page size?
Quoted 12 lines
include/linux/mm.h +4
-0+#else +/* +* Without hugetlb, gigantic folios that are bigger than a single PUD are +* currently impossible. */ #define MAX_FOLIO_ORDER PUD_ORDER#endif mm/Kconfig +0
-0
mm/Kconfig config PAGE_MAPCOUNT · line 916
Quoted 9 lines
mm/Kconfig +6
-0@@ -908,6 +908,13 @@ config PAGE_MAPCOUNT config PGTABLE_HAS_HUGE_LEAVES def_bool TRANSPARENT_HUGEPAGE || HUGETLB_PAGE +# +# We can end up creating gigantic folio. +# +config HAVE_GIGANTIC_FOLIOS + def_bool (HUGETLB_PAGE && ARCH_HAS_GIGANTIC_PAGE) || \ + (ZONE_DEVICE && HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)
Maybe worth spelling out in a comment these two cases?
Quoted 7 lines
mm/Kconfig +1
-1+ # TODO: Allow to be enabled without THP config ARCH_SUPPORTS_HUGE_PFNMAP def_bool n --2.51.0
David Hildenbrand (Red Hat)
maintainerQuoted 1 line · Lorenzo Stoakes
FYI, trivial to fix but a conflict on mm/Kconfig for mm-new:
Thanks for the review!
Yeah, this fix will have to obviously go in sooner. And it's easy to resolve.
That's why this patch is already in mm/mm-hotfixes-unstable.
[...]
Quoted 11 lines · David Hildenbrand (Red Hat)
Quoted 7 lines
In the past,
CONFIG_ARCH_HAS_GIGANTIC_PAGEindicated that we support runtime allocation of gigantic hugetlb folios. In the meantime it evolved into a generic way for the architecture to state that it supports gigantic hugetlb folios.In commit
fae7d834c43c("mm: add__dump_folio()") we started usingCONFIG_ARCH_HAS_GIGANTIC_PAGEto decideMAX_FOLIO_ORDER: whether we couldHm strange commit to introduce this :)
The first commit to be confused about what CONFIG_ARCH_HAS_GIGANTIC_PAGE actually means (obviously hugetlb, ... :) ), and which sizes are possible...
[...]
Quoted 9 lines
Quoted 4 lines
To fix it, let's make powerpc select
CONFIG_ARCH_HAS_GIGANTIC_PAGEwith hugetlb on powerpc, and increase the maximum folio size with hugetlb to 16 GiB (possible on arm64 and powerpc). Note that on some powerpcI guess this is due to 64 KiB base page possibilities. Fun :)
Will this cause powerpc to now support gigantic hugetlb pages when it didn't before?
It's not really related to 64K IIRC, just the way CONFIG_ARCH_FORCE_MAX_ORDER and other things interact with powerpcs ways of mapping cont-pmd-like things for hugetlb.
This patch here doesn't change any of that, it just makes us now correctly detect that gigantic folios are indeed possible.
Quoted 27 lines
Quoted 10 lines
configurations, whether we actually have gigantic pages
depends on the setting ofCONFIG_ARCH_FORCE_MAX_ORDER, but there is nothing really problematic about setting it unconditionally: we just try to keep the value small so we can better detect problems in__dump_folio()and inconsistencies around the expected largest folio in the system.Ideally, we'd have a better way to obtain the maximum hugetlb folio size and detect ourselves whether we really end up with gigantic folios. Let's defer bigger changes and fix the warnings first.
Right.
Quoted 3 lines
While at it, handle gigantic DAX folios more clearly: DAX can only end up creating gigantic folios with
HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD.Yes, this is... quite something. Config implying gigantic THP possible but actually only relevant to DAX...
Quoted 4 lines
Add a new
KconfigoptionHAVE_GIGANTIC_FOLIOSto make both cases clearer. In particular, worry aboutARCH_HAS_GIGANTIC_PAGEonly withHUGETLB_PAGE.Hm, I see:
Quoted 7 lines
config
HUGETLB_PAGE
def_boolHUGETLBFS
selectXARRAY_MULTIWhich means (unless I misunderstand
Kconfig, very possible :) that this is always set if HUGETLBFS is specified.
Yeah, def_bool enforces that both are set.
Quoted 2 lines
Would it be clearer to just check for
CONFIG_HUGETLBFS?
IMHO, MM code should focus on CONFIG_HUGETLB_PAGE (especially when dealing with the page/folio aspects), not the FS part of it.
$ git grep CONFIG_HUGETLB_PAGE | wc -l 45 $ git grep CONFIG_HUGETLBFS | wc -l 7
Unsurprisingly, we are not being completely consistent :)
Quoted 11 lines
Quoted 4 lines
Note: with enabling
CONFIG_ARCH_HAS_GIGANTIC_PAGEon powerpc, we will now also allow for runtime allocations of folios in some more powerpc configs.Ah OK you're answering the above. I mean I don't think it'll be a problem either.
Quoted 3 lines
I don't think this is a problem, but if it is we could handle it through
__HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED.
Quoted 7 lines
Quoted 3 lines
While __dump_page()/__dump_folio was also problematic (not handling dumping of tail pages of such gigantic folios correctly), it doesn't relevant critical enough to mark it as a fix.
Small typo 'it doesn't relevant critical enough' -> 'it doesn't seem critical enough' perhaps? Doesn't really matter, only fixup if respin or easy for Andrew to fix.
Ah yes, thanks.
Quoted 2 lines
Are you planning to do follow ups then I guess?
As time permits, I think this all needs to be reworked :(
[...]
Quoted 8 lines
arch/powerpc/Kconfig config PPC · line 140
Quoted 5 lines
arch/powerpc/Kconfig +1
-0@@ -137,6 +137,7 @@ config PPC select ARCH_HAS_DMA_OPS if PPC64 select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_GIGANTIC_PAGE if ARCH_SUPPORTS_HUGETLBFSGiven we know the architecture can support it (presumably all powerpc arches or all that can support hugetlbfs anyway?), this seems reasonable.
powerpc allows for quite some different configs, so I assume there are some configs that don't allow ARCH_SUPPORTS_HUGETLBFS.
[...]
Quoted 6 lines
include/linux/mm.h static inline unsigned long folio_nr_pages(const struct folio *folio) · line 2093
Quoted 4 lines
include/linux/mm.h +1
-1/* * There is no real limit on the folio size. We limit them to the maximum we -* currently expect (e.g., hugetlb, dax). +* currently expect: with hugetlb, we expect no folios larger than 16 GiB. Maybe worth saying 'see
CONFIG_HAVE_GIGANTIC_FOLIOSdefinition' or something?
To me that's implied from the initial ifdef. But not strong opinion about spelling that out.
Quoted 6 lines
Quoted 3 lines
+ */
+#defineMAX_FOLIO_ORDERget_order(SZ_16G)Hmm, is the base page size somehow runtime adjustable on powerpc? Why isn't
PUD_ORDERgood enough here?
We tried P4D_ORDER but even that doesn't work. I think we effectively end up with cont-pmd/cont-PUD mappings (or even cont-p4d, I am not 100% sure because the folding code complicates that).
See powerpcs variant of huge_pte_alloc() where we have stuff like
p4d = p4d_offset(pgd_offset(mm, addr), addr);
if (!mm_pud_folded(mm) && sz >= P4D_SIZE)
return (pte_t *)p4d;
As soon as we go to things like P4D_ORDER we're suddenly in the range of 512 GiB on x86 etc, so that's also not what we want as an easy fix. (and it didn't work)
Quoted 3 lines
Or does powerpc have some way of getting 16 GiB gigantic pages even with 4 KiB base page size?
IIUC, yes.
Take a look at MMU_PAGE_16G.
There is MMU_PAGE_64G already defined, but it's essentially unused for now.
Quoted 16 lines
Quoted 16 lines
include/linux/mm.h +4
-0+#else +/* +* Without hugetlb, gigantic folios that are bigger than a single PUD are +* currently impossible. */ #define MAX_FOLIO_ORDER PUD_ORDER#endif mm/Kconfig +0
-0@@ -908,6 +908,13 @@ config PAGE_MAPCOUNT config PGTABLE_HAS_HUGE_LEAVES def_bool TRANSPARENT_HUGEPAGE || HUGETLB_PAGE
Quoted 8 lines
mm/Kconfig config PAGE_MAPCOUNT · line 916
Quoted 6 lines
mm/Kconfig +6
-0+# +# We can end up creating gigantic folio. +# +config HAVE_GIGANTIC_FOLIOS + def_bool (HUGETLB_PAGE && ARCH_HAS_GIGANTIC_PAGE) || \ + (ZONE_DEVICE && HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)Maybe worth spelling out in a comment these two cases?
Not sure if the comments wouldn't just explain what we are reading?
"gigantic folios with hugetlb, PUD-sized folios with ZONE_DEVICE"?
Signature · 3 lines
Cheers David
Christophe Leroy
reviewerLe 13/11/2025 à 16:21, David Hildenbrand (Red Hat) a écrit :
Quoted 13 lines · Lorenzo Stoakes
[...]
Quoted 8 lines
Quoted 5 lines
(quoted diff) +0
-0@@ -137,6 +137,7 @@ config PPCselect ARCH_HAS_DMA_OPS if PPC64
selectARCH_HAS_FORTIFY_SOURCE
selectARCH_HAS_GCOV_PROFILE_ALL
+ select ARCH_HAS_GIGANTIC_PAGE ifARCH_SUPPORTS_HUGETLBFSGiven we know the architecture can support it (presumably all powerpc arches or all that can support hugetlbfs anyway?), this seems reasonable.
Quoted 1 line
powerpc allows for quite some different configs, so I assume there are some configs that don't allow
ARCH_SUPPORTS_HUGETLBFS.
Yes indeed. For instance the powerpc 603 and 604 have no huge pages.
Quoted 22 lines
[...]
Quoted 7 lines
Quoted 5 lines
/*
* There is no real limit on the folio size. We limit them to the maximum we
- * currently expect (e.g., hugetlb, dax).
+ * currently expect: with hugetlb, we expect no folios larger than 16 GiB.Maybe worth saying 'see
CONFIG_HAVE_GIGANTIC_FOLIOSdefinition' or something?To me that's implied from the initial ifdef. But not strong opinion about spelling that out.
Quoted 6 lines
Quoted 3 lines
+ */
+#define MAX_FOLIO_ORDERget_order(SZ_16G)Hmm, is the base page size somehow runtime adjustable on powerpc? Why isn't
PUD_ORDERgood enough here?We tried
P4D_ORDERbut even that doesn't work. I think we effectively end up with cont-pmd/cont-PUD mappings (or even cont-p4d, I am not 100% sure because the folding code complicates that).
Quoted 8 lines
See powerpcs variant of
huge_pte_alloc()where we have stuff likep4d =
p4d_offset(pgd_offset(mm, addr), addr);
if (!mm_pud_folded(mm) && sz >=P4D_SIZE)
return (pte_t*)p4d;As soon as we go to things like
P4D_ORDERwe're suddenly in the range of 512 GiB on x86 etc, so that's also not what we want as an easy fix. (and it didn't work)
On 32 bits there are only PGDIR et Page Table,
PGDIR_SHIFT = P4D_SHIFT = PUD_SHIFT = PMD_SHIFT
For instance on powerpc 8xx,PGDIR_SIZE is 4M
Largest hugepage is 8M.
So even PGDIR_ORDER isn't enough.
Christophe
David Hildenbrand (Red Hat)
maintainerQuoted 102 lines · David Hildenbrand (Red Hat)
In the past,
CONFIG_ARCH_HAS_GIGANTIC_PAGEindicated that we support runtime allocation of gigantic hugetlb folios. In the meantime it evolved into a generic way for the architecture to state that it supports gigantic hugetlb folios.In commit
fae7d834c43c("mm: add__dump_folio()") we started usingCONFIG_ARCH_HAS_GIGANTIC_PAGEto decideMAX_FOLIO_ORDER: whether we could have folios larger than what the buddy can handle. In the context of that commit, we started usingMAX_FOLIO_ORDERto detect page corruptions when dumping tail pages of folios. Before that commit, we assumed that we cannot have folios larger than the highest buddy order, which was obviously wrong.In commit
7b4f21f5e038("mm/hugetlb: check for unreasonable folio sizes when registering hstate"), we usedMAX_FOLIO_ORDERto detect inconsistencies, and in fact, we found some now.Powerpc allows for configs that can allocate gigantic folio during boot (not at runtime), that do not set
CONFIG_ARCH_HAS_GIGANTIC_PAGEand can exceedPUD_ORDER.To fix it, let's make powerpc select
CONFIG_ARCH_HAS_GIGANTIC_PAGEwith hugetlb on powerpc, and increase the maximum folio size with hugetlb to 16 GiB (possible on arm64 and powerpc). Note that on some powerpc configurations, whether we actually have gigantic pages
depends on the setting ofCONFIG_ARCH_FORCE_MAX_ORDER, but there is nothing really problematic about setting it unconditionally: we just try to keep the value small so we can better detect problems in__dump_folio()and inconsistencies around the expected largest folio in the system.Ideally, we'd have a better way to obtain the maximum hugetlb folio size and detect ourselves whether we really end up with gigantic folios. Let's defer bigger changes and fix the warnings first.
While at it, handle gigantic DAX folios more clearly: DAX can only end up creating gigantic folios with
HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD.Add a new
KconfigoptionHAVE_GIGANTIC_FOLIOSto make both cases clearer. In particular, worry aboutARCH_HAS_GIGANTIC_PAGEonly withHUGETLB_PAGE.Note: with enabling
CONFIG_ARCH_HAS_GIGANTIC_PAGEon powerpc, we will now also allow for runtime allocations of folios in some more powerpc configs. I don't think this is a problem, but if it is we could handle it through__HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED.While __dump_page()/__dump_folio was also problematic (not handling dumping of tail pages of such gigantic folios correctly), it doesn't relevant critical enough to mark it as a fix.
Fixes 7b4f21f5e038 ("mm/hugetlb: check for unreasonable folio sizes when registering hstate")Reported-by Christophe Leroy <[email protected]>Reported-by Sourabh Jain <[email protected]>Cc Andrew Morton <[email protected]>Cc Ritesh Harjani (IBM) <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Donet Tom <[email protected]>Cc Michael Ellerman <[email protected]>Cc Nicholas Piggin <[email protected]>Cc Christophe Leroy <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Signed-off-by David Hildenbrand (Red Hat) <[email protected]>--- arch/powerpc/Kconfig | 1 + include/linux/mm.h | 12 +++++++++--- mm/Kconfig | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-)arch/powerpc/Kconfig +1
-0@@ -137,6 +137,7 @@ config PPC select ARCH_HAS_DMA_OPS if PPC64 select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_GIGANTIC_PAGE if ARCH_SUPPORTS_HUGETLBFS select ARCH_HAS_KCOV select ARCH_HAS_KERNEL_FPU_SUPPORT if PPC64 && PPC_FPU select ARCH_HAS_MEMBARRIER_CALLBACKSinclude/linux/mm.h +1
-1@@ -2074,7 +2074,7 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)return folio_large_nr_pages (folio); } -#if !defined(CONFIG_ARCH_HAS_GIGANTIC_PAGE ) +#if !defined(CONFIG_HAVE_GIGANTIC_FOLIOS )/* * We don't expect any folios that exceed buddy sizes (and consequently * memory sections). @@ -2087,10 +2087,16 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)* pages are guaranteed to be contiguous.
include/linux/mm.h static inline unsigned long folio_nr_pages(const struct folio *folio) · line 2095
Quoted 10 lines
include/linux/mm.h +4
-2*/ #define MAX_FOLIO_ORDER PFN_SECTION_SHIFT -#else +#elif defined(CONFIG_HUGETLB_PAGE )/* * There is no real limit on the folio size. We limit them to the maximum we -* currently expect (e.g., hugetlb, dax). +* currently expect: with hugetlb, we expect no folios larger than 16 GiB. +*/ +#define MAX_FOLIO_ORDER get_order(SZ_16G)
Turns out that's a problem on 32bit builds, because it won't fit into unsigned long. Grml.
include/linux/mm.h +3 -2
@@ -2090,9 +2090,10 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)#elif defined(CONFIG_HUGETLB_PAGE )/* * There is no real limit on the folio size. We limit them to the maximum we -* currently expect: with hugetlb, we expect no folios larger than 16 GiB. +* currently expect: with hugetlb, we expect no folios larger than 16 GiB +* on 64bit and 1 GiB on 32bit. */ -#define MAX_FOLIO_ORDER get_order(SZ_16G) +#define MAX_FOLIO_ORDER get_order(IS_ENABLED(CONFIG_64BIT) ? SZ_16G : SZ_1G)#else /*
I'll resend the patch ...
Signature · 3 lines
Cheers David
Quoted 9 lines · David Hildenbrand (Red Hat)
Quoted 1 line · Lorenzo Stoakes
FYI, trivial to fix but a conflict on mm/Kconfig for mm-new:
Thanks for the review!
Yeah, this fix will have to obviously go in sooner. And it's easy to resolve.
That's why this patch is already in
mm/mm-hotfixes-unstable.
Ack.
Quoted 10 lines
[...]
Quoted 7 lines · David Hildenbrand (Red Hat)
Quoted 5 lines
In the past,
CONFIG_ARCH_HAS_GIGANTIC_PAGEindicated that we support runtime allocation of gigantic hugetlb folios. In the meantime it evolved into a generic way for the architecture to state that it supports gigantic hugetlb folios.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
In commit
fae7d834c43c("mm: add__dump_folio()") we started usingCONFIG_ARCH_HAS_GIGANTIC_PAGEto decideMAX_FOLIO_ORDER: whether we couldHm strange commit to introduce this :)
The first commit to be confused about what
CONFIG_ARCH_HAS_GIGANTIC_PAGEactually means (obviously hugetlb, ... :) ), and which sizes are possible...
Yeah, sigh, we love to make things confusing :)
Quoted 8 lines
[...]
Quoted 5 lines
Quoted 4 lines
To fix it, let's make powerpc select
CONFIG_ARCH_HAS_GIGANTIC_PAGEwith hugetlb on powerpc, and increase the maximum folio size with hugetlb to 16 GiB (possible on arm64 and powerpc). Note that on some powerpc
Quoted 8 lines
Quoted 4 lines
I guess this is due to 64 KiB base page possibilities. Fun :)
Will this cause powerpc to now support gigantic hugetlb pages when it didn't before?
It's not really related to 64K IIRC, just the way
CONFIG_ARCH_FORCE_MAX_ORDERand other things interact with powerpcs ways of mapping cont-pmd-like things for hugetlb.
Ah OK, as I was thinking if it's base pages we could just keep order the same... if it's somehow possible to get higher sizes even with without then makes sense to specify.
Lord... I wonder if we should have a doc somewhere describing all the ins and outs of this?
Not that I'm asking my perenially busy co-maintainer to do _even more_ work but maybe an idea for the future :P
Quoted 39 lines
This patch here doesn't change any of that, it just makes us now correctly detect that gigantic folios are indeed possible.
Quoted 27 lines
Quoted 10 lines
configurations, whether we actually have gigantic pages
depends on the setting ofCONFIG_ARCH_FORCE_MAX_ORDER, but there is nothing really problematic about setting it unconditionally: we just try to keep the value small so we can better detect problems in__dump_folio()and inconsistencies around the expected largest folio in the system.Ideally, we'd have a better way to obtain the maximum hugetlb folio size and detect ourselves whether we really end up with gigantic folios. Let's defer bigger changes and fix the warnings first.
Right.
Quoted 3 lines
While at it, handle gigantic DAX folios more clearly: DAX can only end up creating gigantic folios with
HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD.Yes, this is... quite something. Config implying gigantic THP possible but actually only relevant to DAX...
Quoted 4 lines
Add a new
KconfigoptionHAVE_GIGANTIC_FOLIOSto make both cases clearer. In particular, worry aboutARCH_HAS_GIGANTIC_PAGEonly withHUGETLB_PAGE.Hm, I see:
Quoted 7 lines
config
HUGETLB_PAGE
def_boolHUGETLBFS
selectXARRAY_MULTIWhich means (unless I misunderstand
Kconfig, very possible :) that this is always set if HUGETLBFS is specified.
Quoted 7 lines
Yeah,
def_boolenforces that both are set.Quoted 2 lines
Would it be clearer to just check for
CONFIG_HUGETLBFS?IMHO, MM code should focus on
CONFIG_HUGETLB_PAGE(especially when dealing with the page/folio aspects), not the FS part of it.
Yeah this is another weird fs/mm split for something that really is ultimately an mm thing...
Quoted 7 lines
$ git grep CONFIG_HUGETLB_PAGE | wc -l 45 $ git grep CONFIG_HUGETLBFS | wc -l 7Unsurprisingly, we are not being completely consistent :)
Well fair enough :)
Quoted 20 lines
Quoted 12 lines
Quoted 5 lines
Note: with enabling
CONFIG_ARCH_HAS_GIGANTIC_PAGEon powerpc, we will now also allow for runtime allocations of folios in some more powerpc configs.Ah OK you're answering the above. I mean I don't think it'll be a problem either.
Quoted 3 lines
I don't think this is a problem, but if it is we could handle it through
__HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED.Quoted 7 lines
Quoted 3 lines
While __dump_page()/__dump_folio was also problematic (not handling dumping of tail pages of such gigantic folios correctly), it doesn't relevant critical enough to mark it as a fix.
Small typo 'it doesn't relevant critical enough' -> 'it doesn't seem critical enough' perhaps? Doesn't really matter, only fixup if respin or easy for Andrew to fix.
Quoted 6 lines
Ah yes, thanks.
Quoted 2 lines
Are you planning to do follow ups then I guess?
As time permits, I think this all needs to be reworked :(
Yup! :)
Quoted 12 lines
[...]
Quoted 8 lines
arch/powerpc/Kconfig config PPC · line 140
Quoted 5 lines
arch/powerpc/Kconfig +1
-0@@ -137,6 +137,7 @@ config PPC select ARCH_HAS_DMA_OPS if PPC64 select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_GIGANTIC_PAGE if ARCH_SUPPORTS_HUGETLBFSGiven we know the architecture can support it (presumably all powerpc arches or all that can support hugetlbfs anyway?), this seems reasonable.
Quoted 2 lines
powerpc allows for quite some different configs, so I assume there are some configs that don't allow
ARCH_SUPPORTS_HUGETLBFS.
Ah OK.
Quoted 17 lines
[...]
Quoted 6 lines
Quoted 4 lines
/*
* There is no real limit on the folio size. We limit them to the maximum we
- * currently expect (e.g., hugetlb, dax).
+ * currently expect: with hugetlb, we expect no folios larger than 16 GiB.Maybe worth saying 'see
CONFIG_HAVE_GIGANTIC_FOLIOSdefinition' or something?To me that's implied from the initial ifdef. But not strong opinion about spelling that out.
Quoted 4 lines
Quoted 3 lines
+ */
+#defineMAX_FOLIO_ORDERget_order(SZ_16G)
Quoted 6 lines
Quoted 2 lines
Hmm, is the base page size somehow runtime adjustable on powerpc? Why isn't
PUD_ORDERgood enough here?We tried
P4D_ORDERbut even that doesn't work. I think we effectively end up with cont-pmd/cont-PUD mappings (or even cont-p4d, I am not 100% sure because the folding code complicates that).
Ah wow, didn't even know such things could be a thing :)
Quoted 10 lines
See powerpcs variant of
huge_pte_alloc()where we have stuff likep4d =
p4d_offset(pgd_offset(mm, addr), addr);
if (!mm_pud_folded(mm) && sz >=P4D_SIZE)return (pte_t *)p4d;As soon as we go to things like
P4D_ORDERwe're suddenly in the range of 512 GiB on x86 etc, so that's also not what we want as an easy fix. (and it didn't work)
Yeah... better to be explicit about the ppc case I think you're right.
Quoted 8 lines
Quoted 4 lines
Or does powerpc have some way of getting 16 GiB gigantic pages even with 4 KiB base page size?
IIUC, yes.
Take a look at
MMU_PAGE_16G.
Ack yeah, surprising, but these arches can be a whole other world... too used to basic arm64/x86-64 :)
Quoted 2 lines
There is
MMU_PAGE_64Galready defined, but it's essentially unused for now.
Hmm :)
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
include/linux/mm.h +4
-0+#else +/* +* Without hugetlb, gigantic folios that are bigger than a single PUD are +* currently impossible. */ #define MAX_FOLIO_ORDER PUD_ORDER#endif mm/Kconfig +0
-0@@ -908,6 +908,13 @@ config PAGE_MAPCOUNT config PGTABLE_HAS_HUGE_LEAVES def_bool TRANSPARENT_HUGEPAGE || HUGETLB_PAGEQuoted 8 lines
mm/Kconfig config PAGE_MAPCOUNT · line 916
Quoted 6 lines
mm/Kconfig +6
-0+# +# We can end up creating gigantic folio. +# +config HAVE_GIGANTIC_FOLIOS + def_bool (HUGETLB_PAGE && ARCH_HAS_GIGANTIC_PAGE) || \ + (ZONE_DEVICE && HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)Maybe worth spelling out in a comment these two cases?
Quoted 3 lines
Not sure if the comments wouldn't just explain what we are reading?
"gigantic folios with hugetlb, PUD-sized folios with
ZONE_DEVICE"?
Yeah true not vital.
Quoted 5 lines
--
CheersDavid
Cheers, Lorenzo