From: sashiko-bot@kernel.org
To: "Jan Kara" <jack@suse.cz>, "Christian Brauner" <brauner@kernel.org>
Cc: "Christoph Hellwig" <hch@infradead.org>,
linux-mm@kvack.org, "Mikhail Rudenko" <xyzzy@yandex-team.ru>,
"Andreas Gruenbacher" <agruenba@redhat.com>
Subject: Re: [PATCH v5 7/8] fs: Add throttling to deferred inode reclaim
Date: Wed, 02 Dec 2026 14:36:41 +0000 [thread overview]
Message-ID: <sashiko-outbox-245973@kernel.org> (raw)
In-Reply-To: <20261201143522.483168-15-jack@suse.cz>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] fs: sub-jiffy delay truncates to 0 in deferred_delay_work()
- [Medium] fs: missing PF_EXITING checks in deferred inode reclaim
throttling
- [Low] fs: missing __GFP_NOWARN in throttle_inode_deferred_reclaim()
allocation
--
commit 9f0a0ebfbed99db0ac1abb610f2f8e9a97ee5e15
Author: Jan Kara <jack@suse.cz>
fs: Add throttling to deferred inode reclaim
This commit tracks the average per-inode deferred reclaim duration per
superblock and throttles tasks calling mark_inode_reclaim_deferred() via
TWA_RESUME task_work when the deferred reclaim queue exceeds a threshold.
> diff --git a/fs/inode.c b/fs/inode.c
> index 581d8b9888ac0..d2ae950bba6bd 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
[ ... ]
> @@ -1217,6 +1257,80 @@ static void __init deferred_reclaim_init(void)
> }
> }
>
> +struct deferred_reclaim_delay {
> + struct callback_head task_work;
> + u64 delay;
> +};
> +
> +static void deferred_delay_work(struct callback_head *work)
> +{
> + struct deferred_reclaim_delay *dd =
> + container_of(work, struct deferred_reclaim_delay, task_work);
> +
> + schedule_timeout_killable(nsecs_to_jiffies(dd->delay));
> + kfree(dd);
> +}
[Severity: Medium]
Does passing nsecs_to_jiffies(dd->delay) to schedule_timeout_killable()
cause any sub-jiffy nanosecond delay to sleep for a full jiffy?
throttle_inode_deferred_reclaim() checks whether the scaled delay is
non-zero in nanoseconds, so any delay between 1 ns and TICK_NSEC - 1 ns
queues deferred_delay_work(). nsecs_to_jiffies() truncates sub-jiffy
values to 0, and schedule_timeout(0) does not return immediately:
kernel/time/sleep_timeout.c:schedule_timeout() {
...
expire = timeout + jiffies;
timer.task = current;
timer_setup_on_stack(&timer.timer, process_timeout, 0);
timer.timer.expires = expire;
add_timer(&timer.timer);
schedule();
...
}
As a result, any non-zero sub-jiffy delay sleeps until the next timer tick
instead of scaling proportionally with the queue length or respecting the
4x reclaim time cap. Using schedule_hrtimeout() (similar to
blkcg_maybe_throttle_blkg()) or checking the converted jiffies value for
zero before queuing task_work would avoid this.
> +
> +/*
> + * Size of deferred reclaim list from which we start throttling tasks creating
> + * inodes marked for deferred reclaim.
> + */
> +#define INODE_DEFERRED_RECLAIM_LIMIT 8192
> +
> +static void throttle_inode_deferred_reclaim(struct inode *inode)
> +{
> + struct super_block *sb = inode->i_sb;
> + unsigned int len;
> +
> + /*
> + * Don't throttle kthreads. They are doing work for somebody else
> + * anyway so throttling is counterproductive.
> + */
> + if (current->flags & PF_KTHREAD)
> + return;
[Severity: Medium]
Should throttle_inode_deferred_reclaim() and deferred_delay_work() also
bail out when current->flags & PF_EXITING is set?
If mark_inode_reclaim_deferred() is called right before a task enters
do_exit() without returning to userspace (for example during
vfs_coredump() in get_signal()) or during do_exit() before
exit_task_work() runs (such as acct_process()), deferred_delay_work() will
be executed from exit_task_work(). By that point exit_signals() has
already set PF_EXITING and flushed pending signals including SIGKILL, so
schedule_timeout_killable() sleeps uninterruptibly on a task that is
already exiting.
> +
> + /*
> + * If inodes with deferred reclaim are accumulating too much, slow down
> + * tasks creating them. This doesn't provide any kind of guarantee on
> + * the length of the deferred list since lots of inodes with
> + * I_DEFER_RECLAIM can be already present in the inode cache and we
> + * have no control when they reach the deferred list. But if the
> + * pressure on the deferred list is sustained, the balance should
> + * eventually be established.
> + */
> + len = atomic_read(&sb->s_deferred_reclaim_count);
> + if (len > INODE_DEFERRED_RECLAIM_LIMIT) {
> + u64 delay = READ_ONCE(sb->s_deferred_reclaim_delay);
> + struct deferred_reclaim_delay *dd;
> +
> + /*
> + * Scale the delay based on how much we exceed the limit. Wait
> + * at most 4x as long as estimated time to reclaim the inode.
> + */
> + len = min(len, 5 * INODE_DEFERRED_RECLAIM_LIMIT);
> + delay = div_u64(delay * (len - INODE_DEFERRED_RECLAIM_LIMIT),
> + INODE_DEFERRED_RECLAIM_LIMIT);
> + if (!delay)
> + return;
> +
> + dd = kmalloc_obj(*dd, GFP_NOFS | __GFP_NORETRY);
[Severity: Low]
Should this opportunistic allocation include __GFP_NOWARN? Because
allocation failure is expected and ignored under memory pressure, omitting
__GFP_NOWARN allows the page and slab allocators to emit allocation
failure warnings and backtraces when __GFP_NORETRY gives up.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201105733.18997-1-jack@suse.cz?part=7
next prev parent reply other threads:[~2026-12-02 14:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 14:35 [PATCH v5 0/8] fs: Deferred inode reclaim Jan Kara
2026-12-01 14:35 ` [PATCH v5 1/8] writeback: Fix missed lazytime flush Jan Kara
2026-12-01 14:35 ` [PATCH v5 2/8] fs: Fix inode writeback list placement for switched and redirtied inodes Jan Kara
2026-12-02 14:36 ` sashiko-bot
2026-12-01 14:35 ` [PATCH v5 3/8] fs: Avoid inode dirtying on last iput Jan Kara
2026-12-02 14:36 ` sashiko-bot
2026-12-01 14:35 ` [PATCH v5 4/8] fs: Basic infrastructure for offloading inode reclaim Jan Kara
2026-12-02 14:36 ` sashiko-bot
2026-12-01 14:35 ` [PATCH v5 5/8] fs: Defer reclaim of unlinked inodes Jan Kara
2026-12-02 14:36 ` sashiko-bot
2026-12-01 14:35 ` [PATCH v5 6/8] fs: Defer reclaim of inodes requiring metadata writeback Jan Kara
2026-12-01 14:35 ` [PATCH v5 7/8] fs: Add throttling to deferred inode reclaim Jan Kara
2026-12-02 14:36 ` sashiko-bot [this message]
2026-12-01 14:35 ` [PATCH v5 8/8] ext4: Defer inode reclaim if it has preallocations Jan Kara
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-245973@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agruenba@redhat.com \
--cc=brauner@kernel.org \
--cc=hch@infradead.org \
--cc=jack@suse.cz \
--cc=linux-mm@kvack.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xyzzy@yandex-team.ru \
/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