Skip to content

blk-cgroup: store blkcg in bio before blkcg_mutex conversion - #1152

Open
blktests-ci[bot] wants to merge 3 commits into
linus-master_basefrom
series/1139858=>linus-master
Open

blk-cgroup: store blkcg in bio before blkcg_mutex conversion#1152
blktests-ci[bot] wants to merge 3 commits into
linus-master_basefrom
series/1139858=>linus-master

Conversation

@blktests-ci

@blktests-ci blktests-ci Bot commented Aug 18, 2026

Copy link
Copy Markdown

Pull request for series with
subject: blk-cgroup: store blkcg in bio before blkcg_mutex conversion
version: 3
url: https://patchwork.kernel.org/project/linux-block/list/?series=1147597

Yu Kuai added 3 commits August 18, 2026 08:05
blkg lookup currently uses a per-blkcg radix tree keyed by request queue
ID, plus a lookup hint for the common case. This spreads the queue-local
blkcg association index across every blkcg and requires radix-tree
preloading before creating a blkg while holding q->queue_lock.

Replace the radix tree and lookup hint with a request_queue-owned
rhashtable keyed by the blkcg CSS ID. Cache the ID in each blkg; the blkg
holds a CSS reference until after it leaves the hash, so the ID cannot be
reused while it is hash-visible. The integer key also reduces hashing and
comparison work relative to a pointer-sized key on 64-bit systems.

Keep entries until blkg_release() and provide blkg_lookup_any() for callers
which need to find dying entries. blkg_lookup() filters offline entries so
existing lookup semantics remain unchanged.

Keep q->blkg_list for ordered policy and scheduler walks. All current
walkers are cgroupfs or sysfs slow paths, so they can move to rhashtable
iteration once the q->queue_lock to q->blkcg_mutex conversion lands.
Initialize and destroy the hash with request_queue, and remove the
radix-tree preload paths which are no longer needed.

blkg_release() removes the hash entry only when the blkg was successfully
inserted into q->blkg_list; the list_empty case covers allocation or
creation failure before insertion.

Signed-off-by: Yu Kuai <yukuai@fygo.io>
A bio currently stores and pins a queue-local blkg. This forces bio
association and remap paths to look up or create a blkg even when no
blkcg policy will use the bio, and ties the stored state to the current
block device.

Store and reference the queue-independent blkcg in the bio instead. Add
helpers that lazily look up or create the queue-local blkg when a policy
needs it, and pin the result until the bio changes devices or releases
its cgroup state.

If blkg creation fails while walking down the hierarchy, use the closest
available ancestor and update the bio's blkcg association before recording
the blkg reference. This keeps later CSS ID hash lookups matched with the
pinned blkg.

Keep lookup-only users from creating missing blkgs. A pinned blkg remains
in the queue hash until the bio drops its reference, so allow the bio to
recover it from the hash after the blkg starts dying. Rename the bio
association helpers to describe the blkcg state they now store.

Signed-off-by: Yu Kuai <yukuai@fygo.io>
blkcg_punt_bio_submit() currently queues punted bios on blkg->async_bios,
so it has to call bio_blkg() to find or create a queue-local blkg.  Bios
now carry and pin the blkcg css, so punted bio lifetime no longer needs to
be anchored by a blkg.

Keeping the punt state in blkg can instantiate a blkg even when no blkcg
policy is enabled, just to bounce submission from a shared kthread.  Move
async_bio_lock, async_bios and async_bio_work to struct blkcg, and queue
punted bios on bio_blkcg() for non-root cgroups.  Root or unassociated bios
are submitted directly.

This preserves the priority-inversion avoidance while preventing
blkcg_punt_bio_submit() from creating blkgs that are not needed by any
policy.

Signed-off-by: Yu Kuai <yukuai@fygo.io>
@blktests-ci

blktests-ci Bot commented Aug 18, 2026

Copy link
Copy Markdown
Author

Upstream branch: 8d3ae59
series: https://patchwork.kernel.org/project/linux-block/list/?series=1147597
version: 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants