From: John Garry <john.g.garry@oracle.com>
To: Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Damien Le Moal <dlemoal@kernel.org>,
Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>,
linux-block@vger.kernel.org, linux-nvme@lists.infradead.org,
virtualization@lists.linux.dev
Subject: Re: [PATCH 03/15] block: add an API to atomically update queue limits
Date: Thu, 25 Jan 2024 10:28:49 +0000 [thread overview]
Message-ID: <79eb5c4c-d9c0-4a70-94ac-04892bbf8085@oracle.com> (raw)
In-Reply-To: <20240122173645.1686078-4-hch@lst.de>
> +
> +int blk_validate_limits(struct queue_limits *lim)
> +{
> + unsigned int max_hw_sectors;
> +
> + if (!lim->logical_block_size)
> + lim->logical_block_size = SECTOR_SIZE;
nit: This function is doing a bit more than validating, as the function
name suggests
> +
> + if (!lim->physical_block_size)
> + lim->physical_block_size = SECTOR_SIZE;
> + if (lim->physical_block_size < lim->logical_block_size)
> + lim->physical_block_size = lim->physical_block_size;
> +
> + if (!lim->io_min)
> + lim->io_min = SECTOR_SIZE;
> + if (lim->io_min < lim->physical_block_size)
> + lim->io_min = lim->physical_block_size;
> +
> + if (!lim->max_hw_sectors)
> + lim->max_hw_sectors = BLK_SAFE_MAX_SECTORS;
> + if (WARN_ON_ONCE(lim->max_hw_sectors < PAGE_SIZE / SECTOR_SIZE))
> + return -EINVAL;
The WARN_ON_ONCE usage is odd, as it will only ever WARN once for a
specific q, while other queues associated with other drivers may have
the same limit issue. But I suppose if one issue is fixed, then the
other will make itself known...
> +
> + lim->max_hw_sectors = round_down(lim->max_hw_sectors,
> + lim->logical_block_size >> SECTOR_SHIFT);
> +
> + max_hw_sectors = min_not_zero(lim->max_hw_sectors,
> + lim->max_dev_sectors);
> + if (lim->max_user_sectors) {
> + if (lim->max_user_sectors > max_hw_sectors ||
> + lim->max_user_sectors < PAGE_SIZE / SECTOR_SIZE)
> + return -EINVAL;
> + lim->max_sectors = min(max_hw_sectors, lim->max_user_sectors);
> + } else {
> + lim->max_sectors = min(max_hw_sectors, BLK_DEF_MAX_SECTORS_CAP);
> + }
> +
>
> +/**
> + * queue_limits_commit_update - commit an atomic update of queue limits
> + * @q: queue to update
> + * @lim: limits to apply
> + *
> + * Apply the limits in @lim that were obtained from queue_limits_start_update()
> + * and updated by the caller to @q.
> + *
> + * Returns 0 if successful, else a negative error code.
> + */
> +int queue_limits_commit_update(struct request_queue *q,
> + struct queue_limits *lim)
> + __releases(q->limits_lock)
> +{
> + int error = blk_validate_limits(lim);
> +
> + if (!error) {
> + q->limits = *lim;
this is duplicating what blk_alloc_queue() does
> + if (q->disk)
> + blk_apply_bdi_limits(q->disk->bdi, lim);
> + }
> + mutex_unlock(&q->limits_lock);
> + return error;
> +}
> +EXPORT_SYMBOL_GPL(queue_limits_commit_update);
> +
> /**
> * blk_queue_bounce_limit - set bounce buffer limit for queue
> * @q: the request queue for the device
> diff --git a/block/blk.h b/block/blk.h
> index 1ef920f72e0f87..58b5dbac2a487d 100644
> --- a/block/blk.h
> +++ b/block/blk.h
> @@ -447,6 +447,7 @@ static inline void bio_release_page(struct bio *bio, struct page *page)
> unpin_user_page(page);
> }
>
> +int blk_validate_limits(struct queue_limits *lim);
> struct request_queue *blk_alloc_queue(int node_id);
>
> int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode);
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index 4a2e82c7971c86..5b5d3b238de1e7 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -473,6 +473,7 @@ struct request_queue {
>
> struct mutex sysfs_lock;
> struct mutex sysfs_dir_lock;
> + struct mutex limits_lock;
>
> /*
> * for reusing dead hctx instance in case of updating
> @@ -861,6 +862,28 @@ static inline unsigned int blk_chunk_sectors_left(sector_t offset,
> return chunk_sectors - (offset & (chunk_sectors - 1));
> }
>
> +/**
> + * queue_limits_start_update - start an atomic update of queue limits
> + * @q: queue to update
> + *
> + * This functions starts an atomic update of the queue limits. It takes a lock
> + * to prevent other updates and returns a snapshot of the current limits that
> + * the caller can modify. The caller must call queue_limits_commit_update()
> + * to finish the update.
> + *
> + * Context: process context. The caller must have frozen the queue or ensured
> + * that there is outstanding I/O by other means.
> + */
> +static inline struct queue_limits
> +queue_limits_start_update(struct request_queue *q)
> + __acquires(q->limits_lock)
> +{
> + mutex_lock(&q->limits_lock);
> + return q->limits;
> +}
> +int queue_limits_commit_update(struct request_queue *q,
> + struct queue_limits *lim);
It ain't so nice that the code for queue_limits_start_update() and
queue_limits_commit_update() pair are in separate files.
> +
> /*
> * Access functions for manipulating queue properties
> */
next prev parent reply other threads:[~2024-01-25 10:29 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-22 17:36 atomic queue limits updates Christoph Hellwig
2024-01-22 17:36 ` [PATCH 01/15] block: move max_{open,active}_zones to struct queue_limits Christoph Hellwig
2024-01-23 4:39 ` Damien Le Moal
2024-01-24 6:00 ` Hannes Reinecke
2024-01-22 17:36 ` [PATCH 02/15] block: refactor disk_update_readahead Christoph Hellwig
2024-01-23 4:41 ` Damien Le Moal
2024-01-23 8:40 ` Christoph Hellwig
2024-01-24 6:01 ` Hannes Reinecke
2024-01-22 17:36 ` [PATCH 03/15] block: add an API to atomically update queue limits Christoph Hellwig
2024-01-23 4:50 ` Damien Le Moal
2024-01-23 8:44 ` Christoph Hellwig
2024-01-24 6:08 ` Hannes Reinecke
2024-01-24 9:21 ` Christoph Hellwig
2024-01-25 10:28 ` John Garry [this message]
2024-01-25 14:35 ` Christoph Hellwig
2024-01-22 17:36 ` [PATCH 04/15] block: use queue_limits_commit_update in queue_max_sectors_store Christoph Hellwig
2024-01-23 5:07 ` Damien Le Moal
2024-01-24 6:09 ` Hannes Reinecke
2024-01-22 17:36 ` [PATCH 05/15] block: add a max_user_discard_sectors queue limit Christoph Hellwig
2024-01-22 18:27 ` Keith Busch
2024-01-22 18:38 ` Christoph Hellwig
2024-01-24 15:44 ` Keith Busch
2024-01-25 8:12 ` Christoph Hellwig
2024-01-24 6:10 ` Hannes Reinecke
2024-01-22 17:36 ` [PATCH 06/15] nvme: remove the hack to not update the discard limits in nvme_config_discard Christoph Hellwig
2024-01-23 5:12 ` Damien Le Moal
2024-01-23 8:45 ` Christoph Hellwig
2024-01-24 6:11 ` Hannes Reinecke
2024-01-22 17:36 ` [PATCH 07/15] block: use queue_limits_commit_update in queue_discard_max_store Christoph Hellwig
2024-01-23 5:16 ` Damien Le Moal
2024-01-24 6:12 ` Hannes Reinecke
2024-01-22 17:36 ` [PATCH 08/15] block: pass a queue_limits argument to blk_alloc_queue Christoph Hellwig
2024-01-23 5:17 ` Damien Le Moal
2024-01-24 6:14 ` Hannes Reinecke
2024-01-25 9:45 ` John Garry
2024-01-25 14:32 ` Christoph Hellwig
2024-01-22 17:36 ` [PATCH 09/15] block: pass a queue_limits argument to blk_mq_init_queue Christoph Hellwig
2024-01-23 5:19 ` Damien Le Moal
2024-01-24 6:16 ` Hannes Reinecke
2024-01-22 17:36 ` [PATCH 10/15] block: pass a queue_limits argument to blk_mq_alloc_disk Christoph Hellwig
2024-01-23 5:22 ` Damien Le Moal
2024-01-24 6:17 ` Hannes Reinecke
2024-01-22 17:36 ` [PATCH 11/15] virtio_blk: split virtblk_probe Christoph Hellwig
2024-01-23 5:26 ` Damien Le Moal
2024-01-23 14:16 ` Stefan Hajnoczi
2024-01-23 20:23 ` Chaitanya Kulkarni
2024-01-24 6:19 ` Hannes Reinecke
2024-01-22 17:36 ` [PATCH 12/15] virtio_blk: pass queue_limits to blk_mq_alloc_disk Christoph Hellwig
2024-01-23 5:27 ` Damien Le Moal
2024-01-23 14:19 ` Stefan Hajnoczi
2024-01-24 6:21 ` Hannes Reinecke
2024-06-28 14:25 ` John Garry
2024-06-29 5:19 ` Christoph Hellwig
2024-06-30 9:55 ` John Garry
2024-07-01 4:54 ` Christoph Hellwig
2024-01-22 17:36 ` [PATCH 13/15] loop: cleanup loop_config_discard Christoph Hellwig
2024-01-23 5:28 ` Damien Le Moal
2024-01-24 5:29 ` Chaitanya Kulkarni
2024-01-24 6:21 ` Hannes Reinecke
2024-01-22 17:36 ` [PATCH 14/15] loop: pass queue_limits to blk_mq_alloc_disk Christoph Hellwig
2024-01-23 5:29 ` Damien Le Moal
2024-01-24 6:22 ` Hannes Reinecke
2024-01-22 17:36 ` [PATCH 15/15] loop: use the atomic queue limits update API Christoph Hellwig
2024-01-23 5:31 ` Damien Le Moal
2024-01-24 6:22 ` Hannes Reinecke
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=79eb5c4c-d9c0-4a70-94ac-04892bbf8085@oracle.com \
--to=john.g.garry@oracle.com \
--cc=axboe@kernel.dk \
--cc=dlemoal@kernel.org \
--cc=hch@lst.de \
--cc=jasowang@redhat.com \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=martin.petersen@oracle.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=sagi@grimberg.me \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.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).