nvme: queue-depth multipath iopolicy
v7 cover nvme: queue-depth multipath iopolicy
I've addressed Chaitanya's and Hannes's review comments and retested everything. Test results can be seen at:
https://github.com/johnmeneghini/iopolicy/tree/sample3
Please add this to nvme-6.11.
Changes since V6:
Cleanup tab formatting in nvme.h and removed extra white lines. Removed the results variable from nvme_mpath_end_request().
Changes since V5:
Refactored nvme_find_path() to reduce the spaghetti code. Cleaned up all comments and reduced the total size of the diff, and fixed the commit message. Thomas Song now gets credit as the first author.
Changes since V4:
Removed atomic_set() from and return if (old_iopolicy == iopolicy) At the beginning of nvme_subsys_iopolicy_update().
Changes since V3:
Addresssed all review comments, fixed the commit log, and moved nr_counter initialization from nvme_mpath_init_ctlr() to nvme_mpath_init_identify().
Changes since V2:
Add the NVME_MPATH_CNT_ACTIVE flag to eliminate a READ_ONCE in the completion path and increment/decrement the active_nr count on all mpath IOs - including passthru commands.
Send a pr_notice when ever the iopolicy on a subsystem is changed. This is important for support reasons. It is fully expected that users will be changing the iopolicy with active IO in progress.
Squashed everything and rebased to nvme-v6.10
Changes since V1:
I'm re-issuing Ewan's queue-depth patches in preparation for LSFMM
These patches were first show at ALPSS 2023 where I shared the following graphs which measure the IO distribution across 4 active-optimized controllers using the round-robin verses queue-depth iopolicy.
https://people.redhat.com/jmeneghi/ALPSS_2023/NVMe_QD_Multipathing.pdf
Since that time we have continued testing these patches with a number of different nvme-of storage arrays and test bed configurations, and I've codified the tests and methods we use to measure IO distribution
All of my test results, together with the scripts I used to generate these graphs, are available at:
https://github.com/johnmeneghini/iopolicy
Please use the scripts in this repository to do your own testing.
These patches are based on nvme-v6.9
Thomas Song (1):
nvme-multipath: implement "queue-depth" iopolicy
drivers/nvme/host/core.c | 2 +- drivers/nvme/host/multipath.c | 103 +++++++++++++++++++++++++++++++--- drivers/nvme/host/nvme.h | 5 ++ 3 files changed, 101 insertions(+), 9 deletions(-)
Signature · 1 line
2.45.1
PATCH v7 1/1 nvme-multipath: implement "queue-depth" iopolicy
From: Thomas Song <[email protected]>
The round-robin path selector is inefficient in cases where there is a difference in latency between paths. In the presence of one or more high latency paths the round-robin selector continues to use the high latency path equally. This results in a bias towards the highest latency path and can cause a significant decrease in overall performance as IOs pile on the highest latency path. This problem is acute with NVMe-oF controllers.
The queue-depth policy instead sends I/O requests down the path with the least amount of requests in its request queue. Paths with lower latency will clear requests more quickly and have less requests in their queues compared to higher latency paths. The goal of this path selector is to make more use of lower latency paths which will bring down overall IO latency and increase throughput and performance.
[emilne: patch developed by Thomas Song @ Pure Storage, fixed whitespace
and compilation warnings, updated MODULE_PARM description, and fixed potential issue with ->current_path[] being used]
--- drivers/nvme/host/core.c | 2 +- drivers/nvme/host/multipath.c | 103 +++++++++++++++++++++++++++++++--- drivers/nvme/host/nvme.h | 5 ++ 3 files changed, 101 insertions(+), 9 deletions(-)
drivers/nvme/host/core.c +1 -1
@@ -110,7 +110,7 @@ struct workqueue_struct *nvme_delete_wq;EXPORT_SYMBOL_GPL (nvme_delete_wq);static LIST_HEAD (nvme_subsystems); -static DEFINE_MUTEX (nvme_subsystems_lock); +DEFINE_MUTEX (nvme_subsystems_lock);static DEFINE_IDA (nvme_instance_ida);static dev_t nvme_ctrl_base_chr_devt;
drivers/nvme/host/multipath.c +95 -8
181 lines not on this page · raw message
drivers/nvme/host/nvme.h +5 -0
@@ -50,6 +50,8 @@ extern struct workqueue_struct *nvme_wq;extern struct workqueue_struct *nvme_reset_wq;extern struct workqueue_struct *nvme_delete_wq; +extern struct mutex nvme_subsystems_lock; +/* * List of workarounds for devices that required behavior not specified in * the standard.
@@ -195,6 +197,7 @@ enum {NVME_REQ_CANCELLED = (1 <<0 ),NVME_REQ_USERCMD = (1 <<1 ),NVME_MPATH_IO_STATS = (1 <<2 ), + NVME_MPATH_CNT_ACTIVE = (1 << 3), };static inline struct nvme_request *nvme_req (struct request *req)
@@ -360,6 +363,7 @@ struct nvme_ctrl {size_t ana_log_size;struct timer_list anatt_timer;struct work_struct ana_work; +atomic_t nr_active;#endif #ifdef CONFIG_NVME_HOST_AUTH
@@ -408,6 +412,7 @@ static inline enum nvme_ctrl_state nvme_ctrl_state(struct nvme_ctrl *ctrl)enum nvme_iopolicy {NVME_IOPOLICY_NUMA ,NVME_IOPOLICY_RR , +NVME_IOPOLICY_QD , };struct nvme_subsystem {
Signature · 1 line
2.45.1
Christoph Hellwig
maintainerRe: [PATCH v7 1/1] nvme-multipath: implement "queue-depth" iopolicy
Quoted 1 line
[jmeneghi: vairious changes and improvements, addressed review comments]
s/vairious/various/
drivers/nvme/host/multipath.c void nvme_mpath_end_request(struct request *rq) · line 152
Quoted 1 line
drivers/nvme/host/multipath.c +1
-0+if ((nvme_req (rq)->flags &NVME_MPATH_CNT_ACTIVE ))
No need for the double braces here.
drivers/nvme/host/multipath.c void nvme_mpath_end_request(struct request *rq) · line 153
Quoted 1 line
drivers/nvme/host/multipath.c +1
-0+WARN_ON_ONCE ((atomic_dec_if_positive (&ns->ctrl->nr_active)) <0 );
Overly long line.
But I don't understand why you need the WARN_ON anyway. If the value must always be positive there is no point in atomic_dec_if_positive. If misaccounting is fine there WARN_ON is counterproductive.
drivers/nvme/host/multipath.c static struct nvme_ns *nvme_next_ns(struct nvme_ns_head *head, · line 312
Quoted 11 lines
drivers/nvme/host/multipath.c +7
-3-static struct nvme_ns *nvme_round_robin_path (struct nvme_ns_head *head, -int node,struct nvme_ns *old) +static struct nvme_ns *nvme_round_robin_path (struct nvme_ns_head *head) { -struct nvme_ns *ns, *found =NULL ; +struct nvme_ns *ns, *old, *found =NULL ; +int node =numa_node_id (); + + old =srcu_dereference (head->current_path[node], &head->srcu); +if (unlikely (!old)) +return __nvme_find_path (head, node);
Can you split the refactoring of the existing path selectors into a prep patch, please?
drivers/nvme/host/multipath.c static ssize_t nvme_subsys_iopolicy_show(struct device *dev, · line 877
Quoted 10 lines
drivers/nvme/host/multipath.c +10
-0+static void nvme_subsys_iopolicy_update (struct nvme_subsystem *subsys, +int iopolicy) +{ +struct nvme_ctrl *ctrl; +int old_iopolicy =READ_ONCE (subsys->iopolicy); + +if (old_iopolicy == iopolicy) +return ; + +WRITE_ONCE (subsys->iopolicy, iopolicy);
What is the atomicy model here? There doesn't seem to be any global lock protecting it? Maybe move it into the nvme_subsystems_lock critical section?
drivers/nvme/host/multipath.c static ssize_t nvme_subsys_iopolicy_show(struct device *dev, · line 887
Quoted 3 lines
drivers/nvme/host/multipath.c +3
-0+pr_notice ("%s: changed from %s to %s for subsysnqn %s\n" , __func__, + nvme_iopolicy_names[old_iopolicy], nvme_iopolicy_names[iopolicy], + subsys->subnqn);
The function is not really relevant here, this should become something like:
pr_notice("%s: changing iopolicy from %s to %s\n",
subsys->subnqn,
nvme_iopolicy_names[old_iopolicy],
nvme_iopolicy_names[iopolicy]);or maybe:
dev_notice(changing iopolicy from %s to %s\n", &subsys->dev, nvme_iopolicy_names[old_iopolicy], nvme_iopolicy_names[iopolicy]);
Re: [PATCH v7 1/1] nvme-multipath: implement "queue-depth" iopolicy
Quoted 6 lines · Christoph Hellwig
drivers/nvme/host/multipath.c void nvme_mpath_end_request(struct request *rq) · line 153
Quoted 1 line
drivers/nvme/host/multipath.c +1
-0+WARN_ON_ONCE ((atomic_dec_if_positive (&ns->ctrl->nr_active)) <0 );Overly long line.
But I don't understand why you need the
WARN_ONanyway. If the value must always be positive there is no point inatomic_dec_if_positive. If misaccounting is fine thereWARN_ONis counterproductive.
Agreed. I wanted this here for testing purposes. In all of my hours of running tests I never saw this warning go off, so I agree it should be removed.
/John
Re: [PATCH v7 1/1] nvme-multipath: implement "queue-depth" iopolicy
In reply to Christoph HellwigQuoted 16 lines · Christoph Hellwig
drivers/nvme/host/multipath.c static struct nvme_ns *nvme_next_ns(struct nvme_ns_head *head, · line 312
Quoted 13 lines
[jmeneghi: vairious changes and improvements, addressed review comments]
drivers/nvme/host/multipath.c +7
-3-static struct nvme_ns *nvme_round_robin_path (struct nvme_ns_head *head, -int node,struct nvme_ns *old) +static struct nvme_ns *nvme_round_robin_path (struct nvme_ns_head *head) { -struct nvme_ns *ns, *found =NULL ; +struct nvme_ns *ns, *old, *found =NULL ; +int node =numa_node_id (); + + old =srcu_dereference (head->current_path[node], &head->srcu); +if (unlikely (!old)) +return __nvme_find_path (head, node);Can you split the refactoring of the existing path selectors into a prep patch, please?
Yes, I can do that.
Quoted 6 lines
Quoted 6 lines
drivers/nvme/host/multipath.c +6
-0+static void nvme_subsys_iopolicy_update (struct nvme_subsystem *subsys, +int iopolicy) +{ +struct nvme_ctrl *ctrl; +int old_iopolicy =READ_ONCE (subsys->iopolicy); +
Quoted 8 lines
drivers/nvme/host/multipath.c static ssize_t nvme_subsys_iopolicy_show(struct device *dev, · line 877
Quoted 4 lines
drivers/nvme/host/multipath.c +4
-0+if (old_iopolicy == iopolicy) +return ; + +WRITE_ONCE (subsys->iopolicy, iopolicy);What is the atomicy model here? There doesn't seem to be any global lock protecting it? Maybe move it into the
nvme_subsystems_lockcritical section?
Good question. I didn't write this code. Yes, I agree this looks racy. Updates to the subsys->iopolicy variable are not atomic. They don't need to be. The process of changing the iopolicy doesn't need to be synchronized and each CPU's cache will be updated lazily. This was done to avoid the expense of adding (another) atomic read the io path.
So really, the nvme_subsystems_lock only protects the list_entrys in &nvme_subsystems. I can move the WRITE_ONCE() update to after the lock, but then were did the caller - nvme_subsys_iopolicy_update() - get it's reference for the nvme_subsystem* from? And there's no lock or synchronization on the read side.
The subsys->iopolicy has always been unprotected. It's been that way from since before this change.
At least... that's my read of the code.
Quoted 11 lines
drivers/nvme/host/multipath.c static ssize_t nvme_subsys_iopolicy_show(struct device *dev, · line 887
Quoted 3 lines
drivers/nvme/host/multipath.c +3
-0+pr_notice ("%s: changed from %s to %s for subsysnqn %s\n" , __func__, + nvme_iopolicy_names[old_iopolicy], nvme_iopolicy_names[iopolicy], + subsys->subnqn);The function is not really relevant here, this should become something like:
pr_notice("%s: changing iopolicy from %s to %s\n", subsys->subnqn, nvme_iopolicy_names[old_iopolicy], nvme_iopolicy_names[iopolicy]);
How about:
pr_notice("Changed iopolicy from %s to %s for subsysnqn %s\n",
nvme_iopolicy_names[old_iopolicy],
nvme_iopolicy_names[iopolicy],
subsys->subnqn);Quoted 7 lines
or maybe:
dev_notice(changing iopolicy from %s to %s\n", &subsys->dev, nvme_iopolicy_names[old_iopolicy], nvme_iopolicy_names[iopolicy]);
The dev_notice will only spit out the nvme controller number (e.g. nvme5c5n3) and that's not very helpful to the user. I want to include the subsystemNQN because that's easily visible and something the user can see on both the storage and the host.
Example:
root:resultsF > echo "round-robin" > /sys/class/nvme-subsystem/nvme-subsys11/iopolicy
[Thu Jun 20 13:42:59 2024] Changed iopolicy from queue-depth to round-robin for subsysnqn nqn.1992-08.com.netapp:sn.2b82d9b13bb211ee8744d039ea989119:subsystem.SS104a
root:resultsF > nvme list-subsys | grep -A 8 nqn.1992-08.com.netapp:sn.2b82d9b13bb211ee8744d039ea989119:subsystem.SS104a nvme-subsys11 - NQN=nqn.1992-08.com.netapp:sn.2b82d9b13bb211ee8744d039ea989119:subsystem.SS104a
hostnqn=nqn.2014-08.org.nvmexpress:uuid:4c4c4544-0034-5310-8057-b2c04f355333
iopolicy=round-robin
\
+- nvme8 tcp traddr=172.18.60.14,trsvcid=4420,src_addr=172.18.60.4 live
+- nvme17 tcp traddr=172.18.50.15,trsvcid=4420,src_addr=172.18.50.3 live
+- nvme12 tcp traddr=172.18.60.16,trsvcid=4420,src_addr=172.18.60.4 live
+- nvme10 tcp traddr=172.18.50.13,trsvcid=4420,src_addr=172.18.50.3 live/John
Christoph Hellwig
maintainerRe: [PATCH v7 1/1] nvme-multipath: implement "queue-depth" iopolicy
Quoted 15 lines · John Meneghini
Quoted 6 lines
Quoted 6 lines
drivers/nvme/host/multipath.c +6
-0+static void nvme_subsys_iopolicy_update (struct nvme_subsystem *subsys, +int iopolicy) +{ +struct nvme_ctrl *ctrl; +int old_iopolicy =READ_ONCE (subsys->iopolicy); +Quoted 8 lines
drivers/nvme/host/multipath.c static ssize_t nvme_subsys_iopolicy_show(struct device *dev, · line 877
Quoted 4 lines
drivers/nvme/host/multipath.c +4
-0+if (old_iopolicy == iopolicy) +return ; + +WRITE_ONCE (subsys->iopolicy, iopolicy);What is the atomicy model here? There doesn't seem to be any global lock protecting it? Maybe move it into the
nvme_subsystems_lockcritical section?
Quoted 5 lines
Good question. I didn't write this code. Yes, I agree this looks racy. Updates to the
subsys->iopolicyvariable are not atomic. They don't need to be. The process of changing the iopolicy doesn't need to be synchronized and each CPU's cache will be updated lazily. This was done to avoid the expense of adding (another) atomic read the io path.
Looks like all sysfs ->store calls for the same attribute are protected by of->mutex in kernfs_fop_write_iter and we should actually be fine here. Sorry for the noise.
Quoted 11 lines
Quoted 4 lines
pr_notice("%s: changing iopolicy from %s to %s\n", subsys->subnqn, nvme_iopolicy_names[old_iopolicy], nvme_iopolicy_names[iopolicy]);How about:
pr_notice("Changed iopolicy from %s to %s for subsysnqn %s\n",
nvme_iopolicy_names[old_iopolicy], nvme_iopolicy_names[iopolicy], subsys->subnqn);
Having the identification as the prefixe seems easier to parse and grep for.
Re: [PATCH v7 1/1] nvme-multipath: implement "queue-depth" iopolicy
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · John Meneghini
How about:
pr_notice("Changed iopolicy from %s to %s for subsysnqn %s\n",
nvme_iopolicy_names[old_iopolicy], nvme_iopolicy_names[iopolicy], subsys->subnqn);Having the identification as the prefixe seems easier to parse and grep for.
To be clear Christoph, your saying you'd like the NQN in the prefix of the dmesg?
E.g.:
root> echo "round-robin" > /sys/class/nvme-subsystem/nvme-subsys11/iopolicy
[Thu Jun 24 11:44:20 2024] subsysnqn nqn.1992-08.com.netapp:sn.2b82d9b13bb211ee8744d039ea989119:subsystem.SS104a iopolicy changed from queue-depth to round-robin.
Correct?
/John
Christoph Hellwig
maintainerRe: [PATCH v7 1/1] nvme-multipath: implement "queue-depth" iopolicy
Quoted 4 lines · John Meneghini
Quoted 2 lines
Having the identification as the prefixe seems easier to parse and grep for.
To be clear Christoph, your saying you'd like the NQN in the prefix of the dmesg?
Yes.