On 9/13/26 12:24 PM, Yu Kuai wrote:
From: Yu Kuai<[email protected]>

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.

Keep completion and accounting users lookup-only when they do not create
a blkg themselves. In particular, blk_cgroup_bio_start() only accounts a
bio when a policy path has already pinned BIO_BLKG_REF. This avoids
creating a blkg from the unconditional accounting hook when no policy is
enabled.

Protect every rhashtable lookup with an RCU read-side critical section.
Annotate the lookup helpers and recursive wrappers with
__must_hold_shared(RCU) so Clang can verify that contract.

Do not include BIO_BLKG_REF in device-mapper saved bio flags. Remapping
drops the associated reference, and restoring the bit later would claim
ownership without reacquiring the reference.

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.

Signed-off-by: Yu Kuai<[email protected]>
Reviewed-by: Tao Cui<[email protected]>

Looks good to me.
Reviewed-by: Nilay Shroff <[email protected]>


Reply via email to