Skip to contentSkip to conversation

arm64: enable THP_SWAP for arm64

PATCH Superseded Barry Song 4 participants 7 messages May 27, 2022 – May 31, 2022

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Barry Song

author
#0 lore raw

PATCH v2 1/1 arm64: enable THP_SWAP for arm64

From: Barry Song <[email protected]>

THP_SWAP has been proved to improve the swap throughput significantly on x86_64 according to commit bd4c82c22c367e ("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. So we are going to get similar improvement. For other page sizes such as 16KB and 64KB, PMD might be too large. Negative side effects such as IO latency might be a problem. Thus, we can only safely enable the counterpart of X86_64.
A corner case is that MTE has an assumption that only base pages can be swapped. We won't enable THP_SWP for ARM64 hardware with MTE support until MTE is re-arched.

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 Anshuman Khandual <[email protected]>
Cc Steven Price <[email protected]>
Cc Yang Shi <[email protected]>
---
 arch/arm64/Kconfig               |  1 +
 arch/arm64/include/asm/pgtable.h |  2 ++
 include/linux/huge_mm.h          | 12 ++++++++++++
 mm/swap_slots.c                  |  2 +-
 4 files changed, 16 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +1 -0
index a4968845e67f..5306009df2dc 100644
@@ -101,6 +101,7 @@ config ARM64
 	select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
 	select ARCH_WANT_LD_ORPHAN_WARN
 	select ARCH_WANTS_NO_INSTR
+	select ARCH_WANTS_THP_SWAP if ARM64_4K_PAGES
 	select ARCH_HAS_UBSAN_SANITIZE_ALL
 	select ARM_AMBA
 	select ARM_ARCH_TIMER
arch/arm64/include/asm/pgtable.h +2 -0
index 0b6632f18364..06076139c72c 100644
@@ -45,6 +45,8 @@
 	__flush_tlb_range(vma, addr, end, PUD_SIZE, false, 1)
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
+#define arch_thp_swp_supported !system_supports_mte
+
 /*
  * Outside of a few very special situations (e.g. hibernation), we always
  * use broadcast TLB invalidation instructions, therefore a spurious page
include/linux/huge_mm.h +12 -0
index de29821231c9..4ddaf6ad73ef 100644
@@ -461,4 +461,16 @@ static inline int split_folio_to_list(struct folio *folio,
 	return split_huge_page_to_list(&folio->page, list);
 }
 
+/*
+ * archs that select ARCH_WANTS_THP_SWAP but don't support THP_SWP due to
+ * limitations in the implementation like arm64 MTE can override this to
+ * false
+ */
+#ifndef arch_thp_swp_supported
+static inline bool arch_thp_swp_supported(void)
+{
+	return true;
+}
+#endif
+
 #endif /* _LINUX_HUGE_MM_H */
mm/swap_slots.c +1 -1
index 2a65a89b5b4d..10b94d64cc25 100644
@@ -307,7 +307,7 @@ swp_entry_t folio_alloc_swap(struct folio *folio)
 	entry.val = 0;
 
 	if (folio_test_large(folio)) {
-		if (IS_ENABLED(CONFIG_THP_SWAP))
+		if (IS_ENABLED(CONFIG_THP_SWAP) && arch_thp_swp_supported())
 			get_swap_pages(1, &entry, folio_nr_pages(folio));
 		goto out;
 	}
Signature · 1 line
2.25.1
#1 lore raw

Hello Barry,

Quoted 5 lines · Barry Song

From: Barry Song <[email protected]>

THP_SWAP has been proved to improve the swap throughput significantly on x86_64 according to commit bd4c82c22c367e ("mm, THP, swap: delay splitting THP after swapped out").

It will be useful to run similar experiments on arm64 platform to demonstrate tangible benefit, else we might be just enabling this feature just because x86 has it. Do you have some data points ?

Quoted 2 lines

As long as arm64 uses 4K page size, it is quite similar with x86_64 by having 2MB PMD THP. So we are going to get similar improvement.

This is an assumption without any data points (until now). Please do provide some results.

Quoted 3 lines

For other page sizes such as 16KB and 64KB, PMD might be too large. Negative side effects such as IO latency might be a problem. Thus, we can only safely enable the counterpart of X86_64.

Incorrect reasoning. Although sometimes it might be okay to enable a feature on platforms with possible assumptions about its benefits, but to claim 'similar improvement, safely, .. etc' while comparing against x86 4K page config without data points, is not very helpful.

Quoted 3 lines

A corner case is that MTE has an assumption that only base pages can be swapped. We won't enable THP_SWP for ARM64 hardware with MTE support until MTE is re-arched.

re-arched ?? Did you imply that MTE is reworked to support THP ?

Quoted 34 lines
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 Anshuman Khandual <[email protected]>
Cc Steven Price <[email protected]>
Cc Yang Shi <[email protected]>
---
 arch/arm64/Kconfig               |  1 +
 arch/arm64/include/asm/pgtable.h |  2 ++
 include/linux/huge_mm.h          | 12 ++++++++++++
 mm/swap_slots.c                  |  2 +-
 4 files changed, 16 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +1 -0
index a4968845e67f..5306009df2dc 100644
@@ -101,6 +101,7 @@ config ARM64
 	select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
 	select ARCH_WANT_LD_ORPHAN_WARN
 	select ARCH_WANTS_NO_INSTR
+	select ARCH_WANTS_THP_SWAP if ARM64_4K_PAGES
 	select ARCH_HAS_UBSAN_SANITIZE_ALL
 	select ARM_AMBA
 	select ARM_ARCH_TIMER
arch/arm64/include/asm/pgtable.h +0 -0
index 0b6632f18364..06076139c72c 100644

arch/arm64/include/asm/pgtable.h line 48

Quoted 4 lines
arch/arm64/include/asm/pgtable.h +1 -0
@@ -45,6 +45,8 @@
 	__flush_tlb_range(vma, addr, end, PUD_SIZE, false, 1)
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
+#define arch_thp_swp_supported !system_supports_mte

Does it check for 'system_supports_mte' as a symbol or call system_supports_mte() to ascertain runtime MTE support ? It might well be correct, but just does not look much intuitive.

Quoted 9 lines
arch/arm64/include/asm/pgtable.h +1 -0
+
 /*
  * Outside of a few very special situations (e.g. hibernation), we always
  * use broadcast TLB invalidation instructions, therefore a spurious page
include/linux/huge_mm.h +0 -0
index de29821231c9..4ddaf6ad73ef 100644

include/linux/huge_mm.h static inline int split_folio_to_list(struct folio *folio, · line 466

Quoted 6 lines
include/linux/huge_mm.h +3 -0
@@ -461,4 +461,16 @@ static inline int split_folio_to_list(struct folio *folio,
 	return split_huge_page_to_list(&folio->page, list);
 }
 
+/*
+ * archs that select ARCH_WANTS_THP_SWAP but don't support THP_SWP due to
+ * limitations in the implementation like arm64 MTE can override this to

A small nit.

A 'comma' here will be better. s/arm64 MTE can/arm64 MTE, can/

include/linux/huge_mm.h static inline int split_folio_to_list(struct folio *folio, · line 467

Quoted 1 line
include/linux/huge_mm.h +1 -0
+ * false

Similarly a 'full stop' here will be better as well.

Quoted 14 lines
include/linux/huge_mm.h +8 -0
+ */
+#ifndef arch_thp_swp_supported
+static inline bool arch_thp_swp_supported(void)
+{
+	return true;
+}
+#endif
+
 #endif /* _LINUX_HUGE_MM_H */
mm/swap_slots.c +0 -0
index 2a65a89b5b4d..10b94d64cc25 100644

mm/swap_slots.c swp_entry_t folio_alloc_swap(struct folio *folio) · line 313

Quoted 8 lines
mm/swap_slots.c +1 -1
@@ -307,7 +307,7 @@ swp_entry_t folio_alloc_swap(struct folio *folio)
 	entry.val = 0;
 
 	if (folio_test_large(folio)) {
-		if (IS_ENABLED(CONFIG_THP_SWAP))
+		if (IS_ENABLED(CONFIG_THP_SWAP) && arch_thp_swp_supported())
 			get_swap_pages(1, &entry, folio_nr_pages(folio));
 		goto out;
 	}

- Anshuman

author
#2 lore raw
Quoted 2 lines · Anshuman Khandual

Hello Barry,

Hi Anshuman,
thanks!

Quoted 11 lines · Barry Song
Quoted 5 lines

From: Barry Song <[email protected]>

THP_SWAP has been proved to improve the swap throughput significantly on x86_64 according to commit bd4c82c22c367e ("mm, THP, swap: delay splitting THP after swapped out").

It will be useful to run similar experiments on arm64 platform to demonstrate tangible benefit, else we might be just enabling this feature just because x86 has it. Do you have some data points ?

Quoted 5 lines
Quoted 2 lines

As long as arm64 uses 4K page size, it is quite similar with x86_64 by having 2MB PMD THP. So we are going to get similar improvement.

This is an assumption without any data points (until now). Please do provide some results.

Fair enough though I believe THP_SWP is arch-independent. Our testing will post data. Plus, we do need it for real use cases with some possible out-of-tree code for this moment. so this patch does not originate only because x86 has it :-)

