writeback: Improve busyloop prevention and inode requeueing
Subsystems (4)
Jan Kara
reviewerv4 cover writeback: Improve busyloop prevention and inode requeueing
Hello,
this is a fourth version of my patch series improving busyloop prevention in
writeback code and then replacing some redirty_tail() calls with requeue_io() to avoid postponing writeback for too long.
Changes since v3:
* Improved busyloop prevention to abort work which cannot make progress if we are retrying for too long or if there is some other work to do.
* Increased maximum sleep time in the busy loop to avoid eating CPU power unnecessarily.
* Removed wbc->pages_skipped check
Thanks to Fengguang for review, testing and good suggestions.
Honza
Jan Kara
reviewerPATCH v4 1/2 writeback: Improve busyloop prevention
Writeback of an inode can be stalled by things like internal fs locks being held. So in case we didn't write anything during a pass through b_io list, just wait for a moment and try again. When retrying is fruitless for a long time, or we have some other work to do, we just stop current work to avoid blocking flusher thread.
--- fs/fs-writeback.c | 39 +++++++++++++++++++++++++++------------ 1 files changed, 27 insertions(+), 12 deletions(-)
fs/fs-writeback.c +27 -12
@@ -699,8 +699,11 @@ static long wb_writeback(struct bdi_writeback *wb,unsigned long wb_start = jiffies;long nr_pages = work->nr_pages;unsigned long oldest_jif; -struct inode *inode;long progress; +long pause =1 ; +long max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ; oldest_jif = jiffies; work->older_than_this = &oldest_jif;
@@ -755,25 +758,37 @@ static long wb_writeback(struct bdi_writeback *wb,* mean the overall work is done. So we keep looping as long * as made some progress on cleaning pages or inodes. */ -if (progress) +if (progress) { + pause =1 ;continue ; + }/* * No more inodes for IO, bail */ if (list_empty (&wb->b_more_io))break ;/* -* Nothing written. Wait for some inode to -* become available for writeback. Otherwise -* we'll just busyloop. +* Nothing written (some internal fs locks were unavailable or +* inode was under writeback from balance_dirty_pages() or +* similar conditions). */ -if (!list_empty (&wb->b_more_io)) { -trace_writeback_wait (wb->bdi, work); - inode =wb_inode (wb->b_more_io.prev); -spin_lock (&inode->i_lock); -inode_wait_for_writeback (inode, wb); -spin_unlock (&inode->i_lock); - } +/* If there's some other work to do, proceed with it... */ +if (!list_empty (&wb->bdi->work_list) || + (!work->for_background &&over_bground_thresh ())) +break ; +/* +* Wait for a while to avoid busylooping unless we waited for +* so long it does not make sense to retry anymore. +*/ +if (pause > max_pause) +break ; +trace_writeback_wait (wb->bdi, work); +spin_unlock (&wb->list_lock); +__set_current_state (TASK_INTERRUPTIBLE ); +schedule_timeout (pause); +if (pause < max_pause) + pause <<=1 ; +spin_lock (&wb->list_lock); }spin_unlock (&wb->list_lock);
Signature · 1 line
1.7.1
Jan Kara
reviewerPATCH v4 2/2 writeback: Replace some redirty_tail() calls with requeue_io()
In reply to Jan KaraCalling redirty_tail() can put off inode writeback for upto 30 seconds (or whatever dirty_expire_centisecs is). This is unnecessarily big delay in some cases and in other cases it is a really bad thing. In particular XFS tries to be nice to writeback and when ->write_inode is called for an inode with locked ilock, it just redirties the inode and returns EAGAIN. That currently causes writeback_single_inode() to redirty_tail() the inode. As contended ilock is common thing with XFS while extending files the result can be that inode writeout is put off for a really long time.
Now that we have more robust busyloop prevention in wb_writeback() we can call requeue_io() in cases where quick retry is required without fear of raising CPU consumption too much.
--- fs/fs-writeback.c | 56 +++++++++++++++++++++++++++------------------------- 1 files changed, 29 insertions(+), 27 deletions(-)
fs/fs-writeback.c +29 -27
@@ -356,6 +356,7 @@ writeback_single_inode(struct inode *inode, struct bdi_writeback *wb,long nr_to_write = wbc->nr_to_write;unsigned dirty;int ret; +bool inode_written = false;assert_spin_locked (&wb->list_lock);assert_spin_locked (&inode->i_lock);
@@ -420,6 +421,8 @@ writeback_single_inode(struct inode *inode, struct bdi_writeback *wb,/* Don't write the inode if only I_DIRTY_PAGES was set */ if (dirty & (I_DIRTY_SYNC |I_DIRTY_DATASYNC )) {int err =write_inode (inode, wbc); +if (!err) + inode_written = true;if (ret ==0 ) ret = err; }
@@ -430,17 +433,20 @@ writeback_single_inode(struct inode *inode, struct bdi_writeback *wb,if (!(inode->i_state &I_FREEING )) {/* * Sync livelock prevention. Each inode is tagged and synced in -* one shot. If still dirty, it will be redirty_tail()'ed below. -* Update the dirty time to prevent enqueue and sync it again. +* one shot. If still dirty, update dirty time and put it back +* to dirty list to prevent enqueue and syncing it again. */ if ((inode->i_state &I_DIRTY ) && - (wbc->sync_mode ==WB_SYNC_ALL || wbc->tagged_writepages)) + (wbc->sync_mode ==WB_SYNC_ALL || wbc->tagged_writepages)) { inode->dirtied_when = jiffies; - -if (mapping_tagged (mapping,PAGECACHE_TAG_DIRTY )) { +redirty_tail (inode, wb); + }else if (mapping_tagged (mapping,PAGECACHE_TAG_DIRTY )) {/* -* We didn't write back all the pages. nfs_writepages() -* sometimes bales out without doing anything. +* We didn't write back all the pages. We may have just +* run out of our writeback slice, or nfs_writepages() +* sometimes bales out without doing anything, or e.g. +* btrfs ignores for_kupdate writeback requests for +* metadata inodes. */ inode->i_state |=I_DIRTY_PAGES ;if (wbc->nr_to_write <=0 ) {
@@ -450,11 +456,9 @@ writeback_single_inode(struct inode *inode, struct bdi_writeback *wb,requeue_io (inode, wb); }else {/* -* Writeback blocked by something other than -* congestion. Delay the inode for some time to -* avoid spinning on the CPU (100% iowait) -* retrying writeback of the dirty page/inode -* that cannot be performed immediately. +* Writeback blocked by something. Put inode +* back to dirty list to prevent livelocking of +* writeback. */ redirty_tail (inode, wb); }
@@ -463,9 +467,19 @@ writeback_single_inode(struct inode *inode, struct bdi_writeback *wb,* Filesystems can dirty the inode during writeback * operations, such as delayed allocation during * submission or metadata updates after data IO -* completion. +* completion. Also inode could have been dirtied by +* some process aggressively touching metadata. +* Finally, filesystem could just fail to write the +* inode for some reason. We have to distinguish the +* last case from the previous ones - in the last case +* we want to give the inode quick retry, in the +* other cases we want to put it back to the dirty list +* to avoid livelocking of writeback. */ -redirty_tail (inode, wb); +if (inode_written) +redirty_tail (inode, wb); +else +requeue_io (inode, wb); }else {/* * The inode is clean. At this point we either have
@@ -581,13 +595,6 @@ static long writeback_sb_inodes(struct super_block *sb, wrote += write_chunk - wbc.nr_to_write;if (!(inode->i_state &I_DIRTY )) wrote++; -if (wbc.pages_skipped) { -/* -* writeback is not making progress due to locked -* buffers. Skip this inode for now. -*/ -redirty_tail (inode, wb); - }spin_unlock (&inode->i_lock);spin_unlock (&wb->list_lock);iput (inode);
@@ -618,12 +625,7 @@ static long __writeback_inodes_wb(struct bdi_writeback *wb,struct super_block *sb = inode->i_sb;if (!grab_super_passive (sb)) { -/* -* grab_super_passive() may fail consistently due to -* s_umount being grabbed by someone else. Don't use -* requeue_io() to avoid busy retrying the inode/sb. -*/ -redirty_tail (inode, wb); +requeue_io (inode, wb);continue ; } wrote +=writeback_sb_inodes (sb, wb, work);
Signature · 1 line
1.7.1
Quoted 7 lines · Jan Kara
Hello,
this is a fourth version of my patch series improving busyloop prevention in
writeback code and then replacing someredirty_tail()calls withrequeue_io()to avoid postponing writeback for too long.
Quoted 8 lines
Changes since v3:
* Improved busyloop prevention to abort work which cannot make progress if we are retrying for too long or if there is some other work to do.
* Increased maximum sleep time in the busy loop to avoid eating CPU power unnecessarily.
* Removedwbc->pages_skippedcheckThanks to Fengguang for review, testing and good suggestions.
Yeah the new version addresses my previous concerns, and the test results are good in general:
3.1.0-rc8-ioless6a+ 3.1.0-rc8-ioless6-requeue6+
------------------------ ------------------------
58.23 -2.7% 56.65 thresh=100M/btrfs-10dd-4k-8p-4096M-100M:10-X
58.43 -2.0% 57.25 thresh=100M/btrfs-1dd-4k-8p-4096M-100M:10-X
58.53 -1.9% 57.42 thresh=100M/btrfs-2dd-4k-8p-4096M-100M:10-X
37.34 +0.1% 37.38 thresh=100M/ext3-10dd-4k-8p-4096M-100M:10-X
44.44 +0.5% 44.68 thresh=100M/ext3-1dd-4k-8p-4096M-100M:10-X
41.70 +2.0% 42.52 thresh=100M/ext3-2dd-4k-8p-4096M-100M:10-X
46.45 -0.3% 46.33 thresh=100M/ext4-10dd-4k-8p-4096M-100M:10-X
56.60 -1.5% 55.75 thresh=100M/ext4-1dd-4k-8p-4096M-100M:10-X
54.14 -0.9% 53.64 thresh=100M/ext4-2dd-4k-8p-4096M-100M:10-X
44.53 -2.6% 43.37 thresh=100M/xfs-10dd-4k-8p-4096M-100M:10-X
55.89 -2.3% 54.58 thresh=100M/xfs-1dd-4k-8p-4096M-100M:10-X
51.11 +0.0% 51.12 thresh=100M/xfs-2dd-4k-8p-4096M-100M:10-X
56.55 -1.3% 55.82 thresh=1G/btrfs-100dd-4k-8p-4096M-1024M:10-X
56.11 -0.9% 55.60 thresh=1G/btrfs-10dd-4k-8p-4096M-1024M:10-X
56.21 -0.9% 55.69 thresh=1G/btrfs-1dd-4k-8p-4096M-1024M:10-X
30.66 -1.3% 30.26 thresh=1G/ext3-100dd-4k-8p-4096M-1024M:10-X
35.24 -1.5% 34.72 thresh=1G/ext3-10dd-4k-8p-4096M-1024M:10-X
43.58 -0.7% 43.28 thresh=1G/ext3-1dd-4k-8p-4096M-1024M:10-X
50.42 -0.8% 50.01 thresh=1G/ext4-100dd-4k-8p-4096M-1024M:10-X
56.23 -2.1% 55.03 thresh=1G/ext4-10dd-4k-8p-4096M-1024M:10-X
58.12 -1.2% 57.42 thresh=1G/ext4-1dd-4k-8p-4096M-1024M:10-X
41.76 -5.9% 39.31 thresh=1G/xfs-100dd-4k-8p-4096M-1024M:10-X
48.34 +0.8% 48.70 thresh=1G/xfs-10dd-4k-8p-4096M-1024M:10-X
52.36 -2.0% 51.29 thresh=1G/xfs-1dd-4k-8p-4096M-1024M:10-X
32.09 -0.0% 32.08 thresh=1M/ext4-10dd-4k-8p-4096M-1M:10-X
51.36 +3.3% 53.05 thresh=1M/ext4-1dd-4k-8p-4096M-1M:10-X
46.93 +0.4% 47.13 thresh=1M/ext4-2dd-4k-8p-4096M-1M:10-X
28.68 -4.9% 27.28 thresh=1M/xfs-10dd-4k-8p-4096M-1M:10-X
51.95 +3.0% 53.51 thresh=1M/xfs-1dd-4k-8p-4096M-1M:10-X
47.07 -15.5% 39.78 thresh=1M/xfs-2dd-4k-8p-4096M-1M:10-X
54.37 +3.0% 56.02 thresh=8M/btrfs-10dd-4k-8p-4096M-8M:10-X
56.12 +3.5% 58.06 thresh=8M/btrfs-1dd-4k-8p-4096M-8M:10-X
56.22 +2.9% 57.87 thresh=8M/btrfs-2dd-4k-8p-4096M-8M:10-X
32.21 +1.1% 32.55 thresh=8M/ext3-10dd-4k-8p-4096M-8M:10-X
45.37 +1.6% 46.10 thresh=8M/ext3-1dd-4k-8p-4096M-8M:10-X
43.71 +2.5% 44.81 thresh=8M/ext3-2dd-4k-8p-4096M-8M:10-X
35.58 +0.9% 35.90 thresh=8M/ext4-10dd-4k-8p-4096M-8M:10-X
56.39 -0.9% 55.91 thresh=8M/ext4-1dd-4k-8p-4096M-8M:10-X
51.26 +0.7% 51.61 thresh=8M/ext4-2dd-4k-8p-4096M-8M:10-X
31.07 -0.3% 30.97 thresh=8M/xfs-10dd-4k-8p-4096M-8M:10-X
55.44 -1.4% 54.68 thresh=8M/xfs-1dd-4k-8p-4096M-8M:10-X
47.59 -0.7% 47.25 thresh=8M/xfs-2dd-4k-8p-4096M-8M:10-X
2016.38 -0.7% 2002.40 TOTALThanks,
Fengguang
Re: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Jan KaraQuoted 18 lines · Jan Kara
Writeback of an inode can be stalled by things like internal fs locks being held. So in case we didn't write anything during a pass through
b_iolist, just wait for a moment and try again. When retrying is fruitless for a long time, or we have some other work to do, we just stop current work to avoid blocking flusher thread.CC Christoph Hellwig <[email protected]>Reviewed-by Wu Fengguang <[email protected]>Signed-off-by Jan Kara <[email protected]>--- fs/fs-writeback.c | 39 +++++++++++++++++++++++++++------------ 1 files changed, 27 insertions(+), 12 deletions(-)fs/fs-writeback.c +0
-0
fs/fs-writeback.c static long wb_writeback(struct bdi_writeback *wb, · line 706
Quoted 9 lines
fs/fs-writeback.c +4
-1@@ -699,8 +699,11 @@ static long wb_writeback(struct bdi_writeback *wb,unsigned long wb_start = jiffies;long nr_pages = work->nr_pages;unsigned long oldest_jif; -struct inode *inode;long progress; +long pause =1 ; +long max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ;
It's better not to put the flusher to sleeps more than 10ms, so that when the condition changes, we don't risk making the storage idle for too long time.
So let's distinguish between accumulated and one-shot max pause time in the below code?
The other changes look fine to me.
Thanks,
Fengguang
Quoted 53 lines
fs/fs-writeback.c +23
-11oldest_jif = jiffies; work->older_than_this = &oldest_jif;@@ -755,25 +758,37 @@ static long wb_writeback(struct bdi_writeback *wb,* mean the overall work is done. So we keep looping as long * as made some progress on cleaning pages or inodes. */ -if (progress) +if (progress) { + pause =1 ;continue ; + }/* * No more inodes for IO, bail */ if (list_empty (&wb->b_more_io))break ;/* -* Nothing written. Wait for some inode to -* become available for writeback. Otherwise -* we'll just busyloop. +* Nothing written (some internal fs locks were unavailable or +* inode was under writeback from balance_dirty_pages() or +* similar conditions). */ -if (!list_empty (&wb->b_more_io)) { -trace_writeback_wait (wb->bdi, work); - inode =wb_inode (wb->b_more_io.prev); -spin_lock (&inode->i_lock); -inode_wait_for_writeback (inode, wb); -spin_unlock (&inode->i_lock); - } +/* If there's some other work to do, proceed with it... */ +if (!list_empty (&wb->bdi->work_list) || + (!work->for_background &&over_bground_thresh ())) +break ; +/* +* Wait for a while to avoid busylooping unless we waited for +* so long it does not make sense to retry anymore. +*/ +if (pause > max_pause) +break ; +trace_writeback_wait (wb->bdi, work); +spin_unlock (&wb->list_lock); +__set_current_state (TASK_INTERRUPTIBLE ); +schedule_timeout (pause); +if (pause < max_pause) + pause <<=1 ; +spin_lock (&wb->list_lock); }spin_unlock (&wb->list_lock);Signature · 1 line
1.7.1
Re: [PATCH 2/2] writeback: Replace some redirty_tail() calls with requeue_io()
In reply to Jan KaraJan,
This looks fine, too.
If no objections, I'd like to push the patches (preferably with updated patch 1) to linux-next ASAP.
Thanks,
Fengguang
Quoted 136 lines · Jan Kara
Calling
redirty_tail()can put off inode writeback for upto 30 seconds (or whateverdirty_expire_centisecsis). This is unnecessarily big delay in some cases and in other cases it is a really bad thing. In particular XFS tries to be nice to writeback and when ->write_inode is called for an inode with locked ilock, it just redirties the inode and returns EAGAIN. That currently causeswriteback_single_inode()toredirty_tail()the inode. As contended ilock is common thing with XFS while extending files the result can be that inode writeout is put off for a really long time.Now that we have more robust busyloop prevention in
wb_writeback()we can callrequeue_io()in cases where quick retry is required without fear of raising CPU consumption too much.CC Christoph Hellwig <[email protected]>Acked-by Wu Fengguang <[email protected]>Signed-off-by Jan Kara <[email protected]>--- fs/fs-writeback.c | 56 +++++++++++++++++++++++++++------------------------- 1 files changed, 29 insertions(+), 27 deletions(-)fs/fs-writeback.c +29
-27@@ -356,6 +356,7 @@ writeback_single_inode(struct inode *inode, struct bdi_writeback *wb,long nr_to_write = wbc->nr_to_write;unsigned dirty;int ret; +bool inode_written = false;assert_spin_locked (&wb->list_lock);assert_spin_locked (&inode->i_lock);@@ -420,6 +421,8 @@ writeback_single_inode(struct inode *inode, struct bdi_writeback *wb,/* Don't write the inode if only I_DIRTY_PAGES was set */ if (dirty & (I_DIRTY_SYNC |I_DIRTY_DATASYNC )) {int err =write_inode (inode, wbc); +if (!err) + inode_written = true;if (ret ==0 ) ret = err; }@@ -430,17 +433,20 @@ writeback_single_inode(struct inode *inode, struct bdi_writeback *wb,if (!(inode->i_state &I_FREEING )) {/* * Sync livelock prevention. Each inode is tagged and synced in -* one shot. If still dirty, it will be redirty_tail()'ed below. -* Update the dirty time to prevent enqueue and sync it again. +* one shot. If still dirty, update dirty time and put it back +* to dirty list to prevent enqueue and syncing it again. */ if ((inode->i_state &I_DIRTY ) && - (wbc->sync_mode ==WB_SYNC_ALL || wbc->tagged_writepages)) + (wbc->sync_mode ==WB_SYNC_ALL || wbc->tagged_writepages)) { inode->dirtied_when = jiffies; - -if (mapping_tagged (mapping,PAGECACHE_TAG_DIRTY )) { +redirty_tail (inode, wb); + }else if (mapping_tagged (mapping,PAGECACHE_TAG_DIRTY )) {/* -* We didn't write back all the pages. nfs_writepages() -* sometimes bales out without doing anything. +* We didn't write back all the pages. We may have just +* run out of our writeback slice, or nfs_writepages() +* sometimes bales out without doing anything, or e.g. +* btrfs ignores for_kupdate writeback requests for +* metadata inodes. */ inode->i_state |=I_DIRTY_PAGES ;if (wbc->nr_to_write <=0 ) {@@ -450,11 +456,9 @@ writeback_single_inode(struct inode *inode, struct bdi_writeback *wb,requeue_io (inode, wb); }else {/* -* Writeback blocked by something other than -* congestion. Delay the inode for some time to -* avoid spinning on the CPU (100% iowait) -* retrying writeback of the dirty page/inode -* that cannot be performed immediately. +* Writeback blocked by something. Put inode +* back to dirty list to prevent livelocking of +* writeback. */ redirty_tail (inode, wb); }@@ -463,9 +467,19 @@ writeback_single_inode(struct inode *inode, struct bdi_writeback *wb,* Filesystems can dirty the inode during writeback * operations, such as delayed allocation during * submission or metadata updates after data IO -* completion. +* completion. Also inode could have been dirtied by +* some process aggressively touching metadata. +* Finally, filesystem could just fail to write the +* inode for some reason. We have to distinguish the +* last case from the previous ones - in the last case +* we want to give the inode quick retry, in the +* other cases we want to put it back to the dirty list +* to avoid livelocking of writeback. */ -redirty_tail (inode, wb); +if (inode_written) +redirty_tail (inode, wb); +else +requeue_io (inode, wb); }else {/* * The inode is clean. At this point we either have @@ -581,13 +595,6 @@ static long writeback_sb_inodes(struct super_block *sb, wrote += write_chunk - wbc.nr_to_write;if (!(inode->i_state &I_DIRTY )) wrote++; -if (wbc.pages_skipped) { -/* -* writeback is not making progress due to locked -* buffers. Skip this inode for now. -*/ -redirty_tail (inode, wb); - }spin_unlock (&inode->i_lock);spin_unlock (&wb->list_lock);iput (inode);@@ -618,12 +625,7 @@ static long __writeback_inodes_wb(struct bdi_writeback *wb,struct super_block *sb = inode->i_sb;if (!grab_super_passive (sb)) { -/* -* grab_super_passive() may fail consistently due to -* s_umount being grabbed by someone else. Don't use -* requeue_io() to avoid busy retrying the inode/sb. -*/ -redirty_tail (inode, wb); +requeue_io (inode, wb);continue ; } wrote +=writeback_sb_inodes (sb, wb, work);Signature · 1 line
1.7.1
Re: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Wu FengguangQuoted 33 lines · Wu Fengguang
Quoted 18 lines · Jan Kara
Writeback of an inode can be stalled by things like internal fs locks being held. So in case we didn't write anything during a pass through
b_iolist, just wait for a moment and try again. When retrying is fruitless for a long time, or we have some other work to do, we just stop current work to avoid blocking flusher thread.CC Christoph Hellwig <[email protected]>Reviewed-by Wu Fengguang <[email protected]>Signed-off-by Jan Kara <[email protected]>--- fs/fs-writeback.c | 39 +++++++++++++++++++++++++++------------ 1 files changed, 27 insertions(+), 12 deletions(-)fs/fs-writeback.c +0
-0fs/fs-writeback.c static long wb_writeback(struct bdi_writeback *wb, · line 706
Quoted 9 lines
fs/fs-writeback.c +4
-1@@ -699,8 +699,11 @@ static long wb_writeback(struct bdi_writeback *wb,unsigned long wb_start = jiffies;long nr_pages = work->nr_pages;unsigned long oldest_jif; -struct inode *inode;long progress; +long pause =1 ; +long max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ;It's better not to put the flusher to sleeps more than 10ms, so that when the condition changes, we don't risk making the storage idle for too long time.
Quoted 2 lines
So let's distinguish between accumulated and one-shot max pause time in the below code?
I was thinking about this as well but then I realized that when some work
is queued or when background writeback is necessary, we always wakeup flusher thread so these conditions will be noticed promptly. And regarding locks we potentially blocked on, we always wait only as long as we already waited in previous waits together so that doesn't look like too defensive to me. Or are you concerned about something else? I've just noticed the was was unnecessarily racy wrt wakeups so attached is a new version which should be safe in this regard.
Specifically I didn't want to wake up every 10 ms because if there are
inodes which are unwriteable for a long time like in case of btrfs, we would just wakeup flusher thread (and thus CPU) every 10 ms on otherwise idle system and that does draw considerable amount of power on a laptop.
Quoted 53 lines
Quoted 53 lines
fs/fs-writeback.c +23
-11oldest_jif = jiffies; work->older_than_this = &oldest_jif;@@ -755,25 +758,37 @@ static long wb_writeback(struct bdi_writeback *wb,* mean the overall work is done. So we keep looping as long * as made some progress on cleaning pages or inodes. */ -if (progress) +if (progress) { + pause =1 ;continue ; + }/* * No more inodes for IO, bail */ if (list_empty (&wb->b_more_io))break ;/* -* Nothing written. Wait for some inode to -* become available for writeback. Otherwise -* we'll just busyloop. +* Nothing written (some internal fs locks were unavailable or +* inode was under writeback from balance_dirty_pages() or +* similar conditions). */ -if (!list_empty (&wb->b_more_io)) { -trace_writeback_wait (wb->bdi, work); - inode =wb_inode (wb->b_more_io.prev); -spin_lock (&inode->i_lock); -inode_wait_for_writeback (inode, wb); -spin_unlock (&inode->i_lock); - } +/* If there's some other work to do, proceed with it... */ +if (!list_empty (&wb->bdi->work_list) || + (!work->for_background &&over_bground_thresh ())) +break ; +/* +* Wait for a while to avoid busylooping unless we waited for +* so long it does not make sense to retry anymore. +*/ +if (pause > max_pause) +break ; +trace_writeback_wait (wb->bdi, work); +spin_unlock (&wb->list_lock); +__set_current_state (TASK_INTERRUPTIBLE ); +schedule_timeout (pause); +if (pause < max_pause) + pause <<=1 ; +spin_lock (&wb->list_lock); }spin_unlock (&wb->list_lock);Signature · 1 line
1.7.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 1 line
From
7d59989e38af2e10101f7d9f0c98343fe551c536Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Thu, 8 Sep 2011 01:05:25 +0200
Subject: [PATCH 1/2] writeback: Improve busyloop prevention
Writeback of an inode can be stalled by things like internal fs locks being held. So in case we didn't write anything during a pass through b_io list, just wait for a moment and try again. When retrying is fruitless for a long time, or we have some other work to do, we just stop current work to avoid blocking flusher thread.
--- fs/fs-writeback.c | 43 ++++++++++++++++++++++++++++++++----------- 1 files changed, 32 insertions(+), 11 deletions(-)
fs/fs-writeback.c +32 -11
@@ -699,8 +699,11 @@ static long wb_writeback(struct bdi_writeback *wb,unsigned long wb_start = jiffies;long nr_pages = work->nr_pages;unsigned long oldest_jif; -struct inode *inode;long progress; +long pause =1 ; +long max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ; oldest_jif = jiffies; work->older_than_this = &oldest_jif;
@@ -755,25 +758,43 @@ static long wb_writeback(struct bdi_writeback *wb,* mean the overall work is done. So we keep looping as long * as made some progress on cleaning pages or inodes. */ -if (progress) +if (progress) { + pause =1 ;continue ; + }/* * No more inodes for IO, bail */ if (list_empty (&wb->b_more_io))break ;/* -* Nothing written. Wait for some inode to -* become available for writeback. Otherwise -* we'll just busyloop. +* Nothing written (some internal fs locks were unavailable or +* inode was under writeback from balance_dirty_pages() or +* similar conditions). +* +* Wait for a while to avoid busylooping unless we waited for +* so long it does not make sense to retry anymore. */ -if (!list_empty (&wb->b_more_io)) { -trace_writeback_wait (wb->bdi, work); - inode =wb_inode (wb->b_more_io.prev); -spin_lock (&inode->i_lock); -inode_wait_for_writeback (inode, wb); -spin_unlock (&inode->i_lock); +if (pause > max_pause) +break ; +/* +* Set state here to prevent races with someone waking us up +* (because new work is queued or because background limit is +* exceeded). +*/ +set_current_state (TASK_INTERRUPTIBLE ); +/* If there's some other work to do, proceed with it... */ +if (!list_empty (&wb->bdi->work_list) || + (!work->for_background &&over_bground_thresh ())) { +__set_current_state (TASK_RUNNING ); +break ; } +trace_writeback_wait (wb->bdi, work); +spin_unlock (&wb->list_lock); +schedule_timeout (pause); +if (pause < max_pause) + pause <<=1 ; +spin_lock (&wb->list_lock); }spin_unlock (&wb->list_lock);
Signature · 1 line
1.7.1
Jan Kara
reviewerRe: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to a message not in the archiveQuoted 9 lines · Wu Fengguang
Quoted 8 lines
fs/fs-writeback.c static long wb_writeback(struct bdi_writeback *wb, · line 706
Quoted 4 lines
fs/fs-writeback.c +4
-0+long pause =1 ; +long max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ;It's better not to put the flusher to sleeps more than 10ms, so that when the condition changes, we don't risk making the storage idle for too long time.
Quoted 8 lines
Yeah, the one big regression case
3.1.0-rc8-ioless6a+ 3.1.0-rc8-ioless6-requeue6+ ------------------------ ------------------------ 47.07 -15.5% 39.78 thresh=1M/xfs-2dd-4k-8p-4096M-1M:10-Xis exactly caused by the large sleep: the attached graphs are showing one period of no-progress on the number of written pages.
Thanks for the tests! Interesting. Do you have trace file from that run?
I see the writeback stalled for 20s or so which is more than dirty_writeback_centisecs so I think something more complicated must have happened.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Jan KaraWhat btrfs does for the btree inode is insane, and I'm pretty sure I already complained about it. It really needs to stop registering that inode with the writeback code and just driver it manually. Same as other filesystems do for their "micro-managed" metadata.
Re: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Jan KaraQuoted 16 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines
fs/fs-writeback.c static long wb_writeback(struct bdi_writeback *wb, · line 706
Quoted 4 lines
fs/fs-writeback.c +4
-0+long pause =1 ; +long max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ;It's better not to put the flusher to sleeps more than 10ms, so that when the condition changes, we don't risk making the storage idle for too long time.
Yeah, the one big regression case
3.1.0-rc8-ioless6a+ 3.1.0-rc8-ioless6-requeue6+ ------------------------ ------------------------ 47.07 -15.5% 39.78 thresh=1M/xfs-2dd-4k-8p-4096M-1M:10-X
Quoted 6 lines
Quoted 2 lines
is exactly caused by the large sleep: the attached graphs are showing one period of no-progress on the number of written pages.
Thanks for the tests! Interesting. Do you have trace file from that run?
I see the writeback stalled for 20s or so which is more thandirty_writeback_centisecsso I think something more complicated must have happened.
I noticed that
1) the global dirty limit is exceeded (dirty=286, limit=256), hence the dd tasks are hard blocked in balance_dirty_pages().
flush-8:0-1170 [004] 211.068427: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447
2) the flusher thread is not woken up because we test writeback_in_progress() in balance_dirty_pages().
if (unlikely(!writeback_in_progress(bdi)))
bdi_start_background_writeback(bdi);Thus the flusher thread wait and wait as in below trace.
flush-8:0-1170 [004] 211.068427: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447
flush-8:0-1170 [004] 211.068428: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32
flush-8:0-1170 [004] 211.068428: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background
flush-8:0-1170 [004] 211.068440: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=9 index=0 to_write=1024 wrote=0
flush-8:0-1170 [004] 211.068442: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background
flush-8:0-1170 [004] 211.068443: writeback_wait: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 213.110122: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447
flush-8:0-1170 [004] 213.110126: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32
flush-8:0-1170 [004] 213.110126: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background
flush-8:0-1170 [004] 213.110134: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=11 index=0 to_write=1024 wrote=0
flush-8:0-1170 [004] 213.110135: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background
flush-8:0-1170 [004] 213.110135: writeback_wait: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 217.193470: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447
flush-8:0-1170 [004] 217.193471: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32
flush-8:0-1170 [004] 217.193471: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background
flush-8:0-1170 [004] 217.193483: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=15 index=0 to_write=1024 wrote=0
flush-8:0-1170 [004] 217.193485: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=backgroundThis should be fixable by removing the BDI_writeback_running flag before doing the wait sleep.
Thanks,
Fengguang
Re: [PATCH 1/2] writeback: Improve busyloop prevention
Quoted 53 lines · Wu Fengguang
Quoted 16 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines
fs/fs-writeback.c static long wb_writeback(struct bdi_writeback *wb, · line 706
Quoted 4 lines
fs/fs-writeback.c +4
-0+long pause =1 ; +long max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ;It's better not to put the flusher to sleeps more than 10ms, so that when the condition changes, we don't risk making the storage idle for too long time.
Yeah, the one big regression case
3.1.0-rc8-ioless6a+ 3.1.0-rc8-ioless6-requeue6+ ------------------------ ------------------------ 47.07 -15.5% 39.78 thresh=1M/xfs-2dd-4k-8p-4096M-1M:10-XQuoted 6 lines
Quoted 2 lines
is exactly caused by the large sleep: the attached graphs are showing one period of no-progress on the number of written pages.
Thanks for the tests! Interesting. Do you have trace file from that run?
I see the writeback stalled for 20s or so which is more thandirty_writeback_centisecsso I think something more complicated must have happened.I noticed that
1) the global dirty limit is exceeded (dirty=286, limit=256), hence the dd tasks are hard blocked in
balance_dirty_pages().flush-8:0-1170 [004] 211.068427: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=20814472) the flusher thread is not woken up because we test
writeback_in_progress()inbalance_dirty_pages().if (unlikely(!writeback_in_progress(bdi))) bdi_start_background_writeback(bdi);Thus the flusher thread wait and wait as in below trace.
flush-8:0-1170 [004] 211.068427: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 211.068428: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 211.068428: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 211.068440: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=9 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 211.068442: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 211.068443: writeback_wait: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=backgroundflush-8:0-1170 [004] 213.110122: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 213.110126: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 213.110126: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 213.110134: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=11 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 213.110135: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 213.110135: writeback_wait: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background
Quoted 5 lines
flush-8:0-1170 [004] 217.193470: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447
flush-8:0-1170 [004] 217.193471: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32
flush-8:0-1170 [004] 217.193471: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background
flush-8:0-1170 [004] 217.193483: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=15 index=0 to_write=1024 wrote=0
flush-8:0-1170 [004] 217.193485: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=backgroundIt's still puzzling why dirty pages remain at 286 and does not get cleaned by either flusher threads for local XFS and NFSROOT for so long time..
Thanks,
Fengguang
Re: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Christoph HellwigExcerpts from Christoph Hellwig's message of 2011-10-14 03:18:02 -0400:
Quoted 5 lines
What btrfs does for the btree inode is insane, and I'm pretty sure I already complained about it. It really needs to stop registering that inode with the writeback code and just driver it manually. Same as other filesystems do for their "micro-managed" metadata.
So I think you probably don't like the inode and the part where we actively decide not to writeback when there isn't much dirty.
Yes, it would be different if btrfs had its own LRU for the btrees, and if it maintained them such that the LRU understood it was better to kick out leaves than roots.
I've really wanted to play with this for a while.
-chris
Re: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Wu FengguangQuoted 6 lines
2) the flusher thread is not woken up because we test
writeback_in_progress()inbalance_dirty_pages().if (unlikely(!writeback_in_progress(bdi))) bdi_start_background_writeback(bdi);
[...]
Quoted 2 lines
This should be fixable by removing the
BDI_writeback_runningflag before doing the wait sleep.
I tried adding the below patch, and this time it shows 1.8% performance improvement. Looks not bad :-)
3.1.0-rc8-ioless6a+ 3.1.0-rc8-ioless6-requeue7+
------------------------ ------------------------
32.09 +1.1% 32.45 thresh=1M/ext4-10dd-4k-8p-4096M-1M:10-X
51.36 +3.2% 53.00 thresh=1M/ext4-1dd-4k-8p-4096M-1M:10-X
46.93 +1.9% 47.80 thresh=1M/ext4-2dd-4k-8p-4096M-1M:10-X
28.68 +1.6% 29.15 thresh=1M/xfs-10dd-4k-8p-4096M-1M:10-X
51.95 +4.2% 54.13 thresh=1M/xfs-1dd-4k-8p-4096M-1M:10-X
47.07 +1.5% 47.80 thresh=1M/xfs-2dd-4k-8p-4096M-1M:10-X
54.37 +2.2% 55.58 thresh=8M/btrfs-10dd-4k-8p-4096M-8M:10-X
56.12 +4.2% 58.49 thresh=8M/btrfs-1dd-4k-8p-4096M-8M:10-X
56.22 +2.4% 57.55 thresh=8M/btrfs-2dd-4k-8p-4096M-8M:10-X
32.21 +1.7% 32.77 thresh=8M/ext3-10dd-4k-8p-4096M-8M:10-X
45.37 +2.7% 46.58 thresh=8M/ext3-1dd-4k-8p-4096M-8M:10-X
43.71 +2.6% 44.83 thresh=8M/ext3-2dd-4k-8p-4096M-8M:10-X
35.58 +1.3% 36.06 thresh=8M/ext4-10dd-4k-8p-4096M-8M:10-X
56.39 +0.4% 56.61 thresh=8M/ext4-1dd-4k-8p-4096M-8M:10-X
51.26 +1.4% 51.98 thresh=8M/ext4-2dd-4k-8p-4096M-8M:10-X
31.07 +0.3% 31.16 thresh=8M/xfs-10dd-4k-8p-4096M-8M:10-X
55.44 -2.0% 54.33 thresh=8M/xfs-1dd-4k-8p-4096M-8M:10-X
47.59 +0.6% 47.87 thresh=8M/xfs-2dd-4k-8p-4096M-8M:10-X
823.40 +1.8% 838.14 TOTALfs/fs-writeback.c +2 -0
@@ -809,8 +809,10 @@ static long wb_writeback(struct bdi_writbreak ;trace_writeback_wait (wb->bdi, work);spin_unlock (&wb->list_lock); +clear_bit (BDI_writeback_running, &wb->bdi->state);__set_current_state (TASK_INTERRUPTIBLE );schedule_timeout (pause); +set_bit (BDI_writeback_running, &wb->bdi->state);if (pause < max_pause) pause <<=1 ;spin_lock (&wb->list_lock);
Re: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Wu FengguangQuoted 60 lines · Wu Fengguang
Quoted 53 lines · Wu Fengguang
Quoted 16 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ long pause = 1; + long max_pause = dirty_writeback_interval ? + msecs_to_jiffies(dirty_writeback_interval * 10) : + HZ;It's better not to put the flusher to sleeps more than 10ms, so that when the condition changes, we don't risk making the storage idle for too long time.
Yeah, the one big regression case
3.1.0-rc8-ioless6a+ 3.1.0-rc8-ioless6-requeue6+ ------------------------ ------------------------ 47.07 -15.5% 39.78 thresh=1M/xfs-2dd-4k-8p-4096M-1M:10-XQuoted 6 lines
Quoted 2 lines
is exactly caused by the large sleep: the attached graphs are showing one period of no-progress on the number of written pages.
Thanks for the tests! Interesting. Do you have trace file from that run?
I see the writeback stalled for 20s or so which is more thandirty_writeback_centisecsso I think something more complicated must have happened.I noticed that
1) the global dirty limit is exceeded (dirty=286, limit=256), hence the dd tasks are hard blocked in
balance_dirty_pages().flush-8:0-1170 [004] 211.068427: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=20814472) the flusher thread is not woken up because we test
writeback_in_progress()inbalance_dirty_pages().if (unlikely(!writeback_in_progress(bdi))) bdi_start_background_writeback(bdi);Thus the flusher thread wait and wait as in below trace.
flush-8:0-1170 [004] 211.068427: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 211.068428: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 211.068428: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 211.068440: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=9 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 211.068442: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 211.068443: writeback_wait: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=backgroundflush-8:0-1170 [004] 213.110122: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 213.110126: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 213.110126: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 213.110134: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=11 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 213.110135: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 213.110135: writeback_wait: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=backgroundQuoted 5 lines
flush-8:0-1170 [004] 217.193470: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 217.193471: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 217.193471: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 217.193483: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=15 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 217.193485: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background
Quoted 3 lines
It's still puzzling why dirty pages remain at 286 and does not get cleaned by either flusher threads for local XFS and NFSROOT for so long time..
I was looking at this as well. So the reason why pages were not cleaned
by the flusher thread is that there were 2 dirty inodes and the inode with dirty pages had i_dirtied_whan newer than the time when we started this background writeback. Thus the running background writeback work always included only the other inode which has no dirty pages but I_DIRTY_SYNC set. Apparently XFS is stubborn and refuses to write the inode although we try rather hard. That is probably because dd writing to this inode is stuck in balance_dirty_pages() and holds ilock - which is a bit unfortunate behavior but what can we do...
I think the patch you suggest in the other email does not fix the above
scenario (although it is useful for reducing latency so I'll include it - thanks for it!). Probably you were just lucky enough not to hit it in your next run. What I'd suggest is to refresh oldest_jif in wb_writeback() when we do not make any progress with writeback. Thus we allow freshly dirtied inodes to be queued when we cannot make progress with the current set of inodes. The resulting patch is attached.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 1 line
From
b85b7cdaf5fafec2d850304c1d0b1813c1c122a3Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Thu, 8 Sep 2011 01:05:25 +0200
Subject: [PATCH 1/2] writeback: Improve busyloop prevention
Writeback of an inode can be stalled by things like internal fs locks being held. So in case we didn't write anything during a pass through b_io list, just wait for a moment and try again. Also allow newly dirtied inodes to be queued during the retry. When retrying is fruitless for a long time, or we have some other work to do, we just stop current work to avoid blocking flusher thread.
--- fs/fs-writeback.c | 61 +++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 48 insertions(+), 13 deletions(-)
fs/fs-writeback.c +48 -13
@@ -699,8 +699,11 @@ static long wb_writeback(struct bdi_writeback *wb,unsigned long wb_start = jiffies;long nr_pages = work->nr_pages;unsigned long oldest_jif; -struct inode *inode;long progress; +long pause =1 ; +long max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ; oldest_jif = jiffies; work->older_than_this = &oldest_jif;
@@ -730,11 +733,19 @@ static long wb_writeback(struct bdi_writeback *wb,if (work->for_background && !over_bground_thresh ())break ; +/* +* Refresh oldest timestamp. In kupdate style we include +* freshly expired inodes in each round. For other types of +* writeback we don't want to include newly dirtied inodes +* to avoid livelocking. But in case we made no progress in +* the last writeback round, allow new inodes to be queued +* so that we don't block flusher thread unnecessarily. +*/ if (work->for_kupdate) { oldest_jif = jiffies -msecs_to_jiffies (dirty_expire_interval *10 ); - work->older_than_this = &oldest_jif; - } + }else if (pause >1 ) + oldest_jif = jiffies;trace_writeback_start (wb->bdi, work);if (list_empty (&wb->b_io))
@@ -755,25 +766,49 @@ static long wb_writeback(struct bdi_writeback *wb,* mean the overall work is done. So we keep looping as long * as made some progress on cleaning pages or inodes. */ -if (progress) +if (progress) { + pause =1 ;continue ; + }/* * No more inodes for IO, bail */ if (list_empty (&wb->b_more_io))break ;/* -* Nothing written. Wait for some inode to -* become available for writeback. Otherwise -* we'll just busyloop. +* Nothing written (some internal fs locks were unavailable or +* inode was under writeback from balance_dirty_pages() or +* similar conditions). +* +* Wait for a while to avoid busylooping unless we waited for +* so long it does not make sense to retry anymore. */ -if (!list_empty (&wb->b_more_io)) { -trace_writeback_wait (wb->bdi, work); - inode =wb_inode (wb->b_more_io.prev); -spin_lock (&inode->i_lock); -inode_wait_for_writeback (inode, wb); -spin_unlock (&inode->i_lock); +if (pause > max_pause) +break ; +/* +* Set state here to prevent races with someone waking us up +* (because new work is queued or because background limit is +* exceeded). +*/ +set_current_state (TASK_INTERRUPTIBLE ); +/* If there's some other work to do, proceed with it... */ +if (!list_empty (&wb->bdi->work_list) || + (!work->for_background &&over_bground_thresh ())) { +__set_current_state (TASK_RUNNING ); +break ; } +trace_writeback_wait (wb->bdi, work); +spin_unlock (&wb->list_lock); +/* +* Clear writeback_running so that we properly indicate that +* writeback is currently stalled +*/ +clear_bit (BDI_writeback_running, &wb->bdi->state); +schedule_timeout (pause); +set_bit (BDI_writeback_running, &wb->bdi->state); +if (pause < max_pause) + pause <<=1 ; +spin_lock (&wb->list_lock); }spin_unlock (&wb->list_lock);
Signature · 1 line
1.7.1
Re: [PATCH 1/2] writeback: Improve busyloop prevention
Quoted 61 lines · Jan Kara
Quoted 60 lines · Wu Fengguang
Quoted 58 lines · Wu Fengguang
Quoted 16 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines
fs/fs-writeback.c static long wb_writeback(struct bdi_writeback *wb, · line 706
Quoted 4 lines
fs/fs-writeback.c +4
-0+long pause =1 ; +long max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ;It's better not to put the flusher to sleeps more than 10ms, so that when the condition changes, we don't risk making the storage idle for too long time.
Yeah, the one big regression case
3.1.0-rc8-ioless6a+ 3.1.0-rc8-ioless6-requeue6+ ------------------------ ------------------------ 47.07 -15.5% 39.78 thresh=1M/xfs-2dd-4k-8p-4096M-1M:10-XQuoted 6 lines
Quoted 2 lines
is exactly caused by the large sleep: the attached graphs are showing one period of no-progress on the number of written pages.
Thanks for the tests! Interesting. Do you have trace file from that run?
I see the writeback stalled for 20s or so which is more thandirty_writeback_centisecsso I think something more complicated must have happened.I noticed that
1) the global dirty limit is exceeded (dirty=286, limit=256), hence the dd tasks are hard blocked in
balance_dirty_pages().flush-8:0-1170 [004] 211.068427: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=20814472) the flusher thread is not woken up because we test
writeback_in_progress()inbalance_dirty_pages().if (unlikely(!writeback_in_progress(bdi))) bdi_start_background_writeback(bdi);Thus the flusher thread wait and wait as in below trace.
flush-8:0-1170 [004] 211.068427: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 211.068428: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 211.068428: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 211.068440: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=9 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 211.068442: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 211.068443: writeback_wait: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=backgroundflush-8:0-1170 [004] 213.110122: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 213.110126: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 213.110126: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 213.110134: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=11 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 213.110135: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 213.110135: writeback_wait: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=backgroundflush-8:0-1170 [004] 217.193470: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 217.193471: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 217.193471: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 217.193483: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=15 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 217.193485: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background
Quoted 8 lines
Quoted 3 lines
It's still puzzling why dirty pages remain at 286 and does not get cleaned by either flusher threads for local XFS and NFSROOT for so long time..
I was looking at this as well. So the reason why pages were not cleaned
by the flusher thread is that there were 2 dirty inodes and the inode with dirty pages hadi_dirtied_whannewer than the time when we started this background writeback. Thus the running background writeback work always included only the other inode which has no dirty pages butI_DIRTY_SYNCset.
Yes that's very likely, given that the background work can run for very long time and there are still code paths to redirty_tail() the inode.
This sounds horrible -- as time goes by, more and more inodes could be excluded from the background writeback due to inode->dirtied_when being touched undesirably.
Quoted 4 lines
Apparently XFS is stubborn and refuses to write the inode although we try rather hard. That is probably because dd writing to this inode is stuck in
balance_dirty_pages()and holds ilock - which is a bit unfortunate behavior but what can we do...
Yeah, and there may well be other known or unknown long lived blocking cases. What we can do in VFS is to be not so picky on these conditions...
To be frank I still like the requeue_io_wait() approach. It can trivially replace _all_ redity_tail() calls and hence avoid touching inode->dirtied_when -- keeping that time stamp sane is the one thing I would really like to do.
It also narrows down the perhaps blocked inodes and hence the need to do heuristic wait-and-retry to the minimal.
It does introduce one more list, which IMHO is more tolerable than the problems it fixed. And its max delay time can be reduced explicitly if necessary: when there are heavy dirtiers, it will quickly be woken up by balance_dirty_pages(); in other cases we can let the kupdate work check s_more_io_wait before aborting to ensure 5s max delay:
@@ -863,7 +863,7 @@ static long wb_check_old_data_flush(stru
expired = wb->last_old_flush +
msecs_to_jiffies(dirty_writeback_interval * 10);
- if (time_before(jiffies, expired))
+ if (time_before(jiffies, expired) && list_empty(&wb->b_more_io_wait))
return 0;
wb->last_old_flush = jiffies;Quoted 7 lines
I think the patch you suggest in the other email does not fix the above
scenario (although it is useful for reducing latency so I'll include it - thanks for it!). Probably you were just lucky enough not to hit it in your next run. What I'd suggest is to refresholdest_jifinwb_writeback()when we do not make any progress with writeback. Thus we allow freshly dirtied inodes to be queued when we cannot make progress with the current set of inodes. The resulting patch is attached.
Refreshing oldest_jif should be safe for the background work. However there is risk of livelock for other works, as the oldest_jif test is there right for preventing livelocks..
For one thing, it will break this code:
/*
* Sync livelock prevention. Each inode is tagged and synced in
* one shot. If still dirty, it will be redirty_tail()'ed below.
* Update the dirty time to prevent enqueue and sync it again.
*/
if ((inode->i_state & I_DIRTY) &&
(wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages))
inode->dirtied_when = jiffies;Quoted 23 lines
From
b85b7cdaf5fafec2d850304c1d0b1813c1c122a3Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Thu, 8 Sep 2011 01:05:25 +0200
Subject: [PATCH 1/2] writeback: Improve busyloop preventionWriteback of an inode can be stalled by things like internal fs locks being held. So in case we didn't write anything during a pass through
b_iolist, just wait for a moment and try again. Also allow newly dirtied inodes to be queued during the retry. When retrying is fruitless for a long time, or we have some other work to do, we just stop current work to avoid blocking flusher thread.CC Christoph Hellwig <[email protected]>Reviewed-by Wu Fengguang <[email protected]>Signed-off-by Jan Kara <[email protected]>--- fs/fs-writeback.c | 61 +++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 48 insertions(+), 13 deletions(-)fs/fs-writeback.c +0
-0
fs/fs-writeback.c static long wb_writeback(struct bdi_writeback *wb, · line 706
Quoted 9 lines
fs/fs-writeback.c +4
-1@@ -699,8 +699,11 @@ static long wb_writeback(struct bdi_writeback *wb,unsigned long wb_start = jiffies;long nr_pages = work->nr_pages;unsigned long oldest_jif; -struct inode *inode;long progress; +long pause =1 ; +long max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ;
There seems no strong reasons to prefer dirty_writeback_interval over HZ. So how about use the simpler form "max_pause = HZ"?
Thanks,
Fengguang
Jan Kara
reviewerRe: [PATCH 1/2] writeback: Improve busyloop prevention
Quoted 71 lines · Wu Fengguang
Quoted 61 lines · Jan Kara
Quoted 60 lines · Wu Fengguang
Quoted 58 lines · Wu Fengguang
Quoted 16 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ long pause = 1; + long max_pause = dirty_writeback_interval ? + msecs_to_jiffies(dirty_writeback_interval * 10) : + HZ;It's better not to put the flusher to sleeps more than 10ms, so that when the condition changes, we don't risk making the storage idle for too long time.
Yeah, the one big regression case
3.1.0-rc8-ioless6a+ 3.1.0-rc8-ioless6-requeue6+ ------------------------ ------------------------ 47.07 -15.5% 39.78 thresh=1M/xfs-2dd-4k-8p-4096M-1M:10-XQuoted 6 lines
Quoted 2 lines
is exactly caused by the large sleep: the attached graphs are showing one period of no-progress on the number of written pages.
Thanks for the tests! Interesting. Do you have trace file from that run?
I see the writeback stalled for 20s or so which is more thandirty_writeback_centisecsso I think something more complicated must have happened.I noticed that
1) the global dirty limit is exceeded (dirty=286, limit=256), hence the dd tasks are hard blocked in
balance_dirty_pages().flush-8:0-1170 [004] 211.068427: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=20814472) the flusher thread is not woken up because we test
writeback_in_progress()inbalance_dirty_pages().if (unlikely(!writeback_in_progress(bdi))) bdi_start_background_writeback(bdi);Thus the flusher thread wait and wait as in below trace.
flush-8:0-1170 [004] 211.068427: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 211.068428: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 211.068428: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 211.068440: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=9 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 211.068442: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 211.068443: writeback_wait: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=backgroundflush-8:0-1170 [004] 213.110122: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 213.110126: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 213.110126: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 213.110134: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=11 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 213.110135: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 213.110135: writeback_wait: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=backgroundflush-8:0-1170 [004] 217.193470: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 217.193471: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 217.193471: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 217.193483: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=15 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 217.193485: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=backgroundQuoted 8 lines
Quoted 3 lines
It's still puzzling why dirty pages remain at 286 and does not get cleaned by either flusher threads for local XFS and NFSROOT for so long time..
I was looking at this as well. So the reason why pages were not cleaned
by the flusher thread is that there were 2 dirty inodes and the inode with dirty pages hadi_dirtied_whannewer than the time when we started this background writeback. Thus the running background writeback work always included only the other inode which has no dirty pages butI_DIRTY_SYNCset.
Quoted 6 lines
Yes that's very likely, given that the background work can run for very long time and there are still code paths to
redirty_tail()the inode.This sounds horrible -- as time goes by, more and more inodes could be excluded from the background writeback due to
inode->dirtied_whenbeing touched undesirably.
Yes, but it's not only about touching inode->i_dirtied_when. It can also
be the case that the inode started to be dirty only after we started the writeback. For example in your run, I'm pretty confident from the traces that that's what happened. This behavior can happen for a long time (I think I introduced it by 7624ee72aa09334af072853457a5d46d9901c3f8) and is a result of how we do livelock avoidance using older_than_this (or wb_start previously). Just when you don't have long-running work that cannot progress, it will be mostly hidden (only might be observable as a small inefficiency of background writeback).
Quoted 7 lines
Quoted 4 lines
Apparently XFS is stubborn and refuses to write the inode although we try rather hard. That is probably because dd writing to this inode is stuck in
balance_dirty_pages()and holds ilock - which is a bit unfortunate behavior but what can we do...Yeah, and there may well be other known or unknown long lived blocking cases. What we can do in VFS is to be not so picky on these conditions...
True.
Quoted 4 lines
To be frank I still like the
requeue_io_wait()approach. It can trivially replace _all_redity_tail()calls and hence avoid touchinginode->dirtied_when-- keeping that time stamp sane is the one thing I would really like to do.
As I pointed out above, it's not only about redirty_tail() so I belive we
should solve this problem regardless whether we use requeue_io_wait() or other busyloop prevention - do you agree with the attached patch? If yes, add it to your patch queue for the next merge window please.
BTW: I think you cannot avoid _all_ redirty_tail() calls - in situation
where inode was really redirtied you need to really redirty_tail() it. But I agree you can remove all redirty_tail() calls which are there because we failed to make any progress with the inode.
Quoted 10 lines
It also narrows down the perhaps blocked inodes and hence the need to do heuristic wait-and-retry to the minimal.
It does introduce one more list, which IMHO is more tolerable than the problems it fixed. And its max delay time can be reduced explicitly if necessary: when there are heavy dirtiers, it will quickly be woken up by
balance_dirty_pages(); in other cases we can let the kupdate work checks_more_io_waitbefore aborting to ensure 5s max delay:
Review static long wb_check_old_data_flush(stru · line 869
Quoted 8 lines
(quoted diff) +1
-1@@ -863,7 +863,7 @@ static long wb_check_old_data_flush(stru expired = wb->last_old_flush + msecs_to_jiffies(dirty_writeback_interval * 10); - if (time_before(jiffies, expired)) + if (time_before(jiffies, expired) && list_empty(&wb->b_more_io_wait)) return 0; wb->last_old_flush = jiffies;
So after seeing complications with my code I was also reconsidering your
approach. Having additional list should be OK if we document the logic of all the lists in one place in detail. So the remaining problem I have is the uncertainty when writeback will be retried. Your change above guarantees one immediate retry in case we were not doing for_kupdate writeback when filesystem refused to write the inode and the next retry in dirty_writeback_interval which seems too late. But if we trigger kupdate work earlier to retry blocked inodes, your method would be a viable alternative - something like (completely untested) second attached patch? With that I find both approaches mostly equivalent so if your passes testing and you like it more, then I'm fine with that.
Quoted 11 lines
Quoted 7 lines
I think the patch you suggest in the other email does not fix the above
scenario (although it is useful for reducing latency so I'll include it - thanks for it!). Probably you were just lucky enough not to hit it in your next run. What I'd suggest is to refresholdest_jifinwb_writeback()when we do not make any progress with writeback. Thus we allow freshly dirtied inodes to be queued when we cannot make progress with the current set of inodes. The resulting patch is attached.Refreshing
oldest_jifshould be safe for the background work. However there is risk of livelock for other works, as theoldest_jiftest is there right for preventing livelocks..
Yes, I know, I just figured that refreshing oldest_jif only when we could
not make progress (and thus we know there is no other work to do because we would break out of the loop in that case) is safe. But it is subtle and actually I've realized that refreshing oldest_jif for background writeback is enough so let's just do that.
Quoted 10 lines
For one thing, it will break this code:
/* * Sync livelock prevention. Each inode is tagged and synced in * one shot. If still dirty, it will be redirty_tail()'ed below. * Update the dirty time to prevent enqueue and sync it again. */ if ((inode->i_state & I_DIRTY) && (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)) inode->dirtied_when = jiffies;
Hum, right, but for WB_SYNC_ALL writeback filesystem should better not
refuse to writeback any inode. Other things would break horribly. And it certainly is not an issue when we refresh the timestamp only for background writeback.
Quoted 9 lines
Quoted 9 lines
fs/fs-writeback.c +0
-1@@ -699,8 +699,11 @@ static long wb_writeback(struct bdi_writeback *wb,unsigned long wb_start = jiffies;long nr_pages = work->nr_pages;unsigned long oldest_jif; -struct inode *inode;
Quoted 8 lines
fs/fs-writeback.c static long wb_writeback(struct bdi_writeback *wb, · line 706
Quoted 5 lines
fs/fs-writeback.c +4
-0long progress; +long pause =1 ; +long max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ;There seems no strong reasons to prefer
dirty_writeback_intervalover HZ. So how about use the simpler form "max_pause= HZ"?
Well, dirty_writeback_interval actually makes some sense here. It is the
interval in which user wants flusher thread to recheck dirtiness situation. So it defines latency user wants from flusher thread. Thus after this time we definitely want to break out of any work which cannot progress. If dirty_writeback_interval is shorter than 1s, we would break this by using HZ in the above code. Also I wanted to avoid introducing another magic value to writeback code when there is tunable which makes sense and can be used... I can add a comment explaining this if you want.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 1 line
From
7b559f1cea41cdba7b39138ad1637f8000e218b9Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Wed, 19 Oct 2011 11:44:41 +0200
Subject: [PATCH] writeback: Include all dirty inodes in background writeback
Current livelock avoidance code makes background work to include only inodes that were dirtied before background writeback has started. However background writeback can be running for a long time and thus excluding newly dirtied inodes can eventually exclude significant portion of dirty inodes making background writeback inefficient. Since background writeback avoids livelocking the flusher thread by yielding to any other work, there is no real reason why background work should not include all dirty inodes so change the logic in wb_writeback().
--- fs/fs-writeback.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
fs/fs-writeback.c +8 -2
@@ -730,11 +730,17 @@ static long wb_writeback(struct bdi_writeback *wb,if (work->for_background && !over_bground_thresh ())break ; +/* +* Kupdate and background works are special and we want to +* include all inodes that need writing. Livelock avoidance is +* handled by these works yielding to any other work so we are +* safe. +*/ if (work->for_kupdate) { oldest_jif = jiffies -msecs_to_jiffies (dirty_expire_interval *10 ); - work->older_than_this = &oldest_jif; - } + }else if (work->for_background) + oldest_jif = jiffies;trace_writeback_start (wb->bdi, work);if (list_empty (&wb->b_io))
Signature · 1 line
1.7.1
Quoted 1 line
From
595677f8efcaa0d9f675bf74a7048739323afd06Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Wed, 19 Oct 2011 13:44:46 +0200
Subject: [PATCH] writeback: Retry kupdate work early if we need to retry some inode writeback
In case we could not do any writeback for some inodes, trigger next kupdate work early so that writeback on these inodes is not delayed for the whole dirty_writeback_interval.
--- fs/fs-writeback.c | 25 ++++++++++++++++++------- 1 files changed, 18 insertions(+), 7 deletions(-)
fs/fs-writeback.c +18 -7
@@ -701,6 +701,7 @@ static long wb_writeback(struct bdi_writeback *wb,unsigned long oldest_jif;struct inode *inode;long progress; +long total_progress =0 ; oldest_jif = jiffies; work->older_than_this = &oldest_jif;
@@ -750,6 +751,7 @@ static long wb_writeback(struct bdi_writeback *wb,else progress =__writeback_inodes_wb (wb, work);trace_writeback_written (wb->bdi, work); + total_progress += progress;wb_update_bandwidth (wb, wb_start);
@@ -783,7 +785,7 @@ static long wb_writeback(struct bdi_writeback *wb, }spin_unlock (&wb->list_lock); -return nr_pages - work->nr_pages; +return total_progress; }/*
@@ -845,7 +847,7 @@ static long wb_check_old_data_flush(struct bdi_writeback *wb) expired = wb->last_old_flush +msecs_to_jiffies (dirty_writeback_interval *10 ); -if (time_before (jiffies, expired)) +if (time_before (jiffies, expired) &&list_empty (&wb->b_more_io_wait))return 0 ; wb->last_old_flush = jiffies;
@@ -915,7 +917,11 @@ int bdi_writeback_thread(void *data) {struct bdi_writeback *wb = data;struct backing_dev_info *bdi = wb->bdi; -long pages_written; +long progress; +unsigned int pause =1 ; +unsigned int max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ; current->flags |=PF_SWAPWRITE ;set_freezable ();
@@ -935,12 +941,14 @@ int bdi_writeback_thread(void *data)*/ del_timer (&wb->wakeup_timer); - pages_written =wb_do_writeback (wb,0 ); + progress =wb_do_writeback (wb,0 );trace_writeback_pages_written (pages_written); -if (pages_written) +if (progress) { wb->last_active = jiffies; + pause =1 ; + }set_current_state (TASK_INTERRUPTIBLE );if (!list_empty (&bdi->work_list) ||kthread_should_stop ()) {
@@ -948,8 +956,11 @@ int bdi_writeback_thread(void *data)continue ; } -if (wb_has_dirty_io (wb) && dirty_writeback_interval) -schedule_timeout (msecs_to_jiffies (dirty_writeback_interval *10 )); +if (!list_empty (&wb->b_more_io_wait) && pause < max_pause) { +schedule_timeout (pause); + pause <<=1 ; + }else if (wb_has_dirty_io (wb) && dirty_writeback_interval) +schedule_timeout (max_pause);else {/* * We have nothing to do, so can go sleep without any
Signature · 1 line
1.7.1
Re: [PATCH 1/2] writeback: Improve busyloop prevention
Quoted 75 lines · Jan Kara
Quoted 74 lines · Wu Fengguang
Quoted 61 lines · Jan Kara
Quoted 60 lines · Wu Fengguang
Quoted 58 lines · Wu Fengguang
Quoted 16 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines
fs/fs-writeback.c int bdi_writeback_thread(void *data) · line 924
Quoted 4 lines
fs/fs-writeback.c +4
-0+long pause =1 ; +long max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ;It's better not to put the flusher to sleeps more than 10ms, so that when the condition changes, we don't risk making the storage idle for too long time.
Yeah, the one big regression case
3.1.0-rc8-ioless6a+ 3.1.0-rc8-ioless6-requeue6+ ------------------------ ------------------------ 47.07 -15.5% 39.78 thresh=1M/xfs-2dd-4k-8p-4096M-1M:10-XQuoted 6 lines
Quoted 2 lines
is exactly caused by the large sleep: the attached graphs are showing one period of no-progress on the number of written pages.
Thanks for the tests! Interesting. Do you have trace file from that run?
I see the writeback stalled for 20s or so which is more thandirty_writeback_centisecsso I think something more complicated must have happened.I noticed that
1) the global dirty limit is exceeded (dirty=286, limit=256), hence the dd tasks are hard blocked in
balance_dirty_pages().flush-8:0-1170 [004] 211.068427: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=20814472) the flusher thread is not woken up because we test
writeback_in_progress()inbalance_dirty_pages().if (unlikely(!writeback_in_progress(bdi))) bdi_start_background_writeback(bdi);Thus the flusher thread wait and wait as in below trace.
flush-8:0-1170 [004] 211.068427: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 211.068428: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 211.068428: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 211.068440: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=9 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 211.068442: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 211.068443: writeback_wait: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=backgroundflush-8:0-1170 [004] 213.110122: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 213.110126: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 213.110126: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 213.110134: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=11 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 213.110135: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 213.110135: writeback_wait: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=backgroundflush-8:0-1170 [004] 217.193470: global_dirty_state: dirty=286 writeback=0 unstable=0 bg_thresh=128 thresh=256 limit=256 dirtied=2084879 written=2081447 flush-8:0-1170 [004] 217.193471: task_io: read=9216 write=12873728 cancelled_write=0 nr_dirtied=0 nr_dirtied_pause=32 flush-8:0-1170 [004] 217.193471: writeback_start: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=background flush-8:0-1170 [004] 217.193483: writeback_single_inode: bdi 8:0: ino=131 state=I_DIRTY_SYNC dirtied_when=4294869658 age=15 index=0 to_write=1024 wrote=0 flush-8:0-1170 [004] 217.193485: writeback_written: bdi 8:0: sb_dev 0:0 nr_pages=9223372036854774848 sync_mode=0 kupdate=0 range_cyclic=1 background=1 reason=backgroundQuoted 8 lines
Quoted 3 lines
It's still puzzling why dirty pages remain at 286 and does not get cleaned by either flusher threads for local XFS and NFSROOT for so long time..
I was looking at this as well. So the reason why pages were not cleaned
by the flusher thread is that there were 2 dirty inodes and the inode with dirty pages hadi_dirtied_whannewer than the time when we started this background writeback. Thus the running background writeback work always included only the other inode which has no dirty pages butI_DIRTY_SYNCset.Yes that's very likely, given that the background work can run for very long time and there are still code paths to
redirty_tail()the inode.
Quoted 7 lines
Quoted 3 lines
This sounds horrible -- as time goes by, more and more inodes could be excluded from the background writeback due to
inode->dirtied_whenbeing touched undesirably.Yes, but it's not only about touching
inode->i_dirtied_when. It can also
be the case that the inode started to be dirty only after we started the writeback. For example in your run, I'm pretty confident from the traces that that's what happened.
Yeah, that's possible because the dirty threshold is merely 1MB, and one inode could be cleaned totally (in the meanwhile the dd is throttled) and then made dirty again.
Quoted 4 lines
This behavior can happen for a long time (I
think I introduced it by7624ee72aa09334af072853457a5d46d9901c3f8) and is a result of how we do livelock avoidance usingolder_than_this(orwb_startpreviously).
I'd say that commit itself is towards the right direction. Unfortunately the writeback logic is a bit more twisted than our vision..
Quoted 3 lines
Just when you don't have long-running work that cannot progress, it will be mostly hidden (only might be observable as a small inefficiency of background writeback).
Yes.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Apparently XFS is stubborn and refuses to write the inode although we try rather hard. That is probably because dd writing to this inode is stuck in
balance_dirty_pages()and holds ilock - which is a bit unfortunate behavior but what can we do...Yeah, and there may well be other known or unknown long lived blocking cases. What we can do in VFS is to be not so picky on these conditions...
Quoted 8 lines
True.
Quoted 4 lines
To be frank I still like the
requeue_io_wait()approach. It can trivially replace _all_redity_tail()calls and hence avoid touchinginode->dirtied_when-- keeping that time stamp sane is the one thing I would really like to do.As I pointed out above, it's not only about
redirty_tail()so I belive we
should solve this problem regardless whether we userequeue_io_wait()or
Good point. Yeah we need to make the background work accept newly dirtied indoes. This could make the flusher less concentrated on the elder pages, but there seems no obvious right solution...
Quoted 2 lines
other busyloop prevention - do you agree with the attached patch? If yes, add it to your patch queue for the next merge window please.
OK, I'll think about it.
Quoted 4 lines
BTW: I think you cannot avoid _all_
redirty_tail()calls - in situation
where inode was really redirtied you need to reallyredirty_tail()it. But I agree you can remove allredirty_tail()calls which are there because we failed to make any progress with the inode.
That's right. We only convert redirty_tail(possibly blocked inode) to requeue_io_wait(). Well, in general. In the case of failed grab_super_passive(), it's not even the current inode being blocked, but _something_ get blocked. But we still have to requeue_io_wait() it to avoid busy retrying.
In the below case,
if (inode->i_sb != sb) {
if (work->sb) {
/*
* We only want to write back data for this
* superblock, move all inodes not belonging
* to it back onto the dirty list.
*/
redirty_tail(inode, wb);
continue;
}It's better off to _not_ enqueue that inode in the first place inside move_expired_inodes(). Then we can safely convert that redirty_tail() to requeue_io() to skip the irrelevant inodes already in s_io/s_more_io.
Quoted 17 lines
Quoted 17 lines
It also narrows down the perhaps blocked inodes and hence the need to do heuristic wait-and-retry to the minimal.
It does introduce one more list, which IMHO is more tolerable than the problems it fixed. And its max delay time can be reduced explicitly if necessary: when there are heavy dirtiers, it will quickly be woken up by
balance_dirty_pages(); in other cases we can let the kupdate work checks_more_io_waitbefore aborting to ensure 5s max delay:fs/fs-writeback.c +1
-1@@ -863,7 +863,7 @@ static long wb_check_old_data_flush(stru expired = wb->last_old_flush +msecs_to_jiffies (dirty_writeback_interval *10 ); -if (time_before (jiffies, expired)) +if (time_before (jiffies, expired) &&list_empty (&wb->b_more_io_wait))return 0 ;
Quoted 4 lines
fs/fs-writeback.c static long wb_check_old_data_flush(struct bdi_writeback *wb) · line 853
Quoted 1 line
fs/fs-writeback.c +0
-0wb->last_old_flush = jiffies;So after seeing complications with my code I was also reconsidering your
approach. Having additional list should be OK if we document the logic of all the lists in one place in detail.
Actually, if without the "requeue on I_SYNC" case, we can do without s_more_io_wait and still be able to prevent the unnecessary changes to dirtied_when. Because if we do requeue_io() for all inodes and still find !progress on a full iteration of b_io, we are mostly sure that the inodes remaining inside b_more_io is related to some block condition and can modify the loop break condition to consider that.
Quoted 7 lines
So the remaining problem I have is
the uncertainty when writeback will be retried. Your change above guarantees one immediate retry in case we were not doingfor_kupdatewriteback when filesystem refused to write the inode and the next retry indirty_writeback_intervalwhich seems too late. But if we trigger kupdate work earlier to retry blocked inodes, your method would be a viable alternative - something like (completely untested) second attached patch?
Yeah! I have a similar patch for shortening the retry interval from dirty_writeback_interval=5s to dirty_writeback_interval/10=500ms:
@@ -967,9 +967,14 @@ int bdi_writeback_thread(void *data)
continue;
}- if (wb_has_dirty_io(wb) && dirty_writeback_interval)
- schedule_timeout(msecs_to_jiffies(dirty_writeback_interval * 10));
- else {
+ if (wb_has_dirty_io(wb) && dirty_writeback_interval) {
+ unsigned long t;
+ if (!list_empty(&wb->b_more_io_wait))
+ t = msecs_to_jiffies(dirty_writeback_interval);
+ else
+ t = msecs_to_jiffies(dirty_writeback_interval * 10);
+ schedule_timeout(t);
+ } else {
/*
* We have nothing to do, so can go sleep without any
* timeout and save power. When a work is queued or
However your adaptive sleep seems better, and it also covers the dirty_writeback_interval=0 case.
Quoted 2 lines
With that I find both approaches mostly equivalent so if your passes testing and you like it more, then I'm fine with that.
OK, thanks!
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
I think the patch you suggest in the other email does not fix the above
scenario (although it is useful for reducing latency so I'll include it - thanks for it!). Probably you were just lucky enough not to hit it in your next run. What I'd suggest is to refresholdest_jifinwb_writeback()when we do not make any progress with writeback. Thus we allow freshly dirtied inodes to be queued when we cannot make progress with the current set of inodes. The resulting patch is attached.
Quoted 8 lines
Quoted 3 lines
Refreshing
oldest_jifshould be safe for the background work. However there is risk of livelock for other works, as theoldest_jiftest is there right for preventing livelocks..Yes, I know, I just figured that refreshing
oldest_jifonly when we could
not make progress (and thus we know there is no other work to do because we would break out of the loop in that case) is safe. But it is subtle and actually I've realized that refreshingoldest_jiffor background writeback is enough so let's just do that.
OK.
Quoted 10 lines
Quoted 10 lines
For one thing, it will break this code:
/* * Sync livelock prevention. Each inode is tagged and synced in * one shot. If still dirty, it will be redirty_tail()'ed below. * Update the dirty time to prevent enqueue and sync it again. */ if ((inode->i_state & I_DIRTY) && (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)) inode->dirtied_when = jiffies;
Quoted 4 lines
Hum, right, but for
WB_SYNC_ALLwriteback filesystem should better not
refuse to writeback any inode. Other things would break horribly. And it certainly is not an issue when we refresh the timestamp only for background writeback.
Ah yes!
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
fs/fs-writeback.c +0
-1@@ -699,8 +699,11 @@ static long wb_writeback(struct bdi_writeback *wb,unsigned long wb_start = jiffies;long nr_pages = work->nr_pages;unsigned long oldest_jif; -struct inode *inode;Quoted 8 lines
fs/fs-writeback.c static long wb_writeback(struct bdi_writeback *wb, · line 706
Quoted 5 lines
fs/fs-writeback.c +4
-0long progress; +long pause =1 ; +long max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ;There seems no strong reasons to prefer
dirty_writeback_intervalover HZ. So how about use the simpler form "max_pause= HZ"?
Quoted 8 lines
Well,
dirty_writeback_intervalactually makes some sense here. It is the
interval in which user wants flusher thread to recheck dirtiness situation. So it defines latency user wants from flusher thread. Thus after this time we definitely want to break out of any work which cannot progress. Ifdirty_writeback_intervalis shorter than 1s, we would break this by using HZ in the above code. Also I wanted to avoid introducing another magic value to writeback code when there is tunable which makes sense and can be used... I can add a comment explaining this if you want.
Good point.
Thanks,
Fengguang
Re: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Jan KaraQuoted 5 lines
From
7b559f1cea41cdba7b39138ad1637f8000e218b9Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Wed, 19 Oct 2011 11:44:41 +0200
Subject: [PATCH] writeback: Include all dirty inodes in background writeback
Quoted 8 lines
Current livelock avoidance code makes background work to include only inodes that were dirtied before background writeback has started. However background writeback can be running for a long time and thus excluding newly dirtied inodes can eventually exclude significant portion of dirty inodes making background writeback inefficient. Since background writeback avoids livelocking the flusher thread by yielding to any other work, there is no real reason why background work should not include all dirty inodes so change the logic in
wb_writeback().
Looks good to me. Thanks!
Quoted 32 lines
Signed-off-by Jan Kara <[email protected]>--- fs/fs-writeback.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)fs/fs-writeback.c +8
-2@@ -730,11 +730,17 @@ static long wb_writeback(struct bdi_writeback *wb,if (work->for_background && !over_bground_thresh ())break ; +/* +* Kupdate and background works are special and we want to +* include all inodes that need writing. Livelock avoidance is +* handled by these works yielding to any other work so we are +* safe. +*/ if (work->for_kupdate) { oldest_jif = jiffies -msecs_to_jiffies (dirty_expire_interval *10 ); - work->older_than_this = &oldest_jif; - } + }else if (work->for_background) + oldest_jif = jiffies;trace_writeback_start (wb->bdi, work);if (list_empty (&wb->b_io))Signature · 1 line
1.7.1
Re: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Jan KaraQuoted 8 lines
From
595677f8efcaa0d9f675bf74a7048739323afd06Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Wed, 19 Oct 2011 13:44:46 +0200
Subject: [PATCH] writeback: Retry kupdate work early if we need to retry some inode writebackIn case we could not do any writeback for some inodes, trigger next kupdate work early so that writeback on these inodes is not delayed for the whole
dirty_writeback_interval.
Looks good, too.
Quoted 44 lines
Signed-off-by Jan Kara <[email protected]>--- fs/fs-writeback.c | 25 ++++++++++++++++++------- 1 files changed, 18 insertions(+), 7 deletions(-)fs/fs-writeback.c +4
-2@@ -701,6 +701,7 @@ static long wb_writeback(struct bdi_writeback *wb,unsigned long oldest_jif;struct inode *inode;long progress; +long total_progress =0 ; oldest_jif = jiffies; work->older_than_this = &oldest_jif;@@ -750,6 +751,7 @@ static long wb_writeback(struct bdi_writeback *wb,else progress =__writeback_inodes_wb (wb, work);trace_writeback_written (wb->bdi, work); + total_progress += progress;wb_update_bandwidth (wb, wb_start);@@ -783,7 +785,7 @@ static long wb_writeback(struct bdi_writeback *wb, }spin_unlock (&wb->list_lock); -return nr_pages - work->nr_pages; +return total_progress; }/* @@ -845,7 +847,7 @@ static long wb_check_old_data_flush(struct bdi_writeback *wb) expired = wb->last_old_flush +msecs_to_jiffies (dirty_writeback_interval *10 ); -if (time_before (jiffies, expired)) +if (time_before (jiffies, expired) &&list_empty (&wb->b_more_io_wait))return 0 ; wb->last_old_flush = jiffies;
fs/fs-writeback.c int bdi_writeback_thread(void *data) · line 920
Quoted 5 lines
fs/fs-writeback.c +1
-1@@ -915,7 +917,11 @@ int bdi_writeback_thread(void *data) {struct bdi_writeback *wb = data;struct backing_dev_info *bdi = wb->bdi; -long pages_written; +long progress;
I'd like to separate out the pages_written=>progress changes, which will make two more clear patches.
Thanks,
Fengguang
Quoted 41 lines
fs/fs-writeback.c +13
-4+unsigned int pause =1 ; +unsigned int max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ; current->flags |=PF_SWAPWRITE ;set_freezable ();@@ -935,12 +941,14 @@ int bdi_writeback_thread(void *data)*/ del_timer (&wb->wakeup_timer); - pages_written =wb_do_writeback (wb,0 ); + progress =wb_do_writeback (wb,0 );trace_writeback_pages_written (pages_written); -if (pages_written) +if (progress) { wb->last_active = jiffies; + pause =1 ; + }set_current_state (TASK_INTERRUPTIBLE );if (!list_empty (&bdi->work_list) ||kthread_should_stop ()) {@@ -948,8 +956,11 @@ int bdi_writeback_thread(void *data)continue ; } -if (wb_has_dirty_io (wb) && dirty_writeback_interval) -schedule_timeout (msecs_to_jiffies (dirty_writeback_interval *10 )); +if (!list_empty (&wb->b_more_io_wait) && pause < max_pause) { +schedule_timeout (pause); + pause <<=1 ; + }else if (wb_has_dirty_io (wb) && dirty_writeback_interval) +schedule_timeout (max_pause);else {/* * We have nothing to do, so can go sleep without any Signature · 1 line
1.7.1
Re: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Jan KaraQuoted 12 lines · Jan Kara
Quoted 3 lines
It's still puzzling why dirty pages remain at 286 and does not get cleaned by either flusher threads for local XFS and NFSROOT for so long time..
I was looking at this as well. So the reason why pages were not cleaned
by the flusher thread is that there were 2 dirty inodes and the inode with dirty pages hadi_dirtied_whannewer than the time when we started this background writeback. Thus the running background writeback work always included only the other inode which has no dirty pages butI_DIRTY_SYNCset. Apparently XFS is stubborn and refuses to write the inode although we try rather hard. That is probably because dd writing to this inode is stuck inbalance_dirty_pages()and holds ilock - which is a bit unfortunate behavior but what can we do...
Stop writing data from balance_dirty_pages()?
Anyway, XFS tries very hard to not block in a non-block ->write_inode or ->writepages, which generally is a good thing to avoid getting stuck in the flusher thread. For cases like this where an inode is long beyond it's due time it might make sense to simply do a synchronous write_inode from the flusher thread to force the inode out.
Re: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Jan KaraJan,
I tried the below combined patch over the ioless one, and find some minor regressions. I studied the thresh=1G/ext3-1dd case in particular and find that nr_writeback and the iostat avgrq-sz drops from time to time.
I'll try to bisect the changeset.
3.1.0-rc9-ioless-full-next-20111014+ 3.1.0-rc9-ioless-full-more_io_wait-next-20111014+ ------------------------ ------------------------
56.47 -0.6% 56.13 thresh=100M/btrfs-10dd-4k-8p-4096M-100M:10-X
56.28 -0.4% 56.07 thresh=100M/btrfs-1dd-4k-8p-4096M-100M:10-X
56.11 -0.1% 56.05 thresh=100M/btrfs-2dd-4k-8p-4096M-100M:10-X
37.86 +1.8% 38.54 thresh=100M/ext3-10dd-4k-8p-4096M-100M:10-X
45.91 +0.7% 46.22 thresh=100M/ext3-1dd-4k-8p-4096M-100M:10-X
41.87 +0.8% 42.19 thresh=100M/ext3-2dd-4k-8p-4096M-100M:10-X
45.68 -0.4% 45.50 thresh=100M/ext4-10dd-4k-8p-4096M-100M:10-X
55.74 -2.2% 54.51 thresh=100M/ext4-1dd-4k-8p-4096M-100M:10-X
46.20 -4.8% 43.98 thresh=100M/xfs-10dd-4k-8p-4096M-100M:10-X
55.72 +0.1% 55.76 thresh=100M/xfs-1dd-4k-8p-4096M-100M:10-X
54.01 -2.0% 52.94 thresh=100M/xfs-2dd-4k-8p-4096M-100M:10-X
55.08 -1.0% 54.52 thresh=1G/btrfs-100dd-4k-8p-4096M-1024M:10-X
55.49 -1.0% 54.94 thresh=1G/btrfs-10dd-4k-8p-4096M-1024M:10-X
55.38 -2.7% 53.91 thresh=1G/btrfs-1dd-4k-8p-4096M-1024M:10-X
36.70 -1.5% 36.15 thresh=1G/ext3-100dd-4k-8p-4096M-1024M:10-X
40.64 -5.9% 38.25 thresh=1G/ext3-10dd-4k-8p-4096M-1024M:10-X
48.65 -6.9% 45.30 thresh=1G/ext3-1dd-4k-8p-4096M-1024M:10-X
49.84 -3.2% 48.23 thresh=1G/ext4-100dd-4k-8p-4096M-1024M:10-X
56.03 -3.3% 54.21 thresh=1G/ext4-10dd-4k-8p-4096M-1024M:10-X
57.42 -2.3% 56.07 thresh=1G/ext4-1dd-4k-8p-4096M-1024M:10-X
45.74 -1.4% 45.12 thresh=1G/xfs-100dd-4k-8p-4096M-1024M:10-X
54.19 -0.5% 53.94 thresh=1G/xfs-10dd-4k-8p-4096M-1024M:10-X
55.93 -0.5% 55.66 thresh=1G/xfs-1dd-4k-8p-4096M-1024M:10-X
2.77 +27.8% 3.54 thresh=1M/btrfs-10dd-4k-8p-4096M-1M:10-X
2.20 -15.5% 1.86 thresh=1M/btrfs-1dd-4k-8p-4096M-1M:10-X
2.42 -1.3% 2.39 thresh=1M/btrfs-2dd-4k-8p-4096M-1M:10-X
28.91 +1.9% 29.47 thresh=1M/ext3-10dd-4k-8p-4096M-1M:10-X
45.02 +1.1% 45.50 thresh=1M/ext3-1dd-4k-8p-4096M-1M:10-X
40.91 +0.4% 41.09 thresh=1M/ext3-2dd-4k-8p-4096M-1M:10-X
31.82 +2.3% 32.56 thresh=1M/ext4-10dd-4k-8p-4096M-1M:10-X
52.33 -0.9% 51.85 thresh=1M/ext4-1dd-4k-8p-4096M-1M:10-X
28.43 +1.2% 28.77 thresh=1M/xfs-10dd-4k-8p-4096M-1M:10-X
52.93 -3.8% 50.90 thresh=1M/xfs-1dd-4k-8p-4096M-1M:10-X
46.87 -0.0% 46.85 thresh=1M/xfs-2dd-4k-8p-4096M-1M:10-X
54.54 -1.3% 53.82 thresh=8M/btrfs-10dd-4k-8p-4096M-8M:10-X
56.60 -1.4% 55.80 thresh=8M/btrfs-1dd-4k-8p-4096M-8M:10-X
56.21 -0.4% 55.96 thresh=8M/btrfs-2dd-4k-8p-4096M-8M:10-X
32.54 +0.2% 32.62 thresh=8M/ext3-10dd-4k-8p-4096M-8M:10-X
46.01 -1.0% 45.55 thresh=8M/ext3-1dd-4k-8p-4096M-8M:10-X
44.13 -0.6% 43.87 thresh=8M/ext3-2dd-4k-8p-4096M-8M:10-X
35.78 -0.4% 35.63 thresh=8M/ext4-10dd-4k-8p-4096M-8M:10-X
55.29 +0.2% 55.38 thresh=8M/ext4-1dd-4k-8p-4096M-8M:10-X
31.21 -0.8% 30.96 thresh=8M/xfs-10dd-4k-8p-4096M-8M:10-X
54.10 -0.3% 53.95 thresh=8M/xfs-1dd-4k-8p-4096M-8M:10-X
46.97 +0.5% 47.20 thresh=8M/xfs-2dd-4k-8p-4096M-8M:10-X
2010.92 -1.1% 1989.70 TOTAL write_bwfs/fs-writeback.c +50 -16
@@ -234,6 +234,15 @@ static void requeue_io(struct inode *inolist_move (&inode->i_wb_list, &wb->b_more_io); } +/* +* The inode should be retried in an opportunistic way. +*/ +static void requeue_io_wait (struct inode *inode,struct bdi_writeback *wb) +{ +assert_spin_locked (&wb->list_lock); +list_move (&inode->i_wb_list, &wb->b_more_io_wait); +} +static void inode_sync_complete (struct inode *inode) {/*
@@ -321,6 +330,7 @@ static void queue_io(struct bdi_writebacint moved;assert_spin_locked (&wb->list_lock);list_splice_init (&wb->b_more_io, &wb->b_io); +list_splice_init (&wb->b_more_io_wait, &wb->b_io); moved =move_expired_inodes (&wb->b_dirty, &wb->b_io, work);trace_writeback_queue_io (wb, work, moved); }
@@ -470,7 +480,7 @@ writeback_single_inode(struct inode *ino* retrying writeback of the dirty page/inode * that cannot be performed immediately. */ -redirty_tail (inode, wb); +requeue_io_wait (inode, wb); } }else if (inode->i_state &I_DIRTY ) {/*
@@ -478,8 +488,18 @@ writeback_single_inode(struct inode *ino* operations, such as delayed allocation during * submission or metadata updates after data IO * completion. +* +* For the latter case it is very important to give +* the inode another turn on b_more_io instead of +* redirtying it. Constantly moving dirtied_when +* forward will prevent us from ever writing out +* the metadata dirtied in the I/O completion handler. +* +* For files on XFS that constantly get appended to +* calling redirty_tail means they will never get +* their updated i_size written out. */ -redirty_tail (inode, wb); +requeue_io_wait (inode, wb); }else {/* * The inode is clean. At this point we either have
@@ -600,7 +620,7 @@ static long writeback_sb_inodes(struct s* writeback is not making progress due to locked * buffers. Skip this inode for now. */ -redirty_tail (inode, wb); +requeue_io_wait (inode, wb); }spin_unlock (&inode->i_lock);spin_unlock (&wb->list_lock);
@@ -637,7 +657,7 @@ static long __writeback_inodes_wb(struct* s_umount being grabbed by someone else. Don't use * requeue_io() to avoid busy retrying the inode/sb. */ -redirty_tail (inode, wb); +requeue_io_wait (inode, wb);continue ; } wrote +=writeback_sb_inodes (sb, wb, work);
@@ -720,10 +740,10 @@ static long wb_writeback(struct bdi_writ struct wb_writeback_work *work) {unsigned long wb_start = jiffies; -long nr_pages = work->nr_pages;unsigned long oldest_jif;struct inode *inode;long progress; +long total_progress =0 ; oldest_jif = jiffies; work->older_than_this = &oldest_jif;
@@ -753,11 +773,17 @@ static long wb_writeback(struct bdi_writif (work->for_background && !over_bground_thresh (wb->bdi))break ; +/* +* Kupdate and background works are special and we want to +* include all inodes that need writing. Livelock avoidance is +* handled by these works yielding to any other work so we are +* safe. +*/ if (work->for_kupdate) { oldest_jif = jiffies -msecs_to_jiffies (dirty_expire_interval *10 ); - work->older_than_this = &oldest_jif; - } + }else if (work->for_background) + oldest_jif = jiffies;trace_writeback_start (wb->bdi, work);if (list_empty (&wb->b_io))
@@ -767,6 +793,7 @@ static long wb_writeback(struct bdi_writelse progress =__writeback_inodes_wb (wb, work);trace_writeback_written (wb->bdi, work); + total_progress += progress;wb_update_bandwidth (wb, wb_start);
@@ -800,7 +827,7 @@ static long wb_writeback(struct bdi_writ }spin_unlock (&wb->list_lock); -return nr_pages - work->nr_pages; +return total_progress; }/*
@@ -863,7 +890,7 @@ static long wb_check_old_data_flush(stru expired = wb->last_old_flush +msecs_to_jiffies (dirty_writeback_interval *10 ); -if (time_before (jiffies, expired)) +if (time_before (jiffies, expired) &&list_empty (&wb->b_more_io_wait))return 0 ; wb->last_old_flush = jiffies;
@@ -934,7 +961,11 @@ int bdi_writeback_thread(void *data) {struct bdi_writeback *wb = data;struct backing_dev_info *bdi = wb->bdi; -long pages_written; +long progress; +unsigned int pause =1 ; +unsigned int max_pause = dirty_writeback_interval ? +msecs_to_jiffies (dirty_writeback_interval *10 ) : +HZ ; current->flags |=PF_SWAPWRITE ;set_freezable ();
@@ -954,12 +985,12 @@ int bdi_writeback_thread(void *data)*/ del_timer (&wb->wakeup_timer); - pages_written =wb_do_writeback (wb,0 ); + progress =wb_do_writeback (wb,0 ); -trace_writeback_pages_written (pages_written); - -if (pages_written) +if (progress) { wb->last_active = jiffies; + pause =1 ; + }set_current_state (TASK_INTERRUPTIBLE );if (!list_empty (&bdi->work_list) ||kthread_should_stop ()) {
@@ -967,8 +998,11 @@ int bdi_writeback_thread(void *data)continue ; } -if (wb_has_dirty_io (wb) && dirty_writeback_interval) -schedule_timeout (msecs_to_jiffies (dirty_writeback_interval *10 )); +if (!list_empty (&wb->b_more_io_wait) && pause < max_pause) { +schedule_timeout (pause); + pause <<=1 ; + }else if (wb_has_dirty_io (wb) && dirty_writeback_interval) +schedule_timeout (max_pause);else {/* * We have nothing to do, so can go sleep without any
include/linux/backing-dev.h +5 -3
@@ -59,6 +59,7 @@ struct bdi_writeback {struct list_head b_dirty;/* dirty inodes */ struct list_head b_io;/* parked for writeback */ struct list_head b_more_io;/* parked for more writeback */ +struct list_head b_more_io_wait;/* opportunistic retry io */ spinlock_t list_lock;/* protects the b_* lists */ };
@@ -133,9 +134,10 @@ extern struct list_head bdi_pending_liststatic inline int wb_has_dirty_io (struct bdi_writeback *wb) { -return !list_empty (&wb->b_dirty) || - !list_empty (&wb->b_io) || - !list_empty (&wb->b_more_io); +return !list_empty (&wb->b_dirty) || + !list_empty (&wb->b_io) || + !list_empty (&wb->b_more_io) || + !list_empty (&wb->b_more_io_wait); } static inline void __add_bdi_stat(struct backing_dev_info *bdi,
mm/backing-dev.c +8 -2
@@ -74,10 +74,10 @@ static int bdi_debug_stats_show(struct sunsigned long background_thresh;unsigned long dirty_thresh;unsigned long bdi_thresh; -unsigned long nr_dirty, nr_io, nr_more_io; +unsigned long nr_dirty, nr_io, nr_more_io, nr_more_io_wait;struct inode *inode; - nr_dirty = nr_io = nr_more_io =0 ; + nr_dirty = nr_io = nr_more_io = nr_more_io_wait =0 ;spin_lock (&wb->list_lock);list_for_each_entry (inode, &wb->b_dirty, i_wb_list) nr_dirty++;
@@ -85,6 +85,8 @@ static int bdi_debug_stats_show(struct s nr_io++;list_for_each_entry (inode, &wb->b_more_io, i_wb_list) nr_more_io++; +list_for_each_entry (inode, &wb->b_more_io_wait, i_wb_list) + nr_more_io_wait++;spin_unlock (&wb->list_lock);global_dirty_limits (&background_thresh, &dirty_thresh);
@@ -103,6 +105,7 @@ static int bdi_debug_stats_show(struct s"b_dirty: %10lu\n" "b_io: %10lu\n" "b_more_io: %10lu\n" +"b_more_io_wait: %10lu\n" "bdi_list: %10u\n" "state: %10lx\n" , (unsigned long) K(bdi_stat(bdi, BDI_WRITEBACK)),
@@ -116,6 +119,7 @@ static int bdi_debug_stats_show(struct s nr_dirty, nr_io, nr_more_io, + nr_more_io_wait, !list_empty(&bdi->bdi_list), bdi->state);#undef K
@@ -651,6 +655,7 @@ static void bdi_wb_init(struct bdi_writeINIT_LIST_HEAD (&wb->b_dirty);INIT_LIST_HEAD (&wb->b_io);INIT_LIST_HEAD (&wb->b_more_io); +INIT_LIST_HEAD (&wb->b_more_io_wait);spin_lock_init (&wb->list_lock);setup_timer (&wb->wakeup_timer, wakeup_timer_fn, (unsigned long )bdi); }
@@ -718,6 +723,7 @@ void bdi_destroy(struct backing_dev_infolist_splice (&bdi->wb.b_dirty, &dst->b_dirty);list_splice (&bdi->wb.b_io, &dst->b_io);list_splice (&bdi->wb.b_more_io, &dst->b_more_io); +list_splice (&bdi->wb.b_more_io_wait, &dst->b_more_io_wait);spin_unlock (&bdi->wb.list_lock);spin_unlock (&dst->list_lock); }
Re: [PATCH 1/2] writeback: Improve busyloop prevention
Quoted 7 lines · Wu Fengguang
Jan,
I tried the below combined patch over the ioless one, and find some minor regressions. I studied the thresh=1G/ext3-1dd case in particular and find that
nr_writebackand the iostat avgrq-sz drops from time to time.I'll try to bisect the changeset.
Current finding is, performance is restored if only applying this:
fs/fs-writeback.c +21 -1
@@ -234,6 +234,15 @@ static void requeue_io(struct inode *inolist_move (&inode->i_wb_list, &wb->b_more_io); } +/* +* The inode should be retried in an opportunistic way. +*/ +static void requeue_io_wait (struct inode *inode,struct bdi_writeback *wb) +{ +assert_spin_locked (&wb->list_lock); +list_move (&inode->i_wb_list, &wb->b_more_io_wait); +} +static void inode_sync_complete (struct inode *inode) {/*
@@ -321,6 +330,7 @@ static void queue_io(struct bdi_writebacint moved;assert_spin_locked (&wb->list_lock);list_splice_init (&wb->b_more_io, &wb->b_io); +list_splice_init (&wb->b_more_io_wait, &wb->b_io); moved =move_expired_inodes (&wb->b_dirty, &wb->b_io, work);trace_writeback_queue_io (wb, work, moved); }
@@ -478,8 +488,18 @@ writeback_single_inode(struct inode *ino* operations, such as delayed allocation during * submission or metadata updates after data IO * completion. +* +* For the latter case it is very important to give +* the inode another turn on b_more_io instead of +* redirtying it. Constantly moving dirtied_when +* forward will prevent us from ever writing out +* the metadata dirtied in the I/O completion handler. +* +* For files on XFS that constantly get appended to +* calling redirty_tail means they will never get +* their updated i_size written out. */ -redirty_tail (inode, wb); +requeue_io_wait (inode, wb); }else {/* * The inode is clean. At this point we either have
include/linux/backing-dev.h +5 -3
@@ -59,6 +59,7 @@ struct bdi_writeback {struct list_head b_dirty;/* dirty inodes */ struct list_head b_io;/* parked for writeback */ struct list_head b_more_io;/* parked for more writeback */ +struct list_head b_more_io_wait;/* opportunistic retry io */ spinlock_t list_lock;/* protects the b_* lists */ };
@@ -133,9 +134,10 @@ extern struct list_head bdi_pending_liststatic inline int wb_has_dirty_io (struct bdi_writeback *wb) { -return !list_empty (&wb->b_dirty) || - !list_empty (&wb->b_io) || - !list_empty (&wb->b_more_io); +return !list_empty (&wb->b_dirty) || + !list_empty (&wb->b_io) || + !list_empty (&wb->b_more_io) || + !list_empty (&wb->b_more_io_wait); } static inline void __add_bdi_stat(struct backing_dev_info *bdi,
mm/backing-dev.c +8 -2
@@ -74,10 +74,10 @@ static int bdi_debug_stats_show(struct sunsigned long background_thresh;unsigned long dirty_thresh;unsigned long bdi_thresh; -unsigned long nr_dirty, nr_io, nr_more_io; +unsigned long nr_dirty, nr_io, nr_more_io, nr_more_io_wait;struct inode *inode; - nr_dirty = nr_io = nr_more_io =0 ; + nr_dirty = nr_io = nr_more_io = nr_more_io_wait =0 ;spin_lock (&wb->list_lock);list_for_each_entry (inode, &wb->b_dirty, i_wb_list) nr_dirty++;
@@ -85,6 +85,8 @@ static int bdi_debug_stats_show(struct s nr_io++;list_for_each_entry (inode, &wb->b_more_io, i_wb_list) nr_more_io++; +list_for_each_entry (inode, &wb->b_more_io_wait, i_wb_list) + nr_more_io_wait++;spin_unlock (&wb->list_lock);global_dirty_limits (&background_thresh, &dirty_thresh);
@@ -103,6 +105,7 @@ static int bdi_debug_stats_show(struct s"b_dirty: %10lu\n" "b_io: %10lu\n" "b_more_io: %10lu\n" +"b_more_io_wait: %10lu\n" "bdi_list: %10u\n" "state: %10lx\n" , (unsigned long) K(bdi_stat(bdi, BDI_WRITEBACK)),
@@ -116,6 +119,7 @@ static int bdi_debug_stats_show(struct s nr_dirty, nr_io, nr_more_io, + nr_more_io_wait, !list_empty(&bdi->bdi_list), bdi->state);#undef K
@@ -651,6 +655,7 @@ static void bdi_wb_init(struct bdi_writeINIT_LIST_HEAD (&wb->b_dirty);INIT_LIST_HEAD (&wb->b_io);INIT_LIST_HEAD (&wb->b_more_io); +INIT_LIST_HEAD (&wb->b_more_io_wait);spin_lock_init (&wb->list_lock);setup_timer (&wb->wakeup_timer, wakeup_timer_fn, (unsigned long )bdi); }
@@ -718,6 +723,7 @@ void bdi_destroy(struct backing_dev_infolist_splice (&bdi->wb.b_dirty, &dst->b_dirty);list_splice (&bdi->wb.b_io, &dst->b_io);list_splice (&bdi->wb.b_more_io, &dst->b_more_io); +list_splice (&bdi->wb.b_more_io_wait, &dst->b_more_io_wait);spin_unlock (&bdi->wb.list_lock);spin_unlock (&dst->list_lock); }
Re: [PATCH 1/2] writeback: Improve busyloop prevention
Quoted 8 lines · Wu Fengguang
Quoted 7 lines · Wu Fengguang
Jan,
I tried the below combined patch over the ioless one, and find some minor regressions. I studied the thresh=1G/ext3-1dd case in particular and find that
nr_writebackand the iostat avgrq-sz drops from time to time.I'll try to bisect the changeset.
This is interesting, the culprit is found to be patch 1, which is simply
if (work->for_kupdate) {
oldest_jif = jiffies -
msecs_to_jiffies(dirty_expire_interval * 10);- work->older_than_this = &oldest_jif;
- }
+ } else if (work->for_background)
+ oldest_jif = jiffies;
Thanks,
Fengguang
Jan Kara
reviewerRe: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Christoph HellwigQuoted 14 lines · Christoph Hellwig
Quoted 12 lines · Jan Kara
Quoted 3 lines
It's still puzzling why dirty pages remain at 286 and does not get cleaned by either flusher threads for local XFS and NFSROOT for so long time..
I was looking at this as well. So the reason why pages were not cleaned
by the flusher thread is that there were 2 dirty inodes and the inode with dirty pages hadi_dirtied_whannewer than the time when we started this background writeback. Thus the running background writeback work always included only the other inode which has no dirty pages butI_DIRTY_SYNCset. Apparently XFS is stubborn and refuses to write the inode although we try rather hard. That is probably because dd writing to this inode is stuck inbalance_dirty_pages()and holds ilock - which is a bit unfortunate behavior but what can we do...
Quoted 1 line
Stop writing data from
balance_dirty_pages()?
Well, this was also with Fengguang's IO-less patches so writing frombalance_dirty_pages() was not an issue.
Quoted 5 lines
Anyway, XFS tries very hard to not block in a non-block ->write_inode or ->writepages, which generally is a good thing to avoid getting stuck in the flusher thread. For cases like this where an inode is long beyond it's due time it might make sense to simply do a synchronous
write_inodefrom the flusher thread to force the inode out.
Yeah, that might be a good option.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
reviewerRe: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Wu FengguangQuoted 15 lines · Wu Fengguang
Quoted 8 lines · Wu Fengguang
Quoted 7 lines · Wu Fengguang
Jan,
I tried the below combined patch over the ioless one, and find some minor regressions. I studied the thresh=1G/ext3-1dd case in particular and find that
nr_writebackand the iostat avgrq-sz drops from time to time.I'll try to bisect the changeset.
This is interesting, the culprit is found to be patch 1, which is simply
if (work->for_kupdate) { oldest_jif = jiffies - msecs_to_jiffies(dirty_expire_interval * 10);
Review
Quoted 4 lines
(quoted diff) +2
-2- work->older_than_this = &oldest_jif; - } + } else if (work->for_background) + oldest_jif = jiffies;
Yeah. I had a look into the trace and you can notice that during the
whole dd run, we were running a single background writeback work (you can verify that by work->nr_pages decreasing steadily). Without refreshing oldest_jif, we'd write block device inode for /dev/sda (you can identify that by bdi=8:0, ino=0) only once. When refreshing oldest_jif, we write it every 5 seconds (kjournald dirties the device inode after committing a transaction by dirtying metadata buffers which were just committed and can now be checkpointed either by kjournald or flusher thread). So although the performance is slightly reduced, I'd say that the behavior is a desired one.
Also if you observed the performance on a really long run, the difference should get smaller because eventually, kjournald has to flush the metadata blocks when the journal fills up and we need to free some journal space and at that point flushing is even more expensive because we have to do a blocking write during which all transaction operations, thus effectively the whole filesystem, are blocked.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 1/2] writeback: Improve busyloop prevention
Quoted 20 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines · Wu Fengguang
Quoted 7 lines · Wu Fengguang
Jan,
I tried the below combined patch over the ioless one, and find some minor regressions. I studied the thresh=1G/ext3-1dd case in particular and find that
nr_writebackand the iostat avgrq-sz drops from time to time.I'll try to bisect the changeset.
This is interesting, the culprit is found to be patch 1, which is simply
if (work->for_kupdate) { oldest_jif = jiffies - msecs_to_jiffies(dirty_expire_interval * 10);Review
Quoted 4 lines
(quoted diff) +2
-2- work->older_than_this = &oldest_jif; - } + } else if (work->for_background) + oldest_jif = jiffies;
Quoted 3 lines
Yeah. I had a look into the trace and you can notice that during the
whole dd run, we were running a single background writeback work (you can verify that bywork->nr_pagesdecreasing steadily).
Yes, it is.
Quoted 6 lines
Without refreshing
oldest_jif, we'd write block device inode for/dev/sda(you can identify that by bdi=8:0, ino=0) only once. When refreshingoldest_jif, we write it every 5 seconds (kjournald dirties the device inode after committing a transaction by dirtying metadata buffers which were just committed and can now be checkpointed either by kjournald or flusher thread).
OK, now I understand the regular drops of nr_writeback and avgrq-sz:
on every 5s, it takes _some time_ to write inode 0, during which the flusher is blocked and the IO queue runs low.
Quoted 2 lines
So although the performance is slightly reduced, I'd say that the behavior is a desired one.
OK. However it's sad to see the flusher get blocked from time to time...
Quoted 6 lines
Also if you observed the performance on a really long run, the difference should get smaller because eventually, kjournald has to flush the metadata blocks when the journal fills up and we need to free some journal space and at that point flushing is even more expensive because we have to do a blocking write during which all transaction operations, thus effectively the whole filesystem, are blocked.
OK. The dd test time was 300s, I'll increase it to 900s (cannot do more because it's a 90GB disk partition).
Thanks,
Fengguang
Jan Kara
reviewerRe: [PATCH 1/2] writeback: Improve busyloop prevention
Quoted 34 lines · Wu Fengguang
Quoted 20 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines · Wu Fengguang
Quoted 7 lines · Wu Fengguang
Jan,
I tried the below combined patch over the ioless one, and find some minor regressions. I studied the thresh=1G/ext3-1dd case in particular and find that
nr_writebackand the iostat avgrq-sz drops from time to time.I'll try to bisect the changeset.
This is interesting, the culprit is found to be patch 1, which is simply
if (work->for_kupdate) { oldest_jif = jiffies - msecs_to_jiffies(dirty_expire_interval * 10);Review
Quoted 4 lines
(quoted diff) +2
-2- work->older_than_this = &oldest_jif; - } + } else if (work->for_background) + oldest_jif = jiffies;Quoted 3 lines
Yeah. I had a look into the trace and you can notice that during the
whole dd run, we were running a single background writeback work (you can verify that bywork->nr_pagesdecreasing steadily).Yes, it is.
Quoted 6 lines
Without refreshing
oldest_jif, we'd write block device inode for/dev/sda(you can identify that by bdi=8:0, ino=0) only once. When refreshingoldest_jif, we write it every 5 seconds (kjournald dirties the device inode after committing a transaction by dirtying metadata buffers which were just committed and can now be checkpointed either by kjournald or flusher thread).
Quoted 8 lines
OK, now I understand the regular drops of
nr_writebackand avgrq-sz:
on every 5s, it takes_sometime_to write inode 0, during which the flusher is blocked and the IO queue runs low.Quoted 2 lines
So although the performance is slightly reduced, I'd say that the behavior is a desired one.
OK. However it's sad to see the flusher get blocked from time to time...
Well, it doesn't get blocked. It just has to write out inode which cannot
be written out so efficiently. But that's nothing we can really solve...
Quoted 9 lines
Quoted 6 lines
Also if you observed the performance on a really long run, the difference should get smaller because eventually, kjournald has to flush the metadata blocks when the journal fills up and we need to free some journal space and at that point flushing is even more expensive because we have to do a blocking write during which all transaction operations, thus effectively the whole filesystem, are blocked.
OK. The dd test time was 300s, I'll increase it to 900s (cannot do more because it's a 90GB disk partition).
Yes, that might be an interesting try...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
reviewerRe: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to a message not in the archiveQuoted 39 lines · Wu Fengguang
Quoted 31 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines · Wu Fengguang
Quoted 7 lines · Wu Fengguang
Jan,
I tried the below combined patch over the ioless one, and find some minor regressions. I studied the thresh=1G/ext3-1dd case in particular and find that
nr_writebackand the iostat avgrq-sz drops from time to time.I'll try to bisect the changeset.
This is interesting, the culprit is found to be patch 1, which is simply
if (work->for_kupdate) { oldest_jif = jiffies - msecs_to_jiffies(dirty_expire_interval * 10);Review
Quoted 4 lines
(quoted diff) +2
-2- work->older_than_this = &oldest_jif; - } + } else if (work->for_background) + oldest_jif = jiffies;Yeah. I had a look into the trace and you can notice that during the
whole dd run, we were running a single background writeback work (you can verify that bywork->nr_pagesdecreasing steadily). Without refreshingoldest_jif, we'd write block device inode for/dev/sda(you can identify that by bdi=8:0, ino=0) only once. When refreshingoldest_jif, we write it every 5 seconds (kjournald dirties the device inode after committing a transaction by dirtying metadata buffers which were just committed and can now be checkpointed either by kjournald or flusher thread). So although the performance is slightly reduced, I'd say that the behavior is a desired one.Quoted 6 lines
Also if you observed the performance on a really long run, the difference should get smaller because eventually, kjournald has to flush the metadata blocks when the journal fills up and we need to free some journal space and at that point flushing is even more expensive because we have to do a blocking write during which all transaction operations, thus effectively the whole filesystem, are blocked.
Quoted 6 lines
Jan, I got figures for test case
ext3-1dd-4k-8p-2941M-1000M:10-3.1.0-rc9-ioless-full-nfs-wq5-next-20111014+
There is no single drop of
nr_writebackin the longer 1200s run, which wrote ~60GB data.
I did some calculations. Default journal size for a filesystem of your
size is 128 MB which allows recording of around 128 GB of data. So your test probably didn't hit the point where the journal is recycled yet. An easy way to make sure journal gets recycled is to set its size to a lower value when creating the filesystem by
mke2fs -J size=8
Then at latest after writing 8 GB the effect of journal recycling should
be visible (I suggest writing at least 16 or so so that we can see some pattern). Also note that without the patch altering background writeback, kjournald will do all the writeback of the metadata and kjournal works with buffer heads. Thus IO it does is *not* accounted in mm statistics. You will observe its effects only by a sudden increase in await or svctm because the disk got busy by IO you don't see. Also secondarily you could probably observe that as a hiccup in the number of dirtied/written pages.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
reviewerRe: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to a message not in the archiveQuoted 42 lines · Wu Fengguang
Quoted 20 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines · Wu Fengguang
Quoted 7 lines · Wu Fengguang
Jan,
I tried the below combined patch over the ioless one, and find some minor regressions. I studied the thresh=1G/ext3-1dd case in particular and find that
nr_writebackand the iostat avgrq-sz drops from time to time.I'll try to bisect the changeset.
This is interesting, the culprit is found to be patch 1, which is simply
if (work->for_kupdate) { oldest_jif = jiffies - msecs_to_jiffies(dirty_expire_interval * 10);Review
Quoted 4 lines
(quoted diff) +2
-2- work->older_than_this = &oldest_jif; - } + } else if (work->for_background) + oldest_jif = jiffies;Quoted 10 lines
Yeah. I had a look into the trace and you can notice that during the
whole dd run, we were running a single background writeback work (you can verify that bywork->nr_pagesdecreasing steadily). Without refreshingoldest_jif, we'd write block device inode for/dev/sda(you can identify that by bdi=8:0, ino=0) only once. When refreshingoldest_jif, we write it every 5 seconds (kjournald dirties the device inode after committing a transaction by dirtying metadata buffers which were just committed and can now be checkpointed either by kjournald or flusher thread). So although the performance is slightly reduced, I'd say that the behavior is a desired one.This is part of ext3-1dd-4k-8p-2941M-1024M:10-3.1.0-rc9-ioless-full-more_io_wait-next-20111014+/trace.bz2
flush-8:0-3133 [000] 357.418668: writeback_single_inode: bdi 8:0: ino=12 state=I_DIRTY_PAGES dirtied_when=4294728197 age=297 index=3443711 to_write=6144 wrote=6144 flush-8:0-3133 [000] 357.954817: writeback_single_inode: bdi 8:0: ino=0 state= dirtied_when=4295024858 age=1 index=3708770 to_write=6144 wrote=59 flush-8:0-3133 [000] 358.509053: writeback_single_inode: bdi 8:0: ino=12 state=I_DIRTY_PAGES dirtied_when=4294728197 age=298 index=3449855 to_write=6144 wrote=6144 flush-8:0-3133 [002] 358.774390: writeback_single_inode: bdi 8:0: ino=12 state=I_DIRTY_PAGES dirtied_when=4294728197 age=298 index=3455999 to_write=6144 wrote=6144 flush-8:0-3133 [002] 358.783747: writeback_single_inode: bdi 8:0: ino=12 state=I_DIRTY_PAGES dirtied_when=4294728197 age=298 index=3462143 to_write=6144 wrote=6144
Quoted 7 lines
I noticed that there is nothing else blocking the flusher because the
write_begintrace events always start immediately after eachwriteback_single_inodeevent.And the writeback for ino 0 took 357.954817-357.418668 = ~500ms but only writes 59 pages, which is the major reason
nr_writebackdrops from ~80MB to ~50MB.
Yes, this is not a big surprise. Metadata (indirect blocks) are
interleaved with data so all the metadata IO are just single block (4 KB) writes unlike data IO which comes in 4 MB chunks. This is also why you see request size drop in the graphs you attached to the next email. Also since you have to seek to fulfil each 4 KB IO request, and seek times are on the order of 5-15 ms, you easily get to metadata writeback of 59 pages taking around 500 ms. The filesystem could do better and avoid these seeks but it does not and it is beyond the task of writeback to fix it. Writeback just has to count with the fact that some pages are fast to write (e.g. sequential writes as you generate them) and some pages are hard to write (in this case metadata pages).
Quoted 5 lines
What's more,
nr_writebackis only able to restore
after this event (perhaps ext3 is cleaning up something during the time, which blocks dd inwrite_begin()or whatever):dd-3556 [000] 358.768670: balance_dirty_pages: bdi 8:0: limit=262144 setpoint=213489 dirty=212003 bdi_setpoint=213389 bdi_dirty=211640 dirty_ratelimit=46580 task_ratelimit=47444 dirtied=149 dirtied_pause=149 period=12 think=196 pause=-184 paused=0
Well, my bet would be that dd needed to access some metadata block (such
as free block bitmap) but it was under IO so dd was blocked until the IO finished.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
reviewerRe: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to a message not in the archiveQuoted 65 lines · Wu Fengguang
Quoted 44 lines · Jan Kara
Quoted 43 lines · Wu Fengguang
Quoted 31 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines · Wu Fengguang
Quoted 7 lines · Wu Fengguang
Jan,
I tried the below combined patch over the ioless one, and find some minor regressions. I studied the thresh=1G/ext3-1dd case in particular and find that
nr_writebackand the iostat avgrq-sz drops from time to time.I'll try to bisect the changeset.
This is interesting, the culprit is found to be patch 1, which is simply
if (work->for_kupdate) { oldest_jif = jiffies - msecs_to_jiffies(dirty_expire_interval * 10);Review
Quoted 4 lines
(quoted diff) +2
-2- work->older_than_this = &oldest_jif; - } + } else if (work->for_background) + oldest_jif = jiffies;Yeah. I had a look into the trace and you can notice that during the
whole dd run, we were running a single background writeback work (you can verify that bywork->nr_pagesdecreasing steadily). Without refreshingoldest_jif, we'd write block device inode for/dev/sda(you can identify that by bdi=8:0, ino=0) only once. When refreshingoldest_jif, we write it every 5 seconds (kjournald dirties the device inode after committing a transaction by dirtying metadata buffers which were just committed and can now be checkpointed either by kjournald or flusher thread). So although the performance is slightly reduced, I'd say that the behavior is a desired one.Quoted 6 lines
Also if you observed the performance on a really long run, the difference should get smaller because eventually, kjournald has to flush the metadata blocks when the journal fills up and we need to free some journal space and at that point flushing is even more expensive because we have to do a blocking write during which all transaction operations, thus effectively the whole filesystem, are blocked.
Jan, I got figures for test case
ext3-1dd-4k-8p-2941M-1000M:10-3.1.0-rc9-ioless-full-nfs-wq5-next-20111014+
Quoted 8 lines
Quoted 2 lines
There is no single drop of
nr_writebackin the longer 1200s run, which wrote ~60GB data.I did some calculations. Default journal size for a filesystem of your
size is 128 MB which allows recording of around 128 GB of data. So your test probably didn't hit the point where the journal is recycled yet. An easy way to make sure journal gets recycled is to set its size to a lower value when creating the filesystem by
mke2fs -J size=8I tried the "-J size=8" and get similar interesting results for ext3/4, before/after this change:
if (work->for_kupdate) { oldest_jif = jiffies - msecs_to_jiffies(dirty_expire_interval * 10);(quoted diff) +2
-2- work->older_than_this = &oldest_jif; - } + } else if (work->for_background) + oldest_jif = jiffies;
Quoted 7 lines
So I only attach the graphs for one case:
ext4-1dd-4k-8p-2941M-1000M:10-3.1.0-ioless-full-next-20111025+
Two of the graphs are very interesting. balance_dirty_pages-pause.png shows increasingly large negative pause times, which indicates large delays inside some ext4's routines.
Likely we are hanging waiting for transaction start. 8 MB journal puts
rather big pressure on journal space so we end up waiting on kjournald a lot. But I'm not sure why wait times would increase on large scale - with ext4 it's harder to estimate used journal space because it uses extents so the amount of metadata written depends on fragmentation. If you could post ext3 graphs, maybe I could make some sense from it...
Quoted 3 lines
And iostat-util.png shows very large CPU utilization...Oh well the
lock_stathas thercu_torture_timeron the top. I'd better retest without the rcu torture test option...
Yes, I guess this might be just debugging artefact.
Quoted 9 lines
Quoted 8 lines
Then at latest after writing 8 GB the effect of journal recycling should
be visible (I suggest writing at least 16 or so so that we can see some pattern). Also note that without the patch altering background writeback, kjournald will do all the writeback of the metadata and kjournal works with buffer heads. Thus IO it does is *not* accounted in mm statistics. You will observe its effects only by a sudden increase in await or svctm because the disk got busy by IO you don't see. Also secondarily you could probably observe that as a hiccup in the number of dirtied/written pages.
Quoted 3 lines
Ah good to know that. It could explain the drops of IO size.
iostat should still be reporting the journal IO, is it?
Yes.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 1/2] writeback: Improve busyloop prevention
Quoted 25 lines
Quoted 18 lines
Quoted 6 lines
I did some calculations. Default journal size for a filesystem of your
size is 128 MB which allows recording of around 128 GB of data. So your test probably didn't hit the point where the journal is recycled yet. An easy way to make sure journal gets recycled is to set its size to a lower value when creating the filesystem by
mke2fs -J size=8I tried the "-J size=8" and get similar interesting results for ext3/4, before/after this change:
if (work->for_kupdate) { oldest_jif = jiffies - msecs_to_jiffies(dirty_expire_interval * 10);(quoted diff) +2
-2- work->older_than_this = &oldest_jif; - } + } else if (work->for_background) + oldest_jif = jiffies;Quoted 7 lines
So I only attach the graphs for one case:
ext4-1dd-4k-8p-2941M-1000M:10-3.1.0-ioless-full-next-20111025+
Two of the graphs are very interesting. balance_dirty_pages-pause.png shows increasingly large negative pause times, which indicates large delays inside some ext4's routines.
Quoted 6 lines
Likely we are hanging waiting for transaction start. 8 MB journal puts
rather big pressure on journal space so we end up waiting on kjournald a lot. But I'm not sure why wait times would increase on large scale - with ext4 it's harder to estimate used journal space because it uses extents so the amount of metadata written depends on fragmentation. If you could post ext3 graphs, maybe I could make some sense from it...
Oops it's me that messed it up again -- two chunks were lost during when rebasing the patchset which leads to the misbehavior -- big sorry!
Jan Kara
reviewerRe: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to a message not in the archiveQuoted 63 lines · Wu Fengguang
Quoted 53 lines · Jan Kara
Quoted 39 lines · Wu Fengguang
Quoted 31 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines · Wu Fengguang
Quoted 7 lines · Wu Fengguang
Jan,
I tried the below combined patch over the ioless one, and find some minor regressions. I studied the thresh=1G/ext3-1dd case in particular and find that
nr_writebackand the iostat avgrq-sz drops from time to time.I'll try to bisect the changeset.
This is interesting, the culprit is found to be patch 1, which is simply
if (work->for_kupdate) { oldest_jif = jiffies - msecs_to_jiffies(dirty_expire_interval * 10);Review
Quoted 4 lines
(quoted diff) +2
-2- work->older_than_this = &oldest_jif; - } + } else if (work->for_background) + oldest_jif = jiffies;Yeah. I had a look into the trace and you can notice that during the
whole dd run, we were running a single background writeback work (you can verify that bywork->nr_pagesdecreasing steadily). Without refreshingoldest_jif, we'd write block device inode for/dev/sda(you can identify that by bdi=8:0, ino=0) only once. When refreshingoldest_jif, we write it every 5 seconds (kjournald dirties the device inode after committing a transaction by dirtying metadata buffers which were just committed and can now be checkpointed either by kjournald or flusher thread). So although the performance is slightly reduced, I'd say that the behavior is a desired one.Quoted 6 lines
Also if you observed the performance on a really long run, the difference should get smaller because eventually, kjournald has to flush the metadata blocks when the journal fills up and we need to free some journal space and at that point flushing is even more expensive because we have to do a blocking write during which all transaction operations, thus effectively the whole filesystem, are blocked.
Quoted 6 lines
Jan, I got figures for test case
ext3-1dd-4k-8p-2941M-1000M:10-3.1.0-rc9-ioless-full-nfs-wq5-next-20111014+
There is no single drop of
nr_writebackin the longer 1200s run, which wrote ~60GB data.I did some calculations. Default journal size for a filesystem of your
size is 128 MB which allows recording of around 128 GB of data. So your test probably didn't hit the point where the journal is recycled yet. An easy way to make sure journal gets recycled is to set its size to a lower value when creating the filesystem by
mke2fs -J size=8Quoted 8 lines
Then at latest after writing 8 GB the effect of journal recycling should
be visible (I suggest writing at least 16 or so so that we can see some pattern). Also note that without the patch altering background writeback, kjournald will do all the writeback of the metadata and kjournal works with buffer heads. Thus IO it does is *not* accounted in mm statistics. You will observe its effects only by a sudden increase in await or svctm because the disk got busy by IO you don't see. Also secondarily you could probably observe that as a hiccup in the number of dirtied/written pages.
Quoted 5 lines
Jan, finally the `correct' results for "-J size=8" w/o the patch altering background writeback.
I noticed the periodic small drops of
nr_writebackin global_dirty_state.png, other than that it looks pretty good.
If you look at iostat graphs, you'll notice periodic increases in await
time in roughly 100 s intervals. I belive this could be checkpointing that's going on in the background. Also there are (negative) peaks in the "paused" graph. Anyway, the main question is - do you see any throughput difference with/without the background writeback patch with the small journal?
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 1/2] writeback: Improve busyloop prevention
Quoted 64 lines · Jan Kara
Quoted 63 lines · Wu Fengguang
Quoted 61 lines · Jan Kara
Quoted 39 lines · Wu Fengguang
Quoted 31 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines · Wu Fengguang
Quoted 7 lines · Wu Fengguang
Jan,
I tried the below combined patch over the ioless one, and find some minor regressions. I studied the thresh=1G/ext3-1dd case in particular and find that
nr_writebackand the iostat avgrq-sz drops from time to time.I'll try to bisect the changeset.
This is interesting, the culprit is found to be patch 1, which is simply
if (work->for_kupdate) { oldest_jif = jiffies - msecs_to_jiffies(dirty_expire_interval * 10);Review
Quoted 4 lines
(quoted diff) +2
-2- work->older_than_this = &oldest_jif; - } + } else if (work->for_background) + oldest_jif = jiffies;Yeah. I had a look into the trace and you can notice that during the
whole dd run, we were running a single background writeback work (you can verify that bywork->nr_pagesdecreasing steadily). Without refreshingoldest_jif, we'd write block device inode for/dev/sda(you can identify that by bdi=8:0, ino=0) only once. When refreshingoldest_jif, we write it every 5 seconds (kjournald dirties the device inode after committing a transaction by dirtying metadata buffers which were just committed and can now be checkpointed either by kjournald or flusher thread). So although the performance is slightly reduced, I'd say that the behavior is a desired one.Quoted 6 lines
Also if you observed the performance on a really long run, the difference should get smaller because eventually, kjournald has to flush the metadata blocks when the journal fills up and we need to free some journal space and at that point flushing is even more expensive because we have to do a blocking write during which all transaction operations, thus effectively the whole filesystem, are blocked.
Quoted 6 lines
Jan, I got figures for test case
ext3-1dd-4k-8p-2941M-1000M:10-3.1.0-rc9-ioless-full-nfs-wq5-next-20111014+
There is no single drop of
nr_writebackin the longer 1200s run, which wrote ~60GB data.I did some calculations. Default journal size for a filesystem of your
size is 128 MB which allows recording of around 128 GB of data. So your test probably didn't hit the point where the journal is recycled yet. An easy way to make sure journal gets recycled is to set its size to a lower value when creating the filesystem by
mke2fs -J size=8Then at latest after writing 8 GB the effect of journal recycling should
be visible (I suggest writing at least 16 or so so that we can see some pattern). Also note that without the patch altering background writeback, kjournald will do all the writeback of the metadata and kjournal works with buffer heads. Thus IO it does is *not* accounted in mm statistics. You will observe its effects only by a sudden increase in await or svctm because the disk got busy by IO you don't see. Also secondarily you could probably observe that as a hiccup in the number of dirtied/written pages.
Quoted 7 lines
Quoted 5 lines
Jan, finally the `correct' results for "-J size=8" w/o the patch altering background writeback.
I noticed the periodic small drops of
nr_writebackin global_dirty_state.png, other than that it looks pretty good.If you look at iostat graphs, you'll notice periodic increases in await
time in roughly 100 s intervals. I belive this could be checkpointing
Yes it is. And there is frequent drop of IO queue size.
Quoted 2 lines
that's going on in the background. Also there are (negative) peaks in the "paused" graph.
Yeah, this happens on all ext3/4 workloads and I'm kind of used to it ;)
Quoted 3 lines
Anyway, the main question is - do you see any throughput difference with/without the background writeback patch with the small journal?
Here are the comparisons w/o the patch. The results w/ the patch should be available tomorrow.
wfg@bee /export/writeback% ./compare.rb -g ext4 -c fs -e io_wkB_s thresh*/*-20111102+
ext4 ext4:jsize=8
------------------------ ------------------------
47684.35 -0.3% 47546.62 thresh=1000M/X-100dd-4k-8p-4096M-1000M:10-3.1.0-ioless-full-next-20111102+
54015.86 -1.6% 53166.76 thresh=1000M/X-10dd-4k-8p-4096M-1000M:10-3.1.0-ioless-full-next-20111102+
55320.03 +0.6% 55657.48 thresh=1000M/X-1dd-4k-8p-4096M-1000M:10-3.1.0-ioless-full-next-20111102+
44271.29 +2.6% 45443.23 thresh=100M/X-10dd-4k-8p-4096M-100M:10-3.1.0-ioless-full-next-20111102+
54334.22 -1.0% 53801.15 thresh=100M/X-1dd-4k-8p-4096M-100M:10-3.1.0-ioless-full-next-20111102+
52563.67 -0.7% 52207.05 thresh=100M/X-2dd-4k-8p-4096M-100M:10-3.1.0-ioless-full-next-20111102+
308189.41 -0.1% 307822.30 TOTAL io_wkB_swfg@bee /export/writeback% ./compare.rb -g ext3 -c fs -e io_wkB_s thresh*/*-20111102+
ext3 ext3:jsize=8
------------------------ ------------------------
36231.89 -1.6% 35659.34 thresh=1000M/X-100dd-4k-8p-4096M-1000M:10-3.1.0-ioless-full-next-20111102+
41115.07 -6.2% 38564.52 thresh=1000M/X-10dd-4k-8p-4096M-1000M:10-3.1.0-ioless-full-next-20111102+
48025.75 -3.8% 46213.55 thresh=1000M/X-1dd-4k-8p-4096M-1000M:10-3.1.0-ioless-full-next-20111102+
45317.31 +1.6% 46023.21 thresh=100M/X-1dd-4k-8p-4096M-100M:10-3.1.0-ioless-full-next-20111102+
40552.64 +4.0% 42182.84 thresh=100M/X-2dd-4k-8p-4096M-100M:10-3.1.0-ioless-full-next-20111102+
211242.67 -1.2% 208643.45 TOTAL io_wkB_sI'm currently rewriting the test scripts to make it easier for others to understand and make use of it. It will also gain the feature to run each test 2+ times to get a better idea of the fluctuations :)
Thanks,
Fengguang
Jan Kara
reviewerRe: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to a message not in the archiveQuoted 100 lines · Wu Fengguang
Quoted 67 lines · Jan Kara
Quoted 66 lines · Wu Fengguang
Quoted 53 lines · Jan Kara
Quoted 39 lines · Wu Fengguang
Quoted 31 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines · Wu Fengguang
Quoted 7 lines · Wu Fengguang
Jan,
I tried the below combined patch over the ioless one, and find some minor regressions. I studied the thresh=1G/ext3-1dd case in particular and find that
nr_writebackand the iostat avgrq-sz drops from time to time.I'll try to bisect the changeset.
This is interesting, the culprit is found to be patch 1, which is simply
if (work->for_kupdate) { oldest_jif = jiffies - msecs_to_jiffies(dirty_expire_interval * 10);Review
Quoted 4 lines
(quoted diff) +2
-2- work->older_than_this = &oldest_jif; - } + } else if (work->for_background) + oldest_jif = jiffies;Yeah. I had a look into the trace and you can notice that during the
whole dd run, we were running a single background writeback work (you can verify that bywork->nr_pagesdecreasing steadily). Without refreshingoldest_jif, we'd write block device inode for/dev/sda(you can identify that by bdi=8:0, ino=0) only once. When refreshingoldest_jif, we write it every 5 seconds (kjournald dirties the device inode after committing a transaction by dirtying metadata buffers which were just committed and can now be checkpointed either by kjournald or flusher thread). So although the performance is slightly reduced, I'd say that the behavior is a desired one.Quoted 6 lines
Also if you observed the performance on a really long run, the difference should get smaller because eventually, kjournald has to flush the metadata blocks when the journal fills up and we need to free some journal space and at that point flushing is even more expensive because we have to do a blocking write during which all transaction operations, thus effectively the whole filesystem, are blocked.
Quoted 6 lines
Jan, I got figures for test case
ext3-1dd-4k-8p-2941M-1000M:10-3.1.0-rc9-ioless-full-nfs-wq5-next-20111014+
There is no single drop of
nr_writebackin the longer 1200s run, which wrote ~60GB data.I did some calculations. Default journal size for a filesystem of your
size is 128 MB which allows recording of around 128 GB of data. So your test probably didn't hit the point where the journal is recycled yet. An easy way to make sure journal gets recycled is to set its size to a lower value when creating the filesystem by
mke2fs -J size=8Quoted 8 lines
Then at latest after writing 8 GB the effect of journal recycling should
be visible (I suggest writing at least 16 or so so that we can see some pattern). Also note that without the patch altering background writeback, kjournald will do all the writeback of the metadata and kjournal works with buffer heads. Thus IO it does is *not* accounted in mm statistics. You will observe its effects only by a sudden increase in await or svctm because the disk got busy by IO you don't see. Also secondarily you could probably observe that as a hiccup in the number of dirtied/written pages.Jan, finally the `correct' results for "-J size=8" w/o the patch altering background writeback.
Quoted 8 lines
Quoted 2 lines
I noticed the periodic small drops of
nr_writebackin global_dirty_state.png, other than that it looks pretty good.If you look at iostat graphs, you'll notice periodic increases in await
time in roughly 100 s intervals. I belive this could be checkpointing that's going on in the background. Also there are (negative) peaks in the "paused" graph. Anyway, the main question is - do you see any throughput difference with/without the background writeback patch with the small journal?Jan, I got the results before/after patch -- there is small performance drops either with plain mkfs or mkfs "-J size=8", while the latter does see smaller drops.
To make it more accurate, I use the average wkB/s value reported by iostat for the comparison.
wfg@bee /export/writeback% ./compare.rb -g jsize -e
io_wkB_sthresh*/*-ioless-full-next-20111102+ thresh*/*-20111102+ 3.1.0-ioless-full-next-20111102+ 3.1.0-ioless-full-bg-all-next-20111102+
------------------------ ------------------------35659.34 -0.8% 35377.54 thresh=1000M/ext3:jsize=8-100dd-4k-8p-4096M-1000M:10-X 38564.52 -1.9% 37839.55 thresh=1000M/ext3:jsize=8-10dd-4k-8p-4096M-1000M:10-X 46213.55 -3.1% 44784.05 thresh=1000M/ext3:jsize=8-1dd-4k-8p-4096M-1000M:10-X 47546.62 +0.5% 47790.81 thresh=1000M/ext4:jsize=8-100dd-4k-8p-4096M-1000M:10-X 53166.76 +0.6% 53512.28 thresh=1000M/ext4:jsize=8-10dd-4k-8p-4096M-1000M:10-X 55657.48 -0.2% 55530.27 thresh=1000M/ext4:jsize=8-1dd-4k-8p-4096M-1000M:10-X 38868.18 -1.9% 38146.89 thresh=100M/ext3:jsize=8-10dd-4k-8p-4096M-100M:10-X 46023.21 -0.2% 45908.73 thresh=100M/ext3:jsize=8-1dd-4k-8p-4096M-100M:10-X 42182.84 -1.5% 41556.99 thresh=100M/ext3:jsize=8-2dd-4k-8p-4096M-100M:10-X 45443.23 -0.9% 45038.84 thresh=100M/ext4:jsize=8-10dd-4k-8p-4096M-100M:10-X 53801.15 -0.9% 53315.74 thresh=100M/ext4:jsize=8-1dd-4k-8p-4096M-100M:10-X 52207.05 -0.6% 51913.22 thresh=100M/ext4:jsize=8-2dd-4k-8p-4096M-100M:10-X 33389.88 -3.5% 32226.18 thresh=10M/ext3:jsize=8-10dd-4k-8p-4096M-10M:10-X
Quoted 8 lines
45430.23 -3.5% 43846.57 thresh=10M/ext3:jsize=8-1dd-4k-8p-4096M-10M:10-X
44186.72 -4.5% 42185.16 thresh=10M/ext3:jsize=8-2dd-4k-8p-4096M-10M:10-X
36237.34 -3.1% 35128.90 thresh=10M/ext4:jsize=8-10dd-4k-8p-4096M-10M:10-X
54633.30 -2.7% 53135.13 thresh=10M/ext4:jsize=8-1dd-4k-8p-4096M-10M:10-X
50767.63 -1.9% 49800.59 thresh=10M/ext4:jsize=8-2dd-4k-8p-4096M-10M:10-X
49654.38 -4.8% 47274.27 thresh=1M/ext4:jsize=8-1dd-4k-8p-4096M-1M:10-X
45142.01 -5.3% 42745.49 thresh=1M/ext4:jsize=8-2dd-4k-8p-4096M-1M:10-X
914775.42 -1.9% 897057.21 TOTAL io_wkB_s These differences look negligible unless thresh <= 10M when flushing
becomes rather aggressive I'd say and thus the fact that background writeback can switch inodes is more noticeable. OTOH thresh <= 10M doesn't look like a case which needs optimizing for.
Quoted 13 lines
wfg@bee /export/writeback% ./compare.rb -v jsize -e
io_wkB_sthresh*/*-ioless-full-next-20111102+ thresh*/*-20111102+ 3.1.0-ioless-full-next-20111102+ 3.1.0-ioless-full-bg-all-next-20111102+
------------------------ ------------------------36231.89 -3.8% 34855.10 thresh=1000M/ext3-100dd-4k-8p-4096M-1000M:10-X 41115.07 -12.7% 35886.36 thresh=1000M/ext3-10dd-4k-8p-4096M-1000M:10-X 48025.75 -14.3% 41146.57 thresh=1000M/ext3-1dd-4k-8p-4096M-1000M:10-X 47684.35 -6.4% 44644.30 thresh=1000M/ext4-100dd-4k-8p-4096M-1000M:10-X 54015.86 -4.0% 51851.01 thresh=1000M/ext4-10dd-4k-8p-4096M-1000M:10-X 55320.03 -2.6% 53867.63 thresh=1000M/ext4-1dd-4k-8p-4096M-1000M:10-X 37400.51 +1.6% 38012.57 thresh=100M/ext3-10dd-4k-8p-4096M-100M:10-X 45317.31 -4.5% 43272.16 thresh=100M/ext3-1dd-4k-8p-4096M-100M:10-X 40552.64 +0.8% 40884.60 thresh=100M/ext3-2dd-4k-8p-4096M-100M:10-X 44271.29 -5.6% 41789.76 thresh=100M/ext4-10dd-4k-8p-4096M-100M:10-X
Quoted 8 lines
54334.22 -3.5% 52435.69 thresh=100M/ext4-1dd-4k-8p-4096M-100M:10-X
52563.67 -6.1% 49341.84 thresh=100M/ext4-2dd-4k-8p-4096M-100M:10-X
45027.95 -1.0% 44599.37 thresh=10M/ext3-1dd-4k-8p-4096M-10M:10-X
42478.40 +0.3% 42608.48 thresh=10M/ext3-2dd-4k-8p-4096M-10M:10-X
35178.47 -0.2% 35103.56 thresh=10M/ext4-10dd-4k-8p-4096M-10M:10-X
54079.64 -0.5% 53834.85 thresh=10M/ext4-1dd-4k-8p-4096M-10M:10-X
49982.11 -0.4% 49803.44 thresh=10M/ext4-2dd-4k-8p-4096M-10M:10-X
783579.17 -3.8% 753937.28 TOTAL io_wkB_s Here I can see some noticeable drops in the realistic thresh=100M case
(case thresh=1000M is unrealistic but it still surprise me that there are drops as well). I'll try to reproduce your results so that I can look into this more effectively.
Honza
Re: [PATCH 1/2] writeback: Improve busyloop prevention
Quoted 109 lines · Jan Kara
Quoted 100 lines · Wu Fengguang
Quoted 67 lines · Jan Kara
Quoted 66 lines · Wu Fengguang
Quoted 53 lines · Jan Kara
Quoted 39 lines · Wu Fengguang
Quoted 31 lines · Jan Kara
Quoted 15 lines · Wu Fengguang
Quoted 8 lines · Wu Fengguang
Quoted 7 lines · Wu Fengguang
Jan,
I tried the below combined patch over the ioless one, and find some minor regressions. I studied the thresh=1G/ext3-1dd case in particular and find that
nr_writebackand the iostat avgrq-sz drops from time to time.I'll try to bisect the changeset.
This is interesting, the culprit is found to be patch 1, which is simply
if (work->for_kupdate) { oldest_jif = jiffies - msecs_to_jiffies(dirty_expire_interval * 10);Review
Quoted 4 lines
(quoted diff) +2
-2- work->older_than_this = &oldest_jif; - } + } else if (work->for_background) + oldest_jif = jiffies;Yeah. I had a look into the trace and you can notice that during the
whole dd run, we were running a single background writeback work (you can verify that bywork->nr_pagesdecreasing steadily). Without refreshingoldest_jif, we'd write block device inode for/dev/sda(you can identify that by bdi=8:0, ino=0) only once. When refreshingoldest_jif, we write it every 5 seconds (kjournald dirties the device inode after committing a transaction by dirtying metadata buffers which were just committed and can now be checkpointed either by kjournald or flusher thread). So although the performance is slightly reduced, I'd say that the behavior is a desired one.Quoted 6 lines
Also if you observed the performance on a really long run, the difference should get smaller because eventually, kjournald has to flush the metadata blocks when the journal fills up and we need to free some journal space and at that point flushing is even more expensive because we have to do a blocking write during which all transaction operations, thus effectively the whole filesystem, are blocked.
Quoted 6 lines
Jan, I got figures for test case
ext3-1dd-4k-8p-2941M-1000M:10-3.1.0-rc9-ioless-full-nfs-wq5-next-20111014+
There is no single drop of
nr_writebackin the longer 1200s run, which wrote ~60GB data.I did some calculations. Default journal size for a filesystem of your
size is 128 MB which allows recording of around 128 GB of data. So your test probably didn't hit the point where the journal is recycled yet. An easy way to make sure journal gets recycled is to set its size to a lower value when creating the filesystem by
mke2fs -J size=8Quoted 8 lines
Then at latest after writing 8 GB the effect of journal recycling should
be visible (I suggest writing at least 16 or so so that we can see some pattern). Also note that without the patch altering background writeback, kjournald will do all the writeback of the metadata and kjournal works with buffer heads. Thus IO it does is *not* accounted in mm statistics. You will observe its effects only by a sudden increase in await or svctm because the disk got busy by IO you don't see. Also secondarily you could probably observe that as a hiccup in the number of dirtied/written pages.Jan, finally the `correct' results for "-J size=8" w/o the patch altering background writeback.
Quoted 8 lines
Quoted 2 lines
I noticed the periodic small drops of
nr_writebackin global_dirty_state.png, other than that it looks pretty good.If you look at iostat graphs, you'll notice periodic increases in await
time in roughly 100 s intervals. I belive this could be checkpointing that's going on in the background. Also there are (negative) peaks in the "paused" graph. Anyway, the main question is - do you see any throughput difference with/without the background writeback patch with the small journal?Jan, I got the results before/after patch -- there is small performance drops either with plain mkfs or mkfs "-J size=8", while the latter does see smaller drops.
To make it more accurate, I use the average wkB/s value reported by iostat for the comparison.
wfg@bee /export/writeback% ./compare.rb -g jsize -e
io_wkB_sthresh*/*-ioless-full-next-20111102+ thresh*/*-20111102+ 3.1.0-ioless-full-next-20111102+ 3.1.0-ioless-full-bg-all-next-20111102+
------------------------ ------------------------35659.34 -0.8% 35377.54 thresh=1000M/ext3:jsize=8-100dd-4k-8p-4096M-1000M:10-X 38564.52 -1.9% 37839.55 thresh=1000M/ext3:jsize=8-10dd-4k-8p-4096M-1000M:10-X 46213.55 -3.1% 44784.05 thresh=1000M/ext3:jsize=8-1dd-4k-8p-4096M-1000M:10-X 47546.62 +0.5% 47790.81 thresh=1000M/ext4:jsize=8-100dd-4k-8p-4096M-1000M:10-X 53166.76 +0.6% 53512.28 thresh=1000M/ext4:jsize=8-10dd-4k-8p-4096M-1000M:10-X 55657.48 -0.2% 55530.27 thresh=1000M/ext4:jsize=8-1dd-4k-8p-4096M-1000M:10-X 38868.18 -1.9% 38146.89 thresh=100M/ext3:jsize=8-10dd-4k-8p-4096M-100M:10-X 46023.21 -0.2% 45908.73 thresh=100M/ext3:jsize=8-1dd-4k-8p-4096M-100M:10-X 42182.84 -1.5% 41556.99 thresh=100M/ext3:jsize=8-2dd-4k-8p-4096M-100M:10-X 45443.23 -0.9% 45038.84 thresh=100M/ext4:jsize=8-10dd-4k-8p-4096M-100M:10-X 53801.15 -0.9% 53315.74 thresh=100M/ext4:jsize=8-1dd-4k-8p-4096M-100M:10-X 52207.05 -0.6% 51913.22 thresh=100M/ext4:jsize=8-2dd-4k-8p-4096M-100M:10-X 33389.88 -3.5% 32226.18 thresh=10M/ext3:jsize=8-10dd-4k-8p-4096M-10M:10-XQuoted 8 lines
45430.23 -3.5% 43846.57 thresh=10M/ext3:jsize=8-1dd-4k-8p-4096M-10M:10-X 44186.72 -4.5% 42185.16 thresh=10M/ext3:jsize=8-2dd-4k-8p-4096M-10M:10-X 36237.34 -3.1% 35128.90 thresh=10M/ext4:jsize=8-10dd-4k-8p-4096M-10M:10-X 54633.30 -2.7% 53135.13 thresh=10M/ext4:jsize=8-1dd-4k-8p-4096M-10M:10-X 50767.63 -1.9% 49800.59 thresh=10M/ext4:jsize=8-2dd-4k-8p-4096M-10M:10-X 49654.38 -4.8% 47274.27 thresh=1M/ext4:jsize=8-1dd-4k-8p-4096M-1M:10-X 45142.01 -5.3% 42745.49 thresh=1M/ext4:jsize=8-2dd-4k-8p-4096M-1M:10-X 914775.42 -1.9% 897057.21 TOTAL io_wkB_s
Quoted 4 lines
These differences look negligible unless thresh <= 10M when flushing
becomes rather aggressive I'd say and thus the fact that background writeback can switch inodes is more noticeable. OTOH thresh <= 10M doesn't look like a case which needs optimizing for.
Agreed in principle.
Quoted 21 lines
Quoted 13 lines
wfg@bee /export/writeback% ./compare.rb -v jsize -e
io_wkB_sthresh*/*-ioless-full-next-20111102+ thresh*/*-20111102+ 3.1.0-ioless-full-next-20111102+ 3.1.0-ioless-full-bg-all-next-20111102+
------------------------ ------------------------36231.89 -3.8% 34855.10 thresh=1000M/ext3-100dd-4k-8p-4096M-1000M:10-X 41115.07 -12.7% 35886.36 thresh=1000M/ext3-10dd-4k-8p-4096M-1000M:10-X 48025.75 -14.3% 41146.57 thresh=1000M/ext3-1dd-4k-8p-4096M-1000M:10-X 47684.35 -6.4% 44644.30 thresh=1000M/ext4-100dd-4k-8p-4096M-1000M:10-X 54015.86 -4.0% 51851.01 thresh=1000M/ext4-10dd-4k-8p-4096M-1000M:10-X 55320.03 -2.6% 53867.63 thresh=1000M/ext4-1dd-4k-8p-4096M-1000M:10-X 37400.51 +1.6% 38012.57 thresh=100M/ext3-10dd-4k-8p-4096M-100M:10-X 45317.31 -4.5% 43272.16 thresh=100M/ext3-1dd-4k-8p-4096M-100M:10-X 40552.64 +0.8% 40884.60 thresh=100M/ext3-2dd-4k-8p-4096M-100M:10-X 44271.29 -5.6% 41789.76 thresh=100M/ext4-10dd-4k-8p-4096M-100M:10-XQuoted 8 lines
54334.22 -3.5% 52435.69 thresh=100M/ext4-1dd-4k-8p-4096M-100M:10-X 52563.67 -6.1% 49341.84 thresh=100M/ext4-2dd-4k-8p-4096M-100M:10-X 45027.95 -1.0% 44599.37 thresh=10M/ext3-1dd-4k-8p-4096M-10M:10-X 42478.40 +0.3% 42608.48 thresh=10M/ext3-2dd-4k-8p-4096M-10M:10-X 35178.47 -0.2% 35103.56 thresh=10M/ext4-10dd-4k-8p-4096M-10M:10-X 54079.64 -0.5% 53834.85 thresh=10M/ext4-1dd-4k-8p-4096M-10M:10-X 49982.11 -0.4% 49803.44 thresh=10M/ext4-2dd-4k-8p-4096M-10M:10-X 783579.17 -3.8% 753937.28 TOTAL io_wkB_s
Quoted 4 lines
Here I can see some noticeable drops in the realistic thresh=100M case
(case thresh=1000M is unrealistic but it still surprise me that there are drops as well). I'll try to reproduce your results so that I can look into this more effectively.
OK. I'm trying to bring out the test scripts in a useful way, so as to make it easier for you to do comparison/analyzes more freely :)
Thanks,
Fengguang
Jan Kara
reviewerRe: [PATCH 1/2] writeback: Improve busyloop prevention
In reply to Jan KaraQuoted 21 lines · Jan Kara
Quoted 13 lines
wfg@bee /export/writeback% ./compare.rb -v jsize -e
io_wkB_sthresh*/*-ioless-full-next-20111102+ thresh*/*-20111102+ 3.1.0-ioless-full-next-20111102+ 3.1.0-ioless-full-bg-all-next-20111102+
------------------------ ------------------------36231.89 -3.8% 34855.10 thresh=1000M/ext3-100dd-4k-8p-4096M-1000M:10-X 41115.07 -12.7% 35886.36 thresh=1000M/ext3-10dd-4k-8p-4096M-1000M:10-X 48025.75 -14.3% 41146.57 thresh=1000M/ext3-1dd-4k-8p-4096M-1000M:10-X 47684.35 -6.4% 44644.30 thresh=1000M/ext4-100dd-4k-8p-4096M-1000M:10-X 54015.86 -4.0% 51851.01 thresh=1000M/ext4-10dd-4k-8p-4096M-1000M:10-X 55320.03 -2.6% 53867.63 thresh=1000M/ext4-1dd-4k-8p-4096M-1000M:10-X 37400.51 +1.6% 38012.57 thresh=100M/ext3-10dd-4k-8p-4096M-100M:10-X 45317.31 -4.5% 43272.16 thresh=100M/ext3-1dd-4k-8p-4096M-100M:10-X 40552.64 +0.8% 40884.60 thresh=100M/ext3-2dd-4k-8p-4096M-100M:10-X 44271.29 -5.6% 41789.76 thresh=100M/ext4-10dd-4k-8p-4096M-100M:10-XQuoted 8 lines
54334.22 -3.5% 52435.69 thresh=100M/ext4-1dd-4k-8p-4096M-100M:10-X 52563.67 -6.1% 49341.84 thresh=100M/ext4-2dd-4k-8p-4096M-100M:10-X 45027.95 -1.0% 44599.37 thresh=10M/ext3-1dd-4k-8p-4096M-10M:10-X 42478.40 +0.3% 42608.48 thresh=10M/ext3-2dd-4k-8p-4096M-10M:10-X 35178.47 -0.2% 35103.56 thresh=10M/ext4-10dd-4k-8p-4096M-10M:10-X 54079.64 -0.5% 53834.85 thresh=10M/ext4-1dd-4k-8p-4096M-10M:10-X 49982.11 -0.4% 49803.44 thresh=10M/ext4-2dd-4k-8p-4096M-10M:10-X 783579.17 -3.8% 753937.28 TOTAL io_wkB_s
Quoted 4 lines
Here I can see some noticeable drops in the realistic thresh=100M case
(case thresh=1000M is unrealistic but it still surprise me that there are drops as well). I'll try to reproduce your results so that I can look into this more effectively.
So I've run a test on a machine with 1G of memory, thresh=184M (so
something similar to your 4G-1G test). I've used tiobench using 10 threads, each thread writing 1.6G file. I have run the test 10 times to get an idea of fluctuations. The result is:
without patch with patch
AVG STDDEV AVG STDDEV
199.884820 +- 1.32268 200.466003 +- 0.377405
The numbers are time-to-completion so lower is better. Summary is: No statistically meaningful difference. I'll run more tests with different dirty thresholds to see whether I won't be able to observe some difference...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 1/2] writeback: Improve busyloop prevention
Jan,
Sorry for the long delay!
Quoted 34 lines · Jan Kara
Quoted 21 lines · Jan Kara
Quoted 13 lines
wfg@bee /export/writeback% ./compare.rb -v jsize -e
io_wkB_sthresh*/*-ioless-full-next-20111102+ thresh*/*-20111102+ 3.1.0-ioless-full-next-20111102+ 3.1.0-ioless-full-bg-all-next-20111102+
------------------------ ------------------------36231.89 -3.8% 34855.10 thresh=1000M/ext3-100dd-4k-8p-4096M-1000M:10-X 41115.07 -12.7% 35886.36 thresh=1000M/ext3-10dd-4k-8p-4096M-1000M:10-X 48025.75 -14.3% 41146.57 thresh=1000M/ext3-1dd-4k-8p-4096M-1000M:10-X 47684.35 -6.4% 44644.30 thresh=1000M/ext4-100dd-4k-8p-4096M-1000M:10-X 54015.86 -4.0% 51851.01 thresh=1000M/ext4-10dd-4k-8p-4096M-1000M:10-X 55320.03 -2.6% 53867.63 thresh=1000M/ext4-1dd-4k-8p-4096M-1000M:10-X 37400.51 +1.6% 38012.57 thresh=100M/ext3-10dd-4k-8p-4096M-100M:10-X 45317.31 -4.5% 43272.16 thresh=100M/ext3-1dd-4k-8p-4096M-100M:10-X 40552.64 +0.8% 40884.60 thresh=100M/ext3-2dd-4k-8p-4096M-100M:10-X 44271.29 -5.6% 41789.76 thresh=100M/ext4-10dd-4k-8p-4096M-100M:10-XQuoted 8 lines
54334.22 -3.5% 52435.69 thresh=100M/ext4-1dd-4k-8p-4096M-100M:10-X 52563.67 -6.1% 49341.84 thresh=100M/ext4-2dd-4k-8p-4096M-100M:10-X 45027.95 -1.0% 44599.37 thresh=10M/ext3-1dd-4k-8p-4096M-10M:10-X 42478.40 +0.3% 42608.48 thresh=10M/ext3-2dd-4k-8p-4096M-10M:10-X 35178.47 -0.2% 35103.56 thresh=10M/ext4-10dd-4k-8p-4096M-10M:10-X 54079.64 -0.5% 53834.85 thresh=10M/ext4-1dd-4k-8p-4096M-10M:10-X 49982.11 -0.4% 49803.44 thresh=10M/ext4-2dd-4k-8p-4096M-10M:10-X 783579.17 -3.8% 753937.28 TOTAL io_wkB_sQuoted 4 lines
Here I can see some noticeable drops in the realistic thresh=100M case
(case thresh=1000M is unrealistic but it still surprise me that there are drops as well). I'll try to reproduce your results so that I can look into this more effectively.So I've run a test on a machine with 1G of memory, thresh=184M (so
something similar to your 4G-1G test). I've used tiobench using 10 threads, each thread writing 1.6G file. I have run the test 10 times to get an idea of fluctuations. The result is:
without patch with patch
AVG STDDEV AVG STDDEV
199.884820 +- 1.32268 200.466003 +- 0.377405
Quoted 4 lines
The numbers are time-to-completion so lower is better. Summary is: No statistically meaningful difference. I'll run more tests with different dirty thresholds to see whether I won't be able to observe some difference...
I carried out some tests on ext3/ext4 before/after patch. Most tests are repeated for 3 times so as to get an idea about the variations.
The ":jsize=8" notion means "-J size=8" in action.
The overall deltas are -0.3% for ext4 and -3.3% for ext3. I noticed that the regressions mostly happen for the "-J size=8" cases. For normal mkfs, ext4 actually sees +2.5% increase and ext3 sees only -0.8% drop.
I don't find any misbehaves in the graphs.
So in general I think the test results are acceptable.
Thanks,
Fengguang
---
compare-io.sh can be found here
https://github.com/fengguang/writeback-tests/
all cases:
wfg@bee /export/writeback% ./compare-io.sh snb/*/{*-3.2.0-rc1,*-3.2.0-rc1-bg-all+} | grep TOTAL
10288.05 -1.7% 10112.32 TOTAL write_bw
10515330.05 -1.7% 10340244.65 TOTAL io_wkB_s
22691.02 -0.1% 22675.29 TOTAL io_w_s
1177578.21 -3.3% 1138850.24 TOTAL io_wrqm_s
115888.13 -0.6% 115170.24 TOTAL io_avgrq_sz
17112.93 -0.5% 17032.84 TOTAL io_avgqu_sz
96998.62 +0.7% 97649.86 TOTAL io_await
838.95 -1.8% 823.97 TOTAL io_svctm
12493.72 +0.0% 12493.90 TOTAL io_util
32.06 -0.1% 32.03 TOTAL cpu_user
0.00 +nan% 0.00 TOTAL cpu_nice
514.20 -0.7% 510.85 TOTAL cpu_system
4168.71 +5402.9% 229401.29 TOTAL cpu_iowait
0.00 +nan% 0.00 TOTAL cpu_steal
7784.93 -2.5% 7587.00 TOTAL cpu_idlenormal mkfs:
wfg@bee /export/writeback% ./compare-io.sh -v jsize snb/*/{*-3.2.0-rc1,*-3.2.0-rc1-bg-all+} | grep TOTAL
5309.47 +0.9% 5357.55 TOTAL write_bw
5426694.86 +1.0% 5480854.55 TOTAL io_wkB_s
11532.74 +4.1% 12010.72 TOTAL io_w_s
599951.24 -0.9% 594789.05 TOTAL io_wrqm_s
60481.46 -2.0% 59242.21 TOTAL io_avgrq_sz
8727.64 -0.5% 8687.29 TOTAL io_avgqu_sz
49759.66 -3.6% 47945.50 TOTAL io_await
419.03 -6.6% 391.51 TOTAL io_svctm
6396.66 +0.0% 6397.08 TOTAL io_util
16.86 +2.1% 17.22 TOTAL cpu_user
0.00 +nan% 0.00 TOTAL cpu_nice
263.49 +0.0% 263.59 TOTAL cpu_system
2188.46 +4.3% 2283.60 TOTAL cpu_iowait
0.00 +nan% 0.00 TOTAL cpu_steal
3931.13 -2.4% 3835.53 TOTAL cpu_idleext3 normal mkfs:
wfg@bee /export/writeback% ./compare-io.sh -v jsize -g ext3 snb/*/{*-3.2.0-rc1,*-3.2.0-rc1-bg-all+} | grep TOTAL
2365.00 -0.8% 2345.04 TOTAL write_bw
2420077.26 -0.8% 2400572.22 TOTAL io_wkB_s
5494.17 +5.9% 5820.50 TOTAL io_w_s
599733.51 -0.9% 594590.82 TOTAL io_wrqm_s
28648.41 -4.3% 27409.62 TOTAL io_avgrq_sz
4393.66 -0.3% 4380.82 TOTAL io_avgqu_sz
26496.62 -4.1% 25409.98 TOTAL io_await
241.60 -8.8% 220.24 TOTAL io_svctm
3197.57 -0.0% 3197.26 TOTAL io_util
8.40 +1.7% 8.54 TOTAL cpu_user
0.00 +nan% 0.00 TOTAL cpu_nice
132.00 -0.5% 131.32 TOTAL cpu_system
1050.19 +5.0% 1102.49 TOTAL cpu_iowait
0.00 +nan% 0.00 TOTAL cpu_steal
2009.39 -2.6% 1957.63 TOTAL cpu_idleext4 normal mkfs:
wfg@bee /export/writeback% ./compare-io.sh -v jsize -g ext4 snb/*/{*-3.2.0-rc1,*-3.2.0-rc1-bg-all+} | grep TOTAL
2944.47 +2.3% 3012.52 TOTAL write_bw
3006617.60 +2.5% 3080282.33 TOTAL io_wkB_s
6038.57 +2.5% 6190.22 TOTAL io_w_s
217.73 -9.0% 198.23 TOTAL io_wrqm_s
31833.06 -0.0% 31832.59 TOTAL io_avgrq_sz
4333.98 -0.6% 4306.47 TOTAL io_avgqu_sz
23263.05 -3.1% 22535.51 TOTAL io_await
177.43 -3.5% 171.28 TOTAL io_svctm
3199.09 +0.0% 3199.83 TOTAL io_util
8.46 +2.6% 8.68 TOTAL cpu_user
0.00 +nan% 0.00 TOTAL cpu_nice
131.49 +0.6% 132.28 TOTAL cpu_system
1138.27 +3.8% 1181.12 TOTAL cpu_iowait
0.00 +nan% 0.00 TOTAL cpu_steal
1921.74 -2.3% 1877.90 TOTAL cpu_idleSome details for ext4/ext3:
wfg@bee /export/writeback% ./compare.rb -g ext4 -e io_wkB_s snb/*/{*-3.2.0-rc1,*-3.2.0-rc1-bg-all+}
3.2.0-rc1 3.2.0-rc1-bg-all+
------------------------ ------------------------
84473.27 +14.6% 96810.30 snb/thresh=1000M/ext4-100dd-1-3.2.0-rc1
96971.63 -0.2% 96817.43 snb/thresh=1000M/ext4-100dd-2-3.2.0-rc1
93518.20 +13.0% 105681.79 snb/thresh=1000M/ext4-10dd-1-3.2.0-rc1
91381.67 +15.4% 105428.50 snb/thresh=1000M/ext4-10dd-2-3.2.0-rc1
105734.03 -7.6% 97746.25 snb/thresh=1000M/ext4-10dd-3-3.2.0-rc1
106967.36 -9.7% 96610.37 snb/thresh=1000M/ext4-1dd-1-3.2.0-rc1
105721.10 +0.1% 105821.17 snb/thresh=1000M/ext4-1dd-2-3.2.0-rc1
93144.96 +15.1% 107163.72 snb/thresh=1000M/ext4-1dd-3-3.2.0-rc1
91008.48 -5.9% 85667.88 snb/thresh=1000M/ext4:jsize=8-100dd-1-3.2.0-rc1
83903.83 +1.7% 85332.89 snb/thresh=1000M/ext4:jsize=8-100dd-2-3.2.0-rc1
91294.62 +2.2% 93291.84 snb/thresh=1000M/ext4:jsize=8-10dd-1-3.2.0-rc1
99669.41 -6.4% 93324.27 snb/thresh=1000M/ext4:jsize=8-10dd-2-3.2.0-rc1
97860.10 -2.1% 95845.66 snb/thresh=1000M/ext4:jsize=8-1dd-1-3.2.0-rc1
94028.20 +1.2% 95164.13 snb/thresh=1000M/ext4:jsize=8-1dd-2-3.2.0-rc1
106718.79 -11.1% 94867.78 snb/thresh=1000M/ext4:jsize=8-1dd-3-3.2.0-rc1
67377.61 +13.9% 76717.96 snb/thresh=100M/ext4-100dd-1-3.2.0-rc1
76879.86 -2.9% 74629.73 snb/thresh=100M/ext4-100dd-2-3.2.0-rc1
81428.25 +13.0% 92024.19 snb/thresh=100M/ext4-10dd-1-3.2.0-rc1
81262.62 +6.9% 86877.99 snb/thresh=100M/ext4-10dd-2-3.2.0-rc1
92194.34 -9.5% 83411.11 snb/thresh=100M/ext4-10dd-3-3.2.0-rc1
94225.13 +12.7% 106187.25 snb/thresh=100M/ext4-1dd-1-3.2.0-rc1
97244.07 -0.5% 96772.82 snb/thresh=100M/ext4-1dd-2-3.2.0-rc1
91910.86 +7.9% 99214.46 snb/thresh=100M/ext4-1dd-3-3.2.0-rc1
69473.36 -2.2% 67959.60 snb/thresh=100M/ext4:jsize=8-100dd-1-3.2.0-rc1
69488.99 -2.4% 67832.74 snb/thresh=100M/ext4:jsize=8-100dd-2-3.2.0-rc1
92434.46 -10.9% 82384.58 snb/thresh=100M/ext4:jsize=8-10dd-1-3.2.0-rc1
85331.01 -3.4% 82406.72 snb/thresh=100M/ext4:jsize=8-10dd-2-3.2.0-rc1
106049.14 -11.7% 93615.96 snb/thresh=100M/ext4:jsize=8-1dd-1-3.2.0-rc1
106210.30 -11.9% 93573.97 snb/thresh=100M/ext4:jsize=8-1dd-2-3.2.0-rc1
95406.63 -2.4% 93129.65 snb/thresh=100M/ext4:jsize=8-1dd-3-3.2.0-rc1
89037.60 +0.5% 89483.46 snb/thresh=2G/ext4-100dd-1-3.2.0-rc1
88633.10 +8.8% 96438.86 snb/thresh=2G/ext4-100dd-2-3.2.0-rc1
105652.96 -11.6% 93410.17 snb/thresh=2G/ext4-10dd-1-3.2.0-rc1
91111.88 +16.7% 106299.99 snb/thresh=2G/ext4-10dd-2-3.2.0-rc1
90829.10 +16.4% 105759.23 snb/thresh=2G/ext4-10dd-3-3.2.0-rc1
108116.09 -11.4% 95782.88 snb/thresh=2G/ext4-1dd-1-3.2.0-rc1
108440.24 +0.1% 108508.84 snb/thresh=2G/ext4-1dd-2-3.2.0-rc1
95097.15 +9.4% 104081.54 snb/thresh=2G/ext4-1dd-3-3.2.0-rc1
100816.94 -9.9% 90836.14 snb/thresh=2G/ext4:jsize=8-100dd-1-3.2.0-rc1
92018.44 -3.7% 88608.54 snb/thresh=2G/ext4:jsize=8-100dd-2-3.2.0-rc1
91911.35 +4.0% 95545.77 snb/thresh=2G/ext4:jsize=8-10dd-1-3.2.0-rc1
105958.52 -11.2% 94135.56 snb/thresh=2G/ext4:jsize=8-10dd-2-3.2.0-rc1
94454.87 +1.7% 96052.07 snb/thresh=2G/ext4:jsize=8-1dd-1-3.2.0-rc1
94129.58 +2.1% 96079.46 snb/thresh=2G/ext4:jsize=8-1dd-2-3.2.0-rc1
107918.43 -11.6% 95372.06 snb/thresh=2G/ext4:jsize=8-1dd-3-3.2.0-rc1
93440.85 -7.4% 86511.28 snb/thresh=8G/ext4-100dd-1-3.2.0-rc1
90258.33 -2.9% 87628.67 snb/thresh=8G/ext4-100dd-2-3.2.0-rc1
106366.23 -13.6% 91884.53 snb/thresh=8G/ext4-10dd-1-3.2.0-rc1
92778.89 -0.6% 92213.84 snb/thresh=8G/ext4-10dd-2-3.2.0-rc1
91049.68 +15.8% 105478.65 snb/thresh=8G/ext4-10dd-3-3.2.0-rc1
94623.79 +1.1% 95704.38 snb/thresh=8G/ext4-1dd-1-3.2.0-rc1
99052.74 -1.0% 98097.38 snb/thresh=8G/ext4-1dd-2-3.2.0-rc1
101694.01 -6.5% 95083.58 snb/thresh=8G/ext4-1dd-3-3.2.0-rc1
104697.47 -9.7% 94582.62 snb/thresh=8G/ext4:jsize=8-100dd-1-3.2.0-rc1
99339.28 -3.1% 96299.59 snb/thresh=8G/ext4:jsize=8-100dd-2-3.2.0-rc1
92131.87 +6.6% 98239.08 snb/thresh=8G/ext4:jsize=8-10dd-1-3.2.0-rc1
106453.21 -10.0% 95858.09 snb/thresh=8G/ext4:jsize=8-10dd-2-3.2.0-rc1
95807.93 -3.1% 92818.24 snb/thresh=8G/ext4:jsize=8-10dd-3-3.2.0-rc1
95341.79 +13.5% 108206.19 snb/thresh=8G/ext4:jsize=8-1dd-1-3.2.0-rc1
94420.66 +2.6% 96839.02 snb/thresh=8G/ext4:jsize=8-1dd-2-3.2.0-rc1
93483.45 +7.3% 100283.10 snb/thresh=8G/ext4:jsize=8-1dd-3-3.2.0-rc1
5764378.71 -0.3% 5744435.53 TOTAL io_wkB_swfg@bee /export/writeback% ./compare.rb -g ext3 -e io_wkB_s snb/*/{*-3.2.0-rc1,*-3.2.0-rc1-bg-all+}
3.2.0-rc1 3.2.0-rc1-bg-all+
------------------------ ------------------------
67942.37 +10.7% 75241.90 snb/thresh=1000M/ext3-100dd-1-3.2.0-rc1
70086.88 +9.1% 76474.81 snb/thresh=1000M/ext3-100dd-2-3.2.0-rc1
70151.68 +14.8% 80558.96 snb/thresh=1000M/ext3-10dd-1-3.2.0-rc1
73726.08 +7.7% 79387.64 snb/thresh=1000M/ext3-10dd-2-3.2.0-rc1
74274.58 +8.2% 80379.63 snb/thresh=1000M/ext3-10dd-3-3.2.0-rc1
77488.67 -3.9% 74429.64 snb/thresh=1000M/ext3-1dd-1-3.2.0-rc1
87472.78 -5.3% 82842.31 snb/thresh=1000M/ext3-1dd-2-3.2.0-rc1
80476.31 +2.6% 82599.50 snb/thresh=1000M/ext3-1dd-3-3.2.0-rc1
74607.08 -21.1% 58885.80 snb/thresh=1000M/ext3:jsize=8-100dd-1-3.2.0-rc1
66799.19 -14.1% 57388.42 snb/thresh=1000M/ext3:jsize=8-100dd-2-3.2.0-rc1
70984.70 +1.4% 72010.71 snb/thresh=1000M/ext3:jsize=8-10dd-1-3.2.0-rc1
79739.20 -10.3% 71495.41 snb/thresh=1000M/ext3:jsize=8-10dd-2-3.2.0-rc1
73494.35 -2.1% 71919.37 snb/thresh=1000M/ext3:jsize=8-10dd-3-3.2.0-rc1
82797.80 -9.2% 75185.91 snb/thresh=1000M/ext3:jsize=8-1dd-1-3.2.0-rc1
73225.25 -2.3% 71531.99 snb/thresh=1000M/ext3:jsize=8-1dd-2-3.2.0-rc1
80920.52 -11.5% 71591.89 snb/thresh=1000M/ext3:jsize=8-1dd-3-3.2.0-rc1
55866.74 +14.5% 63983.45 snb/thresh=100M/ext3-100dd-1-3.2.0-rc1
63516.92 -10.8% 56657.25 snb/thresh=100M/ext3-100dd-2-3.2.0-rc1
79772.17 +0.2% 79962.32 snb/thresh=100M/ext3-10dd-1-3.2.0-rc1
71211.04 +3.2% 73469.61 snb/thresh=100M/ext3-10dd-2-3.2.0-rc1
75960.20 +2.3% 77684.90 snb/thresh=100M/ext3-10dd-3-3.2.0-rc1
74090.84 +12.2% 83154.21 snb/thresh=100M/ext3-1dd-1-3.2.0-rc1
82997.81 -0.3% 82755.64 snb/thresh=100M/ext3-1dd-2-3.2.0-rc1
73987.01 +10.0% 81398.04 snb/thresh=100M/ext3-1dd-3-3.2.0-rc1
60477.45 -22.0% 47175.66 snb/thresh=100M/ext3:jsize=8-100dd-1-3.2.0-rc1
51895.73 -9.1% 47196.06 snb/thresh=100M/ext3:jsize=8-100dd-2-3.2.0-rc1
70934.34 -11.1% 63057.75 snb/thresh=100M/ext3:jsize=8-10dd-1-3.2.0-rc1
73631.00 -13.8% 63444.69 snb/thresh=100M/ext3:jsize=8-10dd-2-3.2.0-rc1
70808.72 -9.7% 63915.61 snb/thresh=100M/ext3:jsize=8-10dd-3-3.2.0-rc1
81741.64 -8.0% 75201.74 snb/thresh=100M/ext3:jsize=8-1dd-1-3.2.0-rc1
73874.82 -6.8% 68886.61 snb/thresh=100M/ext3:jsize=8-1dd-2-3.2.0-rc1
82993.12 -16.5% 69303.45 snb/thresh=100M/ext3:jsize=8-1dd-3-3.2.0-rc1
68866.74 -0.8% 68311.58 snb/thresh=2G/ext3-100dd-1-3.2.0-rc1
67564.11 +13.6% 76719.46 snb/thresh=2G/ext3-100dd-2-3.2.0-rc1
75070.89 -5.4% 71030.23 snb/thresh=2G/ext3-10dd-1-3.2.0-rc1
81434.15 -2.7% 79194.71 snb/thresh=2G/ext3-10dd-2-3.2.0-rc1
73935.70 +7.7% 79592.27 snb/thresh=2G/ext3-10dd-3-3.2.0-rc1
79820.91 -7.2% 74061.53 snb/thresh=2G/ext3-1dd-1-3.2.0-rc1
77685.01 -2.1% 76026.55 snb/thresh=2G/ext3-1dd-2-3.2.0-rc1
85991.41 -9.9% 77493.53 snb/thresh=2G/ext3-1dd-3-3.2.0-rc1
67874.30 -0.5% 67532.29 snb/thresh=2G/ext3:jsize=8-100dd-1-3.2.0-rc1
68509.10 -4.4% 65490.60 snb/thresh=2G/ext3:jsize=8-100dd-2-3.2.0-rc1
70306.67 +2.4% 72015.48 snb/thresh=2G/ext3:jsize=8-10dd-1-3.2.0-rc1
79750.15 -11.7% 70393.85 snb/thresh=2G/ext3:jsize=8-10dd-2-3.2.0-rc1
77675.53 -8.9% 70737.37 snb/thresh=2G/ext3:jsize=8-10dd-3-3.2.0-rc1
79488.16 -8.0% 73142.17 snb/thresh=2G/ext3:jsize=8-1dd-1-3.2.0-rc1
74246.27 +0.8% 74833.84 snb/thresh=2G/ext3:jsize=8-1dd-2-3.2.0-rc1
72685.30 +1.7% 73896.29 snb/thresh=2G/ext3:jsize=8-1dd-3-3.2.0-rc1
77685.67 -13.3% 67340.38 snb/thresh=8G/ext3-100dd-1-3.2.0-rc1
68913.88 -2.0% 67541.52 snb/thresh=8G/ext3-100dd-2-3.2.0-rc1
77486.78 -9.4% 70175.15 snb/thresh=8G/ext3-10dd-1-3.2.0-rc1
83617.81 -13.4% 72390.80 snb/thresh=8G/ext3-10dd-2-3.2.0-rc1
73818.10 -5.3% 69890.46 snb/thresh=8G/ext3-10dd-3-3.2.0-rc1
85714.30 -14.3% 73452.90 snb/thresh=8G/ext3-1dd-1-3.2.0-rc1
76820.46 -4.7% 73246.99 snb/thresh=8G/ext3-1dd-2-3.2.0-rc1
86629.27 -15.6% 73124.34 snb/thresh=8G/ext3-1dd-3-3.2.0-rc1
62348.10 +12.7% 70243.05 snb/thresh=8G/ext3:jsize=8-100dd-1-3.2.0-rc1
68753.14 -6.8% 64044.01 snb/thresh=8G/ext3:jsize=8-100dd-2-3.2.0-rc1
70475.06 +1.7% 71693.23 snb/thresh=8G/ext3:jsize=8-10dd-1-3.2.0-rc1
69322.48 +1.2% 70162.89 snb/thresh=8G/ext3:jsize=8-10dd-2-3.2.0-rc1
78733.88 -8.0% 72443.10 snb/thresh=8G/ext3:jsize=8-10dd-3-3.2.0-rc1
72872.62 +10.8% 80718.93 snb/thresh=8G/ext3:jsize=8-1dd-1-3.2.0-rc1
76446.68 -2.5% 74534.80 snb/thresh=8G/ext3:jsize=8-1dd-2-3.2.0-rc1
72461.74 +3.7% 75163.91 snb/thresh=8G/ext3:jsize=8-1dd-3-3.2.0-rc1
4750951.34 -3.3% 4595809.11 TOTAL io_wkB_swfg@bee /export/writeback% ./compare.rb -g ext3- -e io_wkB_s snb/*/{*-3.2.0-rc1,*-3.2.0-rc1-bg-all+}
3.2.0-rc1 3.2.0-rc1-bg-all+
------------------------ ------------------------
67942.37 +10.7% 75241.90 snb/thresh=1000M/ext3-100dd-1-3.2.0-rc1
70086.88 +9.1% 76474.81 snb/thresh=1000M/ext3-100dd-2-3.2.0-rc1
70151.68 +14.8% 80558.96 snb/thresh=1000M/ext3-10dd-1-3.2.0-rc1
73726.08 +7.7% 79387.64 snb/thresh=1000M/ext3-10dd-2-3.2.0-rc1
74274.58 +8.2% 80379.63 snb/thresh=1000M/ext3-10dd-3-3.2.0-rc1
77488.67 -3.9% 74429.64 snb/thresh=1000M/ext3-1dd-1-3.2.0-rc1
87472.78 -5.3% 82842.31 snb/thresh=1000M/ext3-1dd-2-3.2.0-rc1
80476.31 +2.6% 82599.50 snb/thresh=1000M/ext3-1dd-3-3.2.0-rc1
55866.74 +14.5% 63983.45 snb/thresh=100M/ext3-100dd-1-3.2.0-rc1
63516.92 -10.8% 56657.25 snb/thresh=100M/ext3-100dd-2-3.2.0-rc1
79772.17 +0.2% 79962.32 snb/thresh=100M/ext3-10dd-1-3.2.0-rc1
71211.04 +3.2% 73469.61 snb/thresh=100M/ext3-10dd-2-3.2.0-rc1
75960.20 +2.3% 77684.90 snb/thresh=100M/ext3-10dd-3-3.2.0-rc1
74090.84 +12.2% 83154.21 snb/thresh=100M/ext3-1dd-1-3.2.0-rc1
82997.81 -0.3% 82755.64 snb/thresh=100M/ext3-1dd-2-3.2.0-rc1
73987.01 +10.0% 81398.04 snb/thresh=100M/ext3-1dd-3-3.2.0-rc1
68866.74 -0.8% 68311.58 snb/thresh=2G/ext3-100dd-1-3.2.0-rc1
67564.11 +13.6% 76719.46 snb/thresh=2G/ext3-100dd-2-3.2.0-rc1
75070.89 -5.4% 71030.23 snb/thresh=2G/ext3-10dd-1-3.2.0-rc1
81434.15 -2.7% 79194.71 snb/thresh=2G/ext3-10dd-2-3.2.0-rc1
73935.70 +7.7% 79592.27 snb/thresh=2G/ext3-10dd-3-3.2.0-rc1
79820.91 -7.2% 74061.53 snb/thresh=2G/ext3-1dd-1-3.2.0-rc1
77685.01 -2.1% 76026.55 snb/thresh=2G/ext3-1dd-2-3.2.0-rc1
85991.41 -9.9% 77493.53 snb/thresh=2G/ext3-1dd-3-3.2.0-rc1
77685.67 -13.3% 67340.38 snb/thresh=8G/ext3-100dd-1-3.2.0-rc1
68913.88 -2.0% 67541.52 snb/thresh=8G/ext3-100dd-2-3.2.0-rc1
77486.78 -9.4% 70175.15 snb/thresh=8G/ext3-10dd-1-3.2.0-rc1
83617.81 -13.4% 72390.80 snb/thresh=8G/ext3-10dd-2-3.2.0-rc1
73818.10 -5.3% 69890.46 snb/thresh=8G/ext3-10dd-3-3.2.0-rc1
85714.30 -14.3% 73452.90 snb/thresh=8G/ext3-1dd-1-3.2.0-rc1
76820.46 -4.7% 73246.99 snb/thresh=8G/ext3-1dd-2-3.2.0-rc1
86629.27 -15.6% 73124.34 snb/thresh=8G/ext3-1dd-3-3.2.0-rc1
2420077.26 -0.8% 2400572.22 TOTAL io_wkB_swfg@bee /export/writeback% ./compare.rb -g ext4- -e io_wkB_s snb/*/{*-3.2.0-rc1,*-3.2.0-rc1-bg-all+}
3.2.0-rc1 3.2.0-rc1-bg-all+
------------------------ ------------------------
84473.27 +14.6% 96810.30 snb/thresh=1000M/ext4-100dd-1-3.2.0-rc1
96971.63 -0.2% 96817.43 snb/thresh=1000M/ext4-100dd-2-3.2.0-rc1
93518.20 +13.0% 105681.79 snb/thresh=1000M/ext4-10dd-1-3.2.0-rc1
91381.67 +15.4% 105428.50 snb/thresh=1000M/ext4-10dd-2-3.2.0-rc1
105734.03 -7.6% 97746.25 snb/thresh=1000M/ext4-10dd-3-3.2.0-rc1
106967.36 -9.7% 96610.37 snb/thresh=1000M/ext4-1dd-1-3.2.0-rc1
105721.10 +0.1% 105821.17 snb/thresh=1000M/ext4-1dd-2-3.2.0-rc1
93144.96 +15.1% 107163.72 snb/thresh=1000M/ext4-1dd-3-3.2.0-rc1
67377.61 +13.9% 76717.96 snb/thresh=100M/ext4-100dd-1-3.2.0-rc1
76879.86 -2.9% 74629.73 snb/thresh=100M/ext4-100dd-2-3.2.0-rc1
81428.25 +13.0% 92024.19 snb/thresh=100M/ext4-10dd-1-3.2.0-rc1
81262.62 +6.9% 86877.99 snb/thresh=100M/ext4-10dd-2-3.2.0-rc1
92194.34 -9.5% 83411.11 snb/thresh=100M/ext4-10dd-3-3.2.0-rc1
94225.13 +12.7% 106187.25 snb/thresh=100M/ext4-1dd-1-3.2.0-rc1
97244.07 -0.5% 96772.82 snb/thresh=100M/ext4-1dd-2-3.2.0-rc1
91910.86 +7.9% 99214.46 snb/thresh=100M/ext4-1dd-3-3.2.0-rc1
89037.60 +0.5% 89483.46 snb/thresh=2G/ext4-100dd-1-3.2.0-rc1
88633.10 +8.8% 96438.86 snb/thresh=2G/ext4-100dd-2-3.2.0-rc1
105652.96 -11.6% 93410.17 snb/thresh=2G/ext4-10dd-1-3.2.0-rc1
91111.88 +16.7% 106299.99 snb/thresh=2G/ext4-10dd-2-3.2.0-rc1
90829.10 +16.4% 105759.23 snb/thresh=2G/ext4-10dd-3-3.2.0-rc1
108116.09 -11.4% 95782.88 snb/thresh=2G/ext4-1dd-1-3.2.0-rc1
108440.24 +0.1% 108508.84 snb/thresh=2G/ext4-1dd-2-3.2.0-rc1
95097.15 +9.4% 104081.54 snb/thresh=2G/ext4-1dd-3-3.2.0-rc1
93440.85 -7.4% 86511.28 snb/thresh=8G/ext4-100dd-1-3.2.0-rc1
90258.33 -2.9% 87628.67 snb/thresh=8G/ext4-100dd-2-3.2.0-rc1
106366.23 -13.6% 91884.53 snb/thresh=8G/ext4-10dd-1-3.2.0-rc1
92778.89 -0.6% 92213.84 snb/thresh=8G/ext4-10dd-2-3.2.0-rc1
91049.68 +15.8% 105478.65 snb/thresh=8G/ext4-10dd-3-3.2.0-rc1
94623.79 +1.1% 95704.38 snb/thresh=8G/ext4-1dd-1-3.2.0-rc1
99052.74 -1.0% 98097.38 snb/thresh=8G/ext4-1dd-2-3.2.0-rc1
101694.01 -6.5% 95083.58 snb/thresh=8G/ext4-1dd-3-3.2.0-rc1
3006617.60 +2.5% 3080282.33 TOTAL io_wkB_sThanks,
Fengguang
Jan Kara
reviewerRe: [PATCH 1/2] writeback: Improve busyloop prevention
Hello Fengguang,
Quoted 45 lines · Wu Fengguang
Quoted 34 lines · Jan Kara
Quoted 21 lines · Jan Kara
Quoted 13 lines
wfg@bee /export/writeback% ./compare.rb -v jsize -e
io_wkB_sthresh*/*-ioless-full-next-20111102+ thresh*/*-20111102+ 3.1.0-ioless-full-next-20111102+ 3.1.0-ioless-full-bg-all-next-20111102+
------------------------ ------------------------36231.89 -3.8% 34855.10 thresh=1000M/ext3-100dd-4k-8p-4096M-1000M:10-X 41115.07 -12.7% 35886.36 thresh=1000M/ext3-10dd-4k-8p-4096M-1000M:10-X 48025.75 -14.3% 41146.57 thresh=1000M/ext3-1dd-4k-8p-4096M-1000M:10-X 47684.35 -6.4% 44644.30 thresh=1000M/ext4-100dd-4k-8p-4096M-1000M:10-X 54015.86 -4.0% 51851.01 thresh=1000M/ext4-10dd-4k-8p-4096M-1000M:10-X 55320.03 -2.6% 53867.63 thresh=1000M/ext4-1dd-4k-8p-4096M-1000M:10-X 37400.51 +1.6% 38012.57 thresh=100M/ext3-10dd-4k-8p-4096M-100M:10-X 45317.31 -4.5% 43272.16 thresh=100M/ext3-1dd-4k-8p-4096M-100M:10-X 40552.64 +0.8% 40884.60 thresh=100M/ext3-2dd-4k-8p-4096M-100M:10-X 44271.29 -5.6% 41789.76 thresh=100M/ext4-10dd-4k-8p-4096M-100M:10-XQuoted 8 lines
54334.22 -3.5% 52435.69 thresh=100M/ext4-1dd-4k-8p-4096M-100M:10-X 52563.67 -6.1% 49341.84 thresh=100M/ext4-2dd-4k-8p-4096M-100M:10-X 45027.95 -1.0% 44599.37 thresh=10M/ext3-1dd-4k-8p-4096M-10M:10-X 42478.40 +0.3% 42608.48 thresh=10M/ext3-2dd-4k-8p-4096M-10M:10-X 35178.47 -0.2% 35103.56 thresh=10M/ext4-10dd-4k-8p-4096M-10M:10-X 54079.64 -0.5% 53834.85 thresh=10M/ext4-1dd-4k-8p-4096M-10M:10-X 49982.11 -0.4% 49803.44 thresh=10M/ext4-2dd-4k-8p-4096M-10M:10-X 783579.17 -3.8% 753937.28 TOTAL io_wkB_sQuoted 4 lines
Here I can see some noticeable drops in the realistic thresh=100M case
(case thresh=1000M is unrealistic but it still surprise me that there are drops as well). I'll try to reproduce your results so that I can look into this more effectively.So I've run a test on a machine with 1G of memory, thresh=184M (so
something similar to your 4G-1G test). I've used tiobench using 10 threads, each thread writing 1.6G file. I have run the test 10 times to get an idea of fluctuations. The result is:
without patch with patch
AVG STDDEV AVG STDDEV
199.884820 +- 1.32268 200.466003 +- 0.377405Quoted 4 lines
The numbers are time-to-completion so lower is better. Summary is: No statistically meaningful difference. I'll run more tests with different dirty thresholds to see whether I won't be able to observe some difference...
I carried out some tests on ext3/ext4 before/after patch. Most tests are repeated for 3 times so as to get an idea about the variations.
The ":jsize=8" notion means "-J size=8" in action.
Quoted 7 lines
The overall deltas are -0.3% for ext4 and -3.3% for ext3. I noticed that the regressions mostly happen for the "-J size=8" cases. For normal mkfs, ext4 actually sees +2.5% increase and ext3 sees only -0.8% drop.
I don't find any misbehaves in the graphs.
So in general I think the test results are acceptable.
Thanks for running the tests. I looked through the results and given the
variation I would be happy with them. Will you merge the patch or should I resend it?
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 1/2] writeback: Improve busyloop prevention
Jan,
Quoted 5 lines
Quoted 2 lines
I don't find any misbehaves in the graphs.
So in general I think the test results are acceptable.Thanks for running the tests. I looked through the results and given the
variation I would be happy with them. Will you merge the patch or should I resend it?
The patch I tested is this one. It's obviously better than w/ patch.
Looking backing a bit more, the change is related to the old topic "how can the flush order align better with the LRU order". The general idea was to make background work behave more like kupdate work which I still think is a good idea. However the patch I proposed at the time have some unpleasant/convoluted "goto" and didn't make it eventually. The code is then leaved in this bad state...
I'll merge this patch.
Thanks,
Fengguang
---
Subject: writeback: Include all dirty inodes in background writeback
Date: Wed, 19 Oct 2011 11:44:41 +0200
From: Jan Kara <[email protected]>
Current livelock avoidance code makes background work to include only inodes that were dirtied before background writeback has started. However background writeback can be running for a long time and thus excluding newly dirtied inodes can eventually exclude significant portion of dirty inodes making background writeback inefficient. Since background writeback avoids livelocking the flusher thread by yielding to any other work, there is no real reason why background work should not include all dirty inodes so change the logic in wb_writeback().
--- fs/fs-writeback.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/fs-writeback.c +8 -2
@@ -780,11 +780,17 @@ static long wb_writeback(struct bdi_writif (work->for_background && !over_bground_thresh (wb->bdi))break ; +/* +* Kupdate and background works are special and we want to +* include all inodes that need writing. Livelock avoidance is +* handled by these works yielding to any other work so we are +* safe. +*/ if (work->for_kupdate) { oldest_jif = jiffies -msecs_to_jiffies (dirty_expire_interval *10 ); - work->older_than_this = &oldest_jif; - } + }else if (work->for_background) + oldest_jif = jiffies;trace_writeback_start (wb->bdi, work);if (list_empty (&wb->b_io))