diff mbox series

[v2,3/9] null_blk: Align max_hw_sectors to blocksize

Message ID 20201111051648.635300-4-damien.lemoal@wdc.com (mailing list archive)
State New, archived
Headers show
Series null_blk fixes, improvements and cleanup | expand

Commit Message

Damien Le Moal Nov. 11, 2020, 5:16 a.m. UTC
null_blk always uses the default BLK_SAFE_MAX_SECTORS value for the
max_hw_sectors and max_sectors queue limits resulting in a maximum
request size of 127 sectors. When the blocksize setting is larger than
the default 512B, this maximum request size is not aligned to the
block size. To emulate a real device more accurately, fix this by
setting the max_hw_sectors and max_sectors queue limits to a value
that is aligned to the block size.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 drivers/block/null_blk_main.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Christoph Hellwig Nov. 11, 2020, 8:06 a.m. UTC | #1
On Wed, Nov 11, 2020 at 02:16:42PM +0900, Damien Le Moal wrote:
> null_blk always uses the default BLK_SAFE_MAX_SECTORS value for the
> max_hw_sectors and max_sectors queue limits resulting in a maximum
> request size of 127 sectors. When the blocksize setting is larger than
> the default 512B, this maximum request size is not aligned to the
> block size. To emulate a real device more accurately, fix this by
> setting the max_hw_sectors and max_sectors queue limits to a value
> that is aligned to the block size.

Shouldn't we fix this in the block layer instead of individual drivers?
Damien Le Moal Nov. 11, 2020, 8:19 a.m. UTC | #2
On 2020/11/11 17:07, Christoph Hellwig wrote:
> On Wed, Nov 11, 2020 at 02:16:42PM +0900, Damien Le Moal wrote:
>> null_blk always uses the default BLK_SAFE_MAX_SECTORS value for the
>> max_hw_sectors and max_sectors queue limits resulting in a maximum
>> request size of 127 sectors. When the blocksize setting is larger than
>> the default 512B, this maximum request size is not aligned to the
>> block size. To emulate a real device more accurately, fix this by
>> setting the max_hw_sectors and max_sectors queue limits to a value
>> that is aligned to the block size.
> 
> Shouldn't we fix this in the block layer instead of individual drivers?
> 

Yes, I wondered about that too. Probably a good idea to have that generic but
that will require changing both blk_queue_logical_block_size() and
blk_queue_max_hw_sectors() since drivers may call these in different order.

Jens, thoughts ?
diff mbox series

Patch

diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index 4685ea401d5b..b77a506a4ae4 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -1866,6 +1866,9 @@  static int null_add_dev(struct nullb_device *dev)
 
 	blk_queue_logical_block_size(nullb->q, dev->blocksize);
 	blk_queue_physical_block_size(nullb->q, dev->blocksize);
+	blk_queue_max_hw_sectors(nullb->q,
+				 round_down(queue_max_hw_sectors(nullb->q),
+					    dev->blocksize >> SECTOR_SHIFT));
 
 	null_config_discard(nullb);