Skip to content

Commit d438834

Browse files
Matthew Wilcox (Oracle)torvalds
authored andcommitted
fs: convert mpage_readpages to mpage_readahead
Implement the new readahead aop and convert all callers (block_dev, exfat, ext2, fat, gfs2, hpfs, isofs, jfs, nilfs2, ocfs2, omfs, qnx6, reiserfs & udf). The callers are all trivial except for GFS2 & OCFS2. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Junxiao Bi <junxiao.bi@oracle.com> # ocfs2 Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> # ocfs2 Reviewed-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: John Hubbard <jhubbard@nvidia.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: William Kucharski <william.kucharski@oracle.com> Cc: Chao Yu <yuchao0@huawei.com> Cc: Cong Wang <xiyou.wangcong@gmail.com> Cc: Darrick J. Wong <darrick.wong@oracle.com> Cc: Eric Biggers <ebiggers@google.com> Cc: Gao Xiang <gaoxiang25@huawei.com> Cc: Jaegeuk Kim <jaegeuk@kernel.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Zi Yan <ziy@nvidia.com> Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com> Cc: Miklos Szeredi <mszeredi@redhat.com> Link: http://lkml.kernel.org/r/20200414150233.24495-17-willy@infradead.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f2c817b commit d438834

18 files changed

Lines changed: 73 additions & 126 deletions

File tree

‎fs/block_dev.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,9 @@ static int blkdev_readpage(struct file * file, struct page * page)
614614
return block_read_full_page(page, blkdev_get_block);
615615
}
616616

617-
static int blkdev_readpages(struct file *file, struct address_space *mapping,
618-
struct list_head *pages, unsigned nr_pages)
617+
static void blkdev_readahead(struct readahead_control *rac)
619618
{
620-
return mpage_readpages(mapping, pages, nr_pages, blkdev_get_block);
619+
mpage_readahead(rac, blkdev_get_block);
621620
}
622621

