Skip to content

Commit ca2b221

Browse files
mgurtovoykeithbusch
authored andcommitted
nvmet: introduce new max queue size configuration entry
Using this port configuration, one will be able to set the maximal queue size to be used for any controller that will be associated to the configured port. The default value stayed 1024 but each transport will be able to set the its own values before enabling the port. Introduce lower limit of 16 for minimal queue depth (same as we use in the host fabrics drivers). Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Israel Rukshin <israelr@nvidia.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Reviewed-by: Guixin Liu <kanie@linux.alibaba.com> Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent ad178ba commit ca2b221

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

drivers/nvme/target/configfs.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,32 @@ static ssize_t nvmet_param_inline_data_size_store(struct config_item *item,
273273

274274
CONFIGFS_ATTR(nvmet_, param_inline_data_size);
275275

276+
static ssize_t nvmet_param_max_queue_size_show(struct config_item *item,
277+
char *page)
278+
{
279+
struct nvmet_port *port = to_nvmet_port(item);
280+
281+
return snprintf(page, PAGE_SIZE, "%d\n", port->max_queue_size);
282+
}
283+
284+
static ssize_t nvmet_param_max_queue_size_store(struct config_item *item,
285+
const char *page, size_t count)
286+
{
287+
struct nvmet_port *port = to_nvmet_port(item);
288+
int ret;
289+
290+
if (nvmet_is_port_enabled(port, __func__))
291+
return -EACCES;
292+
ret = kstrtoint(page, 0, &port->max_queue_size);
293+
if (ret) {
294+
pr_err("Invalid value '%s' for max_queue_size\n", page);
295+
return -EINVAL;
296+
}
297+
return count;
298+
}
299+
300+
CONFIGFS_ATTR(nvmet_, param_max_queue_size);
301+
276302
#ifdef CONFIG_BLK_DEV_INTEGRITY
277303
static ssize_t nvmet_param_pi_enable_show(struct config_item *item,
278304
char *page)
@@ -1859,6 +1885,7 @@ static struct configfs_attribute *nvmet_port_attrs[] = {
18591885
&nvmet_attr_addr_trtype,
18601886
&nvmet_attr_addr_tsas,
18611887
&nvmet_attr_param_inline_data_size,
1888+
&nvmet_attr_param_max_queue_size,
18621889
#ifdef CONFIG_BLK_DEV_INTEGRITY
18631890
&nvmet_attr_param_pi_enable,
18641891
#endif
@@ -1917,6 +1944,7 @@ static struct config_group *nvmet_ports_make(struct config_group *group,
19171944
INIT_LIST_HEAD(&port->subsystems);
19181945
INIT_LIST_HEAD(&port->referrals);
19191946
port->inline_data_size = -1; /* < 0 == let the transport choose */
1947+
port->max_queue_size = -1; /* < 0 == let the transport choose */
19201948

19211949
port->disc_addr.portid = cpu_to_le16(portid);
19221950
port->disc_addr.adrfam = NVMF_ADDR_FAMILY_MAX;

drivers/nvme/target/core.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,18 @@ int nvmet_enable_port(struct nvmet_port *port)
358358
if (port->inline_data_size < 0)
359359
port->inline_data_size = 0;
360360

361+
/*
362+
* If the transport didn't set the max_queue_size properly, then clamp
363+
* it to the target limits. Also set default values in case the
364+
* transport didn't set it at all.
365+
*/
366+
if (port->max_queue_size < 0)
367+
port->max_queue_size = NVMET_MAX_QUEUE_SIZE;
368+
else
369+
port->max_queue_size = clamp_t(int, port->max_queue_size,
370+
NVMET_MIN_QUEUE_SIZE,
371+
NVMET_MAX_QUEUE_SIZE);
372+
361373
port->enabled = true;
362374
port->tr_ops = ops;
363375
return 0;
@@ -1223,9 +1235,10 @@ static void nvmet_init_cap(struct nvmet_ctrl *ctrl)
12231235
ctrl->cap |= (15ULL << 24);
12241236
/* maximum queue entries supported: */
12251237
if (ctrl->ops->get_max_queue_size)
1226-
ctrl->cap |= ctrl->ops->get_max_queue_size(ctrl) - 1;
1238+
ctrl->cap |= min_t(u16, ctrl->ops->get_max_queue_size(ctrl),
1239+
ctrl->port->max_queue_size) - 1;
12271240
else
1228-
ctrl->cap |= NVMET_QUEUE_SIZE - 1;
1241+
ctrl->cap |= ctrl->port->max_queue_size - 1;
12291242

12301243
if (nvmet_is_passthru_subsys(ctrl->subsys))
12311244
nvmet_passthrough_override_cap(ctrl);

drivers/nvme/target/nvmet.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ struct nvmet_port {
163163
void *priv;
164164
bool enabled;
165165
int inline_data_size;
166+
int max_queue_size;
166167
const struct nvmet_fabrics_ops *tr_ops;
167168
bool pi_enable;
168169
};
@@ -543,7 +544,8 @@ void nvmet_subsys_disc_changed(struct nvmet_subsys *subsys,
543544
void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type,
544545
u8 event_info, u8 log_page);
545546

546-
#define NVMET_QUEUE_SIZE 1024
547+
#define NVMET_MIN_QUEUE_SIZE 16
548+
#define NVMET_MAX_QUEUE_SIZE 1024
547549
#define NVMET_NR_QUEUES 128
548550
#define NVMET_MAX_CMD(ctrl) (NVME_CAP_MQES(ctrl->cap) + 1)
549551

0 commit comments

Comments
 (0)