Skip to content

Commit 0d3bd88

Browse files
htejunaxboe
authored andcommitted
swap,blkcg: issue swap io with the appropriate context
For backcharging we need to know who the page belongs to when swapping it out. We don't worry about things that do ->rw_page (zram etc) at the moment, we're only worried about pages that actually go to a block device. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Josef Bacik <jbacik@fb.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 0d1e0c7 commit 0d3bd88

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

block/bio.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,30 @@ EXPORT_SYMBOL(bioset_init_from_src);
20152015

20162016
#ifdef CONFIG_BLK_CGROUP
20172017

2018+
#ifdef CONFIG_MEMCG
2019+
/**
2020+
* bio_associate_blkcg_from_page - associate a bio with the page's blkcg
2021+
* @bio: target bio
2022+
* @page: the page to lookup the blkcg from
2023+
*
2024+
* Associate @bio with the blkcg from @page's owning memcg. This works like
2025+
* every other associate function wrt references.
2026+
*/
2027+
int bio_associate_blkcg_from_page(struct bio *bio, struct page *page)
2028+
{
2029+
struct cgroup_subsys_state *blkcg_css;
2030+
2031+
if (unlikely(bio->bi_css))
2032+
return -EBUSY;
2033+
if (!page->mem_cgroup)
2034+
return 0;
2035+
blkcg_css = cgroup_get_e_css(page->mem_cgroup->css.cgroup,
2036+
&io_cgrp_subsys);
2037+
bio->bi_css = blkcg_css;
2038+
return 0;
2039+
}
2040+
#endif /* CONFIG_MEMCG */
2041+
20182042
/**
20192043
* bio_associate_blkcg - associate a bio with the specified blkcg
20202044
* @bio: target bio

include/linux/bio.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,13 @@ do { \
553553
#define bio_dev(bio) \
554554
disk_devt((bio)->bi_disk)
555555

556+
#if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP)
557+
int bio_associate_blkcg_from_page(struct bio *bio, struct page *page);
558+
#else
559+
static inline int bio_associate_blkcg_from_page(struct bio *bio,
560+
struct page *page) { return 0; }
561+
#endif
562+
556563
#ifdef CONFIG_BLK_CGROUP
557564
int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css);
558565
int bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg);

mm/page_io.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +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);
342343
count_swpout_vm_event(page);
343344
set_page_writeback(page);
344345
unlock_page(page);

0 commit comments

Comments
 (0)