Skip to contentSkip to conversation

enable PT_RECLAIM on all 64-bit architectures

PATCH Superseded Qi Zheng 7 participants 30 messages Nov 14, 2025 – Nov 19, 2025

Subsystems (11)
Memory management x86 MIPS MM core +7 more subsystems

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Qi Zheng

author
#0 lore raw

cover enable PT_RECLAIM on all 64-bit architectures

From: Qi Zheng <[email protected]>

Hi all,

This series aims to enable PT_RECLAIM on all 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.

Therefore, this series first enables MMU_GATHER_RCU_TABLE_FREE on all 64-bit architectures, and finally makes PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT. This way, PT_RECLAIM can be enabled by default on all 64-bit architectures.

Comments and suggestions are welcome!

Thanks,
Qi

Qi Zheng (7):
alpha: mm: enable MMU_GATHER_RCU_TABLE_FREE
arc: 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: make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT

 arch/alpha/Kconfig                   | 1 +
 arch/alpha/include/asm/tlb.h         | 8 +++++---
 arch/arc/Kconfig                     | 1 +
 arch/arc/include/asm/pgalloc.h       | 9 ++++++---
 arch/loongarch/Kconfig               | 1 +
 arch/loongarch/include/asm/pgalloc.h | 6 ++++--
 arch/mips/Kconfig                    | 1 +
 arch/mips/include/asm/pgalloc.h      | 6 ++++--
 arch/parisc/Kconfig                  | 1 +
 arch/parisc/include/asm/tlb.h        | 6 ++++--
 arch/um/Kconfig                      | 1 +
 arch/x86/Kconfig                     | 1 -
 mm/Kconfig                           | 6 +-----
 13 files changed, 30 insertions(+), 18 deletions(-)
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH 1/7 alpha: mm: enable MMU_GATHER_RCU_TABLE_FREE

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 enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.

Cc Richard Henderson <[email protected]>
Cc Matt Turner <[email protected]>
---
 arch/alpha/Kconfig           | 1 +
 arch/alpha/include/asm/tlb.h | 8 +++++---
 2 files changed, 6 insertions(+), 3 deletions(-)
arch/alpha/Kconfig +1 -0
index 80367f2cf821c..681ed894d9e72 100644
@@ -40,6 +40,7 @@ config ALPHA
 	select MMU_GATHER_NO_RANGE
 	select SPARSEMEM_EXTREME if SPARSEMEM
 	select ZONE_DMA
+	select MMU_GATHER_RCU_TABLE_FREE
 	help
 	  The Alpha is a 64-bit general-purpose processor designed and
 	  marketed by the Digital Equipment Corporation of blessed memory,
arch/alpha/include/asm/tlb.h +5 -3
index 4f79e331af5ea..4fe5a901720f0 100644
@@ -4,7 +4,9 @@
 
 #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
author
#4 lore raw

PATCH 2/7 arc: mm: enable MMU_GATHER_RCU_TABLE_FREE

In reply to 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 enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.

Cc Vineet Gupta <[email protected]>
---
 arch/arc/Kconfig               | 1 +
 arch/arc/include/asm/pgalloc.h | 9 ++++++---
 2 files changed, 7 insertions(+), 3 deletions(-)
arch/arc/Kconfig +1 -0
index f27e6b90428e4..47db93952386d 100644
@@ -54,6 +54,7 @@ config ARC
 	select HAVE_ARCH_JUMP_LABEL if ISA_ARCV2 && !CPU_ENDIAN_BE32
 	select TRACE_IRQFLAGS_SUPPORT
 	select HAVE_EBPF_JIT if ISA_ARCV2
+	select MMU_GATHER_RCU_TABLE_FREE
 
 config LOCKDEP_SUPPORT
 	def_bool y
arch/arc/include/asm/pgalloc.h +6 -3
index dfae070fe8d55..b1c6619435613 100644
@@ -72,7 +72,8 @@ static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4dp, pud_t *pudp)
 	set_p4d(p4dp, __p4d((unsigned long)pudp));
 }
 
-#define __pud_free_tlb(tlb, pmd, addr)  pud_free((tlb)->mm, pmd)
+#define __pud_free_tlb(tlb, pud, addr)	\
+	tlb_remove_ptdesc((tlb), virt_to_ptdesc(pud))
 
 #endif
 
@@ -83,10 +84,12 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmdp)
 	set_pud(pudp, __pud((unsigned long)pmdp));
 }
 
-#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 /* _ASM_ARC_PGALLOC_H */
Signature · 1 line
2.20.1
author
#8 lore raw

PATCH 3/7 loongarch: mm: enable MMU_GATHER_RCU_TABLE_FREE

In reply to 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 enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.

Cc Huacai Chen <[email protected]>
Cc WANG Xuerui <[email protected]>
---
 arch/loongarch/Kconfig               | 1 +
 arch/loongarch/include/asm/pgalloc.h | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
arch/loongarch/Kconfig +1 -0
index 5b1116733d881..3bf2f2a9cd647 100644
@@ -210,6 +210,7 @@ config LOONGARCH
 	select USER_STACKTRACE_SUPPORT
 	select VDSO_GETRANDOM
 	select ZONE_DMA32
+	select MMU_GATHER_RCU_TABLE_FREE
 
 config 32BIT
 	bool
arch/loongarch/include/asm/pgalloc.h +4 -2
index 1c63a9d9a6d35..0539d04bf1525 100644
@@ -79,7 +79,8 @@ 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 +100,8 @@ 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
author
#13 lore raw

PATCH 4/7 mips: mm: enable MMU_GATHER_RCU_TABLE_FREE

In reply to 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 enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.

Cc Thomas Bogendoerfer <[email protected]>
---
 arch/mips/Kconfig               | 1 +
 arch/mips/include/asm/pgalloc.h | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
arch/mips/Kconfig +1 -0
index e8683f58fd3e2..0ee8820a354c4 100644
@@ -108,6 +108,7 @@ config MIPS
 	select TRACE_IRQFLAGS_SUPPORT
 	select ARCH_HAS_ELFCORE_COMPAT
 	select HAVE_ARCH_KCSAN if 64BIT
+	select MMU_GATHER_RCU_TABLE_FREE
 
 config MIPS_FIXUP_BIGPHYS_ADDR
 	bool
arch/mips/include/asm/pgalloc.h +4 -2
index 942af87f1cddb..c00f445045f43 100644
@@ -72,7 +72,8 @@ 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
 
@@ -98,7 +99,8 @@ 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
author
#14 lore raw

PATCH 5/7 parisc: mm: enable MMU_GATHER_RCU_TABLE_FREE

In reply to 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 enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.

Cc "James E.J. Bottomley" <[email protected]>
Cc Helge Deller <[email protected]>
---
 arch/parisc/Kconfig           | 1 +
 arch/parisc/include/asm/tlb.h | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
arch/parisc/Kconfig +1 -0
index 47fd9662d8005..946cbe21a4118 100644
@@ -92,6 +92,7 @@ config PARISC
 	select TRACE_IRQFLAGS_SUPPORT
 	select HAVE_FUNCTION_DESCRIPTORS if 64BIT
 	select PCI_MSI_ARCH_FALLBACKS if PCI_MSI
