Re: [PATCH v2 3/3] writeback: use a per-sb counter to drain inode wb switches at umount

From: Baokun Li

Date: Mon May 18 2026 - 07:58:07 EST


在 2026/5/18 19:42, Christian Brauner 写道:
> On Sun, 17 May 2026 22:21:32 +0800, Baokun Li <libaokun@xxxxxxxxxxxxxxxxx> wrote:
>> diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
>> index 9ae290547eb2..4282fcfe027b 100644
>> --- a/fs/fs-writeback.c
>> +++ b/fs/fs-writeback.c
>> @@ -1215,38 +1209,30 @@ int cgroup_writeback_by_id(u64 bdi_id, int memcg_id,
>> [ ... skip 38 lines ... ]
>> - * in-flight switcher that already passed the SB_ACTIVE check
>> - * to finish queueing its work, so flush_workqueue() below
>> - * will then drain it.
>> - */
>> - synchronize_rcu();
>> + while (atomic_read(&sb->s_isw_nr_in_flight)) {
> Would probably be a bit nicer to just wait until the count is zero?
> We have that pattern for inode_dio_wait(). So something like (untested):
>
> static bool cgroup_writeback_finished(const struct super_block *sb)
> {
> if (atomic_read(&sb->s_isw_nr_in_flight) == 0)
> return true;
>
> flush_workqueue(isw_wq);
> return false;
> }
>
> void cgroup_writeback_wait(const struct super_block *sb)
> {
> wait_var_event(&sb->s_isw_nr_in_flight, cgroup_writeback_finished(sb));
> }
>
> void cgroup_writeback_finish(const struct super_block *sb)
> {
> if (atomic_dec_and_test(&sb->s_isw_nr_in_flight))
> wake_up_var(&sb->s_isw_nr_in_flight);
> }
>

Thank you for your suggestion!

Totally agree. sashiko also raised similar opinions, and
I will send out the v3 patch using this proposal right away.


Cheers,
Baokun