Quoted 10 lines
Quoted 4 lines

For other page sizes such as 16KB and 64KB, PMD might be too large. Negative side effects such as IO latency might be a problem. Thus, we can only safely enable the counterpart of X86_64.

Incorrect reasoning. Although sometimes it might be okay to enable a feature on platforms with possible assumptions about its benefits, but to claim 'similar improvement, safely, .. etc' while comparing against x86 4K page config without data points, is not very helpful.

Quoted 5 lines
Quoted 3 lines

A corner case is that MTE has an assumption that only base pages can be swapped. We won't enable THP_SWP for ARM64 hardware with MTE support until MTE is re-arched.

re-arched ?? Did you imply that MTE is reworked to support THP ?

I think at least MTE should be able to coexist with THP_SWP though I am not quite sure if MTE can be re-worked to fully support THP.

Quoted 38 lines
Quoted 38 lines
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 Anshuman Khandual <[email protected]>
Cc Steven Price <[email protected]>
Cc Yang Shi <[email protected]>
---
 arch/arm64/Kconfig               |  1 +
 arch/arm64/include/asm/pgtable.h |  2 ++
 include/linux/huge_mm.h          | 12 ++++++++++++
 mm/swap_slots.c                  |  2 +-
 4 files changed, 16 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +1 -0
