Skip to contentSkip to conversation

blk-cgroup: store blkcg in bio before blkcg_mutex conversion

RFC PATCH Superseded Yu Kuai 5 participants 12 messages Aug 18 – Aug 20

Subsystems (16)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Yu Kuai

author
#0 lore raw

v3 cover blk-cgroup: store blkcg in bio before blkcg_mutex conversion

From: Yu Kuai <[email protected]>

This RFC remains a preparatory series for the blkcg_mutex conversion proposed in the related blkcg_mutex RFC v2 series [1]. That conversion moves queue-local blkg topology synchronization from q->queue_lock to q->blkcg_mutex, which is awkward while bios directly store queue-local blkg references.

v1 made the stored bio association queue-independent by replacing bi_blkg with bi_blkcg, but a bio-owned blkg reference still had to be recovered by looking up the bio's blkcg and current request_queue. Tao Cui reported that cgroup removal deletes a dying blkg from the per-blkcg radix tree before a throttled bio drops its reference. A later lookup for that pinned blkg then fails, triggers the warning in bio_pinned_blkg(), and leaks the reference.

v2 makes request_queue the authoritative lookup owner before converting the bio association. A queue-owned rhashtable, keyed by the blkcg CSS ID, keeps dying blkgs discoverable until their references drain while q->blkg_list remains available for ordered walks. The bio conversion then stores and pins the blkcg CSS, lazily creates a blkg only for users which need one, and uses lookup-only access for completion and accounting paths which already own a blkg reference. Async bio punt state is finally moved from blkg to blkcg so punting alone does not instantiate a queue-local blkg.

A git branch is available at:
https://git.kernel.org/pub/scm/linux/kernel/git/yukuai/linux.git/log/?h=block-7.3-blkg_list-rhashtable-v3

Changes since v2:

- Drop the old patch 1 and send it separately as a bugfix for 7.3 and -stable, as suggested by Christoph Hellwig.
- Rebase onto the latest for-7.3/block branch.
- In the new patch 1, note that the remaining q->blkg_list walkers are cgroupfs/sysfs slow paths and can move to rhashtable iteration after the queue_lock-to-blkcg_mutex conversion.
- In the new patch 1, explain the list_empty case in blkg_release(), and add an RCU lockdep assertion plus documentation that blkg_lookup_any() does not acquire a reference.

Changes since v1:

- Add patch 1 to wait for every old blkg to leave q->blkg_list before a shared request_queue is rebound, instead of treating root_blkg == NULL as completion of asynchronous blkg teardown.
- Add patch 2 to replace the per-blkcg radix tree and lookup hint with a request_queue rhashtable keyed by blkcg->css.id, as suggested by Christoph Hellwig. Keep dying pinned blkgs in the hash until blkg_release() so bio-owned references remain discoverable.
- Fold the v1 helper-only patch into patch 3, as suggested by Jan Kara and Christoph Hellwig, and make bio_blkcg() naturally return NULL for an unassociated bio.
- Rework patch 3 so blkg_lookup_create() acquires the bio-owned reference, falls back to a live parent when creation or tryget fails, and updates bi_blkcg when the returned blkg belongs to an ancestor.
- Make bio_blkg_lookup() lookup-only: it returns NULL unless BIO_BLKG_REF is already set. Use bio_blkg() in the BFQ and IOCOST merge paths which may need to create a blkg, while keeping blk_cgroup_bio_start() and completion paths lookup-only.
- Move CSS online-reference handling into bio_associate_blkcg_from_css(), including fallback to the root blkcg, so bio_associate_blkcg() does not take a redundant reference.
- Keep the v1 async bio punt conversion as patch 4 and document that async_bio_lock protects async_bios.

Previous versions:
v2: https://lore.kernel.org/r/[email protected]
v1: https://lore.kernel.org/r/[email protected]

Related series:
[1] RFC v2 blk-cgroup: protect blkgs with blkcg_mutex

      https://lore.kernel.org/r/[email protected]

Yu Kuai (3):
blk-cgroup: use a request_queue rhashtable for blkg lookup
blk-cgroup: store blkcg in bio instead of blkg
blk-cgroup: move async bio punt state to blkcg

 Documentation/admin-guide/cgroup-v2.rst |   2 +-
 block/bfq-cgroup.c                      |  16 +-
 block/bfq-iosched.c                     |  19 +-
 block/bio.c                             |  22 +-
 block/blk-cgroup-fc-appid.c             |  10 +-
 block/blk-cgroup.c                      | 339 ++++++++++++++----------
 block/blk-cgroup.h                      |  89 +++++--
 block/blk-core.c                        |   9 +-
 block/blk-crypto-fallback.c             |   2 +-
 block/blk-iocost.c                      |  12 +-
 block/blk-iolatency.c                   |  11 +-
 block/blk-ioprio.c                      |   2 +-
 block/blk-throttle.c                    |   2 +-
 block/blk-throttle.h                    |   2 +-
 drivers/md/bcache/request.c             |   2 +-
 drivers/md/dm.c                         |   2 +-
 drivers/md/md.c                         |   2 +-
 drivers/nvdimm/nd_virtio.c              |   2 +-
 fs/gfs2/lops.c                          |   3 +-
 include/linux/bio.h                     |  26 +-
 include/linux/blk_types.h               |   9 +-
 include/linux/blkdev.h                  |   2 +
 include/linux/writeback.h               |   2 +-
 mm/page_io.c                            |  13 +-
 24 files changed, 364 insertions(+), 236 deletions(-)
Signature · 1 line
2.51.0
author
#1 lore raw

RFC PATCH v3 1/3 blk-cgroup: use a request_queue rhashtable for blkg lookup

From: Yu Kuai <[email protected]>

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.

---
 block/blk-cgroup.c     | 64 +++++++++++++++++++-----------------------
 block/blk-cgroup.h     | 49 +++++++++++++++++++++++---------
 block/blk-core.c       |  9 ++++--
 include/linux/blkdev.h |  2 ++
 4 files changed, 74 insertions(+), 50 deletions(-)
block/blk-cgroup.c +29 -35
index 2b5c29434e42..753a8022a283 100644
@@ -64,10 +64,17 @@ bool blkcg_debug_stats = false;
 
 static DEFINE_RAW_SPINLOCK(blkg_stat_lock);
 
 #define BLKG_DESTROY_BATCH_SIZE  64
 
+const struct rhashtable_params blkg_hash_params = {
+	.key_len		= sizeof_field(struct blkcg_gq, blkcg_id),
+	.key_offset		= offsetof(struct blkcg_gq, blkcg_id),
+	.head_offset		= offsetof(struct blkcg_gq, q_hash_node),
+	.automatic_shrinking	= true,
+};
+
 /*
  * Lockless lists for tracking IO stats update
  *
  * New IO stats are stored in the percpu iostat_cpu within blkcg_gq (blkg).
  * There are multiple blkg's (one for each block device) attached to each
@@ -192,10 +199,20 @@ static void blkg_release(struct percpu_ref *ref)
 {
 	struct blkcg_gq *blkg = container_of(ref, struct blkcg_gq, refcnt);
 	struct blkcg *blkcg = blkg->blkcg;
 	int cpu;
 
+	/*
+	 * A blkg that was never inserted into q->blkg_list has no hash
+	 * entry.  This happens when allocation or creation fails before
+	 * rhashtable_insert_fast() succeeds.
+	 */
+	if (!list_empty(&blkg->q_node))
+		WARN_ON_ONCE(rhashtable_remove_fast(&blkg->q->blkg_hash,
+						    &blkg->q_hash_node,
+						    blkg_hash_params));
+
 	/*
 	 * Flush all the non-empty percpu lockless lists before releasing
 	 * us, given these stat belongs to us.
 	 *
 	 * blkg_stat_lock is for serializing blkg stat update
@@ -325,10 +342,11 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct gendisk *disk,
 		goto out_put_queue;
 
 	blkg->q = disk->queue;
 	INIT_LIST_HEAD(&blkg->q_node);
 	blkg->blkcg = blkcg;
+	blkg->blkcg_id = blkcg->css.id;
 	blkg->iostat.blkg = blkg;
 #ifdef CONFIG_BLK_CGROUP_PUNT_BIO
 	spin_lock_init(&blkg->async_bio_lock);
 	bio_list_init(&blkg->async_bios);
 	INIT_WORK(&blkg->async_bio_work, blkg_async_bio_workfn);
@@ -421,11 +439,12 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg, struct gendisk *disk,
 			pol->pd_init_fn(blkg->pd[i]);
 	}
 
 	/* insert */
 	spin_lock(&blkcg->lock);
-	ret = radix_tree_insert(&blkcg->blkg_tree, disk->queue->id, blkg);
+	ret = rhashtable_insert_fast(&disk->queue->blkg_hash,
+				     &blkg->q_hash_node, blkg_hash_params);
 	if (likely(!ret)) {
 		hlist_add_head_rcu(&blkg->blkcg_node, &blkcg->blkg_list);
 		list_add(&blkg->q_node, &disk->queue->blkg_list);
 
 		for (i = 0; i < BLKCG_MAX_POLS; i++) {
@@ -474,13 +493,10 @@ static struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,
 	struct blkcg_gq *blkg;
 
 	rcu_read_lock();
 	blkg = blkg_lookup(blkcg, q);
 	if (blkg) {
-		if (blkcg != &blkcg_root &&
-		    blkg != rcu_dereference(blkcg->blkg_hint))
-			rcu_assign_pointer(blkcg->blkg_hint, blkg);
 		rcu_read_unlock();
 		return blkg;
 	}
 	rcu_read_unlock();
 
@@ -544,21 +560,12 @@ static void blkg_destroy(struct blkcg_gq *blkg)
 		}
 	}
 
 	blkg->online = false;
 
-	radix_tree_delete(&blkcg->blkg_tree, blkg->q->id);
 	hlist_del_init_rcu(&blkg->blkcg_node);
 
-	/*
-	 * Both setting lookup hint to and clearing it from @blkg are done
-	 * under queue_lock.  If it's not pointing to @blkg now, it never
-	 * will.  Hint assignment itself can race safely.
-	 */
-	if (rcu_access_pointer(blkcg->blkg_hint) == blkg)
-		rcu_assign_pointer(blkcg->blkg_hint, NULL);
-
 	/*
 	 * Put the reference taken at the time of creation so that when all
 	 * queues are gone, group can be destroyed.
 	 */
 	percpu_ref_kill(&blkg->refcnt);
@@ -880,47 +887,37 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
 		if (unlikely(!new_blkg)) {
 			ret = -ENOMEM;
 			goto fail_exit;
 		}
 
-		if (radix_tree_preload(GFP_KERNEL)) {
-			blkg_free(new_blkg);
-			ret = -ENOMEM;
-			goto fail_exit;
-		}
-
 		spin_lock_irq(&q->queue_lock);
 
 		if (!blkcg_policy_enabled(q, pol)) {
 			blkg_free(new_blkg);
 			ret = -EOPNOTSUPP;
-			goto fail_preloaded;
+			goto fail_unlock;
 		}
 
 		blkg = blkg_lookup(pos, q);
 		if (blkg) {
 			blkg_free(new_blkg);
 		} else {
 			blkg = blkg_create(pos, disk, new_blkg);
 			if (IS_ERR(blkg)) {
 				ret = PTR_ERR(blkg);
-				goto fail_preloaded;
+				goto fail_unlock;
 			}
 		}
 
-		radix_tree_preload_end();
-
 		if (pos == blkcg)
 			goto success;
 	}
 success:
 	mutex_unlock(&q->blkcg_mutex);
 	ctx->blkg = blkg;
 	return 0;
 
-fail_preloaded:
-	radix_tree_preload_end();
 fail_unlock:
 	spin_unlock_irq(&q->queue_lock);
 fail_exit:
 	mutex_unlock(&q->blkcg_mutex);
 	/*
@@ -1418,11 +1415,10 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
 		cpd->plid = i;
 	}
 
 	spin_lock_init(&blkcg->lock);
 	refcount_set(&blkcg->online_pin, 1);
-	INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_NOWAIT);
 	INIT_HLIST_HEAD(&blkcg->blkg_list);
 #ifdef CONFIG_CGROUP_WRITEBACK
 	INIT_LIST_HEAD(&blkcg->cgwb_list);
 #endif
 	list_add_tail(&blkcg->all_blkcgs_node, &all_blkcgs);
@@ -1455,21 +1451,26 @@ static int blkcg_css_online(struct cgroup_subsys_state *css)
 	if (parent)
 		blkcg_pin_online(&parent->css);
 	return 0;
 }
 
-void blkg_init_queue(struct request_queue *q)
+int blkg_init_queue(struct request_queue *q)
 {
 	INIT_LIST_HEAD(&q->blkg_list);
 	mutex_init(&q->blkcg_mutex);
+	return rhashtable_init(&q->blkg_hash, &blkg_hash_params);
+}
+
+void blkg_exit_queue(struct request_queue *q)
+{
+	rhashtable_destroy(&q->blkg_hash);
 }
 
 int blkcg_init_disk(struct gendisk *disk)
 {
 	struct request_queue *q = disk->queue;
 	struct blkcg_gq *new_blkg, *blkg;
-	bool preloaded;
 
 	/*
 	 * If the queue is shared across disk rebind (e.g., SCSI), the
 	 * previous disk's blkcg state is cleaned up asynchronously via
 	 * disk_release() -> blkcg_exit_disk(). Wait for that cleanup to
@@ -1483,30 +1484,23 @@ int blkcg_init_disk(struct gendisk *disk)
 
 	new_blkg = blkg_alloc(&blkcg_root, disk, GFP_KERNEL);
 	if (!new_blkg)
 		return -ENOMEM;
 
-	preloaded = !radix_tree_preload(GFP_KERNEL);
-
 	/* Make sure the root blkg exists. */
 	/* spin_lock_irq can serve as RCU read-side critical section. */
 	spin_lock_irq(&q->queue_lock);
 	blkg = blkg_create(&blkcg_root, disk, new_blkg);
 	if (IS_ERR(blkg))
 		goto err_unlock;
 	q->root_blkg = blkg;
 	spin_unlock_irq(&q->queue_lock);
 
-	if (preloaded)
-		radix_tree_preload_end();
-
 	return 0;
 
 err_unlock:
 	spin_unlock_irq(&q->queue_lock);
