Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zhang Peng" <zippermonkey@icloud.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"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>,
	"Kairui Song" <kasong@tencent.com>,
	"Barry Song" <baohua@kernel.org>,
	"Axel Rasmussen" <axelrasmussen@google.com>,
	"Yuanchu Xie" <yuanchu@google.com>, "Wei Xu" <weixugc@google.com>,
	"Baoquan He" <baoquan.he@linux.dev>,
	"Baolin Wang" <baolin.wang@linux.alibaba.com>
Cc: linux-mm@kvack.org, "Zhang Peng" <bruzzhang@tencent.com>
Subject: Re: [PATCH v6 5/5] mm/vmscan: batch dirty TLB flushes before pageout
Date: Sun, 01 Nov 2026 02:51:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-192259@kernel.org> (raw)
In-Reply-To: <20261031-batch-tlb-flush-v6-5-190539839eec@tencent.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm/vmscan: split shmem tail folios left unprocessed in shrink_folio_list()
--

commit cb4d38468a11c1912d88e753c3510180ab891a8b
Author: Zhang Peng <zippermonkey@icloud.com>

mm/vmscan: batch dirty TLB flushes before pageout

This commit batches dirty swap-backed folios during shrink_folio_list() into
a folio_batch so that pending writable TLB entries can be flushed once per
batch with try_to_unmap_flush_dirty() before paging the folios out. Folios
are unlocked while queued in the batch and re-locked and revalidated in
folio_batch_pageout().

> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 061414ff45bb8..1150361e7d525 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -1334,6 +1334,92 @@ static enum folio_pageout_result folio_try_pageout(struct folio *folio,
>  	unreachable();
>  }
>  
> +static void folio_batch_pageout(struct folio_batch *batch,
> +		struct reclaim_folio_state *state, struct scan_control *sc,
> +		struct reclaim_stat *stat, struct swap_io_ctx *ctx,
> +		struct list_head *folio_list)
> +{

[ ... ]

> +	for (i = 0; i < nr; i++) {
> +		struct folio *folio = batch->folios[i];
> +
> +		switch (folio_try_pageout(folio, sc, ctx, folio_list)) {

[ ... ]

> @@ -1721,6 +1804,10 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
>  		VM_BUG_ON_FOLIO(folio_test_lru(folio) ||
>  				folio_test_unevictable(folio), folio);
>  	}
> +	if (folio_batch_count(&pageout_folios)) {
> +		folio_batch_pageout(&pageout_folios, &state, sc, stat,
> +				    &ctx, folio_list);
> +	}
>  	/* 'folio_list' is always empty here */

[Severity: Medium]
What happens if a dirty large shmem folio is split during this final
folio_batch_pageout() call after the while (!list_empty(folio_list)) loop
has already exited?

When folio_batch_pageout() calls folio_try_pageout() -> pageout() ->
shmem_writeout(), shmem_writeout() can split a large shmem folio via
split_folio_to_list(folio, folio_list) (for example when CONFIG_THP_SWAP is
disabled, the folio crosses i_size, or folio_alloc_swap() fails with
-E2BIG):

mm/shmem.c:shmem_writeout() {
	...
		if (split_folio_to_list(folio, folio_list))
			goto redirty;
	...
}

Then folio_try_pageout() adjusts sc->nr_scanned expecting the newly split
tail folios on folio_list to be scanned by the main loop in
shrink_folio_list():

mm/vmscan.c:folio_try_pageout() {
	...
	case PAGE_ACTIVATE:
		/*
		 * If shmem folio is split when writeback to swap, the
		 * tail pages will make their own pass through this
		 * function and be accounted then.  There is no need to
		 * clamp nr_pages here: folio_activate_locked() derives
		 * the count from folio_nr_pages() itself.
		 */
		if (nr_pages > 1 && !folio_test_large(folio))
			sc->nr_scanned -= (nr_pages - 1);
		return FOLIO_PAGEOUT_ACTIVATE;
	case PAGE_KEEP:
		return FOLIO_PAGEOUT_KEEP_LOCKED;
	case PAGE_SUCCESS:
		if (nr_pages > 1 && !folio_test_large(folio))
			sc->nr_scanned -= (nr_pages - 1);
	...
}

Because this final folio_batch_pageout() runs after the
while (!list_empty(folio_list)) loop has finished, won't those split tail
folios remain unprocessed on folio_list (violating the "'folio_list' is
always empty here" invariant) and leave sc->nr_scanned undercounted by
nr_pages - 1?

Should shrink_folio_list() loop back to process folio_list again if
folio_batch_pageout() adds split tail folios back onto folio_list?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261031-batch-tlb-flush-v6-0-190539839eec@tencent.com?part=5


  reply	other threads:[~2026-11-01  2:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31 10:35 [PATCH v6 0/5] mm: batch TLB flushing for dirty folios in vmscan Zhang Peng
2026-10-31 10:35 ` [PATCH v6 1/5] mm/vmscan: introduce folio_activate_locked() helper Zhang Peng
2026-10-31 10:35 ` [PATCH v6 2/5] mm/vmscan: extract folio reclaim freeing from shrink_folio_list() Zhang Peng
2026-10-31 10:35 ` [PATCH v6 3/5] mm/vmscan: extract folio pageout " Zhang Peng
2026-10-31 10:35 ` [PATCH v6 4/5] mm/vmscan: extract folio unmap logic into folio_try_unmap() Zhang Peng
2026-10-31 10:35 ` [PATCH v6 5/5] mm/vmscan: batch dirty TLB flushes before pageout Zhang Peng
2026-11-01  2:51   ` sashiko-bot [this message]
2026-11-15 23:02 ` [PATCH v6 0/5] mm: batch TLB flushing for dirty folios in vmscan Barry Song (Xiaomi)
2026-11-15 23:27   ` Barry Song

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-192259@kernel.org \
    --to=sashiko-bot@kernel.org \
    --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=bruzzhang@tencent.com \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kasong@tencent.com \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@kernel.org \
    --cc=qi.zheng@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=weixugc@google.com \
    --cc=yuanchu@google.com \
    --cc=zippermonkey@icloud.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