xfs: implement cgroup writeback support
PATCH v2 1/1 xfs: implement cgroup writeback support
From: Shaohua Li <[email protected]>
Basically this is a copy of commit 001e4a8775f6(ext4: implement cgroup writeback support). Tested with a fio test, verified writeback is throttled against cgroup io.max write bandwidth, also verified moving the fio test to another cgroup and the writeback is throttled against new cgroup setting.
I created a test for this as attached, please try! I'll send the test out for inclusion later.
--- fs/xfs/xfs_aops.c | 12 ++++++++++-- fs/xfs/xfs_super.c | 1 + 2 files changed, 11 insertions(+), 2 deletions(-)
fs/xfs/xfs_aops.c +10 -2
@@ -561,7 +561,8 @@ xfs_alloc_ioend(struct inode *inode, unsigned int type, xfs_off_t offset, - struct buffer_head *bh) + struct buffer_head *bh, + struct writeback_control *wbc) { struct xfs_ioend *ioend;struct bio *bio;
@@ -578,6 +579,8 @@ xfs_alloc_ioend(INIT_WORK (&ioend->io_work, xfs_end_io); ioend->io_append_trans =NULL ; ioend->io_bio = bio; +/* attach new bio to its cgroup */ +wbc_init_bio (wbc, bio);return ioend; }
@@ -605,6 +608,8 @@ xfs_chain_bio( ioend->io_bio->bi_write_hint = ioend->io_inode->i_write_hint;submit_bio (ioend->io_bio); ioend->io_bio = new; +/* attach new bio to its cgroup */ +wbc_init_bio (wbc, new); }/*
@@ -628,7 +633,7 @@ xfs_add_to_ioend( offset != wpc->ioend->io_offset + wpc->ioend->io_size) {if (wpc->ioend)list_add (&wpc->ioend->io_list, iolist); - wpc->ioend =xfs_alloc_ioend (inode, wpc->io_type, offset, bh); + wpc->ioend =xfs_alloc_ioend (inode, wpc->io_type, offset, bh, wbc); }/*
@@ -638,6 +643,9 @@ xfs_add_to_ioend(while (xfs_bio_add_buffer (wpc->ioend->io_bio, bh) != bh->b_size)xfs_chain_bio (wpc->ioend, wbc, bh); +/* Charge write size to its cgroup for cgroup switching track */ +wbc_account_io (wbc, bh->b_page, bh->b_size); + wpc->ioend->io_size += bh->b_size; wpc->last_block = bh->b_blocknr;xfs_start_buffer_writeback (bh);
fs/xfs/xfs_super.c +1 -0
@@ -1634,6 +1634,7 @@ xfs_fs_fill_super( sb->s_max_links =XFS_MAXLINK ; sb->s_time_gran =1 ;set_posix_acl_flag (sb); + sb->s_iflags |=SB_I_CGROUPWB ;/* version 5 superblocks support inode version counters. */ if (XFS_SB_VERSION_NUM (&mp->m_sb) ==XFS_SB_VERSION_5 )
Signature · 1 line
2.9.5
Quoted 1 line
From
0edbc6d9f7abae299d6b1bd4b8ad76728afab313Mon Sep 17 00:00:00 2001
Message-Id: <0edbc6d9f7abae299d6b1bd4b8ad76728afab313.1508043579.git.shli@fb.com>
From: Shaohua Li <[email protected]>
Date: Sat, 14 Oct 2017 18:57:06 -0700
Subject: [PATCH] Add cgroup2 writeback test
--- common/cgroup2 | 18 +++++++++++++++++ tests/generic/463 | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/463.out | 2 ++ tests/generic/group | 1 + 4 files changed, 77 insertions(+) create mode 100644 common/cgroup2 create mode 100755 tests/generic/463 create mode 100644 tests/generic/463.out
common/cgroup2 new file +18 -0
@@ -0,0 +1,18 @@ +#!/bin/bash +# cgroup2 specific common functions + +export CGROUP2_PATH="/sys/fs/cgroup" + +_require_cgroup2() +{ + if [ ! -f ${CGROUP2_PATH}/cgroup.subtree_control ]; then + _notrun "Test requires cgroup2 enabled" + fi +} + +_get_scratch_dev_devt() +{ + ls -l $SCRATCH_DEV | awk '{printf("%s:%s", substr($5, 1, length($5)-1), 0)}' +} + +/bin/true
tests/generic/463 new file +56 -0
56 lines not on this page · raw message
tests/generic/463.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 463 +Cgroup writeback test success
tests/generic/group +1 -0
@@ -465,3 +465,4 @@ 460 auto quick rw 461 auto shutdown stress 462 auto quick dax +463 cgroup writeback test
Signature · 1 line
2.11.0
Quoted 10 lines · Shaohua Li
From: Shaohua Li <[email protected]>
Basically this is a copy of commit 001e4a8775f6(ext4: implement cgroup writeback support). Tested with a fio test, verified writeback is throttled against cgroup io.max write bandwidth, also verified moving the fio test to another cgroup and the writeback is throttled against new cgroup setting.
I created a test for this as attached, please try! I'll send the test out for inclusion later.
Hmmm. The test you appended just checks that bytes get written. That's pretty much useless for verification of the features you describe above (throttling rate it correct, dynamic throttle application as memcg config changes).
You explicitly state this is a memcg IO QoS feature and that you have a set of fio tests that verify that it works as expected. We need those "works as expected" fio tests formalised into automated fstests. Both upstream fs developers and downstream distro QE departments need to be able to verify that the bandwidth control and throttling works as advertised - it's essential that we have regression tests for this....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 17 lines · Dave Chinner
Quoted 10 lines · Shaohua Li
From: Shaohua Li <[email protected]>
Basically this is a copy of commit 001e4a8775f6(ext4: implement cgroup writeback support). Tested with a fio test, verified writeback is throttled against cgroup io.max write bandwidth, also verified moving the fio test to another cgroup and the writeback is throttled against new cgroup setting.
I created a test for this as attached, please try! I'll send the test out for inclusion later.
Hmmm. The test you appended just checks that bytes get written. That's pretty much useless for verification of the features you describe above (throttling rate it correct, dynamic throttle application as memcg config changes).
Quoted 7 lines
You explicitly state this is a memcg IO QoS feature and that you have a set of fio tests that verify that it works as expected. We need those "works as expected" fio tests formalised into automated fstests. Both upstream fs developers and downstream distro QE departments need to be able to verify that the bandwidth control and throttling works as advertised - it's essential that we have regression tests for this....
Right, this test only verifies the writeback is correctly charged to a cgroup, it doesn't verify the writeback is running in correct bandwidth. I did try to create such automatic test, but my attempt failed. To measure speed, we need measure the time for a test. But writeback is async, the file write finishes before the data is written to disk. We can't call a fsync, because fsync write is different than writeback write, which is charged to correct cgroup even without cgroup writeback support. For my test, I run iostat and check the disk speed is correct, so I don't have idea to create an automatic test.
Thanks,
Shaohua
Quoted 26 lines · Shaohua Li
Quoted 17 lines · Dave Chinner
Quoted 10 lines · Shaohua Li
From: Shaohua Li <[email protected]>
Basically this is a copy of commit 001e4a8775f6(ext4: implement cgroup writeback support). Tested with a fio test, verified writeback is throttled against cgroup io.max write bandwidth, also verified moving the fio test to another cgroup and the writeback is throttled against new cgroup setting.
I created a test for this as attached, please try! I'll send the test out for inclusion later.
Hmmm. The test you appended just checks that bytes get written. That's pretty much useless for verification of the features you describe above (throttling rate it correct, dynamic throttle application as memcg config changes).
Quoted 7 lines
You explicitly state this is a memcg IO QoS feature and that you have a set of fio tests that verify that it works as expected. We need those "works as expected" fio tests formalised into automated fstests. Both upstream fs developers and downstream distro QE departments need to be able to verify that the bandwidth control and throttling works as advertised - it's essential that we have regression tests for this....
Quoted 3 lines
Right, this test only verifies the writeback is correctly charged to a cgroup, it doesn't verify the writeback is running in correct bandwidth. I did try to create such automatic test, but my attempt failed.
<sigh>
Quoted 5 lines
To measure speed, we need measure the time for a test. But writeback is async, the file write finishes before the data is written to disk. We can't call a fsync, because fsync write is different than writeback write, which is charged to correct cgroup even without cgroup writeback support.
What a fucking mess. We were told that if we didn't implement the writeback hooks in the filesystem then the memcg write throttling would not be active on the filesystem.
Looks like we got taken for a bunch of suckers, eh?
So now I don't trust what we've been told about metadata IO being ignored by memcg throttling. What happens to REQ_META IO from within a throttled memcg task context? Does that also get throttled according to the current task memcg limits?
Quoted 2 lines
For my test, I run iostat and check the disk
speed is correct, so I don't have idea to create an automatic test.
Seems to me like there is an obvious answer to your problem:syncfs()
That is, syncfs uses the bdi flusher threads to do async writeback of all outstanding dirty data on the filesystem, and it also waits for that async writeback to complete. e.g: set the writeback throttle speed to 5MB/s then run:
# time xfs_io -f -c "pwrite 0 100m" -c "syncfs" /path/to/file
If that takes less than 20s to run, then async writeback through the bdi flusher workqueue wasn't throttled properly.
You can use this basic concept to do all manner of more complex testing, including changing throttle rates and the memcgs that tasks belong to.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 43 lines · Dave Chinner
Quoted 26 lines · Shaohua Li
Quoted 17 lines · Dave Chinner
Quoted 10 lines · Shaohua Li
From: Shaohua Li <[email protected]>
Basically this is a copy of commit 001e4a8775f6(ext4: implement cgroup writeback support). Tested with a fio test, verified writeback is throttled against cgroup io.max write bandwidth, also verified moving the fio test to another cgroup and the writeback is throttled against new cgroup setting.
I created a test for this as attached, please try! I'll send the test out for inclusion later.
Hmmm. The test you appended just checks that bytes get written. That's pretty much useless for verification of the features you describe above (throttling rate it correct, dynamic throttle application as memcg config changes).
Quoted 7 lines
You explicitly state this is a memcg IO QoS feature and that you have a set of fio tests that verify that it works as expected. We need those "works as expected" fio tests formalised into automated fstests. Both upstream fs developers and downstream distro QE departments need to be able to verify that the bandwidth control and throttling works as advertised - it's essential that we have regression tests for this....
Quoted 3 lines
Right, this test only verifies the writeback is correctly charged to a cgroup, it doesn't verify the writeback is running in correct bandwidth. I did try to create such automatic test, but my attempt failed.
<sigh>
Quoted 5 lines
To measure speed, we need measure the time for a test. But writeback is async, the file write finishes before the data is written to disk. We can't call a fsync, because fsync write is different than writeback write, which is charged to correct cgroup even without cgroup writeback support.
What a fucking mess. We were told that if we didn't implement the writeback hooks in the filesystem then the memcg write throttling would not be active on the filesystem.
Quoted 6 lines
Looks like we got taken for a bunch of suckers, eh?
So now I don't trust what we've been told about metadata IO being ignored by memcg throttling. What happens to
REQ_METAIO from within a throttled memcg task context? Does that also get throttled according to the current task memcg limits?
Yes, it's throttled according to current blkcg settings. This can be fixed however, Tejun recently posted patches to force all meta IO changed to root cgroup, we can do same thing for xfs.
Quoted 11 lines
Quoted 2 lines
For my test, I run iostat and check the disk
speed is correct, so I don't have idea to create an automatic test.Seems to me like there is an obvious answer to your problem:
syncfs()That is, syncfs uses the bdi flusher threads to do async writeback of all outstanding dirty data on the filesystem, and it also waits for that async writeback to complete. e.g: set the writeback throttle speed to 5MB/s then run:
Quoted 4 lines
# time xfs_io -f -c "pwrite 0 100m" -c "syncfs" /path/to/fileIf that takes less than 20s to run, then async writeback through the bdi flusher workqueue wasn't throttled properly.
Good idea, this is exactly what I want, thanks! Will post a xfs test soon.
Thanks,
Shaohua
fs/xfs/xfs_aops.c xfs_add_to_ioend( · line 636
Quoted 2 lines
fs/xfs/xfs_aops.c +1
-1- wpc->ioend =xfs_alloc_ioend (inode, wpc->io_type, offset, bh); + wpc->ioend =xfs_alloc_ioend (inode, wpc->io_type, offset, bh, wbc);
Too long line, please fix.
fs/xfs/xfs_super.c xfs_fs_fill_super( · line 1637
Quoted 1 line
fs/xfs/xfs_super.c +1
-0+ sb->s_iflags |=SB_I_CGROUPWB ;
Didn't Tejun just change this to a per-inode flag?