From: Wei Yang <richard.weiyang@gmail.com>
To: akpm@linux-foundation.org, david@kernel.org,
lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com,
vbabka@suse.cz, rppt@kernel.org, surenb@google.com,
mhocko@suse.com
Cc: linux-mm@kvack.org, hanchuanhua@oppo.com, v-songbaohua@oppo.com,
Wei Yang <richard.weiyang@gmail.com>
Subject: [PATCH 0/3] mm/memory: align alloc_swap_folio() logic with alloc_anon_folio()
Date: Tue, 16 Dec 2025 07:59:41 +0000 [thread overview]
Message-ID: <20251216075943.29593-1-richard.weiyang@gmail.com> (raw)
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
next reply other threads:[~2025-12-16 8:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-16 7:59 Wei Yang [this message]
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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251216075943.29593-1-richard.weiyang@gmail.com \
--to=richard.weiyang@gmail.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=hanchuanhua@oppo.com \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=v-songbaohua@oppo.com \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox