1 ext4: implement cgroup writeback support
3 From: Tejun Heo <tj@kernel.org>
5 For ordered and writeback data modes, all data IOs go through
6 ext4_io_submit. This patch adds cgroup writeback support by invoking
7 wbc_init_bio() from io_submit_init_bio() and wbc_account_io() in
8 io_submit_add_bh(). Journal data which is written by jbd2 worker is
9 left alone by this patch and will always be written out from the root
12 ext4_fill_super() is updated to set MS_CGROUPWB when data mode is
13 either ordered or writeback. In journaled data mode, most IOs become
14 synchronous through the journal and enabling cgroup writeback support
15 doesn't make much sense or difference. Journaled data mode is left
18 Lightly tested with sequential data write workload. Behaves as
21 Signed-off-by: Tejun Heo <tj@kernel.org>
22 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
24 fs/ext4/page-io.c | 2 ++
25 fs/ext4/super.c | 2 ++
26 2 files changed, 4 insertions(+)
28 diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
29 index 3f80cb2..c56ba7b 100644
30 --- a/fs/ext4/page-io.c
31 +++ b/fs/ext4/page-io.c
32 @@ -383,6 +383,7 @@ static int io_submit_init_bio(struct ext4_io_submit *io,
33 bio = bio_alloc(GFP_NOIO, min(nvecs, BIO_MAX_PAGES));
36 + wbc_init_bio(io->io_wbc, bio);
37 bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
38 bio->bi_bdev = bh->b_bdev;
39 bio->bi_end_io = ext4_end_bio;
40 @@ -411,6 +412,7 @@ static int io_submit_add_bh(struct ext4_io_submit *io,
41 ret = bio_add_page(io->io_bio, page, bh->b_size, bh_offset(bh));
42 if (ret != bh->b_size)
43 goto submit_and_retry;
44 + wbc_account_io(io->io_wbc, page, bh->b_size);
48 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
49 index 56b8bb7..3ad1eb4 100644
52 @@ -3623,6 +3623,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
54 if (test_opt(sb, DELALLOC))
55 clear_opt(sb, DELALLOC);
57 + sb->s_iflags |= SB_I_CGROUPWB;
60 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |