From: sashiko-bot@kernel.org
To: "Qiliang Yuan" <odys.yuan@gmail.com>
Cc: tytso@mit.edu, linux-ext4@vger.kernel.org
Subject: Re: [PATCH v3] jbd2: fix shrinker scan budget accounting in jbd2_journal_shrink_scan()
Date: Mon, 28 Sep 2026 14:56:40 +0000 [thread overview]
Message-ID: <20260928145640.72B221F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260928-fix-jbd2-shrink-scan-nr-scanned-v3-1-916caaa53420@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] jbd2: SHRINK_STOP return bypasses nr_scanned accounting
--
commit 77b2a9acfe221fe68e4d994c53d398a2afba6743
Author: Qiliang Yuan <odys.yuan@gmail.com>
jbd2: fix shrinker scan budget accounting in jbd2_journal_shrink_scan()
This commit changes the jbd2 shrinker to report the actual number of
scanned objects via sc->nr_scanned. It also introduces a condition to
return SHRINK_STOP when no buffers were successfully freed, to prevent
do_shrink_slab() from looping over busy buffers.
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index 00f5a98f3d4fe..a61b7a59c0a0e 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -1263,10 +1263,27 @@ static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink,
> trace_jbd2_shrink_scan_enter(journal, sc->nr_to_scan, count);
>
> nr_shrunk = jbd2_journal_shrink_checkpoint_list(journal, &nr_to_scan);
> + sc->nr_scanned = sc->nr_to_scan - nr_to_scan;
>
> count = percpu_counter_read_positive(&journal->j_checkpoint_jh_count);
> trace_jbd2_shrink_scan_exit(journal, nr_to_scan, nr_shrunk, count);
>
> + /*
> + * Give up on this reclaim pass if this call didn't manage to free
> + * anything. This is deliberately based on nr_shrunk, not on
> + * sc->nr_scanned: a checkpoint list can be full of buffers that are
> + * still busy being written back, in which case a call can
> + * legitimately scan (and correctly report through sc->nr_scanned)
> + * a full batch of them without freeing a single one. Retrying
> + * immediately within the same synchronous reclaim pass is not going
> + * to let any of that in-flight writeback complete any sooner, so
> + * there is nothing to gain from letting do_shrink_slab() keep
> + * calling us against the same stale freeable count until its
> + * one-shot scan budget for this priority level is exhausted.
> + */
> + if (nr_shrunk == 0)
> + return SHRINK_STOP;
[Severity: Medium]
Will returning SHRINK_STOP here bypass the intended accounting of
sc->nr_scanned?
Looking at do_shrink_slab() in mm/shrinker.c, when a shrinker returns
SHRINK_STOP, the loop breaks early:
mm/shrinker.c:do_shrink_slab() {
...
ret = shrinker->scan_objects(shrinker, shrinkctl);
if (ret == SHRINK_STOP)
break;
freed += ret;
count_vm_events(SLABS_SCANNED, shrinkctl->nr_scanned);
total_scan -= shrinkctl->nr_scanned;
scanned += shrinkctl->nr_scanned;
...
}
Since the break happens before the accounting updates, won't this entirely
discard the scan progress reported by jbd2 when it hits a batch of busy
buffers? This appears to leave the scanned items unrecorded in vmstat and
leaves them un-subtracted from the deferred scan budget.
> +
> return nr_shrunk;
> }
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260928-fix-jbd2-shrink-scan-nr-scanned-v3-1-916caaa53420@gmail.com?part=1
next prev parent reply other threads:[~2026-09-28 14:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 14:44 [PATCH v3] jbd2: fix shrinker scan budget accounting in jbd2_journal_shrink_scan() Qiliang Yuan
2026-09-28 14:56 ` sashiko-bot [this message]
2026-09-29 21:05 ` Jan Kara
2026-09-30 3:31 ` Zhang Yi
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=20260928145640.72B221F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=odys.yuan@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tytso@mit.edu \
/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