index a4968845e67f..5306009df2dc 100644
@@ -101,6 +101,7 @@ config ARM64
      select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
      select ARCH_WANT_LD_ORPHAN_WARN
      select ARCH_WANTS_NO_INSTR
+     select ARCH_WANTS_THP_SWAP if ARM64_4K_PAGES
      select ARCH_HAS_UBSAN_SANITIZE_ALL
      select ARM_AMBA
      select ARM_ARCH_TIMER
arch/arm64/include/asm/pgtable.h +0 -0
index 0b6632f18364..06076139c72c 100644
@@ -45,6 +45,8 @@
      __flush_tlb_range(vma, addr, end, PUD_SIZE, false, 1)
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
Quoted 5 lines

arch/arm64/include/asm/pgtable.h line 48

Quoted 1 line
arch/arm64/include/asm/pgtable.h +1 -0
+#define arch_thp_swp_supported !system_supports_mte

Does it check for 'system_supports_mte' as a symbol or call system_supports_mte() to ascertain runtime MTE support ? It might well be correct, but just does not look much intuitive.

yep. looks a bit weird. but considering we only need this for arm64 and arch_thp_swp_supported
is a macro, I can't find a better way to make code modification smaller than this in mm core, arm64
and x86. and probably we will totally remove it once we make MTE co-exist with THP_SWP.

Do you have any suggestions for a better solution?

Quoted 13 lines
Quoted 13 lines
arch/arm64/include/asm/pgtable.h +1 -0
+
 /*
  * Outside of a few very special situations (e.g. hibernation), we always
  * use broadcast TLB invalidation instructions, therefore a spurious page
include/linux/huge_mm.h +0 -0
index de29821231c9..4ddaf6ad73ef 100644
@@ -461,4 +461,16 @@ static inline int split_folio_to_list(struct folio *folio,
      return split_huge_page_to_list(&folio->page, list);
 }
 
Quoted 7 lines

include/linux/huge_mm.h static inline int split_folio_to_list(struct folio *folio, · line 466

Quoted 3 lines
include/linux/huge_mm.h +3 -0
+/*
+ * archs that select ARCH_WANTS_THP_SWAP but don't support THP_SWP due to
+ * limitations in the implementation like arm64 MTE can override this to

A small nit.

A 'comma' here will be better. s/arm64 MTE can/arm64 MTE, can/

yep.

Quoted 5 lines

include/linux/huge_mm.h static inline int split_folio_to_list(struct folio *folio, · line 467

Quoted 2 lines
include/linux/huge_mm.h +1 -0
+ * false

Similarly a 'full stop' here will be better as well.

yep.

Quoted 16 lines
Quoted 16 lines
include/linux/huge_mm.h +8 -0
+ */
+#ifndef arch_thp_swp_supported
+static inline bool arch_thp_swp_supported(void)
+{
+     return true;
+}
+#endif
+
 #endif /* _LINUX_HUGE_MM_H */