+	select MMU_GATHER_RCU_TABLE_FREE
 
 	help
 	  The PA-RISC microprocessor is designed by Hewlett-Packard and used
arch/parisc/include/asm/tlb.h +4 -2
index 44235f367674d..ab7d4113df61a 100644
@@ -5,8 +5,10 @@
 #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
author
#15 lore raw

PATCH 6/7 um: mm: enable MMU_GATHER_RCU_TABLE_FREE

In reply to 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 enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.

Cc Richard Weinberger <[email protected]>
Cc Anton Ivanov <[email protected]>
Cc Johannes Berg <[email protected]>
---
 arch/um/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/um/Kconfig +1 -0
index 097c6a6265ef3..47a41bc77bb24 100644
@@ -41,6 +41,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
author
#16 lore raw

PATCH 7/7 mm: make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT

In reply to Qi Zheng

From: Qi Zheng <[email protected]>

Make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE so that PT_RECLAIM can be enabled by default on all architectures that support MMU_GATHER_RCU_TABLE_FREE.

Considering that a large number of PTE page table pages (such as 100GB+) can only be caused on a 64-bit system, let PT_RECLAIM also depend on 64BIT.

---
 arch/x86/Kconfig | 1 -
 mm/Kconfig       | 6 +-----
 2 files changed, 1 insertion(+), 6 deletions(-)
arch/x86/Kconfig +0 -1
index eac2e86056902..96bff81fd4787 100644
@@ -330,7 +330,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 +1 -5
index a5a90b169435d..e795fbd69e50c 100644
@@ -1440,14 +1440,10 @@ 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 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
+	depends on MMU_GATHER_RCU_TABLE_FREE && MMU && SMP && 64BIT
 	help
 	  Try to reclaim empty user page table pages in paths other than munmap
 	  and exit_mmap path.
Signature · 1 line
2.20.1
author
#5 lore raw

Re: [PATCH 2/7] arc: mm: enable MMU_GATHER_RCU_TABLE_FREE

In reply to Qi Zheng
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 enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.

Quoted 6 lines
Cc Vineet Gupta <[email protected]>
---
  arch/arc/Kconfig               | 1 +
  arch/arc/include/asm/pgalloc.h | 9 ++++++---
  2 files changed, 7 insertions(+), 3 deletions(-)

Strangely, it seems that only ARC does not define CONFIG_64BIT?

Does the ARC architecture support 64-bit? Did I miss something?

Quoted 42 lines
arch/arc/Kconfig +1 -0
index f27e6b90428e4..47db93952386d 100644
@@ -54,6 +54,7 @@ config ARC
  	select HAVE_ARCH_JUMP_LABEL if ISA_ARCV2 && !CPU_ENDIAN_BE32
  	select TRACE_IRQFLAGS_SUPPORT
  	select HAVE_EBPF_JIT if ISA_ARCV2
+	select MMU_GATHER_RCU_TABLE_FREE
 
  config LOCKDEP_SUPPORT
  	def_bool y
arch/arc/include/asm/pgalloc.h +6 -3
index dfae070fe8d55..b1c6619435613 100644
@@ -72,7 +72,8 @@ static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4dp, pud_t *pudp)
  	set_p4d(p4dp, __p4d((unsigned long)pudp));
  }
 
-#define __pud_free_tlb(tlb, pmd, addr)  pud_free((tlb)->mm, pmd)
+#define __pud_free_tlb(tlb, pud, addr)	\
+	tlb_remove_ptdesc((tlb), virt_to_ptdesc(pud))
 
  #endif
 
@@ -83,10 +84,12 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmdp)
  	set_pud(pudp, __pud((unsigned long)pmdp));
  }
 
-#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 /* _ASM_ARC_PGALLOC_H */
maintainer
#9 lore raw

Re: [PATCH 3/7] loongarch: mm: enable MMU_GATHER_RCU_TABLE_FREE

In reply to Qi Zheng

Hi, Qi Zheng,

We usually use LoongArch rather than loongarch, but if you want to keep consistency for all patches, just do it.

Quoted 21 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 enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.

Cc Huacai Chen <[email protected]>
Cc WANG Xuerui <[email protected]>
---
 arch/loongarch/Kconfig               | 1 +
 arch/loongarch/include/asm/pgalloc.h | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
arch/loongarch/Kconfig +0 -0
index 5b1116733d881..3bf2f2a9cd647 100644

arch/loongarch/Kconfig config LOONGARCH · line 213

Quoted 4 lines
arch/loongarch/Kconfig +1 -0
@@ -210,6 +210,7 @@ config LOONGARCH
        select USER_STACKTRACE_SUPPORT
        select VDSO_GETRANDOM
        select ZONE_DMA32
+       select MMU_GATHER_RCU_TABLE_FREE

Please use alpha-betical order.

Quoted 8 lines
arch/loongarch/Kconfig +0 -0
 config 32BIT
        bool
arch/loongarch/include/asm/pgalloc.h +0 -0
index 1c63a9d9a6d35..0539d04bf1525 100644

arch/loongarch/include/asm/pgalloc.h static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address) · line 83

Quoted 6 lines
arch/loongarch/include/asm/pgalloc.h +2 -1
@@ -79,7 +79,8 @@ 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))

I think we can define it in one line.

arch/loongarch/include/asm/pgalloc.h static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address) · line 104

Quoted 10 lines
arch/loongarch/include/asm/pgalloc.h +2 -1
 #endif
 
@@ -99,7 +100,8 @@ 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))

The same.

Other patches have the same problem.

Huacai

Quoted 6 lines
arch/loongarch/include/asm/pgalloc.h +0 -1
 #endif /* __PAGETABLE_PUD_FOLDED */
 
--

2.20.1

author
#10 lore raw

Re: [PATCH 3/7] loongarch: mm: enable MMU_GATHER_RCU_TABLE_FREE

Hi Huacai,

Quoted 4 lines · Huacai Chen

Hi, Qi Zheng,

We usually use LoongArch rather than loongarch, but if you want to keep consistency for all patches, just do it.

OK, will change to use LoongArch.

Quoted 18 lines · Qi Zheng
Quoted 16 lines

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 enable MMU_GATHER_RCU_TABLE_FREE to prepare for enabling the PT_RECLAIM feature, which resolves this problem.

Cc Huacai Chen <[email protected]>
Cc WANG Xuerui <[email protected]>
---
  arch/loongarch/Kconfig               | 1 +
  arch/loongarch/include/asm/pgalloc.h | 6 ++++--
  2 files changed, 5 insertions(+), 2 deletions(-)
Quoted 10 lines

arch/loongarch/Kconfig config LOONGARCH · line 213

Quoted 9 lines
arch/loongarch/Kconfig +1 -0
index 5b1116733d881..3bf2f2a9cd647 100644
@@ -210,6 +210,7 @@ config LOONGARCH
         select USER_STACKTRACE_SUPPORT
         select VDSO_GETRANDOM
         select ZONE_DMA32
+       select MMU_GATHER_RCU_TABLE_FREE

Please use alpha-betical order.

OK, will do.

Quoted 12 lines
Quoted 12 lines
arch/loongarch/Kconfig +0 -0
  config 32BIT
         bool
