Skip to content

Commit

Permalink
mm: improve cleanup when ->readpages doesn't process all pages
Browse files Browse the repository at this point in the history
If ->readpages doesn't process all the pages, then it is best to act as
though they weren't requested so that a subsequent readahead can try
again.

So:

  - remove any 'ahead' pages from the page cache so they can be loaded
    with ->readahead() rather then multiple ->read()s

  - update the file_ra_state to reflect the reads that were actually
    submitted.

This allows ->readpages() to abort early due e.g.  to congestion, which
will then allow us to remove the inode_read_congested() test from
page_Cache_async_ra().

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: NeilBrown <[email protected]>
Cc: Anna Schumaker <[email protected]>
Cc: Chao Yu <[email protected]>
Cc: Darrick J. Wong <[email protected]>
Cc: Ilya Dryomov <[email protected]>
Cc: Jaegeuk Kim <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Jeff Layton <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Lars Ellenberg <[email protected]>
Cc: Miklos Szeredi <[email protected]>
Cc: Paolo Valente <[email protected]>
Cc: Philipp Reisner <[email protected]>
Cc: Ryusuke Konishi <[email protected]>
Cc: Trond Myklebust <[email protected]>
Cc: Wu Fengguang <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
neilbrown authored and torvalds committed Mar 22, 2022
1 parent 84dacdb commit 9fd472a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions mm/readahead.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@
* for necessary resources (e.g. memory or indexing information) to
* become available. Pages in the final ``async_size`` may be
* considered less urgent and failure to read them is more acceptable.
* They will eventually be read individually using ->readpage().
* In this case it is best to use delete_from_page_cache() to remove the
* pages from the page cache as is automatically done for pages that
* were not fetched with readahead_page(). This will allow a
* subsequent synchronous read ahead request to try them again. If they
* are left in the page cache, then they will be read individually using
* ->readpage().
*
*/

#include <linux/kernel.h>
Expand Down Expand Up @@ -226,8 +232,17 @@ static void read_pages(struct readahead_control *rac, struct list_head *pages,

if (aops->readahead) {
aops->readahead(rac);
/* Clean up the remaining pages */
/*
* Clean up the remaining pages. The sizes in ->ra
* maybe be used to size next read-ahead, so make sure
* they accurately reflect what happened.
*/
while ((page = readahead_page(rac))) {
rac->ra->size -= 1;
if (rac->ra->async_size > 0) {
rac->ra->async_size -= 1;
delete_from_page_cache(page);
}
unlock_page(page);
put_page(page);
}
Expand Down

0 comments on commit 9fd472a

Please sign in to comment.