Skip to content

Commit fd42df3

Browse files
dennisszhouaxboe
authored andcommitted
blkcg: associate writeback bios with a blkg
One of the goals of this series is to remove a separate reference to the css of the bio. This can and should be accessed via bio_blkcg(). In this patch, wbc_init_bio() now requires a bio to have a device associated with it. Signed-off-by: Dennis Zhou <dennis@kernel.org> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 6a7f6d8 commit fd42df3

6 files changed

Lines changed: 37 additions & 11 deletions

File tree

‎Documentation/admin-guide/cgroup-v2.rst‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,8 +1879,10 @@ following two functions.
18791879

18801880
wbc_init_bio(@wbc, @bio)
18811881
Should be called for each bio carrying writeback data and
1882-
associates the bio with the inode's owner cgroup. Can be
1883-
called anytime between bio allocation and submission.
1882+
associates the bio with the inode's owner cgroup and the
1883+
corresponding request queue. This must be called after
1884+
a queue (device) has been associated with the bio and
1885+
before submission.
18841886

18851887
wbc_account_io(@wbc, @page, @bytes)
18861888
Should be called for each data segment being written out.
@@ -1899,7 +1901,7 @@ the configuration, the bio may be executed at a lower priority and if
18991901
the writeback session is holding shared resources, e.g. a journal
19001902
entry, may lead to priority inversion. There is no one easy solution
19011903
for the problem. Filesystems can try to work around specific problem
1902-
cases by skipping wbc_init_bio() or using bio_associate_blkcg()
1904+
cases by skipping wbc_init_bio() and using bio_associate_blkg()
19031905
directly.
19041906

19051907

‎block/bio.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,24 @@ static void __bio_associate_blkg_from_css(struct bio *bio,
20342034
rcu_read_unlock();
20352035
}
20362036

2037+
/**
2038+
* bio_associate_blkg_from_css - associate a bio with a specified css
2039+
* @bio: target bio
2040+
* @css: target css
2041+
*
2042+
* Associate @bio with the blkg found by combining the css's blkg and the
2043+
* request_queue of the @bio. This takes a reference on the css that will
2044+
* be put upon freeing of @bio.
2045+
*/
2046+
void bio_associate_blkg_from_css(struct bio *bio,
2047+
struct cgroup_subsys_state *css)
2048+
{
2049+
css_get(css);
2050+
bio->bi_css = css;
2051+
__bio_associate_blkg_from_css(bio, css);
2052+
}
2053+
EXPORT_SYMBOL_GPL(bio_associate_blkg_from_css);
2054+
20372055
#ifdef CONFIG_MEMCG
20382056
/**
20392057
* bio_associate_blkg_from_page - associate a bio with the page's blkg

‎fs/buffer.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,11 +3060,6 @@ static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
30603060
*/
30613061
bio = bio_alloc(GFP_NOIO, 1);
30623062

3063-
if (wbc) {
3064-
wbc_init_bio(wbc, bio);
3065-
wbc_account_io(wbc, bh->b_page, bh->b_size);
3066-
}
3067-
30683063
bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
30693064
bio_set_dev(bio, bh->b_bdev);
30703065
bio->bi_write_hint = write_hint;
@@ -3084,6 +3079,11 @@ static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
30843079
op_flags |= REQ_PRIO;
30853080
bio_set_op_attrs(bio, op, op_flags);
30863081

3082+
if (wbc) {
3083+
wbc_init_bio(wbc, bio);
3084+
wbc_account_io(wbc, bh->b_page, bh->b_size);
3085+
}
3086+
30873087
submit_bio(bio);
30883088
return 0;
30893089
}

‎fs/ext4/page-io.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,13 @@ static int io_submit_init_bio(struct ext4_io_submit *io,
374374
bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES);
375375
if (!bio)
376376
return -ENOMEM;
377-
wbc_init_bio(io->io_wbc, bio);
378377
bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
379378
bio_set_dev(bio, bh->b_bdev);
380379
bio->bi_end_io = ext4_end_bio;
381380
bio->bi_private = ext4_get_io_end(io->io_end);
382381
io->io_bio = bio;
383382
io->io_next_block = bh->b_blocknr;
383+
wbc_init_bio(io->io_wbc, bio);
384384
return 0;
385385
}
386386

‎include/linux/bio.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,18 @@ static inline void bio_associate_blkg_from_page(struct bio *bio,
515515
int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css);
516516
void bio_disassociate_blkg(struct bio *bio);
517517
void bio_associate_blkg(struct bio *bio);
518+
void bio_associate_blkg_from_css(struct bio *bio,
519+
struct cgroup_subsys_state *css);
518520
void bio_disassociate_task(struct bio *bio);
519521
void bio_clone_blkcg_association(struct bio *dst, struct bio *src);
520522
#else /* CONFIG_BLK_CGROUP */
521523
static inline int bio_associate_blkcg(struct bio *bio,
522524
struct cgroup_subsys_state *blkcg_css) { return 0; }
523525
static inline void bio_disassociate_blkg(struct bio *bio) { }
524526
static inline void bio_associate_blkg(struct bio *bio) { }
527+
static inline void bio_associate_blkg_from_css(struct bio *bio,
528+
struct cgroup_subsys_state *css)
529+
{ }
525530
static inline void bio_disassociate_task(struct bio *bio) { }
526531
static inline void bio_clone_blkcg_association(struct bio *dst,
527532
struct bio *src) { }

‎include/linux/writeback.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ static inline void wbc_attach_fdatawrite_inode(struct writeback_control *wbc,
246246
*
247247
* @bio is a part of the writeback in progress controlled by @wbc. Perform
248248
* writeback specific initialization. This is used to apply the cgroup
249-
* writeback context.
249+
* writeback context. Must be called after the bio has been associated with
250+
* a device.
250251
*/
251252
static inline void wbc_init_bio(struct writeback_control *wbc, struct bio *bio)
252253
{
@@ -257,7 +258,7 @@ static inline void wbc_init_bio(struct writeback_control *wbc, struct bio *bio)
257258
* regular writeback instead of writing things out itself.
258259
*/
259260
if (wbc->wb)
260-
bio_associate_blkcg(bio, wbc->wb->blkcg_css);
261+
bio_associate_blkg_from_css(bio, wbc->wb->blkcg_css);
261262
}
262263

263264
#else /* CONFIG_CGROUP_WRITEBACK */

0 commit comments

Comments
 (0)