arch/loongarch/include/asm/pgalloc.h +0 -0
index 1c63a9d9a6d35..0539d04bf1525 100644
@@ -79,7 +79,8 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
         return pmd;
  }
 
Quoted 4 lines

arch/loongarch/include/asm/pgalloc.h static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address) · line 83

Quoted 3 lines
arch/loongarch/include/asm/pgalloc.h +2 -1
-#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))

I think we can define it in one line.

will do.

Quoted 8 lines
Quoted 8 lines
arch/loongarch/include/asm/pgalloc.h +0 -0
  #endif
 
@@ -99,7 +100,8 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
         return pud;
  }
 
Quoted 6 lines

arch/loongarch/include/asm/pgalloc.h static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address) · line 104

Quoted 3 lines
arch/loongarch/include/asm/pgalloc.h +2 -1
-#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))

The same.

Other patches have the same problem.

Got it, will convert them all to the one-line type.

Thanks,
Qi

Quoted 9 lines

Huacai

Quoted 6 lines
arch/loongarch/include/asm/pgalloc.h +0 -1
  #endif /* __PAGETABLE_PUD_FOLDED */
 
--

2.20.1

maintainer
#2 lore raw

Re: [PATCH 1/7] alpha: mm: enable MMU_GATHER_RCU_TABLE_FREE

In reply to Qi Zheng

Hi,

I applied your patches to a fresh pull of torvalds/linux.git repo but was unable to build the kernel (on Alpha) with this patch applied.

I made the following changes in order to get it to build on Alpha:

mm/pt_reclaim.c +1 -1
index 7e9455a18aae..6761b0c282bf 100644
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/hugetlb.h>
-#include <asm-generic/tlb.h>
 #include <asm/pgalloc.h>
+#include <asm/tlb.h>
 
 #include "internal.h"
 

/Magnus

maintainer
#6 lore raw

Re: [PATCH 2/7] arc: mm: enable MMU_GATHER_RCU_TABLE_FREE

In reply to Qi Zheng
Quoted 3 lines · Qi Zheng

Strangely, it seems that only ARC does not define CONFIG_64BIT?

Does the ARC architecture support 64-bit? Did I miss something?

ARC is 32-bit only !

-Vineet

#17 lore raw

Re: [PATCH 7/7] mm: make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT

In reply to Qi Zheng
kernel test robot noticed the following build errors:

Hi Qi,

kernel test robot noticed the following build errors:

[auto build test ERROR on deller-parisc/for-next]
[also build test ERROR on uml/next tip/x86/core akpm-mm/mm-everything linus/master v6.18-rc5 next-20251114] [cannot apply to uml/fixes vgupta-arc/for-next vgupta-arc/for-curr]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Qi-Zheng/alpha-mm-enable-MMU_GATHER_RCU_TABLE_FREE/20251114-191543
base:   https://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git for-next
patch link:    https://lore.kernel.org/r/0a4d1e6f0bf299cafd1fc624f965bd1ca542cea8.1763117269.git.zhengqi.arch%40bytedance.com
patch subject: [PATCH 7/7] mm: make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT
config: arm64-randconfig-004-20251115 (https://download.01.org/0day-ci/archive/20251115/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251115/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from mm/pt_reclaim.c:3:
mm/pt_reclaim.c: In function 'free_pte':

>> include/asm-generic/tlb.h:731:3: error: implicit declaration of function '__pte_free_tlb'; did you mean 'pte_free_tlb'? [-Werror=implicit-function-declaration]
      __pte_free_tlb(tlb, ptep, address);  \
      ^~~~~~~~~~~~~~
   mm/pt_reclaim.c:31:2: note: in expansion of macro 'pte_free_tlb'
     pte_free_tlb(tlb, pmd_pgtable(pmdval), addr);
     ^~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +731 include/asm-generic/tlb.h

a00cc7d9dd93d6 Matthew Wilcox         2017-02-24  701  
a00cc7d9dd93d6 Matthew Wilcox         2017-02-24  702  #define tlb_remove_pud_tlb_entry(tlb, pudp, address)			\
a00cc7d9dd93d6 Matthew Wilcox         2017-02-24  703  	do {								\
2631ed00b04988 Peter Zijlstra (Intel  2020-06-25  704) 		tlb_flush_pud_range(tlb, address, HPAGE_PUD_SIZE);	\
a00cc7d9dd93d6 Matthew Wilcox         2017-02-24  705  		__tlb_remove_pud_tlb_entry(tlb, pudp, address);		\
a00cc7d9dd93d6 Matthew Wilcox         2017-02-24  706  	} while (0)
a00cc7d9dd93d6 Matthew Wilcox         2017-02-24  707  
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  708  /*
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  709   * For things like page tables caches (ie caching addresses "inside" the
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  710   * page tables, like x86 does), for legacy reasons, flushing an
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  711   * individual page had better flush the page table caches behind it. This
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  712   * is definitely how x86 works, for example. And if you have an
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  713   * architected non-legacy page table cache (which I'm not aware of
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  714   * anybody actually doing), you're going to have some architecturally
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  715   * explicit flushing for that, likely *separate* from a regular TLB entry
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  716   * flush, and thus you'd need more than just some range expansion..
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  717   *
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  718   * So if we ever find an architecture
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  719   * that would want something that odd, I think it is up to that
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  720   * architecture to do its own odd thing, not cause pain for others
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  721   * http://lkml.kernel.org/r/CA+55aFzBggoXtNXQeng5d_mRoDnaMBE5Y+URs+PHR67nUpMtaw@mail.gmail.com
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  722   *
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  723   * For now w.r.t page table cache, mark the range_size as PAGE_SIZE
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  724   */
b5bc66b7131087 Aneesh Kumar K.V       2016-12-12  725  
a90744bac57c3c Nicholas Piggin        2018-07-13  726  #ifndef pte_free_tlb
9e1b32caa525cb Benjamin Herrenschmidt 2009-07-22  727  #define pte_free_tlb(tlb, ptep, address)			\
^1da177e4c3f41 Linus Torvalds         2005-04-16  728  	do {							\
2631ed00b04988 Peter Zijlstra (Intel  2020-06-25  729) 		tlb_flush_pmd_range(tlb, address, PAGE_SIZE);	\
22a61c3c4f1379 Peter Zijlstra         2018-08-23  730  		tlb->freed_tables = 1;				\
9e1b32caa525cb Benjamin Herrenschmidt 2009-07-22 @731  		__pte_free_tlb(tlb, ptep, address);		\
^1da177e4c3f41 Linus Torvalds         2005-04-16  732  	} while (0)
a90744bac57c3c Nicholas Piggin        2018-07-13  733  #endif

^1da177e4c3f41 Linus Torvalds 2005-04-16 734

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#18 lore raw

Re: [PATCH 7/7] mm: make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT

In reply to Qi Zheng
kernel test robot noticed the following build errors:

Hi Qi,

kernel test robot noticed the following build errors:

[auto build test ERROR on deller-parisc/for-next]
[also build test ERROR on uml/next tip/x86/core akpm-mm/mm-everything linus/master v6.18-rc5 next-20251114] [cannot apply to uml/fixes vgupta-arc/for-next vgupta-arc/for-curr]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Qi-Zheng/alpha-mm-enable-MMU_GATHER_RCU_TABLE_FREE/20251114-191543
base:   https://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git for-next
patch link:    https://lore.kernel.org/r/0a4d1e6f0bf299cafd1fc624f965bd1ca542cea8.1763117269.git.zhengqi.arch%40bytedance.com
patch subject: [PATCH 7/7] mm: make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT
config: arm64-randconfig-002-20251115 (https://download.01.org/0day-ci/archive/20251115/[email protected]/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251115/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> mm/pt_reclaim.c:31:2: error: call to undeclared function '__pte_free_tlb'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      31 |         pte_free_tlb(tlb, pmd_pgtable(pmdval), addr);
         |         ^
   include/asm-generic/tlb.h:731:3: note: expanded from macro 'pte_free_tlb'
     731 |                 __pte_free_tlb(tlb, ptep, address);             \
         |                 ^

1 error generated.

vim +/__pte_free_tlb +31 mm/pt_reclaim.c

6375e95f381e3d Qi Zheng 2024-12-04  27  
6375e95f381e3d Qi Zheng 2024-12-04  28  void free_pte(struct mm_struct *mm, unsigned long addr, struct mmu_gather *tlb,
6375e95f381e3d Qi Zheng 2024-12-04  29  	      pmd_t pmdval)
6375e95f381e3d Qi Zheng 2024-12-04  30  {
6375e95f381e3d Qi Zheng 2024-12-04 @31  	pte_free_tlb(tlb, pmd_pgtable(pmdval), addr);
6375e95f381e3d Qi Zheng 2024-12-04  32  	mm_dec_nr_ptes(mm);
6375e95f381e3d Qi Zheng 2024-12-04  33  }

6375e95f381e3d Qi Zheng 2024-12-04 34

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#3 lore raw

Re: [PATCH 1/7] alpha: mm: enable MMU_GATHER_RCU_TABLE_FREE

In reply to Magnus Lindholm

Hi Magnus,

Quoted 6 lines · Magnus Lindholm

Hi,

I applied your patches to a fresh pull of torvalds/linux.git repo but was unable to build the kernel (on Alpha) with this patch applied.

I made the following changes in order to get it to build on Alpha:

Thanks! Will fix it in the next version.

Quoted 16 lines
mm/pt_reclaim.c +1 -1
index 7e9455a18aae..6761b0c282bf 100644
@@ -1,7 +1,7 @@
  // SPDX-License-Identifier: GPL-2.0
  #include <linux/hugetlb.h>
-#include <asm-generic/tlb.h>
  #include <asm/pgalloc.h>
+#include <asm/tlb.h>
 
  #include "internal.h"
 

/Magnus

author
#7 lore raw

Re: [PATCH 2/7] arc: mm: enable MMU_GATHER_RCU_TABLE_FREE

In reply to Vineet Gupta
Quoted 6 lines · Vineet Gupta
Quoted 3 lines · Qi Zheng

Strangely, it seems that only ARC does not define CONFIG_64BIT?

Does the ARC architecture support 64-bit? Did I miss something?

ARC is 32-bit only !

Got it! Will drop this patch in the next version.

Thanks!

Quoted 2 lines

-Vineet

author
#11 lore raw

Re: [PATCH 3/7] loongarch: mm: enable MMU_GATHER_RCU_TABLE_FREE

In reply to Huacai Chen

Hi Huacai,

Quoted 1 line · Huacai Chen

Hi, Qi Zheng,

[...]

Quoted 5 lines

arch/loongarch/include/asm/pgalloc.h static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address) · line 83

Quoted 4 lines
arch/loongarch/include/asm/pgalloc.h +2 -1
-#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))

I think we can define it in one line.

Do we need to change __pte_free_tlb() to a single-line format as well?

Thanks,
Qi

Quoted 1 line
Quoted 1 line
maintainer
#12 lore raw

Re: [PATCH 3/7] loongarch: mm: enable MMU_GATHER_RCU_TABLE_FREE

Quoted 9 lines · Qi Zheng

Hi Huacai,

Quoted 1 line · Huacai Chen

Hi, Qi Zheng,

[...]

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 4 lines

arch/loongarch/include/asm/pgalloc.h static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address) · line 83

