Re: [PATCH 07/13] block: lift setting the readahead size into the block layer

2020-09-24 Thread Martin K. Petersen


Christoph,

> 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.

Looks good!

Reviewed-by: Martin K. Petersen 

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH 07/13] block: lift setting the readahead size into the block layer

2020-09-24 Thread Mike Snitzer
On Thu, Sep 24 2020 at  2:51am -0400,
Christoph Hellwig  wrote:

> 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 
> Acked-by: Coly Li 
> Reviewed-by: Johannes Thumshirn 

Thanks for adding blk_queue_update_readahead()

Reviewed-by: Mike Snitzer 



Re: [PATCH 07/13] block: lift setting the readahead size into the block layer

2020-09-24 Thread Jan Kara
On Thu 24-09-20 08:51:34, Christoph Hellwig wrote:
> 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 
> Acked-by: Coly Li 
> Reviewed-by: Johannes Thumshirn 

The patch looks good to me now. You can add:

Reviewed-by: Jan Kara 

Honza

> ---
>  block/blk-settings.c | 18 --
>  block/blk-sysfs.c|  2 ++
>  drivers/block/aoe/aoeblk.c   |  1 -
>  drivers/block/drbd/drbd_nl.c | 10 +-
>  drivers/md/bcache/super.c|  3 ---
>  drivers/md/dm-table.c|  3 +--
>  drivers/md/raid0.c   | 16 
>  drivers/md/raid10.c  | 24 +---
>  drivers/md/raid5.c   | 13 +
>  drivers/nvme/host/core.c |  1 +
>  include/linux/blkdev.h   |  1 +
>  11 files changed, 24 insertions(+), 68 deletions(-)
> 
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index 5ea3de48afba22..4f6eb4bb17236a 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -372,6 +372,19 @@ void blk_queue_alignment_offset(struct request_queue *q, 
> unsigned int offset)
>  }
>  EXPORT_SYMBOL(blk_queue_alignment_offset);
>  
> +void blk_queue_update_readahead(struct request_queue *q)
> +{
> + /*
> +  * For read-ahead of large files to be effective, we need to read ahead
> +  * at least twice the optimal I/O size.
> +  */
> + q->backing_dev_info->ra_pages =
> + max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
> + q->backing_dev_info->io_pages =
> + queue_max_sectors(q) >> (PAGE_SHIFT - 9);
> +}
> +EXPORT_SYMBOL_GPL(blk_queue_update_readahead);
> +
>  /**
>   * blk_limits_io_min - set minimum request size for a device
>   * @limits: the queue limits
> @@ -450,6 +463,8 @@ EXPORT_SYMBOL(blk_limits_io_opt);
>  void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
>  {
>   blk_limits_io_opt(>limits, opt);
> + q->backing_dev_info->ra_pages =
> + max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
>  }
>  EXPORT_SYMBOL(blk_queue_io_opt);
>  
> @@ -631,8 +646,7 @@ void disk_stack_limits(struct gendisk *disk, struct 
> block_device *bdev,
>  top, bottom);
>   }
>  
> - t->backing_dev_info->io_pages =
> - t->limits.max_sectors >> (PAGE_SHIFT - 9);
> + blk_queue_update_readahead(disk->queue);
>  }
>  EXPORT_SYMBOL(disk_stack_limits);
>  
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index 81722cdcf0cb21..869ed21a9edcab 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -854,6 +854,8 @@ int blk_register_queue(struct gendisk *disk)
>   percpu_ref_switch_to_percpu(>q_usage_counter);
>   }
>  
> + blk_queue_update_readahead(q);
> +
>   ret = blk_trace_init_sysfs(dev);
>   if (ret)
>   return ret;
> diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
> index d8cfc233e64b93..c34e71b0c4a98c 100644
> --- a/drivers/block/aoe/aoeblk.c
> +++ b/drivers/block/aoe/aoeblk.c
> @@ -406,7 +406,6 @@ aoeblk_gdalloc(void *vp)
>   WARN_ON(d->gd);
>   WARN_ON(d->flags & DEVFL_UP);
>   blk_queue_max_hw_sectors(q, BLK_DEF_MAX_SECTORS);
> - q->backing_dev_info->ra_pages = SZ_2M / PAGE_SIZE;
>   blk_queue_io_opt(q, SZ_2M);
>   d->bufpool = mp;
>   d->blkq = gd->queue = q;
> diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
> index aaff5bde391506..54a4930c04fe07 100644
> --- a/drivers/block/drbd/drbd_nl.c
> +++ b/drivers/block/drbd/drbd_nl.c
> @@ -1362,15 +1362,7 @@ static void drbd_setup_queue_param(struct drbd_device 
> *device, struct drbd_backi
>  
>   if (b) {
>   blk_stack_limits(>limits, >limits, 0);
> -
> - if (q->backing_dev_info->ra_pages !=
> - b->backing_dev_info->ra_pages) {
> - drbd_info(device, "Adjusting my ra_pages to backing 
> device's (%lu -> %lu)\n",
> -  q->backing_dev_info->ra_pages,
> -  b->backing_dev_info->ra_pages);
> - q->backing_dev_info->ra_pages =
> - b->backing_dev_info->ra_pages;
> - }
> + blk_queue_update_readahead(q);
>   }
>   fixup_discard_if_not_supported(q);
>   fixup_write_zeroes(device, q);
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index 48113005ed86ad..6bfa771673623e 100644
> --- 

[PATCH 07/13] block: lift setting the readahead size into the block layer

2020-09-24 Thread Christoph Hellwig
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 
Acked-by: Coly Li 
Reviewed-by: Johannes Thumshirn 
---
 block/blk-settings.c | 18 --
 block/blk-sysfs.c|  2 ++
 drivers/block/aoe/aoeblk.c   |  1 -
 drivers/block/drbd/drbd_nl.c | 10 +-
 drivers/md/bcache/super.c|  3 ---
 drivers/md/dm-table.c|  3 +--
 drivers/md/raid0.c   | 16 
 drivers/md/raid10.c  | 24 +---
 drivers/md/raid5.c   | 13 +
 drivers/nvme/host/core.c |  1 +
 include/linux/blkdev.h   |  1 +
 11 files changed, 24 insertions(+), 68 deletions(-)

diff --git a/block/blk-settings.c b/block/blk-settings.c
index 5ea3de48afba22..4f6eb4bb17236a 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -372,6 +372,19 @@ void blk_queue_alignment_offset(struct request_queue *q, 
unsigned int offset)
 }
 EXPORT_SYMBOL(blk_queue_alignment_offset);
 
+void blk_queue_update_readahead(struct request_queue *q)
+{
+   /*
+* For read-ahead of large files to be effective, we need to read ahead
+* at least twice the optimal I/O size.
+*/
+   q->backing_dev_info->ra_pages =
+   max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
+   q->backing_dev_info->io_pages =
+   queue_max_sectors(q) >> (PAGE_SHIFT - 9);
+}
+EXPORT_SYMBOL_GPL(blk_queue_update_readahead);
+
 /**
  * blk_limits_io_min - set minimum request size for a device
  * @limits: the queue limits
@@ -450,6 +463,8 @@ EXPORT_SYMBOL(blk_limits_io_opt);
 void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
 {
blk_limits_io_opt(>limits, opt);
+   q->backing_dev_info->ra_pages =
+   max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
 }
 EXPORT_SYMBOL(blk_queue_io_opt);
 
@@ -631,8 +646,7 @@ void disk_stack_limits(struct gendisk *disk, struct 
block_device *bdev,
   top, bottom);
}
 
-   t->backing_dev_info->io_pages =
-   t->limits.max_sectors >> (PAGE_SHIFT - 9);
+   blk_queue_update_readahead(disk->queue);
 }
 EXPORT_SYMBOL(disk_stack_limits);
 
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 81722cdcf0cb21..869ed21a9edcab 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -854,6 +854,8 @@ int blk_register_queue(struct gendisk *disk)
percpu_ref_switch_to_percpu(>q_usage_counter);
}
 
+   blk_queue_update_readahead(q);
+
ret = blk_trace_init_sysfs(dev);
if (ret)
return ret;
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index d8cfc233e64b93..c34e71b0c4a98c 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -406,7 +406,6 @@ aoeblk_gdalloc(void *vp)
WARN_ON(d->gd);
WARN_ON(d->flags & DEVFL_UP);
blk_queue_max_hw_sectors(q, BLK_DEF_MAX_SECTORS);
-   q->backing_dev_info->ra_pages = SZ_2M / PAGE_SIZE;
blk_queue_io_opt(q, SZ_2M);
d->bufpool = mp;
d->blkq = gd->queue = q;
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index aaff5bde391506..54a4930c04fe07 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -1362,15 +1362,7 @@ static void drbd_setup_queue_param(struct drbd_device 
*device, struct drbd_backi
 
if (b) {
blk_stack_limits(>limits, >limits, 0);
-
-   if (q->backing_dev_info->ra_pages !=
-   b->backing_dev_info->ra_pages) {
-   drbd_info(device, "Adjusting my ra_pages to backing 
device's (%lu -> %lu)\n",
-q->backing_dev_info->ra_pages,
-b->backing_dev_info->ra_pages);
-   q->backing_dev_info->ra_pages =
-   b->backing_dev_info->ra_pages;
-   }
+   blk_queue_update_readahead(q);
}
fixup_discard_if_not_supported(q);
fixup_write_zeroes(device, q);
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 48113005ed86ad..6bfa771673623e 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1427,9 +1427,6 @@ static int cached_dev_init(struct cached_dev *dc, 
unsigned int block_size)
if (ret)
return ret;
 
-   dc->disk.disk->queue->backing_dev_info->ra_pages =
-   max(dc->disk.disk->queue->backing_dev_info->ra_pages,
-   

Re: [PATCH 07/13] block: lift setting the readahead size into the block layer

2020-09-22 Thread Coly Li
On 2020/9/21 16:07, Christoph Hellwig wrote:
> 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.
> 
> Signed-off-by: Christoph Hellwig 
> Reviewed-by: Johannes Thumshirn 

For the bcache part,

Acked-by: Coly Li 


Thanks.

Coly Li


> ---
>  block/blk-settings.c |  5 ++---
>  block/blk-sysfs.c|  9 +
>  drivers/block/aoe/aoeblk.c   |  1 -
>  drivers/block/drbd/drbd_nl.c | 12 +---
>  drivers/md/bcache/super.c|  3 ---
>  drivers/md/raid0.c   | 16 
>  drivers/md/raid10.c  | 24 +---
>  drivers/md/raid5.c   | 13 +
>  8 files changed, 14 insertions(+), 69 deletions(-)
> 
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index 76a7e03bcd6cac..01049e9b998f1d 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -452,6 +452,8 @@ EXPORT_SYMBOL(blk_limits_io_opt);
>  void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
>  {
>   blk_limits_io_opt(>limits, opt);
> + q->backing_dev_info->ra_pages =
> + max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
>  }
>  EXPORT_SYMBOL(blk_queue_io_opt);
>  
> @@ -628,9 +630,6 @@ void disk_stack_limits(struct gendisk *disk, struct 
> block_device *bdev,
>   printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
>  top, bottom);
>   }
> -
> - t->backing_dev_info->io_pages =
> - t->limits.max_sectors >> (PAGE_SHIFT - 9);
>  }
>  EXPORT_SYMBOL(disk_stack_limits);
>  
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index 81722cdcf0cb21..83915b4a1fc3ad 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -854,6 +854,15 @@ int blk_register_queue(struct gendisk *disk)
>   percpu_ref_switch_to_percpu(>q_usage_counter);
>   }
>  
> + /*
> +  * For read-ahead of large files to be effective, we need to read ahead
> +  * at least twice the optimal I/O size.
> +  */
> + q->backing_dev_info->ra_pages =
> + max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
> + q->backing_dev_info->io_pages =
> + queue_max_sectors(q) >> (PAGE_SHIFT - 9);
> +
>   ret = blk_trace_init_sysfs(dev);
>   if (ret)
>   return ret;
> diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
> index d8cfc233e64b93..c34e71b0c4a98c 100644
> --- a/drivers/block/aoe/aoeblk.c
> +++ b/drivers/block/aoe/aoeblk.c
> @@ -406,7 +406,6 @@ aoeblk_gdalloc(void *vp)
>   WARN_ON(d->gd);
>   WARN_ON(d->flags & DEVFL_UP);
>   blk_queue_max_hw_sectors(q, BLK_DEF_MAX_SECTORS);
> - q->backing_dev_info->ra_pages = SZ_2M / PAGE_SIZE;
>   blk_queue_io_opt(q, SZ_2M);
>   d->bufpool = mp;
>   d->blkq = gd->queue = q;
> diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
> index aaff5bde391506..f8fb1c9b1bb6c1 100644
> --- a/drivers/block/drbd/drbd_nl.c
> +++ b/drivers/block/drbd/drbd_nl.c
> @@ -1360,18 +1360,8 @@ static void drbd_setup_queue_param(struct drbd_device 
> *device, struct drbd_backi
>   decide_on_discard_support(device, q, b, discard_zeroes_if_aligned);
>   decide_on_write_same_support(device, q, b, o, disable_write_same);
>  
> - if (b) {
> + if (b)
>   blk_stack_limits(>limits, >limits, 0);
> -
> - if (q->backing_dev_info->ra_pages !=
> - b->backing_dev_info->ra_pages) {
> - drbd_info(device, "Adjusting my ra_pages to backing 
> device's (%lu -> %lu)\n",
> -  q->backing_dev_info->ra_pages,
> -  b->backing_dev_info->ra_pages);
> - q->backing_dev_info->ra_pages =
> - b->backing_dev_info->ra_pages;
> - }
> - }
>   fixup_discard_if_not_supported(q);
>   fixup_write_zeroes(device, q);
>  }
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index 48113005ed86ad..6bfa771673623e 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -1427,9 +1427,6 @@ static int cached_dev_init(struct cached_dev *dc, 
> unsigned int block_size)
>   if (ret)
>   return ret;
>  
> - dc->disk.disk->queue->backing_dev_info->ra_pages =
> - max(dc->disk.disk->queue->backing_dev_info->ra_pages,
> - q->backing_dev_info->ra_pages);
>   blk_queue_io_opt(dc->disk.disk->queue,
>   max(queue_io_opt(dc->disk.disk->queue), queue_io_opt(q)));
>  
> diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
> index f54a449f97aa79..aa2d7279176880 100644
> --- a/drivers/md/raid0.c
> +++ b/drivers/md/raid0.c
> @@ -410,22 

