Skip to content

Commit c2e4cd5

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: lift setting the readahead size into the block layer
Drivers shouldn't really mess with the readahead size, as that is a VM concept. Instead set it based on the optimal I/O size by lifting the algorithm from the md driver when registering the disk. Also set bdi->io_pages there as well by applying the same scheme based on max_sectors. To ensure the limits work well for stacking drivers a new helper is added to update the readahead limits from the block limits, which is also called from disk_stack_limits. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Mike Snitzer <snitzer@redhat.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 16ef510 commit c2e4cd5

11 files changed

Lines changed: 24 additions & 68 deletions

File tree

‎block/blk-settings.c‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,19 @@ void blk_queue_alignment_offset(struct request_queue *q, unsigned int offset)
372372
}
373373
EXPORT_SYMBOL(blk_queue_alignment_offset);
374374

375+
void blk_queue_update_readahead(struct request_queue *q)
376+
{
377+
/*
378+
* For read-ahead of large files to be effective, we need to read ahead
379+
* at least twice the optimal I/O size.
380+
*/
381+
q->backing_dev_info->ra_pages =
382+
max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
383+
q->backing_dev_info->io_pages =
384+
queue_max_sectors(q) >> (PAGE_SHIFT - 9);
385+
}
386+
EXPORT_SYMBOL_GPL(blk_queue_update_readahead);
387+
375388
/**
376389
* blk_limits_io_min - set minimum request size for a device
377390
* @limits: the queue limits
@@ -450,6 +463,8 @@ EXPORT_SYMBOL(blk_limits_io_opt);
450463
void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
451464
{
452465
blk_limits_io_opt(&q->limits, opt);
466+
q->backing_dev_info->ra_pages =
467+
max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
453468
}
454469
EXPORT_SYMBOL(blk_queue_io_opt);
455470

@@ -631,8 +646,7 @@ void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
631646
top, bottom);
632647
}
633648

634-
t->backing_dev_info->io_pages =
635-
t->limits.max_sectors >> (PAGE_SHIFT - 9);
649+
blk_queue_update_readahead(disk->queue);
636650
}
637651
EXPORT_SYMBOL(disk_stack_limits);
638652

‎block/blk-sysfs.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,8 @@ int blk_register_queue(struct gendisk *disk)
854854
percpu_ref_switch_to_percpu(&q->q_usage_counter);
855855
}
856856

857+
blk_queue_update_readahead(q);
858+
857859
ret = blk_trace_init_sysfs(dev);
858860
if (ret)
859861
return ret;

‎drivers/block/aoe/aoeblk.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ aoeblk_gdalloc(void *vp)
406406
WARN_ON(d->gd);
407407
WARN_ON(d->flags & DEVFL_UP);
408408
blk_queue_max_hw_sectors(q, BLK_DEF_MAX_SECTORS);
409-
q->backing_dev_info->ra_pages = SZ_2M / PAGE_SIZE;
410409
blk_queue_io_opt(q, SZ_2M);
411410
d->bufpool = mp;
412411
d->blkq = gd->queue = q;

‎drivers/block/drbd/drbd_nl.c‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,15 +1362,7 @@ static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backi
13621362

13631363
if (b) {
13641364
blk_stack_limits(&q->limits, &b->limits, 0);
1365-
1366-
if (q->backing_dev_info->ra_pages !=
1367-
b->backing_dev_info->ra_pages) {
1368-
drbd_info(device, "Adjusting my ra_pages to backing device's (%lu -> %lu)\n",
1369-
q->backing_dev_info->ra_pages,
1370-
b->backing_dev_info->ra_pages);
1371-
q->backing_dev_info->ra_pages =
1372-
b->backing_dev_info->ra_pages;
1373-
}
1365+
blk_queue_update_readahead(q);
13741366
}
13751367
fixup_discard_if_not_supported(q);
13761368
fixup_write_zeroes(device, q);

‎drivers/md/bcache/super.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,9 +1427,6 @@ static int cached_dev_init(struct cached_dev *dc, unsigned int block_size)
14271427
if (ret)
14281428
return ret;
14291429

1430-
dc->disk.disk->queue->backing_dev_info->ra_pages =
1431-
max(dc->disk.disk->queue->backing_dev_info->ra_pages,
1432-
q->backing_dev_info->ra_pages);
14331430
blk_queue_io_opt(dc->disk.disk->queue,
14341431
max(queue_io_opt(dc->disk.disk->queue), queue_io_opt(q)));
14351432

‎drivers/md/dm-table.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,8 +1925,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
19251925
}
19261926
#endif
19271927

1928-
/* Allow reads to exceed readahead limits */
1929-
q->backing_dev_info->io_pages = limits->max_sectors >> (PAGE_SHIFT - 9);
1928+
blk_queue_update_readahead(q);
19301929
}
19311930

19321931
unsigned int dm_table_get_num_targets(struct dm_table *t)

