Skip to content

Commit 74b7c02

Browse files
dennisszhouaxboe
authored andcommitted
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>
1 parent 5bf9a1f commit 74b7c02

File tree

3 files changed

+68
-28
lines changed

3 files changed

+68
-28
lines changed

block/bio.c

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,30 +1956,6 @@ EXPORT_SYMBOL(bioset_init_from_src);
19561956

19571957
#ifdef CONFIG_BLK_CGROUP
19581958

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-
19831959
/**
19841960
* bio_associate_blkcg - associate a bio with the specified blkcg
19851961
* @bio: target bio
@@ -2030,6 +2006,65 @@ int bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg)
20302006
return 0;
20312007
}
20322008

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+
20332068
/**
20342069
* bio_associate_create_blkg - associate a bio with a blkg from q
20352070
* @q: request_queue where bio is going

include/linux/bio.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,21 +533,26 @@ do { \
533533
disk_devt((bio)->bi_disk)
534534

535535
#if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP)
536-
int bio_associate_blkcg_from_page(struct bio *bio, struct page *page);
536+
int bio_associate_blkg_from_page(struct bio *bio, struct page *page);
537537
#else
538-
static inline int bio_associate_blkcg_from_page(struct bio *bio,
539-
struct page *page) { return 0; }
538+
static inline int bio_associate_blkg_from_page(struct bio *bio,
539+
struct page *page) { return 0; }
540540
#endif
541541

542542
#ifdef CONFIG_BLK_CGROUP
543543
int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css);
544544
int bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg);
545+
int bio_associate_blkg_from_css(struct bio *bio,
546+
struct cgroup_subsys_state *css);
545547
int bio_associate_create_blkg(struct request_queue *q, struct bio *bio);
546548
void bio_disassociate_task(struct bio *bio);
547549
void bio_clone_blkcg_association(struct bio *dst, struct bio *src);
548550
#else /* CONFIG_BLK_CGROUP */
549551
static inline int bio_associate_blkcg(struct bio *bio,
550552
struct cgroup_subsys_state *blkcg_css) { return 0; }
553+
static inline int bio_associate_blkg_from_css(struct bio *bio,
554+
struct cgroup_subsys_state *css)
555+
{ return 0; }
551556
static inline int bio_associate_create_blkg(struct request_queue *q,
552557
struct bio *bio) { return 0; }
553558
static inline void bio_disassociate_task(struct bio *bio) { }

mm/page_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
339339
goto out;
340340
}
341341
bio->bi_opf = REQ_OP_WRITE | REQ_SWAP | wbc_to_write_flags(wbc);
342-
bio_associate_blkcg_from_page(bio, page);
342+
bio_associate_blkg_from_page(bio, page);
343343
count_swpout_vm_event(page);
344344
set_page_writeback(page);
345345
unlock_page(page);

0 commit comments

Comments
 (0)