From patchwork Thu Dec 21 13:23:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13501922 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A110C35274 for ; Thu, 21 Dec 2023 13:24:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A3278D0016; Thu, 21 Dec 2023 08:24:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 953AE8D0014; Thu, 21 Dec 2023 08:24:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CC958D0016; Thu, 21 Dec 2023 08:24:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 663408D0014 for ; Thu, 21 Dec 2023 08:24:45 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3BC36A23A5 for ; Thu, 21 Dec 2023 13:24:45 +0000 (UTC) X-FDA: 81590895330.20.76FBB33 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 77B9AA0019 for ; Thu, 21 Dec 2023 13:24:43 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="ZH/K1LL5"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703165083; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/8o/jzOtIP8Ko02Zj7+GBh+0/dDxeH6NEFPQ0ZzQc+4=; b=5MwcKcFI2xCIZxpY44c+wp01GCrHgq8liaAbT70oDXNMSSWO4tAt9nYeF6t72JNCK+Qo9y cfHAsXIlalWgAt7crM+ZghNiNcLWzb0zJQet31rhu3Sy6Waiid1sNSMxU0CrSAHmflpkPI Yg9hY4SydMPim+FkH7/1517rnuvT37M= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="ZH/K1LL5"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703165083; a=rsa-sha256; cv=none; b=grG2g15bJtpUh1nOZfvLAUqoEVdmBfSLsTRO8fgA+ZvLbX1EJWT/T2PJ90Z0wpqih0ZDW1 ykMl76JqeKN9qje5dX5xWTWGyb1mQHiOFS6DCNjS7C8CYL2cPvjRnq5CBXGNtryLcEjLwO chepb9QQAv7+1uyvL7u/Fw84VchQLWI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703165082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/8o/jzOtIP8Ko02Zj7+GBh+0/dDxeH6NEFPQ0ZzQc+4=; b=ZH/K1LL58HKoZyn3DpGCcnZSCRQJ3mIaX7fTE7oDINLQejRCswIsIGpDvbFs2zkhSDJmoH bxNgwuaK5nPulW8ctd17g7cxrnPIZn3oBxR+nehLH1abC2F1Nom3DGTFBXsl4X44nUtoQt 5/r2gmE0iSOI1Mcbfy8GuWhDP8kZxTM= 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-248-whnSRbVTPqyRQu2WUIvUpg-1; Thu, 21 Dec 2023 08:24:37 -0500 X-MC-Unique: whnSRbVTPqyRQu2WUIvUpg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 65AA688CDCD; Thu, 21 Dec 2023 13:24:36 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.39.195.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80DDD492BFA; Thu, 21 Dec 2023 13:24:33 +0000 (UTC) From: David Howells To: Jeff Layton , Steve French Cc: David Howells , Matthew Wilcox , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Dominique Martinet , Eric Van Hensbergen , Ilya Dryomov , Christian Brauner , linux-cachefs@redhat.com, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 08/40] netfs: Add a procfile to list in-progress requests Date: Thu, 21 Dec 2023 13:23:03 +0000 Message-ID: <20231221132400.1601991-9-dhowells@redhat.com> In-Reply-To: <20231221132400.1601991-1-dhowells@redhat.com> References: <20231221132400.1601991-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Rspamd-Queue-Id: 77B9AA0019 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ibxbu9qbwg53saz6uggbj9m8mabwt31u X-HE-Tag: 1703165083-900265 X-HE-Meta: U2FsdGVkX1+JwumyE85zNj0vgfPYKs4AKFsalKpagsJuudhMtxAKI4oNyQXDHPh66GuG6oteHLbDC8qfLHSHBThjuE7vpffhhg/rmhimr8/45QF9+5VNx4CTAdRg61gyyXmiiQPDJL0ozgWf8UhqjfFly1ixhbUU8C6LfU3F1vNJcD7bvbFJ29XzixiFJ1yljoKEe1Fos+BZTKHvn8KlRNrXENhmlXA1posxUGGQ511r23260yYQoc+Ur+k0xPBuWYiQa26DcsJBzDx4hkX6hG3Bx1nxKOZq9c93vGfB9zylCEcvYtFMCkaGbQy33+m0XkvHYfV8bQmcjiWolvxtK242XMpAMnxS+l7RJz2phGkEmSJitm16ziB+PfeeyDRNGw8xo4cODo+dBihHboilv+9gxqfCqv7EbC/pso/my9dxVMcjnxuVxzHzaIUIcmPRF09QpbNjalR1uEPJCPYdz+n/YhFhnHQde3YNT/COVq97OcupynahdcrhWXpD122Y7KkzHwyLhxc58yYOWDWPhzEJ+sZcWriflZqC0LgXaFuVnrPgqP50rXXWeuPSV+aovlJxGzT5z5xeAOKDZGDAD67uwwFPoxbrRQPaCAQ2AGaVpw9vJ7hN9xI8u8O//grYZuFPzzfiZ1hCDNqjEyF7wFfD1TNU7woNghj4+iGG+kvD4f0nqMAexdHmz10iIhBmEkhR4GRFuS9Zmylpc7p56DscxTdOzY3/h3glHuHqjQefg0iyCISKLRhwsqTMdFoAQLkxUJdrMPJmf4yeNY8FPBL28VUpLGcYkgvggYMRHhdMWOApG5Mwi0ByBdTh6vtnc4ICvzF4nyY0Hu6gjwJZRliBPZek7LTcrbQq6YpnSY5u87H39Ms9D7UDmBLHnjFQFeTM3zA1UtR33FSFMc+gckROIg281XaG2qg5gK7mXxXt57dxeqMYU1ur64qidomQMDkaIyLQHNoLZAkbb6y mtbpJnjK 2vq7IYG+LzTvenuppNjGJYePoT7qe6QHnQsYczpjAqj7cWO89He+rXn+154patAC9pRffZ5v0+hdy6sXCAQx53Rgsi05iryjGObrPlJvN0p0jWLuDJTmxkfKCDwGw9RVtVeZ+v6UvBAgI4jdIDewtWTkupH4kiRP23SadqvjsVawwhMu+SqmNkEOKatHUFbprgTAEgFjvz789x7ch3NMUXTyG8D8hcgZmrzqI/KrK2PKvudpEoA/qq4FLt8htucuCRE4TtGFZepeiMSDBDDnVeP9SDUxdGYjKEHzXoc6HEWLENEY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a procfile, /proc/fs/netfs/requests, to list in-progress netfslib I/O requests. Signed-off-by: David Howells cc: Jeff Layton cc: linux-cachefs@redhat.com cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/netfs/internal.h | 22 ++++++++++++++ fs/netfs/main.c | 69 ++++++++++++++++++++++++++++++++++++++++++- fs/netfs/objects.c | 4 ++- include/linux/netfs.h | 6 +++- 4 files changed, 98 insertions(+), 3 deletions(-) diff --git a/fs/netfs/internal.h b/fs/netfs/internal.h index 3f6e22229433..4708fb15446b 100644 --- a/fs/netfs/internal.h +++ b/fs/netfs/internal.h @@ -33,6 +33,28 @@ int netfs_begin_read(struct netfs_io_request *rreq, bool sync); * main.c */ extern unsigned int netfs_debug; +extern struct list_head netfs_io_requests; +extern spinlock_t netfs_proc_lock; + +#ifdef CONFIG_PROC_FS +static inline void netfs_proc_add_rreq(struct netfs_io_request *rreq) +{ + spin_lock(&netfs_proc_lock); + list_add_tail_rcu(&rreq->proc_link, &netfs_io_requests); + spin_unlock(&netfs_proc_lock); +} +static inline void netfs_proc_del_rreq(struct netfs_io_request *rreq) +{ + if (!list_empty(&rreq->proc_link)) { + spin_lock(&netfs_proc_lock); + list_del_rcu(&rreq->proc_link); + spin_unlock(&netfs_proc_lock); + } +} +#else +static inline void netfs_proc_add_rreq(struct netfs_io_request *rreq) {} +static inline void netfs_proc_del_rreq(struct netfs_io_request *rreq) {} +#endif /* * objects.c diff --git a/fs/netfs/main.c b/fs/netfs/main.c index c9af6e0896d3..97ce1436615b 100644 --- a/fs/netfs/main.c +++ b/fs/netfs/main.c @@ -21,13 +21,80 @@ unsigned netfs_debug; module_param_named(debug, netfs_debug, uint, S_IWUSR | S_IRUGO); MODULE_PARM_DESC(netfs_debug, "Netfs support debugging mask"); +#ifdef CONFIG_PROC_FS +LIST_HEAD(netfs_io_requests); +DEFINE_SPINLOCK(netfs_proc_lock); + +static const char *netfs_origins[] = { + [NETFS_READAHEAD] = "RA", + [NETFS_READPAGE] = "RP", + [NETFS_READ_FOR_WRITE] = "RW", +}; + +/* + * Generate a list of I/O requests in /proc/fs/netfs/requests + */ +static int netfs_requests_seq_show(struct seq_file *m, void *v) +{ + struct netfs_io_request *rreq; + + if (v == &netfs_io_requests) { + seq_puts(m, + "REQUEST OR REF FL ERR OPS COVERAGE\n" + "======== == === == ==== === =========\n" + ); + return 0; + } + + rreq = list_entry(v, struct netfs_io_request, proc_link); + seq_printf(m, + "%08x %s %3d %2lx %4d %3d @%04llx %zx/%zx", + rreq->debug_id, + netfs_origins[rreq->origin], + refcount_read(&rreq->ref), + rreq->flags, + rreq->error, + atomic_read(&rreq->nr_outstanding), + rreq->start, rreq->submitted, rreq->len); + seq_putc(m, '\n'); + return 0; +} + +static void *netfs_requests_seq_start(struct seq_file *m, loff_t *_pos) + __acquires(rcu) +{ + rcu_read_lock(); + return seq_list_start_head(&netfs_io_requests, *_pos); +} + +static void *netfs_requests_seq_next(struct seq_file *m, void *v, loff_t *_pos) +{ + return seq_list_next(v, &netfs_io_requests, _pos); +} + +static void netfs_requests_seq_stop(struct seq_file *m, void *v) + __releases(rcu) +{ + rcu_read_unlock(); +} + +static const struct seq_operations netfs_requests_seq_ops = { + .start = netfs_requests_seq_start, + .next = netfs_requests_seq_next, + .stop = netfs_requests_seq_stop, + .show = netfs_requests_seq_show, +}; +#endif /* CONFIG_PROC_FS */ + static int __init netfs_init(void) { int ret = -ENOMEM; if (!proc_mkdir("fs/netfs", NULL)) goto error; - + if (!proc_create_seq("fs/netfs/requests", S_IFREG | 0444, NULL, + &netfs_requests_seq_ops)) + goto error_proc; #ifdef CONFIG_FSCACHE_STATS if (!proc_create_single("fs/netfs/stats", S_IFREG | 0444, NULL, netfs_stats_show)) diff --git a/fs/netfs/objects.c b/fs/netfs/objects.c index e17cdf53f6a7..85f428fc52e6 100644 --- a/fs/netfs/objects.c +++ b/fs/netfs/objects.c @@ -45,6 +45,7 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping, } } + netfs_proc_add_rreq(rreq); netfs_stat(&netfs_n_rh_rreq); return rreq; } @@ -76,12 +77,13 @@ static void netfs_free_request(struct work_struct *work) container_of(work, struct netfs_io_request, work); trace_netfs_rreq(rreq, netfs_rreq_trace_free); + netfs_proc_del_rreq(rreq); netfs_clear_subrequests(rreq, false); if (rreq->netfs_ops->free_request) rreq->netfs_ops->free_request(rreq); if (rreq->cache_resources.ops) rreq->cache_resources.ops->end_operation(&rreq->cache_resources); - kfree(rreq); + kfree_rcu(rreq, rcu); netfs_stat_d(&netfs_n_rh_rreq); } diff --git a/include/linux/netfs.h b/include/linux/netfs.h index 32faf6c89702..7244ddebd974 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -175,10 +175,14 @@ enum netfs_io_origin { * operations to a variety of data stores and then stitch the result together. */ struct netfs_io_request { - struct work_struct work; + union { + struct work_struct work; + struct rcu_head rcu; + }; struct inode *inode; /* The file being accessed */ struct address_space *mapping; /* The mapping being accessed */ struct netfs_cache_resources cache_resources; + struct list_head proc_link; /* Link in netfs_iorequests */ struct list_head subrequests; /* Contributory I/O operations */ void *netfs_priv; /* Private data for the netfs */ unsigned int debug_id;