linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] mm/memory: align alloc_swap_folio() logic with alloc_anon_folio()
@ 2025-12-16  7:59 Wei Yang
  2025-12-16  7:59 ` [PATCH 1/2] mm: bail out do_swap_page() when no PTE table exist Wei Yang
  2025-12-16  7:59 ` [PATCH 2/2] mm: avoid unnecessary PTE table lock during initial swap folio scan Wei Yang
  0 siblings, 2 replies; 9+ messages in thread
From: Wei Yang @ 2025-12-16  7:59 UTC (permalink / raw)
  To: akpm, david, lorenzo.stoakes, Liam.Howlett, vbabka, rppt, surenb, mhocko
  Cc: linux-mm, hanchuanhua, v-songbaohua, Wei Yang

This series cleans up the logic used when swapping in large folios to bring it
in line with the established patterns in alloc_anon_folio().

Context:

When swapping in a large folio, the kernel performs a process similar to
alloc_anon_folio(): it scans the PTE range to determine the highest suitable
order for a large folio and then attempts allocation. However, two key
discrepancies currently exist in alloc_swap_folio():

  1. Improper Fallback: It currently falls back to an order-0 folio if
     pte_offset_map_lock() returns NULL.
  2. Unnecessary Locking: It locks the page table during the initial scanning
     phase.

Improvements:

Based on an analysis of the alloc_anon_folio() implementation, this series
applies the following corrections to the swap-in path:

  1. Bail out on NULL PTE: If pte_offset_map_lock() returns NULL, it indicates
     the page table has changed under us. In this scenario, the operation is
     likely to fail later anyway; continuing the process is inefficient and
     unnecessary.

  2. Lockless Initial Scan: The initial scan only reads PTEs to determine the
     appropriate folio order. Since no modifications are made at this stage,
     and the table is re-verified and locked before the actual write, the
     initial lock is redundant. Removing it reduces lock contention and system
     load.

Wei Yang (2):
  mm: bail out do_swap_page() when no PTE table exist
  mm: avoid unnecessary PTE table lock during initial swap folio scan

 mm/memory.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

-- 
2.34.1



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

end of thread, other threads:[~2025-12-21  9:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-16  7:59 [PATCH 0/3] mm/memory: align alloc_swap_folio() logic with alloc_anon_folio() Wei Yang
2025-12-16  7:59 ` [PATCH 1/2] mm: bail out do_swap_page() when no PTE table exist Wei Yang
2025-12-19  8:42   ` David Hildenbrand (Red Hat)
2025-12-20  3:24     ` Wei Yang
2025-12-21  9:40       ` David Hildenbrand (Red Hat)
2025-12-16  7:59 ` [PATCH 2/2] mm: avoid unnecessary PTE table lock during initial swap folio scan Wei Yang
2025-12-19  8:47   ` David Hildenbrand (Red Hat)
2025-12-20  3:36     ` Wei Yang
2025-12-21  9:47       ` David Hildenbrand (Red Hat)

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