Skip to content

Commit 1ea5212

Browse files
davidhildenbrandakpm00
authored andcommitted
mm: factor out large folio handling from folio_nr_pages() into folio_large_nr_pages()
Let's factor it out into a simple helper function. This helper will also come in handy when working with code where we know that our folio is large. While at it, let's consistently return a "long" value from all these similar functions. Note that we cannot use "unsigned int" (even though _folio_nr_pages is of that type), because it would break some callers that do stuff like "-folio_nr_pages()". Both "int" or "unsigned long" would work as well. Maybe in the future we'll have the nr_pages readily available for all large folios, maybe even for small folios, or maybe for none. Link: https://lkml.kernel.org/r/20250303163014.1128035-3-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Andy Lutomirks^H^Hski <luto@kernel.org> Cc: Borislav Betkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jann Horn <jannh@google.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Lance Yang <ioworker0@gmail.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Matthew Wilcow (Oracle) <willy@infradead.org> Cc: Michal Koutn <mkoutny@suse.com> Cc: Muchun Song <muchun.song@linux.dev> Cc: tejun heo <tj@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Zefan Li <lizefan.x@bytedance.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 6220ea5 commit 1ea5212

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

include/linux/mm.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,18 @@ static inline unsigned int folio_large_order(const struct folio *folio)
11991199
return folio->_flags_1 & 0xff;
12001200
}
12011201

1202+
#ifdef CONFIG_64BIT
1203+
static inline long folio_large_nr_pages(const struct folio *folio)
1204+
{
1205+
return folio->_folio_nr_pages;
1206+
}
1207+
#else
1208+
static inline long folio_large_nr_pages(const struct folio *folio)
1209+
{
1210+
return 1L << folio_large_order(folio);
1211+
}
1212+
#endif
1213+
12021214
/*
12031215
* compound_order() can be called without holding a reference, which means
12041216
* that niceties like page_folio() don't work. These callers should be
@@ -2147,11 +2159,7 @@ static inline long folio_nr_pages(const struct folio *folio)
21472159
{
21482160
if (!folio_test_large(folio))
21492161
return 1;
2150-
#ifdef CONFIG_64BIT
2151-
return folio->_folio_nr_pages;
2152-
#else
2153-
return 1L << folio_large_order(folio);
2154-
#endif
2162+
return folio_large_nr_pages(folio);
21552163
}
21562164

21572165
/* Only hugetlbfs can allocate folios larger than MAX_ORDER */
@@ -2166,24 +2174,20 @@ static inline long folio_nr_pages(const struct folio *folio)
21662174
* page. compound_nr() can be called on a tail page, and is defined to
21672175
* return 1 in that case.
21682176
*/
2169-
static inline unsigned long compound_nr(struct page *page)
2177+
static inline long compound_nr(struct page *page)
21702178
{
21712179
struct folio *folio = (struct folio *)page;
21722180

21732181
if (!test_bit(PG_head, &folio->flags))
21742182
return 1;
2175-
#ifdef CONFIG_64BIT
2176-
return folio->_folio_nr_pages;
2177-
#else
2178-
return 1L << folio_large_order(folio);
2179-
#endif
2183+
return folio_large_nr_pages(folio);
21802184
}
21812185

21822186
/**
21832187
* thp_nr_pages - The number of regular pages in this huge page.
21842188
* @page: The head page of a huge page.
21852189
*/
2186-
static inline int thp_nr_pages(struct page *page)
2190+
static inline long thp_nr_pages(struct page *page)
21872191
{
21882192
return folio_nr_pages((struct folio *)page);
21892193
}

0 commit comments

Comments
 (0)