Skip to content

Commit 459779d

Browse files
damien-lemoalaxboe
authored andcommitted
block: Improve read ahead size for rotational devices
For a device that does not advertize an optimal I/O size, the function blk_apply_bdi_limits() defaults to an initial setting of the ra_pages field of struct backing_dev_info to VM_READAHEAD_PAGES, that is, 128 KB. This low I/O size value is far from being optimal for hard-disk devices: when reading files from multiple contexts using buffered I/Os, the seek overhead between the small read commands generated to read-ahead multiple files will significantly limit the performance that can be achieved. This fact applies to all ATA devices as ATA does not define an optimal I/O size and the SCSI SAT specification does not define a default value to expose to the host. Modify blk_apply_bdi_limits() to use a device max_sectors limit to calculate the ra_pages field of struct backing_dev_info, when the device is a rotational one (BLK_FEAT_ROTATIONAL feature is set). For a SCSI disk, this defaults to 2560 KB, which significantly improve performance for buffered reads. Using XFS and sequentially reading randomly selected (large) files stored on a SATA HDD, the maximum throughput achieved with 8 readers reading files with 1MB buffered I/Os increases from 122 MB/s to 167 MB/s (+36%). The improvement is even larger when reading files using 128 KB buffered I/Os, with a throughput increasing from 57 MB/s to 165 MB/s (+189%). Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: John Garry <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 86aa721 commit 459779d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

block/blk-settings.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,24 @@ EXPORT_SYMBOL(blk_set_stacking_limits);
6262
void blk_apply_bdi_limits(struct backing_dev_info *bdi,
6363
struct queue_limits *lim)
6464
{
65+
u64 io_opt = lim->io_opt;
66+
6567
/*
6668
* For read-ahead of large files to be effective, we need to read ahead
67-
* at least twice the optimal I/O size.
69+
* at least twice the optimal I/O size. For rotational devices that do
70+
* not report an optimal I/O size (e.g. ATA HDDs), use the maximum I/O
71+
* size to avoid falling back to the (rather inefficient) small default
72+
* read-ahead size.
6873
*
6974
* There is no hardware limitation for the read-ahead size and the user
7075
* might have increased the read-ahead size through sysfs, so don't ever
7176
* decrease it.
7277
*/
78+
if (!io_opt && (lim->features & BLK_FEAT_ROTATIONAL))
79+
io_opt = (u64)lim->max_sectors << SECTOR_SHIFT;
80+
7381
bdi->ra_pages = max3(bdi->ra_pages,
74-
lim->io_opt * 2 / PAGE_SIZE,
82+
io_opt * 2 >> PAGE_SHIFT,
7583
VM_READAHEAD_PAGES);
7684
bdi->io_pages = lim->max_sectors >> PAGE_SECTORS_SHIFT;
7785
}

0 commit comments

Comments
 (0)