Quoted 3 lines
arch/loongarch/include/asm/pgalloc.h +2 -1
-#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))

I think we can define it in one line.

Do we need to change __pte_free_tlb() to a single-line format as well?

Yes, there is no 80 columns limit now.

Huacai

Quoted 8 lines

Thanks,
Qi

Quoted 1 line
Quoted 1 line
#26 lore raw
In reply to Qi Zheng
Quoted 10 lines · Qi Zheng

From: Qi Zheng <[email protected]>

Hi all,

This series aims to enable PT_RECLAIM on all 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.

Makes sense!

Quoted 4 lines

Therefore, this series first enables MMU_GATHER_RCU_TABLE_FREE on all 64-bit architectures, and finally makes PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT. This way, PT_RECLAIM can be enabled by default on all 64-bit architectures.

Could we then even go ahead and stop making PT_RECLAIM user-selectable?

Signature · 3 lines
Cheers

David
#19 lore raw

Re: [PATCH 7/7] mm: make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT

In reply to Qi Zheng
Quoted 1 line · Qi Zheng

From: Qi Zheng <[email protected]>

Subject: s/&&/&/

Quoted 34 lines

Make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE so that PT_RECLAIM can be enabled by default on all architectures that support MMU_GATHER_RCU_TABLE_FREE.

Considering that a large number of PTE page table pages (such as 100GB+) can only be caused on a 64-bit system, let PT_RECLAIM also depend on 64BIT.

---
  arch/x86/Kconfig | 1 -
  mm/Kconfig       | 6 +-----
  2 files changed, 1 insertion(+), 6 deletions(-)
arch/x86/Kconfig +0 -1
index eac2e86056902..96bff81fd4787 100644
@@ -330,7 +330,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 +0 -0
index a5a90b169435d..e795fbd69e50c 100644
@@ -1440,14 +1440,10 @@ 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).

mm/Kconfig config ARCH_HAS_USER_SHADOW_STACK · line 1446

Quoted 10 lines
mm/Kconfig +1 -5
 
-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
+	depends on MMU_GATHER_RCU_TABLE_FREE && MMU && SMP && 64BIT

Who would we have MMU_GATHER_RCU_TABLE_FREE without MMU? (can we drop the MMU part)

Why do we care about SMP in the first place? (can we frop SMP)

But I also wonder why we need "MMU_GATHER_RCU_TABLE_FREE && 64BIT":

Would it be harmful on 32bit (sure, we might not reclaim as much, but still there is memory to be reclaimed?)?

If all 64BIT support MMU_GATHER_RCU_TABLE_FREE (as you previously state), why can't we only check for 64BIT?

Signature · 3 lines
Cheers

David
#27 lore raw
In reply to David Hildenbrand (Red Hat)
Quoted 12 lines · David Hildenbrand (Red Hat)
Quoted 10 lines · Qi Zheng

From: Qi Zheng <[email protected]>

Hi all,

This series aims to enable PT_RECLAIM on all 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.

