summaryrefslogtreecommitdiffstats
path: root/include/linux/blk-cgroup.h
diff options
context:
space:
mode:
authorDennis Zhou <dennis@kernel.org>2018-12-05 12:10:28 -0500
committerJens Axboe <axboe@kernel.dk>2018-12-07 22:26:36 -0700
commitbeea9da07d8a6228a7e4a31a83f9478d513bf03f (patch)
tree263661b03b835c4715fbeb97c2bdbd0331233001 /include/linux/blk-cgroup.h
parentb978962ad4f7f9c06e5aa07b2a9b22f6d600456c (diff)
downloadtalos-op-linux-beea9da07d8a6228a7e4a31a83f9478d513bf03f.tar.gz
talos-op-linux-beea9da07d8a6228a7e4a31a83f9478d513bf03f.zip
blkcg: convert blkg_lookup_create() to find closest blkg
There are several scenarios where blkg_lookup_create() can fail such as the blkcg dying, request_queue is dying, or simply being OOM. Most handle this by simply falling back to the q->root_blkg and calling it a day. This patch implements the notion of closest blkg. During blkg_lookup_create(), if it fails to create, return the closest blkg found or the q->root_blkg. blkg_try_get_closest() is introduced and used during association so a bio is always attached to a blkg. Signed-off-by: Dennis Zhou <dennis@kernel.org> Acked-by: Tejun Heo <tj@kernel.org> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'include/linux/blk-cgroup.h')
-rw-r--r--include/linux/blk-cgroup.h24
1 files changed, 15 insertions, 9 deletions
diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h
index b3b1a8187d23..c08e96e521ed 100644
--- a/include/linux/blk-cgroup.h
+++ b/include/linux/blk-cgroup.h
@@ -545,6 +545,20 @@ static inline struct blkcg_gq *blkg_try_get(struct blkcg_gq *blkg)
return NULL;
}
+/**
+ * blkg_try_get_closest - try and get a blkg ref on the closet blkg
+ * @blkg: blkg to get
+ *
+ * This walks up the blkg tree to find the closest non-dying blkg and returns
+ * the blkg that it did association with as it may not be the passed in blkg.
+ */
+static inline struct blkcg_gq *blkg_try_get_closest(struct blkcg_gq *blkg)
+{
+ while (!atomic_inc_not_zero(&blkg->refcnt))
+ blkg = blkg->parent;
+
+ return blkg;
+}
void __blkg_release_rcu(struct rcu_head *rcu);
@@ -797,15 +811,7 @@ static inline bool blkcg_bio_issue_check(struct request_queue *q,
/* associate blkcg if bio hasn't attached one */
bio_associate_blkcg(bio, NULL);
blkcg = bio_blkcg(bio);
-
- blkg = blkg_lookup(blkcg, q);
- if (unlikely(!blkg)) {
- spin_lock_irq(&q->queue_lock);
- blkg = __blkg_lookup_create(blkcg, q);
- if (IS_ERR(blkg))
- blkg = NULL;
- spin_unlock_irq(&q->queue_lock);
- }
+ blkg = blkg_lookup_create(blkcg, q);
throtl = blk_throtl_bio(q, blkg, bio);
OpenPOWER on IntegriCloud