From: Fengguang Wu Move the call to thrashing_recovery_readahead() before state_based_readahead(). That catches the rare case where thrashing happened on the time we are to read the page at ra->lookahead_index. Obviously this case should be handled by thrashing_recovery_readahead() instead of state_based_readahead(). Signed-off-by: Fengguang Wu Signed-off-by: Andrew Morton --- mm/readahead.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff -puN mm/readahead.c~readahead-call-scheme-catch-thrashing-on-lookahead-time mm/readahead.c --- a/mm/readahead.c~readahead-call-scheme-catch-thrashing-on-lookahead-time +++ a/mm/readahead.c @@ -1638,6 +1638,13 @@ page_cache_readahead_adaptive(struct add return initial_readahead(mapping, filp, ra, req_size); /* + * Recover from possible thrashing. + */ + if (!page && offset - ra->prev_page <= 1 && ra_has_index(ra, offset)) + return thrashing_recovery_readahead(mapping, filp, ra, + offset, ra_max); + + /* * State based sequential read-ahead. */ if (offset == ra->prev_page + 1 && @@ -1647,13 +1654,6 @@ page_cache_readahead_adaptive(struct add offset, req_size, ra_max); /* - * Recover from possible thrashing. - */ - if (!page && offset - ra->prev_page <= 1 && ra_has_index(ra, offset)) - return thrashing_recovery_readahead(mapping, filp, ra, - offset, ra_max); - - /* * Backward read-ahead. */ if (!page && try_backward_prefetching(ra, offset, req_size, ra_max)) _