From patchwork Thu Oct 24 14:05:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13849098 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 3D171CE8E7A for ; Thu, 24 Oct 2024 14:06:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8F1F6B00A1; Thu, 24 Oct 2024 10:06:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A18556B00A2; Thu, 24 Oct 2024 10:06:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 891FA6B00A3; Thu, 24 Oct 2024 10:06:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6A3A56B00A1 for ; Thu, 24 Oct 2024 10:06:42 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2CC53812F5 for ; Thu, 24 Oct 2024 14:06:26 +0000 (UTC) X-FDA: 82708670520.01.DF211C9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id C1A2520027 for ; Thu, 24 Oct 2024 14:06:31 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="BU88/Nvf"; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729778722; a=rsa-sha256; cv=none; b=XtCCXUc9GpPkzeFbFOz472sMPaI9y49WZLCfjp76z3IfKoUr76DSLDiHJUxSUTsChz+2R1 ZzyLXYhXWdYsP8B/HLG3QcuN+7k7LhAFgpvLyxzK6XRSWVvipQgegFkLGYH5TTrf0lnBcO XrbNcBgu2ogE4g/LWbGsonQjAMm87iw= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="BU88/Nvf"; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729778722; 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=DUlYZzbaKUHX76MZjhLNdaJFIvV/RRK5UT5LJFkHe/Y=; b=rsa9+zBc0+aT0iDLIgfYGPemfQW3DkMh4To3OJkLrPGyn/1CWb7ByOT3Q86CNxD2ZCFuA/ VD6Q7S88FmcmFxtfoIBDIF5+S5tlBrGPXLkviBNvEBHVkTxHl54yyJE8TEgGF4jouTw3pm Rvm3GC1HBPkrx/IzofdYlXJ4jJs4Wfo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729778799; 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=DUlYZzbaKUHX76MZjhLNdaJFIvV/RRK5UT5LJFkHe/Y=; b=BU88/NvfEU42CPyfC7UMmGeG86wNfPs39ruBWJoNih/x3Xbai2FKx6kupS990nFVreQuRu ZIVaVDK7g7IWm0QN2kViPf778lmmqGKUDubw80ScZQxeZrc/QurN+62T0ZNazMg0doDQvS dvZHMMs0QJ3e+Uz/QPVUjR2FiiAJlII= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-362-dFLyIxx0N0msN1U-ylJXxw-1; Thu, 24 Oct 2024 10:06:35 -0400 X-MC-Unique: dFLyIxx0N0msN1U-ylJXxw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4BA0C1955F3D; Thu, 24 Oct 2024 14:06:28 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.231]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9CB30196BB7D; Thu, 24 Oct 2024 14:06:22 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French , Matthew Wilcox Cc: David Howells , Jeff Layton , Gao Xiang , Dominique Martinet , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Eric Van Hensbergen , Ilya Dryomov , 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 04/27] netfs: Use a folio_queue allocation and free functions Date: Thu, 24 Oct 2024 15:05:02 +0100 Message-ID: <20241024140539.3828093-5-dhowells@redhat.com> In-Reply-To: <20241024140539.3828093-1-dhowells@redhat.com> References: <20241024140539.3828093-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Stat-Signature: kugsfw4x91hrecbtk4rfim8bepqwpc11 X-Rspamd-Queue-Id: C1A2520027 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1729778791-963020 X-HE-Meta: U2FsdGVkX1/B5BmvB4VaR/dlRkIbrZIQX83Aoy/sPNWoKfSpPKERXzIzPrGPPjdrS8hew6kDn+j0hCzbHe407teeVmtxbbSZE69tmTCuSTGL9ZGqUxtG8Dg9UQnVDNgjmHwxE6NhLYfkuYnT6QGopRvlCxaxnBqIFVgtEYrjmkJKs8C0x27iaeiBVNy1SdybT+CFw41nppxfAG6t3cZ1Q4SPlLAS3CYJkEwfXpJYpMSmUnby8c+g2hxoBh/xGAwbkELMg+p5+4R1Nqh29Ru2uVv8JlF/IVmwDEmRnc+c/oO31U/YTqx66BTq+7qaQoScaB84NCmF0XLfpLyECYJ5lUqQAxSKwIWQZwvOc1xc6BlUgSV74GT4cBWtfSCa+ZIP4XaaDFmxxmTsh1XHQQjMLZYSz/RA7tN8Y6Cs2zwZNxP5WUDYfzDpS9axMLoe/s294l+aQ1ogOygtiP4uITkXxCZFirl8RMI6mHbWN945lkROwgXsxDZ5TwmlE9KItbUpp5F4Pskihr7X3uzLH+9/mMVO+LISlSMdzSJFstqVZckpRw2jV/opwAStYPpJv4x6+U8IlMM3AsnjIAM9GaZo0HVX7aizarlbjB5msqCMRzqhC/YpusTQRmcK/iGtNzXhzAssxF9c1OfQNB8AmVbvX2U71DV6flV9stR7zT9q1WdfpfVXzIq93qR9eV0cE7G3JTYqvpH/8Nx/bQvPpxKa2r7pB4sefOdDbRS6ItL0Kb6SnnMF496NMlz6sVZuH+A3qrzlLUHq7dPcpqrFQOQnlG/PAPoMUAgA1OmwMEo2hxKOsms9kLL86bLfUQw8LAxl6p1SF+MkMqmGxcsgXqd8rv6OeQwGzIP4gHegM/NfMKG9iZZHxYxLtJNb1u0Se6FCcz5x7ROsSdvrYCJNvOnBG6FsxJmBHQ85VLErJIaW6y/+EaPxsGLDrEzHqL6ZxS3n9GDEu8pY3DDxD06TALi TYP4pJS6 4bgdZ81AwAK5CnGMqB+dPeAf8SdQAih+TtEDcaotWPuU1Jopb9IiSCVMKszqmCJ6wI6FDppXbqsD/Sr3RQuOYNK6jxOp0gGLiq4hUf2oeLB53MxlZZCU9XN4LIOD256sdh2uPyt2o4TW+/f/k4ApCPoJ27wQDC2Pu7J9sB8LwVYROd/Dgp61hlEfKNU0aFLVqmWiuAu9RFdBSeal+UzCW5ExYagwi1KfwRG8yGSx+4+KWaXdzxliBL02MgTIftYEdPgI8hBEqn6PFRTXTbpBnT2M4PzyE37uXY1aMuc4mhXe2ESBX/N4yRIhv9bi44rnVtFt7XVEOJx27UMg2Pymm9thTx/aqrswiA5+EB2DlgRiG1KfqF9pLKWZ0wb4wspC/u2Kn38UE+GrW0hE= 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: 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 cc: Jeff Layton 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 #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