[PATCH v8 1/2] nvme-multipath: prepare for "queue-depth" iopolicy

John Meneghini posted 2 patches 1 year, 5 months ago
[PATCH v8 1/2] nvme-multipath: prepare for "queue-depth" iopolicy
Posted by John Meneghini 1 year, 5 months ago
This patch prepares for the introduction of a new iopolicy by breaking up
the nvme_find_path() code path into sub-routines.

Signed-off-by: John Meneghini <jmeneghi@redhat.com>
---
 drivers/nvme/host/multipath.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 8a4d0e377114..0ade378e514b 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -291,10 +291,14 @@ static struct nvme_ns *nvme_next_ns(struct nvme_ns_head *head,
 	return list_first_or_null_rcu(&head->list, struct nvme_ns, siblings);
 }
 
-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;
+	int node = numa_node_id();
+	struct nvme_ns *old = srcu_dereference(head->current_path[node], &head->srcu);
+
+	if (unlikely(!old))
+		return __nvme_find_path(head, node);
 
 	if (list_is_singular(&head->list)) {
 		if (nvme_path_is_disabled(old))
@@ -340,7 +344,7 @@ static inline bool nvme_path_is_optimized(struct nvme_ns *ns)
 		ns->ana_state == NVME_ANA_OPTIMIZED;
 }
 
-inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head)
+static struct nvme_ns *nvme_numa_path(struct nvme_ns_head *head)
 {
 	int node = numa_node_id();
 	struct nvme_ns *ns;
@@ -348,14 +352,19 @@ inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head)
 	ns = srcu_dereference(head->current_path[node], &head->srcu);
 	if (unlikely(!ns))
 		return __nvme_find_path(head, node);
-
-	if (READ_ONCE(head->subsys->iopolicy) == NVME_IOPOLICY_RR)
-		return nvme_round_robin_path(head, node, ns);
 	if (unlikely(!nvme_path_is_optimized(ns)))
 		return __nvme_find_path(head, node);
 	return ns;
 }
 
+inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head)
+{
+	if (READ_ONCE(head->subsys->iopolicy) == NVME_IOPOLICY_RR)
+		return nvme_round_robin_path(head);
+	else
+		return nvme_numa_path(head);
+}
+
 static bool nvme_available_path(struct nvme_ns_head *head)
 {
 	struct nvme_ns *ns;
-- 
2.45.2
Re: [PATCH v8 1/2] nvme-multipath: prepare for "queue-depth" iopolicy
Posted by Sagi Grimberg 1 year, 5 months ago
other than the comment from hch,

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Re: [PATCH v8 1/2] nvme-multipath: prepare for "queue-depth" iopolicy
Posted by Chaitanya Kulkarni 1 year, 5 months ago
On 6/25/24 05:26, John Meneghini wrote:
> This patch prepares for the introduction of a new iopolicy by breaking up
> the nvme_find_path() code path into sub-routines.
>
> Signed-off-by: John Meneghini <jmeneghi@redhat.com>
> ---
>   drivers/nvme/host/multipath.c | 21 +++++++++++++++------
>   1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index 8a4d0e377114..0ade378e514b 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -291,10 +291,14 @@ static struct nvme_ns *nvme_next_ns(struct nvme_ns_head *head,
>   	return list_first_or_null_rcu(&head->list, struct nvme_ns, siblings);
>   }
>   
> -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;
> +	int node = numa_node_id();
> +	struct nvme_ns *old = srcu_dereference(head->current_path[node], &head->srcu);
> +
> +	if (unlikely(!old))
> +		return __nvme_find_path(head, node);

nit:- above looks little bit odd with long line, I'd just :-

         struct nvme_ns *old;

         old = srcu_dereference(head->current_path[node], &head->srcu);
         if (unlikely(!old))
                 return __nvme_find_path(head, node);


>   
>   	if (list_is_singular(&head->list)) {
>   		if (nvme_path_is_disabled(old))
> @@ -340,7 +344,7 @@ static inline bool nvme_path_is_optimized(struct nvme_ns *ns)
>   		ns->ana_state == NVME_ANA_OPTIMIZED;
>   }
>   
> -inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head)
> +static struct nvme_ns *nvme_numa_path(struct nvme_ns_head *head)
>   {
>   	int node = numa_node_id();
>   	struct nvme_ns *ns;
> @@ -348,14 +352,19 @@ inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head)
>   	ns = srcu_dereference(head->current_path[node], &head->srcu);
>   	if (unlikely(!ns))
>   		return __nvme_find_path(head, node);
> -
> -	if (READ_ONCE(head->subsys->iopolicy) == NVME_IOPOLICY_RR)
> -		return nvme_round_robin_path(head, node, ns);
>   	if (unlikely(!nvme_path_is_optimized(ns)))
>   		return __nvme_find_path(head, node);
>   	return ns;
>   }
>   
> +inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head)
> +{
> +	if (READ_ONCE(head->subsys->iopolicy) == NVME_IOPOLICY_RR)
> +		return nvme_round_robin_path(head);
> +	else
> +		return nvme_numa_path(head);

nit: - else is not needed ...

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck


Re: [PATCH v8 1/2] nvme-multipath: prepare for "queue-depth" iopolicy
Posted by Christoph Hellwig 1 year, 5 months ago
On Tue, Jun 25, 2024 at 08:26:04AM -0400, John Meneghini wrote:
> +	struct nvme_ns *old = srcu_dereference(head->current_path[node], &head->srcu);

Please avoid the overly long line here.

> +inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head)
> +{
> +	if (READ_ONCE(head->subsys->iopolicy) == NVME_IOPOLICY_RR)
> +		return nvme_round_robin_path(head);
> +	else
> +		return nvme_numa_path(head);

No need for an else after a return.