Re: [RFC PATCH v2 1/8] block: associate blkg in submit_bio instead of bio_set_dev
Nilay Shroff <[email protected]> Wed, 29 Jul 2026 13:35:40 +0530
| Newsgroups | org.kernel.vger.cgroups,org.kernel.vger.linux-block |
|---|---|
| Message-ID | <[email protected]> |
On 7/27/26 1:46 PM, yu kuai wrote: > Hi, > > 在 2026/7/24 20:30, Yu Kuai 写道: >> From: Yu Kuai<[email protected]> >> >> bio_set_dev(), bio_init() and bio_reset() associate a bio with a blkg for >> its target queue. That association may have to create a new blkg, and >> currently there are lots of callers that are under atomic context. >> >> Move the association out of those helpers and into the submit path, which >> is always sleepable (submit_bio_noacct() already does might_sleep()): >> >> - submit_bio() associates new I/O before bio_set_ioprio(), whose >> blkcg_set_ioprio() reads the policy from bio->bi_blkg. >> >> - submit_bio_noacct() (re)associates when a bio has no blkg yet or was >> remapped to a different queue. blk_throtl_bio() and the rq_qos >> throttlers (iocost, iolatency) pair bio->bi_blkg with the queue of >> bio->bi_bdev, so a remapped bio must be reassociated to the new queue. >> >> - bio_set_dev() no longer associates; instead it drops the existing blkg >> when the device changes, since that blkg is tied to the old queue. >> bio_init()/bio_reset() leave bi_blkg NULL. >> >> Introduce bio_disassociate_blkg() to drop a bio's blkg reference and use it >> from bio_set_dev(), bio_uninit() and the bio freeing path, replacing their >> open-coded blkg_put(). > Turns out bio will be submitted by kworker for some drivers and for > blkcg_punt_bio_submit(). Is it possible to record blkcg during bio initialization, > as blkcg must exist, and then covert it to blkg during submission? I can use union > for blkcg and blkg to avoid new field in struct bio. Since blkcg_punt_bio_submit() is the only deferred submission path, and it seems to me that all of its callers (btrfs mostly) appear to be in sleepable context, would it be sufficient to associate the blkg before punting the bio rather than changing the bio lifetime semantics? Thanks, --Nilay