Skip to content

Commit d0637c5

Browse files
Barry Songwilldeacon
authored andcommitted
arm64: enable THP_SWAP for arm64
THP_SWAP has been proven to improve the swap throughput significantly on x86_64 according to commit bd4c82c ("mm, THP, swap: delay splitting THP after swapped out"). As long as arm64 uses 4K page size, it is quite similar with x86_64 by having 2MB PMD THP. THP_SWAP is architecture-independent, thus, enabling it on arm64 will benefit arm64 as well. A corner case is that MTE has an assumption that only base pages can be swapped. We won't enable THP_SWAP for ARM64 hardware with MTE support until MTE is reworked to coexist with THP_SWAP. A micro-benchmark is written to measure thp swapout throughput as below, unsigned long long tv_to_ms(struct timeval tv) { return tv.tv_sec * 1000 + tv.tv_usec / 1000; } main() { struct timeval tv_b, tv_e;; #define SIZE 400*1024*1024 volatile void *p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (!p) { perror("fail to get memory"); exit(-1); } madvise(p, SIZE, MADV_HUGEPAGE); memset(p, 0x11, SIZE); /* write to get mem */ gettimeofday(&tv_b, NULL); madvise(p, SIZE, MADV_PAGEOUT); gettimeofday(&tv_e, NULL); printf("swp out bandwidth: %ld bytes/ms\n", SIZE/(tv_to_ms(tv_e) - tv_to_ms(tv_b))); } Testing is done on rk3568 64bit Quad Core Cortex-A55 platform - ROCK 3A. thp swp throughput w/o patch: 2734bytes/ms (mean of 10 tests) thp swp throughput w/ patch: 3331bytes/ms (mean of 10 tests) Cc: "Huang, Ying" <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Steven Price <[email protected]> Cc: Yang Shi <[email protected]> Reviewed-by: Anshuman Khandual <[email protected]> Signed-off-by: Barry Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent a111daf commit d0637c5

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

arch/arm64/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ config ARM64
101101
select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
102102
select ARCH_WANT_LD_ORPHAN_WARN
103103
select ARCH_WANTS_NO_INSTR
104+
select ARCH_WANTS_THP_SWAP if ARM64_4K_PAGES
104105
select ARCH_HAS_UBSAN_SANITIZE_ALL
105106
select ARM_AMBA
106107
select ARM_ARCH_TIMER

arch/arm64/include/asm/pgtable.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
__flush_tlb_range(vma, addr, end, PUD_SIZE, false, 1)
4646
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
4747

48+
static inline bool arch_thp_swp_supported(void)
49+
{
50+
return !system_supports_mte();
51+
}
52+
#define arch_thp_swp_supported arch_thp_swp_supported
53+
4854
/*
4955
* Outside of a few very special situations (e.g. hibernation), we always
5056
* use broadcast TLB invalidation instructions, therefore a spurious page

include/linux/huge_mm.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,16 @@ static inline int split_folio_to_list(struct folio *folio,
461461
return split_huge_page_to_list(&folio->page, list);
462462
}
463463

464+
/*
465+
* archs that select ARCH_WANTS_THP_SWAP but don't support THP_SWP due to
466+
* limitations in the implementation like arm64 MTE can override this to
467+
* false
468+
*/
469+
#ifndef arch_thp_swp_supported
470+
static inline bool arch_thp_swp_supported(void)
471+
{
472+
return true;
473+
}
474+
#endif
475+
464476
#endif /* _LINUX_HUGE_MM_H */

mm/swap_slots.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ swp_entry_t folio_alloc_swap(struct folio *folio)
307307
entry.val = 0;
308308

309309
if (folio_test_large(folio)) {
310-
if (IS_ENABLED(CONFIG_THP_SWAP))
310+
if (IS_ENABLED(CONFIG_THP_SWAP) && arch_thp_swp_supported())
311311
get_swap_pages(1, &entry, folio_nr_pages(folio));
312312
goto out;
313313
}

0 commit comments

Comments
 (0)