Quoted 8 lines

Makes sense!

Quoted 4 lines

Therefore, this series first enables MMU_GATHER_RCU_TABLE_FREE on all 64-bit architectures, and finally makes PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT. This way, PT_RECLAIM can be enabled by default on all 64-bit architectures.

Could we then even go ahead and stop making PT_RECLAIM user-selectable?

OK, will change to:

config PT_RECLAIM

	def_bool y
	depends on MMU_GATHER_RCU_TABLE_FREE && MMU && SMP && 64BIT
Quoted 1 line
author
#20 lore raw

Re: [PATCH 7/7] mm: make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT

In reply to David Hildenbrand (Red Hat)
Quoted 4 lines · David Hildenbrand (Red Hat)
Quoted 1 line · Qi Zheng

From: Qi Zheng <[email protected]>

Subject: s/&&/&/

will do.

Quoted 38 lines
Quoted 38 lines

Make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE so that PT_RECLAIM can be enabled by default on all architectures that support MMU_GATHER_RCU_TABLE_FREE.

Considering that a large number of PTE page table pages (such as 100GB+) can only be caused on a 64-bit system, let PT_RECLAIM also depend on 64BIT.

---
  arch/x86/Kconfig | 1 -
  mm/Kconfig       | 6 +-----

  2 files changed, 1 insertion(+), 6 deletions(-)
arch/x86/Kconfig +0 -0
index eac2e86056902..96bff81fd4787 100644
@@ -330,7 +330,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 +0 -0
index a5a90b169435d..e795fbd69e50c 100644
@@ -1440,14 +1440,10 @@ 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).

mm/Kconfig +0 -3
-config ARCH_SUPPORTS_PT_RECLAIM
-    def_bool n
-
Quoted 8 lines
Quoted 6 lines

  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
+    depends on MMU_GATHER_RCU_TABLE_FREE && MMU && SMP && 64BIT

Who would we have MMU_GATHER_RCU_TABLE_FREE without MMU? (can we drop the MMU part)

OK.

Quoted 2 lines

Why do we care about SMP in the first place? (can we frop SMP)

OK.

Quoted 4 lines

But I also wonder why we need "MMU_GATHER_RCU_TABLE_FREE && 64BIT":

Would it be harmful on 32bit (sure, we might not reclaim as much, but still there is memory to be reclaimed?)?

This is also fine on 32bit, but the benefits are not significant, So I chose to enable it only on 64-bit.

I actually tried enabling MMU_GATHER_RCU_TABLE_FREE on all architectures, and apart from sparc32 being a bit troublesome (because it uses mm->page_table_lock for synchronization within __pte_free_tlb()), the modifications were relatively simple.

Quoted 2 lines

If all 64BIT support MMU_GATHER_RCU_TABLE_FREE (as you previously state), why can't we only check for 64BIT?

OK, will do.

Thanks,
Qi

Quoted 1 line
#28 lore raw
In reply to Qi Zheng
Quoted 26 lines · Qi Zheng
Quoted 23 lines · David Hildenbrand (Red Hat)
Quoted 4 lines · Qi Zheng

From: Qi Zheng <[email protected]>

Hi all,

Quoted 8 lines

This series aims to enable PT_RECLAIM on all 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.

Makes sense!

Quoted 6 lines

Therefore, this series first enables MMU_GATHER_RCU_TABLE_FREE on all 64-bit
architectures, and finally makes PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE
&& 64BIT. This way, PT_RECLAIM can be enabled by default on all 64-bit architectures.

Quoted 3 lines
Quoted 1 line

Could we then even go ahead and stop making PT_RECLAIM user-selectable?

OK, will change to:

Was more of a question: is there any scenario where we ran so far into issues with it?

Signature · 3 lines
Cheers

David
#21 lore raw

Re: [PATCH 7/7] mm: make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT

In reply to Qi Zheng
Quoted 67 lines · Qi Zheng
Quoted 4 lines · David Hildenbrand (Red Hat)
Quoted 1 line · Qi Zheng

From: Qi Zheng <[email protected]>

Subject: s/&&/&/

will do.

Quoted 40 lines
Quoted 40 lines

Make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE so that PT_RECLAIM can
be enabled by default on all architectures that support MMU_GATHER_RCU_TABLE_FREE.

Considering that a large number of PTE page table pages (such as 100GB+) can only be caused on a 64-bit system, let PT_RECLAIM also depend on 64BIT.

---
   arch/x86/Kconfig | 1 -
   mm/Kconfig       | 6 +-----
   2 files changed, 1 insertion(+), 6 deletions(-)
arch/x86/Kconfig +0 -1
index eac2e86056902..96bff81fd4787 100644
@@ -330,7 +330,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 +0 -3
index a5a90b169435d..e795fbd69e50c 100644
@@ -1440,14 +1440,10 @@ 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 ARCH_SUPPORTS_PT_RECLAIM
-    def_bool n
-
   config PT_RECLAIM
Quoted 8 lines

mm/Kconfig config ARCH_HAS_USER_SHADOW_STACK · line 1446

Quoted 5 lines
mm/Kconfig +1 -2
       bool "reclaim empty user page table pages"
       default y
-    depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP
-    select MMU_GATHER_RCU_TABLE_FREE
+    depends on MMU_GATHER_RCU_TABLE_FREE && MMU && SMP && 64BIT

Who would we have MMU_GATHER_RCU_TABLE_FREE without MMU? (can we drop the MMU part)

OK.

Quoted 2 lines

Why do we care about SMP in the first place? (can we frop SMP)

OK.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

But I also wonder why we need "MMU_GATHER_RCU_TABLE_FREE && 64BIT":

Would it be harmful on 32bit (sure, we might not reclaim as much, but still there is memory to be reclaimed?)?

This is also fine on 32bit, but the benefits are not significant, So I chose to enable it only on 64-bit.

Right. Address space is smaller, but also memory is smaller. Not that I think we strictly *must* to support 32bit, I merely wonder why we wouldn't just enable it here.

OTOH, if there is a good reason we cannot enable it, we can definitely just keep it 64bit only.

Quoted 11 lines

I actually tried enabling MMU_GATHER_RCU_TABLE_FREE on all architectures, and apart from sparc32 being a bit troublesome (because it uses mm->page_table_lock for synchronization within __pte_free_tlb()), the modifications were relatively simple.

Quoted 3 lines

If all 64BIT support MMU_GATHER_RCU_TABLE_FREE (as you previously state), why can't we only check for 64BIT?

OK, will do.

This was also more of a question for discussion:

Would it make sense to have

config PT_RECLAIM
def_bool y
depends on MMU_GATHER_RCU_TABLE_FREE

(a) Would we want to make it configurable (why?)
(b) Do we really care about SMP (why?)
(c) Do we want to limit to 64bit (why?)
(d) Do we really need the MMU check in addition to MMU_GATHER_RCU_TABLE_FREE

Signature · 3 lines
Cheers

David
author
#29 lore raw
In reply to David Hildenbrand (Red Hat)
Quoted 27 lines · David Hildenbrand (Red Hat)
Quoted 26 lines · Qi Zheng
Quoted 23 lines · David Hildenbrand (Red Hat)
Quoted 4 lines · Qi Zheng

