mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RFC 0/8] mm/huge_memory: clean up and speed up large folio splitting
@ 2026-11-13 21:26 Kairui Song via B4 Relay
  2026-11-13 21:26 ` [PATCH RFC 1/8] mm: add folio_prev() Kairui Song via B4 Relay
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: Kairui Song via B4 Relay @ 2026-11-13 21:26 UTC (permalink / raw)
  To: linux-mm
  Cc: David Hildenbrand, Lorenzo Stoakes, Liam R. Howlett,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
	Matthew Wilcox, Andrew Morton, Johannes Weiner, Michal Hocko,
	Qi Zheng, Shakeel Butt, Barry Song, Axel Rasmussen, Yuanchu Xie,
	Wei Xu, Baoquan He, Baolin Wang, Zi Yan, Nico Pache,
	Ryan Roberts, Dev Jain, Lance Yang, Usama Arif, Kiryl Shutsemau,
	linux-kernel, linux-fsdevel, Kairui Song

Hi all,

This series slghtly cleans up the large folio split path and reduces
its overhead: uniformly splitting PMD sized file folios to order 0
is over 20% faster.

I realize this might not be the best time for pushing more optimizations,
but I am posting this as an early RFC as it adds two helpers, folio_prev()
and xas_prev_canonical(), and uses them to walk the after-split folios
in reverse, saving a few local variables, avoiding a for-loop pitfall [1],
and publishing the folios with a single Xarray walk.

Walking backwards also changes the order the pieces are put on the LRU or
the reclaim list: they are now in ascending order instead of descending,
which is the actually intended order. The effect was not very
measurable though.

New code is mostly the two helpers and an Xarray selftest. The change to
mm/huge_memory.c is LOC-neutral.

Worth noting (not part of the series): I found these useful while
preparation for supporting all kinds of folio splitting folios in the
swap cache. I also tried to get rid of lruvec lock for the splitting,
or at least decouple the lock and reduce lock scope of it. It turns out,
not cleanly doable at this moment, and the main blocker is: MGLRU.
MGLRU will read a folio's size without holding a ref, solely depending
on the LRU lock to stabilize. To improve this, another rework of MGLRU's
reclaim progress is needed (which will also cover the problem fount by
the MGLRU-FG series that MGLRU sometime have a higher contention than
CLRU on reclaim isolation).

Testing
=======

Split overhead on a 32 vCPU x86-64 KVM guest, 31 GiB RAM, 4K base
pages, 2M THP.  Split a 1 GiB shmem file (512 PMD-sized folios)
uniformly to order 0 through /sys/kernel/debug/split_huge_pages and
time that single write with bash's `time`.  Medians over 12
interleaved rounds per kernel

Test script:
   mount -t tmpfs -o size=2G,huge=always tmpfs /mnt
   fallocate -l 1G /mnt/big
   time echo /mnt/big,0x0,0x40000,0 > /sys/kernel/debug/split_huge_pages
   rm -f /mnt/big
   umount /mnt

Result:
                        Before        After
real                    17 ms        13 ms   (-24%)
sys                     17 ms        13 ms   (-24%)

End to end test showed no regression.

Signed-off-by: Kairui Song <kasong@tencent.com>
---
Kairui Song (8):
      mm: add folio_prev()
      xarray: add xas_prev_canonical()
      mm/huge_memory: avoid an unnecessary folio size reading
      mm/huge_memory: walk the after-split file folios in reverse order
      mm/huge_memory: publish split folios by walking backwards
      mm/huge_memory: rearrange split routine handling for better optimization
      mm/huge_memory: walk the after-split anon folios in reverse order
      mm/huge_memory: walk the folios reversely for the release loop

 include/linux/mm.h     |  23 +++++++++++
 include/linux/xarray.h |  49 +++++++++++++++++++++++
 lib/test_xarray.c      |  97 +++++++++++++++++++++++++++++++++++++++++++++
 lib/xarray.c           |   8 ----
 mm/huge_memory.c       | 105 +++++++++++++++++++++++++------------------------
 5 files changed, 222 insertions(+), 60 deletions(-)
---
base-commit: fae273e48c398c56b819151a607a6c8792dadef0
change-id: 20260915-swap-thp-split-0f86b554b42e

Best regards,
--  
Kairui Song <kasong@tencent.com>



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-11-13 21:47 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13 21:26 [PATCH RFC 0/8] mm/huge_memory: clean up and speed up large folio splitting Kairui Song via B4 Relay
2026-11-13 21:26 ` [PATCH RFC 1/8] mm: add folio_prev() Kairui Song via B4 Relay
2026-11-13 21:26 ` [PATCH RFC 2/8] xarray: add xas_prev_canonical() Kairui Song via B4 Relay
2026-11-13 21:26 ` [PATCH RFC 3/8] mm/huge_memory: avoid an unnecessary folio size reading Kairui Song via B4 Relay
2026-11-13 21:26 ` [PATCH RFC 4/8] mm/huge_memory: walk the after-split file folios in reverse order Kairui Song via B4 Relay
2026-11-13 21:26 ` [PATCH RFC 5/8] mm/huge_memory: publish split folios by walking backwards Kairui Song via B4 Relay
2026-11-13 21:26 ` [PATCH RFC 6/8] mm/huge_memory: rearrange split routine handling for better optimization Kairui Song via B4 Relay
2026-11-13 21:26 ` [PATCH RFC 7/8] mm/huge_memory: walk the after-split anon folios in reverse order Kairui Song via B4 Relay
2026-11-13 21:26 ` [PATCH RFC 8/8] mm/huge_memory: walk the folios reversely for the release loop Kairui Song via B4 Relay
2026-11-13 21:40 ` [PATCH RFC 0/8] mm/huge_memory: clean up and speed up large folio splitting David Hildenbrand (Arm)
2026-11-13 21:46   ` Kairui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®