* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
@ 2026-12-03 19:49 ` Yosry Ahmed
2026-12-03 19:53 ` Nhat Pham
` (9 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: Yosry Ahmed @ 2026-12-03 19:49 UTC (permalink / raw)
To: Usama Arif
Cc: Andrew Morton, hughd, david, baolin.wang, hannes, nphamcs,
chengming.zhou, chrisl, kasong, baohua, shikemeng, baoquan.he,
youngjun.park, alex, linux-mm, riel, shakeel.butt, kernel-team,
rkeilty, atish.patra, dgreid
On Thu, Dec 3, 2026 at 10:03 AM Usama Arif <usama.arif@linux.dev> wrote:
>
> 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.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
Reviewed-by: Yosry Ahmed <yosry@kernel.org>
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
2026-12-03 19:49 ` Yosry Ahmed
@ 2026-12-03 19:53 ` Nhat Pham
2026-12-03 19:57 ` Shakeel Butt
` (8 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: Nhat Pham @ 2026-12-03 19:53 UTC (permalink / raw)
To: Usama Arif
Cc: Andrew Morton, hughd, david, baolin.wang, hannes, yosry,
chengming.zhou, chrisl, kasong, baohua, shikemeng, baoquan.he,
youngjun.park, alex, linux-mm, riel, shakeel.butt, kernel-team,
rkeilty, atish.patra, dgreid
On Thu, Dec 3, 2026 at 11:03 AM Usama Arif <usama.arif@linux.dev> wrote:
>
> 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.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
Reviewed-by: Nhat Pham <nphamcs@gmail.com>
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
2026-12-03 19:49 ` Yosry Ahmed
2026-12-03 19:53 ` Nhat Pham
@ 2026-12-03 19:57 ` Shakeel Butt
2026-12-03 20:03 ` Andrew Morton
` (7 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: Shakeel Butt @ 2026-12-03 19:57 UTC (permalink / raw)
To: Usama Arif
Cc: Andrew Morton, hughd, david, baolin.wang, hannes, yosry, nphamcs,
chengming.zhou, chrisl, kasong, baohua, shikemeng, baoquan.he,
youngjun.park, alex, linux-mm, riel, kernel-team, rkeilty,
atish.patra, dgreid
On Thu, Dec 03, 2026 at 10:02:53AM -0800, Usama Arif wrote:
> 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.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
Acked-by Shakeel Butt <shakeel.butt@linux.dev>
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
` (2 preceding siblings ...)
2026-12-03 19:57 ` Shakeel Butt
@ 2026-12-03 20:03 ` Andrew Morton
2026-12-03 20:07 ` Usama Arif
2026-12-04 1:24 ` SJ Park
` (6 subsequent siblings)
10 siblings, 1 reply; 21+ messages in thread
From: Andrew Morton @ 2026-12-03 20:03 UTC (permalink / raw)
To: Usama Arif
Cc: hughd, david, baolin.wang, hannes, yosry, nphamcs, chengming.zhou,
chrisl, kasong, baohua, shikemeng, baoquan.he, youngjun.park,
alex, linux-mm, riel, shakeel.butt, kernel-team, rkeilty,
atish.patra, dgreid
On Thu, 3 Dec 2026 10:02:53 -0800 Usama Arif <usama.arif@linux.dev> wrote:
> Commit 7ed825f0f766 ("mm: bypass swap readahead for zswap")
That's in mm-unstable.
> 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.
>
> ...
>
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -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.
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 20:03 ` Andrew Morton
@ 2026-12-03 20:07 ` Usama Arif
2026-12-04 3:21 ` Barry Song
0 siblings, 1 reply; 21+ messages in thread
From: Usama Arif @ 2026-12-03 20:07 UTC (permalink / raw)
To: Andrew Morton
Cc: hughd, david, baolin.wang, hannes, yosry, nphamcs, chengming.zhou,
chrisl, kasong, baohua, shikemeng, baoquan.he, youngjun.park,
alex, linux-mm, riel, shakeel.butt, kernel-team, rkeilty,
atish.patra, dgreid
On 03/12/2026 12:03, Andrew Morton wrote:
> On Thu, 3 Dec 2026 10:02:53 -0800 Usama Arif <usama.arif@linux.dev> wrote:
>
>> Commit 7ed825f0f766 ("mm: bypass swap readahead for zswap")
>
> That's in mm-unstable.
>
>> 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.
>>
>> ...
>>
>> --- a/mm/shmem.c
>> +++ b/mm/shmem.c
>> @@ -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
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 20:07 ` Usama Arif
@ 2026-12-04 3:21 ` Barry Song
2026-12-04 10:52 ` David Hildenbrand (Arm)
0 siblings, 1 reply; 21+ messages in thread
From: Barry Song @ 2026-12-04 3:21 UTC (permalink / raw)
To: Usama Arif
Cc: Andrew Morton, hughd, david, baolin.wang, hannes, yosry, nphamcs,
chengming.zhou, chrisl, kasong, shikemeng, baoquan.he,
youngjun.park, alex, linux-mm, riel, shakeel.butt, kernel-team,
rkeilty, atish.patra, dgreid
On Fri, Dec 4, 2026 at 4:07 AM Usama Arif <usama.arif@linux.dev> wrote:
>
>
>
> On 03/12/2026 12:03, Andrew Morton wrote:
[...]
> >> --- a/mm/shmem.c
> >> +++ b/mm/shmem.c
> >> @@ -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.
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,
Reviewed-by: Barry Song <baohua@kernel.org>
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-04 3:21 ` Barry Song
@ 2026-12-04 10:52 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-04 10:52 UTC (permalink / raw)
To: Barry Song, Usama Arif
Cc: Andrew Morton, hughd, baolin.wang, hannes, yosry, nphamcs,
chengming.zhou, chrisl, kasong, shikemeng, baoquan.he,
youngjun.park, alex, linux-mm, riel, shakeel.butt, kernel-team,
rkeilty, atish.patra, dgreid
On 12/4/26 04:21, Barry Song wrote:
> On Fri, Dec 4, 2026 at 4:07 AM Usama Arif <usama.arif@linux.dev> wrote:
>>
>>
>>
>> On 03/12/2026 12:03, Andrew Morton wrote:
> [...]
>
>>>
>>> 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.
--
Cheers,
David
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
` (3 preceding siblings ...)
2026-12-03 20:03 ` Andrew Morton
@ 2026-12-04 1:24 ` SJ Park
2026-12-04 6:39 ` Baolin Wang
` (5 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: SJ Park @ 2026-12-04 1:24 UTC (permalink / raw)
To: Usama Arif
Cc: SJ Park, Andrew Morton, hughd, david, baolin.wang, hannes, yosry,
nphamcs, chengming.zhou, chrisl, kasong, baohua, shikemeng,
baoquan.he, youngjun.park, alex, linux-mm, riel, shakeel.butt,
kernel-team, rkeilty, atish.patra, dgreid
On Thu, 3 Dec 2026 10:02:53 -0800 Usama Arif <usama.arif@linux.dev> wrote:
> 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.
Makes sense to me.
>
> 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.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
Reviewed-by: SJ Park <sj@kernel.org>
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
` (4 preceding siblings ...)
2026-12-04 1:24 ` SJ Park
@ 2026-12-04 6:39 ` Baolin Wang
2026-12-04 7:46 ` Chris Down
` (4 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: Baolin Wang @ 2026-12-04 6:39 UTC (permalink / raw)
To: Usama Arif, Andrew Morton, hughd, david, hannes, yosry, nphamcs,
chengming.zhou, chrisl, kasong, baohua, shikemeng, baoquan.he,
youngjun.park, alex, linux-mm, riel, shakeel.butt, kernel-team,
rkeilty, atish.patra, dgreid
On 12/4/26 2:02 AM, Usama Arif wrote:
> 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.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---
As Andrew pointed out, the unstable commit id should be avoided.
Otherwise LGTM.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
` (5 preceding siblings ...)
2026-12-04 6:39 ` Baolin Wang
@ 2026-12-04 7:46 ` Chris Down
2026-12-04 10:53 ` David Hildenbrand
` (3 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: Chris Down @ 2026-12-04 7:46 UTC (permalink / raw)
To: Usama Arif
Cc: Andrew Morton, hughd, david, baolin.wang, hannes, yosry, nphamcs,
chengming.zhou, chrisl, kasong, baohua, shikemeng, baoquan.he,
youngjun.park, alex, linux-mm, riel, shakeel.butt, kernel-team,
rkeilty, atish.patra, dgreid
Thanks, this looks good.
Reviewed-by: Chris Down <chris@chrisdown.name>
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
` (6 preceding siblings ...)
2026-12-04 7:46 ` Chris Down
@ 2026-12-04 10:53 ` David Hildenbrand
2026-12-04 12:24 ` Harry Yoo
` (2 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2026-12-04 10:53 UTC (permalink / raw)
To: Andrew Morton, hughd, david, baolin.wang, hannes, yosry, nphamcs,
chengming.zhou, chrisl, kasong, baohua, shikemeng, baoquan.he,
youngjun.park, alex, linux-mm, riel, shakeel.butt, kernel-team,
rkeilty, atish.patra, dgreid, Usama Arif
On Thu, 03 Dec 2026 10:02:53 -0800, Usama Arif wrote:
> 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.
>
> [...]
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
--
Cheers,
David
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
` (7 preceding siblings ...)
2026-12-04 10:53 ` David Hildenbrand
@ 2026-12-04 12:24 ` Harry Yoo
2026-12-04 15:14 ` Lorenzo Stoakes (ARM)
2026-12-04 18:03 ` sashiko-bot
10 siblings, 0 replies; 21+ messages in thread
From: Harry Yoo @ 2026-12-04 12:24 UTC (permalink / raw)
To: Usama Arif
Cc: Andrew Morton, hughd, david, baolin.wang, hannes, yosry, nphamcs,
chengming.zhou, chrisl, kasong, baohua, shikemeng, baoquan.he,
youngjun.park, alex, linux-mm, riel, shakeel.butt, kernel-team,
rkeilty, atish.patra, dgreid
On Thu, Dec 03, 2026 at 10:02:53AM -0800, Usama Arif wrote:
> 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.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---
Looks good to me,
Acked-by: Harry Yoo (Meta) <harry@kernel.org>
> mm/shmem.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 344f7edf5e15a3..eba2a22af9a052 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -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 {
> --
> 2.53.1-Meta
--
Cheers,
Harry / Hyeonggon
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
` (8 preceding siblings ...)
2026-12-04 12:24 ` Harry Yoo
@ 2026-12-04 15:14 ` Lorenzo Stoakes (ARM)
2026-12-04 15:32 ` Usama Arif
2026-12-04 18:03 ` sashiko-bot
10 siblings, 1 reply; 21+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-12-04 15:14 UTC (permalink / raw)
To: Usama Arif
Cc: Andrew Morton, hughd, david, baolin.wang, hannes, yosry, nphamcs,
chengming.zhou, chrisl, kasong, baohua, shikemeng, baoquan.he,
youngjun.park, alex, linux-mm, riel, shakeel.butt, kernel-team,
rkeilty, atish.patra, dgreid
On Thu, Dec 03, 2026 at 10:02:53AM -0800, Usama Arif wrote:
> 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.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
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
> ---
> mm/shmem.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 344f7edf5e15a3..eba2a22af9a052 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -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 {
> --
> 2.53.1-Meta
>
>
>
--
Cheers, Lorenzo
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-04 15:14 ` Lorenzo Stoakes (ARM)
@ 2026-12-04 15:32 ` Usama Arif
2026-12-04 16:03 ` Yosry Ahmed
0 siblings, 1 reply; 21+ messages in thread
From: Usama Arif @ 2026-12-04 15:32 UTC (permalink / raw)
To: Lorenzo Stoakes (ARM)
Cc: Usama Arif, Andrew Morton, hughd, david, baolin.wang, hannes,
yosry, nphamcs, chengming.zhou, chrisl, kasong, baohua, shikemeng,
baoquan.he, youngjun.park, alex, linux-mm, riel, shakeel.butt,
kernel-team, rkeilty, atish.patra, dgreid
On Fri, 4 Dec 2026 15:14:02 +0000 "Lorenzo Stoakes (ARM)" <ljs@kernel.org> wrote:
> On Thu, Dec 03, 2026 at 10:02:53AM -0800, Usama Arif wrote:
> > 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.
> >
> > Signed-off-by: Usama Arif <usama.arif@linux.dev>
>
> 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
>
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/20261102144835.304017-1-alex@ghiti.fr/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git/refs/heads
>
>
> > ---
> > mm/shmem.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/mm/shmem.c b/mm/shmem.c
> > index 344f7edf5e15a3..eba2a22af9a052 100644
> > --- a/mm/shmem.c
> > +++ b/mm/shmem.c
> > @@ -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 {
> > --
> > 2.53.1-Meta
> >
> >
> >
>
> --
> Cheers, Lorenzo
>
>
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-04 15:32 ` Usama Arif
@ 2026-12-04 16:03 ` Yosry Ahmed
2026-12-04 17:23 ` David Hildenbrand (Arm)
0 siblings, 1 reply; 21+ messages in thread
From: Yosry Ahmed @ 2026-12-04 16:03 UTC (permalink / raw)
To: Usama Arif
Cc: Lorenzo Stoakes (ARM), Andrew Morton, hughd, david, baolin.wang,
hannes, nphamcs, chengming.zhou, chrisl, kasong, baohua,
shikemeng, baoquan.he, youngjun.park, alex, linux-mm, riel,
shakeel.butt, kernel-team, rkeilty, atish.patra, dgreid
> 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.
> Sorry if the above was discussed somewhere and I missed it.
>
> Thanks!
> Usama
>
> [1] https://lore.kernel.org/all/20261102144835.304017-1-alex@ghiti.fr/
> [2] https://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git/refs/heads
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-04 16:03 ` Yosry Ahmed
@ 2026-12-04 17:23 ` David Hildenbrand (Arm)
2026-12-04 17:28 ` Yosry Ahmed
0 siblings, 1 reply; 21+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-04 17:23 UTC (permalink / raw)
To: Yosry Ahmed, Usama Arif
Cc: Lorenzo Stoakes (ARM), Andrew Morton, hughd, baolin.wang, hannes,
nphamcs, chengming.zhou, chrisl, kasong, baohua, shikemeng,
baoquan.he, youngjun.park, alex, linux-mm, riel, shakeel.butt,
kernel-team, rkeilty, atish.patra, dgreid
On 12/4/26 17:03, Yosry Ahmed wrote:
>> 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.
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.
--
Cheers,
David
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-04 17:23 ` David Hildenbrand (Arm)
@ 2026-12-04 17:28 ` Yosry Ahmed
2026-12-04 18:26 ` Andrew Morton
0 siblings, 1 reply; 21+ messages in thread
From: Yosry Ahmed @ 2026-12-04 17:28 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Usama Arif, Lorenzo Stoakes (ARM), Andrew Morton, hughd,
baolin.wang, hannes, nphamcs, chengming.zhou, chrisl, kasong,
baohua, shikemeng, baoquan.he, youngjun.park, alex, linux-mm,
riel, shakeel.butt, kernel-team, rkeilty, atish.patra, dgreid
On Fri, Dec 4, 2026 at 9:23 AM David Hildenbrand (Arm) <david@kernel.org> wrote:
>
> On 12/4/26 17:03, Yosry Ahmed wrote:
> >> 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.
>
> 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?
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-04 17:28 ` Yosry Ahmed
@ 2026-12-04 18:26 ` Andrew Morton
0 siblings, 0 replies; 21+ messages in thread
From: Andrew Morton @ 2026-12-04 18:26 UTC (permalink / raw)
To: Yosry Ahmed
Cc: David Hildenbrand (Arm), Usama Arif, Lorenzo Stoakes (ARM), hughd,
baolin.wang, hannes, nphamcs, chengming.zhou, chrisl, kasong,
baohua, shikemeng, baoquan.he, youngjun.park, alex, linux-mm,
riel, shakeel.butt, kernel-team, rkeilty, atish.patra, dgreid
On Fri, 4 Dec 2026 09:28:05 -0800 Yosry Ahmed <yosry@kernel.org> wrote:
> On Fri, Dec 4, 2026 at 9:23 AM David Hildenbrand (Arm) <david@kernel.org> wrote:
> >
> > On 12/4/26 17:03, Yosry Ahmed wrote:
> > >> 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.
> >
> > 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".
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-03 18:02 [PATCH] mm/shmem: bypass swap readahead for zswap Usama Arif
` (9 preceding siblings ...)
2026-12-04 15:14 ` Lorenzo Stoakes (ARM)
@ 2026-12-04 18:03 ` sashiko-bot
2026-12-04 18:36 ` Andrew Morton
10 siblings, 1 reply; 21+ messages in thread
From: sashiko-bot @ 2026-12-04 18:03 UTC (permalink / raw)
To: Usama Arif, Andrew Morton, hughd, david, baolin.wang, hannes,
yosry, nphamcs, chengming.zhou, chrisl, kasong, baohua, shikemeng,
baoquan.he, youngjun.park, alex, linux-mm, riel, shakeel.butt,
kernel-team, rkeilty, atish.patra, dgreid
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 <usama.arif@linux.dev>
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.
> 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203180253.2129141-1-usama.arif@linux.dev?part=1
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH] mm/shmem: bypass swap readahead for zswap
2026-12-04 18:03 ` sashiko-bot
@ 2026-12-04 18:36 ` Andrew Morton
0 siblings, 0 replies; 21+ messages in thread
From: Andrew Morton @ 2026-12-04 18:36 UTC (permalink / raw)
To: sashiko-reviews
Cc: sashiko-bot, Usama Arif, hughd, david, baolin.wang, hannes, yosry,
nphamcs, chengming.zhou, chrisl, kasong, baohua, shikemeng,
baoquan.he, youngjun.park, alex, linux-mm, riel, shakeel.butt,
kernel-team, rkeilty, atish.patra, dgreid
On Fri, 04 Dec 2026 18:03:18 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Low] mm/shmem: commit message cites unresolvable commit SHA
> 7ed825f0f766
true, I'll redo that.
^ permalink raw reply [flat|nested] 21+ messages in thread