nvme: core: freeze multipath queue early in nvme_update_ns_info()
PATCH 1/1 nvme: core: freeze multipath queue early in nvme_update_ns_info()
For multipath devices, nvme_update_ns_info() needs to freeze both the queue of the path and the queue of the multipath device. For both operations, it waits for one RCU grace period to pass, ~25ms on my test system. By calling blk_freeze_queue_start() for the multipath queue early, we avoid waiting twice; tests using ftrace have shown that the second blk_mq_freeze_queue_wait() call finishes in just a few microseconds. The path queue is unfrozen before calling blk_mq_freeze_queue_wait() on the multipath queue, so that possibly outstanding IO in the multipath queue can be flushed.
I tested this using the "controller rescan under I/O load" test I submitted recently [1].
[1] https://lore.kernel.org/linux-nvme/[email protected]/T/#u
--- drivers/nvme/host/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +6 -2
@@ -2217,6 +2217,9 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)bool unsupported = false;int ret; +if (nvme_ns_head_multipath (ns->head)) +blk_freeze_queue_start (ns->head->disk->queue); +switch (info->ids.csi) {case NVME_CSI_ZNS :if (!IS_ENABLED (CONFIG_BLK_DEV_ZONED )) {
@@ -2254,7 +2257,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)struct queue_limits *ns_lim = &ns->disk->queue->limits;struct queue_limits lim; -blk_mq_freeze_queue (ns->head->disk->queue); +blk_mq_freeze_queue_wait (ns->head->disk->queue);/* * queue_limits mixes values that are the hardware limitations * for bio splitting with what is the device configuration.
@@ -2288,7 +2291,8 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)nvme_mpath_revalidate_paths (ns);blk_mq_unfreeze_queue (ns->head->disk->queue); - } + }else if (nvme_ns_head_multipath (ns->head)) +blk_mq_unfreeze_queue (ns->head->disk->queue);return ret; }
Signature · 1 line
2.35.3
Quoted 13 lines · Martin Wilck
For multipath devices,
nvme_update_ns_info()needs to freeze both the queue of the path and the queue of the multipath device. For both operations, it waits for one RCU grace period to pass, ~25ms on my test system. By callingblk_freeze_queue_start()for the multipath queue early, we avoid waiting twice; tests using ftrace have shown that the secondblk_mq_freeze_queue_wait()call finishes in just a few microseconds. The path queue is unfrozen before callingblk_mq_freeze_queue_wait()on the multipath queue, so that possibly outstanding IO in the multipath queue can be flushed.I tested this using the "controller rescan under I/O load" test I submitted recently [1].
Quoted 7 lines
[1] https://lore.kernel.org/linux-nvme/[email protected]/T/#u
Signed-off-by Martin Wilck <[email protected]>--- drivers/nvme/host/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Quoted 10 lines · Martin Wilck
For multipath devices,
nvme_update_ns_info()needs to freeze both the queue of the path and the queue of the multipath device. For both operations, it waits for one RCU grace period to pass, ~25ms on my test system. By callingblk_freeze_queue_start()for the multipath queue early, we avoid waiting twice; tests using ftrace have shown that the secondblk_mq_freeze_queue_wait()call finishes in just a few microseconds. The path queue is unfrozen before callingblk_mq_freeze_queue_wait()on the multipath queue, so that possibly outstanding IO in the multipath queue can be flushed.
Quoted 6 lines
I tested this using the "controller rescan under I/O load" test I submitted recently [1].
[1] https://lore.kernel.org/linux-nvme/[email protected]/T/#u
Signed-off-by Martin Wilck <[email protected]>
Quoted 25 lines · Martin Wilck
For multipath devices,
nvme_update_ns_info()needs to freeze both the queue of the path and the queue of the multipath device. For both operations, it waits for one RCU grace period to pass, ~25ms on my test system. By callingblk_freeze_queue_start()for the multipath queue early, we avoid waiting twice; tests using ftrace have shown that the secondblk_mq_freeze_queue_wait()call finishes in just a few microseconds. The path queue is unfrozen before callingblk_mq_freeze_queue_wait()on the multipath queue, so that possibly outstanding IO in the multipath queue can be flushed.I tested this using the "controller rescan under I/O load" test I submitted recently [1].
[1] https://lore.kernel.org/linux-nvme/[email protected]/T/#u
Signed-off-by Martin Wilck <[email protected]>--- drivers/nvme/host/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/nvme/host/core.c +0
-0
drivers/nvme/host/core.c static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info) · line 2222
Quoted 6 lines
drivers/nvme/host/core.c +3
-0@@ -2217,6 +2217,9 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)bool unsupported = false;int ret; +if (nvme_ns_head_multipath (ns->head)) +blk_freeze_queue_start (ns->head->disk->queue); +
From someone reading this code, it looks quite similar to nvme_mpath_start_freeze().
Perhaps create a new helper, with proper kdoc, and possibly also add kdoc to nvme_mpath_start_freeze(), so that a user can easily tell (from the kdoc) when to use which function.
Kind regards,
Niklas
Quoted 22 lines · Niklas Cassel
Quoted 21 lines · Martin Wilck
For multipath devices,
nvme_update_ns_info()needs to freeze both the queue of the path and the queue of the multipath device. For both operations, it waits for one RCU grace period to pass, ~25ms on my test system. By callingblk_freeze_queue_start()for the multipath queue early, we avoid waiting twice; tests using ftrace have shown that the secondblk_mq_freeze_queue_wait()call finishes in just a few microseconds. The path queue is unfrozen before callingblk_mq_freeze_queue_wait()on the multipath queue, so that possibly outstanding IO in the multipath queue can be flushed.I tested this using the "controller rescan under I/O load" test I submitted recently [1].
[1]
https://lore.kernel.org/linux-nvme/[email protected]/T/#uSigned-off-by Martin Wilck <[email protected]>---
drivers/nvme/host/core.c | 8 ++++++--1 file changed, 6 insertions(+), 2 deletions(-)
Quoted 15 lines
drivers/nvme/host/core.c static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info) · line 2222
Quoted 12 lines
drivers/nvme/host/core.c +0
-0@@ -2217,6 +2217,9 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info) bool unsupported = false; int ret;drivers/nvme/host/core.c +3
-0+if (nvme_ns_head_multipath (ns->head)) +blk_freeze_queue_start (ns->head->disk->queue); +From someone reading this code, it looks quite similar to
nvme_mpath_start_freeze().
That function takes a struct nvme_subsystem as argument, and walks over all namespaces in that subsystem, whereas here we're just acting on a single namespace.
Quoted 5 lines
Perhaps create a new helper, with proper kdoc, and possibly also add kdoc to
nvme_mpath_start_freeze(), so that a user can easily tell (from the kdoc)
when to use which function.
What's the benefit of introducing such a trivial helper, used only in a single place of the code?
Thanks for the suggestion, but I'd like to see other maintainers' opinions about this.
Thanks,
Martin
Quoted 43 lines · Martin Wilck
Quoted 22 lines · Niklas Cassel
Quoted 21 lines · Martin Wilck
For multipath devices,
nvme_update_ns_info()needs to freeze both the queue of the path and the queue of the multipath device. For both operations, it waits for one RCU grace period to pass, ~25ms on my test system. By callingblk_freeze_queue_start()for the multipath queue early, we avoid waiting twice; tests using ftrace have shown that the secondblk_mq_freeze_queue_wait()call finishes in just a few microseconds. The path queue is unfrozen before callingblk_mq_freeze_queue_wait()on the multipath queue, so that possibly outstanding IO in the multipath queue can be flushed.I tested this using the "controller rescan under I/O load" test I submitted recently [1].
[1]
https://lore.kernel.org/linux-nvme/[email protected]/T/#uSigned-off-by Martin Wilck <[email protected]>---
drivers/nvme/host/core.c | 8 ++++++--1 file changed, 6 insertions(+), 2 deletions(-)Quoted 15 lines
drivers/nvme/host/core.c static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info) · line 2222
Quoted 12 lines
drivers/nvme/host/core.c +0
-0@@ -2217,6 +2217,9 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info) bool unsupported = false; int ret;drivers/nvme/host/core.c +3
-0+if (nvme_ns_head_multipath (ns->head)) +blk_freeze_queue_start (ns->head->disk->queue); +From someone reading this code, it looks quite similar to
nvme_mpath_start_freeze().That function takes a struct
nvme_subsystemas argument, and walks over all namespaces in that subsystem, whereas here we're just acting on a single namespace.
Quoted 8 lines
Quoted 5 lines
Perhaps create a new helper, with proper kdoc, and possibly also add kdoc to
nvme_mpath_start_freeze(), so that a user can easily tell (from the kdoc)
when to use which function.What's the benefit of introducing such a trivial helper, used only in a single place of the code?
To make nvme_update_ns_info() easier to read, and to keep the existing code style of calling nvme_mpath_*() functions unconditionally.
Sure, with my suggestion you would need a mpath_freeze() and mpath_unfreeze() helper.
But if you add a helper that simply does:
if (nvme_ns_head_multipath(ns->head))
blk_freeze_queue_start(ns->head->disk->queue);
nvme_update_ns_info() could call the helper unconditionally, just like how e.g. nvme_passthru_start() calls nvme_mpath_start_freeze() unconditionally for both multipath and non-multipath NS heads:
https://github.com/torvalds/linux/blob/v6.11-rc4/drivers/nvme/host/core.c#L1205
(And how core.c calls many other nvme_mpath_*() functions unconditionally.)
Quoted 2 lines
Thanks for the suggestion, but I'd like to see other maintainers' opinions about this.
Of course, a suggestion is just a suggestion :)
Kind regards,
Niklas
Sagi Grimberg
maintainerThe patch title should explain what it is fixing, i.e. the reason of its existence. Perhaps something like:
nvme: shorten multipath ns update duration
Quoted 25 lines · Martin Wilck
For multipath devices,
nvme_update_ns_info()needs to freeze both the queue of the path and the queue of the multipath device. For both operations, it waits for one RCU grace period to pass, ~25ms on my test system. By callingblk_freeze_queue_start()for the multipath queue early, we avoid waiting twice; tests using ftrace have shown that the secondblk_mq_freeze_queue_wait()call finishes in just a few microseconds. The path queue is unfrozen before callingblk_mq_freeze_queue_wait()on the multipath queue, so that possibly outstanding IO in the multipath queue can be flushed.I tested this using the "controller rescan under I/O load" test I submitted recently [1].
[1] https://lore.kernel.org/linux-nvme/[email protected]/T/#u
Signed-off-by Martin Wilck <[email protected]>--- drivers/nvme/host/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/nvme/host/core.c +0
-0
drivers/nvme/host/core.c static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info) · line 2221
Quoted 5 lines
drivers/nvme/host/core.c +2
-0@@ -2217,6 +2217,9 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)bool unsupported = false;int ret; +if (nvme_ns_head_multipath (ns->head)) +blk_freeze_queue_start (ns->head->disk->queue);
Lets add a small comment here.
Quoted 14 lines
drivers/nvme/host/core.c +2
-1+switch (info->ids.csi) {case NVME_CSI_ZNS :if (!IS_ENABLED (CONFIG_BLK_DEV_ZONED )) {@@ -2254,7 +2257,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)struct queue_limits *ns_lim = &ns->disk->queue->limits;struct queue_limits lim; -blk_mq_freeze_queue (ns->head->disk->queue); +blk_mq_freeze_queue_wait (ns->head->disk->queue);/* * queue_limits mixes values that are the hardware limitations * for bio splitting with what is the device configuration.
drivers/nvme/host/core.c static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info) · line 2295
Quoted 6 lines
drivers/nvme/host/core.c +2
-1@@ -2288,7 +2291,8 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)nvme_mpath_revalidate_paths (ns);blk_mq_unfreeze_queue (ns->head->disk->queue); - } + }else if (nvme_ns_head_multipath (ns->head)) +blk_mq_unfreeze_queue (ns->head->disk->queue);
Right now if ret!=0 you are unfreezing without waiting, you need to wait for the freeze to complete before unfreezing.
You should restructure the code to make it so that the freeze_start, freeze_wait, unfreeze are paired regardless of the code flows.