Skip to content

Commit 9491ae4

Browse files
axboetorvalds
authored andcommitted
mm: don't cap request size based on read-ahead setting
We ran into a funky issue, where someone doing 256K buffered reads saw 128K requests at the device level. Turns out it is read-ahead capping the request size, since we use 128K as the default setting. This doesn't make a lot of sense - if someone is issuing 256K reads, they should see 256K reads, regardless of the read-ahead setting, if the underlying device can support a 256K read in a single command. This patch introduces a bdi hint, io_pages. This is the soft max IO size for the lower level, I've hooked it up to the bdev settings here. Read-ahead is modified to issue the maximum of the user request size, and the read-ahead max size, but capped to the max request size on the device side. The latter is done to avoid reading ahead too much, if the application asks for a huge read. With this patch, the kernel behaves like the application expects. Link: http://lkml.kernel.org/r/1479498073-8657-1-git-send-email-axboe@fb.com Signed-off-by: Jens Axboe <axboe@fb.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f1f5929 commit 9491ae4

4 files changed

Lines changed: 31 additions & 11 deletions

File tree

‎block/blk-settings.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto
249249
max_sectors = min_not_zero(max_hw_sectors, limits->max_dev_sectors);
250250
max_sectors = min_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
251251
limits->max_sectors = max_sectors;
252+
q->backing_dev_info.io_pages = max_sectors >> (PAGE_SHIFT - 9);
252253
}
253254
EXPORT_SYMBOL(blk_queue_max_hw_sectors);
254255

‎block/blk-sysfs.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
212212

213213
spin_lock_irq(q->queue_lock);
214214
q->limits.max_sectors = max_sectors_kb << 1;
215+
q->backing_dev_info.io_pages = max_sectors_kb >> (PAGE_SHIFT - 10);
215216
spin_unlock_irq(q->queue_lock);
216217

217218
return ret;

‎include/linux/backing-dev-defs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ struct bdi_writeback {
136136
struct backing_dev_info {
137137
struct list_head bdi_list;
138138
unsigned long ra_pages; /* max readahead in PAGE_SIZE units */
139+
unsigned long io_pages; /* max allowed IO size */
139140
unsigned int capabilities; /* Device capabilities */
140141
congested_fn *congested_fn; /* Function pointer if device is md/dm */
141142
void *congested_data; /* Pointer to aux data for congested func */

‎mm/readahead.c‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,21 @@ int __do_page_cache_readahead(struct address_space *mapping, struct file *filp,
207207
* memory at once.
208208
*/
209209
int force_page_cache_readahead(struct address_space *mapping, struct file *filp,
210-
pgoff_t offset, unsigned long nr_to_read)
210+
pgoff_t offset, unsigned long nr_to_read)
211211
{
212+
struct backing_dev_info *bdi = inode_to_bdi(mapping->host);
213+
struct file_ra_state *ra = &filp->f_ra;
214+
unsigned long max_pages;
215+
212216
if (unlikely(!mapping->a_ops->readpage && !mapping->a_ops->readpages))
213217
return -EINVAL;
214218

215-
nr_to_read = min(nr_to_read, inode_to_bdi(mapping->host)->ra_pages);
219+
/*
220+
* If the request exceeds the readahead window, allow the read to
221+
* be up to the optimal hardware IO size
222+
*/
223+
max_pages = max_t(unsigned long, bdi->io_pages, ra->ra_pages);
224+
nr_to_read = min(nr_to_read, max_pages);
216225
while (nr_to_read) {
217226
int err;
218227

@@ -369,9 +378,17 @@ ondemand_readahead(struct address_space *mapping,
369378
bool hit_readahead_marker, pgoff_t offset,
370379
unsigned long req_size)
371380
{
372-
unsigned long max = ra->ra_pages;
381+
struct backing_dev_info *bdi = inode_to_bdi(mapping->host);
382+
unsigned long max_pages = ra->ra_pages;
373383
pgoff_t prev_offset;
374384

385+
/*
386+
* If the request exceeds the readahead window, allow the read to
387+
* be up to the optimal hardware IO size
388+
*/
389+
if (req_size > max_pages && bdi->io_pages > max_pages)
390+
max_pages = min(req_size, bdi->io_pages);
391+
375392
/*
376393
* start of file
377394
*/
@@ -385,7 +402,7 @@ ondemand_readahead(struct address_space *mapping,
385402
if ((offset == (ra->start + ra->size - ra->async_size) ||
386403
offset == (ra->start + ra->size))) {
387404
ra->start += ra->size;
388-
ra->size = get_next_ra_size(ra, max);
405+
ra->size = get_next_ra_size(ra, max_pages);
389406
ra->async_size = ra->size;
390407
goto readit;
391408
}
@@ -400,24 +417,24 @@ ondemand_readahead(struct address_space *mapping,
400417
pgoff_t start;
401418

402419
rcu_read_lock();
403-
start = page_cache_next_hole(mapping, offset + 1, max);
420+
start = page_cache_next_hole(mapping, offset + 1, max_pages);
404421
rcu_read_unlock();
405422

406-
if (!start || start - offset > max)
423+
if (!start || start - offset > max_pages)
407424
return 0;
408425

409426
ra->start = start;
410427
ra->size = start - offset; /* old async_size */
411428
ra->size += req_size;
412-
ra->size = get_next_ra_size(ra, max);
429+
ra->size = get_next_ra_size(ra, max_pages);
413430
ra->async_size = ra->size;
414431
goto readit;
415432
}
416433

417434
/*
418435
* oversize read
419436
*/
420-
if (req_size > max)
437+
if (req_size > max_pages)
421438
goto initial_readahead;
422439

423440
/*
@@ -433,7 +450,7 @@ ondemand_readahead(struct address_space *mapping,
433450
* Query the page cache and look for the traces(cached history pages)
434451
* that a sequential stream would leave behind.
435452
*/
436-
if (try_context_readahead(mapping, ra, offset, req_size, max))
453+
if (try_context_readahead(mapping, ra, offset, req_size, max_pages))
437454
goto readit;
438455

439456
/*
@@ -444,7 +461,7 @@ ondemand_readahead(struct address_space *mapping,
444461

445462
initial_readahead:
446463
ra->start = offset;
447-
ra->size = get_init_ra_size(req_size, max);
464+
ra->size = get_init_ra_size(req_size, max_pages);
448465
ra->async_size = ra->size > req_size ? ra->size - req_size : ra->size;
449466

450467
readit:
@@ -454,7 +471,7 @@ ondemand_readahead(struct address_space *mapping,
454471
* the resulted next readahead window into the current one.
455472
*/
456473
if (offset == ra->start && ra->size == ra->async_size) {
457-
ra->async_size = get_next_ra_size(ra, max);
474+
ra->async_size = get_next_ra_size(ra, max_pages);
458475
ra->size += ra->async_size;
459476
}
460477

0 commit comments

Comments
 (0)