From: Qi Zheng <[email protected]>

Hi all,

Quoted 8 lines

This series aims to enable PT_RECLAIM on all 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.

Makes sense!

Quoted 6 lines

Therefore, this series first enables MMU_GATHER_RCU_TABLE_FREE on all 64-bit
architectures, and finally makes PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE
&& 64BIT. This way, PT_RECLAIM can be enabled by default on all 64-bit architectures.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Could we then even go ahead and stop making PT_RECLAIM user-selectable?

OK, will change to:

Was more of a question: is there any scenario where we ran so far into issues with it?

No, I haven't received any reports of related issues, either within the company or in the community.

Quoted 1 line
author
#22 lore raw

Re: [PATCH 7/7] mm: make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT

In reply to David Hildenbrand (Red Hat)

Hi David,

Quoted 73 lines · David Hildenbrand (Red Hat)
Quoted 72 lines · Qi Zheng
Quoted 4 lines · David Hildenbrand (Red Hat)
Quoted 1 line · Qi Zheng

From: Qi Zheng <[email protected]>

Subject: s/&&/&/

will do.

Quoted 40 lines
Quoted 40 lines

Make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE so that PT_RECLAIM can
be enabled by default on all architectures that support MMU_GATHER_RCU_TABLE_FREE.

Considering that a large number of PTE page table pages (such as 100GB+) can only be caused on a 64-bit system, let PT_RECLAIM also depend on 64BIT.

---
   arch/x86/Kconfig | 1 -
   mm/Kconfig       | 6 +-----

   2 files changed, 1 insertion(+), 6 deletions(-)
arch/x86/Kconfig +0 -0
index eac2e86056902..96bff81fd4787 100644
@@ -330,7 +330,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 +0 -0
index a5a90b169435d..e795fbd69e50c 100644
@@ -1440,14 +1440,10 @@ 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).

mm/Kconfig +0 -3
-config ARCH_SUPPORTS_PT_RECLAIM
-    def_bool n
-

   config PT_RECLAIM

Quoted 8 lines
Quoted 5 lines

       bool "reclaim empty user page table pages" default y
-    depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP -    select MMU_GATHER_RCU_TABLE_FREE
+    depends on MMU_GATHER_RCU_TABLE_FREE && MMU && SMP && 64BIT

Who would we have MMU_GATHER_RCU_TABLE_FREE without MMU? (can we drop the MMU part)

OK.

Quoted 2 lines

Why do we care about SMP in the first place? (can we frop SMP)

OK.

Quoted 5 lines

But I also wonder why we need "MMU_GATHER_RCU_TABLE_FREE && 64BIT":

Would it be harmful on 32bit (sure, we might not reclaim as much, but still there is memory to be reclaimed?)?

Quoted 6 lines
Quoted 2 lines

This is also fine on 32bit, but the benefits are not significant, So I chose to enable it only on 64-bit.

Right. Address space is smaller, but also memory is smaller. Not that I think we strictly *must* to support 32bit, I merely wonder why we wouldn't just enable it here.

OTOH, if there is a good reason we cannot enable it, we can definitely just keep it 64bit only.

The only difficulty is this:

Quoted 6 lines
Quoted 6 lines

I actually tried enabling MMU_GATHER_RCU_TABLE_FREE on all architectures, and apart from sparc32 being a bit troublesome (because it uses mm->page_table_lock for synchronization within __pte_free_tlb()), the modifications were relatively simple.

in sparc32:

void pte_free(struct mm_struct *mm, pgtable_t ptep) {
struct page *page;

page = pfn_to_page(__nocache_pa((unsigned long)ptep) >>

PAGE_SHIFT);
        spin_lock(&mm->page_table_lock);
        if (page_ref_dec_return(page) == 1)
                pagetable_dtor(page_ptdesc(page));
        spin_unlock(&mm->page_table_lock);

        srmmu_free_nocache(ptep, SRMMU_PTE_TABLE_SIZE);
}

#define __pte_free_tlb(tlb, pte, addr) pte_free((tlb)->mm, pte)

To enable MMU_GATHER_RCU_TABLE_FREE on sparc32, we need to implement __tlb_remove_table(), and call the pte_free() above in __tlb_remove_table().

However, the __tlb_remove_table() does not have an mm parameter:

void __tlb_remove_table(void *_table)

so we need to use another lock instead of mm->page_table_lock.

I have already sent the v2 [1], and perhaps after that I can enable PT_RECLAIM on all 32-bit architectures as well.

[1]. https://lore.kernel.org/all/[email protected]/

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

If all 64BIT support MMU_GATHER_RCU_TABLE_FREE (as you previously state), why can't we only check for 64BIT?

OK, will do.

Quoted 7 lines

This was also more of a question for discussion:

Would it make sense to have

config PT_RECLAIM
    def_bool y
    depends on MMU_GATHER_RCU_TABLE_FREE

make sense.

Quoted 2 lines

(a) Would we want to make it configurable (why?)

No, it was just out of caution before.

Quoted 1 line

(b) Do we really care about SMP (why?)

No. Simply because the following situation is impossible to occur:

pte_offset_map
traversing the PTE page table

<preemption or hardirq>

call madvise(MADV_DONTNEED)

so there's no need to free PTE page via RCU.

Quoted 1 line

(c) Do we want to limit to 64bit (why?)

No, just because the profit is greater at 64-BIT.

Quoted 2 lines

(d) Do we really need the MMU check in addition to MMU_GATHER_RCU_TABLE_FREE

No, I was worried about compilation issues before, but now it seems that my worries were unnecessary.

Thanks,
Qi

Quoted 2 lines
#23 lore raw

Re: [PATCH 7/7] mm: make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT

Quoted 118 lines · Qi Zheng

Hi David,

Quoted 78 lines · David Hildenbrand (Red Hat)
Quoted 69 lines · Qi Zheng
Quoted 4 lines · David Hildenbrand (Red Hat)
Quoted 1 line · Qi Zheng

From: Qi Zheng <[email protected]>

Subject: s/&&/&/

will do.

Quoted 42 lines
Quoted 42 lines

Make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE so that PT_RECLAIM can
be enabled by default on all architectures that support MMU_GATHER_RCU_TABLE_FREE.

Considering that a large number of PTE page table pages (such as 100GB+)
can only be caused on a 64-bit system, let PT_RECLAIM also depend on 64BIT.

---
    arch/x86/Kconfig | 1 -
    mm/Kconfig       | 6 +-----
    2 files changed, 1 insertion(+), 6 deletions(-)
arch/x86/Kconfig +0 -1
index eac2e86056902..96bff81fd4787 100644
@@ -330,7 +330,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 +0 -0
index a5a90b169435d..e795fbd69e50c 100644
@@ -1440,14 +1440,10 @@ 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).

mm/Kconfig +0 -3
-config ARCH_SUPPORTS_PT_RECLAIM
-    def_bool n
-
    config PT_RECLAIM
Quoted 8 lines
Quoted 5 lines

       bool "reclaim empty user page table pages" default y
-    depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP -    select MMU_GATHER_RCU_TABLE_FREE
+    depends on MMU_GATHER_RCU_TABLE_FREE && MMU && SMP && 64BIT

