Skip to contentSkip to conversation

nvme: add 'iopolicy' module parameter

PATCH Superseded Hannes Reinecke 2 participants 2 messages Dec 20, 2021 NVMe

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 nvme: add 'iopolicy' module parameter

While the 'iopolicy' sysfs attribute can be set at runtime, most storage arrays prefer to use the 'round-robin' iopolicy per default. We can use udev rules to set this, but is getting rather unwieldy for rebranded arrays as we would have to update the udev rules anytime a new array shows up, leading to the same mess we currently have in multipathd for configuring the RDAC arrays.

Hence this patch adds a module parameter 'iopolicy' to allow the admin to switch the default, and to do away with the need for a udev rule here.

---
 drivers/nvme/host/core.c      |  4 +---
 drivers/nvme/host/multipath.c | 27 +++++++++++++++++++++++++++
 drivers/nvme/host/nvme.h      |  4 ++++
 3 files changed, 32 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +1 -3
index 44c375a1edbb..be404004c235 100644
@@ -2747,9 +2747,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
 		return -EINVAL;
 	}
 	subsys->awupf = le16_to_cpu(id->awupf);
-#ifdef CONFIG_NVME_MULTIPATH
-	subsys->iopolicy = NVME_IOPOLICY_NUMA;
-#endif
+	nvme_mpath_default_iopolicy(subsys);
 
 	subsys->dev.class = nvme_subsys_class;
 	subsys->dev.release = nvme_release_subsystem;
drivers/nvme/host/multipath.c +27 -0
index 7f2071f2460c..de98c0e05777 100644
@@ -13,6 +13,33 @@ module_param(multipath, bool, 0444);
 MODULE_PARM_DESC(multipath,
 	"turn on native support for multiple controllers per subsystem");
 
+static int iopolicy = NVME_IOPOLICY_NUMA;
+
+static int nvme_set_iopolicy(const char *val, const struct kernel_param *kp)
+{
+	char *endp;
+	int p;
+
+	if (!val)
+		return -EINVAL;
+	p = simple_strtoul(val, &endp, 0);
+	if (p != NVME_IOPOLICY_NUMA &&
+	    p != NVME_IOPOLICY_RR)
+		return -EINVAL;
+	iopolicy = p;
+	return 0;
+}
+
+module_param_call(iopolicy, nvme_set_iopolicy, param_get_int,
+		  &iopolicy, 0644);
+MODULE_PARM_DESC(iopolicy,
+	"Default multipath I/O policy; 0 - NUMA (default), 1 - Round-robin");
+
+void nvme_mpath_default_iopolicy(struct nvme_subsystem *subsys)
+{
+	subsys->iopolicy = iopolicy;
+}
+
 void nvme_mpath_unfreeze(struct nvme_subsystem *subsys)
 {
 	struct nvme_ns_head *h;
drivers/nvme/host/nvme.h +4 -0
index a54096ba0552..fe224016418e 100644
@@ -767,6 +767,7 @@ static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl)
 void nvme_mpath_unfreeze(struct nvme_subsystem *subsys);
 void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys);
 void nvme_mpath_start_freeze(struct nvme_subsystem *subsys);
+void nvme_mpath_default_iopolicy(struct nvme_subsystem *subsys);
 bool nvme_mpath_set_disk_name(struct nvme_ns *ns, char *disk_name, int *flags);
 void nvme_failover_req(struct request *req);
 void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl);
@@ -864,6 +865,9 @@ static inline void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys)
 static inline void nvme_mpath_start_freeze(struct nvme_subsystem *subsys)
 {
 }
+static inline void nvme_mpath_default_iopolicy(struct nvme_subsystem *subsys)
+{
+}
 #endif /* CONFIG_NVME_MULTIPATH */
 
 int nvme_revalidate_zones(struct nvme_ns *ns);
Signature · 1 line
2.29.2
maintainer
#1 lore raw
Quoted 54 lines · Hannes Reinecke

While the 'iopolicy' sysfs attribute can be set at runtime, most storage arrays prefer to use the 'round-robin' iopolicy per default. We can use udev rules to set this, but is getting rather unwieldy for rebranded arrays as we would have to update the udev rules anytime a new array shows up, leading to the same mess we currently have in multipathd for configuring the RDAC arrays.

Hence this patch adds a module parameter 'iopolicy' to allow the admin to switch the default, and to do away with the need for a udev rule here.

---
  drivers/nvme/host/core.c      |  4 +---
  drivers/nvme/host/multipath.c | 27 +++++++++++++++++++++++++++
  drivers/nvme/host/nvme.h      |  4 ++++
  3 files changed, 32 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +1 -3
index 44c375a1edbb..be404004c235 100644
@@ -2747,9 +2747,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
  		return -EINVAL;
  	}
  	subsys->awupf = le16_to_cpu(id->awupf);
-#ifdef CONFIG_NVME_MULTIPATH
-	subsys->iopolicy = NVME_IOPOLICY_NUMA;
-#endif
+	nvme_mpath_default_iopolicy(subsys);
 
  	subsys->dev.class = nvme_subsys_class;
  	subsys->dev.release = nvme_release_subsystem;
drivers/nvme/host/multipath.c +11 -0
index 7f2071f2460c..de98c0e05777 100644
@@ -13,6 +13,33 @@ module_param(multipath, bool, 0444);
  MODULE_PARM_DESC(multipath,
  	"turn on native support for multiple controllers per subsystem");
 
+static int iopolicy = NVME_IOPOLICY_NUMA;
+
+static int nvme_set_iopolicy(const char *val, const struct kernel_param *kp)
+{
+	char *endp;
+	int p;
+
+	if (!val)
+		return -EINVAL;
+	p = simple_strtoul(val, &endp, 0);
+	if (p != NVME_IOPOLICY_NUMA &&

drivers/nvme/host/multipath.c module_param(multipath, bool, 0444); · line 36

Quoted 10 lines
drivers/nvme/host/multipath.c +10 -0
+	    p != NVME_IOPOLICY_RR)
+		return -EINVAL;
+	iopolicy = p;
+	return 0;
+}
+
+module_param_call(iopolicy, nvme_set_iopolicy, param_get_int,
+		  &iopolicy, 0644);
+MODULE_PARM_DESC(iopolicy,
+	"Default multipath I/O policy; 0 - NUMA (default), 1 - Round-robin");

Maybe make this a string? user will set numa|round-robin ? That is the sysfs interface iirc...