Skip to content

Commit 4f5d0f8

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 4af54a5 commit 4f5d0f8

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

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

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

4036-
extern struct folio *huge_zero_folio;
4037-
extern unsigned long huge_zero_pfn;
40384062

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

0 commit comments

Comments
 (0)