block: don't forget user settings
v4 cover block: don't forget user settings
From: Keith Busch <[email protected]>
If the user overrides the max sectors for their device (which is currently defaulting to quite a low value for modern hardware), their request is lost on a rescan. Save it and fix the weird type issues.
Changes since v3: Fixed the unsigned long/unsigned int issue raised by clang.
Keith Busch (2):
block: make BLK_DEF_MAX_SECTORS unsigned
block: save user max_sectors limit
Documentation/ABI/stable/sysfs-block | 3 ++- block/blk-settings.c | 9 +++++++-- block/blk-sysfs.c | 21 +++++++++++++++------ drivers/block/null_blk/main.c | 3 +-- include/linux/blkdev.h | 4 +++- 5 files changed, 28 insertions(+), 12 deletions(-)
Signature · 1 line
2.30.2
PATCH v4 1/2 block: make BLK_DEF_MAX_SECTORS unsigned
From: Keith Busch <[email protected]>
This is used as an unsigned value, so define it that way to avoid having to cast it.
--- block/blk-settings.c | 2 +- drivers/block/null_blk/main.c | 3 +-- include/linux/blkdev.h | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-)
block/blk-settings.c +1 -1
@@ -135,7 +135,7 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto limits->max_hw_sectors = max_hw_sectors; max_sectors =min_not_zero (max_hw_sectors, limits->max_dev_sectors); - max_sectors = min_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS); + max_sectors =min (max_sectors,BLK_DEF_MAX_SECTORS ); max_sectors =round_down (max_sectors, limits->logical_block_size >>SECTOR_SHIFT ); limits->max_sectors = max_sectors;
drivers/block/null_blk/main.c +1 -2
@@ -2123,8 +2123,7 @@ static int null_add_dev(struct nullb_device *dev)blk_queue_physical_block_size (nullb->q, dev->blocksize);if (!dev->max_sectors) dev->max_sectors =queue_max_hw_sectors (nullb->q); - dev->max_sectors = min_t(unsigned int, dev->max_sectors, -BLK_DEF_MAX_SECTORS ); + dev->max_sectors =min (dev->max_sectors,BLK_DEF_MAX_SECTORS );blk_queue_max_hw_sectors (nullb->q, dev->max_sectors);if (dev->virt_boundary)
include/linux/blkdev.h +2 -1
@@ -1095,11 +1095,12 @@ static inline bool bdev_is_partition(struct block_device *bdev)enum blk_default_limits {BLK_MAX_SEGMENTS =128 ,BLK_SAFE_MAX_SECTORS =255 , -BLK_DEF_MAX_SECTORS =2560 ,BLK_MAX_SEGMENT_SIZE =65536 ,BLK_SEG_BOUNDARY_MASK =0xFFFFFFFFUL , }; +#define BLK_DEF_MAX_SECTORS 2560u +static inline unsigned long queue_segment_boundary (const struct request_queue *q) {return q->limits.seg_boundary_mask;
Signature · 1 line
2.30.2
Re: [PATCHv4 1/2] block: make BLK_DEF_MAX_SECTORS unsigned
Quoted 2 lines · Keith Busch
This is used as an unsigned value, so define it that way to avoid having to cast it.
Re: [PATCHv4 1/2] block: make BLK_DEF_MAX_SECTORS unsigned
In reply to Keith BuschLooks good:
Re: [PATCHv4 1/2] block: make BLK_DEF_MAX_SECTORS unsigned
In reply to Keith BuschKeith,
Quoted 2 lines
This is used as an unsigned value, so define it that way to avoid having to cast it.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
PATCH v4 2/2 block: save user max_sectors limit
In reply to Keith BuschFrom: Keith Busch <[email protected]>
The user can set the max_sectors limit to any valid value via sysfs /sys/block/<dev>/queue/max_sectors_kb attribute. If the device limits are ever rescanned, though, the limit reverts back to the potentially artificially low BLK_DEF_MAX_SECTORS value.
Preserve the user's setting as the max_sectors limit as long as it's valid. The user can reset back to defaults by writing 0 to the sysfs file.
--- Documentation/ABI/stable/sysfs-block | 3 ++- block/blk-settings.c | 9 +++++++-- block/blk-sysfs.c | 21 +++++++++++++++------ include/linux/blkdev.h | 1 + 4 files changed, 25 insertions(+), 9 deletions(-)
Documentation/ABI/stable/sysfs-block +2 -1
@@ -432,7 +432,8 @@ Contact: [email protected] Description: [RW] This is the maximum number of kilobytes that the block layer will allow for a filesystem request. Must be smaller than - or equal to the maximum size allowed by the hardware. + or equal to the maximum size allowed by the hardware. Write 0 + to use default kernel settings. What: /sys/block/<disk>/queue/max_segment_size
block/blk-settings.c +7 -2
@@ -40,7 +40,7 @@ void blk_set_default_limits(struct queue_limits *lim) lim->virt_boundary_mask =0 ; lim->max_segment_size =BLK_MAX_SEGMENT_SIZE ; lim->max_sectors = lim->max_hw_sectors =BLK_SAFE_MAX_SECTORS ; - lim->max_dev_sectors =0 ; + lim->max_user_sectors = lim->max_dev_sectors =0 ; lim->chunk_sectors =0 ; lim->max_write_zeroes_sectors =0 ; lim->max_zone_append_sectors =0 ;
@@ -135,7 +135,12 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto limits->max_hw_sectors = max_hw_sectors; max_sectors =min_not_zero (max_hw_sectors, limits->max_dev_sectors); - max_sectors =min (max_sectors,BLK_DEF_MAX_SECTORS ); + +if (limits->max_user_sectors) + max_sectors =min (max_sectors, limits->max_user_sectors); +else + max_sectors =min (max_sectors,BLK_DEF_MAX_SECTORS ); + max_sectors =round_down (max_sectors, limits->logical_block_size >>SECTOR_SHIFT ); limits->max_sectors = max_sectors;
block/blk-sysfs.c +15 -6
@@ -239,19 +239,28 @@ static ssize_t queue_zone_append_max_show(struct request_queue *q, char *page)static ssize_t queue_max_sectors_store (struct request_queue *q,const char *page,size_t count) { -unsigned long max_sectors_kb, +unsigned long var; +unsigned int max_sectors_kb, max_hw_sectors_kb =queue_max_hw_sectors (q) >>1 , page_kb =1 << (PAGE_SHIFT -10 ); -ssize_t ret =queue_var_store (&max_sectors_kb, page, count); +ssize_t ret =queue_var_store (&var, page, count);if (ret <0 )return ret; - max_hw_sectors_kb =min_not_zero (max_hw_sectors_kb, (unsigned long ) + max_sectors_kb = (unsigned int )var; + max_hw_sectors_kb =min_not_zero (max_hw_sectors_kb, q->limits.max_dev_sectors >>1 ); - -if (max_sectors_kb > max_hw_sectors_kb || max_sectors_kb < page_kb) -return -EINVAL ; +if (max_sectors_kb ==0 ) { + q->limits.max_user_sectors =0 ; + max_sectors_kb =min (max_hw_sectors_kb, +BLK_DEF_MAX_SECTORS >>1 ); + }else { +if (max_sectors_kb > max_hw_sectors_kb || + max_sectors_kb < page_kb) +return -EINVAL ; + q->limits.max_user_sectors = max_sectors_kb <<1 ; + }spin_lock_irq (&q->queue_lock); q->limits.max_sectors = max_sectors_kb <<1 ;
include/linux/blkdev.h +1 -0
@@ -288,6 +288,7 @@ struct queue_limits {unsigned int max_dev_sectors;unsigned int chunk_sectors;unsigned int max_sectors; +unsigned int max_user_sectors;unsigned int max_segment_size;unsigned int physical_block_size;unsigned int logical_block_size;
Signature · 1 line
2.30.2
Re: [PATCHv4 2/2] block: save user max_sectors limit
Quoted 11 lines · Keith Busch
block/blk-sysfs.c +2
-1@@ -239,19 +239,28 @@ static ssize_t queue_zone_append_max_show(struct request_queue *q, char *page)static ssize_t queue_max_sectors_store (struct request_queue *q,const char *page,size_t count) { - unsigned long max_sectors_kb, +unsigned long var; + unsigned int max_sectors_kb,
block/blk-sysfs.c static ssize_t queue_zone_append_max_show(struct request_queue *q, char *page) · line 251
Quoted 10 lines
block/blk-sysfs.c +2
-2max_hw_sectors_kb =queue_max_hw_sectors (q) >>1 , page_kb =1 << (PAGE_SHIFT -10 ); -ssize_t ret =queue_var_store (&max_sectors_kb, page, count); +ssize_t ret =queue_var_store (&var, page, count);if (ret <0 )return ret; - max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb, (unsigned long) + max_sectors_kb = (unsigned int )var;
Shouldn't this function report an error if 'var' is too large to fit into an unsigned int?
Otherwise this patch looks good to me.
Thanks,
Bart.
Re: [PATCHv4 2/2] block: save user max_sectors limit
Quoted 15 lines · Bart Van Assche
Quoted 14 lines · Keith Busch
block/blk-sysfs.c +2
-2@@ -239,19 +239,28 @@ static ssize_t queue_zone_append_max_show(struct request_queue *q, char *page)static ssize_t queue_max_sectors_store (struct request_queue *q,const char *page,size_t count) { -unsigned long max_sectors_kb, +unsigned long var; +unsigned int max_sectors_kb, max_hw_sectors_kb =queue_max_hw_sectors (q) >>1 , page_kb =1 << (PAGE_SHIFT -10 ); -ssize_t ret =queue_var_store (&max_sectors_kb, page, count);
Quoted 8 lines
block/blk-sysfs.c static ssize_t queue_zone_append_max_show(struct request_queue *q, char *page) · line 251
Quoted 5 lines
block/blk-sysfs.c +2
-1+ssize_t ret =queue_var_store (&var, page, count);if (ret <0 )return ret; - max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb, (unsigned long) + max_sectors_kb = (unsigned int )var;Shouldn't this function report an error if 'var' is too large to fit into an unsigned int?
Yes it should, and queue_var_store() will return -EINVAL if that happens. That's certainly not clear just from reading this patch, but the condition is handled.
Re: [PATCHv4 2/2] block: save user max_sectors limit
In reply to Keith BuschLooks good:
Re: [PATCHv4 2/2] block: save user max_sectors limit
In reply to Keith BuschKeith,
Quoted 8 lines
The user can set the
max_sectorslimit to any valid value via sysfs /sys/block/<dev>/queue/max_sectors_kb attribute. If the device limits are ever rescanned, though, the limit reverts back to the potentially artificially lowBLK_DEF_MAX_SECTORSvalue.Preserve the user's setting as the
max_sectorslimit as long as it's valid. The user can reset back to defaults by writing 0 to the sysfs file.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Quoted 8 lines · Keith Busch
If the user overrides the max sectors for their device (which is currently defaulting to quite a low value for modern hardware), their request is lost on a rescan. Save it and fix the weird type issues.
Changes since v3: Fixed the unsigned long/unsigned int issue raised by clang.
[...]
Applied, thanks!
[1/2] block: make BLK_DEF_MAX_SECTORS unsigned
commit: c749b9c6de40f0882d9c83c8a3780e631603eb9d
[2/2] block: save user max_sectors limit
commit: 39001023bf1dfcee0ad1602501fbdea6f0d3d3bbBest regards,
Signature · 1 line
Jens Axboe