Skip to content

Commit 431a482

Browse files
Fengguang WuLinus Torvalds
authored andcommitted
readahead: move synchronous readahead call out of splice loop
Move synchronous page_cache_readahead_ondemand() call out of splice loop. This avoids one pointless page allocation/insertion in case of non-zero ra_pages, or many pointless readahead calls in case of zero ra_pages. Note that if a user sets ra_pages to less than PIPE_BUFFERS=16 pages, he will not get expected readahead behavior anyway. The splice code works in batches of 16 pages, which can be taken as another form of synchronous readahead. Signed-off-by: Fengguang Wu <wfg@mail.ustc.edu.cn> Cc: Jens Axboe <jens.axboe@oracle.com> Cc: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c743d96 commit 431a482

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎fs/splice.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,23 +290,24 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
290290
* Lookup the (hopefully) full range of pages we need.
291291
*/
292292
spd.nr_pages = find_get_pages_contig(mapping, index, nr_pages, pages);
293+
index += spd.nr_pages;
293294

294295
/*
295296
* If find_get_pages_contig() returned fewer pages than we needed,
296-
* allocate the rest and fill in the holes.
297+
* readahead/allocate the rest and fill in the holes.
297298
*/
299+
if (spd.nr_pages < nr_pages)
300+
page_cache_readahead_ondemand(mapping, &in->f_ra, in,
301+
NULL, index, nr_pages - spd.nr_pages);
302+
298303
error = 0;
299-
index += spd.nr_pages;
300304
while (spd.nr_pages < nr_pages) {
301305
/*
302306
* Page could be there, find_get_pages_contig() breaks on
303307
* the first hole.
304308
*/
305309
page = find_get_page(mapping, index);
306310
if (!page) {
307-
page_cache_readahead_ondemand(mapping, &in->f_ra, in,
308-
NULL, index, nr_pages - spd.nr_pages);
309-
310311
/*
311312
* page didn't exist, allocate one.
312313
*/

0 commit comments

Comments
 (0)