From: Tejun Heo <tj@kernel.org>
To: Jan Kara <jack@suse.cz>
Cc: Christian Brauner <brauner@kernel.org>, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 1/4] writeback: Avoid contention on wb->list_lock when switching inodes
Date: Tue, 9 Sep 2025 06:52:27 -1000 [thread overview]
Message-ID: <aMBbSxwwnvBvQw8C@slm.duckdns.org> (raw)
In-Reply-To: <20250909144400.2901-5-jack@suse.cz>
Hello, Jan.
On Tue, Sep 09, 2025 at 04:44:02PM +0200, Jan Kara wrote:
> There can be multiple inode switch works that are trying to switch
> inodes to / from the same wb. This can happen in particular if some
> cgroup exits which owns many (thousands) inodes and we need to switch
> them all. In this case several inode_switch_wbs_work_fn() instances will
> be just spinning on the same wb->list_lock while only one of them makes
> forward progress. This wastes CPU cycles and quickly leads to softlockup
> reports and unusable system.
>
> Instead of running several inode_switch_wbs_work_fn() instances in
> parallel switching to the same wb and contending on wb->list_lock, run
> just one instance and let the other isw items switching to this wb queue
> behind the one being processed.
>
> Signed-off-by: Jan Kara <jack@suse.cz>
...
> +static void inode_switch_wbs_work_fn(struct work_struct *work)
> +{
> + struct inode_switch_wbs_context *isw =
> + container_of(to_rcu_work(work), struct inode_switch_wbs_context, work);
> + struct bdi_writeback *new_wb = isw->new_wb;
> + bool switch_running;
> +
> + spin_lock_irq(&new_wb->work_lock);
> + switch_running = !list_empty(&new_wb->switch_wbs_ctxs);
> + list_add_tail(&isw->list, &new_wb->switch_wbs_ctxs);
> + spin_unlock_irq(&new_wb->work_lock);
> +
> + /*
> + * Let's leave the real work for the running worker since we'd just
> + * contend with it on wb->list_lock anyway.
> + */
> + if (switch_running)
> + return;
> +
> + /* OK, we will be doing the switching work */
> + wb_get(new_wb);
> + spin_lock_irq(&new_wb->work_lock);
> + while (!list_empty(&new_wb->switch_wbs_ctxs)) {
> + isw = list_first_entry(&new_wb->switch_wbs_ctxs,
> + struct inode_switch_wbs_context, list);
> + spin_unlock_irq(&new_wb->work_lock);
> + process_inode_switch_wbs_work(isw);
> + spin_lock_irq(&new_wb->work_lock);
> + list_del(&isw->list);
> + kfree(isw);
> + }
> + spin_unlock_irq(&new_wb->work_lock);
> + wb_put(new_wb);
> +}
Would it be easier to achieve the same effect if we just reduced @max_active
when creating inode_switch_wbs? If we update cgroup_writeback_init() to use
the following instead:
isw_wq = alloc_workqueue("inode_switch_wbs", WQ_UNBOUND, 1);
Wouldn't that achieve the same thing? Note the addition of WQ_UNBOUND isn't
strictly necessary but we're in the process of defaulting to unbound
workqueues, so might as well update it together. I can't think of any reason
why this would require per-cpu behavior.
Thanks.
--
tejun
next prev parent reply other threads:[~2025-09-09 16:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 14:44 [PATCH 0/4] writeback: Avoid lockups when switching inodes Jan Kara
2025-09-09 14:44 ` [PATCH 1/4] writeback: Avoid contention on wb->list_lock " Jan Kara
2025-09-09 16:52 ` Tejun Heo [this message]
2025-09-10 8:19 ` Jan Kara
2025-09-10 17:10 ` Tejun Heo
2025-09-11 11:30 ` Jan Kara
2025-09-11 12:01 ` Jan Kara
2025-09-12 10:39 ` Jan Kara
2025-09-09 14:44 ` [PATCH 2/4] writeback: Avoid softlockup when switching many inodes Jan Kara
2025-09-09 16:55 ` Tejun Heo
2025-09-09 14:44 ` [PATCH 3/4] writeback: Avoid excessively long inode switching times Jan Kara
2025-09-09 16:56 ` Tejun Heo
2025-09-09 14:44 ` [PATCH 4/4] writeback: Add tracepoint to track pending inode switches Jan Kara
2025-09-09 16:57 ` Tejun Heo
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=aMBbSxwwnvBvQw8C@slm.duckdns.org \
--to=tj@kernel.org \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).