Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
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 v2 6/8] fs: Add throttling to deferred inode reclaim
Date: Wed, 25 Nov 2026 12:00:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-233315@kernel.org> (raw)
In-Reply-To: <20261124115850.3512-14-jack@suse.cz>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] fs: sub-jiffy delay truncation to 1-jiffy sleep in
  deferred_delay_work()
- [Low] trace: writeback: non-standard
  mark_inode_reclaim_deferred_throttle name
- [Low] fs: missing __GFP_NOWARN and direct GFP_NOFS in
  throttle_inode_deferred_reclaim()
--

commit 1ea5687985f2e4f8753b554cdf12dd2d8a420e3c
Author: Jan Kara <jack@suse.cz>

fs: Add throttling to deferred inode reclaim

This commit adds a throttling mechanism that delays tasks on return to
userspace when the per-superblock deferred inode reclaim list exceeds
INODE_DEFERRED_RECLAIM_LIMIT, proportional to the moving-average per-inode
eviction duration.

> diff --git a/fs/inode.c b/fs/inode.c
> index dfba54288cbfd..fdab88f875454 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
[ ... ]
> @@ -1216,6 +1256,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);
> +}
> +
> +/*
> + * 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)
> +{
[ ... ]
> +	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;
> +
> +		if (!delay)
> +			return;
> +
> +		dd = kmalloc_obj(*dd, GFP_NOFS | __GFP_NORETRY);
> +		/*
> +		 * If the allocation failed, don't bother. Throttling is
> +		 * approximate anyway and next time we'll throttle more.
> +		 */
> +		if (!dd)
> +			return;

[Severity: Low]
Since allocation failure is intentionally ignored here, should this include
__GFP_NOWARN so a failed slab expansion under memory pressure does not trigger
warn_alloc() and slab_out_of_memory() splats in dmesg?  Also, MM guidelines
prefer scoped memalloc_nofs_save()/memalloc_nofs_restore() (or
GFP_NOWAIT | __GFP_NOWARN) over passing GFP_NOFS directly.

> +
> +		/*
> +		 * 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);

[Severity: Medium]
Does passing nsecs_to_jiffies(dd->delay) to schedule_timeout_killable() stall
tasks for a full jiffy whenever the scaled nanosecond delay is sub-jiffy or 0?

throttle_inode_deferred_reclaim() checks !delay and allocates dd before
scaling delay down by (len - 8192) / 8192, so a small s_deferred_reclaim_delay
near the limit scales to 0 ns and still queues deferred_delay_work().
Even when the scaled delay is non-zero, any sub-jiffy value is truncated to
0 jiffies by nsecs_to_jiffies(), and schedule_timeout(0) does not return
immediately: it arms a timer for jiffies + 1 and sleeps until the next timer
tick (1 to 10 ms depending on HZ), defeating the proportional ramp-up.

Scaling delay before checking !delay and allocating dd, and sleeping with
schedule_hrtimeout() in deferred_delay_work(), would avoid queuing 0-ns waits
and preserve sub-jiffy delays.

[ ... ]
> diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
> index c2a5b492a71a5..d371d1112843f 100644
> --- a/include/trace/events/writeback.h
> +++ b/include/trace/events/writeback.h
[ ... ]
> +TRACE_EVENT(mark_inode_reclaim_deferred_throttle,
> +	TP_PROTO(struct inode *inode, unsigned int len, u64 delay),
> +	TP_ARGS(inode, len, delay),

[Severity: Low]
This isn't a bug, but tracepoint names normally follow the subsystem_event
convention (such as inode_reclaim_throttle, matching inode_reclaim_update_stat
above) rather than starting with the verb mark_.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124115850.3512-9-jack@suse.cz?part=6


  reply	other threads:[~2026-11-25 12:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 11:58 [PATCH 0/8 v4] fs: Deferred inode reclaim Jan Kara
2026-11-24 11:58 ` [PATCH v2 1/8] writeback: Fix missed lazytime flush Jan Kara
2026-11-24 11:58 ` [PATCH v2 2/8] fs: Avoid inode dirtying on last iput Jan Kara
2026-11-25 12:00   ` sashiko-bot
2026-11-24 11:58 ` [PATCH v2 3/8] fs: Basic infrastructure for offloading inode reclaim Jan Kara
2026-11-25 12:00   ` sashiko-bot
2026-11-24 11:58 ` [PATCH v2 4/8] fs: Defer reclaim of unlinked inodes Jan Kara
2026-11-25 12:00   ` sashiko-bot
2026-11-24 11:58 ` [PATCH v2 5/8] fs: Defer reclaim of inodes requiring metadata writeback Jan Kara
2026-11-24 11:58 ` [PATCH v2 6/8] fs: Add throttling to deferred inode reclaim Jan Kara
2026-11-25 12:00   ` sashiko-bot [this message]
2026-11-24 11:58 ` [PATCH v2 7/8] fs: Protect deferred inode reclaim from freezing Jan Kara
2026-11-25 12:00   ` sashiko-bot
2026-11-24 11:58 ` [PATCH v2 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-233315@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