Re: [PATCH 07/13] block: lift setting the readahead size into the block layer

2020-09-22 Thread Jan Kara
On Mon 21-09-20 10:07:28, Christoph Hellwig wrote:
> 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.
> 
> Signed-off-by: Christoph Hellwig 
> Reviewed-by: Johannes Thumshirn 
...
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index 76a7e03bcd6cac..01049e9b998f1d 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -452,6 +452,8 @@ EXPORT_SYMBOL(blk_limits_io_opt);
>  void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
>  {
>   blk_limits_io_opt(>limits, opt);
> + q->backing_dev_info->ra_pages =
> + max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
>  }
>  EXPORT_SYMBOL(blk_queue_io_opt);
>  
> @@ -628,9 +630,6 @@ void disk_stack_limits(struct gendisk *disk, struct 
> block_device *bdev,
>   printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
>  top, bottom);
>   }
> -
> - t->backing_dev_info->io_pages =
> - t->limits.max_sectors >> (PAGE_SHIFT - 9);
>  }
>  EXPORT_SYMBOL(disk_stack_limits);

One thing I've noticed is that blk_stack_limits() does not use
blk_queue_io_opt() to set new optimal limit. That means that ra_pages won't
be updated for the new queue. E.g. your DRDB change below will result in
ra_pages not being properly updated AFAICT.