-	if (preloaded)
-		radix_tree_preload_end();
 	return PTR_ERR(blkg);
 }
 
 void blkcg_exit_disk(struct gendisk *disk)
 {
block/blk-cgroup.h +36 -13

127 lines not on this page · raw message

block/blk-core.c +7 -2
index 196bccf27f58..e396a316b8bf 100644
@@ -301,10 +301,11 @@ static void blk_free_queue(struct request_queue *q)
 {
 	blk_free_queue_stats(q->stats);
 	if (queue_is_mq(q))
 		blk_mq_release(q);
 
+	blkg_exit_queue(q);
 	ida_free(&blk_queue_ida, q->id);
 	lockdep_unregister_key(&q->io_lock_cls_key);
 	lockdep_unregister_key(&q->q_lock_cls_key);
 	call_rcu(&q->rcu_head, blk_free_queue_rcu);
 }
@@ -479,21 +480,23 @@ struct request_queue *blk_alloc_queue(struct queue_limits *lim, int node_id)
 	spin_lock_init(&q->queue_lock);
 
 	init_waitqueue_head(&q->mq_freeze_wq);
 	mutex_init(&q->mq_freeze_lock);
 
-	blkg_init_queue(q);
+	error = blkg_init_queue(q);
+	if (error)
+		goto fail_stats;
 
 	/*
 	 * Init percpu_ref in atomic mode so that it's faster to shutdown.
 	 * See blk_register_queue() for details.
 	 */
 	error = percpu_ref_init(&q->q_usage_counter,
 				blk_queue_usage_counter_release,
 				PERCPU_REF_INIT_ATOMIC, GFP_KERNEL);
 	if (error)
-		goto fail_stats;
+		goto fail_blkg;
 	lockdep_register_key(&q->io_lock_cls_key);
 	lockdep_register_key(&q->q_lock_cls_key);
 	lockdep_init_map(&q->io_lockdep_map, "&q->q_usage_counter(io)",
 			 &q->io_lock_cls_key, 0);
 	lockdep_init_map(&q->q_lockdep_map, "&q->q_usage_counter(queue)",
@@ -508,10 +511,12 @@ struct request_queue *blk_alloc_queue(struct queue_limits *lim, int node_id)
 	q->nr_requests = BLKDEV_DEFAULT_RQ;
 	q->async_depth = BLKDEV_DEFAULT_RQ;
 
 	return q;
 
+fail_blkg:
+	blkg_exit_queue(q);
 fail_stats:
 	blk_free_queue_stats(q->stats);
 fail_id:
 	ida_free(&blk_queue_ida, q->id);
 fail_q:
include/linux/blkdev.h +2 -0
index 20cb8ed7d987..f3b0e39d3f6b 100644
@@ -25,10 +25,11 @@
 #include <linux/sbitmap.h>
 #include <linux/uuid.h>
 #include <linux/xarray.h>
 #include <linux/file.h>
 #include <linux/lockdep.h>
+#include <linux/rhashtable-types.h>
 
 struct module;
 struct request_queue;
 struct elevator_queue;
 struct blk_trace;
@@ -579,10 +580,11 @@ struct request_queue {
 
 	struct list_head	icq_list;
 #ifdef CONFIG_BLK_CGROUP
 	DECLARE_BITMAP		(blkcg_pols, BLKCG_MAX_POLS);
 	struct blkcg_gq		*root_blkg;
+	struct rhashtable	blkg_hash;
 	struct list_head	blkg_list;
 	struct mutex		blkcg_mutex;
 #endif
 
 	int			node;
Signature · 1 line
2.51.0
author
#4 lore raw

RFC PATCH v3 2/3 blk-cgroup: store blkcg in bio instead of blkg

In reply to Yu Kuai

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.

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.

---
 Documentation/admin-guide/cgroup-v2.rst |   2 +-
 block/bfq-cgroup.c                      |  16 +-
 block/bfq-iosched.c                     |  19 +-
 block/bio.c                             |  22 +--
 block/blk-cgroup-fc-appid.c             |  10 +-
 block/blk-cgroup.c                      | 237 +++++++++++++++---------
 block/blk-cgroup.h                      |  26 ++-
 block/blk-crypto-fallback.c             |   2 +-
 block/blk-iocost.c                      |  12 +-
 block/blk-iolatency.c                   |  11 +-
 block/blk-ioprio.c                      |   2 +-
 block/blk-throttle.c                    |   2 +-
 block/blk-throttle.h                    |   2 +-
 drivers/md/bcache/request.c             |   2 +-
 drivers/md/dm.c                         |   2 +-
 drivers/md/md.c                         |   2 +-
 drivers/nvdimm/nd_virtio.c              |   2 +-
 fs/gfs2/lops.c                          |   3 +-
 include/linux/bio.h                     |  26 +--
 include/linux/blk_types.h               |   9 +-
 include/linux/writeback.h               |   2 +-
 mm/page_io.c                            |  13 +-
 22 files changed, 266 insertions(+), 158 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +1 -1
index 14b8c571c0d1..bbd79931d5ab 100644
@@ -3233,11 +3233,11 @@ incompatible.
 wbc_init_bio() binds the specified bio to its cgroup.  Depending on
 the configuration, the bio may be executed at a lower priority and if
 the writeback session is holding shared resources, e.g. a journal
 entry, may lead to priority inversion.  There is no one easy solution
 for the problem.  Filesystems can try to work around specific problem
-cases by skipping wbc_init_bio() and using bio_associate_blkg()
+cases by skipping wbc_init_bio() and using bio_associate_blkcg()
 directly.
 
 
 Deprecated v1 Core Features
 ===========================
block/bfq-cgroup.c +10 -6
index ef9d63e8542e..4a3975f9ff74 100644
@@ -361,15 +361,17 @@ void bfqg_and_blkg_put(struct bfq_group *bfqg)
 	bfqg_put(bfqg);
 }
 
 void bfqg_stats_update_legacy_io(struct request_queue *q, struct request *rq)
 {
-	struct bfq_group *bfqg = blkg_to_bfqg(rq->bio->bi_blkg);
+	struct blkcg_gq *blkg = bio_blkg_lookup(rq->bio);
+	struct bfq_group *bfqg;
 
-	if (!bfqg)
+	if (!blkg)
 		return;
 
+	bfqg = blkg_to_bfqg(blkg);
 	blkg_rwstat_add(&bfqg->stats.bytes, rq->cmd_flags, blk_rq_bytes(rq));
 	blkg_rwstat_add(&bfqg->stats.ios, rq->cmd_flags, 1);
 }
 
 /* @stats = 0 */
@@ -604,27 +606,29 @@ static void bfq_link_bfqg(struct bfq_data *bfqd, struct bfq_group *bfqg)
 	}
 }
 
 struct bfq_group *bfq_bio_bfqg(struct bfq_data *bfqd, struct bio *bio)
 {
-	struct blkcg_gq *blkg = bio->bi_blkg;
+	struct blkcg_gq *blkg = bio_blkg_lookup(bio);
 	struct bfq_group *bfqg;
 
 	while (blkg) {
 		if (!data_race(blkg->online)) {
 			blkg = blkg->parent;
 			continue;
 		}
+
 		bfqg = blkg_to_bfqg(blkg);
 		if (bfqg->pd.online) {
-			bio_associate_blkg_from_css(bio, &blkg->blkcg->css);
+			bio_associate_blkcg_from_css(bio, &blkg->blkcg->css);
 			return bfqg;
 		}
 		blkg = blkg->parent;
 	}
-	bio_associate_blkg_from_css(bio,
-				&bfqg_to_blkg(bfqd->root_group)->blkcg->css);
+
+	blkg = bfqg_to_blkg(bfqd->root_group);
+	bio_associate_blkcg_from_css(bio, &blkg->blkcg->css);
 	return bfqd->root_group;
 }
 
 /**
  * bfq_bfqq_move - migrate @bfqq to @bfqg.
block/bfq-iosched.c +14 -5
index 0f75301b3115..d4f657bc7a4e 100644
@@ -126,10 +126,11 @@
 
 #include <trace/events/block.h>
 
 #include "elevator.h"
 #include "blk.h"
+#include "blk-cgroup.h"
 #include "blk-mq.h"
 #include "blk-mq-sched.h"
 #include "bfq-iosched.h"
 #include "blk-wbt.h"
 
@@ -2450,19 +2451,20 @@ static bool bfq_bio_merge(struct request_queue *q, struct bio *bio,
 	struct bfq_data *bfqd = q->elevator->elevator_data;
 	struct bfq_io_cq *bic = bfq_bic_lookup(q);
 	struct request *free = NULL;
 	bool ret;
 
+#ifdef CONFIG_BFQ_GROUP_IOSCHED
+	/* blkg creation takes q->queue_lock, so do it before bfqd->lock. */
+	if (bic)
+		bio_blkg(bio);
+#endif
+
 	spin_lock_irq(&bfqd->lock);
 
 	if (bic) {
-		/*
-		 * Make sure cgroup info is uptodate for current process before
-		 * considering the merge.
-		 */
 		bfq_bic_update_cgroup(bic, bio);
-
 		bfqd->bio_bfqq = bic_to_bfqq(bic, op_is_sync(bio->bi_opf),
 					     bfq_actuator_index(bfqd, bio));
 	} else {
 		bfqd->bio_bfqq = NULL;
 	}
@@ -6243,10 +6245,17 @@ static void bfq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 	bool idle_timer_disabled = false;
 	blk_opf_t cmd_flags;
 	LIST_HEAD(free);
 
 #ifdef CONFIG_BFQ_GROUP_IOSCHED
+	/*
+	 * Pin the blkg used to look up bfqg.  If this is the first IO for
+	 * the blkcg on this queue, create the bfqg before holding bfqd->lock.
+	 */
+	if (rq->bio && !bio_flagged(rq->bio, BIO_BLKG_REF))
+		bio_blkg(rq->bio);
+
 	if (!cgroup_subsys_on_dfl(io_cgrp_subsys) && rq->bio)
 		bfqg_stats_update_legacy_io(q, rq);
 #endif
 	spin_lock_irq(&bfqd->lock);
 	bfqq = bfq_init_rq(rq);
block/bio.c +6 -16
index 898b2f5ef8c8..6c84042adf5d 100644
@@ -177,16 +177,11 @@ static inline gfp_t try_alloc_gfp(gfp_t gfp)
 		__GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN;
 }
 
 void bio_uninit(struct bio *bio)
 {
-#ifdef CONFIG_BLK_CGROUP
-	if (bio->bi_blkg) {
-		blkg_put(bio->bi_blkg);
-		bio->bi_blkg = NULL;
-	}
-#endif
+	bio_clear_blkcg(bio);
 	if (bio_integrity(bio))
 		bio_integrity_free(bio);
 
 	bio_crypt_free_ctx(bio);
 }
@@ -231,14 +226,14 @@ void bio_init(struct bio *bio, struct block_device *bdev, struct bio_vec *table,
 	bio->bi_iter.bi_idx = 0;
 	bio->bi_iter.bi_offset = 0;
 	bio->bi_end_io = NULL;
 	bio->bi_private = NULL;
 #ifdef CONFIG_BLK_CGROUP
-	bio->bi_blkg = NULL;
+	bio->bi_blkcg = NULL;
 	bio->issue_time_ns = 0;
 	if (bdev)
-		bio_associate_blkg(bio);
+		bio_associate_blkcg(bio);
 #ifdef CONFIG_BLK_CGROUP_IOCOST
 	bio->bi_iocost_cost = 0;
 #endif
 #endif
 #ifdef CONFIG_BLK_INLINE_ENCRYPTION
@@ -279,11 +274,11 @@ void bio_reset(struct bio *bio, struct block_device *bdev, blk_opf_t opf)
 	memset(bio, 0, BIO_RESET_BYTES);
 	atomic_set(&bio->__bi_remaining, 1);
 	bio->bi_io_vec = bv;
 	bio->bi_bdev = bdev;
 	if (bio->bi_bdev)
-		bio_associate_blkg(bio);
+		bio_associate_blkcg(bio);
 	bio->bi_opf = opf;
 }
 EXPORT_SYMBOL(bio_reset);
 
 /**
@@ -864,11 +859,11 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp)
 
 	if (bio->bi_bdev) {
 		if (bio->bi_bdev == bio_src->bi_bdev &&
 		    bio_flagged(bio_src, BIO_REMAPPED))
 			bio_set_flag(bio, BIO_REMAPPED);
-		bio_clone_blkg_association(bio, bio_src);
+		bio_clone_blkcg_association(bio, bio_src);
 	}
 
 	if (bio_crypt_clone(bio, bio_src, gfp) < 0)
 		return -ENOMEM;
 	if (bio_integrity(bio_src) &&
@@ -1908,21 +1903,16 @@ void bio_endio(struct bio *bio)
 	if (bio->bi_end_io == bio_chain_endio) {
 		bio = __bio_chain_endio(bio);
 		goto again;
 	}
 
-#ifdef CONFIG_BLK_CGROUP
 	/*
 	 * Release cgroup info.  We shouldn't have to do this here, but quite
 	 * a few callers of bio_init fail to call bio_uninit, so we cover up
 	 * for that here at least for now.
 	 */
-	if (bio->bi_blkg) {
-		blkg_put(bio->bi_blkg);
-		bio->bi_blkg = NULL;
-	}
-#endif
+	bio_clear_blkcg(bio);
 
 	if (bio_flagged(bio, BIO_COMPLETE_IN_TASK) && bio_in_atomic())
 		__bio_complete_in_task(bio);
 	else if (bio->bi_end_io)
 		bio->bi_end_io(bio);
block/blk-cgroup-fc-appid.c +8 -2
index 3ec21333f393..7589c6209989 100644
@@ -48,10 +48,16 @@ EXPORT_SYMBOL_GPL(blkcg_set_fc_appid);
  *
  * On success return the fc_app_id, on failure return NULL
  */
 char *blkcg_get_fc_appid(struct bio *bio)
 {
-	if (!bio->bi_blkg || bio->bi_blkg->blkcg->fc_app_id[0] == '\0')
+	struct blkcg *blkcg = bio_blkcg(bio);
+
+	if (!blkcg)
+		return NULL;
+
+	if (blkcg->fc_app_id[0] == '\0')
 		return NULL;
-	return bio->bi_blkg->blkcg->fc_app_id;
+
+	return blkcg->fc_app_id;
 }
 EXPORT_SYMBOL_GPL(blkcg_get_fc_appid);
block/blk-cgroup.c +150 -87

382 lines not on this page · raw message

block/blk-cgroup.h +25 -1
index 7278a8817a49..936428b6127e 100644
@@ -124,10 +124,15 @@ struct blkcg {
 static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
 {
 	return css ? container_of(css, struct blkcg, css) : NULL;
 }
 
+static inline struct blkcg *bio_blkcg(struct bio *bio)
+{
+	return bio->bi_blkcg;
+}
+
 /*
  * A blkcg_gq (blkg) is association between a block cgroup (blkcg) and a
  * request_queue (q).  This is used by blkcg policies which need to track
  * information per blkcg - q pair.
  *
@@ -295,10 +300,13 @@ static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg,
 	if (blkg && !READ_ONCE(blkg->online))
 		blkg = NULL;
 	return blkg;
 }
 
+struct blkcg_gq *bio_blkg_lookup(struct bio *bio);
+struct blkcg_gq *bio_blkg(struct bio *bio);
+
 /**
  * blkg_to_pd - get policy private data
  * @blkg: blkg of interest
  * @pol: policy of interest
  *
@@ -362,10 +370,22 @@ static inline bool blkg_tryget(struct blkcg_gq *blkg)
 static inline void blkg_put(struct blkcg_gq *blkg)
 {
 	percpu_ref_put(&blkg->refcnt);
 }
 
+static inline void bio_clear_blkcg(struct bio *bio)
+{
+	struct blkcg *blkcg = bio_blkcg(bio);
+
+	bio_put_blkg_ref(bio);
+
+	if (blkcg) {
+		css_put(&blkcg->css);
+		bio->bi_blkcg = NULL;
+	}
+}
+
 /**
  * blkg_for_each_descendant_pre - pre-order walk of a blkg's descendants
  * @d_blkg: loop cursor pointing to the current descendant
  * @pos_css: used for iteration
  * @p_blkg: target blkg to walk descendants of
@@ -491,11 +511,11 @@ static inline void blkcg_clear_delay(struct blkcg_gq *blkg)
  * match. The latter is necessary as we don't want to throttle e.g. a metadata
  * update because it happens to be next to a regular IO.
  */
 static inline bool blk_cgroup_mergeable(struct request *rq, struct bio *bio)
 {
-	return rq->bio->bi_blkg == bio->bi_blkg &&
+	return bio_blkcg(rq->bio) == bio_blkcg(bio) &&
 		bio_issue_as_root_blkg(rq->bio) == bio_issue_as_root_blkg(bio);
 }
 
 static inline bool blkcg_policy_enabled(struct request_queue *q,
 				const struct blkcg_policy *pol)
@@ -517,10 +537,13 @@ struct blkcg_policy {
 };
 
 struct blkcg {
 };
 
+static inline struct blkcg *bio_blkcg(struct bio *bio) { return NULL; }
+static inline struct blkcg_gq *bio_blkg_lookup(struct bio *bio) { return NULL; }
+static inline struct blkcg_gq *bio_blkg(struct bio *bio) { return NULL; }
 static inline struct blkcg_gq *blkg_lookup_any(struct blkcg *blkcg, void *key) { return NULL; }
 static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, void *key) { return NULL; }
 static inline int blkg_init_queue(struct request_queue *q) { return 0; }
 static inline void blkg_exit_queue(struct request_queue *q) { }
 static inline int blkcg_init_disk(struct gendisk *disk) { return 0; }