mm/swap_slots.c +0 -0
index 2a65a89b5b4d..10b94d64cc25 100644
@@ -307,7 +307,7 @@ swp_entry_t folio_alloc_swap(struct folio *folio)
      entry.val = 0;
 
Quoted 8 lines

mm/swap_slots.c swp_entry_t folio_alloc_swap(struct folio *folio) · line 313

Quoted 6 lines
mm/swap_slots.c +1 -1
      if (folio_test_large(folio)) {
-             if (IS_ENABLED(CONFIG_THP_SWAP))
+             if (IS_ENABLED(CONFIG_THP_SWAP) && arch_thp_swp_supported())
                      get_swap_pages(1, &entry, folio_nr_pages(folio));
              goto out;
      }

- Anshuman

Thanks
Barry

#3 lore raw
Quoted 40 lines · Barry Song
Quoted 2 lines · Anshuman Khandual

Hello Barry,

Hi Anshuman,
thanks!

Quoted 11 lines · Barry Song
Quoted 5 lines

From: Barry Song <[email protected]>

THP_SWAP has been proved to improve the swap throughput significantly on x86_64 according to commit bd4c82c22c367e ("mm, THP, swap: delay splitting THP after swapped out").

It will be useful to run similar experiments on arm64 platform to demonstrate tangible benefit, else we might be just enabling this feature just because x86 has it. Do you have some data points ?

Quoted 5 lines
Quoted 2 lines

As long as arm64 uses 4K page size, it is quite similar with x86_64 by having 2MB PMD THP. So we are going to get similar improvement.

This is an assumption without any data points (until now). Please do provide some results.

Fair enough though I believe THP_SWP is arch-independent. Our testing will post data. Plus, we do need it for real use cases with some possible out-of-tree code for this moment. so this patch does not originate only because x86 has it :-)

Quoted 10 lines
Quoted 4 lines

For other page sizes such as 16KB and 64KB, PMD might be too large. Negative side effects such as IO latency might be a problem. Thus, we can only safely enable the counterpart of X86_64.

Incorrect reasoning. Although sometimes it might be okay to enable a feature on platforms with possible assumptions about its benefits, but to claim 'similar improvement, safely, .. etc' while comparing against x86 4K page config without data points, is not very helpful.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

A corner case is that MTE has an assumption that only base pages can be swapped. We won't enable THP_SWP for ARM64 hardware with MTE support until MTE is re-arched.

re-arched ?? Did you imply that MTE is reworked to support THP ?

I think at least MTE should be able to coexist with THP_SWP though I am not quite sure if MTE can be re-worked to fully support THP.

There's no fundamental reason it cannot coexist, but there are many open areas around MTE support in general. For example at the moment swap support keeps the tags in memory because there's no easy way to plumb the extra tag data into the swap infrastructure.

The lazy zeroing of MTE tag storage has introduced a lot of complexity and THP is another case where this complexity would show. It's possible that it might make sense to take the hit of clearing tags in all pages (i.e. make clear_page() clear the tags like mte_zero_clear_page_tags()).

Quoted 44 lines
Quoted 38 lines
Quoted 38 lines
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 Anshuman Khandual <[email protected]>
Cc Steven Price <[email protected]>
Cc Yang Shi <[email protected]>
---
 arch/arm64/Kconfig               |  1 +
 arch/arm64/include/asm/pgtable.h |  2 ++
 include/linux/huge_mm.h          | 12 ++++++++++++
 mm/swap_slots.c                  |  2 +-
 4 files changed, 16 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +1 -0
index a4968845e67f..5306009df2dc 100644
@@ -101,6 +101,7 @@ config ARM64
      select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
      select ARCH_WANT_LD_ORPHAN_WARN
      select ARCH_WANTS_NO_INSTR
