From: "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx> Subject: mm: move readahead nr_pages check into read_pages Simplify the callers by moving the check for nr_pages and the BUG_ON into read_pages(). Link: http://lkml.kernel.org/r/20200414150233.24495-5-willy@xxxxxxxxxxxxx Signed-off-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx> Reviewed-by: Zi Yan <ziy@xxxxxxxxxx> Reviewed-by: John Hubbard <jhubbard@xxxxxxxxxx> Reviewed-by: Christoph Hellwig <hch@xxxxxx> Reviewed-by: William Kucharski <william.kucharski@xxxxxxxxxx> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@xxxxxxx> Cc: Chao Yu <yuchao0@xxxxxxxxxx> Cc: Cong Wang <xiyou.wangcong@xxxxxxxxx> Cc: Darrick J. Wong <darrick.wong@xxxxxxxxxx> Cc: Dave Chinner <dchinner@xxxxxxxxxx> Cc: Eric Biggers <ebiggers@xxxxxxxxxx> Cc: Gao Xiang <gaoxiang25@xxxxxxxxxx> Cc: Jaegeuk Kim <jaegeuk@xxxxxxxxxx> Cc: Joseph Qi <joseph.qi@xxxxxxxxxxxxxxxxx> Cc: Junxiao Bi <junxiao.bi@xxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Cc: Miklos Szeredi <mszeredi@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/readahead.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) --- a/mm/readahead.c~mm-move-readahead-nr_pages-check-into-read_pages +++ a/mm/readahead.c @@ -119,6 +119,9 @@ static void read_pages(struct address_sp struct blk_plug plug; unsigned page_idx; + if (!nr_pages) + return; + blk_start_plug(&plug); if (mapping->a_ops->readpages) { @@ -138,6 +141,8 @@ static void read_pages(struct address_sp out: blk_finish_plug(&plug); + + BUG_ON(!list_empty(pages)); } /* @@ -180,8 +185,7 @@ void __do_page_cache_readahead(struct ad * contiguous pages before continuing with the next * batch. */ - if (nr_pages) - read_pages(mapping, filp, &page_pool, nr_pages, + read_pages(mapping, filp, &page_pool, nr_pages, gfp_mask); nr_pages = 0; continue; @@ -202,9 +206,7 @@ void __do_page_cache_readahead(struct ad * uptodate then the caller will launch readpage again, and * will then handle the error. */ - if (nr_pages) - read_pages(mapping, filp, &page_pool, nr_pages, gfp_mask); - BUG_ON(!list_empty(&page_pool)); + read_pages(mapping, filp, &page_pool, nr_pages, gfp_mask); } /* _