Similarly it isn't clear to me how io_pages would get updated after
blk_stack_limits() updates max_hw_sectors...

Otherwise the patch looks good.

Honza

> diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
> index aaff5bde391506..f8fb1c9b1bb6c1 100644
> --- a/drivers/block/drbd/drbd_nl.c
> +++ b/drivers/block/drbd/drbd_nl.c
> @@ -1360,18 +1360,8 @@ static void drbd_setup_queue_param(struct drbd_device 
> *device, struct drbd_backi
>   decide_on_discard_support(device, q, b, discard_zeroes_if_aligned);
>   decide_on_write_same_support(device, q, b, o, disable_write_same);
>  
> - if (b) {
> + if (b)
>   blk_stack_limits(>limits, >limits, 0);
> -
> - if (q->backing_dev_info->ra_pages !=
> - b->backing_dev_info->ra_pages) {
> - drbd_info(device, "Adjusting my ra_pages to backing 
> device's (%lu -> %lu)\n",
> -  q->backing_dev_info->ra_pages,
> -  b->backing_dev_info->ra_pages);
> - q->backing_dev_info->ra_pages =
> - b->backing_dev_info->ra_pages;
> - }
> - }
>   fixup_discard_if_not_supported(q);
>   fixup_write_zeroes(device, q);
>  }
-- 
Jan Kara 
SUSE Labs, CR


