Skip to content

Commit

Permalink
readahead: move synchronous readahead call out of splice loop
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Fengguang Wu authored and Linus Torvalds committed Jul 19, 2007
1 parent c743d96 commit 431a482
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions fs/splice.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,23 +290,24 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
* Lookup the (hopefully) full range of pages we need.
*/
spd.nr_pages = find_get_pages_contig(mapping, index, nr_pages, pages);
index += spd.nr_pages;

/*
* If find_get_pages_contig() returned fewer pages than we needed,
* allocate the rest and fill in the holes.
* readahead/allocate the rest and fill in the holes.
*/
if (spd.nr_pages < nr_pages)
page_cache_readahead_ondemand(mapping, &in->f_ra, in,
NULL, index, nr_pages - spd.nr_pages);

error = 0;
index += spd.nr_pages;
while (spd.nr_pages < nr_pages) {
/*
* Page could be there, find_get_pages_contig() breaks on
* the first hole.
*/
page = find_get_page(mapping, index);
if (!page) {
page_cache_readahead_ondemand(mapping, &in->f_ra, in,
NULL, index, nr_pages - spd.nr_pages);

/*
* page didn't exist, allocate one.
*/
Expand Down

0 comments on commit 431a482

Please sign in to comment.