diff mbox series

block: save user max_sectors limit

Message ID 20221221162758.407742-1-kbusch@meta.com (mailing list archive)
State New, archived
Headers show
Series block: save user max_sectors limit | expand

Commit Message

Keith Busch Dec. 21, 2022, 4:27 p.m. UTC
From: Keith Busch <kbusch@kernel.org>

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 long as it's valid and greater than the
default.

Signed-off-by: Keith Busch <kbusch@kernel.org>
---
 block/blk-settings.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Christoph Hellwig Dec. 22, 2022, 8:40 a.m. UTC | #1
On Thu, Dec 22, 2022 at 04:32:10PM +0800, kernel test robot wrote:
> >> block/blk-settings.c:138:49: warning: comparison of distinct pointer types ('typeof (limits->max_sectors) *' (aka 'unsigned int *') and 'typeof (BLK_DEF_MAX_SECTORS) *' (aka 'int *')) [-Wcompare-distinct-pointer-types]

Yeah, that's not going to work.  BLK_DEF_MAX_SECTORS should probably
become an unsigned constant to fix this.
Keith Busch Dec. 22, 2022, 3:40 p.m. UTC | #2
On Thu, Dec 22, 2022 at 09:40:11AM +0100, Christoph Hellwig wrote:
> On Thu, Dec 22, 2022 at 04:32:10PM +0800, kernel test robot wrote:
> > >> block/blk-settings.c:138:49: warning: comparison of distinct pointer types ('typeof (limits->max_sectors) *' (aka 'unsigned int *') and 'typeof (BLK_DEF_MAX_SECTORS) *' (aka 'int *')) [-Wcompare-distinct-pointer-types]
> 
> Yeah, that's not going to work.  BLK_DEF_MAX_SECTORS should probably
> become an unsigned constant to fix this.

Hm, I should have used max_t() instead of max().

But thinking on this again, we probably want to respect the user setting
even if it's lower than the default too, not just if its larger. I
believe that will require a new queue limit to save that value.
Martin K. Petersen Dec. 22, 2022, 4:07 p.m. UTC | #3
Keith,

> But thinking on this again, we probably want to respect the user
> setting even if it's lower than the default too, not just if its
> larger. I believe that will require a new queue limit to save that
> value.

Yeah, I have struggled with the same problem for various user parameter
overrides in SCSI. Lowering defaults or detected values is fairly
common.
diff mbox series

Patch

diff --git a/block/blk-settings.c b/block/blk-settings.c
index 0477c4d527fee..523348926a800 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -135,7 +135,8 @@  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_t(unsigned int, max_sectors, max(limits->max_sectors,
+							  BLK_DEF_MAX_SECTORS));
 	max_sectors = round_down(max_sectors,
 				 limits->logical_block_size >> SECTOR_SHIFT);
 	limits->max_sectors = max_sectors;