summaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorDennis Zhou <dennis@kernel.org>2018-12-05 12:10:36 -0500
committerJens Axboe <axboe@kernel.dk>2018-12-08 00:26:37 -0500
commitfc5a828bfad628c1092194f2814604943561c52d (patch)
treecb81a0b887a0225c5cdbc925127c533e60be4f99 /block
parentdb6638d7d177a8bc74c9e539e2e0d7d061c767b1 (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. 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 'block')
-rw-r--r--block/bio.c66
1 files changed, 28 insertions, 38 deletions
diff --git a/block/bio.c b/block/bio.c
index 2b6bc7b805ec..ce1e512dca5a 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1966,8 +1966,6 @@ EXPORT_SYMBOL(bioset_init_from_src);
1966void bio_disassociate_blkg(struct bio *bio) 1966void bio_disassociate_blkg(struct bio *bio)
1967{ 1967{
1968 if (bio->bi_blkg) { 1968 if (bio->bi_blkg) {
1969 /* a ref is always taken on css */
1970 css_put(&bio_blkcg(bio)->css);
1971 blkg_put(bio->bi_blkg); 1969 blkg_put(bio->bi_blkg);
1972 bio->bi_blkg = NULL; 1970 bio->bi_blkg = NULL;
1973 } 1971 }
@@ -1995,33 +1993,31 @@ static void __bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg)
1995 bio->bi_blkg = blkg_try_get_closest(blkg); 1993 bio->bi_blkg = blkg_try_get_closest(blkg);
1996} 1994}
1997 1995
1998static void __bio_associate_blkg_from_css(struct bio *bio,
1999 struct cgroup_subsys_state *css)
2000{
2001 struct blkcg_gq *blkg;
2002
2003 rcu_read_lock();
2004
2005 blkg = blkg_lookup_create(css_to_blkcg(css), bio->bi_disk->queue);
2006 __bio_associate_blkg(bio, blkg);
2007
2008 rcu_read_unlock();
2009}
2010
2011/** 1996/**
2012 * bio_associate_blkg_from_css - associate a bio with a specified css 1997 * bio_associate_blkg_from_css - associate a bio with a specified css
2013 * @bio: target bio 1998 * @bio: target bio
2014 * @css: target css 1999 * @css: target css
2015 * 2000 *
2016 * Associate @bio with the blkg found by combining the css's blkg and the 2001 * Associate @bio with the blkg found by combining the css's blkg and the
2017 * request_queue of the @bio. This takes a reference on the css that will 2002 * request_queue of the @bio. This falls back to the queue's root_blkg if
2018 * be put upon freeing of @bio. 2003 * the association fails with the css.
2019 */ 2004 */
2020void bio_associate_blkg_from_css(struct bio *bio, 2005void bio_associate_blkg_from_css(struct bio *bio,
2021 struct cgroup_subsys_state *css) 2006 struct cgroup_subsys_state *css)
2022{ 2007{
2023 css_get(css); 2008 struct request_queue *q = bio->bi_disk->queue;
2024 __bio_associate_blkg_from_css(bio, css); 2009 struct blkcg_gq *blkg;
2010
2011 rcu_read_lock();
2012
2013 if (!css || !css->parent)
2014 blkg = q->root_blkg;
2015 else
2016 blkg = blkg_lookup_create(css_to_blkcg(css), q);
2017
2018 __bio_associate_blkg(bio, blkg);
2019
2020 rcu_read_unlock();
2025} 2021}
2026EXPORT_SYMBOL_GPL(bio_associate_blkg_from_css); 2022EXPORT_SYMBOL_GPL(bio_associate_blkg_from_css);
2027 2023
@@ -2032,8 +2028,8 @@ EXPORT_SYMBOL_GPL(bio_associate_blkg_from_css);
2032 * @page: the page to lookup the blkcg from 2028 * @page: the page to lookup the blkcg from
2033 * 2029 *
2034 * Associate @bio with the blkg from @page's owning memcg and the respective 2030 * Associate @bio with the blkg from @page's owning memcg and the respective
2035 * request_queue. This works like every other associate function wrt 2031 * request_queue. If cgroup_e_css returns %NULL, fall back to the queue's
2036 * references. 2032 * root_blkg.
2037 */ 2033 */
2038void bio_associate_blkg_from_page(struct bio *bio, struct page *page) 2034void bio_associate_blkg_from_page(struct bio *bio, struct page *page)
2039{ 2035{
@@ -2042,8 +2038,12 @@ void bio_associate_blkg_from_page(struct bio *bio, struct page *page)
2042 if (!page->mem_cgroup) 2038 if (!page->mem_cgroup)
2043 return; 2039 return;
2044 2040
2045 css = cgroup_get_e_css(page->mem_cgroup->css.cgroup, &io_cgrp_subsys); 2041 rcu_read_lock();
2046 __bio_associate_blkg_from_css(bio, css); 2042
2043 css = cgroup_e_css(page->mem_cgroup->css.cgroup, &io_cgrp_subsys);
2044 bio_associate_blkg_from_css(bio, css);
2045
2046 rcu_read_unlock();
2047} 2047}
2048#endif /* CONFIG_MEMCG */ 2048#endif /* CONFIG_MEMCG */
2049 2049
@@ -2058,24 +2058,16 @@ void bio_associate_blkg_from_page(struct bio *bio, struct page *page)
2058 */ 2058 */
2059void bio_associate_blkg(struct bio *bio) 2059void bio_associate_blkg(struct bio *bio)
2060{ 2060{
2061 struct request_queue *q = bio->bi_disk->queue; 2061 struct cgroup_subsys_state *css;
2062 struct blkcg *blkcg;
2063 struct blkcg_gq *blkg;
2064 2062
2065 rcu_read_lock(); 2063 rcu_read_lock();
2066 2064
2067 if (bio->bi_blkg) 2065 if (bio->bi_blkg)
2068 blkcg = bio->bi_blkg->blkcg; 2066 css = &bio_blkcg(bio)->css;
2069 else 2067 else
2070 blkcg = css_to_blkcg(blkcg_get_css()); 2068 css = blkcg_css();
2071 2069
2072 if (!blkcg->css.parent) { 2070 bio_associate_blkg_from_css(bio, css);
2073 __bio_associate_blkg(bio, q->root_blkg);
2074 } else {
2075 blkg = blkg_lookup_create(blkcg, q);
2076
2077 __bio_associate_blkg(bio, blkg);
2078 }
2079 2071
2080 rcu_read_unlock(); 2072 rcu_read_unlock();
2081} 2073}
@@ -2097,10 +2089,8 @@ void bio_disassociate_task(struct bio *bio)
2097 */ 2089 */
2098void bio_clone_blkg_association(struct bio *dst, struct bio *src) 2090void bio_clone_blkg_association(struct bio *dst, struct bio *src)
2099{ 2091{
2100 if (src->bi_blkg) { 2092 if (src->bi_blkg)
2101 css_get(&bio_blkcg(src)->css);
2102 __bio_associate_blkg(dst, src->bi_blkg); 2093 __bio_associate_blkg(dst, src->bi_blkg);
2103 }
2104} 2094}
2105EXPORT_SYMBOL_GPL(bio_clone_blkg_association); 2095EXPORT_SYMBOL_GPL(bio_clone_blkg_association);
2106#endif /* CONFIG_BLK_CGROUP */ 2096#endif /* CONFIG_BLK_CGROUP */