From: sashiko-bot@kernel.org
To: "Shakeel Butt" <shakeel.butt@linux.dev>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"David Hildenbrand" <david@kernel.org>
Cc: "Michal Hocko" <mhocko@kernel.org>,
"Roman Gushchin" <roman.gushchin@linux.dev>,
"Muchun Song" <muchun.song@linux.dev>,
"Qi Zheng" <qi.zheng@linux.dev>, "Zi Yan" <ziy@nvidia.com>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Kairui Song" <kasong@tencent.com>,
"Nhat Pham" <nphamcs@gmail.com>,
"Usama Arif" <usama.arif@linux.dev>,
"Hugh Dickins" <hughd@google.com>,
"Meta kernel team" <kernel-team@meta.com>,
linux-mm@kvack.org
Subject: Re: [PATCH 4/4] mm/vmscan: don't give swap to an anon folio that nothing maps
Date: Mon, 30 Nov 2026 18:54:30 +0000 [thread overview]
Message-ID: <sashiko-outbox-241883@kernel.org> (raw)
In-Reply-To: <20261130182755.666042-5-shakeel.butt@linux.dev>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mm/vmscan: unadjusted sc->nr_scanned in shrink_folio_list()
after folio split
- [Medium] mm/vmscan: redundant shrink_folio_list() retry in MGLRU
evict_folios()
--
commit adf73a464f11b1c23175eec0f7510cddfa8d6dc1
Author: Shakeel Butt <shakeel.butt@linux.dev>
mm/vmscan: don't give swap to an anon folio that nothing maps
This commit skips swap allocation in shrink_folio_list() for unmapped
anonymous folios that are not in the swap cache, and frees newly allocated
swap slots if the folio becomes an orphan during the unmap step.
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 99cb209797b4b..ddc1584d06eda 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
[ ... ]
> @@ -1331,6 +1332,19 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
> split_folio_to_list(folio, folio_list))
> goto activate_locked;
> }
> + /*
> + * If nothing maps the folio, its last mapping went
> + * away, usually because its process exited, and no page
> + * table or shmem entry refers to it. It is freed when
> + * the last reference goes away. Giving it swap would
> + * only leave it in the swap cache if something else
> + * still holds a reference. KSM can map a KSM folio
> + * again; a later pass swaps it out then. This comes
> + * after the split above, so it also skips an unmapped
> + * first page of a partially mapped folio.
> + */
> + if (!folio_mapped(folio))
> + goto keep_locked;
[Severity: Medium]
When split_folio_to_list() splits a partially mapped large folio and its
first page is unmapped, does jumping to keep_locked overcount
sc->nr_scanned by nr_pages - 1?
shrink_folio_list() initially adds the full large folio's nr_pages to
sc->nr_scanned, and each split tail page added to folio_list is counted
again when the loop pops it. Jumping to keep_locked skips the post-split
fixup after the swap allocation block:
mm/vmscan.c:shrink_folio_list() {
...
if ((nr_pages > 1) && !folio_test_large(folio)) {
sc->nr_scanned -= (nr_pages - 1);
nr_pages = 1;
}
...
}
Inflating sc->nr_scanned skews vmpressure reporting, reclaim throttling
checks, and kswapd scan targets.
[Severity: Medium]
Under MGLRU, does jumping to keep_locked before folio_mark_dirty() cause
evict_folios() to run a second shrink_folio_list() pass on every unmapped
non-swapcache anonymous folio?
Because unmapping an anonymous folio does not set PG_dirty, returning via
keep_locked leaves the folio inactive, unmapped, clean, and not under
writeback. evict_folios() treats any such folio as one that finished
writeback while isolated and retries shrink_folio_list() on it before
move_folios_to_lru() can drop reclaim's reference:
mm/vmscan.c:evict_folios() {
...
/* retry folios that may have missed folio_rotate_reclaimable() */
if (!skip_retry && !folio_test_active(folio) && !folio_mapped(folio) &&
!folio_test_dirty(folio) && !folio_test_writeback(folio)) {
list_move(&folio->lru, &clean);
continue;
}
...
}
The retry hits goto keep_locked again without reclaiming the folio and
counts nr_pages in sc->nr_scanned a second time.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130182755.666042-1-shakeel.butt@linux.dev?part=4
next prev parent reply other threads:[~2026-11-30 18:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 18:27 [PATCH 0/4] mm, memcg: stop orphaned swap cache from using up memcg IDs Shakeel Butt
2026-11-30 18:27 ` [PATCH 1/4] mm/swap: free orphaned swap cache instead of leaving it to reclaim Shakeel Butt
2026-11-30 18:27 ` [PATCH 2/4] mm: free swap cache that migration or a split leaves unmapped Shakeel Butt
2026-11-30 18:27 ` [PATCH 3/4] mm/memory: free the swap cache folio that a KSM copy leaves behind Shakeel Butt
2026-11-30 18:27 ` [PATCH 4/4] mm/vmscan: don't give swap to an anon folio that nothing maps Shakeel Butt
2026-11-30 18:54 ` sashiko-bot [this message]
2026-11-30 19:13 ` Shakeel Butt
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=sashiko-outbox-241883@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kasong@tencent.com \
--cc=kernel-team@meta.com \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=qi.zheng@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=ziy@nvidia.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