* [PATCH] block: save user max_sectors limit
@ 2022-12-22 17:52 Keith Busch
2022-12-23 6:00 ` Christoph Hellwig
2022-12-27 2:13 ` Damien Le Moal
0 siblings, 2 replies; 9+ messages in thread
From: Keith Busch @ 2022-12-22 17:52 UTC (permalink / raw)
To: linux-block, axboe; +Cc: hch, martin.petersen, Keith Busch
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 kernel defined
BLK_DEF_MAX_SECTORS limit.
Preserve the user's setting for the max_sectors limit as long as it's
valid. The user can reset back to defaults by writing 0 to the sysfs
file.
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
block/blk-settings.c | 9 +++++++--
block/blk-sysfs.c | 10 +++++++++-
include/linux/blkdev.h | 1 +
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/block/blk-settings.c b/block/blk-settings.c
index 0477c4d527fee..e75304f853bd5 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -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_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
+
+ if (limits->max_user_sectors)
+ max_sectors = min_not_zero(max_sectors, limits->max_user_sectors);
+ else
+ max_sectors = min_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
+
max_sectors = round_down(max_sectors,
limits->logical_block_size >> SECTOR_SHIFT);
limits->max_sectors = max_sectors;
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 93d9e9c9a6ea8..db5d1d908f5d9 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -250,8 +250,16 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb, (unsigned long)
q->limits.max_dev_sectors >> 1);
- if (max_sectors_kb > max_hw_sectors_kb || max_sectors_kb < page_kb)
+ if (max_sectors_kb == 0) {
+ q->limits.max_user_sectors = 0;
+ max_sectors_kb = min_t(unsigned int, 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;
+ } else {
+ q->limits.max_user_sectors = max_sectors_kb << 1;
+ }
spin_lock_irq(&q->queue_lock);
q->limits.max_sectors = max_sectors_kb << 1;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 301cf1cf4f2fa..71e97f0a87264 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -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;
--
2.30.2
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] block: save user max_sectors limit
2022-12-22 17:52 [PATCH] block: save user max_sectors limit Keith Busch
@ 2022-12-23 6:00 ` Christoph Hellwig
2022-12-27 16:49 ` Keith Busch
2022-12-27 2:13 ` Damien Le Moal
1 sibling, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2022-12-23 6:00 UTC (permalink / raw)
To: Keith Busch; +Cc: linux-block, axboe, hch, martin.petersen, Keith Busch
On Thu, Dec 22, 2022 at 09:52:04AM -0800, Keith Busch wrote:
> 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 kernel defined
> BLK_DEF_MAX_SECTORS limit.
>
> Preserve the user's setting for the max_sectors limit as long as it's
> valid. The user can reset back to defaults by writing 0 to the sysfs
> file.
>
> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
> block/blk-settings.c | 9 +++++++--
> block/blk-sysfs.c | 10 +++++++++-
> include/linux/blkdev.h | 1 +
> 3 files changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index 0477c4d527fee..e75304f853bd5 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -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_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
> +
> + if (limits->max_user_sectors)
> + max_sectors = min_not_zero(max_sectors, limits->max_user_sectors);
I don't think the min_not_zero here makes sense, as you just checked
max_user_sectors for zero above, and max_sectors better not be zero.
> + else
> + max_sectors = min_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
And please make BLK_DEF_MAX_SECTORS an unsigned constant as it should be
and drop the min_t here. Instead of working around type mismatches
just avoid them from the beginning..
> + if (max_sectors_kb == 0) {
> + q->limits.max_user_sectors = 0;
> + max_sectors_kb = min_t(unsigned int, max_hw_sectors_kb,
> + BLK_DEF_MAX_SECTORS >> 1);
.. which will also pay off here.
> + } else if (max_sectors_kb > max_hw_sectors_kb ||
> + max_sectors_kb < page_kb) {
> return -EINVAL;
And this check should probably move above the old one to keep the
sanity checks first.
> + } else {
> + q->limits.max_user_sectors = max_sectors_kb << 1;
> + }
i.e.
if (max_sectors_kb > max_hw_sectors_kb || max_sectors_kb < page_kb)
return -EINVAL;
q->limits.max_user_sectors = max_sectors_kb << 1;
/* reset to default when the user clears max_sectors_kb: */
if (max_sectors_kb == 0) {
max_sectors_kb =
min(max_hw_sectors_kb, BLK_DEF_MAX_SECTORS >> 1);
}
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] block: save user max_sectors limit
2022-12-23 6:00 ` Christoph Hellwig
@ 2022-12-27 16:49 ` Keith Busch
2022-12-27 16:53 ` Christoph Hellwig
0 siblings, 1 reply; 9+ messages in thread
From: Keith Busch @ 2022-12-27 16:49 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Keith Busch, linux-block, axboe, martin.petersen
On Fri, Dec 23, 2022 at 07:00:09AM +0100, Christoph Hellwig wrote:
> On Thu, Dec 22, 2022 at 09:52:04AM -0800, Keith Busch wrote:
> > + max_sectors = min_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
>
> And please make BLK_DEF_MAX_SECTORS an unsigned constant as it should be
> and drop the min_t here. Instead of working around type mismatches
> just avoid them from the beginning..
Let me just make sure I understand: you don't want BLK_DEF_MAX_SECTORS
defined in an enum, and instead want it a 'const unsigned int'? Or
#define?
> > + } else if (max_sectors_kb > max_hw_sectors_kb ||
> > + max_sectors_kb < page_kb) {
> > return -EINVAL;
>
> And this check should probably move above the old one to keep the
> sanity checks first.
>
> > + } else {
> > + q->limits.max_user_sectors = max_sectors_kb << 1;
> > + }
>
> i.e.
>
> if (max_sectors_kb > max_hw_sectors_kb || max_sectors_kb < page_kb)
> return -EINVAL;
>
> q->limits.max_user_sectors = max_sectors_kb << 1;
>
> /* reset to default when the user clears max_sectors_kb: */
> if (max_sectors_kb == 0) {
We'll never reach here since 0 is < page_kb. But I think I can clean
this up a little bit for the next version.
> max_sectors_kb =
> min(max_hw_sectors_kb, BLK_DEF_MAX_SECTORS >> 1);
> }
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] block: save user max_sectors limit
2022-12-27 16:49 ` Keith Busch
@ 2022-12-27 16:53 ` Christoph Hellwig
0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2022-12-27 16:53 UTC (permalink / raw)
To: Keith Busch
Cc: Christoph Hellwig, Keith Busch, linux-block, axboe,
martin.petersen
On Tue, Dec 27, 2022 at 09:49:15AM -0700, Keith Busch wrote:
> > and drop the min_t here. Instead of working around type mismatches
> > just avoid them from the beginning..
>
> Let me just make sure I understand: you don't want BLK_DEF_MAX_SECTORS
> defined in an enum, and instead want it a 'const unsigned int'? Or
> #define?
Just make sure it's marked as unsigned, either and enum or define
works, just make sure it has the u suffix. Note that for enums recent
gccs enforce the same type over different embers, so you might have
to split it from an existing catchall enum into a separate one.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] block: save user max_sectors limit
2022-12-22 17:52 [PATCH] block: save user max_sectors limit Keith Busch
2022-12-23 6:00 ` Christoph Hellwig
@ 2022-12-27 2:13 ` Damien Le Moal
1 sibling, 0 replies; 9+ messages in thread
From: Damien Le Moal @ 2022-12-27 2:13 UTC (permalink / raw)
To: Keith Busch, linux-block, axboe; +Cc: hch, martin.petersen, Keith Busch
On 12/23/22 02:52, Keith Busch wrote:
> 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 kernel defined
> BLK_DEF_MAX_SECTORS limit.
>
> Preserve the user's setting for the max_sectors limit as long as it's
> valid. The user can reset back to defaults by writing 0 to the sysfs
> file.
Updating Documentation/ABI/stable/sysfs-block about this change would be
nice too.
>
> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
> block/blk-settings.c | 9 +++++++--
> block/blk-sysfs.c | 10 +++++++++-
> include/linux/blkdev.h | 1 +
> 3 files changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index 0477c4d527fee..e75304f853bd5 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -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_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
> +
> + if (limits->max_user_sectors)
> + max_sectors = min_not_zero(max_sectors, limits->max_user_sectors);
> + else
> + max_sectors = min_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
> +
> max_sectors = round_down(max_sectors,
> limits->logical_block_size >> SECTOR_SHIFT);
> limits->max_sectors = max_sectors;
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index 93d9e9c9a6ea8..db5d1d908f5d9 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -250,8 +250,16 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
> max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb, (unsigned long)
> q->limits.max_dev_sectors >> 1);
>
> - if (max_sectors_kb > max_hw_sectors_kb || max_sectors_kb < page_kb)
> + if (max_sectors_kb == 0) {
> + q->limits.max_user_sectors = 0;
> + max_sectors_kb = min_t(unsigned int, 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;
> + } else {
> + q->limits.max_user_sectors = max_sectors_kb << 1;
> + }
>
> spin_lock_irq(&q->queue_lock);
> q->limits.max_sectors = max_sectors_kb << 1;
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index 301cf1cf4f2fa..71e97f0a87264 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -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;
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] block: save user max_sectors limit
@ 2022-12-21 16:27 Keith Busch
[not found] ` <202212221657.yQawgPsu-lkp@intel.com>
0 siblings, 1 reply; 9+ messages in thread
From: Keith Busch @ 2022-12-21 16:27 UTC (permalink / raw)
To: linux-block, axboe; +Cc: hch, martin.petersen, Keith Busch
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(-)
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;
--
2.30.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-12-27 16:54 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-22 17:52 [PATCH] block: save user max_sectors limit Keith Busch
2022-12-23 6:00 ` Christoph Hellwig
2022-12-27 16:49 ` Keith Busch
2022-12-27 16:53 ` Christoph Hellwig
2022-12-27 2:13 ` Damien Le Moal
-- strict thread matches above, loose matches on Subject: below --
2022-12-21 16:27 Keith Busch
[not found] ` <202212221657.yQawgPsu-lkp@intel.com>
2022-12-22 8:40 ` Christoph Hellwig
2022-12-22 15:40 ` Keith Busch
2022-12-22 16:07 ` Martin K. Petersen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).