From patchwork Mon Dec 16 20:40:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13910328 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 683CFE7717F for ; Mon, 16 Dec 2024 20:42:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2FCD6B00B1; Mon, 16 Dec 2024 15:42:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EDE2C6B00B2; Mon, 16 Dec 2024 15:42:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA6AE6B00B3; Mon, 16 Dec 2024 15:42:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BBCE76B00B1 for ; Mon, 16 Dec 2024 15:42:09 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 54F09160EEF for ; Mon, 16 Dec 2024 20:42:09 +0000 (UTC) X-FDA: 82901993496.22.3AC793B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 2FBDA40015 for ; Mon, 16 Dec 2024 20:41:26 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y6fAiMMn; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.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=1734381699; a=rsa-sha256; cv=none; b=2ey3Skmb77xkmGDyqa7UwgMzH7cTw5tZNHnZzv+LyZMsQhSSITDRjmjL5Gzi6zu/jPkICm wLYCsnkKd+/b0bJMjZDWPrGy8OnfketKwVdbDon5FnhVOZBsKf1RdyilrSCln9ch1O7a9m chpjwJQ+S38JKkqMNiJll+7Vp3X5kDg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y6fAiMMn; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.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=1734381699; 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=c4ynYPVximdGHs7dVqzSfcBpzcrEHVdMF9zavpdQExQ=; b=kmXFh2S/vEYiVE1QUCL4Tw2A5eq8atgYHY2a04dNBBe+foia9kSSGnnsnfmgSv8yhRutza sy6V6l/yifJCWKgtKNwVU9vsFuZbnEVPqJOtSOc2raA494XmNGZI4RMyqcse1zFU0vEkpW naoSPNKrhPgw25elCh/pVJPSNuvzBEg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734381727; 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=c4ynYPVximdGHs7dVqzSfcBpzcrEHVdMF9zavpdQExQ=; b=Y6fAiMMnnLtAi9auUFQb6O0IsaaPd70VpRwdCqb2xTn/7KNunp+Q0MZM89gK1pLPCsdTya h7QXlSIGJW7kTChrIzxMOn7yLk2EEF7dZdHkf5KN/80TXnsfF0nDkDigMJcOnUJ9FWKA67 gwEbRYE3eJ/wizgRiWSz5c2jafxTk6E= Received: from mx-prod-mc-02.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-392-HeKwHV38PVG_Gm0rYfgLLg-1; Mon, 16 Dec 2024 15:42:02 -0500 X-MC-Unique: HeKwHV38PVG_Gm0rYfgLLg-1 X-Mimecast-MFC-AGG-ID: HeKwHV38PVG_Gm0rYfgLLg 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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0F2BE1956056; Mon, 16 Dec 2024 20:41:58 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.48]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3B4F919560AD; Mon, 16 Dec 2024 20:41:52 +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 v5 03/32] netfs: Use a folio_queue allocation and free functions Date: Mon, 16 Dec 2024 20:40:53 +0000 Message-ID: <20241216204124.3752367-4-dhowells@redhat.com> In-Reply-To: <20241216204124.3752367-1-dhowells@redhat.com> References: <20241216204124.3752367-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2FBDA40015 X-Stat-Signature: ec86u7cog1u5nm54ag3cc6cfe5t14x45 X-Rspam-User: X-HE-Tag: 1734381686-363207 X-HE-Meta: U2FsdGVkX18CteXQKzx3CSeRlwmJqF34+mkhvmB9yEhc2ONvtDzyXkGyrv9+Yf6CDX6kbBEb4Lr7KakcHNAGyeV3bnmqQ0M/SCkeNhz0eJrDT66mBlR7TM7tSqNYk9LEmgiqXuHmnLo6lG+kEMz7yX9MePKotaAStl08GhxMKxcG2x6KRtAqr0xKlM+TNQwbmxLnTMNN4e1pnD5TvqtQozPEuoGTFMzuZTuo/7BwF6XArh18edcHuAAH8/BHZmIeCTVQAJqSpJ8yniTTq54tKxfswcEfJ01FQ+gSUmfdV7lHnFoN3kRABQxtWvQKFKrbp7r4BCE66nXQRPUq2XAxLip7BHY9EtbOB7/CRz2/N60ARm0ylbF3DAlIH0hg0xJE5UotRQNDdSvRHPWvrCvG0ZnDjsugOIRufFsxILDobtfQn2naDOvXiN1dnAYDbBlC4uy9qxESMOakd5AO1bek3cFbaaSwya+JDUj7TrXQfY8J7EV9s9x9g+i7KcmbiVfHkTA+U83ZhRuIO/Td75U9D4cjt38UvTCt6EYN+xm24zRlQRQOmrFV1JFCApx3Bre/dNHK0JIvBFix/K+lmil37OIm6eIFxFL/WqXo+QKZWTOZYKts0wwrQICDvwuEbaNmb1ho5twPKG7SLUXjXRIUbLWbaDkxM5ahg1KpBrFXFetcYH2C8a6A4WJFylxbjVdX8sRcmEVY7Vk4Z0vDiNZaqe9dOxROjcBEktiMLfAs3RUAmF9RKg4BqtsPh+01BEd986+4OFQ+KAUG7ZH/f/kU7qtLqiShyhOgyRiFDPAkPshTAXvFeAWD4hHTtSdm56RCRqj9VDbvBJY/5/xq4OtISNf9BhBOgsl5m/xTEVoBKTbrV3wiNqjvyiDgaXwi2UJbJbOHP+fQJ4Q9S2aV0fbXNKuCc/4KzwxesZlizGLzfNJJkOF6DGN5a68WYjHv1CTDsZBjHuQkgWWBnl6rRvT O7BEnQMn Tx6IweBkHKu6z8kEybeuMjPyzzphB1gW1Jpu1HzLWSVDhaPBGpUlLQYivN0pTA1w8psNoA16T6z1tg9o955FyoIQv6k1Rc3IliLVCagsYk3qEz3jNTEYTyimco5YX/Vfh/YH8fcYCUX2dtPw/92vP/Sf7dGRASTjsiqPvY1+FxGw9/X8spRkHi/x65tqJva0nVBnE3vDaWHvvpf+3yewDLxwy9uLNvnCeQQzyDHekfb/4cisQ0k4deQKaziw22i5rIZh7uEchERzupZlj85f8SktyxfPmY4phy1F9c+yn/Akqaby2RaNowOQN8zn7GzUBHDTNXAkOYz1PJ8J3IyVbLscgFrgHmmXR+5hvtkrY2gSLitosmlTdqsrLcgPEP/u5G9e06jRMpkF0dJZNhXYercKTFxhkw8ATYop++XQeB+/uztE= 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 4dc9b8286355..78b04763bed6 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; @@ -363,11 +361,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; @@ -440,12 +436,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 ecdd5ced16a8..c69e0f02c30f 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] @@ -453,6 +454,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