Skip to content

Commit e2b0989

Browse files
dennisszhouaxboe
authored andcommitted
blkcg: cleanup and make blk_get_rl use blkg_lookup_create
blk_get_rl is responsible for identifying which request_list a request should be allocated to. Try get logic was added earlier, but semantically the logic was not changed. This patch makes better use of the bio already having a reference to the blkg in the hot path. The cold path uses a better fallback of blkg_lookup_create rather than just blkg_lookup and then falling back to the q->root_rl. If lookup_create fails with anything but -ENODEV, it falls back to q->root_rl. A clarifying comment is added to explain why q->root_rl is used rather than the root blkg's rl. Signed-off-by: Dennis Zhou <dennisszhou@gmail.com> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent f0fcb3e commit e2b0989

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

include/linux/blk-cgroup.h

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -586,28 +586,36 @@ static inline struct request_list *blk_get_rl(struct request_queue *q,
586586

587587
rcu_read_lock();
588588

589-
blkcg = bio_blkcg(bio);
590-
if (!blkcg)
591-
blkcg = css_to_blkcg(blkcg_css());
589+
if (bio && bio->bi_blkg) {
590+
blkcg = bio->bi_blkg->blkcg;
591+
if (blkcg == &blkcg_root)
592+
goto rl_use_root;
593+
594+
blkg_get(bio->bi_blkg);
595+
rcu_read_unlock();
596+
return &bio->bi_blkg->rl;
597+
}
592598

593-
/* bypass blkg lookup and use @q->root_rl directly for root */
599+
blkcg = css_to_blkcg(blkcg_css());
594600
if (blkcg == &blkcg_root)
595-
goto root_rl;
601+
goto rl_use_root;
596602

597-
/*
598-
* Try to use blkg->rl. blkg lookup may fail under memory pressure
599-
* or if either the blkcg or queue is going away. Fall back to
600-
* root_rl in such cases.
601-
*/
602603
blkg = blkg_lookup(blkcg, q);
603604
if (unlikely(!blkg))
604-
goto root_rl;
605+
blkg = __blkg_lookup_create(blkcg, q);
605606

606607
if (!blkg_try_get(blkg))
607-
goto root_rl;
608+
goto rl_use_root;
609+
608610
rcu_read_unlock();
609611
return &blkg->rl;
610-
root_rl:
612+
613+
/*
614+
* Each blkg has its own request_list, however, the root blkcg
615+
* uses the request_queue's root_rl. This is to avoid most
616+
* overhead for the root blkcg.
617+
*/
618+
rl_use_root:
611619
rcu_read_unlock();
612620
return &q->root_rl;
613621
}

0 commit comments

Comments
 (0)