mm/shmem: bypass swap readahead for zswap
Subsystems (2)
PATCH 1/1 mm/shmem: bypass swap readahead for zswap
Commit 7ed825f0f766 ("mm: bypass swap readahead for zswap") made do_swap_page() skip readahead for zswap entries, but shmem_swapin_folio() still only skips it for SWP_SYNCHRONOUS_IO devices.
zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use swap_entry_synchronous() in shmem_swapin_folio(), like do_swap_page(). zswap entries then take the SWP_SYNCHRONOUS_IO path, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.
On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
--- mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/shmem.c +2 -2
@@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,/* Look it up and read it in.. */ folio =swap_cache_get_folio (swap);if (!folio) { -if (data_race (si->flags &SWP_SYNCHRONOUS_IO )) { -/* Direct swapin skipping swap cache & readahead */ +if (swap_entry_synchronous (si, swap)) { +/* Skip readahead: synchronous device or zswap */ folio =shmem_swap_alloc_folio (inode, vmf, index, swap, order, gfp); }else {
Signature · 1 line
2.53.1-Meta
Quoted 16 lines · Usama Arif
Commit
7ed825f0f766("mm: bypass swap readahead for zswap") madedo_swap_page()skip readahead for zswap entries, butshmem_swapin_folio()still only skips it forSWP_SYNCHRONOUS_IOdevices.zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use
swap_entry_synchronous()inshmem_swapin_folio(), likedo_swap_page(). zswap entries then take theSWP_SYNCHRONOUS_IOpath, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.
Quoted 8 lines
On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
Signed-off-by Usama Arif <[email protected]>
Quoted 16 lines · Usama Arif
Commit
7ed825f0f766("mm: bypass swap readahead for zswap") madedo_swap_page()skip readahead for zswap entries, butshmem_swapin_folio()still only skips it forSWP_SYNCHRONOUS_IOdevices.zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use
swap_entry_synchronous()inshmem_swapin_folio(), likedo_swap_page(). zswap entries then take theSWP_SYNCHRONOUS_IOpath, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.
Quoted 8 lines
On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
Signed-off-by Usama Arif <[email protected]>
Quoted 15 lines · Usama Arif
Commit
7ed825f0f766("mm: bypass swap readahead for zswap") madedo_swap_page()skip readahead for zswap entries, butshmem_swapin_folio()still only skips it forSWP_SYNCHRONOUS_IOdevices.zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use
swap_entry_synchronous()inshmem_swapin_folio(), likedo_swap_page(). zswap entries then take theSWP_SYNCHRONOUS_IOpath, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.
Quoted 8 lines
On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
Signed-off-by Usama Arif <[email protected]>
Acked-by Shakeel Butt <[email protected]>
Andrew Morton
maintainerQuoted 1 line · On Thu, 3 Dec 2026 10:02:53 -0800 Usama Arif <[email protected]> wrote:
Commit
7ed825f0f766("mm: bypass swap readahead for zswap")
That's in mm-unstable.
Quoted 27 lines
made
do_swap_page()skip readahead for zswap entries, butshmem_swapin_folio()still only skips it forSWP_SYNCHRONOUS_IOdevices.zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use
swap_entry_synchronous()inshmem_swapin_folio(), likedo_swap_page(). zswap entries then take theSWP_SYNCHRONOUS_IOpath, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
...
mm/shmem.c static int shmem_swapin_folio(struct inode *inode, pgoff_t index, · line 2577
Quoted 10 lines
mm/shmem.c +2
-2@@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,/* Look it up and read it in.. */ folio =swap_cache_get_folio (swap);if (!folio) { -if (data_race (si->flags &SWP_SYNCHRONOUS_IO )) { -/* Direct swapin skipping swap cache & readahead */ +if (swap_entry_synchronous (si, swap)) { +/* Skip readahead: synchronous device or zswap */ folio =shmem_swap_alloc_folio (inode, vmf, index, swap, order, gfp); }else {
So I'll add this as a squashable fix against Alexandre's "mm: bypass swap readahead for zswap" if that's OK.
+ mm-bypass-swap-readahead-for-zswap-fix.patch added to mm-unstable branch
In reply to Usama ArifThe patch titled Subject: mm/shmem: bypass swap readahead for zswap has been added to the -mm mm-unstable branch. Its filename is mm-bypass-swap-readahead-for-zswap-fix.patch
The patch titled
Subject: mm/shmem: bypass swap readahead for zswap
has been added to the -mm mm-unstable branch. Its filename is
mm-bypass-swap-readahead-for-zswap-fix.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-bypass-swap-readahead-for-zswap-fix.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Usama Arif <[email protected]>
Subject: mm/shmem: bypass swap readahead for zswap
Date: Thu, 3 Dec 2026 10:02:53 -0800
Commit 7ed825f0f766 ("mm: bypass swap readahead for zswap") made do_swap_page() skip readahead for zswap entries, but shmem_swapin_folio() still only skips it for SWP_SYNCHRONOUS_IO devices.
zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use swap_entry_synchronous() in shmem_swapin_folio(), like do_swap_page(). zswap entries then take the SWP_SYNCHRONOUS_IO path, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.
On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/shmem.c renamed from mm/shmem.c~mm-bypass-swap-readahead-for-zswap-fix +2 -2
@@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct ino/* Look it up and read it in.. */ folio =swap_cache_get_folio (swap);if (!folio) { -if (data_race (si->flags &SWP_SYNCHRONOUS_IO )) { -/* Direct swapin skipping swap cache & readahead */ +if (swap_entry_synchronous (si, swap)) { +/* Skip readahead: synchronous device or zswap */ folio =shmem_swap_alloc_folio (inode, vmf, index, swap, order, gfp); }else {
_
Patches currently in -mm which might be from [email protected] are
mm-zswap-use-separate-compression-and-decompression-requests.patch mm-zswap-use-stack-requests-for-synchronous-decompression.patch mm-bypass-swap-readahead-for-zswap-fix.patch fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps.patch fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps.patch
Quoted 30 lines · Andrew Morton
Quoted 1 line · On Thu, 3 Dec 2026 10:02:53 -0800 Usama Arif <[email protected]> wrote:
Commit
7ed825f0f766("mm: bypass swap readahead for zswap")That's in mm-unstable.
Quoted 24 lines
made
do_swap_page()skip readahead for zswap entries, butshmem_swapin_folio()still only skips it forSWP_SYNCHRONOUS_IOdevices.zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use
swap_entry_synchronous()inshmem_swapin_folio(), likedo_swap_page(). zswap entries then take theSWP_SYNCHRONOUS_IOpath, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
...
Quoted 16 lines
mm/shmem.c static int shmem_swapin_folio(struct inode *inode, pgoff_t index, · line 2577
Quoted 13 lines
mm/shmem.c +2
-2@@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,/* Look it up and read it in.. */ folio =swap_cache_get_folio (swap);if (!folio) { -if (data_race (si->flags &SWP_SYNCHRONOUS_IO )) { -/* Direct swapin skipping swap cache & readahead */ +if (swap_entry_synchronous (si, swap)) { +/* Skip readahead: synchronous device or zswap */ folio =shmem_swap_alloc_folio (inode, vmf, index, swap, order, gfp); }else {So I'll add this as a squashable fix against Alexandre's "mm: bypass swap readahead for zswap" if that's OK.
Ah its not really a fix, it can go in separately.
Thanks!
Usama
+ mm-shmem-bypass-swap-readahead-for-zswap.patch added to mm-unstable branch
In reply to Usama ArifThe patch titled Subject: mm/shmem: bypass swap readahead for zswap has been added to the -mm mm-unstable branch. Its filename is mm-shmem-bypass-swap-readahead-for-zswap.patch
The patch titled
Subject: mm/shmem: bypass swap readahead for zswap
has been added to the -mm mm-unstable branch. Its filename is
mm-shmem-bypass-swap-readahead-for-zswap.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-shmem-bypass-swap-readahead-for-zswap.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Usama Arif <[email protected]>
Subject: mm/shmem: bypass swap readahead for zswap
Date: Thu, 3 Dec 2026 10:02:53 -0800
Commit 7ed825f0f766 ("mm: bypass swap readahead for zswap") made do_swap_page() skip readahead for zswap entries, but shmem_swapin_folio() still only skips it for SWP_SYNCHRONOUS_IO devices.
zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use swap_entry_synchronous() in shmem_swapin_folio(), like do_swap_page(). zswap entries then take the SWP_SYNCHRONOUS_IO path, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.
On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/shmem.c renamed from mm/shmem.c~mm-shmem-bypass-swap-readahead-for-zswap +2 -2
@@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct ino/* Look it up and read it in.. */ folio =swap_cache_get_folio (swap);if (!folio) { -if (data_race (si->flags &SWP_SYNCHRONOUS_IO )) { -/* Direct swapin skipping swap cache & readahead */ +if (swap_entry_synchronous (si, swap)) { +/* Skip readahead: synchronous device or zswap */ folio =shmem_swap_alloc_folio (inode, vmf, index, swap, order, gfp); }else {
_
Patches currently in -mm which might be from [email protected] are
mm-zswap-use-separate-compression-and-decompression-requests.patch mm-zswap-use-stack-requests-for-synchronous-decompression.patch mm-shmem-bypass-swap-readahead-for-zswap.patch fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps.patch fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps.patch
Quoted 10 lines · On Thu, 3 Dec 2026 10:02:53 -0800 Usama Arif <[email protected]> wrote:
Commit
7ed825f0f766("mm: bypass swap readahead for zswap") madedo_swap_page()skip readahead for zswap entries, butshmem_swapin_folio()still only skips it forSWP_SYNCHRONOUS_IOdevices.zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Quoted 4 lines
Use
swap_entry_synchronous()inshmem_swapin_folio(), likedo_swap_page(). zswap entries then take theSWP_SYNCHRONOUS_IOpath, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.
Makes sense to me.
Quoted 7 lines
On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
Thank you for sharing the data.
Quoted 2 lines
Signed-off-by Usama Arif <[email protected]>
Thanks,
SJ
[...]
Barry Song
Reviewed-byQuoted 4 lines · Usama Arif
On 03/12/2026 12:03, Andrew Morton wrote:
[...]
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
mm/shmem.c +0
-2@@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,/* Look it up and read it in.. */ folio =swap_cache_get_folio (swap);if (!folio) { -if (data_race (si->flags &SWP_SYNCHRONOUS_IO )) { -/* Direct swapin skipping swap cache & readahead */ Quoted 8 lines
mm/shmem.c static int shmem_swapin_folio(struct inode *inode, pgoff_t index, · line 2577
Quoted 5 lines
mm/shmem.c +2
-0+if (swap_entry_synchronous (si, swap)) { +/* Skip readahead: synchronous device or zswap */ folio =shmem_swap_alloc_folio (inode, vmf, index, swap, order, gfp); }else {So I'll add this as a squashable fix against Alexandre's "mm: bypass swap readahead for zswap" if that's OK.
Quoted 1 line
Ah its not really a fix, it can go in separately.
I agree this is not a fix. It's essentially the same thing in two different modules.
BTW, the do_swap_page() change is still in mm-unstable. Is the referenced commit ID stable?
I checked today's mm-unstable and found the following:
"Object 7ed825f0f766 is not on branch mm-unstable"
So I think we should update the changelog to drop the commit ID.
Otherwise,
Quoted 22 lines · Usama Arif
Commit
7ed825f0f766("mm: bypass swap readahead for zswap") madedo_swap_page()skip readahead for zswap entries, butshmem_swapin_folio()still only skips it forSWP_SYNCHRONOUS_IOdevices.zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use
swap_entry_synchronous()inshmem_swapin_folio(), likedo_swap_page(). zswap entries then take theSWP_SYNCHRONOUS_IOpath, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
Quoted 2 lines
Signed-off-by Usama Arif <[email protected]>---
As Andrew pointed out, the unstable commit id should be avoided. Otherwise LGTM.
Thanks, this looks good.
Quoted 8 lines · Barry Song
Quoted 4 lines · Usama Arif
On 03/12/2026 12:03, Andrew Morton wrote:
[...]
Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
So I'll add this as a squashable fix against Alexandre's "mm: bypass swap readahead for zswap" if that's OK.
Ah its not really a fix, it can go in separately.
I agree this is not a fix. It's essentially the same thing in two different modules.
I guess I'll route that through the mm-core tree then? @Andrew please drop it.
Signature · 3 lines
Cheers, David
David Hildenbrand
AppliedQuoted 11 lines · Usama Arif
Commit
7ed825f0f766("mm: bypass swap readahead for zswap") madedo_swap_page()skip readahead for zswap entries, butshmem_swapin_folio()still only skips it forSWP_SYNCHRONOUS_IOdevices.zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
[...]
Applied, thanks!
tree: mm/core.git
branch: shmem-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even though the patches have already been applied. If possible, patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. Further, this is not a guarantee that the patches will go upstream. If in doubt, please check the listed branch.
[1/1] mm/shmem: bypass swap readahead for zswap
https://git.kernel.org/mm/core/c/49038a28
Signature · 3 lines
Cheers, David
Quoted 22 lines · Usama Arif
Commit
7ed825f0f766("mm: bypass swap readahead for zswap") madedo_swap_page()skip readahead for zswap entries, butshmem_swapin_folio()still only skips it forSWP_SYNCHRONOUS_IOdevices.zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use
swap_entry_synchronous()inshmem_swapin_folio(), likedo_swap_page(). zswap entries then take theSWP_SYNCHRONOUS_IOpath, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
Quoted 2 lines
Signed-off-by Usama Arif <[email protected]>---
Looks good to me,
Quoted 20 lines
mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/shmem.c +2
-2@@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,/* Look it up and read it in.. */ folio =swap_cache_get_folio (swap);if (!folio) { -if (data_race (si->flags &SWP_SYNCHRONOUS_IO )) { -/* Direct swapin skipping swap cache & readahead */ +if (swap_entry_synchronous (si, swap)) { +/* Skip readahead: synchronous device or zswap */ folio =shmem_swap_alloc_folio (inode, vmf, index, swap, order, gfp); }else {Signature · 1 line
2.53.1-Meta
Signature · 2 lines
Cheers, Harry / Hyeonggon
Quoted 15 lines · Usama Arif
Commit
7ed825f0f766("mm: bypass swap readahead for zswap") madedo_swap_page()skip readahead for zswap entries, butshmem_swapin_folio()still only skips it forSWP_SYNCHRONOUS_IOdevices.zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use
swap_entry_synchronous()inshmem_swapin_folio(), likedo_swap_page(). zswap entries then take theSWP_SYNCHRONOUS_IOpath, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.
Quoted 8 lines
On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
Signed-off-by Usama Arif <[email protected]>
Something's gone wrong here, maybe the original series that introduced swap_entry_synchronous() was removed from the tree but this is making the for-next tree not build:
mm/shmem.c:2583:7: error: call to undeclared function 'swap_entry_synchronous'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2583 | if (swap_entry_synchronous(si, swap)) {
| ^
1 error generated.
make[3]: *** [scripts/Makefile.build:290: mm/shmem.o] Error 1
Quoted 20 lines
--- mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/shmem.c +2
-3@@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,/* Look it up and read it in.. */ folio =swap_cache_get_folio (swap);if (!folio) { -if (data_race (si->flags &SWP_SYNCHRONOUS_IO )) { -/* Direct swapin skipping swap cache & readahead */ +if (swap_entry_synchronous (si, swap)) { +/* Skip readahead: synchronous device or zswap */ folio =shmem_swap_alloc_folio (inode, vmf, index, swap, order, gfp); }else { --
Quoted 4 lines
2.53.1-Meta
--
Cheers, Lorenzo
Quoted 29 lines · On Fri, 4 Dec 2026 15:14:02 +0000 "Lorenzo Stoakes (ARM)" <[email protected]>…
Quoted 15 lines · Usama Arif
Commit
7ed825f0f766("mm: bypass swap readahead for zswap") madedo_swap_page()skip readahead for zswap entries, butshmem_swapin_folio()still only skips it forSWP_SYNCHRONOUS_IOdevices.zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use
swap_entry_synchronous()inshmem_swapin_folio(), likedo_swap_page(). zswap entries then take theSWP_SYNCHRONOUS_IOpath, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.Quoted 8 lines
On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
Signed-off-by Usama Arif <[email protected]>Something's gone wrong here, maybe the original series that introduced
swap_entry_synchronous()was removed from the tree but this is making the for-next tree not build:
Quoted 6 lines
mm/shmem.c:2583:7: error: call to undeclared function 'swap_entry_synchronous'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2583 | if (swap_entry_synchronous(si, swap)) {
| ^
1 error generated.
make[3]: *** [scripts/Makefile.build:290:mm/shmem.o] Error 1
Yes the patch depends on [1] that introduced swap_entry_synchronous().
David and Andrew, could the patch go on whichever branch [1] went into?
Also this is a slightly broader topic. I always used to send non fixes on top of mm-new. Should I still do this?
I see mm-new, but then I also see feature branches in [2] (or is that just sub system fixes?). [2] also doesnt have a zswap tree.
Sorry if the above was discussed somewhere and I missed it.
Thanks!
Usama
[1] https://lore.kernel.org/all/[email protected]/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git/refs/heads
Quoted 31 lines
Quoted 22 lines
--- mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/shmem.c +2
-3@@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,/* Look it up and read it in.. */ folio =swap_cache_get_folio (swap);if (!folio) { -if (data_race (si->flags &SWP_SYNCHRONOUS_IO )) { -/* Direct swapin skipping swap cache & readahead */ +if (swap_entry_synchronous (si, swap)) { +/* Skip readahead: synchronous device or zswap */ folio =shmem_swap_alloc_folio (inode, vmf, index, swap, order, gfp); }else { --Quoted 4 lines
2.53.1-Meta
--
Cheers, Lorenzo
Quoted 9 lines
Yes the patch depends on [1] that introduced
swap_entry_synchronous().David and Andrew, could the patch go on whichever branch [1] went into?
Also this is a slightly broader topic. I always used to send non fixes on top of mm-new. Should I still do this?
I see mm-new, but then I also see feature branches in [2] (or is that just sub system fixes?). [2] also doesnt have a zswap tree.
Yeah I also wanted to ask at some point which tree/branch will be used to route zswap (and zsmalloc) changes.
Quoted 7 lines
Sorry if the above was discussed somewhere and I missed it.
Thanks!
Usama[1] https://lore.kernel.org/all/[email protected]/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git/refs/heads
Quoted 4 lines · Yosry Ahmed
Quoted 4 lines
Yes the patch depends on [1] that introduced
swap_entry_synchronous().David and Andrew, could the patch go on whichever branch [1] went into?
Quoted 8 lines
Quoted 5 lines
Also this is a slightly broader topic. I always used to send non fixes on top of mm-new. Should I still do this?
I see mm-new, but then I also see feature branches in [2] (or is that just sub system fixes?). [2] also doesnt have a zswap tree.
Yeah I also wanted to ask at some point which tree/branch will be used to route zswap (and zsmalloc) changes.
Yeah, I'm dropping it again, I didn't realize the dependency.
I only compiled the integration branch that goes into -next, not core/for-next.
So Andrew should just take it.
Signature · 3 lines
Cheers, David
Quoted 12 lines · David Hildenbrand (Arm)
Quoted 10 lines · Yosry Ahmed
Quoted 9 lines
Yes the patch depends on [1] that introduced
swap_entry_synchronous().David and Andrew, could the patch go on whichever branch [1] went into?
Also this is a slightly broader topic. I always used to send non fixes on top of mm-new. Should I still do this?
I see mm-new, but then I also see feature branches in [2] (or is that just sub system fixes?). [2] also doesnt have a zswap tree.
Quoted 8 lines
Quoted 2 lines
Yeah I also wanted to ask at some point which tree/branch will be used to route zswap (and zsmalloc) changes.
Yeah, I'm dropping it again, I didn't realize the dependency.
I only compiled the integration branch that goes into -next, not core/for-next.
So Andrew should just take it.
Thank you. Is the plan that Andrew will keep taking zswap/zsmalloc changes in the short-term?
[-] mm-shmem-bypass-swap-readahead-for-zswap.patch removed from -mm tree
In reply to Usama ArifThe quilt patch titled Subject: mm/shmem: bypass swap readahead for zswap has been removed from the -mm tree. Its filename was mm-shmem-bypass-swap-readahead-for-zswap.patch
The quilt patch titled
Subject: mm/shmem: bypass swap readahead for zswap
has been removed from the -mm tree. Its filename was
mm-shmem-bypass-swap-readahead-for-zswap.patch
This patch was dropped because David is taking it
------------------------------------------------------
From: Usama Arif <[email protected]>
Subject: mm/shmem: bypass swap readahead for zswap
Date: Thu, 3 Dec 2026 10:02:53 -0800
Commit 7ed825f0f766 ("mm: bypass swap readahead for zswap") made do_swap_page() skip readahead for zswap entries, but shmem_swapin_folio() still only skips it for SWP_SYNCHRONOUS_IO devices.
zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use swap_entry_synchronous() in shmem_swapin_folio(), like do_swap_page(). zswap entries then take the SWP_SYNCHRONOUS_IO path, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.
On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/shmem.c renamed from mm/shmem.c~mm-shmem-bypass-swap-readahead-for-zswap +2 -2
@@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct ino/* Look it up and read it in.. */ folio =swap_cache_get_folio (swap);if (!folio) { -if (data_race (si->flags &SWP_SYNCHRONOUS_IO )) { -/* Direct swapin skipping swap cache & readahead */ +if (swap_entry_synchronous (si, swap)) { +/* Skip readahead: synchronous device or zswap */ folio =shmem_swap_alloc_folio (inode, vmf, index, swap, order, gfp); }else {
_
Patches currently in -mm which might be from [email protected] are
mm-zswap-use-separate-compression-and-decompression-requests.patch mm-zswap-use-stack-requests-for-synchronous-decompression.patch fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps.patch fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps.patch
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] mm/shmem: commit message cites unresolvable commit SHA 7ed825f0f766 --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] mm/shmem: commit message cites unresolvable commit SHA 7ed825f0f766
--
commit f2cb4c41748a7e427f2863efcefe5838c77ae7e0
Author: Usama Arif <[email protected]>
mm/shmem: bypass swap readahead for zswap
This commit updates shmem_swapin_folio() to use swap_entry_synchronous() so that zswap entries bypass swap readahead just like synchronous swap devices.
Quoted 1 line
Commit
7ed825f0f766("mm: bypass swap readahead for zswap") made
[Severity: Low]
Should this cite c5e8d8c2f4f2 ("mm: bypass swap readahead for zswap") instead? The quoted commit hash does not exist in this tree, leaving a broken reference in git history.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [-] mm-shmem-bypass-swap-readahead-for-zswap.patch removed from -mm tree
In reply to Andrew MortonQuoted 7 lines · On Fri, 04 Dec 2026 09:54:51 -0800 Andrew Morton <[email protected]>…
The quilt patch titled
Subject: mm/shmem: bypass swap readahead for zswap
has been removed from the -mm tree. Its filename was
mm-shmem-bypass-swap-readahead-for-zswap.patchThis patch was dropped because David is taking it
Sorry for all the confusion but the patch would go through
you [1] in the tree where the commit "mm: bypass swap readahead for zswap" exists.
[1] https://lore.kernel.org/all/[email protected]/
Quoted 77 lines
------------------------------------------------------
From: Usama Arif <[email protected]>
Subject: mm/shmem: bypass swap readahead for zswap
Date: Thu, 3 Dec 2026 10:02:53 -0800Commit
7ed825f0f766("mm: bypass swap readahead for zswap") madedo_swap_page()skip readahead for zswap entries, butshmem_swapin_folio()still only skips it forSWP_SYNCHRONOUS_IOdevices.zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use
swap_entry_synchronous()inshmem_swapin_folio(), likedo_swap_page(). zswap entries then take theSWP_SYNCHRONOUS_IOpath, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
Signed-off-by Usama Arif <[email protected]>Signed-off-by Andrew Morton <[email protected]>Reviewed-by Yosry Ahmed <[email protected]>Reviewed-by Nhat Pham <[email protected]>Reviewed-by Barry Song <[email protected]>Reviewed-by Baolin Wang <[email protected]>Cc Hugh Dickins <[email protected]>Cc David Hildenbrand <[email protected]>Cc Johannes Weiner <[email protected]>Cc Chengming Zhou <[email protected]>Cc Christopher Li <[email protected]>Cc Kairui Song <[email protected]>Cc Kemeng Shi <[email protected]>Cc Baoquan He <[email protected]>Cc Youngjun Park <[email protected]>Cc Alexandre Ghiti <[email protected]>Cc Rik van Riel <[email protected]>Cc Shakeel Butt <[email protected]>Cc <[email protected]>Cc <[email protected]>Cc <[email protected]>mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/shmem.c renamed from mm/shmem.c~mm-shmem-bypass-swap-readahead-for-zswap +2
-2@@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct ino/* Look it up and read it in.. */ folio =swap_cache_get_folio (swap);if (!folio) { -if (data_race (si->flags &SWP_SYNCHRONOUS_IO )) { -/* Direct swapin skipping swap cache & readahead */ +if (swap_entry_synchronous (si, swap)) { +/* Skip readahead: synchronous device or zswap */ folio =shmem_swap_alloc_folio (inode, vmf, index, swap, order, gfp); }else {_
Patches currently in -mm which might be from [email protected] are
mm-zswap-use-separate-compression-and-decompression-requests.patch mm-zswap-use-stack-requests-for-synchronous-decompression.patch fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps.patch fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps.patch
+ mm-shmem-bypass-swap-readahead-for-zswap.patch added to mm-unstable branch
In reply to Usama ArifThe patch titled Subject: mm/shmem: bypass swap readahead for zswap has been added to the -mm mm-unstable branch. Its filename is mm-shmem-bypass-swap-readahead-for-zswap.patch
The patch titled
Subject: mm/shmem: bypass swap readahead for zswap
has been added to the -mm mm-unstable branch. Its filename is
mm-shmem-bypass-swap-readahead-for-zswap.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-shmem-bypass-swap-readahead-for-zswap.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Usama Arif <[email protected]>
Subject: mm/shmem: bypass swap readahead for zswap
Date: Thu, 3 Dec 2026 10:02:53 -0800
Commit 7ed825f0f766 ("mm: bypass swap readahead for zswap") made do_swap_page() skip readahead for zswap entries, but shmem_swapin_folio() still only skips it for SWP_SYNCHRONOUS_IO devices.
zswap decompresses in the faulting task, so readahead has no I/O to overlap and only slows the fault down. And since zswap loads are exclusive, pages read ahead but never used stay uncompressed in memory until reclaim compresses them again.
Use swap_entry_synchronous() in shmem_swapin_folio(), like do_swap_page(). zswap entries then take the SWP_SYNCHRONOUS_IO path, which already uses order-0 folios once zswap has been enabled. Entries on the backing device keep cluster readahead.
On productions hosts that run VM workloads backed by shmem guest memory with memfds and swaps only to zswap, about a third of shmem readahead pages were never used. In a QEMU guest with a 2 GB memfd in zswap and page-cluster=3, faulting in 10% of it left 36 MiB in the swap cache before this change and none after. The memcg grew 24 MiB less and the faults took 12% less time.
mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/shmem.c renamed from mm/shmem.c~mm-shmem-bypass-swap-readahead-for-zswap +2 -2
@@ -2570,8 +2570,8 @@ static int shmem_swapin_folio(struct ino/* Look it up and read it in.. */ folio =swap_cache_get_folio (swap);if (!folio) { -if (data_race (si->flags &SWP_SYNCHRONOUS_IO )) { -/* Direct swapin skipping swap cache & readahead */ +if (swap_entry_synchronous (si, swap)) { +/* Skip readahead: synchronous device or zswap */ folio =shmem_swap_alloc_folio (inode, vmf, index, swap, order, gfp); }else {
_
Patches currently in -mm which might be from [email protected] are
mm-zswap-use-separate-compression-and-decompression-requests.patch mm-zswap-use-stack-requests-for-synchronous-decompression.patch mm-shmem-bypass-swap-readahead-for-zswap.patch fs-proc-task_mmu-read-the-pmd-once-in-smaps_pmd_entry.patch fs-proc-task_mmu-dont-read-young-dirty-from-a-non-present-pmd-in-smaps.patch fs-proc-task_mmu-account-device-private-pmds-as-present-in-smaps.patch
Andrew Morton
maintainerQuoted 16 lines · On Fri, 4 Dec 2026 09:28:05 -0800 Yosry Ahmed <[email protected]> wrote:
Quoted 15 lines · David Hildenbrand (Arm)
Quoted 12 lines · Yosry Ahmed
Quoted 9 lines
Yes the patch depends on [1] that introduced
swap_entry_synchronous().David and Andrew, could the patch go on whichever branch [1] went into?
Also this is a slightly broader topic. I always used to send non fixes on top of mm-new. Should I still do this?
I see mm-new, but then I also see feature branches in [2] (or is that just sub system fixes?). [2] also doesnt have a zswap tree.
Yeah I also wanted to ask at some point which tree/branch will be used to route zswap (and zsmalloc) changes.
Quoted 8 lines
Quoted 5 lines
Yeah, I'm dropping it again, I didn't realize the dependency.
I only compiled the integration branch that goes into -next, not core/for-next.
So Andrew should just take it.
Thank you. Is the plan that Andrew will keep taking zswap/zsmalloc changes in the short-term?
As far as I know, yes, until something changes. Maybe not very "short".
Andrew Morton
maintainerQuoted 4 lines · On Fri, 04 Dec 2026 18:03:18 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] mm/shmem: commit message cites unresolvable commit SHA7ed825f0f766
true, I'll redo that.