[PATCH 07/13] block: lift setting the readahead size into the block layer

2020-09-21 Thread Christoph Hellwig
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.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 block/blk-settings.c |  5 ++---
 block/blk-sysfs.c|  9 +
 drivers/block/aoe/aoeblk.c   |  1 -
 drivers/block/drbd/drbd_nl.c | 12 +---
 drivers/md/bcache/super.c|  3 ---
 drivers/md/raid0.c   | 16 
 drivers/md/raid10.c  | 24 +---
 drivers/md/raid5.c   | 13 +
 8 files changed, 14 insertions(+), 69 deletions(-)

diff --git a/block/blk-settings.c b/block/blk-settings.c
index 76a7e03bcd6cac..01049e9b998f1d 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -452,6 +452,8 @@ EXPORT_SYMBOL(blk_limits_io_opt);
 void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
 {
blk_limits_io_opt(>limits, opt);
+   q->backing_dev_info->ra_pages =
+   max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
 }
 EXPORT_SYMBOL(blk_queue_io_opt);
 
@@ -628,9 +630,6 @@ void disk_stack_limits(struct gendisk *disk, struct 
block_device *bdev,
printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
   top, bottom);
}
-
-   t->backing_dev_info->io_pages =
-   t->limits.max_sectors >> (PAGE_SHIFT - 9);
 }
 EXPORT_SYMBOL(disk_stack_limits);
 
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 81722cdcf0cb21..83915b4a1fc3ad 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -854,6 +854,15 @@ int blk_register_queue(struct gendisk *disk)
percpu_ref_switch_to_percpu(>q_usage_counter);
}
 