623622
static int blkdev_write_begin(struct file *file, struct address_space *mapping,
@@ -2085,7 +2084,7 @@ static int blkdev_writepages(struct address_space *mapping,
20852084

20862085
static const struct address_space_operations def_blk_aops = {
20872086
.readpage = blkdev_readpage,
2088-
.readpages = blkdev_readpages,
2087+
.readahead = blkdev_readahead,
20892088
.writepage = blkdev_writepage,
20902089
.write_begin = blkdev_write_begin,
20912090
.write_end = blkdev_write_end,

‎fs/exfat/inode.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,9 @@ static int exfat_readpage(struct file *file, struct page *page)
372372
return mpage_readpage(page, exfat_get_block);
373373
}
374374

375-
static int exfat_readpages(struct file *file, struct address_space *mapping,
376-
struct list_head *pages, unsigned int nr_pages)
375+
static void exfat_readahead(struct readahead_control *rac)
377376
{
378-
return mpage_readpages(mapping, pages, nr_pages, exfat_get_block);
377+
mpage_readahead(rac, exfat_get_block);
379378
}
380379

381380
static int exfat_writepage(struct page *page, struct writeback_control *wbc)
@@ -502,7 +501,7 @@ int exfat_block_truncate_page(struct inode *inode, loff_t from)
502501

503502
static const struct address_space_operations exfat_aops = {
504503
.readpage = exfat_readpage,
505-
.readpages = exfat_readpages,
504+
.readahead = exfat_readahead,
506505
.writepage = exfat_writepage,
507506
.writepages = exfat_writepages,
508507
.write_begin = exfat_write_begin,

‎fs/ext2/inode.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -877,11 +877,9 @@ static int ext2_readpage(struct file *file, struct page *page)
877877
return mpage_readpage(page, ext2_get_block);
878878
}
879879

880-
static int
881-
ext2_readpages(struct file *file, struct address_space *mapping,
882-
struct list_head *pages, unsigned nr_pages)
880+
static void ext2_readahead(struct readahead_control *rac)
883881
{
884-
return mpage_readpages(mapping, pages, nr_pages, ext2_get_block);
882+
mpage_readahead(rac, ext2_get_block);
885883
}
886884

887885
static int
@@ -967,7 +965,7 @@ ext2_dax_writepages(struct address_space *mapping, struct writeback_control *wbc
967965

968966
const struct address_space_operations ext2_aops = {
969967
.readpage = ext2_readpage,
970-
.readpages = ext2_readpages,
968+
.readahead = ext2_readahead,
971969
.writepage = ext2_writepage,
972970
.write_begin = ext2_write_begin,
973971
.write_end = ext2_write_end,
@@ -981,7 +979,7 @@ const struct address_space_operations ext2_aops = {
981979

982980
const struct address_space_operations ext2_nobh_aops = {
983981
.readpage = ext2_readpage,
984-
.readpages = ext2_readpages,
982+
.readahead = ext2_readahead,
985983
.writepage = ext2_nobh_writepage,
986984
.write_begin = ext2_nobh_write_begin,
987985
.write_end = nobh_write_end,

‎fs/fat/inode.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,9 @@ static int fat_readpage(struct file *file, struct page *page)
210210
return mpage_readpage(page, fat_get_block);
211211
}
212212

213-
static int fat_readpages(struct file *file, struct address_space *mapping,
214-
struct list_head *pages, unsigned nr_pages)
213+
static void fat_readahead(struct readahead_control *rac)
215214
{
216-
return mpage_readpages(mapping, pages, nr_pages, fat_get_block);
215+
mpage_readahead(rac, fat_get_block);
217216
}
218217

219218
static void fat_write_failed(struct address_space *mapping, loff_t to)
@@ -344,7 +343,7 @@ int fat_block_truncate_page(struct inode *inode, loff_t from)
344343

345344
static const struct address_space_operations fat_aops = {
346345
.readpage = fat_readpage,
347-
.readpages = fat_readpages,
346+
.readahead = fat_readahead,
348347
.writepage = fat_writepage,
349348
.writepages = fat_writepages,
350349
.write_begin = fat_write_begin,

‎fs/gfs2/aops.c‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ int gfs2_internal_read(struct gfs2_inode *ip, char *buf, loff_t *pos,
577577
}
578578

579579
/**
580-
* gfs2_readpages - Read a bunch of pages at once
580+
* gfs2_readahead - Read a bunch of pages at once
581581
* @file: The file to read from
582582
* @mapping: Address space info
583583
* @pages: List of pages to read
@@ -590,31 +590,24 @@ int gfs2_internal_read(struct gfs2_inode *ip, char *buf, loff_t *pos,
590590
* obviously not something we'd want to do on too regular a basis.
591591
* Any I/O we ignore at this time will be done via readpage later.
592592
* 2. We don't handle stuffed files here we let readpage do the honours.
593-
* 3. mpage_readpages() does most of the heavy lifting in the common case.
593+
* 3. mpage_readahead() does most of the heavy lifting in the common case.
594594
* 4. gfs2_block_map() is relied upon to set BH_Boundary in the right places.
595595
*/
596596

597-
static int gfs2_readpages(struct file *file, struct address_space *mapping,
598-
struct list_head *pages, unsigned nr_pages)
597+
static void gfs2_readahead(struct readahead_control *rac)
599598
{
600-
struct inode *inode = mapping->host;
599+
struct inode *inode = rac->mapping->host;
601600
struct gfs2_inode *ip = GFS2_I(inode);
602-
struct gfs2_sbd *sdp = GFS2_SB(inode);
603601
struct gfs2_holder gh;
604-
int ret;
605602

606603
gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
607-
ret = gfs2_glock_nq(&gh);
608-
if (unlikely(ret))
604+
if (gfs2_glock_nq(&gh))
609605
goto out_uninit;
610606
if (!gfs2_is_stuffed(ip))
611-
ret = mpage_readpages(mapping, pages, nr_pages, gfs2_block_map);
607+
mpage_readahead(rac, gfs2_block_map);
612608
gfs2_glock_dq(&gh);
613609
out_uninit:
614610
gfs2_holder_uninit(&gh);
615-
if (unlikely(gfs2_withdrawn(sdp)))
616-
ret = -EIO;
617-
return ret;
618611
}
619612

620613
/**
@@ -833,7 +826,7 @@ static const struct address_space_operations gfs2_aops = {
833826
.writepage = gfs2_writepage,
834827
.writepages = gfs2_writepages,
835828
.readpage = gfs2_readpage,
836-
.readpages = gfs2_readpages,
829+
.readahead = gfs2_readahead,
837830
.bmap = gfs2_bmap,
838831
.invalidatepage = gfs2_invalidatepage,
839832
.releasepage = gfs2_releasepage,
@@ -847,7 +840,7 @@ static const struct address_space_operations gfs2_jdata_aops = {
847840
.writepage = gfs2_jdata_writepage,
848841
.writepages = gfs2_jdata_writepages,
849842
.readpage = gfs2_readpage,
850-
.readpages = gfs2_readpages,
843+
.readahead = gfs2_readahead,
851844
.set_page_dirty = jdata_set_page_dirty,
852845
.bmap = gfs2_bmap,
853846
.invalidatepage = gfs2_invalidatepage,

‎fs/hpfs/file.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@ static int hpfs_writepage(struct page *page, struct writeback_control *wbc)
125125
return block_write_full_page(page, hpfs_get_block, wbc);
126126
}
127127

128-
static int hpfs_readpages(struct file *file, struct address_space *mapping,
129-
struct list_head *pages, unsigned nr_pages)
128+
static void hpfs_readahead(struct readahead_control *rac)
130129
{
131-
return mpage_readpages(mapping, pages, nr_pages, hpfs_get_block);
130+
mpage_readahead(rac, hpfs_get_block);
132131
}
133132

134133
static int hpfs_writepages(struct address_space *mapping,
@@ -198,7 +197,7 @@ static int hpfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
198197
const struct address_space_operations hpfs_aops = {
199198
.readpage = hpfs_readpage,
200199
.writepage = hpfs_writepage,
201-
.readpages = hpfs_readpages,
200+
.readahead = hpfs_readahead,
202201
.writepages = hpfs_writepages,
203202
.write_begin = hpfs_write_begin,
204203
.write_end = hpfs_write_end,

‎fs/iomap/buffered-io.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ iomap_readpage(struct page *page, const struct iomap_ops *ops)
367367
}
368368

369369
/*
370-
* Just like mpage_readpages and block_read_full_page we always
370+
* Just like mpage_readahead and block_read_full_page we always
371371
* return 0 and just mark the page as PageError on errors. This
372372
* should be cleaned up all through the stack eventually.
373373
*/

‎fs/isofs/inode.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,10 +1185,9 @@ static int isofs_readpage(struct file *file, struct page *page)
11851185
return mpage_readpage(page, isofs_get_block);
11861186
}
11871187

1188-
static int isofs_readpages(struct file *file, struct address_space *mapping,
1189-
struct list_head *pages, unsigned nr_pages)
1188+
static void isofs_readahead(struct readahead_control *rac)
11901189
{
1191-
return mpage_readpages(mapping, pages, nr_pages, isofs_get_block);
1190+
mpage_readahead(rac, isofs_get_block);
11921191
}
11931192

11941193
static sector_t _isofs_bmap(struct address_space *mapping, sector_t block)
@@ -1198,7 +1197,7 @@ static sector_t _isofs_bmap(struct address_space *mapping, sector_t block)
11981197

11991198
static const struct address_space_operations isofs_aops = {
12001199
.readpage = isofs_readpage,
1201-
.readpages = isofs_readpages,
1200+
.readahead = isofs_readahead,
12021201
.bmap = _isofs_bmap
12031202
};
12041203

‎fs/jfs/inode.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,9 @@ static int jfs_readpage(struct file *file, struct page *page)
296296
return mpage_readpage(page, jfs_get_block);
297297
}
298298

299-
static int jfs_readpages(struct file *file, struct address_space *mapping,
300-
struct list_head *pages, unsigned nr_pages)
299+
static void jfs_readahead(struct readahead_control *rac)
301300
{
302-
return mpage_readpages(mapping, pages, nr_pages, jfs_get_block);
301+
mpage_readahead(rac, jfs_get_block);
303302
}
304303

305304
static void jfs_write_failed(struct address_space *mapping, loff_t to)
@@ -358,7 +357,7 @@ static ssize_t jfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
358357

359358
const struct address_space_operations jfs_aops = {
360359
.readpage = jfs_readpage,
361-
.readpages = jfs_readpages,
360+
.readahead = jfs_readahead,
362361
.writepage = jfs_writepage,
363362
.writepages = jfs_writepages,
364363
.write_begin = jfs_write_begin,

‎fs/mpage.c‎

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ mpage_alloc(struct block_device *bdev,
9191
}
9292

9393
/*
94-
* support function for mpage_readpages. The fs supplied get_block might
94+
* support function for mpage_readahead. The fs supplied get_block might
9595
* return an up to date buffer. This is used to map that buffer into
9696
* the page, which allows readpage to avoid triggering a duplicate call
9797
* to get_block.
@@ -338,13 +338,8 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
338338
}
339339

340340
/**
341-
* mpage_readpages - populate an address space with some pages & start reads against them
342-
* @mapping: the address_space
343-
* @pages: The address of a list_head which contains the target pages. These
344-
* pages have their ->index populated and are otherwise uninitialised.
345-
* The page at @pages->prev has the lowest file offset, and reads should be
346-
* issued in @pages->prev to @pages->next order.
347-
* @nr_pages: The number of pages at *@pages
341+
* mpage_readahead - start reads against pages
342+
* @rac: Describes which pages to read.
348343
* @get_block: The filesystem's block mapper function.
349344
*
350345
* This function walks the pages and the blocks within each page, building and
@@ -381,36 +376,25 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
381376
*
382377
* This all causes the disk requests to be issued in the correct order.
383378
*/
384-
int
385-
mpage_readpages(struct address_space *mapping, struct list_head *pages,
386-
unsigned nr_pages, get_block_t get_block)
379+
void mpage_readahead(struct readahead_control *rac, get_block_t get_block)
387380
{
381+
struct page *page;
388382
struct mpage_readpage_args args = {
389383
.get_block = get_block,
390384
.is_readahead = true,
391385
};
392-
unsigned page_idx;
393-
394-
for (page_idx = 0; page_idx < nr_pages; page_idx++) {
395-
struct page *page = lru_to_page(pages);
396386

387+
while ((page = readahead_page(rac))) {
397388
prefetchw(&page->flags);
398-
list_del(&page->lru);
399-
if (!add_to_page_cache_lru(page, mapping,
400-
page->index,
401-
readahead_gfp_mask(mapping))) {
402-
args.page = page;
403-
args.nr_pages = nr_pages - page_idx;
404-
args.bio = do_mpage_readpage(&args);
405-
}
389+
args.page = page;
390+
args.nr_pages = readahead_count(rac);
391+
args.bio = do_mpage_readpage(&args);
406392
put_page(page);
407393
}
408-
BUG_ON(!list_empty(pages));
409394
if (args.bio)
410395
mpage_bio_submit(REQ_OP_READ, REQ_RAHEAD, args.bio);
411-
return 0;
412396
}
413-
EXPORT_SYMBOL(mpage_readpages);
397+
EXPORT_SYMBOL(mpage_readahead);
414398

415399
/*
416400
* This isn't called much at all
@@ -563,7 +547,7 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
563547
* Page has buffers, but they are all unmapped. The page was
564548
* created by pagein or read over a hole which was handled by
565549
* block_read_full_page(). If this address_space is also
566-
* using mpage_readpages then this can rarely happen.
550+
* using mpage_readahead then this can rarely happen.
567551
*/
568552
goto confused;
569553
}

0 commit comments

Comments
 (0)