Skip to content

Commit 3f4b638

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 4e9509e commit 3f4b638

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
@@ -4018,17 +4018,41 @@ static inline bool vma_is_special_huge(const struct vm_area_struct *vma)
40184018

40194019
#endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
40204020

4021+
extern struct folio *huge_zero_folio;
4022+
extern unsigned long huge_zero_pfn;
4023+
40214024
#ifdef CONFIG_STATIC_PMD_ZERO_PAGE
40224025
extern void __init static_pmd_zero_init(void);
4026+
4027+
/*
4028+
* largest_zero_folio - Get the largest zero size folio available
4029+
*
4030+
* This function will return a PMD sized zero folio if CONFIG_STATIC_PMD_ZERO_PAGE
4031+
* is enabled. Otherwise, a ZERO_PAGE folio is returned.
4032+
*
4033+
* Deduce the size of the folio with folio_size instead of assuming the
4034+
* folio size.
4035+
*/
4036+
static inline struct folio *largest_zero_folio(void)
4037+
{
4038+
if(!huge_zero_folio)
4039+
return page_folio(ZERO_PAGE(0));
4040+
4041+
return READ_ONCE(huge_zero_folio);
4042+
}
4043+
40234044
#else
40244045
static inline void __init static_pmd_zero_init(void)
40254046
{
40264047
return;
40274048
}
4049+
4050+
static inline struct folio *largest_zero_folio(void)
4051+
{
4052+
return page_folio(ZERO_PAGE(0));
4053+
}
40284054
#endif
40294055

4030-
extern struct folio *huge_zero_folio;
4031-
extern unsigned long huge_zero_pfn;
40324056

40334057
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
40344058
static inline bool is_huge_zero_folio(const struct folio *folio)

0 commit comments

Comments
 (0)