Re: [PATCH] bfq: Transfer allocated request counts when moving queues

From: yu kuai

Date: Tue Nov 10 2026 - 04:13:47 EST


在 2026/10/28 17:42, sunyangkai 写道:

> When bfq_bfqq_move() moves a queue with outstanding requests to another
> group, it changes entity->parent without transferring these charges.
> The old ancestors retain the charges, while subsequent request releases
> decrement the new ancestors even though they were never charged. This
> can leave the destination group's allocated count negative and the
> source group's count inflated after all requests have completed,
> distorting the limits enforced by bfqq_request_over_limit().
>
> Subtract the queue's outstanding request count from its old ancestors
> before dropping the old group reference, and add it to the new ancestors
> after reparenting. Leave the queue's own count unchanged. Shared
> ancestors have no net change, and bfqd->lock serializes the transfer
> with request accounting.
>
> Fixes: 98f044999ba1 ("bfq: Track number of allocated requests in bfq_entity")
> Cc:stable@xxxxxxxxxxxxxxx
> Signed-off-by: sunyangkai<sunyangkai@xxxxxxxxx>
> ---
> Validation used a QEMU guest running a 6.18.18-based kernel, with BFQ
> on a virtio block device. The workload submitted direct asynchronous
> reads in /a/child, moved the task to /b, submitted more reads, and waited
> for all completions before repeating. A read-only kretprobe observed
> bfq_bfqq_move() entry and return counters.
>
> Without the fix, the drained destination group reached allocated=-1
> and then -2. With the fix, outstanding charges were transferred and
> the drained group counts were zero. Both runs covered migrations with
> outstanding requests, completed all reads successfully, and reported
> zero missed probes. This was not a runtime test of upstream master.
>
> block/bfq-cgroup.c | 6 ++++++
> 1 file changed, 6 insertions(+)
Reviewed-by: Yu Kuai <yukuai@xxxxxxx>

--
Thanks,
Kuai