@@ -535,10 +558,11 @@ static inline void blkcg_deactivate_policy(struct gendisk *disk,
 static inline struct blkg_policy_data *blkg_to_pd(struct blkcg_gq *blkg,
 						  const struct blkcg_policy *pol) { return NULL; }
 static inline struct blkcg_gq *pd_to_blkg(struct blkg_policy_data *pd) { return NULL; }
 static inline void blkg_get(struct blkcg_gq *blkg) { }
 static inline void blkg_put(struct blkcg_gq *blkg) { }
+static inline void bio_clear_blkcg(struct bio *bio) { }
 static inline void blk_cgroup_bio_start(struct bio *bio) { }
 static inline bool blk_cgroup_mergeable(struct request *rq, struct bio *bio) { return true; }
 
 #define blk_queue_for_each_rl(rl, q)	\
 	for ((rl) = &(q)->root_rl; (rl); (rl) = NULL)
block/blk-crypto-fallback.c +1 -1
index 2a5c52ab74b4..5ef4baab444b 100644
@@ -185,11 +185,11 @@ static struct bio *blk_crypto_alloc_enc_bio(struct bio *bio_src,
 	bio->bi_end_io		= blk_crypto_fallback_encrypt_endio;
 	bio->bi_ioprio		= bio_src->bi_ioprio;
 	bio->bi_write_hint	= bio_src->bi_write_hint;
 	bio->bi_write_stream	= bio_src->bi_write_stream;
 	bio->bi_iter.bi_sector	= bio_src->bi_iter.bi_sector;
-	bio_clone_blkg_association(bio, bio_src);
+	bio_clone_blkcg_association(bio, bio_src);
 
 	/*
 	 * Move page array up in the allocated memory for the bio vecs as far as
 	 * possible so that we can start filling biovecs from the beginning
 	 * without overwriting the temporary page array.
block/blk-iocost.c +8 -4
index 2745bffcd5ee..57f2b4d4af20 100644
@@ -2684,11 +2684,11 @@ iocg_handle_over_budget(struct rq_qos *rqos, struct ioc_gq *iocg,
 	return action_wait;
 }
 
 static void ioc_rqos_throttle(struct rq_qos *rqos, struct bio *bio)
 {
-	struct blkcg_gq *blkg = bio->bi_blkg;
+	struct blkcg_gq *blkg = bio_blkg(bio);
 	struct ioc *ioc = rqos_to_ioc(rqos);
 	struct ioc_gq *iocg = blkg_to_iocg(blkg);
 	struct ioc_now now;
 	struct iocg_wait wait;
 	u64 abs_cost, cost, vtime;
@@ -2773,11 +2773,11 @@ static void ioc_rqos_throttle(struct rq_qos *rqos, struct bio *bio)
 }
 
 static void ioc_rqos_merge(struct rq_qos *rqos, struct request *rq,
 			   struct bio *bio)
 {
-	struct ioc_gq *iocg = blkg_to_iocg(bio->bi_blkg);
+	struct ioc_gq *iocg = blkg_to_iocg(bio_blkg(bio));
 	struct ioc *ioc = rqos_to_ioc(rqos);
 	sector_t bio_end = bio_end_sector(bio);
 	struct ioc_now now;
 	u64 vtime, abs_cost, cost;
 	unsigned long flags;
@@ -2831,13 +2831,17 @@ static void ioc_rqos_merge(struct rq_qos *rqos, struct request *rq,
 	spin_unlock_irqrestore(&ioc->lock, flags);
 }
 
 static void ioc_rqos_done_bio(struct rq_qos *rqos, struct bio *bio)
 {
-	struct ioc_gq *iocg = blkg_to_iocg(bio->bi_blkg);
+	struct ioc_gq *iocg;
+
+	if (!bio->bi_iocost_cost)
+		return;
 
-	if (iocg && bio->bi_iocost_cost)
+	iocg = blkg_to_iocg(bio_blkg_lookup(bio));
+	if (iocg)
 		atomic64_add(bio->bi_iocost_cost, &iocg->done_vtime);
 }
 
 static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq)
 {
block/blk-iolatency.c +7 -4
index 2caa79a008ad..7220edafd72b 100644
@@ -461,11 +461,11 @@ static void check_scale_change(struct iolatency_grp *iolat)
 }
 
 static void blkcg_iolatency_throttle(struct rq_qos *rqos, struct bio *bio)
 {
 	struct blk_iolatency *blkiolat = BLKIOLATENCY(rqos);
-	struct blkcg_gq *blkg = bio->bi_blkg;
+	struct blkcg_gq *blkg = bio_blkg(bio);
 	bool issue_as_root = bio_issue_as_root_blkg(bio);
 
 	if (!blkiolat->enabled)
 		return;
 
@@ -588,15 +588,18 @@ static void blkcg_iolatency_done_bio(struct rq_qos *rqos, struct bio *bio)
 	u64 window_start;
 	u64 now;
 	bool issue_as_root = bio_issue_as_root_blkg(bio);
 	int inflight = 0;
 
-	blkg = bio->bi_blkg;
-	if (!blkg || !bio_flagged(bio, BIO_QOS_THROTTLED))
+	if (!bio_flagged(bio, BIO_QOS_THROTTLED))
 		return;
 
-	iolat = blkg_to_lat(bio->bi_blkg);
+	blkg = bio_blkg_lookup(bio);
+	if (!blkg)
+		return;
+
+	iolat = blkg_to_lat(blkg);
 	if (!iolat)
 		return;
 
 	if (!iolat->blkiolat->enabled)
 		return;
block/blk-ioprio.c +1 -1
index 8fa8bca35062..5e3f8e49550d 100644
@@ -130,11 +130,11 @@ static struct blkcg_policy ioprio_policy = {
 	.cpd_free_fn	= ioprio_free_cpd,
 };
 
 void blkcg_set_ioprio(struct bio *bio)
 {
-	struct ioprio_blkcg *blkcg = blkcg_to_ioprio_blkcg(bio->bi_blkg->blkcg);
+	struct ioprio_blkcg *blkcg = blkcg_to_ioprio_blkcg(bio_blkcg(bio));
 	u16 prio;
 
 	if (!blkcg || blkcg->prio_policy == POLICY_NO_CHANGE)
 		return;
 
block/blk-throttle.c +1 -1
index ffc3b70065d4..3828c3857900 100644
@@ -1790,11 +1790,11 @@ static bool tg_within_limit(struct throtl_grp *tg, struct bio *bio, bool rw)
 }
 
 bool __blk_throtl_bio(struct bio *bio)
 {
 	struct request_queue *q = bdev_get_queue(bio->bi_bdev);
-	struct blkcg_gq *blkg = bio->bi_blkg;
+	struct blkcg_gq *blkg = bio_blkg(bio);
 	struct throtl_qnode *qn = NULL;
 	struct throtl_grp *tg = blkg_to_tg(blkg);
 	struct throtl_service_queue *sq;
 	bool rw = bio_data_dir(bio);
 	bool throttled = false;
block/blk-throttle.h +1 -1
index 1b5775771e07..45f30179fd9c 100644
@@ -169,11 +169,11 @@ static inline bool blk_should_throtl(struct bio *bio)
 	int rw = bio_data_dir(bio);
 
 	if (!blk_throtl_activated(bio->bi_bdev->bd_queue))
 		return false;
 
-	tg = blkg_to_tg(bio->bi_blkg);
+	tg = blkg_to_tg(bio_blkg(bio));
 	if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) {
 		if (!bio_flagged(bio, BIO_CGROUP_ACCT)) {
 			bio_set_flag(bio, BIO_CGROUP_ACCT);
 			blkg_rwstat_add(&tg->stat_bytes, bio->bi_opf,
 					bio->bi_iter.bi_size);
drivers/md/bcache/request.c +1 -1
index 3fa3b13a410f..c0f945b8d941 100644
@@ -846,11 +846,11 @@ static CLOSURE_CALLBACK(cached_dev_read_done)
 	if (s->iop.bio) {
 		bio_reset(s->iop.bio, s->cache_miss->bi_bdev, REQ_OP_READ);
 		s->iop.bio->bi_iter.bi_sector =
 			s->cache_miss->bi_iter.bi_sector;
 		s->iop.bio->bi_iter.bi_size = s->insert_bio_sectors << 9;
-		bio_clone_blkg_association(s->iop.bio, s->cache_miss);
+		bio_clone_blkcg_association(s->iop.bio, s->cache_miss);
 		bch_bio_map(s->iop.bio, NULL);
 
 		bio_copy_data(s->cache_miss, s->iop.bio);
 
 		bio_put(s->cache_miss);
drivers/md/dm.c +1 -1
index d413bfaf3527..cd68eec77f5a 100644
@@ -1371,11 +1371,11 @@ void dm_submit_bio_remap(struct bio *clone, struct bio *tgt_clone)
 
 	/* establish bio that will get submitted */
 	if (!tgt_clone)
 		tgt_clone = clone;
 
-	bio_clone_blkg_association(tgt_clone, io->orig_bio);
+	bio_clone_blkcg_association(tgt_clone, io->orig_bio);
 
 	/*
 	 * Account io->origin_bio to DM dev on behalf of target
 	 * that took ownership of IO with DM_MAPIO_SUBMITTED.
 	 */
drivers/md/md.c +1 -1
index 680b34a63cb3..fd78d6cc8da1 100644
@@ -9384,11 +9384,11 @@ void md_submit_discard_bio(struct mddev *mddev, struct md_rdev *rdev,
 	__blkdev_issue_discard(rdev->bdev, start, size, GFP_NOIO, &discard_bio);
 	if (!discard_bio)
 		return;
 
 	bio_chain(discard_bio, bio);
-	bio_clone_blkg_association(discard_bio, bio);
+	bio_clone_blkcg_association(discard_bio, bio);
 	mddev_trace_remap(mddev, discard_bio, bio->bi_iter.bi_sector);
 	submit_bio_noacct(discard_bio);
 }
 EXPORT_SYMBOL_GPL(md_submit_discard_bio);
 
drivers/nvdimm/nd_virtio.c +1 -1
index 4176046627be..54e4adb0ccb7 100644
@@ -119,11 +119,11 @@ int async_pmem_flush(struct nd_region *nd_region, struct bio *bio)
 					      REQ_OP_WRITE | REQ_PREFLUSH,
 					      GFP_ATOMIC);
 
 		if (!child)
 			return -ENOMEM;
-		bio_clone_blkg_association(child, bio);
+		bio_clone_blkcg_association(child, bio);
 		child->bi_iter.bi_sector = -1;
 		bio_chain(child, bio);
 		submit_bio(child);
 		return 0;
 	}
fs/gfs2/lops.c +1 -2
index 6dabe73ad790..6512dbd9516f 100644
@@ -482,11 +482,11 @@ static struct bio *gfs2_chain_bio(struct bio *prev, unsigned int nr_iovecs,
 				  sector_t sector, blk_opf_t opf)
 {
 	struct bio *new;
 
 	new = bio_alloc(prev->bi_bdev, nr_iovecs, opf, GFP_NOIO);
-	bio_clone_blkg_association(new, prev);
+	bio_clone_blkcg_association(new, prev);
 	new->bi_iter.bi_sector = sector;
 	bio_chain(new, prev);
 	submit_bio(prev);
 	return new;
 }
@@ -1112,6 +1112,5 @@ const struct gfs2_log_operations *gfs2_log_ops[] = {
 	&gfs2_databuf_lops,
 	&gfs2_buf_lops,
 	&gfs2_revoke_lops,
 	NULL,
 };
-
include/linux/bio.h +15 -11
index bb3235497e67..11637f85c38d 100644
@@ -540,35 +540,39 @@ static inline void bio_release_pages(struct bio *bio, bool mark_dirty)
 
 #define bio_dev(bio) \
 	disk_devt((bio)->bi_bdev->bd_disk)
 
 #ifdef CONFIG_BLK_CGROUP
-void bio_associate_blkg(struct bio *bio);
-void bio_associate_blkg_from_css(struct bio *bio,
-				 struct cgroup_subsys_state *css);
-void bio_clone_blkg_association(struct bio *dst, struct bio *src);
+void bio_associate_blkcg(struct bio *bio);
+void bio_associate_blkcg_from_css(struct bio *bio,
+				  struct cgroup_subsys_state *css);
+void bio_clone_blkcg_association(struct bio *dst, struct bio *src);
+void bio_put_blkg_ref(struct bio *bio);
 void blkcg_punt_bio_submit(struct bio *bio);
 #else	/* CONFIG_BLK_CGROUP */
-static inline void bio_associate_blkg(struct bio *bio) { }
-static inline void bio_associate_blkg_from_css(struct bio *bio,
-					       struct cgroup_subsys_state *css)
+static inline void bio_associate_blkcg(struct bio *bio) { }
+static inline void bio_associate_blkcg_from_css(struct bio *bio,
+						struct cgroup_subsys_state *css)
 { }
-static inline void bio_clone_blkg_association(struct bio *dst,
-					      struct bio *src) { }
+static inline void bio_clone_blkcg_association(struct bio *dst,
+					       struct bio *src) { }
+static inline void bio_put_blkg_ref(struct bio *bio) { }
 static inline void blkcg_punt_bio_submit(struct bio *bio)
 {
 	submit_bio(bio);
 }
 #endif	/* CONFIG_BLK_CGROUP */
 
 static inline void bio_set_dev(struct bio *bio, struct block_device *bdev)
 {
 	bio_clear_flag(bio, BIO_REMAPPED);
-	if (bio->bi_bdev != bdev)
+	if (bio->bi_bdev != bdev) {
+		bio_put_blkg_ref(bio);
 		bio_clear_flag(bio, BIO_BPS_THROTTLED);
+	}
 	bio->bi_bdev = bdev;
-	bio_associate_blkg(bio);
+	bio_associate_blkcg(bio);
 }
 
 /*
  * BIO list management for use by remapping drivers (e.g. DM or MD) and loop.
  *
include/linux/blk_types.h +4 -5
index d49d97a050d0..53ba307b91cb 100644
@@ -244,16 +244,14 @@ struct bio {
 	};
 	bio_end_io_t		*bi_end_io;
 	void			*bi_private;
 #ifdef CONFIG_BLK_CGROUP
 	/*
-	 * Represents the association of the css and request_queue for the bio.
-	 * If a bio goes direct to device, it will not have a blkg as it will
-	 * not have a request_queue associated with it.  The reference is put
-	 * on release of the bio.
+	 * Represents the blkcg css association for the bio.  The reference is
+	 * put on release of the bio.
 	 */
-	struct blkcg_gq		*bi_blkg;
+	struct blkcg		*bi_blkcg;
 	/* Time that this bio was issued. */
 	u64			issue_time_ns;
 #ifdef CONFIG_BLK_CGROUP_IOCOST
 	u64			bi_iocost_cost;
 #endif
@@ -307,10 +305,11 @@ enum {
 	BIO_BPS_THROTTLED,	/* This bio has already been subjected to
 				 * throttling rules. Don't do it again. */
 	BIO_TRACE_COMPLETION,	/* bio_endio() should trace the final completion
 				 * of this bio. */
 	BIO_CGROUP_ACCT,	/* has been accounted to a cgroup */
+	BIO_BLKG_REF,		/* bio pins the associated blkg */
 	BIO_QOS_THROTTLED,	/* bio went through rq_qos throttle path */
 	/*
 	 * This bio has completed bps throttling at the single tg granularity,
 	 * which is different from BIO_BPS_THROTTLED. When the bio is enqueued
 	 * into the sq->queued of the upper tg, or is about to be dispatched,
include/linux/writeback.h +1 -1
index 62552a2ce5b9..4f869fe9cc90 100644
@@ -260,11 +260,11 @@ static inline void wbc_init_bio(struct writeback_control *wbc, struct bio *bio)
 	 * out.  This is intentional as we don't want the function to block
 	 * behind a slow cgroup.  Ultimately, we want pageout() to kick off
 	 * regular writeback instead of writing things out itself.
 	 */
 	if (wbc->wb)
-		bio_associate_blkg_from_css(bio, wbc->wb->blkcg_css);
+		bio_associate_blkcg_from_css(bio, wbc->wb->blkcg_css);
 }
 
 void inode_switch_wbs_work_fn(struct work_struct *work);
 
 #else	/* CONFIG_CGROUP_WRITEBACK */
mm/page_io.c +8 -5
index b23f494fcc83..a4a1b8a8a0e3 100644
@@ -314,11 +314,11 @@ static inline void count_swpout_vm_event(struct folio *folio)
 	count_memcg_folio_events(folio, PSWPOUT, folio_nr_pages(folio));
 	count_vm_events(PSWPOUT, folio_nr_pages(folio));
 }
 
 #if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP)
