[PATCHv3 02/15] mm: Move MAX_FOLIO_ORDER definition to mmzone.h

Kiryl Shutsemau posted 15 patches 3 weeks, 2 days ago
There is a newer version of this series
[PATCHv3 02/15] mm: Move MAX_FOLIO_ORDER definition to mmzone.h
Posted by Kiryl Shutsemau 3 weeks, 2 days ago
Move MAX_FOLIO_ORDER definition from mm.h to mmzone.h.

This is preparation for adding the vmemmap_tails array to struct
pglist_data, which requires MAX_FOLIO_ORDER to be available in mmzone.h.

Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
---
 include/linux/mm.h     | 31 -------------------------------
 include/linux/mmzone.h | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 7c79b3369b82..2c409f583569 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -26,7 +26,6 @@
 #include <linux/page-flags.h>
 #include <linux/page_ref.h>
 #include <linux/overflow.h>
-#include <linux/sizes.h>
 #include <linux/sched.h>
 #include <linux/pgtable.h>
 #include <linux/kasan.h>
@@ -2074,36 +2073,6 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)
 	return folio_large_nr_pages(folio);
 }
 
-#if !defined(CONFIG_HAVE_GIGANTIC_FOLIOS)
-/*
- * We don't expect any folios that exceed buddy sizes (and consequently
- * memory sections).
- */
-#define MAX_FOLIO_ORDER		MAX_PAGE_ORDER
-#elif defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
-/*
- * Only pages within a single memory section are guaranteed to be
- * contiguous. By limiting folios to a single memory section, all folio
- * pages are guaranteed to be contiguous.
- */
-#define MAX_FOLIO_ORDER		PFN_SECTION_SHIFT
-#elif defined(CONFIG_HUGETLB_PAGE)
-/*
- * There is no real limit on the folio size. We limit them to the maximum we
- * currently expect (see CONFIG_HAVE_GIGANTIC_FOLIOS): with hugetlb, we expect
- * no folios larger than 16 GiB on 64bit and 1 GiB on 32bit.
- */
-#define MAX_FOLIO_ORDER		get_order(IS_ENABLED(CONFIG_64BIT) ? SZ_16G : SZ_1G)
-#else
-/*
- * Without hugetlb, gigantic folios that are bigger than a single PUD are
- * currently impossible.
- */
-#define MAX_FOLIO_ORDER		PUD_ORDER
-#endif
-
-#define MAX_FOLIO_NR_PAGES	(1UL << MAX_FOLIO_ORDER)
-
 /*
  * compound_nr() returns the number of pages in this potentially compound
  * page.  compound_nr() can be called on a tail page, and is defined to
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 7fb7331c5725..6a2f3696068e 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -21,8 +21,10 @@
 #include <linux/atomic.h>
 #include <linux/mm_types.h>
 #include <linux/page-flags.h>
+#include <linux/pgtable.h>
 #include <linux/local_lock.h>
 #include <linux/zswap.h>
+#include <linux/sizes.h>
 #include <asm/page.h>
 
 /* Free memory management - zoned buddy allocator.  */
@@ -61,6 +63,36 @@
  */
 #define PAGE_ALLOC_COSTLY_ORDER 3
 
