From: David Howells <dhowells@redhat.com>
To: Christian Brauner <christian@brauner.io>,
Steve French <smfrench@gmail.com>,
Matthew Wilcox <willy@infradead.org>
Cc: David Howells <dhowells@redhat.com>,
Jeff Layton <jlayton@kernel.org>,
Gao Xiang <hsiangkao@linux.alibaba.com>,
Dominique Martinet <asmadeus@codewreck.org>,
Marc Dionne <marc.dionne@auristor.com>,
Paulo Alcantara <pc@manguebit.com>,
Shyam Prasad N <sprasad@microsoft.com>,
Tom Talpey <tom@talpey.com>,
Eric Van Hensbergen <ericvh@kernel.org>,
Ilya Dryomov <idryomov@gmail.com>,
netfs@lists.linux.dev, 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-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 04/31] netfs: Use a folio_queue allocation and free functions
Date: Fri, 25 Oct 2024 21:39:31 +0100 [thread overview]
Message-ID: <20241025204008.4076565-5-dhowells@redhat.com> (raw)
In-Reply-To: <20241025204008.4076565-1-dhowells@redhat.com>
Provide and use folio_queue allocation and free functions to combine the
allocation, initialisation and stat (un)accounting steps that are repeated
in several places.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Jeff Layton <jlayton@kernel.org>
cc: netfs@lists.linux.dev
cc: linux-fsdevel@vger.kernel.org
---
fs/netfs/buffered_read.c | 12 +++---------
fs/netfs/misc.c | 38 ++++++++++++++++++++++++++++++++++----
include/linux/netfs.h | 5 +++++
3 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c
index 7ac34550c403..b5a7beb9d01b 100644
--- a/fs/netfs/buffered_read.c
+++ b/fs/netfs/buffered_read.c
@@ -131,11 +131,9 @@ static ssize_t netfs_prepare_read_iterator(struct netfs_io_subrequest *subreq)
struct folio_queue *tail = rreq->buffer_tail, *new;
size_t added;
- new = kmalloc(sizeof(*new), GFP_NOFS);
+ new = netfs_folioq_alloc(GFP_NOFS);
if (!new)
return -ENOMEM;
- netfs_stat(&netfs_n_folioq);
- folioq_init(new);
new->prev = tail;
tail->next = new;
rreq->buffer_tail = new;
@@ -359,11 +357,9 @@ static int netfs_prime_buffer(struct netfs_io_request *rreq)
struct folio_batch put_batch;
size_t added;
- folioq = kmalloc(sizeof(*folioq), GFP_KERNEL);
+ folioq = netfs_folioq_alloc(GFP_KERNEL);
if (!folioq)
return -ENOMEM;
- netfs_stat(&netfs_n_folioq);
- folioq_init(folioq);
rreq->buffer = folioq;
rreq->buffer_tail = folioq;
rreq->submitted = rreq->start;
@@ -436,12 +432,10 @@ static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct fo
{
struct folio_queue *folioq;
- folioq = kmalloc(sizeof(*folioq), GFP_KERNEL);
+ folioq = netfs_folioq_alloc(GFP_KERNEL);
if (!folioq)
return -ENOMEM;
- netfs_stat(&netfs_n_folioq);
- folioq_init(folioq);
folioq_append(folioq, folio);
BUG_ON(folioq_folio(folioq, 0) != folio);
BUG_ON(folioq_folio_order(folioq, 0) != folio_order(folio));
diff --git a/fs/netfs/misc.c b/fs/netfs/misc.c
index 78fe5796b2b2..6cd7e1ee7a14 100644
--- a/fs/netfs/misc.c
+++ b/fs/netfs/misc.c
@@ -8,6 +8,38 @@
#include <linux/swap.h>
#include "internal.h"
+/**
+ * netfs_folioq_alloc - Allocate a folio_queue struct
+ * @gfp: Allocation constraints
+ *
+ * Allocate, initialise and account the folio_queue struct.
+ */
+struct folio_queue *netfs_folioq_alloc(gfp_t gfp)
+{
+ struct folio_queue *fq;
+
+ fq = kmalloc(sizeof(*fq), gfp);
+ if (fq) {
+ netfs_stat(&netfs_n_folioq);
+ folioq_init(fq);
+ }
+ return fq;
+}
+EXPORT_SYMBOL(netfs_folioq_alloc);
+
+/**
+ * netfs_folioq_free - Free a folio_queue struct
+ * @folioq: The object to free
+ *
+ * Free and unaccount the folio_queue struct.
+ */
+void netfs_folioq_free(struct folio_queue *folioq)
+{
+ netfs_stat_d(&netfs_n_folioq);
+ kfree(folioq);
+}
+EXPORT_SYMBOL(netfs_folioq_free);
+
/*
* Make sure there's space in the rolling queue.
*/
@@ -87,8 +119,7 @@ struct folio_queue *netfs_delete_buffer_head(struct netfs_io_request *wreq)
if (next)
next->prev = NULL;
- netfs_stat_d(&netfs_n_folioq);
- kfree(head);
+ netfs_folioq_free(head);
wreq->buffer = next;
return next;
}
@@ -111,8 +142,7 @@ void netfs_clear_buffer(struct netfs_io_request *rreq)
folio_put(folio);
}
}
- netfs_stat_d(&netfs_n_folioq);
- kfree(p);
+ netfs_folioq_free(p);
}
}
diff --git a/include/linux/netfs.h b/include/linux/netfs.h
index 5eaceef41e6c..b2fa569e875d 100644
--- a/include/linux/netfs.h
+++ b/include/linux/netfs.h
@@ -21,6 +21,7 @@
enum netfs_sreq_ref_trace;
typedef struct mempool_s mempool_t;
+struct folio_queue;
/**
* folio_start_private_2 - Start an fscache write on a folio. [DEPRECATED]
@@ -454,6 +455,10 @@ void netfs_end_io_write(struct inode *inode);
int netfs_start_io_direct(struct inode *inode);
void netfs_end_io_direct(struct inode *inode);
+/* Miscellaneous APIs. */
+struct folio_queue *netfs_folioq_alloc(gfp_t gfp);
+void netfs_folioq_free(struct folio_queue *folioq);
+
/**
* netfs_inode - Get the netfs inode context from the inode
* @inode: The inode to query
next prev parent reply other threads:[~2024-10-25 20:40 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-25 20:39 [PATCH v2 00/31] netfs: Read performance improvements and "single-blob" support David Howells
2024-10-25 20:39 ` [PATCH v2 01/31] netfs: Remove call to folio_index() David Howells
2024-10-25 20:39 ` [PATCH v2 02/31] netfs: Fix a few minor bugs in netfs_page_mkwrite() David Howells
2024-10-25 20:39 ` [PATCH v2 03/31] netfs: Remove unnecessary references to pages David Howells
2024-10-25 20:39 ` David Howells [this message]
2024-10-25 20:39 ` [PATCH v2 05/31] netfs: Add a tracepoint to log the lifespan of folio_queue structs David Howells
2024-10-25 20:39 ` [PATCH v2 06/31] netfs: Abstract out a rolling folio buffer implementation David Howells
2024-10-25 20:39 ` [PATCH v2 07/31] netfs: Make netfs_advance_write() return size_t David Howells
2024-10-25 20:39 ` [PATCH v2 08/31] netfs: Split retry code out of fs/netfs/write_collect.c David Howells
2024-10-25 20:39 ` [PATCH v2 09/31] netfs: Drop the error arg from netfs_read_subreq_terminated() David Howells
2024-10-25 20:39 ` [PATCH v2 10/31] netfs: Drop the was_async " David Howells
2024-10-25 20:39 ` [PATCH v2 11/31] netfs: Don't use bh spinlock David Howells
2024-10-25 20:39 ` [PATCH v2 12/31] afs: Don't use mutex for I/O operation lock David Howells
2024-10-25 20:39 ` [PATCH v2 13/31] afs: Fix EEXIST error returned from afs_rmdir() to be ENOTEMPTY David Howells
2024-10-25 20:39 ` [PATCH v2 14/31] afs: Fix directory format encoding struct David Howells
2024-10-25 20:39 ` [PATCH v2 15/31] netfs: Remove some extraneous directory invalidations David Howells
2024-10-25 20:39 ` [PATCH v2 16/31] cachefiles: Add some subrequest tracepoints David Howells
2024-10-25 20:39 ` [PATCH v2 17/31] cachefiles: Add auxiliary data trace David Howells
2024-10-25 20:39 ` [PATCH v2 18/31] afs: Add more tracepoints to do with tracking validity David Howells
2024-10-25 20:39 ` [PATCH v2 19/31] netfs: Add functions to build/clean a buffer in a folio_queue David Howells
2024-10-25 20:39 ` [PATCH v2 20/31] netfs: Add support for caching single monolithic objects such as AFS dirs David Howells
2024-10-25 20:39 ` [PATCH v2 21/31] afs: Make afs_init_request() get a key if not given a file David Howells
2024-10-25 20:39 ` [PATCH v2 22/31] afs: Use netfslib for directories David Howells
2024-10-25 20:39 ` [PATCH v2 23/31] afs: Use netfslib for symlinks, allowing them to be cached David Howells
2024-10-25 20:39 ` [PATCH v2 24/31] afs: Eliminate afs_read David Howells
2024-10-25 20:39 ` [PATCH v2 25/31] afs: Make {Y,}FS.FetchData an asynchronous operation David Howells
2024-10-25 20:39 ` [PATCH v2 26/31] netfs: Change the read result collector to only use one work item David Howells
2024-10-25 20:39 ` [PATCH v2 27/31] afs: Make afs_mkdir() locally initialise a new directory's content David Howells
2024-10-25 20:39 ` [PATCH v2 28/31] afs: Use the contained hashtable to search a directory David Howells
2024-10-25 20:39 ` [PATCH v2 29/31] afs: Locally initialise the contents of a new symlink on creation David Howells
2024-10-25 20:39 ` [PATCH v2 30/31] afs: Add a tracepoint for afs_read_receive() David Howells
2024-10-25 20:39 ` [PATCH v2 31/31] netfs: Report on NULL folioq in netfs_writeback_unlock_folios() David Howells
2024-10-31 12:58 ` [PATCH v2 25/31] afs: Make {Y,}FS.FetchData an asynchronous operation David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241025204008.4076565-5-dhowells@redhat.com \
--to=dhowells@redhat.com \
--cc=asmadeus@codewreck.org \
--cc=ceph-devel@vger.kernel.org \
--cc=christian@brauner.io \
--cc=ericvh@kernel.org \
--cc=hsiangkao@linux.alibaba.com \
--cc=idryomov@gmail.com \
--cc=jlayton@kernel.org \
--cc=linux-afs@lists.infradead.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nfs@vger.kernel.org \
--cc=marc.dionne@auristor.com \
--cc=netdev@vger.kernel.org \
--cc=netfs@lists.linux.dev \
--cc=pc@manguebit.com \
--cc=smfrench@gmail.com \
--cc=sprasad@microsoft.com \
--cc=tom@talpey.com \
--cc=v9fs@lists.linux.dev \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).