-static void bio_associate_blkg_from_page(struct bio *bio, struct folio *folio)
+static void bio_associate_blkcg_from_page(struct bio *bio, struct folio *folio)
 {
 	struct cgroup_subsys_state *css;
 	struct mem_cgroup *memcg;
 
 	if (!folio_memcg_charged(folio))
@@ -329,16 +329,19 @@ static void bio_associate_blkg_from_page(struct bio *bio, struct folio *folio)
 	css = cgroup_e_css(memcg->css.cgroup, &io_cgrp_subsys);
 	if (!css || !css_tryget(css))
 		css = NULL;
 	rcu_read_unlock();
 
-	bio_associate_blkg_from_css(bio, css);
+	bio_associate_blkcg_from_css(bio, css);
 	if (css)
 		css_put(css);
 }
 #else
-#define bio_associate_blkg_from_page(bio, folio)		do { } while (0)
+static inline void bio_associate_blkcg_from_page(struct bio *bio,
+						 struct folio *folio)
+{
+}
 #endif /* CONFIG_MEMCG && CONFIG_BLK_CGROUP */
 
 struct swap_iocb {
 	struct kiocb		iocb;
 	struct bio_vec		bvecs[SWAP_CLUSTER_MAX];
@@ -434,11 +437,11 @@ static void swap_writepage_bdev_sync(struct folio *folio,
 
 	bio_init(&bio, sis->bdev, &bv, 1, REQ_OP_WRITE | REQ_SWAP);
 	bio.bi_iter.bi_sector = swap_folio_sector(folio);
 	bio_add_folio_nofail(&bio, folio, folio_size(folio), 0);
 
-	bio_associate_blkg_from_page(&bio, folio);
+	bio_associate_blkcg_from_page(&bio, folio);
 	count_swpout_vm_event(folio);
 
 	folio_start_writeback(folio);
 	folio_unlock(folio);
 
@@ -454,11 +457,11 @@ static void swap_writepage_bdev_async(struct folio *folio,
 	bio = bio_alloc(sis->bdev, 1, REQ_OP_WRITE | REQ_SWAP, GFP_NOIO);
 	bio->bi_iter.bi_sector = swap_folio_sector(folio);
 	bio->bi_end_io = end_swap_bio_write;
 	bio_add_folio_nofail(bio, folio, folio_size(folio), 0);
 
-	bio_associate_blkg_from_page(bio, folio);
+	bio_associate_blkcg_from_page(bio, folio);
 	count_swpout_vm_event(folio);
 	folio_start_writeback(folio);
 	folio_unlock(folio);
 	submit_bio(bio);
 }
Signature · 1 line
2.51.0
author
#7 lore raw

RFC PATCH v3 3/3 blk-cgroup: move async bio punt state to blkcg

In reply to Yu Kuai

From: Yu Kuai <[email protected]>

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.

---
 block/blk-cgroup.c | 44 +++++++++++++++++++++-----------------------
 block/blk-cgroup.h | 14 ++++++--------
 2 files changed, 27 insertions(+), 31 deletions(-)
block/blk-cgroup.c +21 -23
index c3bbcb3e7e58..2c758c26bce6 100644
@@ -178,14 +178,10 @@ static void blkg_free(struct blkcg_gq *blkg)
 
 static void __blkg_release(struct rcu_head *rcu)
 {
 	struct blkcg_gq *blkg = container_of(rcu, struct blkcg_gq, rcu_head);
 
-#ifdef CONFIG_BLK_CGROUP_PUNT_BIO
-	WARN_ON(!bio_list_empty(&blkg->async_bios));
-#endif
-
 	blkg_free(blkg);
 }
 
 /*
  * A group is RCU protected, but having an rcu lock does not mean that one
@@ -224,23 +220,22 @@ static void blkg_release(struct percpu_ref *ref)
 }
 
 #ifdef CONFIG_BLK_CGROUP_PUNT_BIO
 static struct workqueue_struct *blkcg_punt_bio_wq;
 
-static void blkg_async_bio_workfn(struct work_struct *work)
+static void blkcg_async_bio_workfn(struct work_struct *work)
 {
-	struct blkcg_gq *blkg = container_of(work, struct blkcg_gq,
-					     async_bio_work);
+	struct blkcg *blkcg = container_of(work, struct blkcg, async_bio_work);
 	struct bio_list bios = BIO_EMPTY_LIST;
 	struct bio *bio;
 	struct blk_plug plug;
 	bool need_plug = false;
 
-	/* as long as there are pending bios, @blkg can't go away */
-	spin_lock(&blkg->async_bio_lock);
-	bio_list_merge_init(&bios, &blkg->async_bios);
-	spin_unlock(&blkg->async_bio_lock);
+	/* as long as there are pending bios, @blkcg can't go away */
+	spin_lock(&blkcg->async_bio_lock);
+	bio_list_merge_init(&bios, &blkcg->async_bios);
+	spin_unlock(&blkcg->async_bio_lock);
 
 	/* start plug only when bio_list contains at least 2 bios */
 	if (bios.head && bios.head->bi_next) {
 		need_plug = true;
 		blk_start_plug(&plug);
@@ -257,19 +252,19 @@ static void blkg_async_bio_workfn(struct work_struct *work)
  * cgroup.  Use this helper instead of submit_bio to punt the actual issuing to
  * a dedicated per-blkcg work item to avoid such priority inversions.
  */
 void blkcg_punt_bio_submit(struct bio *bio)
 {
-	struct blkcg_gq *blkg = bio_blkg(bio);
+	struct blkcg *blkcg = bio_blkcg(bio);
 
-	if (blkg && blkg->parent) {
-		spin_lock(&blkg->async_bio_lock);
-		bio_list_add(&blkg->async_bios, bio);
-		spin_unlock(&blkg->async_bio_lock);
-		queue_work(blkcg_punt_bio_wq, &blkg->async_bio_work);
+	if (blkcg && cgroup_parent(blkcg->css.cgroup)) {
+		spin_lock(&blkcg->async_bio_lock);
+		bio_list_add(&blkcg->async_bios, bio);
+		spin_unlock(&blkcg->async_bio_lock);
+		queue_work(blkcg_punt_bio_wq, &blkcg->async_bio_work);
 	} else {
-		/* Never bounce if there is no non-root blkg to queue on. */
+		/* Never bounce if there is no non-root blkcg to queue on. */
 		submit_bio(bio);
 	}
 }
 EXPORT_SYMBOL_GPL(blkcg_punt_bio_submit);
 
@@ -348,15 +343,10 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct gendisk *disk,
 	blkg->q = disk->queue;
 	INIT_LIST_HEAD(&blkg->q_node);
 	blkg->blkcg = blkcg;
 	blkg->blkcg_id = blkcg->css.id;
 	blkg->iostat.blkg = blkg;
-#ifdef CONFIG_BLK_CGROUP_PUNT_BIO
-	spin_lock_init(&blkg->async_bio_lock);
-	bio_list_init(&blkg->async_bios);
-	INIT_WORK(&blkg->async_bio_work, blkg_async_bio_workfn);
-#endif
 
 	u64_stats_init(&blkg->iostat.sync);
 	for_each_possible_cpu(cpu) {
 		u64_stats_init(&per_cpu_ptr(blkg->iostat_cpu, cpu)->sync);
 		per_cpu_ptr(blkg->iostat_cpu, cpu)->blkg = blkg;
@@ -1388,10 +1378,13 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
 		if (blkcg->cpd[i])
 			blkcg_policy[i]->cpd_free_fn(blkcg->cpd[i]);
 
 	mutex_unlock(&blkcg_pol_mutex);
 
+#ifdef CONFIG_BLK_CGROUP_PUNT_BIO
+	WARN_ON(!bio_list_empty(&blkcg->async_bios));
+#endif
 	free_percpu(blkcg->lhead);
 	kfree(blkcg);
 }
 
 static struct cgroup_subsys_state *
@@ -1436,10 +1429,15 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
 	}
 
 	spin_lock_init(&blkcg->lock);
 	refcount_set(&blkcg->online_pin, 1);
 	INIT_HLIST_HEAD(&blkcg->blkg_list);
+#ifdef CONFIG_BLK_CGROUP_PUNT_BIO
+	spin_lock_init(&blkcg->async_bio_lock);
+	bio_list_init(&blkcg->async_bios);
+	INIT_WORK(&blkcg->async_bio_work, blkcg_async_bio_workfn);
+#endif
 #ifdef CONFIG_CGROUP_WRITEBACK
 	INIT_LIST_HEAD(&blkcg->cgwb_list);
 #endif
 	list_add_tail(&blkcg->all_blkcgs_node, &all_blkcgs);
 
block/blk-cgroup.h +6 -8
index 936428b6127e..eb76cc38b41b 100644
@@ -75,18 +75,11 @@ struct blkcg_gq {
 
 	struct blkg_iostat_set __percpu	*iostat_cpu;
 	struct blkg_iostat_set		iostat;
 
 	struct blkg_policy_data		*pd[BLKCG_MAX_POLS];
-#ifdef CONFIG_BLK_CGROUP_PUNT_BIO
-	spinlock_t			async_bio_lock;
-	struct bio_list			async_bios;
-#endif
-	union {
-		struct work_struct	async_bio_work;
-		struct work_struct	free_work;
-	};
+	struct work_struct		free_work;
 
 	atomic_t			use_delay;
 	atomic64_t			delay_nsec;
 	atomic64_t			delay_start;
 	u64				last_delay;
@@ -111,10 +104,15 @@ struct blkcg {
 	/*
 	 * List of updated percpu blkg_iostat_set's since the last flush.
 	 */
 	struct llist_head __percpu	*lhead;
 
+#ifdef CONFIG_BLK_CGROUP_PUNT_BIO
+	spinlock_t			async_bio_lock; /* protects async_bios */
+	struct bio_list			async_bios;
+	struct work_struct		async_bio_work;
+#endif
 #ifdef CONFIG_BLK_CGROUP_FC_APPID
 	char                            fc_app_id[FC_APPID_LEN];
 #endif
 #ifdef CONFIG_CGROUP_WRITEBACK
 	struct list_head		cgwb_list;
Signature · 1 line
2.51.0
#10 lore raw
In reply to Yu Kuai
Quoted 15 lines · Yu Kuai

From: Yu Kuai <[email protected]>

This RFC remains a preparatory series for the blkcg_mutex conversion proposed in the related blkcg_mutex RFC v2 series [1]. That conversion moves queue-local blkg topology synchronization from q->queue_lock to q->blkcg_mutex, which is awkward while bios directly store queue-local blkg references.

v1 made the stored bio association queue-independent by replacing bi_blkg with bi_blkcg, but a bio-owned blkg reference still had to be recovered by looking up the bio's blkcg and current request_queue. Tao Cui reported that cgroup removal deletes a dying blkg from the per-blkcg radix tree before a throttled bio drops its reference. A later lookup for that pinned blkg then fails, triggers the warning in bio_pinned_blkg(), and leaks the reference.

Quoted 8 lines

v2 makes request_queue the authoritative lookup owner before converting the bio association. A queue-owned rhashtable, keyed by the blkcg CSS ID, keeps dying blkgs discoverable until their references drain while q->blkg_list remains available for ordered walks. The bio conversion then stores and pins the blkcg CSS, lazily creates a blkg only for users which need one, and uses lookup-only access for completion and accounting paths which already own a blkg reference. Async bio punt state is finally moved from blkg to blkcg so punting alone does not instantiate a queue-local blkg.

FYI, a blktests-CI trial run found this patch series triggers the failure of the test case block/027 due to "WARNING: suspicious RCU usage". I manually confirmed that the failure is recreated in stable manner, using the kernel at block/for-next branch tip with git hash a33221f7ab12 as the base.

[   60.048652] [    T958] run blktests block/027 at 2026-08-20 14:54:34
[   60.342288] [    T995] sd 9:0:0:0: [sdd] Synchronizing SCSI cache
[   60.512431] [    T998] scsi_debug:sdebug_driver_probe: scsi_debug: trim poll_queues to 0. poll_q/nr_hw = (0/4)
[   60.514009] [    T998] scsi host10: scsi_debug: version 0191 [20210520]
                            dev_size_mb=8, opts=0x0, submit_queues=4, statistics=0
[   60.532043] [    T998] scsi 10:0:0:0: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.537838] [    T998] scsi 10:0:0:0: Power-on or device reset occurred
[   60.546792] [     T57] sd 10:0:0:0: [sdd] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.547027] [    T998] sd 10:0:0:0: Attached scsi generic sg3 type 0
[   60.548204] [     T57] sd 10:0:0:0: [sdd] Write Protect is off
[   60.550257] [     T57] sd 10:0:0:0: [sdd] Mode Sense: 73 00 10 08
[   60.550572] [     T57] sd 10:0:0:0: [sdd] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.552280] [    T998] scsi 10:0:0:1: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.552669] [     T57] sd 10:0:0:0: [sdd] permanent stream count = 5
[   60.554756] [     T57] sd 10:0:0:0: [sdd] Preferred minimum I/O size 512 bytes
[   60.555874] [     T57] sd 10:0:0:0: [sdd] Optimal transfer size 524288 bytes
[   60.556101] [    T998] scsi 10:0:0:1: Power-on or device reset occurred
[   60.582832] [    T998] sd 10:0:0:1: Attached scsi generic sg4 type 0
[   60.586663] [     T89] sd 10:0:0:1: [sde] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.587870] [     T89] sd 10:0:0:1: [sde] Write Protect is off
[   60.588673] [     T89] sd 10:0:0:1: [sde] Mode Sense: 73 00 10 08
[   60.588824] [     T89] sd 10:0:0:1: [sde] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.592560] [     T89] sd 10:0:0:1: [sde] permanent stream count = 5
[   60.594825] [     T89] sd 10:0:0:1: [sde] Preferred minimum I/O size 512 bytes
[   60.596033] [     T89] sd 10:0:0:1: [sde] Optimal transfer size 524288 bytes
[   60.601864] [    T998] scsi 10:0:0:2: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.606287] [     T57] sd 10:0:0:0: [sdd] Attached SCSI disk
[   60.610427] [    T998] scsi 10:0:0:2: Power-on or device reset occurred
[   60.623979] [    T998] sd 10:0:0:2: Attached scsi generic sg5 type 0
[   60.629219] [     T12] sd 10:0:0:2: [sdf] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.630662] [     T12] sd 10:0:0:2: [sdf] Write Protect is off
[   60.635090] [     T12] sd 10:0:0:2: [sdf] Mode Sense: 73 00 10 08
[   60.635296] [     T12] sd 10:0:0:2: [sdf] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.636699] [    T998] scsi 10:0:0:3: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.638127] [     T12] sd 10:0:0:2: [sdf] permanent stream count = 5
[   60.640352] [     T12] sd 10:0:0:2: [sdf] Preferred minimum I/O size 512 bytes
[   60.641526] [    T998] scsi 10:0:0:3: Power-on or device reset occurred
[   60.642765] [     T12] sd 10:0:0:2: [sdf] Optimal transfer size 524288 bytes
[   60.651574] [     T57] sd 10:0:0:3: [sdg] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.653359] [     T57] sd 10:0:0:3: [sdg] Write Protect is off
[   60.654766] [     T57] sd 10:0:0:3: [sdg] Mode Sense: 73 00 10 08
[   60.654923] [     T57] sd 10:0:0:3: [sdg] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.656232] [    T998] sd 10:0:0:3: Attached scsi generic sg6 type 0
[   60.658805] [     T89] sd 10:0:0:1: [sde] Attached SCSI disk
[   60.661190] [     T57] sd 10:0:0:3: [sdg] permanent stream count = 5
[   60.662705] [     T57] sd 10:0:0:3: [sdg] Preferred minimum I/O size 512 bytes
[   60.664127] [     T57] sd 10:0:0:3: [sdg] Optimal transfer size 524288 bytes
[   60.666666] [    T998] scsi 10:0:0:4: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.670896] [    T998] scsi 10:0:0:4: Power-on or device reset occurred
[   60.745716] [    T998] sd 10:0:0:4: Attached scsi generic sg7 type 0
[   60.747518] [     T85] sd 10:0:0:4: [sdh] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.749227] [     T85] sd 10:0:0:4: [sdh] Write Protect is off
[   60.750985] [     T85] sd 10:0:0:4: [sdh] Mode Sense: 73 00 10 08
[   60.751160] [     T85] sd 10:0:0:4: [sdh] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.753246] [     T85] sd 10:0:0:4: [sdh] permanent stream count = 5
[   60.754701] [     T85] sd 10:0:0:4: [sdh] Preferred minimum I/O size 512 bytes
[   60.756101] [     T85] sd 10:0:0:4: [sdh] Optimal transfer size 524288 bytes
[   60.757227] [    T998] scsi 10:0:0:5: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.759747] [     T57] sd 10:0:0:3: [sdg] Attached SCSI disk
[   60.763568] [    T998] scsi 10:0:0:5: Power-on or device reset occurred
[   60.787866] [     T12] sd 10:0:0:2: [sdf] Attached SCSI disk
[   60.804506] [     T85] sd 10:0:0:4: [sdh] Attached SCSI disk
[   60.852111] [    T998] sd 10:0:0:5: Attached scsi generic sg8 type 0
[   60.856376] [     T85] sd 10:0:0:5: [sdi] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.857802] [    T998] scsi 10:0:0:6: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.858071] [     T85] sd 10:0:0:5: [sdi] Write Protect is off
[   60.861854] [     T85] sd 10:0:0:5: [sdi] Mode Sense: 73 00 10 08
[   60.862017] [     T85] sd 10:0:0:5: [sdi] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.862642] [    T998] scsi 10:0:0:6: Power-on or device reset occurred
[   60.863540] [     T85] sd 10:0:0:5: [sdi] permanent stream count = 5
[   60.866947] [     T85] sd 10:0:0:5: [sdi] Preferred minimum I/O size 512 bytes
[   60.870355] [     T85] sd 10:0:0:5: [sdi] Optimal transfer size 524288 bytes
[   60.898965] [    T998] sd 10:0:0:6: Attached scsi generic sg9 type 0
[   60.904198] [     T12] sd 10:0:0:6: [sdj] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.905768] [     T12] sd 10:0:0:6: [sdj] Write Protect is off
[   60.907526] [     T12] sd 10:0:0:6: [sdj] Mode Sense: 73 00 10 08
[   60.907686] [     T12] sd 10:0:0:6: [sdj] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.909852] [     T12] sd 10:0:0:6: [sdj] permanent stream count = 5
[   60.911593] [     T12] sd 10:0:0:6: [sdj] Preferred minimum I/O size 512 bytes
[   60.912958] [     T12] sd 10:0:0:6: [sdj] Optimal transfer size 524288 bytes
[   60.951487] [    T998] scsi 10:0:0:7: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.953020] [     T12] sd 10:0:0:6: [sdj] Attached SCSI disk
[   60.961132] [    T998] scsi 10:0:0:7: Power-on or device reset occurred
[   61.051690] [     T12] sd 10:0:0:7: [sdk] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.053835] [     T12] sd 10:0:0:7: [sdk] Write Protect is off
[   61.055160] [     T12] sd 10:0:0:7: [sdk] Mode Sense: 73 00 10 08
[   61.055324] [     T12] sd 10:0:0:7: [sdk] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.060649] [     T12] sd 10:0:0:7: [sdk] permanent stream count = 5
[   61.062187] [     T12] sd 10:0:0:7: [sdk] Preferred minimum I/O size 512 bytes
[   61.065148] [     T12] sd 10:0:0:7: [sdk] Optimal transfer size 524288 bytes
[   61.101609] [     T85] sd 10:0:0:5: [sdi] Attached SCSI disk
[   61.106279] [    T998] sd 10:0:0:7: Attached scsi generic sg10 type 0
[   61.114062] [    T998] scsi 10:0:0:8: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.123360] [    T998] scsi 10:0:0:8: Power-on or device reset occurred
[   61.139984] [     T12] sd 10:0:0:7: [sdk] Attached SCSI disk
[   61.217165] [     T89] sd 10:0:0:8: [sdl] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.219292] [     T89] sd 10:0:0:8: [sdl] Write Protect is off
[   61.221173] [     T89] sd 10:0:0:8: [sdl] Mode Sense: 73 00 10 08
[   61.221335] [     T89] sd 10:0:0:8: [sdl] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.223670] [     T89] sd 10:0:0:8: [sdl] permanent stream count = 5
[   61.225332] [     T89] sd 10:0:0:8: [sdl] Preferred minimum I/O size 512 bytes
[   61.226777] [     T89] sd 10:0:0:8: [sdl] Optimal transfer size 524288 bytes
[   61.251833] [    T998] sd 10:0:0:8: Attached scsi generic sg11 type 0
[   61.258846] [    T998] scsi 10:0:0:9: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.266439] [    T998] scsi 10:0:0:9: Power-on or device reset occurred
[   61.279306] [     T12] sd 10:0:0:9: [sdm] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.281013] [     T12] sd 10:0:0:9: [sdm] Write Protect is off
[   61.282263] [     T12] sd 10:0:0:9: [sdm] Mode Sense: 73 00 10 08
[   61.282429] [     T12] sd 10:0:0:9: [sdm] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.283621] [    T998] sd 10:0:0:9: Attached scsi generic sg12 type 0
[   61.285076] [     T12] sd 10:0:0:9: [sdm] permanent stream count = 5
[   61.286842] [     T12] sd 10:0:0:9: [sdm] Preferred minimum I/O size 512 bytes
[   61.288650] [     T12] sd 10:0:0:9: [sdm] Optimal transfer size 524288 bytes
[   61.350640] [    T998] scsi 10:0:0:10: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.356467] [     T12] sd 10:0:0:9: [sdm] Attached SCSI disk
[   61.359096] [    T998] scsi 10:0:0:10: Power-on or device reset occurred
[   61.428598] [     T89] sd 10:0:0:8: [sdl] Attached SCSI disk
[   61.519323] [    T998] sd 10:0:0:10: Attached scsi generic sg13 type 0
[   61.519455] [     T89] sd 10:0:0:10: [sdn] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.524681] [    T998] scsi 10:0:0:11: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.525872] [     T89] sd 10:0:0:10: [sdn] Write Protect is off
[   61.530097] [     T89] sd 10:0:0:10: [sdn] Mode Sense: 73 00 10 08
[   61.530292] [     T89] sd 10:0:0:10: [sdn] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.530887] [    T998] scsi 10:0:0:11: Power-on or device reset occurred
[   61.532201] [     T89] sd 10:0:0:10: [sdn] permanent stream count = 5
[   61.536746] [     T89] sd 10:0:0:10: [sdn] Preferred minimum I/O size 512 bytes
[   61.539106] [     T89] sd 10:0:0:10: [sdn] Optimal transfer size 524288 bytes
[   61.541544] [     T85] sd 10:0:0:11: [sdo] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.543209] [     T85] sd 10:0:0:11: [sdo] Write Protect is off
[   61.545292] [     T85] sd 10:0:0:11: [sdo] Mode Sense: 73 00 10 08
[   61.545453] [     T85] sd 10:0:0:11: [sdo] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.547869] [     T85] sd 10:0:0:11: [sdo] permanent stream count = 5
[   61.550065] [     T85] sd 10:0:0:11: [sdo] Preferred minimum I/O size 512 bytes
[   61.551491] [     T85] sd 10:0:0:11: [sdo] Optimal transfer size 524288 bytes
[   61.560843] [    T998] sd 10:0:0:11: Attached scsi generic sg14 type 0
[   61.575647] [    T998] scsi 10:0:0:12: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.581203] [    T998] scsi 10:0:0:12: Power-on or device reset occurred
[   61.659971] [     T89] sd 10:0:0:10: [sdn] Attached SCSI disk
[   61.703691] [    T998] sd 10:0:0:12: Attached scsi generic sg15 type 0
[   61.714468] [     T85] sd 10:0:0:11: [sdo] Attached SCSI disk
[   61.752593] [    T998] scsi 10:0:0:13: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.761908] [    T998] scsi 10:0:0:13: Power-on or device reset occurred
[   61.770075] [     T89] sd 10:0:0:12: [sdp] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.771727] [     T89] sd 10:0:0:12: [sdp] Write Protect is off
[   61.773108] [     T89] sd 10:0:0:12: [sdp] Mode Sense: 73 00 10 08
[   61.773266] [     T89] sd 10:0:0:12: [sdp] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.775657] [     T89] sd 10:0:0:12: [sdp] permanent stream count = 5
[   61.778651] [     T89] sd 10:0:0:12: [sdp] Preferred minimum I/O size 512 bytes
[   61.781598] [     T89] sd 10:0:0:12: [sdp] Optimal transfer size 524288 bytes
[   61.801054] [     T85] sd 10:0:0:13: [sdq] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.802968] [     T85] sd 10:0:0:13: [sdq] Write Protect is off
[   61.804603] [     T85] sd 10:0:0:13: [sdq] Mode Sense: 73 00 10 08
[   61.804798] [     T85] sd 10:0:0:13: [sdq] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.809291] [     T85] sd 10:0:0:13: [sdq] permanent stream count = 5
[   61.812234] [     T85] sd 10:0:0:13: [sdq] Preferred minimum I/O size 512 bytes
[   61.814067] [     T85] sd 10:0:0:13: [sdq] Optimal transfer size 524288 bytes
[   61.856311] [    T998] sd 10:0:0:13: Attached scsi generic sg16 type 0
[   61.872980] [    T998] scsi 10:0:0:14: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.880018] [    T998] scsi 10:0:0:14: Power-on or device reset occurred
[   61.898152] [     T12] sd 10:0:0:14: [sdr] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.901297] [     T12] sd 10:0:0:14: [sdr] Write Protect is off
[   61.904599] [     T12] sd 10:0:0:14: [sdr] Mode Sense: 73 00 10 08
[   61.904758] [     T12] sd 10:0:0:14: [sdr] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.907952] [     T12] sd 10:0:0:14: [sdr] permanent stream count = 5
[   61.909473] [     T12] sd 10:0:0:14: [sdr] Preferred minimum I/O size 512 bytes
[   61.911556] [     T12] sd 10:0:0:14: [sdr] Optimal transfer size 524288 bytes
[   61.921187] [     T89] sd 10:0:0:12: [sdp] Attached SCSI disk
[   61.947703] [    T998] sd 10:0:0:14: Attached scsi generic sg17 type 0
[   61.956937] [    T998] scsi 10:0:0:15: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.964139] [    T998] scsi 10:0:0:15: Power-on or device reset occurred
[   61.966101] [     T85] sd 10:0:0:13: [sdq] Attached SCSI disk
[   62.054834] [    T998] sd 10:0:0:15: Attached scsi generic sg18 type 0
[   62.063562] [    T998] scsi 10:0:0:16: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   62.069436] [    T998] scsi 10:0:0:16: Power-on or device reset occurred
[   62.070705] [     T89] sd 10:0:0:15: [sds] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   62.073325] [     T89] sd 10:0:0:15: [sds] Write Protect is off
[   62.074520] [     T89] sd 10:0:0:15: [sds] Mode Sense: 73 00 10 08
[   62.074682] [     T89] sd 10:0:0:15: [sds] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   62.078365] [     T85] sd 10:0:0:16: [sdt] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   62.079508] [     T89] sd 10:0:0:15: [sds] permanent stream count = 5
[   62.080108] [     T85] sd 10:0:0:16: [sdt] Write Protect is off
[   62.080978] [     T89] sd 10:0:0:15: [sds] Preferred minimum I/O size 512 bytes
[   62.082994] [     T85] sd 10:0:0:16: [sdt] Mode Sense: 73 00 10 08
[   62.083665] [     T89] sd 10:0:0:15: [sds] Optimal transfer size 524288 bytes
[   62.084433] [    T998] sd 10:0:0:16: Attached scsi generic sg19 type 0
[   62.086905] [     T85] sd 10:0:0:16: [sdt] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   62.090249] [     T85] sd 10:0:0:16: [sdt] permanent stream count = 5
[   62.091796] [     T85] sd 10:0:0:16: [sdt] Preferred minimum I/O size 512 bytes
[   62.095042] [    T998] scsi 10:0:0:17: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   62.096731] [     T85] sd 10:0:0:16: [sdt] Optimal transfer size 524288 bytes
[   62.099216] [     T12] sd 10:0:0:14: [sdr] Attached SCSI disk
[   62.102505] [    T998] scsi 10:0:0:17: Power-on or device reset occurred
[   62.130600] [     T89] sd 10:0:0:15: [sds] Attached SCSI disk
[   62.152860] [     T57] sd 10:0:0:17: [sdu] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   62.154661] [     T57] sd 10:0:0:17: [sdu] Write Protect is off
[   62.156840] [     T57] sd 10:0:0:17: [sdu] Mode Sense: 73 00 10 08
[   62.156999] [     T57] sd 10:0:0:17: [sdu] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   62.158980] [     T57] sd 10:0:0:17: [sdu] permanent stream count = 5
[   62.160461] [     T57] sd 10:0:0:17: [sdu] Preferred minimum I/O size 512 bytes
[   62.161941] [     T57] sd 10:0:0:17: [sdu] Optimal transfer size 524288 bytes
[   62.197490] [    T998] sd 10:0:0:17: Attached scsi generic sg20 type 0
[   62.202924] [     T85] sd 10:0:0:16: [sdt] Attached SCSI disk
[   62.246749] [    T998] scsi 10:0:0:18: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   62.253160] [    T998] scsi 10:0:0:18: Power-on or device reset occurred
[   62.362859] [     T85] sd 10:0:0:18: [sdv] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   62.364530] [     T85] sd 10:0:0:18: [sdv] Write Protect is off
[   62.369860] [     T85] sd 10:0:0:18: [sdv] Mode Sense: 73 00 10 08
[   62.370019] [     T85] sd 10:0:0:18: [sdv] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   62.372485] [     T85] sd 10:0:0:18: [sdv] permanent stream count = 5
[   62.375392] [     T85] sd 10:0:0:18: [sdv] Preferred minimum I/O size 512 bytes
[   62.377326] [     T85] sd 10:0:0:18: [sdv] Optimal transfer size 524288 bytes
[   62.386677] [    T998] sd 10:0:0:18: Attached scsi generic sg21 type 0
[   62.390025] [     T57] sd 10:0:0:17: [sdu] Attached SCSI disk
[   62.395147] [    T998] scsi 10:0:0:19: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   62.400566] [    T998] scsi 10:0:0:19: Power-on or device reset occurred
[   62.492252] [    T998] sd 10:0:0:19: Attached scsi generic sg22 type 0
[   62.504374] [     T89] sd 10:0:0:19: [sdw] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   62.506027] [     T89] sd 10:0:0:19: [sdw] Write Protect is off
[   62.507260] [     T89] sd 10:0:0:19: [sdw] Mode Sense: 73 00 10 08
[   62.507422] [     T89] sd 10:0:0:19: [sdw] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   62.509393] [     T89] sd 10:0:0:19: [sdw] permanent stream count = 5
[   62.512301] [     T89] sd 10:0:0:19: [sdw] Preferred minimum I/O size 512 bytes
[   62.513697] [     T89] sd 10:0:0:19: [sdw] Optimal transfer size 524288 bytes
[   62.541424] [    T998] scsi 10:0:0:20: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   62.552224] [    T998] scsi 10:0:0:20: Power-on or device reset occurred
[   62.599822] [     T85] sd 10:0:0:18: [sdv] Attached SCSI disk
[   62.609329] [     T57] sd 10:0:0:20: [sdx] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   62.613381] [     T57] sd 10:0:0:20: [sdx] Write Protect is off
[   62.618693] [     T57] sd 10:0:0:20: [sdx] Mode Sense: 73 00 10 08
[   62.618850] [     T57] sd 10:0:0:20: [sdx] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   62.621631] [     T57] sd 10:0:0:20: [sdx] permanent stream count = 5
[   62.623343] [     T57] sd 10:0:0:20: [sdx] Preferred minimum I/O size 512 bytes
[   62.624997] [     T57] sd 10:0:0:20: [sdx] Optimal transfer size 524288 bytes
[   62.628524] [    T998] sd 10:0:0:20: Attached scsi generic sg23 type 0
[   62.643270] [     T89] sd 10:0:0:19: [sdw] Attached SCSI disk
[   62.726714] [     T57] sd 10:0:0:20: [sdx] Attached SCSI disk
[   71.628857] [    T958] sd 10:0:0:0: [sdd] Synchronizing SCSI cache
[   71.725933] [   T1258] =============================
[   71.727013] [   T1258] WARNING: suspicious RCU usage
[   71.728048] [   T1258] 7.2.0-rc5+ #448 Not tainted
[   71.729043] [   T1258] -----------------------------
[   71.730053] [   T1258] block/blk-cgroup.h:273 blkg_lookup_any() requires an RCU read lock!
[   71.731460] [   T1258] 
                          other info that might help us debug this:
