From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 60612CD1283 for ; Tue, 26 Mar 2024 15:37:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dIgih3xwbfXL3v7JhMlV0ItI7HRjKT5Ka3nUvCNYarc=; b=z7u0AdZguhhe4XEHlO6LZdCtSa LBdvJEc8KbJfA2FEoNtRi/7ChKSKXWFfLdm9ZHDTjSqFH0VSyO/112TGYAgQmqrDbMWhORbRI0tD7 kPSXPr7H74TjpmtvL2CQlW+2irjG9MHg/vycbwuDEDZtjQ5HjgPBU0ucPWUkkIAc/7+zxiW1k+eRl Y0jxPZ9Qb1qy6BvuOF0v10MxaYR9+qGPGF5RqNCkKlwFibYUEoPJSlOD9OXWLrLa4Vch9wF9HeL8M s6uUYmV5Mfqf3tLZhNMpqzbztLWQ9agVVmAyqFLyG0lzU1gCvWSktxmNs0VDeHwEcACstOo2cEsbb hAjwezeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rp8rp-00000005Dxm-2lpg; Tue, 26 Mar 2024 15:37:37 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rp8q8-00000005D3A-09kG for linux-nvme@lists.infradead.org; Tue, 26 Mar 2024 15:35:58 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id C5E90CE1B28; Tue, 26 Mar 2024 15:35:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1047C433A6; Tue, 26 Mar 2024 15:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711467349; bh=Kv3YRl9LzbqPnD2/oDibTM2oci8Eutg/qoRbtzgs828=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZsJrxt9i2hYTM70fk9u7DQLbMHqTRZZSu8c2ZaI5y/5Rb9se05rzO76XQ8eYkjiO7 VGU0j0KHCq27NO36QiLDYX5FkuwC2oiDZtS+sB3YeoaGrBSq63e9oAY7GDvohmEJRm 4KT4m86fF5OEztFbueLf3Z/wymNLzvUFqaowU4LUnRyQ/WXGXCOWU6LGe0bydQerNu OINXv+hdOrtUCbAy5dWgADmfrAc4mlcI76/fu/K8F8nSyQQxAHE2HSEJ9jvT8uK6kY yzRe2P63UgQ0mAs4I4IZT4hFRC61g+kQuWXa+8HG3UiJiv5WvEd64qFKxcInEYVCvk kZWb8+UDis7uw== From: Hannes Reinecke To: Jens Axboe Cc: Keith Busch , Christoph Hellwig , Sagi Grimberg , linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, Hannes Reinecke Subject: [PATCH 2/2] nvme: add 'latency' iopolicy Date: Tue, 26 Mar 2024 16:35:29 +0100 Message-Id: <20240326153529.75989-3-hare@kernel.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240326153529.75989-1-hare@kernel.org> References: <20240326153529.75989-1-hare@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240326_083552_841434_02095BDC X-CRM114-Status: GOOD ( 18.42 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org From: Hannes Reinecke Add a latency-based I/O policy for multipathing. It uses the blk-nodelat latency tracker to provide latencies for each node, and schedules I/O on the path with the least latency for the submitting node. Signed-off-by: Hannes Reinecke --- drivers/nvme/host/multipath.c | 46 ++++++++++++++++++++++++++++++++--- drivers/nvme/host/nvme.h | 2 ++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index 5397fb428b24..fd3bda6f8543 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -17,6 +17,7 @@ MODULE_PARM_DESC(multipath, static const char *nvme_iopolicy_names[] = { [NVME_IOPOLICY_NUMA] = "numa", [NVME_IOPOLICY_RR] = "round-robin", + [NVME_IOPOLICY_LAT] = "latency", }; static int iopolicy = NVME_IOPOLICY_NUMA; @@ -29,6 +30,10 @@ static int nvme_set_iopolicy(const char *val, const struct kernel_param *kp) iopolicy = NVME_IOPOLICY_NUMA; else if (!strncmp(val, "round-robin", 11)) iopolicy = NVME_IOPOLICY_RR; +#ifdef CONFIG_BLK_NODE_LATENCY + else if (!strncmp(val, "latency", 7)) + iopolicy = NVME_IOPOLICY_LAT; +#endif else return -EINVAL; @@ -40,6 +45,26 @@ static int nvme_get_iopolicy(char *buf, const struct kernel_param *kp) return sprintf(buf, "%s\n", nvme_iopolicy_names[iopolicy]); } +static void nvme_activate_iopolicy(struct nvme_subsystem *subsys, int iopolicy) +{ + struct nvme_ns_head *h; + struct nvme_ns *ns; + bool enable = iopolicy == NVME_IOPOLICY_LAT; + + mutex_lock(&subsys->lock); + list_for_each_entry(h, &subsys->nsheads, entry) { + list_for_each_entry_rcu(ns, &h->list, siblings) { + if (!test_bit(NVME_NS_NLAT, &ns->flags)) + continue; + if (enable) + blk_nodelat_enable(ns->queue); + else + blk_nodelat_disable(ns->queue); + } + } + mutex_unlock(&subsys->lock); +} + module_param_call(iopolicy, nvme_set_iopolicy, nvme_get_iopolicy, &iopolicy, 0644); MODULE_PARM_DESC(iopolicy, @@ -242,13 +267,16 @@ static struct nvme_ns *__nvme_find_path(struct nvme_ns_head *head, int node) { int found_distance = INT_MAX, fallback_distance = INT_MAX, distance; struct nvme_ns *found = NULL, *fallback = NULL, *ns; + int iopolicy = READ_ONCE(head->subsys->iopolicy); list_for_each_entry_rcu(ns, &head->list, siblings) { if (nvme_path_is_disabled(ns)) continue; - if (READ_ONCE(head->subsys->iopolicy) == NVME_IOPOLICY_NUMA) + if (iopolicy == NVME_IOPOLICY_NUMA) distance = node_distance(node, ns->ctrl->numa_node); + else if (iopolicy == NVME_IOPOLICY_LAT) + distance = blk_nodelat_latency(ns->queue, node); else distance = LOCAL_DISTANCE; @@ -339,15 +367,17 @@ static inline bool nvme_path_is_optimized(struct nvme_ns *ns) inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head) { int node = numa_node_id(); + int iopolicy = READ_ONCE(head->subsys->iopolicy); struct nvme_ns *ns; 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) + if (iopolicy == NVME_IOPOLICY_RR) return nvme_round_robin_path(head, node, ns); - if (unlikely(!nvme_path_is_optimized(ns))) + if (iopolicy == NVME_IOPOLICY_LAT || + unlikely(!nvme_path_is_optimized(ns))) return __nvme_find_path(head, node); return ns; } @@ -808,10 +838,10 @@ static ssize_t nvme_subsys_iopolicy_store(struct device *dev, for (i = 0; i < ARRAY_SIZE(nvme_iopolicy_names); i++) { if (sysfs_streq(buf, nvme_iopolicy_names[i])) { WRITE_ONCE(subsys->iopolicy, i); + nvme_activate_iopolicy(subsys, i); return count; } } - return -EINVAL; } SUBSYS_ATTR_RW(iopolicy, S_IRUGO | S_IWUSR, @@ -847,6 +877,14 @@ static int nvme_lookup_ana_group_desc(struct nvme_ctrl *ctrl, void nvme_mpath_add_disk(struct nvme_ns *ns, __le32 anagrpid) { + if (!blk_nodelat_init(ns->disk)) { + int iopolicy = READ_ONCE(ns->head->subsys->iopolicy); + + set_bit(NVME_NS_NLAT, &ns->flags); + if (iopolicy == NVME_IOPOLICY_LAT) + blk_nodelat_enable(ns->queue); + } + if (nvme_ctrl_use_ana(ns->ctrl)) { struct nvme_ana_group_desc desc = { .grpid = anagrpid, diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 27397f8404d6..83c3870d5ed0 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -402,6 +402,7 @@ static inline enum nvme_ctrl_state nvme_ctrl_state(struct nvme_ctrl *ctrl) enum nvme_iopolicy { NVME_IOPOLICY_NUMA, NVME_IOPOLICY_RR, + NVME_IOPOLICY_LAT, }; struct nvme_subsystem { @@ -519,6 +520,7 @@ struct nvme_ns { #define NVME_NS_ANA_PENDING 2 #define NVME_NS_FORCE_RO 3 #define NVME_NS_READY 4 +#define NVME_NS_NLAT 5 struct cdev cdev; struct device cdev_device; -- 2.35.3