+     select ARCH_WANTS_THP_SWAP if ARM64_4K_PAGES
      select ARCH_HAS_UBSAN_SANITIZE_ALL
      select ARM_AMBA
      select ARM_ARCH_TIMER
arch/arm64/include/asm/pgtable.h +0 -0
index 0b6632f18364..06076139c72c 100644
@@ -45,6 +45,8 @@
      __flush_tlb_range(vma, addr, end, PUD_SIZE, false, 1)
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
Quoted 5 lines

arch/arm64/include/asm/pgtable.h line 48

Quoted 1 line
arch/arm64/include/asm/pgtable.h +1 -0
+#define arch_thp_swp_supported !system_supports_mte

Does it check for 'system_supports_mte' as a symbol or call system_supports_mte() to ascertain runtime MTE support ? It might well be correct, but just does not look much intuitive.

Quoted 8 lines

yep. looks a bit weird. but considering we only need this for arm64 and arch_thp_swp_supported
is a macro, I can't find a better way to make code modification smaller than this in mm core, arm64
and x86. and probably we will totally remove it once we make MTE co-exist with THP_SWP.

Do you have any suggestions for a better solution?

It would be better to write it as a function macro:

  #define arch_thp_swp_supported() (!system_supports_mte())

or you could go the whole way and introduce a static inline function (overkill in this case IMHO):

  #define arch_thp_swp_supported
  static inline bool arch_thp_swp_supported(void)
  {
  	return !system_supports_mte();
  }

Otherwise it looks like arch_thp_swp_supported is dependent on the symbol system_supports_mte being NULL (not on the return from the function).

Steve

Quoted 58 lines
Quoted 13 lines
Quoted 13 lines
arch/arm64/include/asm/pgtable.h +1 -0
+
 /*
  * Outside of a few very special situations (e.g. hibernation), we always
  * use broadcast TLB invalidation instructions, therefore a spurious page
include/linux/huge_mm.h +0 -0
index de29821231c9..4ddaf6ad73ef 100644
@@ -461,4 +461,16 @@ static inline int split_folio_to_list(struct folio *folio,
      return split_huge_page_to_list(&folio->page, list);
 }
 
Quoted 7 lines

include/linux/huge_mm.h static inline int split_folio_to_list(struct folio *folio, · line 466

Quoted 3 lines
include/linux/huge_mm.h +3 -0
+/*
+ * archs that select ARCH_WANTS_THP_SWAP but don't support THP_SWP due to
+ * limitations in the implementation like arm64 MTE can override this to

A small nit.

A 'comma' here will be better. s/arm64 MTE can/arm64 MTE, can/

yep.

Quoted 5 lines

include/linux/huge_mm.h static inline int split_folio_to_list(struct folio *folio, · line 467

Quoted 2 lines
include/linux/huge_mm.h +1 -0
+ * false

Similarly a 'full stop' here will be better as well.

yep.

Quoted 16 lines
Quoted 16 lines
include/linux/huge_mm.h +8 -0
+ */
+#ifndef arch_thp_swp_supported
+static inline bool arch_thp_swp_supported(void)
+{
+     return true;
+}
+#endif
+
 #endif /* _LINUX_HUGE_MM_H */
mm/swap_slots.c +0 -0
index 2a65a89b5b4d..10b94d64cc25 100644
@@ -307,7 +307,7 @@ swp_entry_t folio_alloc_swap(struct folio *folio)
      entry.val = 0;
 
Quoted 8 lines

mm/swap_slots.c swp_entry_t folio_alloc_swap(struct folio *folio) · line 313

Quoted 6 lines
mm/swap_slots.c +1 -1
      if (folio_test_large(folio)) {
-             if (IS_ENABLED(CONFIG_THP_SWAP))
+             if (IS_ENABLED(CONFIG_THP_SWAP) && arch_thp_swp_supported())
                      get_swap_pages(1, &entry, folio_nr_pages(folio));
              goto out;
      }

- Anshuman

Thanks
Barry

#4 lore raw
Quoted 117 lines · Steven Price
Quoted 40 lines · Barry Song
Quoted 2 lines · Anshuman Khandual

Hello Barry,

Hi Anshuman,
thanks!

Quoted 11 lines · Barry Song
Quoted 5 lines

From: Barry Song <[email protected]>

