Re: [RFC v2 3/4] mm: add largest_zero_folio() routine
From: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Date: 2025-08-01 04:34:31
Also in:
linux-fsdevel, linux-mm, lkml
"Pankaj Raghav (Samsung)" [off-list ref] writes:
From: Pankaj Raghav <redacted> Add largest_zero_folio() routine so that huge_zero_folio can be
[largest]_zero_folio() can sound a bit confusing with largest in it's name. Maybe optimal_zero_folio()? No hard opinion though. Will leave it upto you. -ritesh
quoted hunk ↗ jump to hunk
used directly when CONFIG_STATIC_HUGE_ZERO_FOLIO is enabled. This will return ZERO_PAGE folio if CONFIG_STATIC_HUGE_ZERO_FOLIO is disabled or if we failed to allocate a huge_zero_folio. Co-developed-by: David Hildenbrand <redacted> Signed-off-by: David Hildenbrand <redacted> Signed-off-by: Pankaj Raghav <redacted> --- include/linux/huge_mm.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 78ebceb61d0e..c44a6736704b 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h@@ -716,4 +716,21 @@ static inline int split_folio_to_order(struct folio *folio, int new_order) return split_folio_to_list_to_order(folio, NULL, new_order); } +/* + * largest_zero_folio - Get the largest zero size folio available + * + * This function will return huge_zero_folio if CONFIG_STATIC_HUGE_ZERO_FOLIO + * is enabled. Otherwise, a ZERO_PAGE folio is returned. + * + * Deduce the size of the folio with folio_size instead of assuming the + * folio size. + */ +static inline struct folio *largest_zero_folio(void) +{ + struct folio *folio = get_static_huge_zero_folio(); + + if (folio) + return folio; + return page_folio(ZERO_PAGE(0)); +} #endif /* _LINUX_HUGE_MM_H */-- 2.49.0