Skip to content

Commit bb65840

Browse files
Panky-codeskawasaki
authored andcommitted
mm: add largest_zero_folio() routine
Add largest_zero_folio() routine so that huge_zero_folio can be used without the need to pass any mm struct. This will return ZERO_PAGE folio if CONFIG_STATIC_PMD_ZERO_PAGE is disabled or if we failed to allocate a PMD page from memblock. This routine can also be called even if THP is disabled. Signed-off-by: Pankaj Raghav <[email protected]>
1 parent bd65ce1 commit bb65840

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

include/linux/mm.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4023,17 +4023,41 @@ static inline bool vma_is_special_huge(const struct vm_area_struct *vma)
40234023

40244024
#endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
40254025

4026+
extern struct folio *huge_zero_folio;
4027+
extern unsigned long huge_zero_pfn;
4028+
40264029
#ifdef CONFIG_STATIC_PMD_ZERO_PAGE
40274030
extern void __init static_pmd_zero_init(void);
4031+
4032+
/*
4033+
* largest_zero_folio - Get the largest zero size folio available
4034+
*
4035+
* This function will return a PMD sized zero folio if CONFIG_STATIC_PMD_ZERO_PAGE
4036+
* is enabled. Otherwise, a ZERO_PAGE folio is returned.
4037+
*
4038+
* Deduce the size of the folio with folio_size instead of assuming the
4039+
* folio size.
4040+
*/
4041+
static inline struct folio *largest_zero_folio(void)
4042+
{
4043+
if(!huge_zero_folio)
4044+
return page_folio(ZERO_PAGE(0));
4045+
4046+
return READ_ONCE(huge_zero_folio);
4047+
}
4048+
40284049
#else
40294050
static inline void __init static_pmd_zero_init(void)
40304051
{
40314052
return;
40324053
}
4054+
4055+
static inline struct folio *largest_zero_folio(void)
4056+
{
4057+
return page_folio(ZERO_PAGE(0));
4058+
}
40334059
#endif
40344060

4035-
extern struct folio *huge_zero_folio;
4036-
extern unsigned long huge_zero_pfn;
40374061

40384062
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
40394063
static inline bool is_huge_zero_folio(const struct folio *folio)

0 commit comments

Comments
 (0)