Linux EXT4 FS development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Qiliang Yuan" <odys.yuan@gmail.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH v5] jbd2: fix shrinker scan budget accounting in jbd2_journal_shrink_scan()
Date: Thu, 01 Oct 2026 07:53:17 +0000	[thread overview]
Message-ID: <20261001075317.9E5B01F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261001-fix-jbd2-shrink-scan-nr-scanned-v5-1-5348b51efce2@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] jbd2: shrinker busy-loops rescanning the same busy checkpoint items
--

commit 22efbdb58b6c52d305510bf987737313bb851b41
Author: Qiliang Yuan <odys.yuan@gmail.com>

jbd2: fix shrinker scan budget accounting in jbd2_journal_shrink_scan()

This patch updates jbd2_journal_shrink_scan() to report the actual number of
scanned buffers back to the shrinker subsystem. It sets sc->nr_scanned based
on how many buffers jbd2_journal_shrink_checkpoint_list() examined, and uses
this value to determine whether to return SHRINK_STOP.

> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index 00f5a98f3d4fe..eac5f84a1afc5 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -1263,10 +1263,22 @@ 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);
>  
> +	/*
> +	 * Key SHRINK_STOP off sc->nr_scanned (buffers actually examined),
> +	 * not nr_shrunk (buffers actually freed): a batch can find every
> +	 * buffer in its transactions busy and free none, while later
> +	 * transactions may still hold buffers whose writeback has
> +	 * completed. sc->nr_scanned only comes back 0 when the checkpoint
> +	 * list had nothing left to walk.
> +	 */
> +	if (sc->nr_scanned == 0)

[Severity: High]
Does this condition cause do_shrink_slab() to busy-loop when the checkpoint
list is fully exhausted but contains a few busy items?

If the shrinker budget is large (for example, due to a stale percpu counter)
but the checkpoint list has only a small number of busy items (e.g., 5),
jbd2_journal_shrink_checkpoint_list() will scan them and set sc->nr_scanned
to 5. Upon reaching the end of the list, it resets
journal->j_shrink_transaction to NULL.

Because sc->nr_scanned is 5, this fails to return SHRINK_STOP.

Will do_shrink_slab() then subtract 5 from its budget and loop immediately,
restarting from the beginning of the list and rescanning those exact same 5
busy items? If this repeats until the large budget is completely drained in
increments of 5, could it cause CPU busy-looping and j_list_lock contention
in the memory reclaim path?

> +		return SHRINK_STOP;
> +
>  	return nr_shrunk;
>  }
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261001-fix-jbd2-shrink-scan-nr-scanned-v5-1-5348b51efce2@gmail.com?part=1

      reply	other threads:[~2026-10-01  7:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01  7:43 [PATCH v5] jbd2: fix shrinker scan budget accounting in jbd2_journal_shrink_scan() Qiliang Yuan
2026-10-01  7:53 ` sashiko-bot [this message]

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=20261001075317.9E5B01F000FF@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