Re: [RFC PATCH 1/1] block: charge passthrough requests to the submitter's cgroup
From: Tao Cui
Date: Tue Sep 22 2026 - 04:20:08 EST
Hi Tejun,
在 2026/9/22 00:51, Tejun Heo 写道:
> On Mon, Sep 21, 2026 at 03:06:47PM +0800, Tao Cui wrote:
>> From: Tao Cui <cuitao@xxxxxxxxxx>
>>
>> Passthrough requests (SG_IO, bsg, nvme passthrough ioctls and uring
>> commands) are dispatched via blk_execute_rq{,_nowait}() without ever
>> passing through submit_bio(), so the bio mapped by blk_rq_map_user()
>> carries no blkcg association: the transferred bytes never show up in
>> cgroup io.stat, and every rq_qos policy on the queue (iocost,
>> iolatency, wbt) is bypassed, as is blk-throttle, which hooks
>> submit_bio_noacct() directly rather than going through rq_qos.
>>
>> A quick demonstration on a scsi_debug device with iocost enabled and
>> vrate pinned to its 1% floor: a direct fio writer was throttled ~10x
>> while the same cgroup issuing sg_dd writes ran at full device speed
>> with zero io.stat accounting.
>>
>> Associate the mapped bio with the submitter's blkcg at dispatch time
>> and run the regular bio accounting (blk_cgroup_bio_start()) and
>> rq_qos throttle paths with it. DRV_IN/DRV_OUT commands are mapped to
>> READ/WRITE so io.stat classifies their bytes normally; request
>> completion already pairs with the throttle through bio_endio() ->
>> rq_qos_done_bio().
>>
>> The charge is gated by opcode (READ/WRITE/DRV_IN/DRV_OUT) and to
>> queues that already have a gendisk: commands issued during device
>> probing (SCSI INQUIRY etc.) have no gendisk yet and stay exempt,
>> following the same probe-exemption reasoning as the passthrough
>> iostats support.
>
> Do you have an actual use case where this matters?
>
I don't have a specific passthrough workload that triggered this in
production. I ran into it while testing blk-iocost accounting coverage.
The relevant concern here is cgroup IO isolation. The expectation of
blkcg IO control is that the IO consumed by a cgroup is reflected in its
accounting and subject to blkcg IO policies. Today that is true for IO
going through submit_bio(), but not for passthrough requests.
The concrete observation was that the same cgroup issuing equivalent
writes through two paths gets different results: normal bio IO is
accounted in io.stat and subject to blkcg IO policies, while SG_IO
writes consume device bandwidth without accounting or blkcg IO control.
So the motivation is not a particular SG_IO application, but whether
passthrough IO should be considered part of the IO usage controlled by
blkcg.
I don't know yet whether the right answer is always-on behavior or an
opt-in mechanism. The RFC was mainly to discuss whether passthrough
paths should be covered by blkcg accounting/enforcement at all.
Thanks,
Tao
> Thanks.
>