Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp837506rdb; Wed, 6 Dec 2023 01:00:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFo9tY4fPN7tnCWTSosl3LHeOJkDmqo0NaToS6ipNEXZPtaOgjrNDVPsif1Dd2E+/unmL9x X-Received: by 2002:a05:6a00:1590:b0:6ce:2731:5f6d with SMTP id u16-20020a056a00159000b006ce27315f6dmr382365pfk.44.1701853250662; Wed, 06 Dec 2023 01:00:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701853250; cv=none; d=google.com; s=arc-20160816; b=Uz5eHiYpQIAShroMiFRa2M9XiJRY6bwTAgZfxSCBEvn0SPv1jdUh2850xwr9ELMvIl cX6IEPjshBwFKA5GD4TtAGccFZ3fOb8FOVVMHLVnh4i5RACIBSHSf+TR8Xsf0SujAe6e nE3KTEr19aIuDnoSboa0NgQ61lNiAFcHra8RdasJa3ldwUPydE2HwtrzA3m0dBu1qj8U wQn06Syo57psaxko7fLfuMarrPIETGfQ4KWYylW5ah2Pf1l8JMaW+dNFSYvG2VpsMhgR uZ/U0Cyqnr09Q9WLKJpEb0OzB4Hq7EjDW/ParCmFsjUasyJ4vZnqqfvdkuiqI0T6Fe9/ cA5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=D4LjJiQvQrEw8ixJLoVbOh7Vk+psYJgH0ZFhL2p51xM=; fh=JWieladFfeaIwBj69e66MtYgIw576fUcTLVAEUXiV9w=; b=UuGKmlaYeeOb/Q0e5UnZK//kB6JLNshKZGsv7MeyfUkhcJaYZZYcUWkjRQ/hTx/7DK lgYAe3pGzh8W4vPkaOV1wo9l6m7vE/1yT7QU/oBX6HO8IXE69IayOFAmb9Ed74/o5n/5 aO8rX8HpGgCOfV5qTMGs/6E9hCVqvGU00YyiJI51Nu+vTkPme5itndexPZK+J7kLu8s0 vZpnwk6xavZIQIvgmFLELRE+GFH8ORHll+ZWBzk/x6/mvRiqh3aLCWl+NbAxMgDZ8qo0 FcMhCtuSrName/ajdYc51bkqiineDyNVtMe+EhizQGGyX7auJUxAzzYmePICnA4GvABG BY3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id fb41-20020a056a002da900b0068a3cb58334si11145852pfb.320.2023.12.06.01.00.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 01:00:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id AE7EA8044437; Wed, 6 Dec 2023 01:00:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376870AbjLFI7u (ORCPT + 99 others); Wed, 6 Dec 2023 03:59:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjLFI7t (ORCPT ); Wed, 6 Dec 2023 03:59:49 -0500 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A0A91736 for ; Wed, 6 Dec 2023 00:59:49 -0800 (PST) Received: by verein.lst.de (Postfix, from userid 2407) id 161D4227A8E; Wed, 6 Dec 2023 09:59:46 +0100 (CET) Date: Wed, 6 Dec 2023 09:59:45 +0100 From: Christoph Hellwig To: Daniel Wagner Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke Subject: Re: [PATCH v3 4/4] nvme: add csi, ms and nuse to sysfs Message-ID: <20231206085945.GC24484@lst.de> References: <20231206081244.32733-1-dwagner@suse.de> <20231206081244.32733-5-dwagner@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231206081244.32733-5-dwagner@suse.de> User-Agent: Mutt/1.5.17 (2007-11-01) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 06 Dec 2023 01:00:07 -0800 (PST) On Wed, Dec 06, 2023 at 09:12:44AM +0100, Daniel Wagner wrote: > libnvme is using the sysfs for enumarating the nvme resources. Though > there are few missing attritbutes in the sysfs. For these libnvme issues > commands during discovering. > > As the kernel already knows all these attributes and we would like to > avoid libnvme to issue commands all the time, expose these missing > attributes. > > The nuse value is updated on request because the nuse is a volatile > value. Since any user can read the sysfs attribute, a very simple rate > limit is added (update max every 5 seconds). A more sophisticated update > strategy can be added later if there is actually a need for it. > > Signed-off-by: Daniel Wagner > --- > drivers/nvme/host/core.c | 28 ++++++++++++++++++++++++++++ > drivers/nvme/host/nvme.h | 2 ++ > drivers/nvme/host/sysfs.c | 31 +++++++++++++++++++++++++++++++ > 3 files changed, 61 insertions(+) > > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c > index caa52c2f57c8..e7dd64ee1653 100644 > --- a/drivers/nvme/host/core.c > +++ b/drivers/nvme/host/core.c > @@ -1663,6 +1663,33 @@ static void nvme_ns_release(struct nvme_ns *ns) > nvme_put_ns(ns); > } > > +int nvme_ns_update_nuse(struct nvme_ns_head *head) > +{ > + static DEFINE_RATELIMIT_STATE(_rs, 5 * HZ, 1); > + struct nvme_id_ns *id; > + struct nvme_ns *ns; > + int srcu_idx, ret = -EWOULDBLOCK; > + > + if (__ratelimit(&_rs)) > + return 0; Can you add a comment on the ratelimiting here? > + > + srcu_idx = srcu_read_lock(&head->srcu); > + ns = nvme_find_path(head); > + if (!ns) > + goto out_unlock; > + > + ret = nvme_identify_ns(ns->ctrl, head->ns_id, &id); > + if (ret) > + goto out_unlock; > + > + head->nuse = le64_to_cpu(id->nuse); This looks like the wrong thing to do for the non-multipath nodes, which should be able to go straight to the ns. I'd move this to sysfs.c, and then do a similar trick to say nvme_send_pr_command to directly use the ns for the non-multipath nodes, and do what you're doing here for the multipath nodes. > static struct attribute *nvme_ns_id_attrs[] = { And I duess the _id is not correct now, I'd just drop it.