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 4/8] fs: Basic infrastructure for offloading inode reclaim
Date: Wed, 02 Dec 2026 14:36:39 +0000 [thread overview]
Message-ID: <sashiko-outbox-245970@kernel.org> (raw)
In-Reply-To: <20261201143522.483168-12-jack@suse.cz>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] fs: max_active in deferred_reclaim_init() halves reclaim
worker concurrency
--
commit 78588b33f83dd121e8205d253bf4506e512f1879
Author: Jan Kara <jack@suse.cz>
fs: Basic infrastructure for offloading inode reclaim
This commit adds infrastructure to mark inodes with I_DEFER_RECLAIM and
offload their eviction from prune_icache_sb() to a dedicated unbound
workqueue with parallel workers.
> diff --git a/fs/inode.c b/fs/inode.c
> index 4b13125f0678c..1f2f31d0f055c 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
[ ... ]
> @@ -1017,6 +1036,39 @@ static enum lru_status inode_lru_isolate(struct list_head *item,
> return LRU_REMOVED;
> }
>
> +/* Number of inodes to process in one reclaim batch */
> +#define INODE_RECLAIM_BATCH_SIZE 16
> +
> +static int get_deferred_sb_id(struct super_block *sb)
> +{
> + return hash_ptr(sb, 32) % deferred_reclaim.workers;
> +}
> +
> +static void queue_deferred_reclaim(struct super_block *sb, int count,
> + struct list_head *list)
> +{
> + int id = get_deferred_sb_id(sb);
> + struct deferred_reclaim_queue *queue =
> + &deferred_reclaim.queues[id];
> + int i, wake_count;
> +
> + spin_lock(&queue->lock);
> + list_splice_tail(list, &queue->list);
> + atomic_add(count, &sb->s_deferred_reclaim_count);
> + spin_unlock(&queue->lock);
> +
> + /* Make sure enough workers are woken for queued inodes of this sb */
> + wake_count = DIV_ROUND_UP(atomic_read(&sb->s_deferred_reclaim_count),
> + INODE_RECLAIM_BATCH_SIZE);
> + if (wake_count > deferred_reclaim.workers)
> + wake_count = deferred_reclaim.workers;
> + for (i = 0; i < wake_count; i++) {
> + queue_work(deferred_reclaim.wq,
> + &deferred_reclaim.work[id]);
> + id = (id + 1) % deferred_reclaim.workers;
> + }
> +}
[ ... ]
> +/* Maximum number of inode reclaim workers */
> +#define MAX_RECLAIM_WORKERS 16
> +
> +static void __init deferred_reclaim_init(void)
> +{
> + int workers = MAX_RECLAIM_WORKERS;
> + int i;
> +
> + /* Scale down the number of workers for small systems */
> + if (workers > num_possible_cpus())
> + workers = num_possible_cpus();
> +
> + deferred_reclaim.workers = workers;
> + deferred_reclaim.work = kmalloc_objs(struct work_struct, workers);
> + deferred_reclaim.queues =
> + kmalloc_objs(struct deferred_reclaim_queue, workers);
> + if (!deferred_reclaim.work || !deferred_reclaim.queues)
> + panic("Failed to allocate deferred inode reclaim queues");
> +
> + deferred_reclaim.wq = alloc_workqueue("deferred-inode-reclaim",
> + WQ_FREEZABLE | WQ_MEM_RECLAIM | WQ_UNBOUND,
> + workers);
[Severity: Medium]
Can setting max_active to workers cap the workqueue at half of its
intended concurrency during a sustained reclaim backlog?
When deferred_reclaim.work[id] starts executing in process_one_work(),
WORK_STRUCT_PENDING_BIT is cleared while the work item retains its
nr_active slot until inode_reclaim_deferred() returns. Because
queue_deferred_reclaim() always starts queuing from the same base id for a
superblock, any subsequent call while work[id] is still running in
inode_reclaim_deferred() re-queues that executing work_struct.
__queue_work() then acquires a second nr_active slot for the same
work[id] and wakes an idle kworker, which detects the execution collision
in assign_work(), moves work[id] to collision->scheduled, and goes back to
sleep while keeping the second nr_active slot pinned.
Once workers / 2 work items are running and have been re-queued once, all
max_active slots are consumed (or even earlier per node on NUMA systems
where max_active is distributed across nodes). The remaining idle
work[(id + i) % workers] items are placed on pwq->inactive_works and
cannot start because running workers do not exit inode_reclaim_deferred()
until all queues are completely empty. Since the number of concurrent
workers is already bounded by the deferred_reclaim.work array of size
workers, passing 0 (or WQ_MAX_ACTIVE) as max_active to alloc_workqueue()
would avoid the nr_active exhaustion, though re-queuing active work items
will still cause extra kworker wakeups.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201105733.18997-1-jack@suse.cz?part=4
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 [this message]
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
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-245970@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