Who would we have MMU_GATHER_RCU_TABLE_FREE without MMU? (can we drop the MMU part)

OK.

Quoted 2 lines

Why do we care about SMP in the first place? (can we frop SMP)

OK.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

But I also wonder why we need "MMU_GATHER_RCU_TABLE_FREE && 64BIT":

Would it be harmful on 32bit (sure, we might not reclaim as much, but still there is memory to be reclaimed?)?

This is also fine on 32bit, but the benefits are not significant, So I chose to enable it only on 64-bit.

Quoted 6 lines

Right. Address space is smaller, but also memory is smaller. Not that I think we strictly *must* to support 32bit, I merely wonder why we wouldn't just enable it here.

OTOH, if there is a good reason we cannot enable it, we can definitely just keep it 64bit only.

The only difficulty is this:

Quoted 6 lines
Quoted 6 lines

I actually tried enabling MMU_GATHER_RCU_TABLE_FREE on all architectures, and apart from sparc32 being a bit troublesome (because it uses mm->page_table_lock for synchronization within __pte_free_tlb()), the modifications were relatively simple.

in sparc32:

void pte_free(struct mm_struct *mm, pgtable_t ptep) {
struct page *page;

page = pfn_to_page(__nocache_pa((unsigned long)ptep) >>

PAGE_SHIFT);
          spin_lock(&mm->page_table_lock);
          if (page_ref_dec_return(page) == 1)
                  pagetable_dtor(page_ptdesc(page));
          spin_unlock(&mm->page_table_lock);

          srmmu_free_nocache(ptep, SRMMU_PTE_TABLE_SIZE);
}

#define __pte_free_tlb(tlb, pte, addr) pte_free((tlb)->mm, pte)

To enable MMU_GATHER_RCU_TABLE_FREE on sparc32, we need to implement __tlb_remove_table(), and call the pte_free() above in __tlb_remove_table().

Quoted 9 lines

However, the __tlb_remove_table() does not have an mm parameter:

void __tlb_remove_table(void *_table)

so we need to use another lock instead of mm->page_table_lock.

I have already sent the v2 [1], and perhaps after that I can enable PT_RECLAIM on all 32-bit architectures as well.

I guess if we just make it depend on MMU_GATHER_RCU_TABLE_FREE that will be fine.

Quoted 34 lines

[1].
https://lore.kernel.org/all/[email protected]/

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

If all 64BIT support MMU_GATHER_RCU_TABLE_FREE (as you previously state), why can't we only check for 64BIT?

OK, will do.

Quoted 7 lines

This was also more of a question for discussion:

Would it make sense to have

config PT_RECLAIM
    def_bool y
    depends on MMU_GATHER_RCU_TABLE_FREE

make sense.

Quoted 2 lines

(a) Would we want to make it configurable (why?)

No, it was just out of caution before.

Quoted 1 line

(b) Do we really care about SMP (why?)

No. Simply because the following situation is impossible to occur:

pte_offset_map
traversing the PTE page table

<preemption or hardirq>

Quoted 7 lines

call madvise(MADV_DONTNEED)

so there's no need to free PTE page via RCU.

Quoted 1 line

(c) Do we want to limit to 64bit (why?)

No, just because the profit is greater at 64-BIT.

I was briefly wondering if on 32bit (but maybe also on 64bit with configurable user page table levels?) we could have the scenario that we only have two page table levels.

So reclaiming the PMD level (corresponding to the highest level) would be impossible. But for that to happen one would have to discard the whole address range through MADV_DONTNEED (impossible I guess) :)

Signature · 3 lines
Cheers

David
author
#24 lore raw

Re: [PATCH 7/7] mm: make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT

Quoted 169 lines · David Hildenbrand (Red Hat)
Quoted 118 lines · Qi Zheng

Hi David,

Quoted 78 lines · David Hildenbrand (Red Hat)
Quoted 69 lines · Qi Zheng
Quoted 4 lines · David Hildenbrand (Red Hat)
Quoted 1 line · Qi Zheng

From: Qi Zheng <[email protected]>

Subject: s/&&/&/

will do.

Quoted 42 lines
Quoted 42 lines

Make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE so that PT_RECLAIM can
be enabled by default on all architectures that support MMU_GATHER_RCU_TABLE_FREE.

Considering that a large number of PTE page table pages (such as 100GB+)
can only be caused on a 64-bit system, let PT_RECLAIM also depend on 64BIT.

---
    arch/x86/Kconfig | 1 -
    mm/Kconfig       | 6 +-----

    2 files changed, 1 insertion(+), 6 deletions(-)
arch/x86/Kconfig +0 -0
index eac2e86056902..96bff81fd4787 100644
@@ -330,7 +330,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 +0 -0
index a5a90b169435d..e795fbd69e50c 100644
@@ -1440,14 +1440,10 @@ 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).

mm/Kconfig +0 -3
-config ARCH_SUPPORTS_PT_RECLAIM
-    def_bool n
-

    config PT_RECLAIM

Quoted 8 lines
Quoted 5 lines

        bool "reclaim empty user page table pages" default y
-    depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP -    select MMU_GATHER_RCU_TABLE_FREE
+    depends on MMU_GATHER_RCU_TABLE_FREE && MMU && SMP && 64BIT

Who would we have MMU_GATHER_RCU_TABLE_FREE without MMU? (can we drop the MMU part)

OK.

Quoted 2 lines

Why do we care about SMP in the first place? (can we frop SMP)

OK.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

But I also wonder why we need "MMU_GATHER_RCU_TABLE_FREE && 64BIT":

Would it be harmful on 32bit (sure, we might not reclaim as much, but still there is memory to be reclaimed?)?

This is also fine on 32bit, but the benefits are not significant, So I chose to enable it only on 64-bit.

Quoted 6 lines

Right. Address space is smaller, but also memory is smaller. Not that I think we strictly *must* to support 32bit, I merely wonder why we wouldn't just enable it here.

OTOH, if there is a good reason we cannot enable it, we can definitely just keep it 64bit only.

The only difficulty is this:

Quoted 6 lines
Quoted 6 lines

I actually tried enabling MMU_GATHER_RCU_TABLE_FREE on all architectures, and apart from sparc32 being a bit troublesome (because it uses mm->page_table_lock for synchronization within __pte_free_tlb()), the modifications were relatively simple.

in sparc32:

void pte_free(struct mm_struct *mm, pgtable_t ptep) {
          struct page *page;

          page = pfn_to_page(__nocache_pa((unsigned long)ptep) >> PAGE_SHIFT);
          spin_lock(&mm->page_table_lock);
          if (page_ref_dec_return(page) == 1) pagetable_dtor(page_ptdesc(page)); spin_unlock(&mm->page_table_lock);

          srmmu_free_nocache(ptep, SRMMU_PTE_TABLE_SIZE); }

#define __pte_free_tlb(tlb, pte, addr)  pte_free((tlb)->mm, pte)

To enable MMU_GATHER_RCU_TABLE_FREE on sparc32, we need to implement __tlb_remove_table(), and call the pte_free() above in __tlb_remove_table().

Quoted 9 lines

However, the __tlb_remove_table() does not have an mm parameter:

