Re: [PATCH v5 9/9] mm: switch deferred split shrinker to list_lru

From: Lance Yang

Date: Mon Jun 08 2026 - 23:21:52 EST



On Mon, Jun 01, 2026 at 02:17:28PM -0400, Johannes Weiner wrote:
>On Mon, Jun 01, 2026 at 09:21:35PM +0800, Lance Yang wrote:
>>
>> On Wed, May 27, 2026 at 04:45:16PM -0400, Johannes Weiner wrote:
>> [...]
>> >diff --git a/mm/swap_state.c b/mm/swap_state.c
>> >index 04f5ce992401..9c3a5cf99778 100644
>> >--- a/mm/swap_state.c
>> >+++ b/mm/swap_state.c
>> >@@ -465,6 +465,16 @@ static struct folio *__swap_cache_alloc(struct swap_cluster_info *ci,
>> > return ERR_PTR(-ENOMEM);
>> > }
>> >
>>
>> Shouldn't this be limited to anon swapin?
>>
>> e.g. vmf && vma_is_anonymous(vmf->vma)
>>
>> >+ if (order > 1 && folio_memcg_alloc_deferred(folio)) {
>>
>> __swap_cache_alloc() is also used by shmem direct swapin, so shmem can
>> get here too when handling a large swap entry:
>>
>> shmem_get_folio_gfp()
>> shmem_swapin_folio()
>> shmem_swap_alloc_folio()
>> swapin_sync()
>> swap_cache_alloc_folio()
>> __swap_cache_alloc()
>> folio_memcg_alloc_deferred()
>
>Good catch, I think you're right. I shouldn't have dismissed that
>branch due to "/* Direct swapin skipping swap cache & readahead */"
>
>> @Baolin please correct me if I got it wrong :)
>>
>> folio_memcg_alloc_deferred() itself doesn't filter shmem out either; it
>> only allocates the memcg list_lru metadata for deferred_split_lru:
>>
>> int folio_memcg_alloc_deferred(struct folio *folio)
>> {
>> if (mem_cgroup_disabled())
>> return 0;
>> return folio_memcg_list_lru_alloc(folio, &deferred_split_lru, GFP_KERNEL);
>> }
>>
>> Since deferred_split_lru only queues anon large folios, doing this for
>> shmem swapin doesn't buy us anything :)
>
>Yes, agreed. I don't think it's a big deal / show stopper in terms of
>user-visible effect, but of course still worth fixing.
>
>I'll send a follow-up patch.

Thanks.

Looks like this has already landed in mm-stable. If you're okay with it,
I can send the follow-up.

From: Lance Yang <lance.yang@xxxxxxxxx>
Date: Tue, 9 Jun 2026 10:56:45 +0800
Subject: [PATCH] mm: prepare deferred split metadata only for anon swapin

__swap_cache_alloc() prepares deferred split metadata for large swapcache
folios.

That also covers shmem swapin, because shmem_swap_alloc_folio() can call
swapin_sync() with a large order[1]. But shmem folios are not queued on
the deferred split queue, so preparing the metadata doesn't buy us
anything there.

So let's limit it to anon swapin.

[1] https://lore.kernel.org/all/20260601132135.14272-1-lance.yang@xxxxxxxxx/

Signed-off-by: Lance Yang <lance.yang@xxxxxxxxx>
---
mm/swap_state.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/swap_state.c b/mm/swap_state.c
index 9c3a5cf99778..7adac957c2b8 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -465,7 +465,8 @@ static struct folio *__swap_cache_alloc(struct swap_cluster_info *ci,
return ERR_PTR(-ENOMEM);
}

- if (order > 1 && folio_memcg_alloc_deferred(folio)) {
+ if (order > 1 && vma && vma_is_anonymous(vma) &&
+ folio_memcg_alloc_deferred(folio)) {
spin_lock(&ci->lock);
__swap_cache_do_del_folio(ci, folio, entry, shadow);
spin_unlock(&ci->lock);
--
2.39.3 (Apple Git-146)