Move the zero-depth check inside the optimized path case to enable early exit. It avoids redundant condition checks for non-optimized paths, and eliminates the per-iteration check at the end of the loop, improving the performance. Cc: Aviv Coro Cc: Bart Van Assche Cc: Benjamin Marzinski Cc: Brian Bunker Cc: Caleb Sander Cc: Chaitanya Kulkarni Cc: Chris Leech Cc: Christophe Varoqui Cc: Christoph Hellwig Cc: Clayton Skaggs Cc: Constantine Gavrilov Cc: Daniel Wagner Cc: David SantamarĂ­a Rogado Cc: Dmitry V. Levin Cc: Ewan D. Milne Cc: Ewan Milne Cc: Hannes Reinecke Cc: James Smart Cc: Jens Axboe Cc: John Meneghini Cc: Jyoti Rani Cc: Keith Busch Cc: Li Xiaokeng Cc: Marco Patalano Cc: Martin Belanger Cc: Martin George Cc: Martin Wilck Cc: Matthias Rudolph Cc: Maurizio Lombardi Cc: NetApp RDAC team Cc: Nilay Shroff Cc: Randy Jennings Cc: Sagi Grimberg Cc: Simon Schricker Cc: Steven Schremmer Cc: Thomas Song Cc: Uday Shankar Cc: Vasuki Manikarnike Cc: Wayne Berthiaume Cc: Zou Ming Cc: BLOCK-ML Cc: DM_DEVEL-ML Cc: NVME-ML Cc: SCSI-ML Signed-off-by: Xose Vazquez Perez --- Status: Compile-tested only. UNTESTED on real hardware. [I do not have access to this kind of hardware] Feedback and testing are highly welcome. --- drivers/nvme/host/multipath.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index 263161cb8ac0..7d212f6e865d 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -409,6 +409,8 @@ static struct nvme_ns *nvme_queue_depth_path(struct nvme_ns_head *head) min_depth_opt = depth; best_opt = ns; } + if (min_depth_opt == 0) + goto out; break; case NVME_ANA_NONOPTIMIZED: if (depth < min_depth_nonopt) { @@ -419,11 +421,8 @@ static struct nvme_ns *nvme_queue_depth_path(struct nvme_ns_head *head) default: break; } - - if (min_depth_opt == 0) - return best_opt; } - +out: return best_opt ? best_opt : best_nonopt; } -- 2.54.0