enable PT_RECLAIM on more 64-bit architectures
Subsystems (12)
v4 cover enable PT_RECLAIM on more 64-bit architectures
From: Qi Zheng <[email protected]>
Changes in v4:
- convert __HAVE_ARCH_TLB_REMOVE_TABLE to CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE config
- fix a WARN_ON_ONCE() on sparc64 (and on ppc)
(reported by Andreas Larsson)
- collect Acked-by (Hi David, I've kept your Acked-by, feel free to drop it)
- rebase onto the v6.19-rc7
Changes in v3:
- modify the commit message in [PATCH v3 1/7] (suggested by David Hildenbrand)
- make PT_RECLAIM depends on MMU_GATHER_RCU_TABLE_FREE instead of 64BIT
- collect Acked-by
- rebase onto the next-20251217
Changelog in v2:
- fix compilation errors (reported by Magnus Lindholm and kernel test robot)
- adjust some code style (suggested by Huacai Chen)
- make PT_RECLAIM user-unselectable (suggested by David Hildenbrand)
- rebase onto the next-20251119
Hi all,
This series aims to enable PT_RECLAIM on more 64-bit architectures.
On a 64-bit system, madvise(MADV_DONTNEED) may cause a large number of empty PTE page table pages (such as 100GB+). To resolve this problem, we need to enable PT_RECLAIM, which depends on MMU_GATHER_RCU_TABLE_FREE.
For these architectures that define its own __tlb_remove_table(), since their page tables are not of type struct ptdesc, they cannot be supported PT_RECLAIM.
Therefore, this series first enables MMU_GATHER_RCU_TABLE_FREE on all 64-bit architectures, then converts __HAVE_ARCH_TLB_REMOVE_TABLE to CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE config, and finally makes PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && !HAVE_ARCH_TLB_REMOVE_TABLE. This way, PT_RECLAIM can be enabled by default on most 64-bit architectures.
Of course, this will also be enabled on some 32-bit architectures that already support MMU_GATHER_RCU_TABLE_FREE. That's fine, PT_RECLAIM works well on all 32-bit architectures as well. Although the benefit isn't significant, there's still memory that can be reclaimed. Perhaps PT_RECLAIM can be enabled on all 32-bit architectures in the future.
Comments and suggestions are welcome!
Thanks,
Qi
Qi Zheng (8):
mm: change mm/pt_reclaim.c to use asm/tlb.h instead of
asm-generic/tlb.h
alpha: mm: enable MMU_GATHER_RCU_TABLE_FREE
LoongArch: mm: enable MMU_GATHER_RCU_TABLE_FREE
mips: mm: enable MMU_GATHER_RCU_TABLE_FREE
parisc: mm: enable MMU_GATHER_RCU_TABLE_FREE
um: mm: enable MMU_GATHER_RCU_TABLE_FREE
mm: convert __HAVE_ARCH_TLB_REMOVE_TABLE to
CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE config
mm: make PT_RECLAIM depends on MMU_GATHER_RCU_TABLE_FREE
arch/alpha/Kconfig | 1 + arch/alpha/include/asm/tlb.h | 6 +++--- arch/loongarch/Kconfig | 1 + arch/loongarch/include/asm/pgalloc.h | 7 +++---- arch/mips/Kconfig | 1 + arch/mips/include/asm/pgalloc.h | 7 +++---- arch/parisc/Kconfig | 1 + arch/parisc/include/asm/tlb.h | 4 ++-- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/tlb.h | 1 - arch/sparc/Kconfig | 1 + arch/sparc/include/asm/tlb_64.h | 1 - arch/um/Kconfig | 1 + arch/x86/Kconfig | 1 - include/asm-generic/tlb.h | 2 +- mm/Kconfig | 8 +++----- mm/pt_reclaim.c | 2 +- 17 files changed, 23 insertions(+), 23 deletions(-)
Signature · 1 line
2.20.1
PATCH v4 1/8 mm: change mm/pt_reclaim.c to use asm/tlb.h instead of asm-generic/tlb.h
From: Qi Zheng <[email protected]>
Generally, the asm/tlb.h will include asm-generic/tlb.h, so change mm/pt_reclaim.c to use asm/tlb.h instead of asm-generic/tlb.h. This is a preparation for enabling CONFIG_PT_RECLAIM on other architectures, such as alpha.
--- mm/pt_reclaim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/pt_reclaim.c +1 -1
@@ -2,7 +2,7 @@#include <linux/hugetlb.h> #include <linux/pgalloc.h> -#include <asm-generic/tlb.h> +#include <asm/tlb.h> #include "internal.h"
Signature · 1 line
2.20.1
PATCH v4 2/8 alpha: mm: enable MMU_GATHER_RCU_TABLE_FREE
In reply to Qi ZhengFrom: Qi Zheng <[email protected]>
On a 64-bit system, madvise(MADV_DONTNEED) may cause a large number of empty PTE page table pages (such as 100GB+). To resolve this problem, first enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.
--- arch/alpha/Kconfig | 1 + arch/alpha/include/asm/tlb.h | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-)
arch/alpha/Kconfig +1 -0
@@ -38,6 +38,7 @@ config ALPHA select OLD_SIGSUSPEND select CPU_NO_EFFICIENT_FFS if !ALPHA_EV67 select MMU_GATHER_NO_RANGE + select MMU_GATHER_RCU_TABLE_FREE select SPARSEMEM_EXTREME if SPARSEMEM select ZONE_DMA help
arch/alpha/include/asm/tlb.h +3 -3
@@ -4,7 +4,7 @@#include <asm-generic/tlb.h> -#define __pte_free_tlb (tlb, pte, address) pte_free((tlb)->mm, pte) -#define __pmd_free_tlb (tlb, pmd, address) pmd_free((tlb)->mm, pmd) - +#define __pte_free_tlb (tlb, pte, address) tlb_remove_ptdesc((tlb), page_ptdesc(pte)) +#define __pmd_free_tlb (tlb, pmd, address) tlb_remove_ptdesc((tlb), virt_to_ptdesc(pmd)) +#endif
Signature · 1 line
2.20.1
Re: [PATCH v4 2/8] alpha: mm: enable MMU_GATHER_RCU_TABLE_FREE
Quoted 44 lines · Qi Zheng
From: Qi Zheng <[email protected]>
On a 64-bit system,
madvise(MADV_DONTNEED)may cause a large number of empty PTE page table pages (such as 100GB+). To resolve this problem, first enableMMU_GATHER_RCU_TABLE_FREEto prepare for enabling thePT_RECLAIMfeature, which resolves this problem.Signed-off-by Qi Zheng <[email protected]>Cc Richard Henderson <[email protected]>Cc Matt Turner <[email protected]>--- arch/alpha/Kconfig | 1 + arch/alpha/include/asm/tlb.h | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-)arch/alpha/Kconfig +1
-0@@ -38,6 +38,7 @@ config ALPHA select OLD_SIGSUSPEND select CPU_NO_EFFICIENT_FFS if !ALPHA_EV67 select MMU_GATHER_NO_RANGE + select MMU_GATHER_RCU_TABLE_FREE select SPARSEMEM_EXTREME if SPARSEMEM select ZONE_DMA helparch/alpha/include/asm/tlb.h +3
-4@@ -4,7 +4,7 @@#include <asm-generic/tlb.h> -#define __pte_free_tlb (tlb, pte, address) pte_free((tlb)->mm, pte) -#define __pmd_free_tlb (tlb, pmd, address) pmd_free((tlb)->mm, pmd) - +#define __pte_free_tlb (tlb, pte, address) tlb_remove_ptdesc((tlb), page_ptdesc(pte)) +#define __pmd_free_tlb (tlb, pmd, address) tlb_remove_ptdesc((tlb), virt_to_ptdesc(pmd)) +#endif --
Quoted 2 lines
2.20.1
Looks good from an Alpha perspective.
PATCH v4 3/8 LoongArch: mm: enable MMU_GATHER_RCU_TABLE_FREE
In reply to Qi ZhengFrom: Qi Zheng <[email protected]>
On a 64-bit system, madvise(MADV_DONTNEED) may cause a large number of empty PTE page table pages (such as 100GB+). To resolve this problem, first enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.
--- arch/loongarch/Kconfig | 1 + arch/loongarch/include/asm/pgalloc.h | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/loongarch/Kconfig +1 -0
@@ -187,6 +187,7 @@ config LOONGARCH select IRQ_LOONGARCH_CPU select LOCK_MM_AND_FIND_VMA select MMU_GATHER_MERGE_VMAS if MMU + select MMU_GATHER_RCU_TABLE_FREE select MODULES_USE_ELF_RELA if MODULES select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK
arch/loongarch/include/asm/pgalloc.h +3 -4
@@ -55,8 +55,7 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)return pte; } -#define __pte_free_tlb (tlb, pte, address) \ - tlb_remove_ptdesc((tlb), page_ptdesc(pte)) +#define __pte_free_tlb (tlb, pte, address) tlb_remove_ptdesc((tlb), page_ptdesc(pte))#ifndef __PAGETABLE_PMD_FOLDED
@@ -79,7 +78,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address) return pmd; } -#define __pmd_free_tlb (tlb, x, addr) pmd_free((tlb)->mm, x) +#define __pmd_free_tlb (tlb, x, addr) tlb_remove_ptdesc((tlb), virt_to_ptdesc(x))#endif
@@ -99,7 +98,7 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address) return pud; } -#define __pud_free_tlb (tlb, x, addr) pud_free((tlb)->mm, x) +#define __pud_free_tlb (tlb, x, addr) tlb_remove_ptdesc((tlb), virt_to_ptdesc(x))#endif /* __PAGETABLE_PUD_FOLDED */
Signature · 1 line
2.20.1
PATCH v4 4/8 mips: mm: enable MMU_GATHER_RCU_TABLE_FREE
In reply to Qi ZhengFrom: Qi Zheng <[email protected]>
On a 64-bit system, madvise(MADV_DONTNEED) may cause a large number of empty PTE page table pages (such as 100GB+). To resolve this problem, first enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.
--- arch/mips/Kconfig | 1 + arch/mips/include/asm/pgalloc.h | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/mips/Kconfig +1 -0
@@ -99,6 +99,7 @@ config MIPS select IRQ_FORCED_THREADING select ISA if EISA select LOCK_MM_AND_FIND_VMA + select MMU_GATHER_RCU_TABLE_FREE select MODULES_USE_ELF_REL if MODULES select MODULES_USE_ELF_RELA if MODULES && 64BIT select PERF_USE_VMALLOC
arch/mips/include/asm/pgalloc.h +3 -4
@@ -48,8 +48,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)extern void pgd_init (void *addr);extern pgd_t *pgd_alloc (struct mm_struct *mm); -#define __pte_free_tlb (tlb, pte, address) \ - tlb_remove_ptdesc((tlb), page_ptdesc(pte)) +#define __pte_free_tlb (tlb, pte, address) tlb_remove_ptdesc((tlb), page_ptdesc(pte))#ifndef __PAGETABLE_PMD_FOLDED
@@ -72,7 +71,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address) return pmd; } -#define __pmd_free_tlb (tlb, x, addr) pmd_free((tlb)->mm, x) +#define __pmd_free_tlb (tlb, x, addr) tlb_remove_ptdesc((tlb), virt_to_ptdesc(x))#endif
@@ -97,7 +96,7 @@ static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4d, pud_t *pud) set_p4d(p4d, __p4d((unsigned long)pud)); } -#define __pud_free_tlb (tlb, x, addr) pud_free((tlb)->mm, x) +#define __pud_free_tlb (tlb, x, addr) tlb_remove_ptdesc((tlb), virt_to_ptdesc(x))#endif /* __PAGETABLE_PUD_FOLDED */
Signature · 1 line
2.20.1
PATCH v4 5/8 parisc: mm: enable MMU_GATHER_RCU_TABLE_FREE
In reply to Qi ZhengFrom: Qi Zheng <[email protected]>
On a 64-bit system, madvise(MADV_DONTNEED) may cause a large number of empty PTE page table pages (such as 100GB+). To resolve this problem, first enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.
--- arch/parisc/Kconfig | 1 + arch/parisc/include/asm/tlb.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
arch/parisc/Kconfig +1 -0
@@ -79,6 +79,7 @@ config PARISC select GENERIC_CLOCKEVENTS select CPU_NO_EFFICIENT_FFS select THREAD_INFO_IN_TASK + select MMU_GATHER_RCU_TABLE_FREE select NEED_DMA_MAP_STATE select NEED_SG_DMA_LENGTH select HAVE_ARCH_KGDB
arch/parisc/include/asm/tlb.h +2 -2
@@ -5,8 +5,8 @@#include <asm-generic/tlb.h> #if CONFIG_PGTABLE_LEVELS ==3 -#define __pmd_free_tlb (tlb, pmd, addr) pmd_free((tlb)->mm, pmd) +#define __pmd_free_tlb (tlb, pmd, addr) tlb_remove_ptdesc((tlb), virt_to_ptdesc(pmd))#endif -#define __pte_free_tlb (tlb, pte, addr) pte_free((tlb)->mm, pte) +#define __pte_free_tlb (tlb, pte, addr) tlb_remove_ptdesc((tlb), page_ptdesc(pte))#endif
Signature · 1 line
2.20.1
Re: [PATCH v4 5/8] parisc: mm: enable MMU_GATHER_RCU_TABLE_FREE
Quoted 7 lines · Qi Zheng
From: Qi Zheng <[email protected]>
On a 64-bit system,
madvise(MADV_DONTNEED)may cause a large number of empty PTE page table pages (such as 100GB+). To resolve this problem, first enableMMU_GATHER_RCU_TABLE_FREEto prepare for enabling thePT_RECLAIMfeature, which resolves this problem.
Quoted 7 lines
Signed-off-by Qi Zheng <[email protected]>Cc "James E.J. Bottomley" <[email protected]>Cc Helge Deller <[email protected]>--- arch/parisc/Kconfig | 1 + arch/parisc/include/asm/tlb.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
Thanks!
Helge
PATCH v4 6/8 um: mm: enable MMU_GATHER_RCU_TABLE_FREE
In reply to Qi ZhengFrom: Qi Zheng <[email protected]>
On a 64-bit system, madvise(MADV_DONTNEED) may cause a large number of empty PTE page table pages (such as 100GB+). To resolve this problem, first enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.
--- arch/um/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/um/Kconfig +1 -0
@@ -42,6 +42,7 @@ config UML select HAVE_SYSCALL_TRACEPOINTS select THREAD_INFO_IN_TASK select SPARSE_IRQ + select MMU_GATHER_RCU_TABLE_FREE config MMU bool
Signature · 1 line
2.20.1
PATCH v4 7/8 mm: convert __HAVE_ARCH_TLB_REMOVE_TABLE to CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE config
In reply to Qi ZhengFrom: Qi Zheng <[email protected]>
For architectures that define __HAVE_ARCH_TLB_REMOVE_TABLE, the page tables at the pmd/pud level are generally not of struct ptdesc type, and do not have pt_rcu_head member, thus these architectures cannot support PT_RECLAIM.
In preparation for enabling PT_RECLAIM on more architectures, convert __HAVE_ARCH_TLB_REMOVE_TABLE to CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE config, so that we can make conditional judgments in Kconfig.
--- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/tlb.h | 1 - arch/sparc/Kconfig | 1 + arch/sparc/include/asm/tlb_64.h | 1 - include/asm-generic/tlb.h | 2 +- mm/Kconfig | 3 +++ 6 files changed, 6 insertions(+), 3 deletions(-)
arch/powerpc/Kconfig +1 -0
@@ -304,6 +304,7 @@ config PPC select LOCK_MM_AND_FIND_VMA select MMU_GATHER_PAGE_SIZE select MMU_GATHER_RCU_TABLE_FREE + select HAVE_ARCH_TLB_REMOVE_TABLE select MMU_GATHER_MERGE_VMAS select MMU_LAZY_TLB_SHOOTDOWN if PPC_BOOK3S_64 select MODULES_USE_ELF_RELA
arch/powerpc/include/asm/tlb.h +0 -1
@@ -37,7 +37,6 @@ extern void tlb_flush(struct mmu_gather *tlb);*/ #define tlb_needs_table_invalidate () radix_enabled() -#define __HAVE_ARCH_TLB_REMOVE_TABLE/* Get the generic bits... */ #include <asm-generic/tlb.h>
arch/sparc/Kconfig +1 -0
@@ -74,6 +74,7 @@ config SPARC64 select HAVE_KRETPROBES select HAVE_KPROBES select MMU_GATHER_RCU_TABLE_FREE if SMP + select HAVE_ARCH_TLB_REMOVE_TABLE if SMP select MMU_GATHER_MERGE_VMAS select MMU_GATHER_NO_FLUSH_CACHE select HAVE_ARCH_TRANSPARENT_HUGEPAGE
arch/sparc/include/asm/tlb_64.h +0 -1
@@ -33,7 +33,6 @@ void flush_tlb_pending(void);#define tlb_needs_table_invalidate () (false)#endif -#define __HAVE_ARCH_TLB_REMOVE_TABLE#include <asm-generic/tlb.h> #endif /* _SPARC64_TLB_H */
include/asm-generic/tlb.h +1 -1
@@ -213,7 +213,7 @@ struct mmu_table_batch {#define MAX_TABLE_BATCH \ ((PAGE_SIZE - sizeof(struct mmu_table_batch)) / sizeof(void *)) -#ifndef __HAVE_ARCH_TLB_REMOVE_TABLE +#ifndef CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE static inline void __tlb_remove_table (void *table) {struct ptdesc *ptdesc = (struct ptdesc *)table;
mm/Kconfig +3 -0
@@ -1451,6 +1451,9 @@ config ARCH_HAS_USER_SHADOW_STACK The architecture has hardware support for userspace shadow call stacks (eg, x86 CET, arm64 GCS or RISC-V Zicfiss). +config HAVE_ARCH_TLB_REMOVE_TABLE + def_bool n + config ARCH_SUPPORTS_PT_RECLAIM def_bool n
Signature · 1 line
2.20.1
David Hildenbrand (Arm)
maintainerRe: [PATCH v4 7/8] mm: convert __HAVE_ARCH_TLB_REMOVE_TABLE to CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE config
Quoted 50 lines · Qi Zheng
From: Qi Zheng <[email protected]>
For architectures that define
__HAVE_ARCH_TLB_REMOVE_TABLE, the page tables at the pmd/pud level are generally not of struct ptdesc type, and do not havept_rcu_headmember, thus these architectures cannot supportPT_RECLAIM.In preparation for enabling
PT_RECLAIMon more architectures, convert__HAVE_ARCH_TLB_REMOVE_TABLEtoCONFIG_HAVE_ARCH_TLB_REMOVE_TABLEconfig, so that we can make conditional judgments inKconfig.Signed-off-by Qi Zheng <[email protected]>--- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/tlb.h | 1 - arch/sparc/Kconfig | 1 + arch/sparc/include/asm/tlb_64.h | 1 - include/asm-generic/tlb.h | 2 +- mm/Kconfig | 3 +++ 6 files changed, 6 insertions(+), 3 deletions(-)arch/powerpc/Kconfig +1
-0@@ -304,6 +304,7 @@ config PPC select LOCK_MM_AND_FIND_VMA select MMU_GATHER_PAGE_SIZE select MMU_GATHER_RCU_TABLE_FREE + select HAVE_ARCH_TLB_REMOVE_TABLE select MMU_GATHER_MERGE_VMAS select MMU_LAZY_TLB_SHOOTDOWN if PPC_BOOK3S_64 select MODULES_USE_ELF_RELAarch/powerpc/include/asm/tlb.h +0
-1@@ -37,7 +37,6 @@ extern void tlb_flush(struct mmu_gather *tlb);*/ #define tlb_needs_table_invalidate () radix_enabled() -#define __HAVE_ARCH_TLB_REMOVE_TABLE/* Get the generic bits... */ #include <asm-generic/tlb.h> arch/sparc/Kconfig +0
-0
arch/sparc/Kconfig config SPARC64 · line 77
Quoted 4 lines
arch/sparc/Kconfig +1
-0@@ -74,6 +74,7 @@ config SPARC64 select HAVE_KRETPROBES select HAVE_KPROBES select MMU_GATHER_RCU_TABLE_FREE if SMP + select HAVE_ARCH_TLB_REMOVE_TABLE if SMP
Why the SMP? At least in tlb_64.h, it was not protected by SMP IIUC.
Apart from that LGTM.
Signature · 3 lines
Cheers, David
Re: [PATCH v4 7/8] mm: convert __HAVE_ARCH_TLB_REMOVE_TABLE to CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE config
Quoted 47 lines · David Hildenbrand (Arm)
Quoted 46 lines · Qi Zheng
From: Qi Zheng <[email protected]>
For architectures that define
__HAVE_ARCH_TLB_REMOVE_TABLE, the page tables at the pmd/pud level are generally not of struct ptdesc type, and do not havept_rcu_headmember, thus these architectures cannot supportPT_RECLAIM.In preparation for enabling
PT_RECLAIMon more architectures, convert__HAVE_ARCH_TLB_REMOVE_TABLEtoCONFIG_HAVE_ARCH_TLB_REMOVE_TABLEconfig, so that we can make conditional judgments inKconfig.Signed-off-by Qi Zheng <[email protected]>---
arch/powerpc/Kconfig | 1 +
arch/powerpc/include/asm/tlb.h | 1 -
arch/sparc/Kconfig | 1 +
arch/sparc/include/asm/tlb_64.h| 1 -
include/asm-generic/tlb.h | 2 +-
mm/Kconfig | 3 +++6 files changed, 6 insertions(+), 3 deletions(-)arch/powerpc/Kconfig +0
-0@@ -304,6 +304,7 @@ config PPCselect
LOCK_MM_AND_FIND_VMA
selectMMU_GATHER_PAGE_SIZE
selectMMU_GATHER_RCU_TABLE_FREE
+ selectHAVE_ARCH_TLB_REMOVE_TABLE
selectMMU_GATHER_MERGE_VMAS
select MMU_LAZY_TLB_SHOOTDOWN ifPPC_BOOK3S_64selectMODULES_USE_ELF_RELAarch/powerpc/include/asm/tlb.h +0
-1@@ -37,7 +37,6 @@ extern void tlb_flush(struct mmu_gather *tlb);*/ #define tlb_needs_table_invalidate() radix_enabled() -#define __HAVE_ARCH_TLB_REMOVE_TABLE /* Get the generic bits... */ #include <asm-generic/tlb.h>arch/sparc/Kconfig +0
-1--- a/arch/sparc/Kconfig
Quoted 8 lines
Quoted 6 lines
+++ b/arch/sparc/Kconfig
arch/sparc/Kconfig +0
-0@@ -74,6 +74,7 @@ config SPARC64select
HAVE_KRETPROBES
selectHAVE_KPROBES
selectMMU_GATHER_RCU_TABLE_FREEif SMP
+ selectHAVE_ARCH_TLB_REMOVE_TABLEif SMPWhy the SMP? At least in
tlb_64.h, it was not protected by SMP IIUC.
Ah, It's just simply aligned with the MMU_GATHER_RCU_TABLE_FREE above.
Quoted 2 lines
Apart from that LGTM.
Thanks!
Quoted 1 line
David Hildenbrand (Arm)
maintainerRe: [PATCH v4 7/8] mm: convert __HAVE_ARCH_TLB_REMOVE_TABLE to CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE config
Quoted 59 lines · Qi Zheng
Quoted 47 lines · David Hildenbrand (Arm)
Quoted 46 lines · Qi Zheng
From: Qi Zheng <[email protected]>
For architectures that define
__HAVE_ARCH_TLB_REMOVE_TABLE, the page tables at the pmd/pud level are generally not of struct ptdesc type, and do not havept_rcu_headmember, thus these architectures cannot supportPT_RECLAIM.In preparation for enabling
PT_RECLAIMon more architectures, convert__HAVE_ARCH_TLB_REMOVE_TABLEtoCONFIG_HAVE_ARCH_TLB_REMOVE_TABLEconfig, so that we can make conditional judgments inKconfig.Signed-off-by Qi Zheng <[email protected]>---
arch/powerpc/Kconfig | 1 +
arch/powerpc/include/asm/tlb.h | 1 -
arch/sparc/Kconfig | 1 +
arch/sparc/include/asm/tlb_64.h| 1 -
include/asm-generic/tlb.h | 2 +-
mm/Kconfig | 3 +++6 files changed, 6 insertions(+), 3 deletions(-)arch/powerpc/Kconfig +0
-0@@ -304,6 +304,7 @@ config PPCselect
LOCK_MM_AND_FIND_VMA
selectMMU_GATHER_PAGE_SIZE
selectMMU_GATHER_RCU_TABLE_FREE
+ selectHAVE_ARCH_TLB_REMOVE_TABLE
selectMMU_GATHER_MERGE_VMAS
select MMU_LAZY_TLB_SHOOTDOWN ifPPC_BOOK3S_64selectMODULES_USE_ELF_RELAarch/powerpc/include/asm/tlb.h +0
-1@@ -37,7 +37,6 @@ extern void tlb_flush(struct mmu_gather *tlb);*/ #define tlb_needs_table_invalidate() radix_enabled() -#define __HAVE_ARCH_TLB_REMOVE_TABLE /* Get the generic bits... */ #include <asm-generic/tlb.h>arch/sparc/Kconfig +0
-1--- a/arch/sparc/KconfigQuoted 8 lines
Quoted 6 lines
+++ b/arch/sparc/Kconfig
arch/sparc/Kconfig +0
-0@@ -74,6 +74,7 @@ config SPARC64select
HAVE_KRETPROBES
selectHAVE_KPROBES
selectMMU_GATHER_RCU_TABLE_FREEif SMP
+ selectHAVE_ARCH_TLB_REMOVE_TABLEif SMPWhy the SMP? At least in
tlb_64.h, it was not protected by SMP IIUC.
Quoted 1 line
Ah, It's just simply aligned with the
MMU_GATHER_RCU_TABLE_FREEabove.
But does that work as expected for !SMP?
Signature · 3 lines
Cheers, David
Re: [PATCH v4 7/8] mm: convert __HAVE_ARCH_TLB_REMOVE_TABLE to CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE config
Quoted 60 lines · David Hildenbrand (Arm)
Quoted 59 lines · Qi Zheng
Quoted 55 lines · David Hildenbrand (Arm)
Quoted 48 lines · Qi Zheng
From: Qi Zheng <[email protected]>
For architectures that define
__HAVE_ARCH_TLB_REMOVE_TABLE, the page tables at the pmd/pud level are generally not of struct ptdesc type, and do not havept_rcu_headmember, thus these architectures cannot supportPT_RECLAIM.In preparation for enabling
PT_RECLAIMon more architectures, convert__HAVE_ARCH_TLB_REMOVE_TABLEtoCONFIG_HAVE_ARCH_TLB_REMOVE_TABLEconfig, so that we can make conditional judgments inKconfig.Signed-off-by Qi Zheng <[email protected]>---
arch/powerpc/Kconfig | 1 +
arch/powerpc/include/asm/tlb.h | 1 -
arch/sparc/Kconfig | 1 +
arch/sparc/include/asm/tlb_64.h| 1 -
include/asm-generic/tlb.h | 2 +-
mm/Kconfig | 3 +++6 files changed, 6 insertions(+), 3 deletions(-)arch/powerpc/Kconfig +0
-0@@ -304,6 +304,7 @@ config PPCselect
LOCK_MM_AND_FIND_VMA
selectMMU_GATHER_PAGE_SIZE
selectMMU_GATHER_RCU_TABLE_FREE
+ selectHAVE_ARCH_TLB_REMOVE_TABLE
selectMMU_GATHER_MERGE_VMAS
select MMU_LAZY_TLB_SHOOTDOWN ifPPC_BOOK3S_64selectMODULES_USE_ELF_RELAarch/powerpc/include/asm/tlb.h +0
-1@@ -37,7 +37,6 @@ extern void tlb_flush(struct mmu_gather *tlb);*/ #define tlb_needs_table_invalidate() radix_enabled() -#define __HAVE_ARCH_TLB_REMOVE_TABLE /* Get the generic bits... */ #include <asm-generic/tlb.h>arch/sparc/Kconfig +0
-0@@ -74,6 +74,7 @@ config SPARC64Quoted 4 lines
select
HAVE_KRETPROBES
selectHAVE_KPROBES
selectMMU_GATHER_RCU_TABLE_FREEif SMP
+ selectHAVE_ARCH_TLB_REMOVE_TABLEif SMPWhy the SMP? At least in
tlb_64.h, it was not protected by SMP IIUC.
Quoted 3 lines
Quoted 1 line
Ah, It's just simply aligned with the
MMU_GATHER_RCU_TABLE_FREEabove.But does that work as expected for !SMP?
In the case of !SMP, tlb_remove_table() will not be called:
static inline void pgtable_free_tlb(struct mmu_gather *tlb, void *table, bool is_page)
{
pgtable_free(table, is_page);
}so I think it's okay to only select it in case of SMP.
Quoted 1 line
Re: [PATCH v4 7/8] mm: convert __HAVE_ARCH_TLB_REMOVE_TABLE to CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE config
Quoted 9 lines · Qi Zheng
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 4 lines · Qi Zheng
Ah, It's just simply aligned with the
MMU_GATHER_RCU_TABLE_FREEabove.
Quoted 8 lines
Quoted 1 line
But does that work as expected for !SMP?
In the case of !SMP,
tlb_remove_table()will not be called:static inline void
pgtable_free_tlb(struct mmu_gather *tlb, void *table, bool is_page){
pgtable_free(table,is_page);
}
Ah, okay. Confusing stuff. Would have been nice to document/mention that in the patch description.
So if it compiles, all good
Signature · 3 lines
Cheers, David
Re: [PATCH v4 7/8] mm: convert __HAVE_ARCH_TLB_REMOVE_TABLE to CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE config
Quoted 19 lines · David Hildenbrand (Arm)
Quoted 9 lines · Qi Zheng
Quoted 6 lines · David Hildenbrand (Arm)
Quoted 4 lines · Qi Zheng
Ah, It's just simply aligned with the
MMU_GATHER_RCU_TABLE_FREEabove.Quoted 8 lines
Quoted 1 line
But does that work as expected for !SMP?
In the case of !SMP,
tlb_remove_table()will not be called:static inline void
pgtable_free_tlb(struct mmu_gather *tlb, void *table, bool is_page){
pgtable_free(table,is_page);
}
Quoted 6 lines
Ah, okay. Confusing stuff. Would have been nice to document/mention that in the patch description.
So if it compiles, all good
It looks a bit weird, but it is actually more logically correct than before the patch. Before this in the !SMP sparc64 case __HAVE_ARCH_TLB_REMOVE_TABLE was defined even with no actual __tlb_remove_table() present. But it did not matter in practice. But I agree that a mention would not hurt.
Tested both with SMP and !SMP
Cheers,
Andreas
PATCH v4 8/8 mm: make PT_RECLAIM depends on MMU_GATHER_RCU_TABLE_FREE
In reply to Qi ZhengFrom: Qi Zheng <[email protected]>
The PT_RECLAIM can work on all architectures that support MMU_GATHER_RCU_TABLE_FREE, except for those that have selected HAVE_ARCH_TLB_REMOVE_TABLE,so make PT_RECLAIM depends on MMU_GATHER_RCU_TABLE_FREE && !HAVE_ARCH_TLB_REMOVE_TABLE.
BTW, change PT_RECLAIM to be enabled by default, since nobody should want to turn it off.
--- arch/x86/Kconfig | 1 - mm/Kconfig | 9 ++------- 2 files changed, 2 insertions(+), 8 deletions(-)
arch/x86/Kconfig +0 -1
@@ -331,7 +331,6 @@ config X86 select FUNCTION_ALIGNMENT_4B imply IMA_SECURE_AND_OR_TRUSTED_BOOT if EFI select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE - select ARCH_SUPPORTS_PT_RECLAIM if X86_64 select ARCH_SUPPORTS_SCHED_SMT if SMP select SCHED_SMT if SMP select ARCH_SUPPORTS_SCHED_CLUSTER if SMP
mm/Kconfig +2 -7
@@ -1454,14 +1454,9 @@ config ARCH_HAS_USER_SHADOW_STACK config HAVE_ARCH_TLB_REMOVE_TABLE def_bool n -config ARCH_SUPPORTS_PT_RECLAIM - def_bool n - config PT_RECLAIM - bool "reclaim empty user page table pages" - default y - depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP - select MMU_GATHER_RCU_TABLE_FREE + def_bool y + depends on MMU_GATHER_RCU_TABLE_FREE && !HAVE_ARCH_TLB_REMOVE_TABLE help Try to reclaim empty user page table pages in paths other than munmap and exit_mmap path.
Signature · 1 line
2.20.1
Andrew Morton
maintainerQuoted 1 line · On Tue, 27 Jan 2026 20:12:53 +0800 Qi Zheng <[email protected]> wrote:
This series aims to enable
PT_RECLAIMon more 64-bit architectures.
Thanks, I updated mm.git's mm-unstable branch to v4.
Quoted 7 lines
Changes in v4:
- convert__HAVE_ARCH_TLB_REMOVE_TABLEtoCONFIG_HAVE_ARCH_TLB_REMOVE_TABLEconfig
- fix aWARN_ON_ONCE()on sparc64 (and on ppc)
(reported by Andreas Larsson)
- collect Acked-by (Hi David, I've kept your Acked-by, feel free to drop it)
- rebase onto the v6.19-rc7
Below is how v4 altered mm.git.
I'm not seeing the WARN_ON_ONCE() fix. I assume that was due to the Kconfig alterations?
arch/powerpc/include/asm/tlb.h renamed from arch/powerpc/include/asm/tlb.h~b +0 -1
@@ -37,7 +37,6 @@ extern void tlb_flush(struct mmu_gather*/ #define tlb_needs_table_invalidate () radix_enabled() -#define __HAVE_ARCH_TLB_REMOVE_TABLE/* Get the generic bits... */ #include <asm-generic/tlb.h>
arch/powerpc/Kconfig renamed from arch/powerpc/Kconfig~b +1 -0
@@ -305,6 +305,7 @@ config PPC select LOCK_MM_AND_FIND_VMA select MMU_GATHER_PAGE_SIZE select MMU_GATHER_RCU_TABLE_FREE + select HAVE_ARCH_TLB_REMOVE_TABLE select MMU_GATHER_MERGE_VMAS select MMU_LAZY_TLB_SHOOTDOWN if PPC_BOOK3S_64 select MODULES_USE_ELF_RELA
arch/sparc/include/asm/tlb_64.h renamed from arch/sparc/include/asm/tlb_64.h~b +0 -1
@@ -33,7 +33,6 @@ void flush_tlb_pending(void);#define tlb_needs_table_invalidate () (false)#endif -#define __HAVE_ARCH_TLB_REMOVE_TABLE#include <asm-generic/tlb.h> #endif /* _SPARC64_TLB_H */
arch/sparc/Kconfig renamed from arch/sparc/Kconfig~b +1 -0
@@ -74,6 +74,7 @@ config SPARC64 select HAVE_KRETPROBES select HAVE_KPROBES select MMU_GATHER_RCU_TABLE_FREE if SMP + select HAVE_ARCH_TLB_REMOVE_TABLE if SMP select MMU_GATHER_MERGE_VMAS select MMU_GATHER_NO_FLUSH_CACHE select HAVE_ARCH_TRANSPARENT_HUGEPAGE
include/asm-generic/tlb.h renamed from include/asm-generic/tlb.h~b +1 -1
@@ -213,7 +213,7 @@ struct mmu_table_batch {#define MAX_TABLE_BATCH \ ((PAGE_SIZE - sizeof(struct mmu_table_batch)) / sizeof(void *)) -#ifndef __HAVE_ARCH_TLB_REMOVE_TABLE +#ifndef CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE static inline void __tlb_remove_table (void *table) {struct ptdesc *ptdesc = (struct ptdesc *)table;
mm/Kconfig renamed from mm/Kconfig~b +4 -1
@@ -1448,9 +1448,12 @@ config ARCH_HAS_USER_SHADOW_STACK The architecture has hardware support for userspace shadow call stacks (eg, x86 CET, arm64 GCS or RISC-V Zicfiss). +config HAVE_ARCH_TLB_REMOVE_TABLE + def_bool n + config PT_RECLAIM def_bool y - depends on MMU_GATHER_RCU_TABLE_FREE + depends on MMU_GATHER_RCU_TABLE_FREE && !HAVE_ARCH_TLB_REMOVE_TABLE help Try to reclaim empty user page table pages in paths other than munmap and exit_mmap path.
_
Quoted 14 lines · Andrew Morton
Quoted 1 line · On Tue, 27 Jan 2026 20:12:53 +0800 Qi Zheng <[email protected]> wrote:
This series aims to enable
PT_RECLAIMon more 64-bit architectures.Thanks, I updated mm.git's mm-unstable branch to v4.
Quoted 7 lines
Changes in v4:
- convert__HAVE_ARCH_TLB_REMOVE_TABLEtoCONFIG_HAVE_ARCH_TLB_REMOVE_TABLEconfig
- fix aWARN_ON_ONCE()on sparc64 (and on ppc)
(reported by Andreas Larsson)
- collect Acked-by (Hi David, I've kept your Acked-by, feel free to drop it)
- rebase onto the v6.19-rc7
Quoted 4 lines
Below is how v4 altered mm.git.
I'm not seeing the
WARN_ON_ONCE()fix. I assume that was due to theKconfigalterations?
Yes, sparc64 and ppc will select HAVE_ARCH_TLB_REMOVE_TABLE, so PT_RECLAIM will not be enabled. This means it won't affect sparc64 and ppc, and will not trigger WARN_ON_ONCE().
I don't have a testing environment for sparc64 and ppc, but I expect it should be able to fix the WARN_ON_ONCE().
Thanks,
Qi
Quoted 72 lines
arch/powerpc/include/asm/tlb.h renamed from arch/powerpc/include/asm/tlb.h~b +0
-1@@ -37,7 +37,6 @@ extern void tlb_flush(struct mmu_gather*/ #define tlb_needs_table_invalidate () radix_enabled() -#define __HAVE_ARCH_TLB_REMOVE_TABLE/* Get the generic bits... */ #include <asm-generic/tlb.h> arch/powerpc/Kconfig renamed from arch/powerpc/Kconfig~b +1
-0@@ -305,6 +305,7 @@ config PPC select LOCK_MM_AND_FIND_VMA select MMU_GATHER_PAGE_SIZE select MMU_GATHER_RCU_TABLE_FREE + select HAVE_ARCH_TLB_REMOVE_TABLE select MMU_GATHER_MERGE_VMAS select MMU_LAZY_TLB_SHOOTDOWN if PPC_BOOK3S_64 select MODULES_USE_ELF_RELAarch/sparc/include/asm/tlb_64.h renamed from arch/sparc/include/asm/tlb_64.h~b +0
-1@@ -33,7 +33,6 @@ void flush_tlb_pending(void);#define tlb_needs_table_invalidate () (false)#endif -#define __HAVE_ARCH_TLB_REMOVE_TABLE#include <asm-generic/tlb.h> #endif /* _SPARC64_TLB_H */ arch/sparc/Kconfig renamed from arch/sparc/Kconfig~b +1
-0@@ -74,6 +74,7 @@ config SPARC64 select HAVE_KRETPROBES select HAVE_KPROBES select MMU_GATHER_RCU_TABLE_FREE if SMP + select HAVE_ARCH_TLB_REMOVE_TABLE if SMP select MMU_GATHER_MERGE_VMAS select MMU_GATHER_NO_FLUSH_CACHE select HAVE_ARCH_TRANSPARENT_HUGEPAGEinclude/asm-generic/tlb.h renamed from include/asm-generic/tlb.h~b +1
-1@@ -213,7 +213,7 @@ struct mmu_table_batch {#define MAX_TABLE_BATCH \ ((PAGE_SIZE - sizeof(struct mmu_table_batch)) / sizeof(void *)) -#ifndef __HAVE_ARCH_TLB_REMOVE_TABLE +#ifndef CONFIG_HAVE_ARCH_TLB_REMOVE_TABLE static inline void __tlb_remove_table (void *table) {struct ptdesc *ptdesc = (struct ptdesc *)table;mm/Kconfig renamed from mm/Kconfig~b +4
-1@@ -1448,9 +1448,12 @@ config ARCH_HAS_USER_SHADOW_STACK The architecture has hardware support for userspace shadow call stacks (eg, x86 CET, arm64 GCS or RISC-V Zicfiss). +config HAVE_ARCH_TLB_REMOVE_TABLE + def_bool n + config PT_RECLAIM def_bool y - depends on MMU_GATHER_RCU_TABLE_FREE + depends on MMU_GATHER_RCU_TABLE_FREE && !HAVE_ARCH_TLB_REMOVE_TABLE help Try to reclaim empty user page table pages in paths other than munmap and exit_mmap path._