[   71.734042] [   T1258] 
                          rcu_scheduler_active = 2, debug_locks = 1
[   71.735857] [   T1258] 1 lock held by fio/1258:
[   71.736805] [   T1258]  #0: ffff88810a4bb6c8 (&q->queue_lock){..-.}-{3:3}, at: bio_blkg+0x131/0xed0
[   71.738307] [   T1258] 
                          stack backtrace:
[   71.739882] [   T1258] CPU: 0 UID: 0 PID: 1258 Comm: fio Not tainted 7.2.0-rc5+ #448 PREEMPT(full) 
[   71.739886] [   T1258] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-10.fc44 06/10/2025
[   71.739890] [   T1258] Call Trace:
[   71.739892] [   T1258]  <TASK>
[   71.739894] [   T1258]  dump_stack_lvl+0x6a/0x90
[   71.739900] [   T1258]  lockdep_rcu_suspicious.cold+0x3a/0x7d
[   71.739906] [   T1258]  blkg_lookup_any+0x3ad/0x5d0
[   71.739910] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.739915] [   T1258]  ? bio_blkg+0x634/0xed0
[   71.739917] [   T1258]  ? lock_release+0x1b5/0x340
[   71.739922] [   T1258]  bio_blkg+0x681/0xed0
[   71.739930] [   T1258]  bfq_insert_requests+0x17cc/0x8f90
[   71.739937] [   T1258]  ? __create_object+0x4e/0xe0
[   71.739941] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.739945] [   T1258]  ? __create_object+0x78/0xe0
[   71.739947] [   T1258]  ? lock_release+0x1b5/0x340
[   71.739952] [   T1258]  ? _raw_spin_unlock_irqrestore+0x35/0x60
[   71.739956] [   T1258]  ? __pfx_bfq_insert_requests+0x10/0x10
[   71.739959] [   T1258]  ? rcu_is_watching+0x11/0xb0
[   71.739963] [   T1258]  ? kmem_cache_alloc_noprof+0x4bf/0x6d0
[   71.739967] [   T1258]  ? radix_tree_node_alloc.constprop.0+0x19e/0x3a0
[   71.739973] [   T1258]  ? radix_tree_node_alloc.constprop.0+0x19e/0x3a0
[   71.739978] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.739982] [   T1258]  ? ioc_find_get_icq+0x585/0xab0
[   71.739985] [   T1258]  ? lock_release+0x1b5/0x340
[   71.739987] [   T1258]  ? trace_hardirqs_on+0x14/0x190
[   71.739991] [   T1258]  ? ioc_find_get_icq+0x594/0xab0
[   71.739997] [   T1258]  ? bdev_count_inflight_rw.part.0+0x17f/0x320
[   71.740005] [   T1258]  ? bdev_count_inflight+0x67/0xa0
[   71.740008] [   T1258]  ? __pfx_bdev_count_inflight+0x10/0x10
[   71.740012] [   T1258]  ? ktime_get+0x27/0x210
[   71.740016] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.740021] [   T1258]  blk_mq_insert_request+0x248/0xbe0
[   71.740025] [   T1258]  ? __pfx_blk_mq_insert_request+0x10/0x10
[   71.740027] [   T1258]  ? kvm_clock_get_cycles+0x14/0x30
[   71.740036] [   T1258]  blk_mq_submit_bio+0xf25/0x2a00
[   71.740040] [   T1258]  ? bio_associate_blkcg_from_css+0x14b/0x670
[   71.740044] [   T1258]  ? __pfx_blk_mq_submit_bio+0x10/0x10
[   71.740047] [   T1258]  ? iov_iter_extract_bvecs+0x50f/0xb30
[   71.740054] [   T1258]  ? __pfx_blk_cgroup_bio_start+0x10/0x10
[   71.740060] [   T1258]  submit_bio_noacct_nocheck+0x41d/0xb00
[   71.740066] [   T1258]  ? __pfx_submit_bio_noacct_nocheck+0x10/0x10
[   71.740071] [   T1258]  ? submit_bio_noacct+0x80c/0x2070
[   71.740078] [   T1258]  blkdev_direct_IO+0x949/0x1f90
[   71.740080] [   T1258]  ? lock_acquire+0x199/0x320
[   71.740083] [   T1258]  ? is_bpf_text_address+0x1d/0xf0
[   71.740086] [   T1258]  ? lock_acquire+0x1a9/0x320
[   71.740088] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.740092] [   T1258]  ? is_bpf_text_address+0x60/0xf0
[   71.740094] [   T1258]  ? lock_release+0x1b5/0x340
[   71.740099] [   T1258]  ? __pfx_blkdev_direct_IO+0x10/0x10
[   71.740102] [   T1258]  ? __kernel_text_address+0xe/0x30
[   71.740105] [   T1258]  ? __pfx_stack_trace_consume_entry+0x10/0x10
[   71.740108] [   T1258]  ? unwind_get_return_address+0x67/0xd0
[   71.740111] [   T1258]  ? arch_stack_walk+0xef/0x140
[   71.740116] [   T1258]  ? selinux_file_permission+0x3c0/0x530
[   71.740122] [   T1258]  blkdev_read_iter+0x223/0x440
[   71.740128] [   T1258]  aio_read+0x2e8/0x5b0
[   71.740133] [   T1258]  ? __pfx_aio_read+0x10/0x10
[   71.740148] [   T1258]  ? __pfx___might_resched+0x10/0x10
[   71.740151] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.740155] [   T1258]  ? __might_fault+0x97/0x140
[   71.740160] [   T1258]  ? io_submit_one+0x440/0x1a70
[   71.740162] [   T1258]  io_submit_one+0x440/0x1a70
[   71.740171] [   T1258]  ? __pfx_io_submit_one+0x10/0x10
[   71.740173] [   T1258]  ? rcu_is_watching+0x11/0xb0
[   71.740182] [   T1258]  ? __pfx___might_resched+0x10/0x10
[   71.740184] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.740191] [   T1258]  ? __x64_sys_io_submit+0x193/0x2f0
[   71.740194] [   T1258]  __x64_sys_io_submit+0x193/0x2f0
[   71.740198] [   T1258]  ? __pfx___x64_sys_io_submit+0x10/0x10
[   71.740203] [   T1258]  ? lock_release+0x1b5/0x340
[   71.740211] [   T1258]  do_syscall_64+0xdf/0x790
[   71.740218] [   T1258]  ? __lock_acquire+0x3d2/0x2440
[   71.740222] [   T1258]  ? __pfx___css_rstat_updated+0x10/0x10
[   71.740228] [   T1258]  ? lock_acquire+0x199/0x320
[   71.740230] [   T1258]  ? count_memcg_events_mm.constprop.0+0x22/0x130
[   71.740233] [   T1258]  ? rcu_is_watching+0x11/0xb0
[   71.740236] [   T1258]  ? count_memcg_events+0x107/0x4c0
[   71.740238] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.740242] [   T1258]  ? rcu_is_watching+0x11/0xb0
[   71.740245] [   T1258]  ? __up_read+0x351/0x9c0
[   71.740249] [   T1258]  ? __pfx___up_read+0x10/0x10
[   71.740252] [   T1258]  ? do_user_addr_fault+0x28c/0xaf0
[   71.740255] [   T1258]  ? lock_release+0x1b5/0x340
[   71.740260] [   T1258]  ? rcu_is_watching+0x11/0xb0
[   71.740263] [   T1258]  ? trace_hardirqs_on+0x14/0x190
[   71.740265] [   T1258]  ? preempt_count_add+0x7f/0x190
[   71.740267] [   T1258]  ? do_syscall_64+0x5d/0x790
[   71.740270] [   T1258]  ? do_syscall_64+0x8d/0x790
[   71.740272] [   T1258]  ? irqentry_exit+0xfc/0x810
[   71.740277] [   T1258]  entry_SYSCALL_64_after_hwframe+0x76/0x7e
[   71.740280] [   T1258] RIP: 0033:0x7f40f240c0cd
[   71.740283] [   T1258] Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 03 4d 0f 00 f7 d8 64 89 01 48
[   71.740285] [   T1258] RSP: 002b:00007fff410d1b08 EFLAGS: 00000246 ORIG_RAX: 00000000000000d1
[   71.740290] [   T1258] RAX: ffffffffffffffda RBX: 00007f40f2316718 RCX: 00007f40f240c0cd
[   71.740292] [   T1258] RDX: 000000001f5f9750 RSI: 0000000000000001 RDI: 00007f40e3fdf000
[   71.740293] [   T1258] RBP: 00007fff410d1b40 R08: 000000001f7094e0 R09: 000000001f709400
[   71.740294] [   T1258] R10: 000000001f709400 R11: 0000000000000246 R12: 00007f40e3fdf000
[   71.740296] [   T1258] R13: 0000000000000000 R14: 000000001f5f9750 R15: 0000000000000001
[   71.740305] [   T1258]  </TASK>
[   73.210606] [    T958] sd 10:0:0:1: [sde] Synchronizing SCSI cache
[   73.251578] [    T296] device offline error, dev sdn, sector 189403096 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256114] [    T296] device offline error, dev sdn, sector 199421272 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256143] [    T296] device offline error, dev sdn, sector 203643552 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256162] [    T296] device offline error, dev sdn, sector 207427136 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256201] [    T296] device offline error, dev sdn, sector 214836224 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256219] [    T296] device offline error, dev sdn, sector 235862656 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256237] [    T296] device offline error, dev sdn, sector 236401976 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256272] [    T296] device offline error, dev sdn, sector 238514280 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256290] [    T296] device offline error, dev sdn, sector 245902744 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256308] [    T296] device offline error, dev sdn, sector 246183280 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   74.011940] [    T958] sd 10:0:0:10: [sdn] Synchronizing SCSI cache
[   74.448759] [    T958] sd 10:0:0:11: [sdo] Synchronizing SCSI cache
[   74.839748] [    T958] sd 10:0:0:12: [sdp] Synchronizing SCSI cache
[   75.265115] [    T958] sd 10:0:0:13: [sdq] Synchronizing SCSI cache
[   75.660906] [    T958] sd 10:0:0:14: [sdr] Synchronizing SCSI cache
[   76.010466] [    T958] sd 10:0:0:15: [sds] Synchronizing SCSI cache
[   76.426481] [    T958] sd 10:0:0:16: [sdt] Synchronizing SCSI cache
[   76.871466] [    T958] sd 10:0:0:17: [sdu] Synchronizing SCSI cache
[   77.286379] [    T958] sd 10:0:0:18: [sdv] Synchronizing SCSI cache
[   77.844417] [    T958] sd 10:0:0:19: [sdw] Synchronizing SCSI cache
[   78.325753] [    T958] sd 10:0:0:2: [sdf] Synchronizing SCSI cache
[   78.331587] [   T1336] blk_print_req_error: 225 callbacks suppressed
[   78.331594] [   T1336] device offline error, dev sdx, sector 129278536 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   78.334828] [   T1336] device offline error, dev sdx, sector 23920864 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   78.687509] [    T958] sd 10:0:0:20: [sdx] Synchronizing SCSI cache
[   78.695490] [    T332] device offline error, dev sdg, sector 200011456 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   78.697842] [    T332] device offline error, dev sdg, sector 80898080 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   78.700331] [    T332] device offline error, dev sdg, sector 31089776 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   78.701066] [    T107] device offline error, dev sdg, sector 107919016 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   79.057557] [    T958] sd 10:0:0:3: [sdg] Synchronizing SCSI cache
[   79.506572] [    T958] sd 10:0:0:4: [sdh] Synchronizing SCSI cache
[   79.516857] [    T106] device offline error, dev sdi, sector 118581624 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   79.517079] [    T332] device offline error, dev sdi, sector 88640592 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   79.518274] [    T106] device offline error, dev sdi, sector 124905824 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   79.519554] [    T332] device offline error, dev sdi, sector 102957264 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   80.013799] [    T958] sd 10:0:0:5: [sdi] Synchronizing SCSI cache
[   80.364040] [    T958] sd 10:0:0:6: [sdj] Synchronizing SCSI cache
[   80.737957] [    T958] sd 10:0:0:7: [sdk] Synchronizing SCSI cache
[   81.150826] [    T958] sd 10:0:0:8: [sdl] Synchronizing SCSI cache
[   81.468618] [    T958] sd 10:0:0:9: [sdm] Synchronizing SCSI cache
maintainer
#11 lore raw

