Linux block layer
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai@kernel.org>
To: axboe@kernel.dk, tj@kernel.org
Cc: hch@lst.de, dongsheng.yang@linux.dev, cengku@gmail.com,
	josef@toxicpanda.com, nilay@linux.ibm.com, ming.lei@redhat.com,
	yukuai@fygo.io, linux-block@vger.kernel.org,
	cgroups@vger.kernel.org
Subject: [RFC PATCH v2 0/8] blk-cgroup: protect blkgs with blkcg_mutex
Date: Fri, 24 Jul 2026 20:30:29 +0800	[thread overview]
Message-ID: <20260724123037.3004560-1-yukuai@kernel.org> (raw)

From: Yu Kuai <yukuai@fygo.io>

This RFC moves queue-local blkg topology synchronization from q->queue_lock
to q->blkcg_mutex -- the same goal as v1 [1] -- but is restructured around
moving blkg association from bio_set_dev()/bio_init() into the submit path.

bio_set_dev() and bio allocation with a bdev currently associate a bio with
the destination queue's blkg.  Those helpers run from locked, irq-disabled
and GFP_NOWAIT contexts, so once missing-blkg creation is serialized by
q->blkcg_mutex they could no longer sleep safely.  Rather than auditing and
patching each such caller (as v1 did), v2 moves blkg association out of
bio_set_dev()/bio_init()/bio_reset() and into submit_bio()/
submit_bio_noacct(), which are always sleepable; bio_set_dev() now only
records the target device and drops the stale blkg.  This follows Christoph
Hellwig's review of v1.

q->blkcg_mutex then serializes blkg lookup/create/destroy, policy
[de]activation and configuration preparation; blkg allocation moves into
blkg_create() with a gfp_t argument; radix-tree preloading is removed; and
creation is shared between the bio path and configuration.

Nowait: REQ_NOWAIT I/O must not sleep to create a blkg.  The nowait
association path trylocks q->blkcg_mutex and allocates with GFP_ATOMIC; on
atomic context, mutex contention or allocation failure it leaves the bio
unassociated and submit_bio() completes it with BLK_STS_AGAIN so the
submitter retries.  This replaces v1's nowait-threading through the
bio_set_dev() callers.

Changes since v1 [1]:

- Reworked on top of "associate blkg in submit_bio instead of bio_set_dev"
- Dropped the per-subsystem bio_set_dev() workarounds -- NVMe multipath
  retarget (v1 1), dm-thin (v1 2), dm-snapshot (v1 3), bcache (v1 8),
  dm-bufio (v1 9), dm-pcache (v1 10), DM NOWAIT remaps (v1 12) -- no longer
  needed because bio_set_dev() no longer associates.
- Dropped atomic bio allocation -- bio_alloc_atomic() (v1 5) and
  non-blocking bio allocation with a bdev (v1 7); the
  nd_virtio/ocfs2 callers are handled separately.
- Dropped the nowait-bio-allocation association helpers (v1 6, 11); nowait
  is handled once, at submit, by failing the bio.
- Kept and adapted: blk-throttle private runtime lock (v1 4); the
  blkcg_mutex conversion (v1 14, now also annotating submit_bio() with
  might_sleep() since association may sleep there); radix preload removal
  (v1 15); blkg_create() allocation (v1 16); shared creation (v1 17); and
  the BFQ locked-cgroup-update fix (v1 13).

[1] v1: https://lore.kernel.org/r/20260704195124.1375075-1-yukuai@kernel.org

Yu Kuai (8):
  block: associate blkg in submit_bio instead of bio_set_dev
  blk-throttle: protect throttle state with td lock
  blk-cgroup: protect blkgs with blkcg_mutex
  blk-cgroup: remove blkg radix tree preloading
  blk-cgroup: allocate blkgs in blkg_create
  blk-cgroup: share blkg creation between lookup and config prep
  bfq: avoid blkg lookup from locked cgroup update
  block: fail nowait bio submit if blkg allocation can't sleep

 block/bfq-cgroup.c    |  26 ++-
 block/bio.c           |  18 +-
 block/blk-cgroup.c    | 434 +++++++++++++++++++-----------------------
 block/blk-cgroup.h    |  16 +-
 block/blk-core.c      |  36 ++++
 block/blk-iocost.c    |   5 +-
 block/blk-iolatency.c |   7 +-
 block/blk-throttle.c  |  93 ++++++---
 include/linux/bio.h   |  18 +-
 9 files changed, 350 insertions(+), 303 deletions(-)


base-commit: 093fbffe03f5c1bb9c10a9e5aa65b23250844403
-- 
2.51.0


             reply	other threads:[~2026-07-24 12:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 12:30 Yu Kuai [this message]
2026-07-24 12:30 ` [RFC PATCH v2 1/8] block: associate blkg in submit_bio instead of bio_set_dev Yu Kuai
2026-07-24 12:30 ` [RFC PATCH v2 2/8] blk-throttle: protect throttle state with td lock Yu Kuai
2026-07-24 12:30 ` [RFC PATCH v2 3/8] blk-cgroup: protect blkgs with blkcg_mutex Yu Kuai
2026-07-24 12:30 ` [RFC PATCH v2 4/8] blk-cgroup: remove blkg radix tree preloading Yu Kuai
2026-07-24 12:30 ` [RFC PATCH v2 5/8] blk-cgroup: allocate blkgs in blkg_create Yu Kuai
2026-07-24 12:30 ` [RFC PATCH v2 6/8] blk-cgroup: share blkg creation between lookup and config prep Yu Kuai
2026-07-24 12:30 ` [RFC PATCH v2 7/8] bfq: avoid blkg lookup from locked cgroup update Yu Kuai
2026-07-24 12:30 ` [RFC PATCH v2 8/8] block: fail nowait bio submit if blkg allocation can't sleep Yu Kuai
2026-07-26  7:08 ` [syzbot ci] Re: blk-cgroup: protect blkgs with blkcg_mutex syzbot ci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260724123037.3004560-1-yukuai@kernel.org \
    --to=yukuai@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=cengku@gmail.com \
    --cc=cgroups@vger.kernel.org \
    --cc=dongsheng.yang@linux.dev \
    --cc=hch@lst.de \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=nilay@linux.ibm.com \
    --cc=tj@kernel.org \
    --cc=yukuai@fygo.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox