add static huge zero folio support
Subsystems (6)
cover add static huge zero folio support
From: Pankaj Raghav <[email protected]>
There are many places in the kernel where we need to zeroout larger chunks but the maximum segment we can zeroout at a time by ZERO_PAGE is limited by PAGE_SIZE.
This concern was raised during the review of adding Large Block Size support to XFS[2][3].
This is especially annoying in block devices and filesystems where we attach multiple ZERO_PAGEs to the bio in different bvecs. With multipage bvec support in block layer, it is much more efficient to send out larger zero pages as a part of a single bvec.
Some examples of places in the kernel where this could be useful:
- blkdev_issue_zero_pages()
- iomap_dio_zero()
- vmalloc.c:zero_iter()
- rxperf_process_call()
- fscrypt_zeroout_range_inline_crypt()
- bch2_checksum_update()
...
Usually huge_zero_folio is allocated on demand, and it will be deallocated by the shrinker if there are no users of it left. At the moment, huge_zero_folio infrastructure refcount is tied to the process lifetime that created it. This might not work for bio layer as the completions can be async and the process that created the huge_zero_folio might no longer be alive. And, one of the main point that came during discussion is to have something bigger than zero page as a drop-in replacement.
Add a config option STATIC_HUGE_ZERO_FOLIO that will always allocate the huge_zero_folio, and it will never drop the reference. This makes using the huge_zero_folio without having to pass any mm struct and does not tie the lifetime of the zero folio to anything, making it a drop-in replacement for ZERO_PAGE.
I have converted blkdev_issue_zero_pages() as an example as a part of this series. I also noticed close to 4% performance improvement just by replacing ZERO_PAGE with static huge_zero_folio.
I will send patches to individual subsystems using the huge_zero_folio once this gets upstreamed.
Looking forward to some feedback.
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/linux-xfs/[email protected]/
[3] https://lore.kernel.org/linux-xfs/[email protected]/
Changes since RFC v2:
- Convert get_huge_zero_page and put_huge_zero_page to *_folio.
- Convert MMF_HUGE_ZERO_PAGE to MMF_HUGE_ZERO_FOLIO.
- Make the retry for huge_zero_folio from 2 to 1.
- Add an extra sanity check in shrinker scan for static huge_zero_folio case.
Changes since v1:
- Fixed all warnings.
- Added a retry feature after a particular time.
- Added Acked-by and Signed-off-by from David.
Changes since last series[1]:
- Instead of allocating a new page through memblock, use the same infrastructure as huge_zero_folio but raise the reference and never drop it. (David)
- And some minor cleanups based on Lorenzo's feedback.
Pankaj Raghav (5):
mm: rename huge_zero_page to huge_zero_folio
mm: rename MMF_HUGE_ZERO_PAGE to MMF_HUGE_ZERO_FOLIO
mm: add static huge zero folio
mm: add largest_zero_folio() routine
block: use largest_zero_folio in __blkdev_issue_zero_pages()
arch/x86/Kconfig | 1 + block/blk-lib.c | 15 +++---- include/linux/huge_mm.h | 35 ++++++++++++++++ include/linux/mm_types.h | 2 +- mm/Kconfig | 21 ++++++++++ mm/huge_memory.c | 86 ++++++++++++++++++++++++++++++---------- 6 files changed, 131 insertions(+), 29 deletions(-)
base-commit: df01d1162a83194a036f0d648ae41e6ad8adbe1a
Signature · 1 line
2.49.0
PATCH 1/5 mm: rename huge_zero_page to huge_zero_folio
From: Pankaj Raghav <[email protected]>
As we already moved from exposing huge_zero_page to huge_zero_folio, change the name of the shrinker and the other helper function to reflect that.
No functional changes.
--- mm/huge_memory.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
mm/huge_memory.c +17 -17
@@ -207,7 +207,7 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,return orders; } -static bool get_huge_zero_page (void ) +static bool get_huge_zero_folio (void ) {struct folio *zero_folio; retry:
@@ -237,7 +237,7 @@ static bool get_huge_zero_page(void)return true; } -static void put_huge_zero_page (void ) +static void put_huge_zero_folio (void ) {/* * Counter should never go to zero here. Only shrinker can put
@@ -251,11 +251,11 @@ struct folio *mm_get_huge_zero_folio(struct mm_struct *mm)if (test_bit (MMF_HUGE_ZERO_PAGE , &mm->flags))return READ_ONCE (huge_zero_folio); -if (!get_huge_zero_page ()) +if (!get_huge_zero_folio ())return NULL ;if (test_and_set_bit (MMF_HUGE_ZERO_PAGE , &mm->flags)) -put_huge_zero_page (); +put_huge_zero_folio ();return READ_ONCE (huge_zero_folio); }
@@ -263,18 +263,18 @@ struct folio *mm_get_huge_zero_folio(struct mm_struct *mm)void mm_put_huge_zero_folio (struct mm_struct *mm) {if (test_bit (MMF_HUGE_ZERO_PAGE , &mm->flags)) -put_huge_zero_page (); +put_huge_zero_folio (); } -static unsigned long shrink_huge_zero_page_count (struct shrinker *shrink, -struct shrink_control *sc) +static unsigned long shrink_huge_zero_folio_count (struct shrinker *shrink, +struct shrink_control *sc) {/* we can free zero page only if last reference remains */ return atomic_read (&huge_zero_refcount) ==1 ?HPAGE_PMD_NR :0 ; } -static unsigned long shrink_huge_zero_page_scan (struct shrinker *shrink, -struct shrink_control *sc) +static unsigned long shrink_huge_zero_folio_scan (struct shrinker *shrink, +struct shrink_control *sc) {if (atomic_cmpxchg (&huge_zero_refcount,1 ,0 ) ==1 ) {struct folio *zero_folio =xchg (&huge_zero_folio,NULL );
@@ -287,7 +287,7 @@ static unsigned long shrink_huge_zero_page_scan(struct shrinker *shrink,return 0 ; } -static struct shrinker *huge_zero_page_shrinker; +static struct shrinker *huge_zero_folio_shrinker;#ifdef CONFIG_SYSFS static ssize_t enabled_show(struct kobject *kobj,
@@ -849,8 +849,8 @@ static inline void hugepage_exit_sysfs(struct kobject *hugepage_kobj)static int __init thp_shrinker_init (void ) { - huge_zero_page_shrinker =shrinker_alloc (0 ,"thp-zero" ); -if (!huge_zero_page_shrinker) + huge_zero_folio_shrinker =shrinker_alloc (0 ,"thp-zero" ); +if (!huge_zero_folio_shrinker)return -ENOMEM ; deferred_split_shrinker = shrinker_alloc(SHRINKER_NUMA_AWARE |
@@ -858,13 +858,13 @@ static int __init thp_shrinker_init(void)SHRINKER_NONSLAB , "thp-deferred_split");if (!deferred_split_shrinker) { -shrinker_free (huge_zero_page_shrinker); +shrinker_free (huge_zero_folio_shrinker);return -ENOMEM ; } - huge_zero_page_shrinker->count_objects = shrink_huge_zero_page_count; - huge_zero_page_shrinker->scan_objects = shrink_huge_zero_page_scan; -shrinker_register (huge_zero_page_shrinker); + huge_zero_folio_shrinker->count_objects = shrink_huge_zero_folio_count; + huge_zero_folio_shrinker->scan_objects = shrink_huge_zero_folio_scan; +shrinker_register (huge_zero_folio_shrinker); deferred_split_shrinker->count_objects = deferred_split_count; deferred_split_shrinker->scan_objects = deferred_split_scan;
@@ -875,7 +875,7 @@ static int __init thp_shrinker_init(void)static void __init thp_shrinker_exit (void ) { -shrinker_free (huge_zero_page_shrinker); +shrinker_free (huge_zero_folio_shrinker);shrinker_free (deferred_split_shrinker); }
Signature · 1 line
2.49.0
Zi Yan
reviewerRe: [PATCH 1/5] mm: rename huge_zero_page to huge_zero_folio
Quoted 8 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
As we already moved from exposing
huge_zero_pagetohuge_zero_folio, change the name of the shrinker and the other helper function to reflect that.No functional changes.
Quoted 8 lines
Reviewed-by Lorenzo Stoakes <[email protected]>Suggested-by David Hildenbrand <[email protected]>Signed-off-by Pankaj Raghav <[email protected]>--- mm/huge_memory.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
LGTM. Reviewed-by: Zi Yan <[email protected]>
Best Regards,
Yan, Zi
PATCH 2/5 mm: rename MMF_HUGE_ZERO_PAGE to MMF_HUGE_ZERO_FOLIO
In reply to Pankaj Raghav (Samsung)From: Pankaj Raghav <[email protected]>
As all the helper functions has been renamed from *_page to *_folio, rename the MM flag from MMF_HUGE_ZERO_PAGE to MMF_HUGE_ZERO_FOLIO.
No functional changes.
--- include/linux/mm_types.h | 2 +- mm/huge_memory.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
include/linux/mm_types.h +1 -1
@@ -1753,7 +1753,7 @@ enum {#define MMF_RECALC_UPROBES 20/* MMF_HAS_UPROBES can be wrong */ #define MMF_OOM_SKIP 21/* mm is of no interest for the OOM killer */ #define MMF_UNSTABLE 22/* mm is unstable for copy_from_user */ -#define MMF_HUGE_ZERO_PAGE 23/* mm has ever used the global huge zero page */ +#define MMF_HUGE_ZERO_FOLIO 23/* mm has ever used the global huge zero folio */ #define MMF_DISABLE_THP 24/* disable THP for all VMAs */ #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP)#define MMF_OOM_REAP_QUEUED 25/* mm was queued for oom_reaper */
mm/huge_memory.c +3 -3
@@ -248,13 +248,13 @@ static void put_huge_zero_folio(void)struct folio *mm_get_huge_zero_folio (struct mm_struct *mm) { -if (test_bit (MMF_HUGE_ZERO_PAGE , &mm->flags)) +if (test_bit (MMF_HUGE_ZERO_FOLIO , &mm->flags))return READ_ONCE (huge_zero_folio);if (!get_huge_zero_folio ())return NULL ; -if (test_and_set_bit (MMF_HUGE_ZERO_PAGE , &mm->flags)) +if (test_and_set_bit (MMF_HUGE_ZERO_FOLIO , &mm->flags))put_huge_zero_folio ();return READ_ONCE (huge_zero_folio);
@@ -262,7 +262,7 @@ struct folio *mm_get_huge_zero_folio(struct mm_struct *mm)void mm_put_huge_zero_folio (struct mm_struct *mm) { -if (test_bit (MMF_HUGE_ZERO_PAGE , &mm->flags)) +if (test_bit (MMF_HUGE_ZERO_FOLIO , &mm->flags))put_huge_zero_folio (); }
Signature · 1 line
2.49.0
Re: [PATCH 2/5] mm: rename MMF_HUGE_ZERO_PAGE to MMF_HUGE_ZERO_FOLIO
Quoted 9 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
As all the helper functions has been renamed from
*_pageto*_folio, rename the MM flag fromMMF_HUGE_ZERO_PAGEtoMMF_HUGE_ZERO_FOLIO.No functional changes.
Suggested-by David Hildenbrand <[email protected]>Signed-off-by Pankaj Raghav <[email protected]>
LGTM, so:
Quoted 50 lines
--- include/linux/mm_types.h | 2 +- mm/huge_memory.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)include/linux/mm_types.h +1
-1@@ -1753,7 +1753,7 @@ enum {#define MMF_RECALC_UPROBES 20/* MMF_HAS_UPROBES can be wrong */ #define MMF_OOM_SKIP 21/* mm is of no interest for the OOM killer */ #define MMF_UNSTABLE 22/* mm is unstable for copy_from_user */ -#define MMF_HUGE_ZERO_PAGE 23/* mm has ever used the global huge zero page */ +#define MMF_HUGE_ZERO_FOLIO 23/* mm has ever used the global huge zero folio */ #define MMF_DISABLE_THP 24/* disable THP for all VMAs */ #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP)#define MMF_OOM_REAP_QUEUED 25/* mm was queued for oom_reaper */ mm/huge_memory.c +3
-4@@ -248,13 +248,13 @@ static void put_huge_zero_folio(void)struct folio *mm_get_huge_zero_folio (struct mm_struct *mm) { -if (test_bit (MMF_HUGE_ZERO_PAGE , &mm->flags)) +if (test_bit (MMF_HUGE_ZERO_FOLIO , &mm->flags))return READ_ONCE (huge_zero_folio);if (!get_huge_zero_folio ())return NULL ; -if (test_and_set_bit (MMF_HUGE_ZERO_PAGE , &mm->flags)) +if (test_and_set_bit (MMF_HUGE_ZERO_FOLIO , &mm->flags))put_huge_zero_folio ();return READ_ONCE (huge_zero_folio);@@ -262,7 +262,7 @@ struct folio *mm_get_huge_zero_folio(struct mm_struct *mm)void mm_put_huge_zero_folio (struct mm_struct *mm) { -if (test_bit (MMF_HUGE_ZERO_PAGE , &mm->flags)) +if (test_bit (MMF_HUGE_ZERO_FOLIO , &mm->flags))put_huge_zero_folio (); } --2.49.0
Re: [PATCH 2/5] mm: rename MMF_HUGE_ZERO_PAGE to MMF_HUGE_ZERO_FOLIO
In reply to Pankaj Raghav (Samsung)Quoted 10 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
As all the helper functions has been renamed from
*_pageto*_folio, rename the MM flag fromMMF_HUGE_ZERO_PAGEtoMMF_HUGE_ZERO_FOLIO.No functional changes.
Suggested-by David Hildenbrand <[email protected]>Signed-off-by Pankaj Raghav <[email protected]>---
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 2/5] mm: rename MMF_HUGE_ZERO_PAGE to MMF_HUGE_ZERO_FOLIO
In reply to Pankaj Raghav (Samsung)Quoted 5 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
As all the helper functions has been renamed from
*_pageto*_folio, rename the MM flag fromMMF_HUGE_ZERO_PAGEtoMMF_HUGE_ZERO_FOLIO.
Quoted 9 lines
No functional changes.
Suggested-by David Hildenbrand <[email protected]>Signed-off-by Pankaj Raghav <[email protected]>--- include/linux/mm_types.h | 2 +- mm/huge_memory.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
Best Regards,
Yan, Zi
PATCH 3/5 mm: add static huge zero folio
In reply to Pankaj Raghav (Samsung)From: Pankaj Raghav <[email protected]>
There are many places in the kernel where we need to zeroout larger chunks but the maximum segment we can zeroout at a time by ZERO_PAGE is limited by PAGE_SIZE.
This is especially annoying in block devices and filesystems where we attach multiple ZERO_PAGEs to the bio in different bvecs. With multipage bvec support in block layer, it is much more efficient to send out larger zero pages as a part of single bvec.
This concern was raised during the review of adding LBS support to XFS[1][2].
Usually huge_zero_folio is allocated on demand, and it will be deallocated by the shrinker if there are no users of it left. At moment, huge_zero_folio infrastructure refcount is tied to the process lifetime that created it. This might not work for bio layer as the completions can be async and the process that created the huge_zero_folio might no longer be alive. And, one of the main point that came during discussion is to have something bigger than zero page as a drop-in replacement.
Add a config option STATIC_HUGE_ZERO_FOLIO that will result in allocating the huge zero folio on first request, if not already allocated, and turn it static such that it can never get freed. This makes using the huge_zero_folio without having to pass any mm struct and does not tie the lifetime of the zero folio to anything, making it a drop-in replacement for ZERO_PAGE.
If STATIC_HUGE_ZERO_FOLIO config option is enabled, then mm_get_huge_zero_folio() will simply return this page instead of dynamically allocating a new PMD page.
This option can waste memory in small systems or systems with 64k base page size. So make it an opt-in and also add an option from individual architecture so that we don't enable this feature for larger base page size systems. Only x86 is enabled as a part of this series. Other architectures shall be enabled as a follow-up to this series.
[1] https://lore.kernel.org/linux-xfs/[email protected]/
[2] https://lore.kernel.org/linux-xfs/[email protected]/
--- arch/x86/Kconfig | 1 + include/linux/huge_mm.h | 18 ++++++++++++++++ mm/Kconfig | 21 +++++++++++++++++++ mm/huge_memory.c | 46 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 85 insertions(+), 1 deletion(-)
arch/x86/Kconfig +1 -0
@@ -153,6 +153,7 @@ config X86 select ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP if X86_64 select ARCH_WANT_HUGETLB_VMEMMAP_PREINIT if X86_64 select ARCH_WANTS_THP_SWAP if X86_64 + select ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO if X86_64 select ARCH_HAS_PARANOID_L1D_FLUSH select ARCH_WANT_IRQS_OFF_ACTIVATE_MM select BUILDTIME_TABLE_SORT
include/linux/huge_mm.h +18 -0
@@ -476,6 +476,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf);extern struct folio *huge_zero_folio;extern unsigned long huge_zero_pfn; +extern atomic_t huge_zero_folio_is_static;static inline bool is_huge_zero_folio (const struct folio *folio) {
@@ -494,6 +495,18 @@ static inline bool is_huge_zero_pmd(pmd_t pmd)struct folio *mm_get_huge_zero_folio (struct mm_struct *mm);void mm_put_huge_zero_folio (struct mm_struct *mm); +struct folio *__get_static_huge_zero_folio (void ); + +static inline struct folio *get_static_huge_zero_folio (void ) +{ +if (!IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) +return NULL ; + +if (likely (atomic_read (&huge_zero_folio_is_static))) +return huge_zero_folio; + +return __get_static_huge_zero_folio (); +}static inline bool thp_migration_supported (void ) {
@@ -685,6 +698,11 @@ static inline int change_huge_pud(struct mmu_gather *tlb, {return 0 ; } + +static inline struct folio *get_static_huge_zero_folio (void ) +{ +return NULL ; +}#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static inline int split_folio_to_list_to_order(struct folio *folio,
mm/Kconfig +21 -0
@@ -823,6 +823,27 @@ config ARCH_WANT_GENERAL_HUGETLB config ARCH_WANTS_THP_SWAP def_bool n +config ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO + def_bool n + +config STATIC_HUGE_ZERO_FOLIO + bool "Allocate a PMD sized folio for zeroing" + depends on ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO && TRANSPARENT_HUGEPAGE + help + Without this config enabled, the huge zero folio is allocated on + demand and freed under memory pressure once no longer in use. + To detect remaining users reliably, references to the huge zero folio + must be tracked precisely, so it is commonly only available for mapping + it into user page tables. + + With this config enabled, the huge zero folio can also be used + for other purposes that do not implement precise reference counting: + it is still allocated on demand, but never freed, allowing for more + wide-spread use, for example, when performing I/O similar to the + traditional shared zeropage. + + Not suitable for memory constrained systems. + config MM_ID def_bool n
mm/huge_memory.c +45 -1
64 lines not on this page · raw message
Signature · 1 line
2.49.0
Re: [PATCH 3/5] mm: add static huge zero folio
Quoted 69 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
There are many places in the kernel where we need to zeroout larger chunks but the maximum segment we can zeroout at a time by
ZERO_PAGEis limited byPAGE_SIZE.This is especially annoying in block devices and filesystems where we attach multiple
ZERO_PAGEsto the bio in different bvecs. With multipage bvec support in block layer, it is much more efficient to send out larger zero pages as a part of single bvec.This concern was raised during the review of adding LBS support to XFS[1][2].
Usually
huge_zero_foliois allocated on demand, and it will be deallocated by the shrinker if there are no users of it left. At moment,huge_zero_folioinfrastructure refcount is tied to the process lifetime that created it. This might not work for bio layer as the completions can be async and the process that created thehuge_zero_foliomight no longer be alive. And, one of the main point that came during discussion is to have something bigger than zero page as a drop-in replacement.Add a config option
STATIC_HUGE_ZERO_FOLIOthat will result in allocating the huge zero folio on first request, if not already allocated, and turn it static such that it can never get freed. This makes using thehuge_zero_foliowithout having to pass any mm struct and does not tie the lifetime of the zero folio to anything, making it a drop-in replacement forZERO_PAGE.If
STATIC_HUGE_ZERO_FOLIOconfig option is enabled, thenmm_get_huge_zero_folio()will simply return this page instead of dynamically allocating a new PMD page.This option can waste memory in small systems or systems with 64k base page size. So make it an opt-in and also add an option from individual architecture so that we don't enable this feature for larger base page size systems. Only x86 is enabled as a part of this series. Other architectures shall be enabled as a follow-up to this series.
[1] https://lore.kernel.org/linux-xfs/[email protected]/
[2] https://lore.kernel.org/linux-xfs/[email protected]/Co-developed-by David Hildenbrand <[email protected]>Signed-off-by David Hildenbrand <[email protected]>Signed-off-by Pankaj Raghav <[email protected]>--- arch/x86/Kconfig | 1 + include/linux/huge_mm.h | 18 ++++++++++++++++ mm/Kconfig | 21 +++++++++++++++++++ mm/huge_memory.c | 46 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 85 insertions(+), 1 deletion(-)arch/x86/Kconfig +1
-0@@ -153,6 +153,7 @@ config X86 select ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP if X86_64 select ARCH_WANT_HUGETLB_VMEMMAP_PREINIT if X86_64 select ARCH_WANTS_THP_SWAP if X86_64 + select ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO if X86_64 select ARCH_HAS_PARANOID_L1D_FLUSH select ARCH_WANT_IRQS_OFF_ACTIVATE_MM select BUILDTIME_TABLE_SORTinclude/linux/huge_mm.h +0
-0
include/linux/huge_mm.h vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf); · line 479
Quoted 4 lines
include/linux/huge_mm.h +1
-0@@ -476,6 +476,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf);extern struct folio *huge_zero_folio;extern unsigned long huge_zero_pfn; +extern atomic_t huge_zero_folio_is_static;
Really don't love having globals like this, please can we have a helper function that tells you this and not extern it?
Also we're not checking CONFIG_STATIC_HUGE_ZERO_FOLIO but still exposing this value which a helper function would avoid also.
include/linux/huge_mm.h static inline bool is_huge_zero_pmd(pmd_t pmd) · line 498
Quoted 8 lines
include/linux/huge_mm.h +1
-0static inline bool is_huge_zero_folio (const struct folio *folio) {@@ -494,6 +495,18 @@ static inline bool is_huge_zero_pmd(pmd_t pmd)struct folio *mm_get_huge_zero_folio (struct mm_struct *mm);void mm_put_huge_zero_folio (struct mm_struct *mm); +struct folio *__get_static_huge_zero_folio (void );
Why are we declaring a static inline function prototype that we then implement immediately below?
Quoted 71 lines
include/linux/huge_mm.h +16
-0+ +static inline struct folio *get_static_huge_zero_folio (void ) +{ +if (!IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) +return NULL ; + +if (likely (atomic_read (&huge_zero_folio_is_static))) +return huge_zero_folio; + +return __get_static_huge_zero_folio (); +}static inline bool thp_migration_supported (void ) {@@ -685,6 +698,11 @@ static inline int change_huge_pud(struct mmu_gather *tlb, {return 0 ; } + +static inline struct folio *get_static_huge_zero_folio (void ) +{ +return NULL ; +}#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static inline int split_folio_to_list_to_order(struct folio *folio,mm/Kconfig +21
-0@@ -823,6 +823,27 @@ config ARCH_WANT_GENERAL_HUGETLB config ARCH_WANTS_THP_SWAP def_bool n +config ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO + def_bool n + +config STATIC_HUGE_ZERO_FOLIO + bool "Allocate a PMD sized folio for zeroing" + depends on ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO && TRANSPARENT_HUGEPAGE + help + Without this config enabled, the huge zero folio is allocated on + demand and freed under memory pressure once no longer in use. + To detect remaining users reliably, references to the huge zero folio + must be tracked precisely, so it is commonly only available for mapping + it into user page tables. + + With this config enabled, the huge zero folio can also be used + for other purposes that do not implement precise reference counting: + it is still allocated on demand, but never freed, allowing for more + wide-spread use, for example, when performing I/O similar to the + traditional shared zeropage. + + Not suitable for memory constrained systems. + config MM_ID def_bool nmm/huge_memory.c +1
-0@@ -75,6 +75,7 @@ static unsigned long deferred_split_scan(struct shrinker *shrink,static bool split_underused_thp = true;static atomic_t huge_zero_refcount; +atomic_t huge_zero_folio_is_static__read_mostly ;struct folio *huge_zero_folio__read_mostly ;unsigned long huge_zero_pfn__read_mostly = ~0UL ;unsigned long huge_anon_orders_always__read_mostly ;
mm/huge_memory.c void mm_put_huge_zero_folio(struct mm_struct *mm) · line 271
Quoted 5 lines
mm/huge_memory.c +2
-0@@ -266,6 +267,45 @@ void mm_put_huge_zero_folio(struct mm_struct *mm)put_huge_zero_folio (); } +#ifdef CONFIG_STATIC_HUGE_ZERO_FOLIO +
Extremely tiny silly nit - there's a blank line below this, but not under the #endif, let's remove this line.
Quoted 7 lines
mm/huge_memory.c +7
-0+struct folio *__get_static_huge_zero_folio (void ) +{ +static unsigned long fail_count_clear_timer; +static atomic_t huge_zero_static_fail_count__read_mostly ; + +if (unlikely (!slab_is_available ())) +return NULL ;
mm/huge_memory.c void mm_put_huge_zero_folio(struct mm_struct *mm) · line 288
Quoted 10 lines
mm/huge_memory.c +10
-0+ +/* +* If we failed to allocate a huge zero folio, just refrain from +* trying for one minute before retrying to get a reference again. +*/ +if (atomic_read (&huge_zero_static_fail_count) >1 ) { +if (time_before (jiffies, fail_count_clear_timer)) +return NULL ; +atomic_set (&huge_zero_static_fail_count,0 ); + }
Yeah I really don't like this. This seems overly complicated and too fiddly. Also if I want a static PMD, do I want to wait a minute for next attempt?
Also doing things this way we might end up:
0. Enabling CONFIG_STATIC_HUGE_ZERO_FOLIO
1. Not doing anything that needs a static PMD for a while + get fragmentation.
2. Do something that needs it - oops can't get order-9 page, and waiting 60 seconds between attempts
3. This is silent so you think you have it switched on but are actually getting bad performance.
I appreciate wanting to reuse this code, but we need to find a way to do this really really early, and get rid of this arbitrary time out. It's very aribtrary and we have no easy way of tracing how this might behave under workload.
Also we end up pinning an order-9 page either way, so no harm in getting it first thing?
Quoted 24 lines
mm/huge_memory.c +20
-0+/* +* Our raised reference will prevent the shrinker from ever having +* success. +*/ +if (!get_huge_zero_folio ()) { +int count =atomic_inc_return (&huge_zero_static_fail_count); + +if (count >1 ) + fail_count_clear_timer =get_jiffies_64 () +60 *HZ ; + +return NULL ; + } + +if (atomic_cmpxchg (&huge_zero_folio_is_static,0 ,1 ) !=0 ) +put_huge_zero_folio (); + + return huge_zero_folio; +} +#endif /* CONFIG_STATIC_HUGE_ZERO_FOLIO */ +static unsigned long shrink_huge_zero_folio_count (struct shrinker *shrink,struct shrink_control *sc) {
mm/huge_memory.c static unsigned long shrink_huge_zero_folio_scan(struct shrinker *shrink, · line 323
Quoted 8 lines
mm/huge_memory.c +4
-1@@ -277,7 +317,11 @@ static unsigned long shrink_huge_zero_folio_scan(struct shrinker *shrink, struct shrink_control *sc) {if (atomic_cmpxchg (&huge_zero_refcount,1 ,0 ) ==1 ) { -struct folio *zero_folio =xchg (&huge_zero_folio,NULL ); +struct folio *zero_folio; + +if (WARN_ON_ONCE (atomic_read (&huge_zero_folio_is_static))) +return 0 ;
I don't hugely love these various sets of static variables, I wonder if we could put them into a helper struct or something, and put these checks into helper functions?
static bool have_static_huge_zero_folio(void)
{
return ...;
}etc.
?
Quoted 7 lines
mm/huge_memory.c +1
-1+ zero_folio =xchg (&huge_zero_folio,NULL );BUG_ON (zero_folio ==NULL );WRITE_ONCE (huge_zero_pfn, ~0UL );folio_put (zero_folio); --2.49.0
Cheers, Lorenzo
Re: [PATCH 3/5] mm: add static huge zero folio
Quoted 204 lines · Lorenzo Stoakes
Quoted 69 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
There are many places in the kernel where we need to zeroout larger chunks but the maximum segment we can zeroout at a time by
ZERO_PAGEis limited byPAGE_SIZE.This is especially annoying in block devices and filesystems where we attach multiple
ZERO_PAGEsto the bio in different bvecs. With multipage bvec support in block layer, it is much more efficient to send out larger zero pages as a part of single bvec.This concern was raised during the review of adding LBS support to XFS[1][2].
Usually
huge_zero_foliois allocated on demand, and it will be deallocated by the shrinker if there are no users of it left. At moment,huge_zero_folioinfrastructure refcount is tied to the process lifetime that created it. This might not work for bio layer as the completions can be async and the process that created thehuge_zero_foliomight no longer be alive. And, one of the main point that came during discussion is to have something bigger than zero page as a drop-in replacement.Add a config option
STATIC_HUGE_ZERO_FOLIOthat will result in allocating the huge zero folio on first request, if not already allocated, and turn it static such that it can never get freed. This makes using thehuge_zero_foliowithout having to pass any mm struct and does not tie the lifetime of the zero folio to anything, making it a drop-in replacement forZERO_PAGE.If
STATIC_HUGE_ZERO_FOLIOconfig option is enabled, thenmm_get_huge_zero_folio()will simply return this page instead of dynamically allocating a new PMD page.This option can waste memory in small systems or systems with 64k base page size. So make it an opt-in and also add an option from individual architecture so that we don't enable this feature for larger base page size systems. Only x86 is enabled as a part of this series. Other architectures shall be enabled as a follow-up to this series.
[1] https://lore.kernel.org/linux-xfs/[email protected]/
[2] https://lore.kernel.org/linux-xfs/[email protected]/Co-developed-by David Hildenbrand <[email protected]>Signed-off-by David Hildenbrand <[email protected]>Signed-off-by Pankaj Raghav <[email protected]>--- arch/x86/Kconfig | 1 + include/linux/huge_mm.h | 18 ++++++++++++++++ mm/Kconfig | 21 +++++++++++++++++++ mm/huge_memory.c | 46 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 85 insertions(+), 1 deletion(-)arch/x86/Kconfig +1
-0@@ -153,6 +153,7 @@ config X86 select ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP if X86_64 select ARCH_WANT_HUGETLB_VMEMMAP_PREINIT if X86_64 select ARCH_WANTS_THP_SWAP if X86_64 + select ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO if X86_64 select ARCH_HAS_PARANOID_L1D_FLUSH select ARCH_WANT_IRQS_OFF_ACTIVATE_MM select BUILDTIME_TABLE_SORTinclude/linux/huge_mm.h +0
-0include/linux/huge_mm.h vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf); · line 479
Quoted 4 lines
include/linux/huge_mm.h +1
-0@@ -476,6 +476,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf);extern struct folio *huge_zero_folio;extern unsigned long huge_zero_pfn; +extern atomic_t huge_zero_folio_is_static;Really don't love having globals like this, please can we have a helper function that tells you this and not extern it?
Also we're not checking
CONFIG_STATIC_HUGE_ZERO_FOLIObut still exposing this value which a helper function would avoid also.include/linux/huge_mm.h static inline bool is_huge_zero_pmd(pmd_t pmd) · line 498
Quoted 8 lines
include/linux/huge_mm.h +1
-0static inline bool is_huge_zero_folio (const struct folio *folio) {@@ -494,6 +495,18 @@ static inline bool is_huge_zero_pmd(pmd_t pmd)struct folio *mm_get_huge_zero_folio (struct mm_struct *mm);void mm_put_huge_zero_folio (struct mm_struct *mm); +struct folio *__get_static_huge_zero_folio (void );Why are we declaring a static inline function prototype that we then implement immediately below?
Quoted 71 lines
include/linux/huge_mm.h +16
-0+ +static inline struct folio *get_static_huge_zero_folio (void ) +{ +if (!IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) +return NULL ; + +if (likely (atomic_read (&huge_zero_folio_is_static))) +return huge_zero_folio; + +return __get_static_huge_zero_folio (); +}static inline bool thp_migration_supported (void ) {@@ -685,6 +698,11 @@ static inline int change_huge_pud(struct mmu_gather *tlb, {return 0 ; } + +static inline struct folio *get_static_huge_zero_folio (void ) +{ +return NULL ; +}#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static inline int split_folio_to_list_to_order(struct folio *folio,mm/Kconfig +21
-0@@ -823,6 +823,27 @@ config ARCH_WANT_GENERAL_HUGETLB config ARCH_WANTS_THP_SWAP def_bool n +config ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO + def_bool n + +config STATIC_HUGE_ZERO_FOLIO + bool "Allocate a PMD sized folio for zeroing" + depends on ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO && TRANSPARENT_HUGEPAGE + help + Without this config enabled, the huge zero folio is allocated on + demand and freed under memory pressure once no longer in use. + To detect remaining users reliably, references to the huge zero folio + must be tracked precisely, so it is commonly only available for mapping + it into user page tables. + + With this config enabled, the huge zero folio can also be used + for other purposes that do not implement precise reference counting: + it is still allocated on demand, but never freed, allowing for more + wide-spread use, for example, when performing I/O similar to the + traditional shared zeropage. + + Not suitable for memory constrained systems. + config MM_ID def_bool nmm/huge_memory.c +1
-0@@ -75,6 +75,7 @@ static unsigned long deferred_split_scan(struct shrinker *shrink,static bool split_underused_thp = true;static atomic_t huge_zero_refcount; +atomic_t huge_zero_folio_is_static__read_mostly ;struct folio *huge_zero_folio__read_mostly ;unsigned long huge_zero_pfn__read_mostly = ~0UL ;unsigned long huge_anon_orders_always__read_mostly ;mm/huge_memory.c void mm_put_huge_zero_folio(struct mm_struct *mm) · line 271
Quoted 5 lines
mm/huge_memory.c +2
-0@@ -266,6 +267,45 @@ void mm_put_huge_zero_folio(struct mm_struct *mm)put_huge_zero_folio (); } +#ifdef CONFIG_STATIC_HUGE_ZERO_FOLIO +Extremely tiny silly nit - there's a blank line below this, but not under the #endif, let's remove this line.
Quoted 7 lines
mm/huge_memory.c +7
-0+struct folio *__get_static_huge_zero_folio (void ) +{ +static unsigned long fail_count_clear_timer; +static atomic_t huge_zero_static_fail_count__read_mostly ; + +if (unlikely (!slab_is_available ())) +return NULL ;mm/huge_memory.c void mm_put_huge_zero_folio(struct mm_struct *mm) · line 288
Quoted 10 lines
mm/huge_memory.c +10
-0+ +/* +* If we failed to allocate a huge zero folio, just refrain from +* trying for one minute before retrying to get a reference again. +*/ +if (atomic_read (&huge_zero_static_fail_count) >1 ) { +if (time_before (jiffies, fail_count_clear_timer)) +return NULL ; +atomic_set (&huge_zero_static_fail_count,0 ); + }Yeah I really don't like this. This seems overly complicated and too fiddly. Also if I want a static PMD, do I want to wait a minute for next attempt?
Also doing things this way we might end up:
0. Enabling
CONFIG_STATIC_HUGE_ZERO_FOLIO
1. Not doing anything that needs a static PMD for a while + get fragmentation.
2. Do something that needs it - oops can't get order-9 page, and waiting 60 seconds between attempts
3. This is silent so you think you have it switched on but are actually getting bad performance.
Quoted 6 lines
I appreciate wanting to reuse this code, but we need to find a way to do this really really early, and get rid of this arbitrary time out. It's very aribtrary and we have no easy way of tracing how this might behave under workload.
Also we end up pinning an order-9 page either way, so no harm in getting it first thing?
What we could do, to avoid messing with memblock and two ways of initializing a huge zero folio early, and just disable the shrinker.
Downside is that the page is really static (not just when actually used at least once). I like it:
arch/x86/Kconfig +1 -0
@@ -153,6 +153,7 @@ config X86 select ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP if X86_64 select ARCH_WANT_HUGETLB_VMEMMAP_PREINIT if X86_64 select ARCH_WANTS_THP_SWAP if X86_64 + select ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO if X86_64 select ARCH_HAS_PARANOID_L1D_FLUSH select ARCH_WANT_IRQS_OFF_ACTIVATE_MM select BUILDTIME_TABLE_SORT
include/linux/huge_mm.h +16 -0
@@ -495,6 +495,17 @@ static inline bool is_huge_zero_pmd(pmd_t pmd)struct folio *mm_get_huge_zero_folio (struct mm_struct *mm);void mm_put_huge_zero_folio (struct mm_struct *mm); +static inline struct folio *get_static_huge_zero_folio (void ) +{ +if (!IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) +return NULL ; + +if (unlikely (!huge_zero_folio)) +return NULL ; + +return huge_zero_folio; +} +static inline bool thp_migration_supported (void ) {return IS_ENABLED (CONFIG_ARCH_ENABLE_THP_MIGRATION );
@@ -685,6 +696,11 @@ static inline int change_huge_pud(struct mmu_gather *tlb, {return 0 ; } + +static inline struct folio *get_static_huge_zero_folio (void ) +{ +return NULL ; +}#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static inline int split_folio_to_list_to_order(struct folio *folio,
mm/Kconfig +21 -0
@@ -823,6 +823,27 @@ config ARCH_WANT_GENERAL_HUGETLB config ARCH_WANTS_THP_SWAP def_bool n +config ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO + def_bool n + +config STATIC_HUGE_ZERO_FOLIO + bool "Allocate a PMD sized folio for zeroing" + depends on ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO && TRANSPARENT_HUGEPAGE + help + Without this config enabled, the huge zero folio is allocated on + demand and freed under memory pressure once no longer in use. + To detect remaining users reliably, references to the huge zero folio + must be tracked precisely, so it is commonly only available for mapping + it into user page tables. + + With this config enabled, the huge zero folio can also be used + for other purposes that do not implement precise reference counting: + it is allocated statically and never freed, allowing for more + wide-spread use, for example, when performing I/O similar to the + traditional shared zeropage. + + Not suitable for memory constrained systems. + config MM_ID def_bool n
mm/huge_memory.c +8 -3
@@ -866,9 +866,14 @@ static int __init thp_shrinker_init(void) huge_zero_folio_shrinker->scan_objects = shrink_huge_zero_folio_scan;shrinker_register (huge_zero_folio_shrinker); - deferred_split_shrinker->count_objects = deferred_split_count; - deferred_split_shrinker->scan_objects = deferred_split_scan; -shrinker_register (deferred_split_shrinker); +if (IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) { +if (!get_huge_zero_folio ()) +pr_warn ("Allocating static huge zero folio failed\n" ); + }else { + deferred_split_shrinker->count_objects = deferred_split_count; + deferred_split_shrinker->scan_objects = deferred_split_scan; +shrinker_register (deferred_split_shrinker); + }return 0 ; }
Signature · 12 lines
2.50.1 Now, one thing I do not like is that we have "ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO" but then have a user-selectable option. Should we just get rid of ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO? -- Cheers, David / dhildenb
Re: [PATCH 3/5] mm: add static huge zero folio
Quoted 10 lines
mm/huge_memory.c +0
-1@@ -866,9 +866,14 @@ static int __init thp_shrinker_init(void) huge_zero_folio_shrinker->scan_objects = shrink_huge_zero_folio_scan;shrinker_register (huge_zero_folio_shrinker); - deferred_split_shrinker->count_objects = deferred_split_count;
mm/huge_memory.c static int __init thp_shrinker_init(void) · line 876
Quoted 10 lines
mm/huge_memory.c +8
-2- deferred_split_shrinker->scan_objects = deferred_split_scan; -shrinker_register (deferred_split_shrinker); +if (IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) { +if (!get_huge_zero_folio ()) +pr_warn ("Allocating static huge zero folio failed\n" ); + }else { + deferred_split_shrinker->count_objects = deferred_split_count; + deferred_split_shrinker->scan_objects = deferred_split_scan; +shrinker_register (deferred_split_shrinker); + }
^ disabled the wrong shrinker, but you should get the idea
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 3/5] mm: add static huge zero folio
In reply to David HildenbrandQuoted 13 lines · David Hildenbrand
Quoted 13 lines
Yeah I really don't like this. This seems overly complicated and too fiddly. Also if I want a static PMD, do I want to wait a minute for next attempt?
Also doing things this way we might end up:
0. Enabling
CONFIG_STATIC_HUGE_ZERO_FOLIO
1. Not doing anything that needs a static PMD for a while + get fragmentation.
2. Do something that needs it - oops can't get order-9 page, and waiting 60 seconds between attempts
3. This is silent so you think you have it switched on but are actually getting bad performance.
Quoted 8 lines
Quoted 6 lines
I appreciate wanting to reuse this code, but we need to find a way to do this really really early, and get rid of this arbitrary time out. It's very aribtrary and we have no easy way of tracing how this might behave under workload.
Also we end up pinning an order-9 page either way, so no harm in getting it first thing?
What we could do, to avoid messing with memblock and two ways of initializing a huge zero folio early, and just disable the shrinker.
Nice, I like this approach!
Quoted 2 lines
Downside is that the page is really static (not just when actually used at least once). I like it:
Well I'm not sure this is a downside :P
User is explicitly enabling an option that says 'I'm cool to lose an order-9 page for this'.
Quoted 100 lines
arch/x86/Kconfig +1
-0@@ -153,6 +153,7 @@ config X86 select ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP if X86_64 select ARCH_WANT_HUGETLB_VMEMMAP_PREINIT if X86_64 select ARCH_WANTS_THP_SWAP if X86_64 + select ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO if X86_64 select ARCH_HAS_PARANOID_L1D_FLUSH select ARCH_WANT_IRQS_OFF_ACTIVATE_MM select BUILDTIME_TABLE_SORTinclude/linux/huge_mm.h +16
-0@@ -495,6 +495,17 @@ static inline bool is_huge_zero_pmd(pmd_t pmd)struct folio *mm_get_huge_zero_folio (struct mm_struct *mm);void mm_put_huge_zero_folio (struct mm_struct *mm); +static inline struct folio *get_static_huge_zero_folio (void ) +{ +if (!IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) +return NULL ; + +if (unlikely (!huge_zero_folio)) +return NULL ; + +return huge_zero_folio; +} +static inline bool thp_migration_supported (void ) {return IS_ENABLED (CONFIG_ARCH_ENABLE_THP_MIGRATION );@@ -685,6 +696,11 @@ static inline int change_huge_pud(struct mmu_gather *tlb, {return 0 ; } + +static inline struct folio *get_static_huge_zero_folio (void ) +{ +return NULL ; +}#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static inline int split_folio_to_list_to_order(struct folio *folio,mm/Kconfig +21
-0@@ -823,6 +823,27 @@ config ARCH_WANT_GENERAL_HUGETLB config ARCH_WANTS_THP_SWAP def_bool n +config ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO + def_bool n + +config STATIC_HUGE_ZERO_FOLIO + bool "Allocate a PMD sized folio for zeroing" + depends on ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO && TRANSPARENT_HUGEPAGE + help + Without this config enabled, the huge zero folio is allocated on + demand and freed under memory pressure once no longer in use. + To detect remaining users reliably, references to the huge zero folio + must be tracked precisely, so it is commonly only available for mapping + it into user page tables. + + With this config enabled, the huge zero folio can also be used + for other purposes that do not implement precise reference counting: + it is allocated statically and never freed, allowing for more + wide-spread use, for example, when performing I/O similar to the + traditional shared zeropage. + + Not suitable for memory constrained systems. + config MM_ID def_bool nmm/huge_memory.c +8
-4@@ -866,9 +866,14 @@ static int __init thp_shrinker_init(void) huge_zero_folio_shrinker->scan_objects = shrink_huge_zero_folio_scan;shrinker_register (huge_zero_folio_shrinker); - deferred_split_shrinker->count_objects = deferred_split_count; - deferred_split_shrinker->scan_objects = deferred_split_scan; -shrinker_register (deferred_split_shrinker); +if (IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) { +if (!get_huge_zero_folio ()) +pr_warn ("Allocating static huge zero folio failed\n" ); + }else { + deferred_split_shrinker->count_objects = deferred_split_count; + deferred_split_shrinker->scan_objects = deferred_split_scan; +shrinker_register (deferred_split_shrinker); + }return 0 ; } --2.50.1
Quoted 4 lines
Now, one thing I do not like is that we have "
ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO" but then have a user-selectable option.Should we just get rid of
ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO?
Yeah, though I guess we probably need to make it need CONFIG_MMU if so? Probably don't want to provide it if it might somehow break things?
I guess we could keep it as long as CONFIG_STATIC_HUGE_ZERO_FOLIO depend on something sensible like CONFIG_MMU maybe 64-bit too?
Anyway this approach looks generally good!
Quoted 6 lines
--
Cheers,David / dhildenb
Cheers, Lorenzo
Re: [PATCH 3/5] mm: add static huge zero folio
Quoted 101 lines
Quoted 101 lines
arch/x86/Kconfig +1
-0@@ -153,6 +153,7 @@ config X86 select ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP if X86_64 select ARCH_WANT_HUGETLB_VMEMMAP_PREINIT if X86_64 select ARCH_WANTS_THP_SWAP if X86_64 + select ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO if X86_64 select ARCH_HAS_PARANOID_L1D_FLUSH select ARCH_WANT_IRQS_OFF_ACTIVATE_MM select BUILDTIME_TABLE_SORTinclude/linux/huge_mm.h +16
-0@@ -495,6 +495,17 @@ static inline bool is_huge_zero_pmd(pmd_t pmd)struct folio *mm_get_huge_zero_folio (struct mm_struct *mm);void mm_put_huge_zero_folio (struct mm_struct *mm); +static inline struct folio *get_static_huge_zero_folio (void ) +{ +if (!IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) +return NULL ; + +if (unlikely (!huge_zero_folio)) +return NULL ; + +return huge_zero_folio; +} +static inline bool thp_migration_supported (void ) {return IS_ENABLED (CONFIG_ARCH_ENABLE_THP_MIGRATION );@@ -685,6 +696,11 @@ static inline int change_huge_pud(struct mmu_gather *tlb, {return 0 ; } + +static inline struct folio *get_static_huge_zero_folio (void ) +{ +return NULL ; +}#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static inline int split_folio_to_list_to_order(struct folio *folio,mm/Kconfig +21
-0@@ -823,6 +823,27 @@ config ARCH_WANT_GENERAL_HUGETLB config ARCH_WANTS_THP_SWAP def_bool n +config ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO + def_bool n + +config STATIC_HUGE_ZERO_FOLIO + bool "Allocate a PMD sized folio for zeroing" + depends on ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO && TRANSPARENT_HUGEPAGE + help + Without this config enabled, the huge zero folio is allocated on + demand and freed under memory pressure once no longer in use. + To detect remaining users reliably, references to the huge zero folio + must be tracked precisely, so it is commonly only available for mapping + it into user page tables. + + With this config enabled, the huge zero folio can also be used + for other purposes that do not implement precise reference counting: + it is allocated statically and never freed, allowing for more + wide-spread use, for example, when performing I/O similar to the + traditional shared zeropage. + + Not suitable for memory constrained systems. + config MM_ID def_bool nmm/huge_memory.c +8
-4@@ -866,9 +866,14 @@ static int __init thp_shrinker_init(void) huge_zero_folio_shrinker->scan_objects = shrink_huge_zero_folio_scan;shrinker_register (huge_zero_folio_shrinker); - deferred_split_shrinker->count_objects = deferred_split_count; - deferred_split_shrinker->scan_objects = deferred_split_scan; -shrinker_register (deferred_split_shrinker); +if (IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) { +if (!get_huge_zero_folio ()) +pr_warn ("Allocating static huge zero folio failed\n" ); + }else { + deferred_split_shrinker->count_objects = deferred_split_count; + deferred_split_shrinker->scan_objects = deferred_split_scan; +shrinker_register (deferred_split_shrinker); + }return 0 ; } --2.50.1
Quoted 7 lines
Quoted 4 lines
Now, one thing I do not like is that we have "
ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO" but then have a user-selectable option.Should we just get rid of
ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO?Yeah, though I guess we probably need to make it need
CONFIG_MMUif so? Probably don't want to provide it if it might somehow break things?
It would still depend on THP, and THP is !MMU. So that should just work.
We could go one step further and special case in mm_get_huge_zero_folio() + mm_put_huge_zero_folio() on CONFIG_STATIC_HUGE_ZERO_FOLIO.
Something like
mm/huge_memory.c +6 -0
@@ -248,6 +248,9 @@ static void put_huge_zero_page(void)struct folio *mm_get_huge_zero_folio (struct mm_struct *mm) { +if (IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) +return huge_zero_folio; +if (test_bit (MMF_HUGE_ZERO_PAGE , &mm->flags))return READ_ONCE (huge_zero_folio);
@@ -262,6 +265,9 @@ struct folio *mm_get_huge_zero_folio(struct mm_struct *mm)void mm_put_huge_zero_folio (struct mm_struct *mm) { +if (IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) +return huge_zero_folio; +if (test_bit (MMF_HUGE_ZERO_PAGE , &mm->flags))put_huge_zero_page (); }
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 3/5] mm: add static huge zero folio
Thanks a lot Lorenzo and David for the feedback and quick iteration on the patchset. I really like the number of lines of code has been steadily reducing since the first version :)
I will fold the changes in the next series.
<snip>
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
(quoted diff) +8
-4@@ -866,9 +866,14 @@ static int __init thp_shrinker_init(void) huge_zero_folio_shrinker->scan_objects = shrink_huge_zero_folio_scan; shrinker_register(huge_zero_folio_shrinker); - deferred_split_shrinker->count_objects = deferred_split_count; - deferred_split_shrinker->scan_objects = deferred_split_scan; - shrinker_register(deferred_split_shrinker); + if (IS_ENABLED(CONFIG_STATIC_HUGE_ZERO_FOLIO)) { + if (!get_huge_zero_folio()) + pr_warn("Allocating static huge zero folio failed\n"); + } else { + deferred_split_shrinker->count_objects = deferred_split_count; + deferred_split_shrinker->scan_objects = deferred_split_scan; + shrinker_register(deferred_split_shrinker); + } return 0; } --2.50.1
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Now, one thing I do not like is that we have "
ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO" but then have a user-selectable option.Should we just get rid of
ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO?
One of the early feedbacks from Lorenzo was that there might be some architectures that has PMD size > 2M might enable this by mistake. So the ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO was introduced as an extra precaution apart from user selectable CONFIG_STATIC_HUGE_ZERO_FOLIO.
Isn't it better to have an extra knob per-arch to be on the safer side or you think it is too excessive?
Quoted 34 lines
Quoted 2 lines
Yeah, though I guess we probably need to make it need
CONFIG_MMUif so? Probably don't want to provide it if it might somehow break things?It would still depend on THP, and THP is !MMU. So that should just work.
We could go one step further and special case in
mm_get_huge_zero_folio()+mm_put_huge_zero_folio()onCONFIG_STATIC_HUGE_ZERO_FOLIO.Something like
mm/huge_memory.c +6
-0@@ -248,6 +248,9 @@ static void put_huge_zero_page(void)struct folio *mm_get_huge_zero_folio (struct mm_struct *mm) { +if (IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) +return huge_zero_folio; +if (test_bit (MMF_HUGE_ZERO_PAGE , &mm->flags))return READ_ONCE (huge_zero_folio);@@ -262,6 +265,9 @@ struct folio *mm_get_huge_zero_folio(struct mm_struct *mm)void mm_put_huge_zero_folio (struct mm_struct *mm) { +if (IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) +return huge_zero_folio; +if (test_bit (MMF_HUGE_ZERO_PAGE , &mm->flags))put_huge_zero_page ();
Quoted 3 lines
}
--
Pankaj
Re: [PATCH 3/5] mm: add static huge zero folio
Quoted 30 lines · Pankaj Raghav (Samsung)
Thanks a lot Lorenzo and David for the feedback and quick iteration on the patchset. I really like the number of lines of code has been steadily reducing since the first version :)
I will fold the changes in the next series.
<snip>
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
(quoted diff) +8
-4@@ -866,9 +866,14 @@ static int __init thp_shrinker_init(void) huge_zero_folio_shrinker->scan_objects = shrink_huge_zero_folio_scan; shrinker_register(huge_zero_folio_shrinker); - deferred_split_shrinker->count_objects = deferred_split_count; - deferred_split_shrinker->scan_objects = deferred_split_scan; - shrinker_register(deferred_split_shrinker); + if (IS_ENABLED(CONFIG_STATIC_HUGE_ZERO_FOLIO)) { + if (!get_huge_zero_folio()) + pr_warn("Allocating static huge zero folio failed\n"); + } else { + deferred_split_shrinker->count_objects = deferred_split_count; + deferred_split_shrinker->scan_objects = deferred_split_scan; + shrinker_register(deferred_split_shrinker); + } return 0; } --2.50.1
Now, one thing I do not like is that we have "
ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO" but then have a user-selectable option.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Should we just get rid of
ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO?One of the early feedbacks from Lorenzo was that there might be some architectures that has PMD size > 2M might enable this by mistake. So the
ARCH_WANTS_STATIC_HUGE_ZERO_FOLIOwas introduced as an extra precaution apart from user selectableCONFIG_STATIC_HUGE_ZERO_FOLIO.
People will find creative ways to mis-configure their system no matter what you try :)
So I think best we can do is document it carefully.
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 3/5] mm: add static huge zero folio
Quoted 31 lines · David Hildenbrand
Quoted 30 lines · Pankaj Raghav (Samsung)
Thanks a lot Lorenzo and David for the feedback and quick iteration on the patchset. I really like the number of lines of code has been steadily reducing since the first version :)
I will fold the changes in the next series.
<snip>
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
(quoted diff) +8
-4@@ -866,9 +866,14 @@ static int __init thp_shrinker_init(void) huge_zero_folio_shrinker->scan_objects = shrink_huge_zero_folio_scan; shrinker_register(huge_zero_folio_shrinker); - deferred_split_shrinker->count_objects = deferred_split_count; - deferred_split_shrinker->scan_objects = deferred_split_scan; - shrinker_register(deferred_split_shrinker); + if (IS_ENABLED(CONFIG_STATIC_HUGE_ZERO_FOLIO)) { + if (!get_huge_zero_folio()) + pr_warn("Allocating static huge zero folio failed\n"); + } else { + deferred_split_shrinker->count_objects = deferred_split_count; + deferred_split_shrinker->scan_objects = deferred_split_scan; + shrinker_register(deferred_split_shrinker); + } return 0; } --2.50.1
Now, one thing I do not like is that we have "
ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO" but then have a user-selectable option.
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Should we just get rid of
ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO?One of the early feedbacks from Lorenzo was that there might be some architectures that has PMD size > 2M might enable this by mistake. So the
ARCH_WANTS_STATIC_HUGE_ZERO_FOLIOwas introduced as an extra precaution apart from user selectableCONFIG_STATIC_HUGE_ZERO_FOLIO.
Oh yeah so I did :P forgot I said that.
Quoted 2 lines
People will find creative ways to mis-configure their system no matter what you try :)
I think with an explicit config flag, this won't be _broken_ so much as wasteful, so therefore not really an issue.
Quoted 2 lines
So I think best we can do is document it carefully.
Yup, well always :)
Quoted 6 lines
--
Cheers,David / dhildenb
Cheers, Lorenzo
Re: [PATCH 3/5] mm: add static huge zero folio
In reply to David HildenbrandQuoted 3 lines
We could go one step further and special case in
mm_get_huge_zero_folio()+mm_put_huge_zero_folio()onCONFIG_STATIC_HUGE_ZERO_FOLIO.
Hmm, but we could have also failed to allocate even though the option was enabled.
2 options:
- we could do:
if (IS_ENABLED(CONFIG_STATIC_HUGE_ZERO_FOLIO) && huge_zero_folio)
return huge_zero_folio;
or
- As dave suggested, we could do a static key and enable it when the option is enabled and the allocation succeeded. The same static key can also be used in get_static_huge_zero_folio().
I think the latter option will look more clean and slightly more optimal?
Quoted 26 lines
Something like
mm/huge_memory.c +6
-0@@ -248,6 +248,9 @@ static void put_huge_zero_page(void)struct folio *mm_get_huge_zero_folio (struct mm_struct *mm) { +if (IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) +return huge_zero_folio; +if (test_bit (MMF_HUGE_ZERO_PAGE , &mm->flags))return READ_ONCE (huge_zero_folio);@@ -262,6 +265,9 @@ struct folio *mm_get_huge_zero_folio(struct mm_struct *mm)void mm_put_huge_zero_folio (struct mm_struct *mm) { +if (IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) +return huge_zero_folio; +if (test_bit (MMF_HUGE_ZERO_PAGE , &mm->flags))put_huge_zero_page ();
Quoted 2 lines
}
--
Pankaj
Re: [PATCH 3/5] mm: add static huge zero folio
Quoted 6 lines · Pankaj Raghav (Samsung)
Quoted 3 lines
We could go one step further and special case in
mm_get_huge_zero_folio()+mm_put_huge_zero_folio()onCONFIG_STATIC_HUGE_ZERO_FOLIO.Hmm, but we could have also failed to allocate even though the option was enabled.
Then we return huge_zero_folio, which is NULL?
Or what are you concerned about?
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 3/5] mm: add static huge zero folio
Quoted 11 lines · David Hildenbrand
Quoted 6 lines · Pankaj Raghav (Samsung)
Quoted 3 lines
We could go one step further and special case in
mm_get_huge_zero_folio()+mm_put_huge_zero_folio()onCONFIG_STATIC_HUGE_ZERO_FOLIO.Hmm, but we could have also failed to allocate even though the option was enabled.
Then we return
huge_zero_folio, which is NULL?Or what are you concerned about?
But don't we want to keep the "dynamic" allocation part be present even though we failed to allocate it statically in the shrinker_init?
Mainly so that the existing users of mm_get_huge_zero_folio() are not affected by these changes.
Quoted 6 lines
Signature · 4 lines
-- Cheers, David / dhildenb
Re: [PATCH 3/5] mm: add static huge zero folio
Quoted 11 lines · Pankaj Raghav (Samsung)
Quoted 10 lines · David Hildenbrand
Quoted 6 lines · Pankaj Raghav (Samsung)
Quoted 3 lines
We could go one step further and special case in
mm_get_huge_zero_folio()+mm_put_huge_zero_folio()onCONFIG_STATIC_HUGE_ZERO_FOLIO.Hmm, but we could have also failed to allocate even though the option was enabled.
Then we return
huge_zero_folio, which is NULL?
Quoted 7 lines
Quoted 1 line
Or what are you concerned about?
But don't we want to keep the "dynamic" allocation part be present even though we failed to allocate it statically in the
shrinker_init?Mainly so that the existing users of
mm_get_huge_zero_folio()are not affected by these changes.
I would just keep it simple and say that if we fail the early allocation (which will be extremely unlikely that early during boot!), just don't ever try to reallocate, even not when we could through mm_get_huge_zero_folio().
That sounds as simple as it gets. Again, failing to allocate that early and then succeeding to allocate later is a fairly unlikely scenario.
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 3/5] mm: add static huge zero folio
Quoted 20 lines · David Hildenbrand
Quoted 11 lines · Pankaj Raghav (Samsung)
Quoted 10 lines · David Hildenbrand
Quoted 6 lines · Pankaj Raghav (Samsung)
Quoted 3 lines
We could go one step further and special case in
mm_get_huge_zero_folio()+mm_put_huge_zero_folio()onCONFIG_STATIC_HUGE_ZERO_FOLIO.Hmm, but we could have also failed to allocate even though the option was enabled.
Then we return
huge_zero_folio, which is NULL?Quoted 7 lines
Quoted 1 line
Or what are you concerned about?
But don't we want to keep the "dynamic" allocation part be present even though we failed to allocate it statically in the
shrinker_init?Mainly so that the existing users of
mm_get_huge_zero_folio()are not affected by these changes.
Quoted 6 lines
I would just keep it simple and say that if we fail the early allocation (which will be extremely unlikely that early during boot!), just don't ever try to reallocate, even not when we could through
mm_get_huge_zero_folio().That sounds as simple as it gets. Again, failing to allocate that early and then succeeding to allocate later is a fairly unlikely scenario.
Ok. I will also document this as a comment just so that people are aware of this behaviour.
Thanks a lot David for the comments and feedback!
Signature · 1 line
Pankaj Raghav
Re: [PATCH 3/5] mm: add static huge zero folio
Quoted 25 lines · Pankaj Raghav (Samsung)
Quoted 24 lines · David Hildenbrand
Quoted 11 lines · Pankaj Raghav (Samsung)
Quoted 10 lines · David Hildenbrand
Quoted 6 lines · Pankaj Raghav (Samsung)
Quoted 3 lines
We could go one step further and special case in
mm_get_huge_zero_folio()+mm_put_huge_zero_folio()onCONFIG_STATIC_HUGE_ZERO_FOLIO.Hmm, but we could have also failed to allocate even though the option was enabled.
Then we return
huge_zero_folio, which is NULL?Quoted 7 lines
Quoted 1 line
Or what are you concerned about?
But don't we want to keep the "dynamic" allocation part be present even though we failed to allocate it statically in the
shrinker_init?Mainly so that the existing users of
mm_get_huge_zero_folio()are not affected by these changes.I would just keep it simple and say that if we fail the early allocation (which will be extremely unlikely that early during boot!), just don't ever try to reallocate, even not when we could through
mm_get_huge_zero_folio().
Quoted 7 lines
Quoted 2 lines
That sounds as simple as it gets. Again, failing to allocate that early and then succeeding to allocate later is a fairly unlikely scenario.
Ok. I will also document this as a comment just so that people are aware of this behaviour.
Thanks a lot David for the comments and feedback!
Sure, as always, feel free to object if you think I am talking nonsense :)
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 3/5] mm: add static huge zero folio
In reply to Pankaj Raghav (Samsung)Quoted 5 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
There are many places in the kernel where we need to zeroout larger chunks but the maximum segment we can zeroout at a time by
ZERO_PAGEis limited byPAGE_SIZE.
...
In x86-land, the rules are pretty clear about using imperative voice. There are quite a few "we's" in the changelog and comments in this series.
I do think they're generally good to avoid and do lead to more clarity, but I'm also not sure how important that is in mm-land these days.
include/linux/huge_mm.h static inline bool is_huge_zero_pmd(pmd_t pmd) · line 509
Quoted 10 lines
include/linux/huge_mm.h +10
-0+static inline struct folio *get_static_huge_zero_folio (void ) +{ +if (!IS_ENABLED (CONFIG_STATIC_HUGE_ZERO_FOLIO )) +return NULL ; + +if (likely (atomic_read (&huge_zero_folio_is_static))) +return huge_zero_folio; + +return __get_static_huge_zero_folio (); +}
This seems like an ideal place to use 'struct static_key'.
Quoted 32 lines
static inline bool
thp_migration_supported(void)
{include/linux/huge_mm.h +5
-0@@ -685,6 +698,11 @@ static inline int change_huge_pud(struct mmu_gather *tlb, {return 0 ; } + +static inline struct folio *get_static_huge_zero_folio (void ) +{ +return NULL ; +}#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static inline int split_folio_to_list_to_order(struct folio *folio,mm/Kconfig +10
-0@@ -823,6 +823,27 @@ config ARCH_WANT_GENERAL_HUGETLB config ARCH_WANTS_THP_SWAP def_bool n +config ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO + def_bool n + +config STATIC_HUGE_ZERO_FOLIO + bool "Allocate a PMD sized folio for zeroing" + depends on ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO && TRANSPARENT_HUGEPAGE + help + Without this config enabled, the huge zero folio is allocated on + demand and freed under memory pressure once no longer in use. + To detect remaining users reliably, references to the huge zero folio
mm/Kconfig config ARCH_WANT_GENERAL_HUGETLB · line 845
Quoted 10 lines
mm/Kconfig +10
-0+ must be tracked precisely, so it is commonly only available for mapping + it into user page tables. + + With this config enabled, the huge zero folio can also be used + for other purposes that do not implement precise reference counting: + it is still allocated on demand, but never freed, allowing for more + wide-spread use, for example, when performing I/O similar to the + traditional shared zeropage. + + Not suitable for memory constrained systems.
IMNHO, this is written like a changelog, not documentation for end users trying to make sense of Kconfig options. I'd suggest keeping it short and sweet:
config PERSISTENT_HUGE_ZERO_FOLIO
bool "Allocate a persistent PMD-sized folio for zeroing"
...
help
Enable this option to reduce the runtime refcounting overhead of the huge zero folio and expand the places in the kernel that can use huge zero folios.
With this option enabled, the huge zero folio is allocated once and never freed. It potentially wastes one huge page worth of memory.
Say Y if your system has lots of memory. Say N if you are memory constrained.
Quoted 28 lines
mm/Kconfig +0
-0config MM_ID def_bool nmm/huge_memory.c +10
-0@@ -75,6 +75,7 @@ static unsigned long deferred_split_scan(struct shrinker *shrink,static bool split_underused_thp = true;static atomic_t huge_zero_refcount; +atomic_t huge_zero_folio_is_static__read_mostly ;struct folio *huge_zero_folio__read_mostly ;unsigned long huge_zero_pfn__read_mostly = ~0UL ;unsigned long huge_anon_orders_always__read_mostly ;@@ -266,6 +267,45 @@ void mm_put_huge_zero_folio(struct mm_struct *mm)put_huge_zero_folio (); } +#ifdef CONFIG_STATIC_HUGE_ZERO_FOLIO + +struct folio *__get_static_huge_zero_folio (void ) +{ +static unsigned long fail_count_clear_timer; +static atomic_t huge_zero_static_fail_count__read_mostly ; + +if (unlikely (!slab_is_available ())) +return NULL ;
mm/huge_memory.c void mm_put_huge_zero_folio(struct mm_struct *mm) · line 288
Quoted 10 lines
mm/huge_memory.c +10
-0+ +/* +* If we failed to allocate a huge zero folio, just refrain from +* trying for one minute before retrying to get a reference again. +*/ +if (atomic_read (&huge_zero_static_fail_count) >1 ) { +if (time_before (jiffies, fail_count_clear_timer)) +return NULL ; +atomic_set (&huge_zero_static_fail_count,0 ); + }
Any reason that this is an open-coded ratelimit instead of using 'struct ratelimit_state'?
I also find the 'huge_zero_static_fail_count' use pretty unintuitive. This is fundamentally a slow path. Ideally, it's called once. In the pathological case, it's called once a minute.
I'd probably just recommend putting a rate limit on this function, then using a plain old mutex for the actual allocation to keep multiple threads out.
Then the function becomes something like this:
if (__ratelimit(&huge_zero_alloc_ratelimit)) return; guard(mutex)(&huge_zero_mutex); if (!get_huge_zero_folio()) return NULL; static_key_enable(&huge_zero_noref_key); return huge_zero_folio;
No atomic, no cmpxchg, no races on allocating.
...
Quoted 6 lines
mm/huge_memory.c +0
-0static unsigned long shrink_huge_zero_folio_count (struct shrinker *shrink,struct shrink_control *sc) {@@ -277,7 +317,11 @@ static unsigned long shrink_huge_zero_folio_scan(struct shrinker *shrink, struct shrink_control *sc) {
mm/huge_memory.c static unsigned long shrink_huge_zero_folio_scan(struct shrinker *shrink, · line 327
Quoted 10 lines
mm/huge_memory.c +5
-1if (atomic_cmpxchg (&huge_zero_refcount,1 ,0 ) ==1 ) { -struct folio *zero_folio =xchg (&huge_zero_folio,NULL ); +struct folio *zero_folio; + +if (WARN_ON_ONCE (atomic_read (&huge_zero_folio_is_static))) +return 0 ; + zero_folio =xchg (&huge_zero_folio,NULL );BUG_ON (zero_folio ==NULL );WRITE_ONCE (huge_zero_pfn, ~0UL );folio_put (zero_folio);
This seems like a hack to me. If you don't want the shrinker to run, then deregister it. Keeping the refcount elevated is fine, but repeatedly calling the shrinker to do atomic_cmpxchg() when you *know* it will do nothing seems silly.
If you can't deregister the shrinker, at least use the static_key approach and check the static key instead of doing futile cmpxchg's forever.
Re: [PATCH 3/5] mm: add static huge zero folio
Quoted 6 lines · Dave Hansen
Quoted 5 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
There are many places in the kernel where we need to zeroout larger chunks but the maximum segment we can zeroout at a time by
ZERO_PAGEis limited byPAGE_SIZE.
Quoted 7 lines
...
In x86-land, the rules are pretty clear about using imperative voice. There are quite a few "we's" in the changelog and comments in this series.
I do think they're generally good to avoid and do lead to more clarity, but I'm also not sure how important that is in mm-land these days.
Yeah, I will change it to imperative to stay consistent.
<snip>
Quoted 42 lines
Quoted 19 lines
static inline int split_folio_to_list_to_order(struct folio *folio,
mm/Kconfig +10
-0@@ -823,6 +823,27 @@ config ARCH_WANT_GENERAL_HUGETLB config ARCH_WANTS_THP_SWAP def_bool n +config ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO + def_bool n + +config STATIC_HUGE_ZERO_FOLIO + bool "Allocate a PMD sized folio for zeroing" + depends on ARCH_WANTS_STATIC_HUGE_ZERO_FOLIO && TRANSPARENT_HUGEPAGE + help + Without this config enabled, the huge zero folio is allocated on + demand and freed under memory pressure once no longer in use. + To detect remaining users reliably, references to the huge zero foliomm/Kconfig config ARCH_WANT_GENERAL_HUGETLB · line 845
Quoted 10 lines
mm/Kconfig +10
-0+ must be tracked precisely, so it is commonly only available for mapping + it into user page tables. + + With this config enabled, the huge zero folio can also be used + for other purposes that do not implement precise reference counting: + it is still allocated on demand, but never freed, allowing for more + wide-spread use, for example, when performing I/O similar to the + traditional shared zeropage. + + Not suitable for memory constrained systems.IMNHO, this is written like a changelog, not documentation for end users trying to make sense of
Kconfigoptions. I'd suggest keeping it short and sweet:config
PERSISTENT_HUGE_ZERO_FOLIO
bool "Allocate a persistent PMD-sized folio for zeroing"
...
help
Enable this option to reduce the runtime refcounting overhead of the huge zero folio and expand the places in the kernel that can use huge zero folios.
Quoted 7 lines
With this option enabled, the huge zero folio is allocated once and never freed. It potentially wastes one huge page worth of memory.
Say Y if your system has lots of memory. Say N if you are memory constrained.
This looks short and to the point. I can fold this in the next version. Thanks.
Quoted 64 lines
Quoted 28 lines
mm/Kconfig +0
-0config MM_ID def_bool nmm/huge_memory.c +10
-0@@ -75,6 +75,7 @@ static unsigned long deferred_split_scan(struct shrinker *shrink,static bool split_underused_thp = true;static atomic_t huge_zero_refcount; +atomic_t huge_zero_folio_is_static__read_mostly ;struct folio *huge_zero_folio__read_mostly ;unsigned long huge_zero_pfn__read_mostly = ~0UL ;unsigned long huge_anon_orders_always__read_mostly ;@@ -266,6 +267,45 @@ void mm_put_huge_zero_folio(struct mm_struct *mm)put_huge_zero_folio (); } +#ifdef CONFIG_STATIC_HUGE_ZERO_FOLIO + +struct folio *__get_static_huge_zero_folio (void ) +{ +static unsigned long fail_count_clear_timer; +static atomic_t huge_zero_static_fail_count__read_mostly ; + +if (unlikely (!slab_is_available ())) +return NULL ;mm/huge_memory.c void mm_put_huge_zero_folio(struct mm_struct *mm) · line 288
Quoted 10 lines
mm/huge_memory.c +10
-0+ +/* +* If we failed to allocate a huge zero folio, just refrain from +* trying for one minute before retrying to get a reference again. +*/ +if (atomic_read (&huge_zero_static_fail_count) >1 ) { +if (time_before (jiffies, fail_count_clear_timer)) +return NULL ; +atomic_set (&huge_zero_static_fail_count,0 ); + }Any reason that this is an open-coded ratelimit instead of using 'struct
ratelimit_state'?I also find the '
huge_zero_static_fail_count' use pretty unintuitive. This is fundamentally a slow path. Ideally, it's called once. In the pathological case, it's called once a minute.I'd probably just recommend putting a rate limit on this function, then using a plain old mutex for the actual allocation to keep multiple threads out.
Then the function becomes something like this:
if (__ratelimit(&huge_zero_alloc_ratelimit)) return; guard(mutex)(&huge_zero_mutex); if (!get_huge_zero_folio()) return NULL; static_key_enable(&huge_zero_noref_key); return huge_zero_folio;
Quoted 1 line
No atomic, no cmpxchg, no races on allocating.
David already reworked this part based on Lorenzo's feedback (he also did not like the ratelimiting part like you). The reworked diff is here[1]. No ratelimiting, etc.
Quoted 17 lines
...
Quoted 14 lines
static unsigned long shrink_huge_zero_folio_count(struct shrinker *shrink,
mm/huge_memory.c +5
-1struct shrink_control *sc) {@@ -277,7 +317,11 @@ static unsigned long shrink_huge_zero_folio_scan(struct shrinker *shrink, struct shrink_control *sc) {if (atomic_cmpxchg (&huge_zero_refcount,1 ,0 ) ==1 ) { -struct folio *zero_folio =xchg (&huge_zero_folio,NULL ); +struct folio *zero_folio; + +if (WARN_ON_ONCE (atomic_read (&huge_zero_folio_is_static))) +return 0 ; + zero_folio =xchg (&huge_zero_folio,NULL );BUG_ON (zero_folio ==NULL );
Quoted 9 lines
mm/huge_memory.c static unsigned long shrink_huge_zero_folio_scan(struct shrinker *shrink, · line 327
Quoted 2 lines
mm/huge_memory.c +0
-0WRITE_ONCE (huge_zero_pfn, ~0UL );folio_put (zero_folio);This seems like a hack to me. If you don't want the shrinker to run, then deregister it. Keeping the refcount elevated is fine, but repeatedly calling the shrinker to do
atomic_cmpxchg()when you *know* it will do nothing seems silly.
The new version[1] deregisters instead of having this condition. :)
Quoted 2 lines
If you can't deregister the shrinker, at least use the
static_keyapproach and check the static key instead of doing futile cmpxchg's forever.
--
Pankaj
PATCH 4/5 mm: add largest_zero_folio() routine
In reply to Pankaj Raghav (Samsung)From: Pankaj Raghav <[email protected]>
Add largest_zero_folio() routine so that huge_zero_folio can be 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.
--- include/linux/huge_mm.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
include/linux/huge_mm.h +17 -0
@@ -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 */
Signature · 1 line
2.49.0
Re: [PATCH 4/5] mm: add largest_zero_folio() routine
Quoted 10 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
Add
largest_zero_folio()routine so thathuge_zero_foliocan be used directly whenCONFIG_STATIC_HUGE_ZERO_FOLIOis enabled. This will returnZERO_PAGEfolio ifCONFIG_STATIC_HUGE_ZERO_FOLIOis disabled or if we failed to allocate ahuge_zero_folio.Co-developed-by David Hildenbrand <[email protected]>Signed-off-by David Hildenbrand <[email protected]>Signed-off-by Pankaj Raghav <[email protected]>
This looks good to me minus nit + comment below, so:
include/linux/huge_mm.h static inline int split_folio_to_order(struct folio *folio, int new_order) · line 719
Quoted 13 lines
--- include/linux/huge_mm.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)include/linux/huge_mm.h +1
-0@@ -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); } +/*
Maybe let's make this a kernel doc comment?
Quoted 5 lines
include/linux/huge_mm.h +5
-0+* 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. +*
include/linux/huge_mm.h static inline int split_folio_to_order(struct folio *folio, int new_order) · line 734
Quoted 10 lines
include/linux/huge_mm.h +10
-0+* 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 ));
Feels like we should have this in a wrapper function somewhere. Then again it seems people generally always open-code 'ZERO_PAGE(0)' anyway so maybe this is sort of the 'way things are done'? :P
Quoted 5 lines
include/linux/huge_mm.h +1
-1+}#endif /* _LINUX_HUGE_MM_H */ --2.49.0
Re: [PATCH 4/5] mm: add largest_zero_folio() routine
Quoted 8 lines · Lorenzo Stoakes
Quoted 7 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
Add
largest_zero_folio()routine so thathuge_zero_foliocan be used directly whenCONFIG_STATIC_HUGE_ZERO_FOLIOis enabled. This will returnZERO_PAGEfolio ifCONFIG_STATIC_HUGE_ZERO_FOLIOis disabled or if we failed to allocate ahuge_zero_folio.
Quoted 8 lines
Quoted 3 lines
Co-developed-by David Hildenbrand <[email protected]>Signed-off-by David Hildenbrand <[email protected]>Signed-off-by Pankaj Raghav <[email protected]>This looks good to me minus nit + comment below, so:
Reviewed-by Lorenzo Stoakes <[email protected]>
Thanks.
Quoted 12 lines
Quoted 12 lines
--- include/linux/huge_mm.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)include/linux/huge_mm.h +0
-0@@ -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); }
Quoted 3 lines
include/linux/huge_mm.h static inline int split_folio_to_order(struct folio *folio, int new_order) · line 719
Quoted 1 line
include/linux/huge_mm.h +1
-0+/* Maybe let's make this a kernel doc comment?
Yes, I will change it in the next version :)
Quoted 26 lines
Quoted 6 lines
include/linux/huge_mm.h +5
-0+* 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. +* include/linux/huge_mm.h static inline int split_folio_to_order(struct folio *folio, int new_order) · line 734
Quoted 10 lines
include/linux/huge_mm.h +10
-0+* 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 ));Feels like we should have this in a wrapper function somewhere. Then again it seems people generally always open-code '
ZERO_PAGE(0)' anyway so maybe this is sort of the 'way things are done'? :PQuoted 5 lines
include/linux/huge_mm.h +1
-1+}#endif /* _LINUX_HUGE_MM_H */ --2.49.0
Re: [PATCH 4/5] mm: add largest_zero_folio() routine
In reply to Pankaj Raghav (Samsung)Quoted 7 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
Add
largest_zero_folio()routine so thathuge_zero_foliocan be used directly whenCONFIG_STATIC_HUGE_ZERO_FOLIOis enabled. This will returnZERO_PAGEfolio ifCONFIG_STATIC_HUGE_ZERO_FOLIOis disabled or if we failed to allocate ahuge_zero_folio.
Quoted 7 lines
Co-developed-by David Hildenbrand <[email protected]>Signed-off-by David Hildenbrand <[email protected]>Signed-off-by Pankaj Raghav <[email protected]>--- include/linux/huge_mm.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
Best Regards,
Yan, Zi
Re: [PATCH 4/5] mm: add largest_zero_folio() routine
In reply to Pankaj Raghav (Samsung)Quoted 6 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
Add
largest_zero_folio()routine so thathuge_zero_foliocan be used directly whenCONFIG_STATIC_HUGE_ZERO_FOLIOis enabled. This will returnZERO_PAGEfolio ifCONFIG_STATIC_HUGE_ZERO_FOLIOis disabled or if we failed to allocate ahuge_zero_folio.
This changelog is telling a lot of the "what" but none of the "why".
The existing huge zero folio API is for users that have an mm. This is *only* for folks that want a huge zero folio but don't have an mm. That's _why_ this function is needed. It's in this series because there was no way to get a huge zero folio before the permanent one was introduced in this series.
Can we please get some of that into the function comment and changelog? It's critical.
Quoted 7 lines
include/linux/huge_mm.h +0
-0@@ -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); }
include/linux/huge_mm.h static inline int split_folio_to_order(struct folio *folio, int new_order) · line 727
Quoted 10 lines
include/linux/huge_mm.h +9
-0+/* +* 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. +*/
This comment needs to get fleshed out. It at _least_ needs to say something along the lines of:
Use this when a huge zero folio is needed but there is no mm lifetime to tie it to. Basically, use this when you can't use mm_get_huge_zero_folio().
include/linux/huge_mm.h static inline int split_folio_to_order(struct folio *folio, int new_order) · line 733
Quoted 6 lines
include/linux/huge_mm.h +6
-0+static inline struct folio *largest_zero_folio (void ) +{ +struct folio *folio =get_static_huge_zero_folio (); + +if (folio) +return folio;
There needs to be a newline in here.
include/linux/huge_mm.h static inline int split_folio_to_order(struct folio *folio, int new_order) · line 736
Quoted 3 lines
include/linux/huge_mm.h +2
-0+ return page_folio(ZERO_PAGE(0)); +}#endif /* _LINUX_HUGE_MM_H */
The code is fine, but the changelog and comments need quite a bit of work.
Re: [PATCH 4/5] mm: add largest_zero_folio() routine
Quoted 10 lines · Dave Hansen
Quoted 6 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
Add
largest_zero_folio()routine so thathuge_zero_foliocan be used directly whenCONFIG_STATIC_HUGE_ZERO_FOLIOis enabled. This will returnZERO_PAGEfolio ifCONFIG_STATIC_HUGE_ZERO_FOLIOis disabled or if we failed to allocate ahuge_zero_folio.This changelog is telling a lot of the "what" but none of the "why".
Quoted 8 lines
The existing huge zero folio API is for users that have an mm. This is *only* for folks that want a huge zero folio but don't have an mm. That's _why_ this function is needed. It's in this series because there was no way to get a huge zero folio before the permanent one was introduced in this series.
Can we please get some of that into the function comment and changelog? It's critical.
Valid point. I will include that in the next version.
Quoted 22 lines
Quoted 8 lines
include/linux/huge_mm.h +0
-0@@ -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); }include/linux/huge_mm.h static inline int split_folio_to_order(struct folio *folio, int new_order) · line 727
Quoted 10 lines
include/linux/huge_mm.h +9
-0+/* +* 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. +*/ This comment needs to get fleshed out. It at _least_ needs to say something along the lines of:
Quoted 4 lines
Use this when a huge zero folio is needed but there is no mm lifetime to tie it to. Basically, use this when you can't use
mm_get_huge_zero_folio().
Agreed.
Quoted 9 lines
include/linux/huge_mm.h static inline int split_folio_to_order(struct folio *folio, int new_order) · line 733
Quoted 6 lines
include/linux/huge_mm.h +6
-0+static inline struct folio *largest_zero_folio (void ) +{ +struct folio *folio =get_static_huge_zero_folio (); + +if (folio) +return folio;There needs to be a newline in here.
Quoted 5 lines
include/linux/huge_mm.h static inline int split_folio_to_order(struct folio *folio, int new_order) · line 736
Quoted 3 lines
include/linux/huge_mm.h +2
-0+ return page_folio(ZERO_PAGE(0)); +}#endif /* _LINUX_HUGE_MM_H */ The code is fine, but the changelog and comments need quite a bit of work.
Sounds good to me. I will make the changes. Thanks Dave.
--
Pankaj
PATCH 5/5 block: use largest_zero_folio in __blkdev_issue_zero_pages()
In reply to Pankaj Raghav (Samsung)From: Pankaj Raghav <[email protected]>
Use largest_zero_folio() in __blkdev_issue_zero_pages(). On systems with CONFIG_STATIC_HUGE_ZERO_FOLIO enabled, we will end up sending larger bvecs instead of multiple small ones.
Noticed a 4% increase in performance on a commercial NVMe SSD which does not support OP_WRITE_ZEROES. The device's MDTS was 128K. The performance gains might be bigger if the device supports bigger MDTS.
--- block/blk-lib.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
block/blk-lib.c +8 -7
@@ -196,6 +196,8 @@ static void __blkdev_issue_zero_pages(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, unsigned int flags) { + struct folio *zero_folio = largest_zero_folio(); +while (nr_sects) {unsigned int nr_vecs =__blkdev_sectors_to_bio_pages (nr_sects);struct bio *bio;
@@ -208,15 +210,14 @@ static void __blkdev_issue_zero_pages(struct block_device *bdev,break ;do { -unsigned int len, added; +unsigned int len; - len =min_t (sector_t, -PAGE_SIZE , nr_sects <<SECTOR_SHIFT ); - added =bio_add_page (bio,ZERO_PAGE (0 ), len,0 ); -if (added < len) + len =min_t (sector_t,folio_size (zero_folio), + nr_sects <<SECTOR_SHIFT ); +if (!bio_add_folio (bio, zero_folio, len,0 ))break ; - nr_sects -= added >>SECTOR_SHIFT ; - sector += added >>SECTOR_SHIFT ; + nr_sects -= len >>SECTOR_SHIFT ; + sector += len >>SECTOR_SHIFT ; }while (nr_sects); *biop =bio_chain_and_submit (*biop, bio);
Signature · 1 line
2.49.0
Re: [PATCH 5/5] block: use largest_zero_folio in __blkdev_issue_zero_pages()
Quoted 9 lines · Pankaj Raghav (Samsung)
From: Pankaj Raghav <[email protected]>
Use
largest_zero_folio()in__blkdev_issue_zero_pages(). On systems withCONFIG_STATIC_HUGE_ZERO_FOLIOenabled, we will end up sending larger bvecs instead of multiple small ones.Noticed a 4% increase in performance on a commercial NVMe SSD which does not support
OP_WRITE_ZEROES. The device's MDTS was 128K. The performance gains might be bigger if the device supports bigger MDTS.
Nice :)
Quoted 2 lines
Signed-off-by Pankaj Raghav <[email protected]>
This is not my area, but LGTM from mm function invocation point of view so:
We will probably want some input from block people on this too.
Quoted 42 lines
--- block/blk-lib.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)block/blk-lib.c +8
-8@@ -196,6 +196,8 @@ static void __blkdev_issue_zero_pages(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, unsigned int flags) { + struct folio *zero_folio = largest_zero_folio(); +while (nr_sects) {unsigned int nr_vecs =__blkdev_sectors_to_bio_pages (nr_sects);struct bio *bio;@@ -208,15 +210,14 @@ static void __blkdev_issue_zero_pages(struct block_device *bdev,break ;do { -unsigned int len, added; +unsigned int len; - len =min_t (sector_t, -PAGE_SIZE , nr_sects <<SECTOR_SHIFT ); - added =bio_add_page (bio,ZERO_PAGE (0 ), len,0 ); -if (added < len) + len =min_t (sector_t,folio_size (zero_folio), + nr_sects <<SECTOR_SHIFT ); +if (!bio_add_folio (bio, zero_folio, len,0 ))break ; - nr_sects -= added >>SECTOR_SHIFT ; - sector += added >>SECTOR_SHIFT ; + nr_sects -= len >>SECTOR_SHIFT ; + sector += len >>SECTOR_SHIFT ; }while (nr_sects); *biop =bio_chain_and_submit (*biop, bio); --2.49.0
Quoted 2 lines · Pankaj Raghav (Samsung)
Add a config option
STATIC_HUGE_ZERO_FOLIOthat will always allocate thehuge_zero_folio, and it will never drop the reference.
"static" is a really odd naming choice for a dynamically allocated structure. It's one that's never freed, sure, but it's still dynamically allocated in the first place.
Quoted 7 lines · Dave Hansen
Quoted 2 lines · Pankaj Raghav (Samsung)
Add a config option
STATIC_HUGE_ZERO_FOLIOthat will always allocate thehuge_zero_folio, and it will never drop the reference."static" is a really odd naming choice for a dynamically allocated structure. It's one that's never freed, sure, but it's still dynamically allocated in the first place.
That is a fair point.
I like the rename you did to PERSISTENT_HUGE_ZERO_FOLIO instead of STATIC_HUGE_ZERO_FOLIO as we still allocate it dynamically.
@David, @Lorenzo and @Zi: Does the rename sound good to you?
--
Pankaj
Quoted 9 lines · Pankaj Raghav (Samsung)
Quoted 7 lines · Dave Hansen
Quoted 2 lines · Pankaj Raghav (Samsung)
Add a config option
STATIC_HUGE_ZERO_FOLIOthat will always allocate thehuge_zero_folio, and it will never drop the reference."static" is a really odd naming choice for a dynamically allocated structure. It's one that's never freed, sure, but it's still dynamically allocated in the first place.
Quoted 6 lines
That is a fair point.
I like the rename you did to
PERSISTENT_HUGE_ZERO_FOLIOinstead ofSTATIC_HUGE_ZERO_FOLIOas we still allocate it dynamically.@David, @Lorenzo and @Zi: Does the rename sound good to you?
Yes, sounds good.
Signature · 3 lines
Cheers, David / dhildenb