Skip to content

Commit 4e893ca

Browse files
Stuart Hayeskeithbusch
authored andcommitted
nvme_core: scan namespaces asynchronously
Use async function calls to make namespace scanning happen in parallel. Without the patch, NVME namespaces are scanned serially, so it can take a long time for all of a controller's namespaces to become available, especially with a slower (TCP) interface with large number of namespaces. It is not uncommon to have large numbers (hundreds or thousands) of namespaces on nvme-of with storage servers. The time it took for all namespaces to show up after connecting (via TCP) to a controller with 1002 namespaces was measured on one system: network latency without patch with patch 0 6s 1s 50ms 210s 10s 100ms 417s 18s Measurements taken on another system show the effect of the patch on the time nvme_scan_work() took to complete, when connecting to a linux nvme-of target with varying numbers of namespaces, on a network of 400us. namespaces without patch with patch 1 16ms 14ms 2 24ms 16ms 4 49ms 22ms 8 101ms 33ms 16 207ms 56ms 100 1.4s 0.6s 1000 12.9s 2.0s On the same system, connecting to a local PCIe NVMe drive (a Samsung PM1733) instead of a network target: namespaces without patch with patch 1 13ms 12ms 2 41ms 13ms Signed-off-by: Stuart Hayes <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]>
1 parent b2261de commit 4e893ca

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

drivers/nvme/host/core.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (c) 2011-2014, Intel Corporation.
55
*/
66

7+
#include <linux/async.h>
78
#include <linux/blkdev.h>
89
#include <linux/blk-mq.h>
910
#include <linux/blk-integrity.h>
@@ -4040,6 +4041,35 @@ static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid)
40404041
}
40414042
}
40424043

4044+
/**
4045+
* struct async_scan_info - keeps track of controller & NSIDs to scan
4046+
* @ctrl: Controller on which namespaces are being scanned
4047+
* @next_nsid: Index of next NSID to scan in ns_list
4048+
* @ns_list: Pointer to list of NSIDs to scan
4049+
*
4050+
* Note: There is a single async_scan_info structure shared by all instances
4051+
* of nvme_scan_ns_async() scanning a given controller, so the atomic
4052+
* operations on next_nsid are critical to ensure each instance scans a unique
4053+
* NSID.
4054+
*/
4055+
struct async_scan_info {
4056+
struct nvme_ctrl *ctrl;
4057+
atomic_t next_nsid;
4058+
__le32 *ns_list;
4059+
};
4060+
4061+
static void nvme_scan_ns_async(void *data, async_cookie_t cookie)
4062+
{
4063+
struct async_scan_info *scan_info = data;
4064+
int idx;
4065+
u32 nsid;
4066+
4067+
idx = (u32)atomic_fetch_inc(&scan_info->next_nsid);
4068+
nsid = le32_to_cpu(scan_info->ns_list[idx]);
4069+
4070+
nvme_scan_ns(scan_info->ctrl, nsid);
4071+
}
4072+
40434073
static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
40444074
unsigned nsid)
40454075
{
@@ -4066,11 +4096,15 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl)
40664096
__le32 *ns_list;
40674097
u32 prev = 0;
40684098
int ret = 0, i;
4099+
ASYNC_DOMAIN(domain);
4100+
struct async_scan_info scan_info;
40694101

40704102
ns_list = kzalloc(NVME_IDENTIFY_DATA_SIZE, GFP_KERNEL);
40714103
if (!ns_list)
40724104
return -ENOMEM;
40734105

4106+
scan_info.ctrl = ctrl;
4107+
scan_info.ns_list = ns_list;
40744108
for (;;) {
40754109
struct nvme_command cmd = {
40764110
.identify.opcode = nvme_admin_identify,
@@ -4086,19 +4120,23 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl)
40864120
goto free;
40874121
}
40884122

4123+
atomic_set(&scan_info.next_nsid, 0);
40894124
for (i = 0; i < nr_entries; i++) {
40904125
u32 nsid = le32_to_cpu(ns_list[i]);
40914126

40924127
if (!nsid) /* end of the list? */
40934128
goto out;
4094-
nvme_scan_ns(ctrl, nsid);
4129+
async_schedule_domain(nvme_scan_ns_async, &scan_info,
4130+
&domain);
40954131
while (++prev < nsid)
40964132
nvme_ns_remove_by_nsid(ctrl, prev);
40974133
}
4134+
async_synchronize_full_domain(&domain);
40984135
}
40994136
out:
41004137
nvme_remove_invalid_namespaces(ctrl, prev);
41014138
free:
4139+
async_synchronize_full_domain(&domain);
41024140
kfree(ns_list);
41034141
return ret;
41044142
}

0 commit comments

Comments
 (0)