[RFC PATCH v2 0/8] blk-cgroup: protect blkgs with blkcg_mutex

Yu Kuai <[email protected]>
Newsgroups org.kernel.vger.linux-block,org.kernel.vger.cgroups
Message-ID <[email protected]>
From: Yu Kuai <[email protected]>

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/[email protected]

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.