--- linux-2.6.8/mm/readahead.c 2004-09-29 17:47:02.677375832 -0700 +++ linux-2.6.8.comment/mm/readahead.c 2004-09-29 17:39:00.880620072 -0700 @@ -329,18 +329,16 @@ int do_page_cache_readahead(struct addre * occasionally. */ static inline void -check_ra_success(struct file_ra_state *ra, pgoff_t attempt, - pgoff_t actual, pgoff_t orig_next_size) +check_ra_success(struct file_ra_state *ra, pgoff_t attempt, pgoff_t actual) { - if (actual == 0) { - if (orig_next_size > 1) { - ra->next_size = orig_next_size - 1; - if (ra->ahead_size) - ra->ahead_size = ra->next_size; - } else { - ra->next_size = -1UL; - ra->size = 0; - } + /* + * decrement window size by the number of pages hitting + * the page cache + */ + ra->next_size -= attempt - actual; + if (ra->next_size <= 0) { + ra->next_size = -1UL; + ra->size = 0; } } @@ -353,7 +351,6 @@ page_cache_readahead(struct address_spac struct file *filp, unsigned long offset) { unsigned max; - unsigned orig_next_size; unsigned actual; int first_access=0; unsigned long average; @@ -377,7 +374,6 @@ page_cache_readahead(struct address_spac if (max == 0) goto out; /* No readahead */ - orig_next_size = ra->next_size; if (ra->next_size == 0) { /* @@ -489,7 +485,7 @@ do_io: * time, the ahead window might get closed if all * the pages are already in the cache. */ - check_ra_success(ra, ra->size, actual, orig_next_size); + check_ra_success(ra, ra->size, actual); } } else { /* @@ -516,8 +512,7 @@ do_io: ra->ahead_size = ra->next_size; actual = do_page_cache_readahead(mapping, filp, ra->ahead_start, ra->ahead_size); - check_ra_success(ra, ra->ahead_size, - actual, orig_next_size); + check_ra_success(ra, ra->ahead_size, actual); } } }