Re: [PATCH v10] loop: defer the queue limits clear to a workqueue
From: Tao Cui
Date: Sat Dec 05 2026 - 22:53:18 EST
Hello, Bart,
在 2026/12/4 17:58, Tao Cui 写道:
> Hello, Bart,
>
> 在 2026/12/4 1:18, Bart Van Assche 写道:
>> On 12/3/26 12:16 AM, Tao Cui wrote:
>>> + lo->clear_wq = alloc_workqueue("loopc%d",
>>> + WQ_UNBOUND | WQ_MEM_RECLAIM,
>>> + 0, lo->lo_number);
>> WQ_MEM_RECLAIM creates a rescuer thread per loop device. Is that flag
>> really needed? Additionally, has it been considered to use a single
>> workqueue for all loop devices?
> Agreed on the flag: v11 drops it, loop%d, which runs the request path
> itself, does not use WQ_MEM_RECLAIM either.
>
> On a single workqueue for all devices: I'd rather not, if you're OK
> with that. The work function reads the loop_device, and the
> per-device queue is what keeps that safe, since lo_free_disk() destroys
> it before the loop_device is freed. A shared queue cannot be destroyed
> at teardown, so the work item would have to carry a new reference on
> the loop device. loop%d is per device already, so I'd keep this shape
> unless you prefer the shared queue.
I implemented your shared-queue suggestion and measured it against the
per-device one, and the tradeoff I mentioned turns out not to be a
real problem: the work item just carries a reference on the loop
device (get_device() when queued, put_device() when done), and nothing
else needs to change.
With your suggestion the clear workqueue is allocated once at module
init ("loopc") instead of per device. Both variants pass the same
suite with identical results (loop/011, the concurrency sweep, the
mkfs/unbind stress, with PROVE_LOCKING enabled), and 16 devices
clearing concurrently converge in the same ~38ms on both. The only
measurable difference is device lifecycle churn: a create/configure/
unbind/remove cycle takes ~9.9us with the shared queue vs ~10.4us with
the per-device queue, since the per-device version allocates and
destroys its workqueue under the global workqueue mutex every cycle.
So I'll use the shared queue in the series.
Thanks,
Tao.