Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

arm64: mm: implement the architecture-specific test_and_clear_young_ptes()

Implement the Arm64 architecture-specific test_and_clear_young_ptes() to
enable batched checking of young flags, improving performance during large
folio reclamation when MGLRU is enabled.

While we're at it, simplify ptep_test_and_clear_young() by calling
test_and_clear_young_ptes(). Since callers guarantee that PTEs are
present before calling these functions, we can use pte_cont() to check the
CONT_PTE flag instead of pte_valid_cont().

Performance testing:

Enable MGLRU, then allocate 10G clean file-backed folios by mmap() in a
memory cgroup, and try to reclaim 8G file-backed folios via the
memory.reclaim interface. I can observe 60%+ performance improvement on
my Arm64 32-core server (and about 15% improvement on my X86 machine).

W/o patchset:
real 0m0.470s
user 0m0.000s
sys 0m0.470s

W/ patchset:
real 0m0.180s
user 0m0.001s
sys 0m0.179s

Link: https://lkml.kernel.org/r/7f891d42a720cc2e57862f3b79e4f774404f313c.1772778858.git.baolin.wang@linux.alibaba.com
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: Rik van Riel <riel@surriel.com>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Jann Horn <jannh@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Wei Xu <weixugc@google.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yuanchu Xie <yuanchu@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Baolin Wang and committed by
Andrew Morton
9970a9a2 56e5b60b

+12 -6
+12 -6
arch/arm64/include/asm/pgtable.h
··· 1812 1812 return __ptep_get_and_clear(mm, addr, ptep); 1813 1813 } 1814 1814 1815 + #define test_and_clear_young_ptes test_and_clear_young_ptes 1816 + static inline int test_and_clear_young_ptes(struct vm_area_struct *vma, 1817 + unsigned long addr, pte_t *ptep, 1818 + unsigned int nr) 1819 + { 1820 + if (likely(nr == 1 && !pte_cont(__ptep_get(ptep)))) 1821 + return __ptep_test_and_clear_young(vma, addr, ptep); 1822 + 1823 + return contpte_test_and_clear_young_ptes(vma, addr, ptep, nr); 1824 + } 1825 + 1815 1826 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 1816 1827 static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, 1817 1828 unsigned long addr, pte_t *ptep) 1818 1829 { 1819 - pte_t orig_pte = __ptep_get(ptep); 1820 - 1821 - if (likely(!pte_valid_cont(orig_pte))) 1822 - return __ptep_test_and_clear_young(vma, addr, ptep); 1823 - 1824 - return contpte_test_and_clear_young_ptes(vma, addr, ptep, 1); 1830 + return test_and_clear_young_ptes(vma, addr, ptep, 1); 1825 1831 } 1826 1832 1827 1833 #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH