From: Christoph Hellwig <hch@lst.de>
To: Keith Busch <kbusch@meta.com>
Cc: linux-block@vger.kernel.org, axboe@kernel.dk, hch@lst.de,
martin.petersen@oracle.com, Keith Busch <kbusch@kernel.org>
Subject: Re: [PATCH] block: save user max_sectors limit
Date: Fri, 23 Dec 2022 07:00:09 +0100 [thread overview]
Message-ID: <20221223060009.GA3088@lst.de> (raw)
In-Reply-To: <20221222175204.1782061-1-kbusch@meta.com>
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);
}
next prev parent reply other threads:[~2022-12-23 6:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-22 17:52 [PATCH] block: save user max_sectors limit Keith Busch
2022-12-23 6:00 ` Christoph Hellwig [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221223060009.GA3088@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=kbusch@kernel.org \
--cc=kbusch@meta.com \
--cc=linux-block@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).