[RFC PATCHv4 5/6] nvme-multipath: add debugfs attribute adaptive_weight_timeout
Nilay Shroff
nilay at linux.ibm.com
Tue Nov 4 02:45:20 PST 2025
By default, the adaptive I/O policy accumulates latency samples over a
15-second window. When this window expires, the driver computes the
average latency and updates the smoothed (EWMA) latency value. The
path weight is then recalculated based on this data.
A 15-second window provides a good balance for most workloads, as it
helps smooth out transient latency spikes and produces a more stable
path weight profile. However, some workloads may benefit from faster
or slower adaptation to changing latency conditions.
This commit introduces a new debugfs attribute, adaptive_weight_timeout,
which allows users to configure the path weight calculation interval
based on their workload requirements.
Signed-off-by: Nilay Shroff <nilay at linux.ibm.com>
---
drivers/nvme/host/core.c | 1 +
drivers/nvme/host/debugfs.c | 40 ++++++++++++++++++++++++++++++++++-
drivers/nvme/host/multipath.c | 7 ++++--
drivers/nvme/host/nvme.h | 1 +
4 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 43b9b0d6cbdf..d3828c4812fc 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3915,6 +3915,7 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
head->rotational = info->is_rotational;
#ifdef CONFIG_NVME_MULTIPATH
head->adp_ewma_shift = NVME_DEFAULT_ADP_EWMA_SHIFT;
+ head->adp_weight_timeout = NVME_DEFAULT_ADP_WEIGHT_TIMEOUT;
#endif
ratelimit_state_init(&head->rs_nuse, 5 * HZ, 1);
ratelimit_set_flags(&head->rs_nuse, RATELIMIT_MSG_ON_RELEASE);
diff --git a/drivers/nvme/host/debugfs.c b/drivers/nvme/host/debugfs.c
index e3c37041e8f2..e382fa411b13 100644
--- a/drivers/nvme/host/debugfs.c
+++ b/drivers/nvme/host/debugfs.c
@@ -146,12 +146,50 @@ static ssize_t nvme_adp_ewma_shift_store(void *data, const char __user *ubuf,
WRITE_ONCE(head->adp_ewma_shift, res);
return count;
}
+
+static int nvme_adp_weight_timeout_show(void *data, struct seq_file *m)
+{
+ struct nvme_ns_head *head = data;
+
+ seq_printf(m, "%llu\n",
+ div_u64(READ_ONCE(head->adp_weight_timeout), NSEC_PER_SEC));
+ return 0;
+}
+
+static ssize_t nvme_adp_weight_timeout_store(void *data,
+ const char __user *ubuf,
+ size_t count, loff_t *ppos)
+{
+ struct nvme_ns_head *head = data;
+ char kbuf[8];
+ u32 res;
+ int ret;
+ size_t len;
+ char *arg;
+
+ len = min(sizeof(kbuf) - 1, count);
+
+ if (copy_from_user(kbuf, ubuf, len))
+ return -EFAULT;
+
+ kbuf[len] = '\0';
+ arg = strstrip(kbuf);
+
+ ret = kstrtou32(arg, 0, &res);
+ if (ret)
+ return ret;
+
+ WRITE_ONCE(head->adp_weight_timeout, res * NSEC_PER_SEC);
+ return count;
+}
#endif
static const struct nvme_debugfs_attr nvme_mpath_debugfs_attrs[] = {
#ifdef CONFIG_NVME_MULTIPATH
- {"adaptive_ewma_shift", 0600, nvme_adp_ewma_shift_show,
+ {"adaptive_ewma_shift", 0600, nvme_adp_ewma_shift_show,
nvme_adp_ewma_shift_store},
+ {"adaptive_weight_timeout", 0600, nvme_adp_weight_timeout_show,
+ nvme_adp_weight_timeout_store},
#endif
{},
};
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index c7470cc8844e..e70a7d5cf036 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -362,8 +362,11 @@ static void nvme_mpath_add_sample(struct request *rq, struct nvme_ns *ns)
stat->batch_count++;
stat->nr_samples++;
- if (now > stat->last_weight_ts &&
- (now - stat->last_weight_ts) >= NVME_DEFAULT_ADP_WEIGHT_TIMEOUT) {
+ if (now > stat->last_weight_ts) {
+ u64 timeout = READ_ONCE(head->adp_weight_timeout);
+
+ if ((now - stat->last_weight_ts) < timeout)
+ return;
stat->last_weight_ts = now;
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 97de45634f08..53d868cccbeb 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -546,6 +546,7 @@ struct nvme_ns_head {
struct nvme_ns * __percpu *adp_path;
u32 adp_ewma_shift;
+ u64 adp_weight_timeout;
#define NVME_NSHEAD_DISK_LIVE 0
#define NVME_NSHEAD_QUEUE_IF_NO_PATH 1
--
2.51.0
More information about the Linux-nvme
mailing list