Skip to content

Commit bdc2491

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, the wbc_init_bio call is changed such that it must be called after a queue has been associated with the bio. 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 74b7c02 commit bdc2491

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

Documentation/admin-guide/cgroup-v2.rst

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

18581858
wbc_init_bio(@wbc, @bio)
18591859
Should be called for each bio carrying writeback data and
1860-
associates the bio with the inode's owner cgroup. Can be
1861-
called anytime between bio allocation and submission.
1860+
associates the bio with the inode's owner cgroup and the
1861+
corresponding request queue. This must be called after
1862+
a queue (device) has been associated with the bio and
1863+
before submission.
18621864

18631865
wbc_account_io(@wbc, @page, @bytes)
18641866
Should be called for each data segment being written out.
@@ -1877,7 +1879,7 @@ the configuration, the bio may be executed at a lower priority and if
18771879
the writeback session is holding shared resources, e.g. a journal
18781880
entry, may lead to priority inversion. There is no one easy solution
18791881
for the problem. Filesystems can try to work around specific problem
1880-
cases by skipping wbc_init_bio() or using bio_associate_blkcg()
1882+
cases by skipping wbc_init_bio() or using bio_associate_create_blkg()
18811883
directly.
18821884

18831885

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/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)