THP_SWAP has been proved to improve the swap throughput significantly on x86_64 according to commit bd4c82c22c367e ("mm, THP, swap: delay splitting THP after swapped out").

It will be useful to run similar experiments on arm64 platform to demonstrate tangible benefit, else we might be just enabling this feature just because x86 has it. Do you have some data points ?

Quoted 5 lines
Quoted 2 lines

As long as arm64 uses 4K page size, it is quite similar with x86_64 by having 2MB PMD THP. So we are going to get similar improvement.

This is an assumption without any data points (until now). Please do provide some results.

Fair enough though I believe THP_SWP is arch-independent. Our testing will post data. Plus, we do need it for real use cases with some possible out-of-tree code for this moment. so this patch does not originate only because x86 has it :-)

Quoted 10 lines
Quoted 4 lines

For other page sizes such as 16KB and 64KB, PMD might be too large. Negative side effects such as IO latency might be a problem. Thus, we can only safely enable the counterpart of X86_64.

Incorrect reasoning. Although sometimes it might be okay to enable a feature on platforms with possible assumptions about its benefits, but to claim 'similar improvement, safely, .. etc' while comparing against x86 4K page config without data points, is not very helpful.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

A corner case is that MTE has an assumption that only base pages can be swapped. We won't enable THP_SWP for ARM64 hardware with MTE support until MTE is re-arched.

re-arched ?? Did you imply that MTE is reworked to support THP ?

I think at least MTE should be able to coexist with THP_SWP though I am not quite sure if MTE can be re-worked to fully support THP.

There's no fundamental reason it cannot coexist, but there are many open areas around MTE support in general. For example at the moment swap support keeps the tags in memory because there's no easy way to plumb the extra tag data into the swap infrastructure.

The lazy zeroing of MTE tag storage has introduced a lot of complexity and THP is another case where this complexity would show. It's possible that it might make sense to take the hit of clearing tags in all pages (i.e. make clear_page() clear the tags like mte_zero_clear_page_tags()).

Quoted 44 lines
Quoted 38 lines
Quoted 38 lines
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 Anshuman Khandual <[email protected]>
Cc Steven Price <[email protected]>
Cc Yang Shi <[email protected]>
---
 arch/arm64/Kconfig               |  1 +
 arch/arm64/include/asm/pgtable.h |  2 ++
 include/linux/huge_mm.h          | 12 ++++++++++++
 mm/swap_slots.c                  |  2 +-
 4 files changed, 16 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +1 -0
index a4968845e67f..5306009df2dc 100644
@@ -101,6 +101,7 @@ config ARM64
      select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
      select ARCH_WANT_LD_ORPHAN_WARN
      select ARCH_WANTS_NO_INSTR
+     select ARCH_WANTS_THP_SWAP if ARM64_4K_PAGES
      select ARCH_HAS_UBSAN_SANITIZE_ALL
      select ARM_AMBA
      select ARM_ARCH_TIMER
arch/arm64/include/asm/pgtable.h +0 -0
index 0b6632f18364..06076139c72c 100644
@@ -45,6 +45,8 @@
      __flush_tlb_range(vma, addr, end, PUD_SIZE, false, 1)
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
Quoted 5 lines

arch/arm64/include/asm/pgtable.h line 48

Quoted 1 line
arch/arm64/include/asm/pgtable.h +1 -0
+#define arch_thp_swp_supported !system_supports_mte

Does it check for 'system_supports_mte' as a symbol or call system_supports_mte() to ascertain runtime MTE support ? It might well be correct, but just does not look much intuitive.

Quoted 8 lines

yep. looks a bit weird. but considering we only need this for arm64 and arch_thp_swp_supported
is a macro, I can't find a better way to make code modification smaller than this in mm core, arm64
and x86. and probably we will totally remove it once we make MTE co-exist with THP_SWP.

Do you have any suggestions for a better solution?

It would be better to write it as a function macro:

  #define arch_thp_swp_supported() (!system_supports_mte())
Quoted 8 lines

or you could go the whole way and introduce a static inline function (overkill in this case IMHO):

  #define arch_thp_swp_supported
  static inline bool arch_thp_swp_supported(void)
  {
  	return !system_supports_mte();
  }

I guess this approach is slightly better.

#5 lore raw
In reply to Barry Song
Quoted 22 lines · Barry Song
Quoted 2 lines · Anshuman Khandual

