Skip to content

Commit d898391

Browse files
Fengguang WuLinus Torvalds
authored andcommitted
readahead: pass real splice size
Pass real splice size to page_cache_readahead_ondemand(). The splice code works in chunks of 16 pages internally. The readahead code should be told of the overall splice size, instead of the internal chunk size. Otherwize bad things may happen. Imagine some 17-page random splice reads. The code before this patch will result in two readahead calls: readahead(16); readahead(1); That leads to one 16-page I/O and one 32-page I/O: one extra I/O and 31 readahead miss pages. 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 431a482 commit d898391

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

‎fs/splice.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
265265
unsigned int flags)
266266
{
267267
struct address_space *mapping = in->f_mapping;
268-
unsigned int loff, nr_pages;
268+
unsigned int loff, nr_pages, req_pages;
269269
struct page *pages[PIPE_BUFFERS];
270270
struct partial_page partial[PIPE_BUFFERS];
271271
struct page *page;
@@ -281,10 +281,8 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
281281

282282
index = *ppos >> PAGE_CACHE_SHIFT;
283283
loff = *ppos & ~PAGE_CACHE_MASK;
284-
nr_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
285-
286-
if (nr_pages > PIPE_BUFFERS)
287-
nr_pages = PIPE_BUFFERS;
284+
req_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
285+
nr_pages = min(req_pages, (unsigned)PIPE_BUFFERS);
288286

289287
/*
290288
* Lookup the (hopefully) full range of pages we need.
@@ -298,7 +296,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
298296
*/
299297
if (spd.nr_pages < nr_pages)
300298
page_cache_readahead_ondemand(mapping, &in->f_ra, in,
301-
NULL, index, nr_pages - spd.nr_pages);
299+
NULL, index, req_pages - spd.nr_pages);
302300

303301
error = 0;
304302
while (spd.nr_pages < nr_pages) {
@@ -355,7 +353,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
355353

356354
if (PageReadahead(page))
357355
page_cache_readahead_ondemand(mapping, &in->f_ra, in,
358-
page, index, nr_pages - page_nr);
356+
page, index, req_pages - page_nr);
359357

360358
/*
361359
* If the page isn't uptodate, we may need to start io on it

0 commit comments

Comments
 (0)