‎drivers/md/raid0.c‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -410,22 +410,6 @@ static int raid0_run(struct mddev *mddev)
410410
mdname(mddev),
411411
(unsigned long long)mddev->array_sectors);
412412

413-
if (mddev->queue) {
414-
/* calculate the max read-ahead size.
415-
* For read-ahead of large files to be effective, we need to
416-
* readahead at least twice a whole stripe. i.e. number of devices
417-
* multiplied by chunk size times 2.
418-
* If an individual device has an ra_pages greater than the
419-
* chunk size, then we will not drive that device as hard as it
420-
* wants. We consider this a configuration error: a larger
421-
* chunksize should be used in that case.
422-
*/
423-
int stripe = mddev->raid_disks *
424-
(mddev->chunk_sectors << 9) / PAGE_SIZE;
425-
if (mddev->queue->backing_dev_info->ra_pages < 2* stripe)
426-
mddev->queue->backing_dev_info->ra_pages = 2* stripe;
427-
}
428-
429413
dump_zones(mddev);
430414

431415
ret = md_integrity_register(mddev);

‎drivers/md/raid10.c‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3873,19 +3873,6 @@ static int raid10_run(struct mddev *mddev)
38733873
mddev->resync_max_sectors = size;
38743874
set_bit(MD_FAILFAST_SUPPORTED, &mddev->flags);
38753875

3876-
if (mddev->queue) {
3877-
int stripe = conf->geo.raid_disks *
3878-
((mddev->chunk_sectors << 9) / PAGE_SIZE);
3879-
3880-
/* Calculate max read-ahead size.
3881-
* We need to readahead at least twice a whole stripe....
3882-
* maybe...
3883-
*/
3884-
stripe /= conf->geo.near_copies;
3885-
if (mddev->queue->backing_dev_info->ra_pages < 2 * stripe)
3886-
mddev->queue->backing_dev_info->ra_pages = 2 * stripe;
3887-
}
3888-
38893876
if (md_integrity_register(mddev))
38903877
goto out_free_conf;
38913878

@@ -4723,17 +4710,8 @@ static void end_reshape(struct r10conf *conf)
47234710
conf->reshape_safe = MaxSector;
47244711
spin_unlock_irq(&conf->device_lock);
47254712

4726-
/* read-ahead size must cover two whole stripes, which is
4727-
* 2 * (datadisks) * chunksize where 'n' is the number of raid devices
4728-
*/
4729-
if (conf->mddev->queue) {
4730-
int stripe = conf->geo.raid_disks *
4731-
((conf->mddev->chunk_sectors << 9) / PAGE_SIZE);
4732-
stripe /= conf->geo.near_copies;
4733-
if (conf->mddev->queue->backing_dev_info->ra_pages < 2 * stripe)
4734-
conf->mddev->queue->backing_dev_info->ra_pages = 2 * stripe;
4713+
if (conf->mddev->queue)
47354714
raid10_set_io_opt(conf);
4736-
}
47374715
conf->fullsync = 0;
47384716
}
47394717

‎drivers/md/raid5.c‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7522,8 +7522,6 @@ static int raid5_run(struct mddev *mddev)
75227522
int data_disks = conf->previous_raid_disks - conf->max_degraded;
75237523
int stripe = data_disks *
75247524
((mddev->chunk_sectors << 9) / PAGE_SIZE);
7525-
if (mddev->queue->backing_dev_info->ra_pages < 2 * stripe)
7526-
mddev->queue->backing_dev_info->ra_pages = 2 * stripe;
75277525

75287526
chunk_size = mddev->chunk_sectors << 9;
75297527
blk_queue_io_min(mddev->queue, chunk_size);
@@ -8111,17 +8109,8 @@ static void end_reshape(struct r5conf *conf)
81118109
spin_unlock_irq(&conf->device_lock);
81128110
wake_up(&conf->wait_for_overlap);
81138111

8114-
/* read-ahead size must cover two whole stripes, which is
8115-
* 2 * (datadisks) * chunksize where 'n' is the number of raid devices
8116-
*/
8117-
if (conf->mddev->queue) {
8118-
int data_disks = conf->raid_disks - conf->max_degraded;
8119-
int stripe = data_disks * ((conf->chunk_sectors << 9)
8120-
/ PAGE_SIZE);
8121-
if (conf->mddev->queue->backing_dev_info->ra_pages < 2 * stripe)
8122-
conf->mddev->queue->backing_dev_info->ra_pages = 2 * stripe;
8112+
if (conf->mddev->queue)
81238113
raid5_set_io_opt(conf);
8124-
}
81258114
}
81268115
}
81278116

‎drivers/nvme/host/core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,7 @@ static int __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
21472147
nvme_update_disk_info(ns->head->disk, ns, id);
21482148
blk_stack_limits(&ns->head->disk->queue->limits,
21492149
&ns->queue->limits, 0);
2150+
blk_queue_update_readahead(ns->head->disk->queue);
21502151
nvme_update_bdev_size(ns->head->disk);
21512152
}
21522153
#endif

0 commit comments

Comments
 (0)