- cancel look-ahead if readahead size is small compared to the look-ahead size,
to avoid too small I/O size, and not to add more memory/io pressure on the
possibly loaded system.
- prevent issuing tiny readahead size, by applying a minimal limit
Signed-off-by: Fengguang Wu <[email protected]>
---
mm/readahead.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
--- linux-2.6.20-rc4-mm1.orig/mm/readahead.c
+++ linux-2.6.20-rc4-mm1/mm/readahead.c
@@ -932,17 +932,21 @@ static int adjust_rala(unsigned long ra_
unsigned long *ra_size, unsigned long *la_size)
{
/*
- * Substract the old look-ahead to get real safe size for the next
- * read-ahead request.
+ * Cancel asynchrous read-ahead,
+ * if there is a major upsurge of load, or fall of this stream's speed.
*/
- if (*ra_size > *la_size)
- *ra_size -= *la_size;
- else {
+ if (*ra_size <= *la_size * 2) {
ra_account(NULL, RA_EVENT_READAHEAD_SHRINK, *ra_size);
return 0;
}
/*
+ * Substract the old look-ahead to get real safe size for the next
+ * read-ahead request.
+ */
+ *ra_size -= *la_size;
+
+ /*
* Set new la_size according to the (still large) ra_size.
*/
*la_size = *ra_size / LOOKAHEAD_RATIO;
@@ -956,6 +960,13 @@ static void limit_rala(unsigned long ra_
unsigned long stream_shift;
/*
+ * Protect against too small I/O sizes,
+ * by mapping [0, 4*min] to [min, 4*min].
+ */
+ if (*ra_size < 4 * MIN_RA_PAGES)
+ *ra_size = MIN_RA_PAGES + *ra_size * 3 / 4;
+
+ /*
* Apply basic upper limits.
*/
if (*ra_size > ra_max)
--