void __tlb_remove_table(void *_table)

so we need to use another lock instead of mm->page_table_lock.

I have already sent the v2 [1], and perhaps after that I can enable PT_RECLAIM on all 32-bit architectures as well.

I guess if we just make it depend on MMU_GATHER_RCU_TABLE_FREE that will be fine.

Quoted 38 lines

[1].
https://lore.kernel.org/all/ [email protected]/

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

If all 64BIT support MMU_GATHER_RCU_TABLE_FREE (as you previously state), why can't we only check for 64BIT?

OK, will do.

Quoted 7 lines

This was also more of a question for discussion:

Would it make sense to have

config PT_RECLAIM
      def_bool y
      depends on MMU_GATHER_RCU_TABLE_FREE

make sense.

Quoted 2 lines

(a) Would we want to make it configurable (why?)

No, it was just out of caution before.

Quoted 1 line

(b) Do we really care about SMP (why?)

No. Simply because the following situation is impossible to occur:

pte_offset_map
traversing the PTE page table

<preemption or hardirq>

call madvise(MADV_DONTNEED)

so there's no need to free PTE page via RCU.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

(c) Do we want to limit to 64bit (why?)

No, just because the profit is greater at 64-BIT.

I was briefly wondering if on 32bit (but maybe also on 64bit with configurable user page table levels?) we could have the scenario that we only have two page table levels.

So reclaiming the PMD level (corresponding to the highest level) would

reclaiming the PMD level? The PT_RECLAIM only reclaim PTE pages, not PMD pages, am I misunderstanding something?

Quoted 2 lines

be impossible. But for that to happen one would have to discard the whole address range through MADV_DONTNEED (impossible I guess) :)

#25 lore raw

Re: [PATCH 7/7] mm: make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE && 64BIT

Quoted 180 lines · Qi Zheng
Quoted 177 lines · David Hildenbrand (Red Hat)
Quoted 120 lines · Qi Zheng

Hi David,

Quoted 79 lines · David Hildenbrand (Red Hat)
Quoted 70 lines · Qi Zheng
Quoted 4 lines · David Hildenbrand (Red Hat)
Quoted 1 line · Qi Zheng

From: Qi Zheng <[email protected]>

Subject: s/&&/&/

will do.

Quoted 43 lines
Quoted 43 lines

Make PT_RECLAIM depend on MMU_GATHER_RCU_TABLE_FREE so that PT_RECLAIM
can
be enabled by default on all architectures that support MMU_GATHER_RCU_TABLE_FREE.

Considering that a large number of PTE page table pages (such as 100GB+)
can only be caused on a 64-bit system, let PT_RECLAIM also depend on 64BIT.

---
     arch/x86/Kconfig | 1 -
     mm/Kconfig       | 6 +-----
     2 files changed, 1 insertion(+), 6 deletions(-)
arch/x86/Kconfig +0 -1
index eac2e86056902..96bff81fd4787 100644
@@ -330,7 +330,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 +0 -0
index a5a90b169435d..e795fbd69e50c 100644
@@ -1440,14 +1440,10 @@ 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).

mm/Kconfig +0 -3
-config ARCH_SUPPORTS_PT_RECLAIM
-    def_bool n
-
     config PT_RECLAIM
Quoted 8 lines
Quoted 5 lines

        bool "reclaim empty user page table pages" default y
-    depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP -    select MMU_GATHER_RCU_TABLE_FREE
+    depends on MMU_GATHER_RCU_TABLE_FREE && MMU && SMP && 64BIT

Who would we have MMU_GATHER_RCU_TABLE_FREE without MMU? (can we drop the MMU part)

OK.

Quoted 2 lines

Why do we care about SMP in the first place? (can we frop SMP)

OK.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

But I also wonder why we need "MMU_GATHER_RCU_TABLE_FREE && 64BIT":

Would it be harmful on 32bit (sure, we might not reclaim as much, but still there is memory to be reclaimed?)?

This is also fine on 32bit, but the benefits are not significant, So I chose to enable it only on 64-bit.

Quoted 6 lines

Right. Address space is smaller, but also memory is smaller. Not that I think we strictly *must* to support 32bit, I merely wonder why we wouldn't just enable it here.

OTOH, if there is a good reason we cannot enable it, we can definitely just keep it 64bit only.

The only difficulty is this:

Quoted 6 lines
Quoted 6 lines

I actually tried enabling MMU_GATHER_RCU_TABLE_FREE on all architectures, and apart from sparc32 being a bit troublesome (because it uses mm->page_table_lock for synchronization within __pte_free_tlb()), the modifications were relatively simple.

in sparc32:

void pte_free(struct mm_struct *mm, pgtable_t ptep) {
          struct page *page;

          page = pfn_to_page(__nocache_pa((unsigned long)ptep) >>
PAGE_SHIFT);
          spin_lock(&mm->page_table_lock);
          if (page_ref_dec_return(page) == 1) pagetable_dtor(page_ptdesc(page)); spin_unlock(&mm->page_table_lock);

          srmmu_free_nocache(ptep, SRMMU_PTE_TABLE_SIZE);
}

#define __pte_free_tlb(tlb, pte, addr)  pte_free((tlb)->mm, pte)

To enable MMU_GATHER_RCU_TABLE_FREE on sparc32, we need to implement __tlb_remove_table(), and call the pte_free() above in __tlb_remove_table().

Quoted 9 lines

However, the __tlb_remove_table() does not have an mm parameter:

void __tlb_remove_table(void *_table)

so we need to use another lock instead of mm->page_table_lock.

I have already sent the v2 [1], and perhaps after that I can enable PT_RECLAIM on all 32-bit architectures as well.

I guess if we just make it depend on MMU_GATHER_RCU_TABLE_FREE that will be fine.

Quoted 42 lines

[1].
https://lore.kernel.org/all/
[email protected]/

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

If all 64BIT support MMU_GATHER_RCU_TABLE_FREE (as you previously state), why can't we only check for 64BIT?

OK, will do.

Quoted 7 lines

This was also more of a question for discussion:

Would it make sense to have

config PT_RECLAIM
      def_bool y
      depends on MMU_GATHER_RCU_TABLE_FREE

make sense.

Quoted 2 lines

(a) Would we want to make it configurable (why?)

No, it was just out of caution before.

Quoted 1 line

(b) Do we really care about SMP (why?)

No. Simply because the following situation is impossible to occur:

pte_offset_map
traversing the PTE page table

<preemption or hardirq>

call madvise(MADV_DONTNEED)

so there's no need to free PTE page via RCU.

Quoted 1 line

(c) Do we want to limit to 64bit (why?)

No, just because the profit is greater at 64-BIT.

Quoted 8 lines
Quoted 5 lines

I was briefly wondering if on 32bit (but maybe also on 64bit with configurable user page table levels?) we could have the scenario that we only have two page table levels.

So reclaiming the PMD level (corresponding to the highest level) would

reclaiming the PMD level? The PT_RECLAIM only reclaim PTE pages, not PMD pages, am I misunderstanding something?

Sorry, I looked too much into PMD table sharing the last days :D

You're right, it would work in any case even with only 2 levels of apge tables.

Signature · 3 lines
Cheers

David