diff options
author | Dennis Zhou (Facebook) <dennisszhou@gmail.com> | 2018-09-11 14:41:31 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-09-21 22:29:09 -0400 |
commit | 74b7c02a9bc124ee3df0d77880ee26db0a325516 (patch) | |
tree | 9600af0dbec0293940a7e0fdfea7e2b1f7dba7e3 /block/bio.c | |
parent | 5bf9a1f3b4efef7e463105dde8bba4d2397909c2 (diff) |
blkcg: associate a blkg for pages being evicted by swap
A prior patch in this series added blkg association to bios issued by
cgroups. There are two other paths that we want to attribute work back
to the appropriate cgroup: swap and writeback. Here we modify the way
swap tags bios to include the blkg. Writeback will be tackle in the next
patch.
Signed-off-by: Dennis Zhou <dennisszhou@gmail.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/bio.c')
-rw-r--r-- | block/bio.c | 83 |
1 files changed, 59 insertions, 24 deletions
diff --git a/block/bio.c b/block/bio.c index 80c948da061c..387480de6992 100644 --- a/block/bio.c +++ b/block/bio.c | |||
@@ -1956,30 +1956,6 @@ EXPORT_SYMBOL(bioset_init_from_src); | |||
1956 | 1956 | ||
1957 | #ifdef CONFIG_BLK_CGROUP | 1957 | #ifdef CONFIG_BLK_CGROUP |
1958 | 1958 | ||
1959 | #ifdef CONFIG_MEMCG | ||
1960 | /** | ||
1961 | * bio_associate_blkcg_from_page - associate a bio with the page's blkcg | ||
1962 | * @bio: target bio | ||
1963 | * @page: the page to lookup the blkcg from | ||
1964 | * | ||
1965 | * Associate @bio with the blkcg from @page's owning memcg. This works like | ||
1966 | * every other associate function wrt references. | ||
1967 | */ | ||
1968 | int bio_associate_blkcg_from_page(struct bio *bio, struct page *page) | ||
1969 | { | ||
1970 | struct cgroup_subsys_state *blkcg_css; | ||
1971 | |||
1972 | if (unlikely(bio->bi_css)) | ||
1973 | return -EBUSY; | ||
1974 | if (!page->mem_cgroup) | ||
1975 | return 0; | ||
1976 | blkcg_css = cgroup_get_e_css(page->mem_cgroup->css.cgroup, | ||
1977 | &io_cgrp_subsys); | ||
1978 | bio->bi_css = blkcg_css; | ||
1979 | return 0; | ||
1980 | } | ||
1981 | #endif /* CONFIG_MEMCG */ | ||
1982 | |||
1983 | /** | 1959 | /** |
1984 | * bio_associate_blkcg - associate a bio with the specified blkcg | 1960 | * bio_associate_blkcg - associate a bio with the specified blkcg |
1985 | * @bio: target bio | 1961 | * @bio: target bio |
@@ -2030,6 +2006,65 @@ int bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg) | |||
2030 | return 0; | 2006 | return 0; |
2031 | } | 2007 | } |
2032 | 2008 | ||
2009 | static int __bio_associate_blkg_from_css(struct bio *bio, | ||
2010 | struct cgroup_subsys_state *css) | ||
2011 | { | ||
2012 | struct blkcg_gq *blkg; | ||
2013 | |||
2014 | rcu_read_lock(); | ||
2015 | |||
2016 | blkg = blkg_lookup_create(css_to_blkcg(css), bio->bi_disk->queue); | ||
2017 | |||
2018 | rcu_read_unlock(); | ||
2019 | |||
2020 | return bio_associate_blkg(bio, blkg); | ||
2021 | } | ||
2022 | |||
2023 | /** | ||
2024 | * bio_associate_blkg_from_css - associate a bio with a specified css | ||
2025 | * @bio: target bio | ||
2026 | * @css: target css | ||
2027 | * | ||
2028 | * Associate @bio with the blkg found by combining the css's blkg and the | ||
2029 | * request_queue of the @bio. This takes a reference on the css that will | ||
2030 | * be put upon freeing of @bio. | ||
2031 | */ | ||
2032 | int bio_associate_blkg_from_css(struct bio *bio, | ||
2033 | struct cgroup_subsys_state *css) | ||
2034 | { | ||
2035 | css_get(css); | ||
2036 | bio->bi_css = css; | ||
2037 | return __bio_associate_blkg_from_css(bio, css); | ||
2038 | } | ||
2039 | EXPORT_SYMBOL_GPL(bio_associate_blkg_from_css); | ||
2040 | |||
2041 | #ifdef CONFIG_MEMCG | ||
2042 | /** | ||
2043 | * bio_associate_blkg_from_page - associate a bio with the page's blkg | ||
2044 | * @bio: target bio | ||
2045 | * @page: the page to lookup the blkcg from | ||
2046 | * | ||
2047 | * Associate @bio with the blkg from @page's owning memcg and the respective | ||
2048 | * request_queue. This works like every other associate function wrt | ||
2049 | * references. | ||
2050 | * | ||
2051 | * Note: this must be called after bio has an associated device. | ||
2052 | */ | ||
2053 | int bio_associate_blkg_from_page(struct bio *bio, struct page *page) | ||
2054 | { | ||
2055 | struct cgroup_subsys_state *css; | ||
2056 | |||
2057 | if (unlikely(bio->bi_css)) | ||
2058 | return -EBUSY; | ||
2059 | if (!page->mem_cgroup) | ||
2060 | return 0; | ||
2061 | css = cgroup_get_e_css(page->mem_cgroup->css.cgroup, &io_cgrp_subsys); | ||
2062 | bio->bi_css = css; | ||
2063 | |||
2064 | return __bio_associate_blkg_from_css(bio, css); | ||
2065 | } | ||
2066 | #endif /* CONFIG_MEMCG */ | ||
2067 | |||
2033 | /** | 2068 | /** |
2034 | * bio_associate_create_blkg - associate a bio with a blkg from q | 2069 | * bio_associate_create_blkg - associate a bio with a blkg from q |
2035 | * @q: request_queue where bio is going | 2070 | * @q: request_queue where bio is going |