From: Alexandre Ghiti <alex@ghiti.fr>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Kairui Song <kasong@tencent.com>, Barry Song <baohua@kernel.org>,
Chris Li <chrisl@kernel.org>,
Kemeng Shi <shikemeng@huaweicloud.com>,
Nhat Pham <nphamcs@gmail.com>, Baoquan He <baoquan.he@linux.dev>,
Youngjun Park <youngjun.park@lge.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Hugh Dickins <hughd@google.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
David Hildenbrand <david@kernel.org>,
Michal Hocko <mhocko@kernel.org>, Qi Zheng <qi.zheng@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Lorenzo Stoakes <ljs@kernel.org>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Alexandre Ghiti <alex@ghiti.fr>
Subject: [PATCH v2 0/1] mm, swap: only prefer nonfull clusters on synchronous devices
Date: Thu, 5 Nov 2026 16:50:16 +0100 [thread overview]
Message-ID: <20261105155032.240457-1-alex@ghiti.fr> (raw)
7.3 regressed swap I/O: for the same swap volume, a workload that
rewrites swapped out memory sends many more requests to the device.
mysql/sysbench in a 256M memcg swapping to an NVMe partition, 7.3
compared to the previous version:
device read requests per transaction +59%
device write requests per transaction +27%
throughput, iocost off no change
throughput, iocost on -19%
Two commits interact:
- Commit 9a42aed48421 ("mm, swap: prefer nonfull over free clusters"),
in 6.18, makes allocations fill the nonfull clusters of their order
before taking a free one.
- Commit 3cedb745d354 ("mm: clarify the folio_free_swap() for
do_swap_page()"), in 7.3, frees the swap slot on an exclusive write
fault. 7.0 to 7.2 kept the slot, but only as a side effect of commit
4b34f1d82c65 ("mm, swap: free the swap cache after folio is
mapped").
The freed slots leave holes in full clusters, which then go back on
the nonfull list. Reclaim allocates slots one folio at a time and
merges the writes afterwards, so a batch of LRU-adjacent folios gets
scattered over those holes and is written with many small requests.
Readahead later finds those pages scattered as well, and needs more
read requests to bring them back.
The RFC [1] listed three fixes, which perform similarly:
A. Revert 3cedb745d354. This keeps the slot on write fault, but undoes
the intent of that commit and keeps swap space pinned under dirty
pages.
B. Below 50% swap usage, make order-0 allocations take a free cluster
before a nonfull one. This is what the allocator already does, at
any usage, on swap devices with discard enabled (swapon
--discard=pages). The threshold is arbitrary and it stops working
as swap fills up.
C. The RFC patch. Reclaim tells the allocator how many pages of each
small order the batch is about to swap out, and those allocations
then follow contiguous free slots.
In the RFC thread, Kairui suggested another option, which he prefers
[2]: keep nonfull-first only on synchronous devices like zram, which
don't merge I/O and where filling holes first keeps the free clusters
for large folios, and go back to preferring free clusters on every
other device, as discard devices already do. This is what v2 does. It
is a few lines, needs no information from reclaim, and performs as
well as C.
Same workload as above, each fix relative to its base kernel:
RFC (C) v2
device read requests per transaction -12% -14%
device write requests per transaction -36% -48%
throughput, iocost off no change no change
throughput, iocost on +41% +33%
Changes since RFC:
- Replace the batch-aware slot allocation with keeping nonfull-first
for synchronous devices only, as suggested by Kairui.
[1] https://lore.kernel.org/linux-mm/20261022145615.2184343-1-alex@ghiti.fr/
[2] https://lore.kernel.org/linux-mm/CAMgjq7BFbXEKEt9faj_rg5AStfLkpJ0j57EQOOJ+L3-w2xRvtg@mail.gmail.com/
Alexandre Ghiti (1):
mm, swap: only prefer nonfull clusters on synchronous devices
mm/swapfile.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
base-commit: afb4eea28037fa55c4560313ecbd8a1e1da8369a
next reply other threads:[~2026-11-05 15:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 15:50 Alexandre Ghiti [this message]
2026-11-05 15:50 ` [PATCH v2 1/1] " Alexandre Ghiti
2026-11-05 16:26 ` Nhat Pham
2026-11-07 10:58 ` Kairui Song
2026-11-09 9:00 ` Alexandre Ghiti
2026-11-09 23:24 ` Andrew Morton
2026-11-10 8:14 ` Alexandre Ghiti
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=20261105155032.240457-1-alex@ghiti.fr \
--to=alex@ghiti.fr \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=chrisl@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=nphamcs@gmail.com \
--cc=qi.zheng@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=shikemeng@huaweicloud.com \
--cc=weixugc@google.com \
--cc=youngjun.park@lge.com \
--cc=yuanchu@google.com \
/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
all inboxes | Powered by JetHome®