Hi,

Quoted 286 lines · Shin'ichiro Kawasaki
Quoted 15 lines · Yu Kuai

From: Yu Kuai <[email protected]>

This RFC remains a preparatory series for the blkcg_mutex conversion proposed in the related blkcg_mutex RFC v2 series [1]. That conversion moves queue-local blkg topology synchronization from q->queue_lock to q->blkcg_mutex, which is awkward while bios directly store queue-local blkg references.

v1 made the stored bio association queue-independent by replacing bi_blkg with bi_blkcg, but a bio-owned blkg reference still had to be recovered by looking up the bio's blkcg and current request_queue. Tao Cui reported that cgroup removal deletes a dying blkg from the per-blkcg radix tree before a throttled bio drops its reference. A later lookup for that pinned blkg then fails, triggers the warning in bio_pinned_blkg(), and leaks the reference.

Quoted 8 lines

v2 makes request_queue the authoritative lookup owner before converting the bio association. A queue-owned rhashtable, keyed by the blkcg CSS ID, keeps dying blkgs discoverable until their references drain while q->blkg_list remains available for ordered walks. The bio conversion then stores and pins the blkcg CSS, lazily creates a blkg only for users which need one, and uses lookup-only access for completion and accounting paths which already own a blkg reference. Async bio punt state is finally moved from blkg to blkcg so punting alone does not instantiate a queue-local blkg.

FYI, a blktests-CI trial run found this patch series triggers the failure of the test case block/027 due to "WARNING: suspicious RCU usage". I manually confirmed that the failure is recreated in stable manner, using the kernel at block/for-next branch tip with git hash a33221f7ab12 as the base.

[   60.048652] [    T958] run blktests block/027 at 2026-08-20 14:54:34
[   60.342288] [    T995] sd 9:0:0:0: [sdd] Synchronizing SCSI cache
[   60.512431] [    T998] scsi_debug:sdebug_driver_probe: scsi_debug: trim poll_queues to 0. poll_q/nr_hw = (0/4)
[   60.514009] [    T998] scsi host10: scsi_debug: version 0191 [20210520]
                             dev_size_mb=8, opts=0x0, submit_queues=4, statistics=0