+#if !defined(CONFIG_HAVE_GIGANTIC_FOLIOS)
+/*
+ * We don't expect any folios that exceed buddy sizes (and consequently
+ * memory sections).
+ */
+#define MAX_FOLIO_ORDER		MAX_PAGE_ORDER
+#elif defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
+/*
+ * Only pages within a single memory section are guaranteed to be
+ * contiguous. By limiting folios to a single memory section, all folio
+ * pages are guaranteed to be contiguous.
+ */
+#define MAX_FOLIO_ORDER		PFN_SECTION_SHIFT
+#elif defined(CONFIG_HUGETLB_PAGE)
+/*
+ * There is no real limit on the folio size. We limit them to the maximum we
+ * currently expect (see CONFIG_HAVE_GIGANTIC_FOLIOS): with hugetlb, we expect
+ * no folios larger than 16 GiB on 64bit and 1 GiB on 32bit.
+ */
+#define MAX_FOLIO_ORDER		get_order(IS_ENABLED(CONFIG_64BIT) ? SZ_16G : SZ_1G)
+#else
+/*
+ * Without hugetlb, gigantic folios that are bigger than a single PUD are
+ * currently impossible.
+ */
+#define MAX_FOLIO_ORDER		PUD_ORDER
+#endif
+
+#define MAX_FOLIO_NR_PAGES	(1UL << MAX_FOLIO_ORDER)
+
 enum migratetype {
 	MIGRATE_UNMOVABLE,
 	MIGRATE_MOVABLE,
-- 
2.51.2
Re: [PATCHv3 02/15] mm: Move MAX_FOLIO_ORDER definition to mmzone.h
Posted by David Hildenbrand (Red Hat) 3 weeks, 2 days ago
On 1/15/26 15:45, Kiryl Shutsemau wrote:
> Move MAX_FOLIO_ORDER definition from mm.h to mmzone.h.

Why should that belong to mmzone.h ? Semantically doesn't make sense, no?

-- 
Cheers

David
Re: [PATCHv3 02/15] mm: Move MAX_FOLIO_ORDER definition to mmzone.h
Posted by David Hildenbrand (Red Hat) 3 weeks, 2 days ago
On 1/15/26 17:35, David Hildenbrand (Red Hat) wrote:
> On 1/15/26 15:45, Kiryl Shutsemau wrote:
>> Move MAX_FOLIO_ORDER definition from mm.h to mmzone.h.
> 
> Why should that belong to mmzone.h ? Semantically doesn't make sense, no?

To clarify, I would have moved it to something more folio-type specific, 
not something buddy/zone specific.

I guess page-flags.h + mm.h are our dumping ground for folio handling. I 
would have moved it to the former.

Likely we want some folio.h in some distant future.

Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>

-- 
Cheers

David
Re: [PATCHv3 02/15] mm: Move MAX_FOLIO_ORDER definition to mmzone.h
Posted by Kiryl Shutsemau 3 weeks, 2 days ago
On Thu, Jan 15, 2026 at 05:48:20PM +0100, David Hildenbrand (Red Hat) wrote:
> On 1/15/26 17:35, David Hildenbrand (Red Hat) wrote:
> > On 1/15/26 15:45, Kiryl Shutsemau wrote:
> > > Move MAX_FOLIO_ORDER definition from mm.h to mmzone.h.
> > 
> > Why should that belong to mmzone.h ? Semantically doesn't make sense, no?
> 
> To clarify, I would have moved it to something more folio-type specific, not
> something buddy/zone specific.
> 
> I guess page-flags.h + mm.h are our dumping ground for folio handling. I
> would have moved it to the former.

I moved it next to MAX_PAGE_ORDER definition which seemed to be logical.
Moving MAX_PAGE_ORDER around is much more risky (will likely generate a
lot of build bugs) and outside of the scope of the patchset.

I think wherever they will be moved, it should be moved together.

> Likely we want some folio.h in some distant future.

Sounds like a plan! :P

> Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>

Thanks!

-- 
  Kiryl Shutsemau / Kirill A. Shutemov
Re: [PATCHv3 02/15] mm: Move MAX_FOLIO_ORDER definition to mmzone.h
Posted by David Hildenbrand (Red Hat) 3 weeks, 2 days ago
On 1/15/26 18:26, Kiryl Shutsemau wrote:
> On Thu, Jan 15, 2026 at 05:48:20PM +0100, David Hildenbrand (Red Hat) wrote:
>> On 1/15/26 17:35, David Hildenbrand (Red Hat) wrote:
>>> On 1/15/26 15:45, Kiryl Shutsemau wrote:
>>>> Move MAX_FOLIO_ORDER definition from mm.h to mmzone.h.
>>>
>>> Why should that belong to mmzone.h ? Semantically doesn't make sense, no?
>>
>> To clarify, I would have moved it to something more folio-type specific, not
>> something buddy/zone specific.
>>
>> I guess page-flags.h + mm.h are our dumping ground for folio handling. I
>> would have moved it to the former.
> 
> I moved it next to MAX_PAGE_ORDER definition which seemed to be logical.

MAX_PAGE_ORDER is a buddy concept. MAX_FOLIO_ORDER is not a buddy concept.

-- 
Cheers

David