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 A75B8C04FFE for ; Tue, 14 May 2024 17:53:45 +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: Content-type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wBO927D575iuHOlHVpwJTixenliXhHTxZ0CblZ6Nq8M=; b=sdVB0HYm0cLUu4yTOPx4bIc+L/ UVkRImj5jAYrbHDYg2sja3MRulo8DHz6I6nRWrL9RKmKSIz2MQzBV55/07O6A4O00+KNQmJKFlDBF 08KULRznvqEgEh07MbTygzLKx0xsCZsaSrrYA9YVsJ6G9lj4mGvb9BDRRO60JHbEWonMLJj2vE1AB kx/lce2PUopxaPhQxzrSCkYrqJBNxw1ugWTJ98ltr3mdmdkLfouTmOZ4+wGkDK4tL58btRm5lE0NV HUYCmYHU8VMzYXSMQwH9sbwBQbVI6rEuOI9wB4Qdk6MK6m1s9I5nHzLdBi+OAhcCVaT6TiCUqiKiN vSIPvQfw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s6wLR-0000000GjA0-0sUg; Tue, 14 May 2024 17:53:45 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s6wLM-0000000Gj6P-3rc6 for linux-nvme@lists.infradead.org; Tue, 14 May 2024 17:53:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715709220; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wBO927D575iuHOlHVpwJTixenliXhHTxZ0CblZ6Nq8M=; b=CI3zTJOKZOfqwzWAWkrijm5W7UmWEHUNX3A/EMQeLqPLz1dHRWlu/m+vZqBBLroda8l91J ad6a5xe6YqUDY2NWVXrfUYvOCszC5adfxJ8Ul3OAq8CWbKTOnqxokAmQeItNeGoITozd/a 8jhpGY9mBfogxPcFoEUTZfH1N7ryiBI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-498-ZMwMrSutM7uMeoQSpaA88g-1; Tue, 14 May 2024 13:53:35 -0400 X-MC-Unique: ZMwMrSutM7uMeoQSpaA88g-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 872A68016FA; Tue, 14 May 2024 17:53:34 +0000 (UTC) Received: from jmeneghi.bos.com (unknown [10.2.17.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67CCB400F13; Tue, 14 May 2024 17:53:33 +0000 (UTC) From: John Meneghini To: tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, emilne@redhat.com, hare@kernel.org Cc: linux-block@vger.kernel.org, cgroups@vger.kernel.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, jmeneghi@redhat.com, jrani@purestorage.com, randyj@purestorage.com Subject: [PATCH v4 5/6] nvme: add 'latency' iopolicy Date: Tue, 14 May 2024 13:53:21 -0400 Message-Id: <20240514175322.19073-6-jmeneghi@redhat.com> In-Reply-To: <20240514175322.19073-1-jmeneghi@redhat.com> References: <20240514175322.19073-1-jmeneghi@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240514_105341_101867_9218280C X-CRM114-Status: GOOD ( 19.06 ) 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 [jmeneghi: fix CONFIG_BLK_NODE_LATENCY n and add latency iopolicy to modinfo] Signed-off-by: John Meneghini --- drivers/nvme/host/multipath.c | 62 ++++++++++++++++++++++++++++++----- drivers/nvme/host/nvme.h | 1 + 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index 8702a40a1971..e9330bb1990b 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -18,6 +18,7 @@ static const char *nvme_iopolicy_names[] = { [NVME_IOPOLICY_NUMA] = "numa", [NVME_IOPOLICY_RR] = "round-robin", [NVME_IOPOLICY_QD] = "queue-depth", + [NVME_IOPOLICY_LAT] = "latency", }; static int iopolicy = NVME_IOPOLICY_NUMA; @@ -32,6 +33,10 @@ static int nvme_set_iopolicy(const char *val, const struct kernel_param *kp) iopolicy = NVME_IOPOLICY_RR; else if (!strncmp(val, "queue-depth", 11)) iopolicy = NVME_IOPOLICY_QD; +#ifdef CONFIG_BLK_NODE_LATENCY + else if (!strncmp(val, "latency", 7)) + iopolicy = NVME_IOPOLICY_LAT; +#endif else return -EINVAL; @@ -43,10 +48,36 @@ static int nvme_get_iopolicy(char *buf, const struct kernel_param *kp) return sprintf(buf, "%s\n", nvme_iopolicy_names[iopolicy]); } +static int nvme_activate_iopolicy(struct nvme_subsystem *subsys, int iopolicy) +{ + struct nvme_ns_head *h; + struct nvme_ns *ns; + bool enable = iopolicy == NVME_IOPOLICY_LAT; + int ret = 0; + + mutex_lock(&subsys->lock); + list_for_each_entry(h, &subsys->nsheads, entry) { + list_for_each_entry_rcu(ns, &h->list, siblings) { + if (enable) { + ret = blk_nlat_enable(ns->disk); + if (ret) + break; + } else + blk_nlat_disable(ns->disk); + } + } + mutex_unlock(&subsys->lock); + return ret; +} + module_param_call(iopolicy, nvme_set_iopolicy, nvme_get_iopolicy, &iopolicy, 0644); MODULE_PARM_DESC(iopolicy, +#if defined(CONFIG_BLK_NODE_LATENCY) + "Default multipath I/O policy; 'numa' (default) , 'round-robin', 'queue-depth' or 'latency'"); +#else "Default multipath I/O policy; 'numa' (default) , 'round-robin' or 'queue-depth'"); +#endif void nvme_mpath_default_iopolicy(struct nvme_subsystem *subsys) { @@ -250,13 +281,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_nlat_latency(ns->disk, node); else distance = LOCAL_DISTANCE; @@ -380,8 +414,8 @@ static inline bool nvme_path_is_optimized(struct nvme_ns *ns) inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head) { - int iopolicy = READ_ONCE(head->subsys->iopolicy); int node; + int iopolicy = READ_ONCE(head->subsys->iopolicy); struct nvme_ns *ns; /* @@ -400,8 +434,8 @@ inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head) 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; } @@ -871,15 +905,18 @@ static ssize_t nvme_subsys_iopolicy_store(struct device *dev, { struct nvme_subsystem *subsys = container_of(dev, struct nvme_subsystem, dev); - int i; + int i, ret; for (i = 0; i < ARRAY_SIZE(nvme_iopolicy_names); i++) { if (sysfs_streq(buf, nvme_iopolicy_names[i])) { - nvme_subsys_iopolicy_update(subsys, i); - return count; + ret = nvme_activate_iopolicy(subsys, i); + if (!ret) { + nvme_subsys_iopolicy_update(subsys, i); + return count; + } + return ret; } } - return -EINVAL; } SUBSYS_ATTR_RW(iopolicy, S_IRUGO | S_IWUSR, @@ -915,6 +952,15 @@ static int nvme_lookup_ana_group_desc(struct nvme_ctrl *ctrl, void nvme_mpath_add_disk(struct nvme_ns *ns, __le32 anagrpid) { + if (!blk_nlat_init(ns->disk) && + READ_ONCE(ns->head->subsys->iopolicy) == NVME_IOPOLICY_LAT) { + int ret = blk_nlat_enable(ns->disk); + + if (unlikely(ret)) + pr_warn("%s: Failed to enable latency tracking, error %d\n", + ns->disk->disk_name, ret); + } + 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 4e876524726a..56b78f21406a 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -406,6 +406,7 @@ enum nvme_iopolicy { NVME_IOPOLICY_NUMA, NVME_IOPOLICY_RR, NVME_IOPOLICY_QD, + NVME_IOPOLICY_LAT, }; struct nvme_subsystem { -- 2.39.3