Skip to content

Commit eed9a32

Browse files
yuzhaogoogleakpm00
authored andcommitted
mm: x86: add CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG
Some architectures support the accessed bit in non-leaf PMD entries, e.g., x86 sets the accessed bit in a non-leaf PMD entry when using it as part of linear address translation [1]. Page table walkers that clear the accessed bit may use this capability to reduce their search space. Note that: 1. Although an inline function is preferable, this capability is added as a configuration option for consistency with the existing macros. 2. Due to the little interest in other varieties, this capability was only tested on Intel and AMD CPUs. Thanks to the following developers for their efforts [2][3]. Randy Dunlap <[email protected]> Stephen Rothwell <[email protected]> [1]: Intel 64 and IA-32 Architectures Software Developer's Manual Volume 3 (June 2021), section 4.8 [2] https://lore.kernel.org/r/[email protected]/ [3] https://lore.kernel.org/r/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Yu Zhao <[email protected]> Reviewed-by: Barry Song <[email protected]> Acked-by: Brian Geffon <[email protected]> Acked-by: Jan Alexander Steffens (heftig) <[email protected]> Acked-by: Oleksandr Natalenko <[email protected]> Acked-by: Steven Barrett <[email protected]> Acked-by: Suleiman Souhlal <[email protected]> Tested-by: Daniel Byrne <[email protected]> Tested-by: Donald Carr <[email protected]> Tested-by: Holger Hoffstätte <[email protected]> Tested-by: Konstantin Kharlamov <[email protected]> Tested-by: Shuang Zhai <[email protected]> Tested-by: Sofia Trinh <[email protected]> Tested-by: Vaibhav Jain <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Aneesh Kumar K.V <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Hillf Danton <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Miaohe Lin <[email protected]> Cc: Michael Larabel <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Qi Zheng <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent e1fd09e commit eed9a32

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

arch/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,14 @@ config DYNAMIC_SIGFRAME
14151415
config HAVE_ARCH_NODE_DEV_GROUP
14161416
bool
14171417

1418+
config ARCH_HAS_NONLEAF_PMD_YOUNG
1419+
bool
1420+
help
1421+
Architectures that select this option are capable of setting the
1422+
accessed bit in non-leaf PMD entries when using them as part of linear
1423+
address translations. Page table walkers that clear the accessed bit
1424+
may use this capability to reduce their search space.
1425+
14181426
source "kernel/gcov/Kconfig"
14191427

14201428
source "scripts/gcc-plugins/Kconfig"

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ config X86
8585
select ARCH_HAS_PMEM_API if X86_64
8686
select ARCH_HAS_PTE_DEVMAP if X86_64
8787
select ARCH_HAS_PTE_SPECIAL
88+
select ARCH_HAS_NONLEAF_PMD_YOUNG if PGTABLE_LEVELS > 2
8889
select ARCH_HAS_UACCESS_FLUSHCACHE if X86_64
8990
select ARCH_HAS_COPY_MC if X86_64
9091
select ARCH_HAS_SET_MEMORY

arch/x86/include/asm/pgtable.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,8 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
815815

816816
static inline int pmd_bad(pmd_t pmd)
817817
{
818-
return (pmd_flags(pmd) & ~_PAGE_USER) != _KERNPG_TABLE;
818+
return (pmd_flags(pmd) & ~(_PAGE_USER | _PAGE_ACCESSED)) !=
819+
(_KERNPG_TABLE & ~_PAGE_ACCESSED);
819820
}
820821

821822
static inline unsigned long pages_to_mb(unsigned long npg)

arch/x86/mm/pgtable.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ int ptep_test_and_clear_young(struct vm_area_struct *vma,
550550
return ret;
551551
}
552552

553-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
553+
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG)
554554
int pmdp_test_and_clear_young(struct vm_area_struct *vma,
555555
unsigned long addr, pmd_t *pmdp)
556556
{
@@ -562,6 +562,9 @@ int pmdp_test_and_clear_young(struct vm_area_struct *vma,
562562

563563
return ret;
564564
}
565+
#endif
566+
567+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
565568
int pudp_test_and_clear_young(struct vm_area_struct *vma,
566569
unsigned long addr, pud_t *pudp)
567570
{

include/linux/pgtable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
213213
#endif
214214

215215
#ifndef __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
216-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
216+
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG)
217217
static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
218218
unsigned long address,
219219
pmd_t *pmdp)
@@ -234,7 +234,7 @@ static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
234234
BUILD_BUG();
235235
return 0;
236236
}
237-
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
237+
#endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG */
238238
#endif
239239

240240
#ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH

0 commit comments

Comments
 (0)