[PATCH] mm: write_cache_pages be more sequential

From: Adrian Hunter
Date: Mon Sep 07 2009 - 03:49:11 EST


If a file is written to sequentially, then writeback
should write the pages sequentially also. However,
that does not always happen. For example:

1) user writes pages 0, 1 and 2 but 2 is incomplete
2) write_cache_pages writes pages 0, 1 and 2 and sets
writeback_index to 3
3) user finishes writing page 2 and writes pages 3 and 4
4) write_cache_pages writes pages 3 and 4, and then cycles
back and writes page 2 again.

So the pages are written out in the order 0, 1, 2, 3 ,4 ,2
instead of 0, 1, 2, 2, 3, 4.

This situation was noticed on UBIFS because it writes
directly from writepage. Hence if there is an unexpected
power-loss, a file will end up with a hole even though
the file was written sequentially by the user.

Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
---
mm/page-writeback.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 81627eb..7410b7a 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -960,6 +960,8 @@ int write_cache_pages(struct address_space *mapping,
pagevec_init(&pvec, 0);
if (wbc->range_cyclic) {
writeback_index = mapping->writeback_index; /* prev offset */
+ if (writeback_index)
+ writeback_index -= 1;
index = writeback_index;
if (index == 0)
cycled = 1;
--
1.5.6.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/