writeback: make mapping->writeback_index to point to the last written page
For range-cyclic writeback (e.g. kupdate), the writeback code sets a
continuation point of the next writeback to mapping->writeback_index which
is set the page after the last written page. This happens so that we
evenly write the whole file even if pages in it get continuously
redirtied.
However, in some cases, sequential writer is writing in the middle of the
page and it just redirties the last written page by continuing from that.
For example with an application which uses a file as a big ring buffer we
see:
[1st writeback session]
...
flush-8:0-2743 4571: block_bio_queue: 8,0 W
94898514 + 8
flush-8:0-2743 4571: block_bio_queue: 8,0 W
94898522 + 8
flush-8:0-2743 4571: block_bio_queue: 8,0 W
94898530 + 8
flush-8:0-2743 4571: block_bio_queue: 8,0 W
94898538 + 8
flush-8:0-2743 4571: block_bio_queue: 8,0 W
94898546 + 8
kworker/0:1-11 4571: block_rq_issue: 8,0 W 0 ()
94898514 + 40
>> flush-8:0-2743 4571: block_bio_queue: 8,0 W
94898554 + 8
>> flush-8:0-2743 4571: block_rq_issue: 8,0 W 0 ()
94898554 + 8
[2nd writeback session after 35sec]
flush-8:0-2743 4606: block_bio_queue: 8,0 W
94898562 + 8
flush-8:0-2743 4606: block_bio_queue: 8,0 W
94898570 + 8
flush-8:0-2743 4606: block_bio_queue: 8,0 W
94898578 + 8
...
kworker/0:1-11 4606: block_rq_issue: 8,0 W 0 ()
94898562 + 640
kworker/0:1-11 4606: block_rq_issue: 8,0 W 0 ()
94899202 + 72
...
flush-8:0-2743 4606: block_bio_queue: 8,0 W
94899962 + 8
flush-8:0-2743 4606: block_bio_queue: 8,0 W
94899970 + 8
flush-8:0-2743 4606: block_bio_queue: 8,0 W
94899978 + 8
flush-8:0-2743 4606: block_bio_queue: 8,0 W
94899986 + 8
flush-8:0-2743 4606: block_bio_queue: 8,0 W
94899994 + 8
kworker/0:1-11 4606: block_rq_issue: 8,0 W 0 ()
94899962 + 40
>> flush-8:0-2743 4606: block_bio_queue: 8,0 W
94898554 + 8
>> flush-8:0-2743 4606: block_rq_issue: 8,0 W 0 ()
94898554 + 8
So we seeked back to
94898554 after we wrote all the pages at the end of
the file.
This extra seek seems unnecessary. If we continue writeback from the last
written page, we can avoid it and do not cause harm to other cases. The
original intent of even writeout over the whole file is preserved and if
the page does not get redirtied pagevec_lookup_tag() just skips it.
As an exceptional case, when I/O error happens, set done_index to the next
page as the comment in the code suggests.
Tested-by: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>