+   /*
+* For read-ahead of large files to be effective, we need to read ahead
+* at least twice the optimal I/O size.
+*/
+   q->backing_dev_info->ra_pages =
+   max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
+   q->backing_dev_info->io_pages =
+   queue_max_sectors(q) >> (PAGE_SHIFT - 9);
+
ret = blk_trace_init_sysfs(dev);
if (ret)
return ret;
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index d8cfc233e64b93..c34e71b0c4a98c 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -406,7 +406,6 @@ aoeblk_gdalloc(void *vp)
WARN_ON(d->gd);
WARN_ON(d->flags & DEVFL_UP);
blk_queue_max_hw_sectors(q, BLK_DEF_MAX_SECTORS);
-   q->backing_dev_info->ra_pages = SZ_2M / PAGE_SIZE;
blk_queue_io_opt(q, SZ_2M);
d->bufpool = mp;
d->blkq = gd->queue = q;
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index aaff5bde391506..f8fb1c9b1bb6c1 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -1360,18 +1360,8 @@ static void drbd_setup_queue_param(struct drbd_device 
*device, struct drbd_backi
decide_on_discard_support(device, q, b, discard_zeroes_if_aligned);
decide_on_write_same_support(device, q, b, o, disable_write_same);
 
-   if (b) {
+   if (b)
blk_stack_limits(>limits, >limits, 0);
-
-   if (q->backing_dev_info->ra_pages !=
-   b->backing_dev_info->ra_pages) {
-   drbd_info(device, "Adjusting my ra_pages to backing 
device's (%lu -> %lu)\n",
-q->backing_dev_info->ra_pages,
-b->backing_dev_info->ra_pages);
-   q->backing_dev_info->ra_pages =
-   b->backing_dev_info->ra_pages;
-   }
-   }
fixup_discard_if_not_supported(q);
fixup_write_zeroes(device, q);
 }
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 48113005ed86ad..6bfa771673623e 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1427,9 +1427,6 @@ static int cached_dev_init(struct cached_dev *dc, 
unsigned int block_size)
if (ret)
return ret;
 
-   dc->disk.disk->queue->backing_dev_info->ra_pages =
-   max(dc->disk.disk->queue->backing_dev_info->ra_pages,
-   q->backing_dev_info->ra_pages);
blk_queue_io_opt(dc->disk.disk->queue,
max(queue_io_opt(dc->disk.disk->queue), queue_io_opt(q)));
 
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index f54a449f97aa79..aa2d7279176880 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -410,22 +410,6 @@ static int raid0_run(struct mddev *mddev)
 mdname(mddev),
 (unsigned long long)mddev->array_sectors);
 
-   if (mddev->queue) {
-   /* calculate the max read-ahead size.
-* For