aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/blk-cgroup.h
diff options
context:
space:
mode:
authorDennis Zhou (Facebook) <dennisszhou@gmail.com>2018-09-11 14:41:34 -0400
committerJens Axboe <axboe@kernel.dk>2018-09-21 22:29:15 -0400
commitf0fcb3ec89f37167810e660b0595d9a6155d9807 (patch)
treedd230c9477e3b316863a589639280965efcbf429 /include/linux/blk-cgroup.h
parentc839e7a03f92bafd71fd145b470dcdc7f43f2d4c (diff)
blkcg: remove additional reference to the css
The previous patch in this series removed carrying around a pointer to the css in blkg. However, the blkg association logic still relied on taking a reference on the css to ensure we wouldn't fail in getting a reference for the blkg. Here the implicit dependency on the css is removed. The association continues to rely on the tryget logic walking up the blkg tree. This streamlines the three ways that association can happen: normal, swap, and writeback. Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Dennis Zhou <dennisszhou@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'include/linux/blk-cgroup.h')
-rw-r--r--include/linux/blk-cgroup.h52
1 files changed, 4 insertions, 48 deletions
diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h
index c41cfcc2b4d8..2951ea3541b1 100644
--- a/include/linux/blk-cgroup.h
+++ b/include/linux/blk-cgroup.h
@@ -249,47 +249,6 @@ static inline struct cgroup_subsys_state *blkcg_css(void)
249 return task_css(current, io_cgrp_id); 249 return task_css(current, io_cgrp_id);
250} 250}
251 251
252/**
253 * blkcg_get_css - find and get a reference to the css
254 *
255 * Find the css associated with either the kthread or the current task.
256 * This takes a reference on the blkcg which will need to be managed by the
257 * caller.
258 */
259static inline struct cgroup_subsys_state *blkcg_get_css(void)
260{
261 struct cgroup_subsys_state *css;
262
263 rcu_read_lock();
264
265 css = kthread_blkcg();
266 if (css) {
267 css_get(css);
268 } else {
269 /*
270 * This is a bit complicated. It is possible task_css is seeing
271 * an old css pointer here. This is caused by the current
272 * thread migrating away from this cgroup and this cgroup dying.
273 * css_tryget() will fail when trying to take a ref on a cgroup
274 * that's ref count has hit 0.
275 *
276 * Therefore, if it does fail, this means current must have
277 * been swapped away already and this is waiting for it to
278 * propagate on the polling cpu. Hence the use of cpu_relax().
279 */
280 while (true) {
281 css = task_css(current, io_cgrp_id);
282 if (likely(css_tryget(css)))
283 break;
284 cpu_relax();
285 }
286 }
287
288 rcu_read_unlock();
289
290 return css;
291}
292
293static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css) 252static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
294{ 253{
295 return css ? container_of(css, struct blkcg, css) : NULL; 254 return css ? container_of(css, struct blkcg, css) : NULL;
@@ -628,10 +587,8 @@ static inline struct request_list *blk_get_rl(struct request_queue *q,
628 rcu_read_lock(); 587 rcu_read_lock();
629 588
630 blkcg = bio_blkcg(bio); 589 blkcg = bio_blkcg(bio);
631 if (blkcg) 590 if (!blkcg)
632 css_get(&blkcg->css); 591 blkcg = css_to_blkcg(blkcg_css());
633 else
634 blkcg = css_to_blkcg(blkcg_get_css());
635 592
636 /* bypass blkg lookup and use @q->root_rl directly for root */ 593 /* bypass blkg lookup and use @q->root_rl directly for root */
637 if (blkcg == &blkcg_root) 594 if (blkcg == &blkcg_root)
@@ -646,7 +603,8 @@ static inline struct request_list *blk_get_rl(struct request_queue *q,
646 if (unlikely(!blkg)) 603 if (unlikely(!blkg))
647 goto root_rl; 604 goto root_rl;
648 605
649 blkg_get(blkg); 606 if (!blkg_try_get(blkg))
607 goto root_rl;
650 rcu_read_unlock(); 608 rcu_read_unlock();
651 return &blkg->rl; 609 return &blkg->rl;
652root_rl: 610root_rl:
@@ -663,8 +621,6 @@ root_rl:
663 */ 621 */
664static inline void blk_put_rl(struct request_list *rl) 622static inline void blk_put_rl(struct request_list *rl)
665{ 623{
666 /* an additional ref is always taken for rl */
667 css_put(&rl->blkg->blkcg->css);
668 if (rl->blkg->blkcg != &blkcg_root) 624 if (rl->blkg->blkcg != &blkcg_root)
669 blkg_put(rl->blkg); 625 blkg_put(rl->blkg);
670} 626}