blk-cgroup: store blkcg in bio before blkcg_mutex conversion - #1152
Open
blktests-ci[bot] wants to merge 3 commits into
Open
blk-cgroup: store blkcg in bio before blkcg_mutex conversion#1152blktests-ci[bot] wants to merge 3 commits into
blktests-ci[bot] wants to merge 3 commits into
Conversation
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>
Author
|
Upstream branch: 8d3ae59 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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