* [PATCH] NVMe: Do not set queue depth beyond device max
@ 2012-07-26 22:21 Keith Busch
2012-07-27 14:07 ` Matthew Wilcox
0 siblings, 1 reply; 2+ messages in thread
From: Keith Busch @ 2012-07-26 22:21 UTC (permalink / raw)
Set the depth to the device maximum if the requested depth exceeds the
device's capabilities.
Signed-off-by: Keith Busch <keith.busch at intel.com>
---
drivers/block/nvme.c | 8 ++++++--
include/linux/nvme.h | 1 +
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/block/nvme.c b/drivers/block/nvme.c
index 7bcd882..40c751d 100644
--- a/drivers/block/nvme.c
+++ b/drivers/block/nvme.c
@@ -892,8 +892,12 @@ static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid,
int depth, int vector)
{
struct device *dmadev = &dev->pci_dev->dev;
- unsigned extra = (depth / 8) + (depth * sizeof(struct nvme_cmd_info));
- struct nvme_queue *nvmeq = kzalloc(sizeof(*nvmeq) + extra, GFP_KERNEL);
+ unsigned extra;
+ struct nvme_queue *nvmeq;
+
+ depth = min_t(int, NVME_CAP_MQES(readq(&dev->bar->cap)) + 1, depth);
+ extra = DIV_ROUND_UP(depth, 8) + (depth * sizeof(struct nvme_cmd_info));
+ nvmeq = kzalloc(sizeof(*nvmeq) + extra, GFP_KERNEL);
if (!nvmeq)
return NULL;
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 9490a00..bddc954 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -35,6 +35,7 @@ struct nvme_bar {
__u64 acq; /* Admin CQ Base Address */
};
+#define NVME_CAP_MQES(cap) (cap & 0xffff)
#define NVME_CAP_TIMEOUT(cap) (((cap) >> 24) & 0xff)
#define NVME_CAP_STRIDE(cap) (((cap) >> 32) & 0xf)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH] NVMe: Do not set queue depth beyond device max
2012-07-26 22:21 [PATCH] NVMe: Do not set queue depth beyond device max Keith Busch
@ 2012-07-27 14:07 ` Matthew Wilcox
0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2012-07-27 14:07 UTC (permalink / raw)
On Thu, Jul 26, 2012@04:21:08PM -0600, Keith Busch wrote:
> Set the depth to the device maximum if the requested depth exceeds the
> device's capabilities.
The problem is that nvme_alloc_queue is called for both IO queues and
the admin queue, but MQES only applies to the IO queues.
I think we need to read it in nvme_setup_io_queues() instead. This also
has the advantage of only reading MQES once instead of once per queue.
> @@ -892,8 +892,12 @@ static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid,
> int depth, int vector)
> {
> struct device *dmadev = &dev->pci_dev->dev;
> - unsigned extra = (depth / 8) + (depth * sizeof(struct nvme_cmd_info));
> - struct nvme_queue *nvmeq = kzalloc(sizeof(*nvmeq) + extra, GFP_KERNEL);
> + unsigned extra;
> + struct nvme_queue *nvmeq;
> +
> + depth = min_t(int, NVME_CAP_MQES(readq(&dev->bar->cap)) + 1, depth);
> + extra = DIV_ROUND_UP(depth, 8) + (depth * sizeof(struct nvme_cmd_info));
> + nvmeq = kzalloc(sizeof(*nvmeq) + extra, GFP_KERNEL);
> if (!nvmeq)
> return NULL;
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-07-27 14:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-26 22:21 [PATCH] NVMe: Do not set queue depth beyond device max Keith Busch
2012-07-27 14:07 ` Matthew Wilcox
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).