Hello Barry,

Hi Anshuman,
thanks!

Quoted 14 lines · Barry Song
Quoted 5 lines

From: Barry Song <[email protected]>

THP_SWAP has been proved to improve the swap throughput significantly on x86_64 according to commit bd4c82c22c367e ("mm, THP, swap: delay splitting THP after swapped out").

It will be useful to run similar experiments on arm64 platform to demonstrate tangible benefit, else we might be just enabling this feature just because x86 has it. Do you have some data points ?

Quoted 2 lines

As long as arm64 uses 4K page size, it is quite similar with x86_64 by having 2MB PMD THP. So we are going to get similar improvement.

Quoted 7 lines
Quoted 2 lines

This is an assumption without any data points (until now). Please do provide some results.

Fair enough though I believe THP_SWP is arch-independent. Our testing will post data. Plus, we do need it for real use cases with some possible out-of-tree code for this moment. so this patch does not originate only because x86 has it :-)

I understand, but as you mentioned some data here will be helpful.

Quoted 11 lines
Quoted 11 lines
Quoted 5 lines

For other page sizes such as 16KB and 64KB, PMD might be too large. Negative side effects such as IO latency might be a problem. Thus, we can only safely enable the counterpart of X86_64.

Incorrect reasoning. Although sometimes it might be okay to enable a feature on platforms with possible assumptions about its benefits, but to claim 'similar improvement, safely, .. etc' while comparing against x86 4K page config without data points, is not very helpful.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

A corner case is that MTE has an assumption that only base pages can be swapped. We won't enable THP_SWP for ARM64 hardware with MTE support until MTE is re-arched.

re-arched ?? Did you imply that MTE is reworked to support THP ?

I think at least MTE should be able to coexist with THP_SWP though I am not quite sure if MTE can be re-worked to fully support THP.

Understood but I just wanted the wording above in the commit message to be changed to literally anything other than 're-arched'.

maintainer
#6 lore raw
In reply to Barry Song
Quoted 19 lines · On Fri, 27 May 2022 22:06:44 +1200 Barry Song <[email protected]> wrote:

From: Barry Song <[email protected]>

THP_SWAP has been proved to improve the swap throughput significantly on x86_64 according to commit bd4c82c22c367e ("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. So we are going to get similar improvement. For other page sizes such as 16KB and 64KB, PMD might be too large. Negative side effects such as IO latency might be a problem. Thus, we can only safely enable the counterpart of X86_64.
A corner case is that MTE has an assumption that only base pages can be swapped. We won't enable THP_SWP for ARM64 hardware with MTE support until MTE is re-arched.

...

arch/arm64/include/asm/pgtable.h line 48

Quoted 4 lines
arch/arm64/include/asm/pgtable.h +1 -0
@@ -45,6 +45,8 @@
 	__flush_tlb_range(vma, addr, end, PUD_SIZE, false, 1)
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
+#define arch_thp_swp_supported !system_supports_mte

Does that even work?

if (arch_thp_swp_supported())

expands to

	if (!system_supports_mte())

so I guess it does work. Is this ugly party trick required for some reason? If so, an apologetic comment describing why would be helpful.

Otherwise, can we use a static inline function here, as we do with the stub function?

Quoted 6 lines
include/linux/huge_mm.h +0 -0
@@ -461,4 +461,16 @@ static inline int split_folio_to_list(struct folio *folio,
 	return split_huge_page_to_list(&folio->page, list);
 }
 

include/linux/huge_mm.h static inline int split_folio_to_list(struct folio *folio, · line 473

Quoted 10 lines
include/linux/huge_mm.h +10 -0
+/*
+ * archs that select ARCH_WANTS_THP_SWAP but don't support THP_SWP due to
+ * limitations in the implementation like arm64 MTE can override this to
+ * false
+ */
+#ifndef arch_thp_swp_supported
+static inline bool arch_thp_swp_supported(void)
+{
+	return true;
+}

Missing a #define arch_thp_swp_supported arch_thp_swp_supported here.

include/linux/huge_mm.h static inline int split_folio_to_list(struct folio *folio, · line 476

Quoted 3 lines
include/linux/huge_mm.h +2 -0
+#endif
+
 #endif /* _LINUX_HUGE_MM_H */

Otherwise looks OK to me. Please include it in the arm64 tree if/when it's considered ready.