[   60.532043] [    T998] scsi 10:0:0:0: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.537838] [    T998] scsi 10:0:0:0: Power-on or device reset occurred
[   60.546792] [     T57] sd 10:0:0:0: [sdd] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.547027] [    T998] sd 10:0:0:0: Attached scsi generic sg3 type 0
[   60.548204] [     T57] sd 10:0:0:0: [sdd] Write Protect is off
[   60.550257] [     T57] sd 10:0:0:0: [sdd] Mode Sense: 73 00 10 08
[   60.550572] [     T57] sd 10:0:0:0: [sdd] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.552280] [    T998] scsi 10:0:0:1: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.552669] [     T57] sd 10:0:0:0: [sdd] permanent stream count = 5
[   60.554756] [     T57] sd 10:0:0:0: [sdd] Preferred minimum I/O size 512 bytes
[   60.555874] [     T57] sd 10:0:0:0: [sdd] Optimal transfer size 524288 bytes
[   60.556101] [    T998] scsi 10:0:0:1: Power-on or device reset occurred
[   60.582832] [    T998] sd 10:0:0:1: Attached scsi generic sg4 type 0
[   60.586663] [     T89] sd 10:0:0:1: [sde] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.587870] [     T89] sd 10:0:0:1: [sde] Write Protect is off
[   60.588673] [     T89] sd 10:0:0:1: [sde] Mode Sense: 73 00 10 08
[   60.588824] [     T89] sd 10:0:0:1: [sde] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.592560] [     T89] sd 10:0:0:1: [sde] permanent stream count = 5
[   60.594825] [     T89] sd 10:0:0:1: [sde] Preferred minimum I/O size 512 bytes
[   60.596033] [     T89] sd 10:0:0:1: [sde] Optimal transfer size 524288 bytes
[   60.601864] [    T998] scsi 10:0:0:2: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.606287] [     T57] sd 10:0:0:0: [sdd] Attached SCSI disk
[   60.610427] [    T998] scsi 10:0:0:2: Power-on or device reset occurred
[   60.623979] [    T998] sd 10:0:0:2: Attached scsi generic sg5 type 0
[   60.629219] [     T12] sd 10:0:0:2: [sdf] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.630662] [     T12] sd 10:0:0:2: [sdf] Write Protect is off
[   60.635090] [     T12] sd 10:0:0:2: [sdf] Mode Sense: 73 00 10 08
[   60.635296] [     T12] sd 10:0:0:2: [sdf] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.636699] [    T998] scsi 10:0:0:3: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.638127] [     T12] sd 10:0:0:2: [sdf] permanent stream count = 5
[   60.640352] [     T12] sd 10:0:0:2: [sdf] Preferred minimum I/O size 512 bytes
[   60.641526] [    T998] scsi 10:0:0:3: Power-on or device reset occurred
[   60.642765] [     T12] sd 10:0:0:2: [sdf] Optimal transfer size 524288 bytes
[   60.651574] [     T57] sd 10:0:0:3: [sdg] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.653359] [     T57] sd 10:0:0:3: [sdg] Write Protect is off
[   60.654766] [     T57] sd 10:0:0:3: [sdg] Mode Sense: 73 00 10 08
[   60.654923] [     T57] sd 10:0:0:3: [sdg] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.656232] [    T998] sd 10:0:0:3: Attached scsi generic sg6 type 0
[   60.658805] [     T89] sd 10:0:0:1: [sde] Attached SCSI disk
[   60.661190] [     T57] sd 10:0:0:3: [sdg] permanent stream count = 5
[   60.662705] [     T57] sd 10:0:0:3: [sdg] Preferred minimum I/O size 512 bytes
[   60.664127] [     T57] sd 10:0:0:3: [sdg] Optimal transfer size 524288 bytes
[   60.666666] [    T998] scsi 10:0:0:4: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.670896] [    T998] scsi 10:0:0:4: Power-on or device reset occurred
[   60.745716] [    T998] sd 10:0:0:4: Attached scsi generic sg7 type 0
[   60.747518] [     T85] sd 10:0:0:4: [sdh] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.749227] [     T85] sd 10:0:0:4: [sdh] Write Protect is off
[   60.750985] [     T85] sd 10:0:0:4: [sdh] Mode Sense: 73 00 10 08
[   60.751160] [     T85] sd 10:0:0:4: [sdh] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.753246] [     T85] sd 10:0:0:4: [sdh] permanent stream count = 5
[   60.754701] [     T85] sd 10:0:0:4: [sdh] Preferred minimum I/O size 512 bytes
[   60.756101] [     T85] sd 10:0:0:4: [sdh] Optimal transfer size 524288 bytes
[   60.757227] [    T998] scsi 10:0:0:5: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.759747] [     T57] sd 10:0:0:3: [sdg] Attached SCSI disk
[   60.763568] [    T998] scsi 10:0:0:5: Power-on or device reset occurred
[   60.787866] [     T12] sd 10:0:0:2: [sdf] Attached SCSI disk
[   60.804506] [     T85] sd 10:0:0:4: [sdh] Attached SCSI disk
[   60.852111] [    T998] sd 10:0:0:5: Attached scsi generic sg8 type 0
[   60.856376] [     T85] sd 10:0:0:5: [sdi] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.857802] [    T998] scsi 10:0:0:6: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.858071] [     T85] sd 10:0:0:5: [sdi] Write Protect is off
[   60.861854] [     T85] sd 10:0:0:5: [sdi] Mode Sense: 73 00 10 08
[   60.862017] [     T85] sd 10:0:0:5: [sdi] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.862642] [    T998] scsi 10:0:0:6: Power-on or device reset occurred
[   60.863540] [     T85] sd 10:0:0:5: [sdi] permanent stream count = 5
[   60.866947] [     T85] sd 10:0:0:5: [sdi] Preferred minimum I/O size 512 bytes
[   60.870355] [     T85] sd 10:0:0:5: [sdi] Optimal transfer size 524288 bytes
[   60.898965] [    T998] sd 10:0:0:6: Attached scsi generic sg9 type 0
[   60.904198] [     T12] sd 10:0:0:6: [sdj] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   60.905768] [     T12] sd 10:0:0:6: [sdj] Write Protect is off
[   60.907526] [     T12] sd 10:0:0:6: [sdj] Mode Sense: 73 00 10 08
[   60.907686] [     T12] sd 10:0:0:6: [sdj] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   60.909852] [     T12] sd 10:0:0:6: [sdj] permanent stream count = 5
[   60.911593] [     T12] sd 10:0:0:6: [sdj] Preferred minimum I/O size 512 bytes
[   60.912958] [     T12] sd 10:0:0:6: [sdj] Optimal transfer size 524288 bytes
[   60.951487] [    T998] scsi 10:0:0:7: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   60.953020] [     T12] sd 10:0:0:6: [sdj] Attached SCSI disk
[   60.961132] [    T998] scsi 10:0:0:7: Power-on or device reset occurred
[   61.051690] [     T12] sd 10:0:0:7: [sdk] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.053835] [     T12] sd 10:0:0:7: [sdk] Write Protect is off
[   61.055160] [     T12] sd 10:0:0:7: [sdk] Mode Sense: 73 00 10 08
[   61.055324] [     T12] sd 10:0:0:7: [sdk] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.060649] [     T12] sd 10:0:0:7: [sdk] permanent stream count = 5
[   61.062187] [     T12] sd 10:0:0:7: [sdk] Preferred minimum I/O size 512 bytes
[   61.065148] [     T12] sd 10:0:0:7: [sdk] Optimal transfer size 524288 bytes
[   61.101609] [     T85] sd 10:0:0:5: [sdi] Attached SCSI disk
[   61.106279] [    T998] sd 10:0:0:7: Attached scsi generic sg10 type 0
[   61.114062] [    T998] scsi 10:0:0:8: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.123360] [    T998] scsi 10:0:0:8: Power-on or device reset occurred
[   61.139984] [     T12] sd 10:0:0:7: [sdk] Attached SCSI disk
[   61.217165] [     T89] sd 10:0:0:8: [sdl] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.219292] [     T89] sd 10:0:0:8: [sdl] Write Protect is off
[   61.221173] [     T89] sd 10:0:0:8: [sdl] Mode Sense: 73 00 10 08
[   61.221335] [     T89] sd 10:0:0:8: [sdl] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.223670] [     T89] sd 10:0:0:8: [sdl] permanent stream count = 5
[   61.225332] [     T89] sd 10:0:0:8: [sdl] Preferred minimum I/O size 512 bytes
[   61.226777] [     T89] sd 10:0:0:8: [sdl] Optimal transfer size 524288 bytes
[   61.251833] [    T998] sd 10:0:0:8: Attached scsi generic sg11 type 0
[   61.258846] [    T998] scsi 10:0:0:9: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.266439] [    T998] scsi 10:0:0:9: Power-on or device reset occurred
[   61.279306] [     T12] sd 10:0:0:9: [sdm] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.281013] [     T12] sd 10:0:0:9: [sdm] Write Protect is off
[   61.282263] [     T12] sd 10:0:0:9: [sdm] Mode Sense: 73 00 10 08
[   61.282429] [     T12] sd 10:0:0:9: [sdm] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.283621] [    T998] sd 10:0:0:9: Attached scsi generic sg12 type 0
[   61.285076] [     T12] sd 10:0:0:9: [sdm] permanent stream count = 5
[   61.286842] [     T12] sd 10:0:0:9: [sdm] Preferred minimum I/O size 512 bytes
[   61.288650] [     T12] sd 10:0:0:9: [sdm] Optimal transfer size 524288 bytes
[   61.350640] [    T998] scsi 10:0:0:10: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.356467] [     T12] sd 10:0:0:9: [sdm] Attached SCSI disk
[   61.359096] [    T998] scsi 10:0:0:10: Power-on or device reset occurred
[   61.428598] [     T89] sd 10:0:0:8: [sdl] Attached SCSI disk
[   61.519323] [    T998] sd 10:0:0:10: Attached scsi generic sg13 type 0
[   61.519455] [     T89] sd 10:0:0:10: [sdn] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.524681] [    T998] scsi 10:0:0:11: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.525872] [     T89] sd 10:0:0:10: [sdn] Write Protect is off
[   61.530097] [     T89] sd 10:0:0:10: [sdn] Mode Sense: 73 00 10 08
[   61.530292] [     T89] sd 10:0:0:10: [sdn] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.530887] [    T998] scsi 10:0:0:11: Power-on or device reset occurred
[   61.532201] [     T89] sd 10:0:0:10: [sdn] permanent stream count = 5
[   61.536746] [     T89] sd 10:0:0:10: [sdn] Preferred minimum I/O size 512 bytes
[   61.539106] [     T89] sd 10:0:0:10: [sdn] Optimal transfer size 524288 bytes
[   61.541544] [     T85] sd 10:0:0:11: [sdo] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.543209] [     T85] sd 10:0:0:11: [sdo] Write Protect is off
[   61.545292] [     T85] sd 10:0:0:11: [sdo] Mode Sense: 73 00 10 08
[   61.545453] [     T85] sd 10:0:0:11: [sdo] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.547869] [     T85] sd 10:0:0:11: [sdo] permanent stream count = 5
[   61.550065] [     T85] sd 10:0:0:11: [sdo] Preferred minimum I/O size 512 bytes
[   61.551491] [     T85] sd 10:0:0:11: [sdo] Optimal transfer size 524288 bytes
[   61.560843] [    T998] sd 10:0:0:11: Attached scsi generic sg14 type 0
[   61.575647] [    T998] scsi 10:0:0:12: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.581203] [    T998] scsi 10:0:0:12: Power-on or device reset occurred
[   61.659971] [     T89] sd 10:0:0:10: [sdn] Attached SCSI disk
[   61.703691] [    T998] sd 10:0:0:12: Attached scsi generic sg15 type 0
[   61.714468] [     T85] sd 10:0:0:11: [sdo] Attached SCSI disk
[   61.752593] [    T998] scsi 10:0:0:13: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.761908] [    T998] scsi 10:0:0:13: Power-on or device reset occurred
[   61.770075] [     T89] sd 10:0:0:12: [sdp] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.771727] [     T89] sd 10:0:0:12: [sdp] Write Protect is off
[   61.773108] [     T89] sd 10:0:0:12: [sdp] Mode Sense: 73 00 10 08
[   61.773266] [     T89] sd 10:0:0:12: [sdp] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.775657] [     T89] sd 10:0:0:12: [sdp] permanent stream count = 5
[   61.778651] [     T89] sd 10:0:0:12: [sdp] Preferred minimum I/O size 512 bytes
[   61.781598] [     T89] sd 10:0:0:12: [sdp] Optimal transfer size 524288 bytes
[   61.801054] [     T85] sd 10:0:0:13: [sdq] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.802968] [     T85] sd 10:0:0:13: [sdq] Write Protect is off
[   61.804603] [     T85] sd 10:0:0:13: [sdq] Mode Sense: 73 00 10 08
[   61.804798] [     T85] sd 10:0:0:13: [sdq] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.809291] [     T85] sd 10:0:0:13: [sdq] permanent stream count = 5
[   61.812234] [     T85] sd 10:0:0:13: [sdq] Preferred minimum I/O size 512 bytes
[   61.814067] [     T85] sd 10:0:0:13: [sdq] Optimal transfer size 524288 bytes
[   61.856311] [    T998] sd 10:0:0:13: Attached scsi generic sg16 type 0
[   61.872980] [    T998] scsi 10:0:0:14: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.880018] [    T998] scsi 10:0:0:14: Power-on or device reset occurred
[   61.898152] [     T12] sd 10:0:0:14: [sdr] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   61.901297] [     T12] sd 10:0:0:14: [sdr] Write Protect is off
[   61.904599] [     T12] sd 10:0:0:14: [sdr] Mode Sense: 73 00 10 08
[   61.904758] [     T12] sd 10:0:0:14: [sdr] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   61.907952] [     T12] sd 10:0:0:14: [sdr] permanent stream count = 5
[   61.909473] [     T12] sd 10:0:0:14: [sdr] Preferred minimum I/O size 512 bytes
[   61.911556] [     T12] sd 10:0:0:14: [sdr] Optimal transfer size 524288 bytes
[   61.921187] [     T89] sd 10:0:0:12: [sdp] Attached SCSI disk
[   61.947703] [    T998] sd 10:0:0:14: Attached scsi generic sg17 type 0
[   61.956937] [    T998] scsi 10:0:0:15: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   61.964139] [    T998] scsi 10:0:0:15: Power-on or device reset occurred
[   61.966101] [     T85] sd 10:0:0:13: [sdq] Attached SCSI disk
[   62.054834] [    T998] sd 10:0:0:15: Attached scsi generic sg18 type 0
[   62.063562] [    T998] scsi 10:0:0:16: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   62.069436] [    T998] scsi 10:0:0:16: Power-on or device reset occurred
[   62.070705] [     T89] sd 10:0:0:15: [sds] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   62.073325] [     T89] sd 10:0:0:15: [sds] Write Protect is off
[   62.074520] [     T89] sd 10:0:0:15: [sds] Mode Sense: 73 00 10 08
[   62.074682] [     T89] sd 10:0:0:15: [sds] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   62.078365] [     T85] sd 10:0:0:16: [sdt] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   62.079508] [     T89] sd 10:0:0:15: [sds] permanent stream count = 5
[   62.080108] [     T85] sd 10:0:0:16: [sdt] Write Protect is off
[   62.080978] [     T89] sd 10:0:0:15: [sds] Preferred minimum I/O size 512 bytes
[   62.082994] [     T85] sd 10:0:0:16: [sdt] Mode Sense: 73 00 10 08
[   62.083665] [     T89] sd 10:0:0:15: [sds] Optimal transfer size 524288 bytes
[   62.084433] [    T998] sd 10:0:0:16: Attached scsi generic sg19 type 0
[   62.086905] [     T85] sd 10:0:0:16: [sdt] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   62.090249] [     T85] sd 10:0:0:16: [sdt] permanent stream count = 5
[   62.091796] [     T85] sd 10:0:0:16: [sdt] Preferred minimum I/O size 512 bytes
[   62.095042] [    T998] scsi 10:0:0:17: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   62.096731] [     T85] sd 10:0:0:16: [sdt] Optimal transfer size 524288 bytes
[   62.099216] [     T12] sd 10:0:0:14: [sdr] Attached SCSI disk
[   62.102505] [    T998] scsi 10:0:0:17: Power-on or device reset occurred
[   62.130600] [     T89] sd 10:0:0:15: [sds] Attached SCSI disk
[   62.152860] [     T57] sd 10:0:0:17: [sdu] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   62.154661] [     T57] sd 10:0:0:17: [sdu] Write Protect is off
[   62.156840] [     T57] sd 10:0:0:17: [sdu] Mode Sense: 73 00 10 08
[   62.156999] [     T57] sd 10:0:0:17: [sdu] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   62.158980] [     T57] sd 10:0:0:17: [sdu] permanent stream count = 5
[   62.160461] [     T57] sd 10:0:0:17: [sdu] Preferred minimum I/O size 512 bytes
[   62.161941] [     T57] sd 10:0:0:17: [sdu] Optimal transfer size 524288 bytes
[   62.197490] [    T998] sd 10:0:0:17: Attached scsi generic sg20 type 0
[   62.202924] [     T85] sd 10:0:0:16: [sdt] Attached SCSI disk
[   62.246749] [    T998] scsi 10:0:0:18: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   62.253160] [    T998] scsi 10:0:0:18: Power-on or device reset occurred
[   62.362859] [     T85] sd 10:0:0:18: [sdv] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   62.364530] [     T85] sd 10:0:0:18: [sdv] Write Protect is off
[   62.369860] [     T85] sd 10:0:0:18: [sdv] Mode Sense: 73 00 10 08
[   62.370019] [     T85] sd 10:0:0:18: [sdv] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   62.372485] [     T85] sd 10:0:0:18: [sdv] permanent stream count = 5
[   62.375392] [     T85] sd 10:0:0:18: [sdv] Preferred minimum I/O size 512 bytes
[   62.377326] [     T85] sd 10:0:0:18: [sdv] Optimal transfer size 524288 bytes
[   62.386677] [    T998] sd 10:0:0:18: Attached scsi generic sg21 type 0
[   62.390025] [     T57] sd 10:0:0:17: [sdu] Attached SCSI disk
[   62.395147] [    T998] scsi 10:0:0:19: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   62.400566] [    T998] scsi 10:0:0:19: Power-on or device reset occurred
[   62.492252] [    T998] sd 10:0:0:19: Attached scsi generic sg22 type 0
[   62.504374] [     T89] sd 10:0:0:19: [sdw] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   62.506027] [     T89] sd 10:0:0:19: [sdw] Write Protect is off
[   62.507260] [     T89] sd 10:0:0:19: [sdw] Mode Sense: 73 00 10 08
[   62.507422] [     T89] sd 10:0:0:19: [sdw] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   62.509393] [     T89] sd 10:0:0:19: [sdw] permanent stream count = 5
[   62.512301] [     T89] sd 10:0:0:19: [sdw] Preferred minimum I/O size 512 bytes
[   62.513697] [     T89] sd 10:0:0:19: [sdw] Optimal transfer size 524288 bytes
[   62.541424] [    T998] scsi 10:0:0:20: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
[   62.552224] [    T998] scsi 10:0:0:20: Power-on or device reset occurred
[   62.599822] [     T85] sd 10:0:0:18: [sdv] Attached SCSI disk
[   62.609329] [     T57] sd 10:0:0:20: [sdx] 268435456 512-byte logical blocks: (137 GB/128 GiB)
[   62.613381] [     T57] sd 10:0:0:20: [sdx] Write Protect is off
[   62.618693] [     T57] sd 10:0:0:20: [sdx] Mode Sense: 73 00 10 08
[   62.618850] [     T57] sd 10:0:0:20: [sdx] Write cache: enabled, read cache: enabled, supports DPO and FUA
[   62.621631] [     T57] sd 10:0:0:20: [sdx] permanent stream count = 5
[   62.623343] [     T57] sd 10:0:0:20: [sdx] Preferred minimum I/O size 512 bytes
[   62.624997] [     T57] sd 10:0:0:20: [sdx] Optimal transfer size 524288 bytes
[   62.628524] [    T998] sd 10:0:0:20: Attached scsi generic sg23 type 0
[   62.643270] [     T89] sd 10:0:0:19: [sdw] Attached SCSI disk
[   62.726714] [     T57] sd 10:0:0:20: [sdx] Attached SCSI disk
[   71.628857] [    T958] sd 10:0:0:0: [sdd] Synchronizing SCSI cache
[   71.725933] [   T1258] =============================
[   71.727013] [   T1258] WARNING: suspicious RCU usage
[   71.728048] [   T1258] 7.2.0-rc5+ #448 Not tainted
[   71.729043] [   T1258] -----------------------------
[   71.730053] [   T1258] block/blk-cgroup.h:273 blkg_lookup_any() requires an RCU read lock!
[   71.731460] [   T1258]
                           other info that might help us debug this:
[   71.734042] [   T1258]
                           rcu_scheduler_active = 2, debug_locks = 1
[   71.735857] [   T1258] 1 lock held by fio/1258:
[   71.736805] [   T1258]  #0: ffff88810a4bb6c8 (&q->queue_lock){..-.}-{3:3}, at: bio_blkg+0x131/0xed0
[   71.738307] [   T1258]
                           stack backtrace:
[   71.739882] [   T1258] CPU: 0 UID: 0 PID: 1258 Comm: fio Not tainted 7.2.0-rc5+ #448 PREEMPT(full)
[   71.739886] [   T1258] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-10.fc44 06/10/2025
[   71.739890] [   T1258] Call Trace:
[   71.739892] [   T1258]  <TASK>
Quoted 8 lines
[   71.739894] [   T1258]  dump_stack_lvl+0x6a/0x90
[   71.739900] [   T1258]  lockdep_rcu_suspicious.cold+0x3a/0x7d
[   71.739906] [   T1258]  blkg_lookup_any+0x3ad/0x5d0
[   71.739910] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.739915] [   T1258]  ? bio_blkg+0x634/0xed0
[   71.739917] [   T1258]  ? lock_release+0x1b5/0x340
[   71.739922] [   T1258]  bio_blkg+0x681/0xed0
[   71.739930] [   T1258]  bfq_insert_requests+0x17cc/0x8f90

Thanks for the test!

This is not a real problem, in this path spin_lock is held so rcu lock is not necessary. I'll add additional rcu lock in this path, because the spin_lock will be removed in the future.

Quoted 130 lines
[   71.739937] [   T1258]  ? __create_object+0x4e/0xe0
[   71.739941] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.739945] [   T1258]  ? __create_object+0x78/0xe0
[   71.739947] [   T1258]  ? lock_release+0x1b5/0x340
[   71.739952] [   T1258]  ? _raw_spin_unlock_irqrestore+0x35/0x60
[   71.739956] [   T1258]  ? __pfx_bfq_insert_requests+0x10/0x10
[   71.739959] [   T1258]  ? rcu_is_watching+0x11/0xb0
[   71.739963] [   T1258]  ? kmem_cache_alloc_noprof+0x4bf/0x6d0
[   71.739967] [   T1258]  ? radix_tree_node_alloc.constprop.0+0x19e/0x3a0
[   71.739973] [   T1258]  ? radix_tree_node_alloc.constprop.0+0x19e/0x3a0
[   71.739978] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.739982] [   T1258]  ? ioc_find_get_icq+0x585/0xab0
[   71.739985] [   T1258]  ? lock_release+0x1b5/0x340
[   71.739987] [   T1258]  ? trace_hardirqs_on+0x14/0x190
[   71.739991] [   T1258]  ? ioc_find_get_icq+0x594/0xab0
[   71.739997] [   T1258]  ? bdev_count_inflight_rw.part.0+0x17f/0x320
[   71.740005] [   T1258]  ? bdev_count_inflight+0x67/0xa0
[   71.740008] [   T1258]  ? __pfx_bdev_count_inflight+0x10/0x10
[   71.740012] [   T1258]  ? ktime_get+0x27/0x210
[   71.740016] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.740021] [   T1258]  blk_mq_insert_request+0x248/0xbe0
[   71.740025] [   T1258]  ? __pfx_blk_mq_insert_request+0x10/0x10
[   71.740027] [   T1258]  ? kvm_clock_get_cycles+0x14/0x30
[   71.740036] [   T1258]  blk_mq_submit_bio+0xf25/0x2a00
[   71.740040] [   T1258]  ? bio_associate_blkcg_from_css+0x14b/0x670
[   71.740044] [   T1258]  ? __pfx_blk_mq_submit_bio+0x10/0x10
[   71.740047] [   T1258]  ? iov_iter_extract_bvecs+0x50f/0xb30
[   71.740054] [   T1258]  ? __pfx_blk_cgroup_bio_start+0x10/0x10
[   71.740060] [   T1258]  submit_bio_noacct_nocheck+0x41d/0xb00
[   71.740066] [   T1258]  ? __pfx_submit_bio_noacct_nocheck+0x10/0x10
[   71.740071] [   T1258]  ? submit_bio_noacct+0x80c/0x2070
[   71.740078] [   T1258]  blkdev_direct_IO+0x949/0x1f90
[   71.740080] [   T1258]  ? lock_acquire+0x199/0x320
[   71.740083] [   T1258]  ? is_bpf_text_address+0x1d/0xf0
[   71.740086] [   T1258]  ? lock_acquire+0x1a9/0x320
[   71.740088] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.740092] [   T1258]  ? is_bpf_text_address+0x60/0xf0
[   71.740094] [   T1258]  ? lock_release+0x1b5/0x340
[   71.740099] [   T1258]  ? __pfx_blkdev_direct_IO+0x10/0x10
[   71.740102] [   T1258]  ? __kernel_text_address+0xe/0x30
[   71.740105] [   T1258]  ? __pfx_stack_trace_consume_entry+0x10/0x10
[   71.740108] [   T1258]  ? unwind_get_return_address+0x67/0xd0
[   71.740111] [   T1258]  ? arch_stack_walk+0xef/0x140
[   71.740116] [   T1258]  ? selinux_file_permission+0x3c0/0x530
[   71.740122] [   T1258]  blkdev_read_iter+0x223/0x440
[   71.740128] [   T1258]  aio_read+0x2e8/0x5b0
[   71.740133] [   T1258]  ? __pfx_aio_read+0x10/0x10
[   71.740148] [   T1258]  ? __pfx___might_resched+0x10/0x10
[   71.740151] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.740155] [   T1258]  ? __might_fault+0x97/0x140
[   71.740160] [   T1258]  ? io_submit_one+0x440/0x1a70
[   71.740162] [   T1258]  io_submit_one+0x440/0x1a70
[   71.740171] [   T1258]  ? __pfx_io_submit_one+0x10/0x10
[   71.740173] [   T1258]  ? rcu_is_watching+0x11/0xb0
[   71.740182] [   T1258]  ? __pfx___might_resched+0x10/0x10
[   71.740184] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.740191] [   T1258]  ? __x64_sys_io_submit+0x193/0x2f0
[   71.740194] [   T1258]  __x64_sys_io_submit+0x193/0x2f0
[   71.740198] [   T1258]  ? __pfx___x64_sys_io_submit+0x10/0x10
[   71.740203] [   T1258]  ? lock_release+0x1b5/0x340
[   71.740211] [   T1258]  do_syscall_64+0xdf/0x790
[   71.740218] [   T1258]  ? __lock_acquire+0x3d2/0x2440
[   71.740222] [   T1258]  ? __pfx___css_rstat_updated+0x10/0x10
[   71.740228] [   T1258]  ? lock_acquire+0x199/0x320
[   71.740230] [   T1258]  ? count_memcg_events_mm.constprop.0+0x22/0x130
[   71.740233] [   T1258]  ? rcu_is_watching+0x11/0xb0
[   71.740236] [   T1258]  ? count_memcg_events+0x107/0x4c0
[   71.740238] [   T1258]  ? find_held_lock+0x2b/0x80
[   71.740242] [   T1258]  ? rcu_is_watching+0x11/0xb0
[   71.740245] [   T1258]  ? __up_read+0x351/0x9c0
[   71.740249] [   T1258]  ? __pfx___up_read+0x10/0x10
[   71.740252] [   T1258]  ? do_user_addr_fault+0x28c/0xaf0
[   71.740255] [   T1258]  ? lock_release+0x1b5/0x340
[   71.740260] [   T1258]  ? rcu_is_watching+0x11/0xb0
[   71.740263] [   T1258]  ? trace_hardirqs_on+0x14/0x190
[   71.740265] [   T1258]  ? preempt_count_add+0x7f/0x190
[   71.740267] [   T1258]  ? do_syscall_64+0x5d/0x790
[   71.740270] [   T1258]  ? do_syscall_64+0x8d/0x790
[   71.740272] [   T1258]  ? irqentry_exit+0xfc/0x810
[   71.740277] [   T1258]  entry_SYSCALL_64_after_hwframe+0x76/0x7e
[   71.740280] [   T1258] RIP: 0033:0x7f40f240c0cd
[   71.740283] [   T1258] Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 03 4d 0f 00 f7 d8 64 89 01 48
[   71.740285] [   T1258] RSP: 002b:00007fff410d1b08 EFLAGS: 00000246 ORIG_RAX: 00000000000000d1
[   71.740290] [   T1258] RAX: ffffffffffffffda RBX: 00007f40f2316718 RCX: 00007f40f240c0cd
[   71.740292] [   T1258] RDX: 000000001f5f9750 RSI: 0000000000000001 RDI: 00007f40e3fdf000
[   71.740293] [   T1258] RBP: 00007fff410d1b40 R08: 000000001f7094e0 R09: 000000001f709400
[   71.740294] [   T1258] R10: 000000001f709400 R11: 0000000000000246 R12: 00007f40e3fdf000
[   71.740296] [   T1258] R13: 0000000000000000 R14: 000000001f5f9750 R15: 0000000000000001
[   71.740305] [   T1258]  </TASK>
[   73.210606] [    T958] sd 10:0:0:1: [sde] Synchronizing SCSI cache
[   73.251578] [    T296] device offline error, dev sdn, sector 189403096 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256114] [    T296] device offline error, dev sdn, sector 199421272 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256143] [    T296] device offline error, dev sdn, sector 203643552 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256162] [    T296] device offline error, dev sdn, sector 207427136 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256201] [    T296] device offline error, dev sdn, sector 214836224 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256219] [    T296] device offline error, dev sdn, sector 235862656 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256237] [    T296] device offline error, dev sdn, sector 236401976 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256272] [    T296] device offline error, dev sdn, sector 238514280 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256290] [    T296] device offline error, dev sdn, sector 245902744 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   73.256308] [    T296] device offline error, dev sdn, sector 246183280 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   74.011940] [    T958] sd 10:0:0:10: [sdn] Synchronizing SCSI cache
[   74.448759] [    T958] sd 10:0:0:11: [sdo] Synchronizing SCSI cache
[   74.839748] [    T958] sd 10:0:0:12: [sdp] Synchronizing SCSI cache
[   75.265115] [    T958] sd 10:0:0:13: [sdq] Synchronizing SCSI cache
[   75.660906] [    T958] sd 10:0:0:14: [sdr] Synchronizing SCSI cache
[   76.010466] [    T958] sd 10:0:0:15: [sds] Synchronizing SCSI cache
[   76.426481] [    T958] sd 10:0:0:16: [sdt] Synchronizing SCSI cache
[   76.871466] [    T958] sd 10:0:0:17: [sdu] Synchronizing SCSI cache
[   77.286379] [    T958] sd 10:0:0:18: [sdv] Synchronizing SCSI cache
[   77.844417] [    T958] sd 10:0:0:19: [sdw] Synchronizing SCSI cache
[   78.325753] [    T958] sd 10:0:0:2: [sdf] Synchronizing SCSI cache
[   78.331587] [   T1336] blk_print_req_error: 225 callbacks suppressed
[   78.331594] [   T1336] device offline error, dev sdx, sector 129278536 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   78.334828] [   T1336] device offline error, dev sdx, sector 23920864 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   78.687509] [    T958] sd 10:0:0:20: [sdx] Synchronizing SCSI cache
[   78.695490] [    T332] device offline error, dev sdg, sector 200011456 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   78.697842] [    T332] device offline error, dev sdg, sector 80898080 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   78.700331] [    T332] device offline error, dev sdg, sector 31089776 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   78.701066] [    T107] device offline error, dev sdg, sector 107919016 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   79.057557] [    T958] sd 10:0:0:3: [sdg] Synchronizing SCSI cache
[   79.506572] [    T958] sd 10:0:0:4: [sdh] Synchronizing SCSI cache
[   79.516857] [    T106] device offline error, dev sdi, sector 118581624 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   79.517079] [    T332] device offline error, dev sdi, sector 88640592 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   79.518274] [    T106] device offline error, dev sdi, sector 124905824 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   79.519554] [    T332] device offline error, dev sdi, sector 102957264 op 0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
[   80.013799] [    T958] sd 10:0:0:5: [sdi] Synchronizing SCSI cache
[   80.364040] [    T958] sd 10:0:0:6: [sdj] Synchronizing SCSI cache
[   80.737957] [    T958] sd 10:0:0:7: [sdk] Synchronizing SCSI cache
[   81.150826] [    T958] sd 10:0:0:8: [sdl] Synchronizing SCSI cache
[   81.468618] [    T958] sd 10:0:0:9: [sdm] Synchronizing SCSI cache
Signature · 2 lines
Thanks,
Kuai
Reviewed-by on v3 1/3
#3 lore raw

Re: [RFC PATCH v3 1/3] blk-cgroup: use a request_queue rhashtable for blkg lookup

In reply to Yu Kuai
Quoted 21 lines · Yu Kuai

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.

Quoted 3 lines

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.

Reviewed-by on v3 2/3
#6 lore raw

Re: [RFC PATCH v3 2/3] blk-cgroup: store blkcg in bio instead of blkg

In reply to Yu Kuai
Quoted 15 lines · Yu Kuai

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.

Quoted 4 lines

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.

Reviewed-by on v3 3/3
#9 lore raw

Re: [RFC PATCH v3 3/3] blk-cgroup: move async bio punt state to blkcg

In reply to Yu Kuai
Quoted 11 lines · Yu Kuai

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.

Quoted 3 lines

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