Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2591187rdg; Mon, 16 Oct 2023 08:51:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHD1JULxhpad6y2LEwF7rPF3sm9iAV0i09BBUrDoYfUmy5OJ0Tj2ASP/OKeegYkl4NNtxL X-Received: by 2002:a17:902:aa05:b0:1c5:8a0e:b01e with SMTP id be5-20020a170902aa0500b001c58a0eb01emr26729072plb.63.1697471469964; Mon, 16 Oct 2023 08:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697471469; cv=none; d=google.com; s=arc-20160816; b=jIvfNbH+fo2ZoN/VnEiWFU1Yet+pepSA/+H4OH6ILmuCthXXmZGn+tUcq2nWZnY6Xd KoIg3r2fzhfBiplUw5y4eaieO058vLCv4+SMINdhg14AWdQ2FxAjlHowg1eiRS5GcO8x QVe9wL3wk0dq/Nq8cajtwrUHhZI5BgoXVJG/q6ovZD2jZDhxCKZxJZh4cgOO4HA0czbW 0hOt83cSe7jVP1kaAbXFl1mExugVdNW6aU83cII11vg1IA6FCnLIGy5ZGJ8IXsrvV7Aa BjhjUxwi+tceiw5+p3s/bLcjpBjVXldcCi88adAnNyWKpnPZ8Ibeda2JL73O6ZXiFHT8 hCPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=JvS0t8MsMF0LNNMt+NtwGTOOC8NAA7j4/DHff6qLlCw=; fh=w1XMNo7C5mJn3+5mWgQPEQu/TJN4HhHxYuaxIps+vE4=; b=OAzGSauOSNVlIJ7+4Faj/ADxZdX8h5mnuNtpwDleb5fg+ITxFnj3SGvYA3A27hSH4m xGRbziagalUXAAWC2NxfGSgTf22bokC8LrUzECmAWSBS4eJk8XEwvv/dOVBtnKxf4I4e pRjMF2vesxCMoXgQ5r/QEsG5KJ0YYwj+0kY05jNkBHkjMPg0T2QKxzbuhVdlvPX5E4Xq 6EVxMRDF+1EEShsODpHUtcy8HrnPk8ilswjCh1D5cmEHipc9ASQ6QyKIaZexjl8jGUjS yGVm8J4zYIbWSwGzk9MjTqfhjt+3tTEgP8RutkHuNq/ZEWdzpgSj02dwDhH3HbFgRd+3 zJQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="a2t0uQf/"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id j11-20020a170902da8b00b001c9cc3a07c3si10666486plx.280.2023.10.16.08.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 08:51:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="a2t0uQf/"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 382598050022; Mon, 16 Oct 2023 08:51:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232582AbjJPPu4 (ORCPT + 99 others); Mon, 16 Oct 2023 11:50:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230343AbjJPPuz (ORCPT ); Mon, 16 Oct 2023 11:50:55 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D78BAB; Mon, 16 Oct 2023 08:50:52 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E701C433C8; Mon, 16 Oct 2023 15:50:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697471452; bh=8Z3jrNAij+Fk5+s3c9fGMpm3Llf0bqvYwxb17CmvIj4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=a2t0uQf/DvBBY36/YSVGHmEbDVIJss6218VIOQFaRNy8JmQ0oer3kf5Do4B/XVenG 33gyHHvUp34cAPyShV8hXUknOC/FDMNGdNjTPZJIcqDJUhBRCBvvVC16qC3yq7Sc0K 6I7K8HlxTttf8VEYSL/9nhJiLXbO97xByEonHK91iC09/ZE70rl6GZxNnpxTwr5E5V q5Pqgk3a6b2L7xZJwBVEiGuUDDd7tXyymGf5isDXPBkRuGcR3Q9MlwE/DlbvXcKCcL QDOSHkHAxS6J/twjTAZ2McHQ4XR/fhs1WSS1NGUGj/jDf09dQOLLUlJEXb+HyrMikw OssnuHYl7WxWQ== Message-ID: <01b4b502db610db7e100a6a1371acd8633a5dbb7.camel@kernel.org> Subject: Re: [RFC PATCH 07/53] netfs: Provide invalidate_folio and release_folio calls From: Jeff Layton To: David Howells , Steve French Cc: Matthew Wilcox , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Dominique Martinet , Ilya Dryomov , Christian Brauner , 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, linux-cachefs@redhat.com Date: Mon, 16 Oct 2023 11:50:49 -0400 In-Reply-To: <20231013160423.2218093-8-dhowells@redhat.com> References: <20231013160423.2218093-1-dhowells@redhat.com> <20231013160423.2218093-8-dhowells@redhat.com> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 16 Oct 2023 08:51:07 -0700 (PDT) On Fri, 2023-10-13 at 17:03 +0100, David Howells wrote: > Provide default invalidate_folio and release_folio calls. These will nee= d > to interact with invalidation correctly at some point. They will be need= ed > if netfslib is to make use of folio->private for its own purposes. >=20 > 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/9p/vfs_addr.c | 33 ++------------------------- > fs/afs/file.c | 53 ++++--------------------------------------- > fs/ceph/addr.c | 24 ++------------------ > fs/netfs/Makefile | 1 + > fs/netfs/misc.c | 51 +++++++++++++++++++++++++++++++++++++++++ > include/linux/netfs.h | 6 +++-- > 6 files changed, 64 insertions(+), 104 deletions(-) > create mode 100644 fs/netfs/misc.c >=20 > diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c > index 8a635999a7d6..18a666c43e4a 100644 > --- a/fs/9p/vfs_addr.c > +++ b/fs/9p/vfs_addr.c > @@ -104,35 +104,6 @@ const struct netfs_request_ops v9fs_req_ops =3D { > .issue_read =3D v9fs_issue_read, > }; > =20 > -/** > - * v9fs_release_folio - release the private state associated with a foli= o > - * @folio: The folio to be released > - * @gfp: The caller's allocation restrictions > - * > - * Returns true if the page can be released, false otherwise. > - */ > - > -static bool v9fs_release_folio(struct folio *folio, gfp_t gfp) > -{ > - if (folio_test_private(folio)) > - return false; > -#ifdef CONFIG_9P_FSCACHE > - if (folio_test_fscache(folio)) { > - if (current_is_kswapd() || !(gfp & __GFP_FS)) > - return false; > - folio_wait_fscache(folio); > - } > - fscache_note_page_release(v9fs_inode_cookie(V9FS_I(folio_inode(folio)))= ); > -#endif > - return true; > -} > - > -static void v9fs_invalidate_folio(struct folio *folio, size_t offset, > - size_t length) > -{ > - folio_wait_fscache(folio); > -} > - > #ifdef CONFIG_9P_FSCACHE > static void v9fs_write_to_cache_done(void *priv, ssize_t transferred_or_= error, > bool was_async) > @@ -355,8 +326,8 @@ const struct address_space_operations v9fs_addr_opera= tions =3D { > .writepage =3D v9fs_vfs_writepage, > .write_begin =3D v9fs_write_begin, > .write_end =3D v9fs_write_end, > - .release_folio =3D v9fs_release_folio, > - .invalidate_folio =3D v9fs_invalidate_folio, > + .release_folio =3D netfs_release_folio, > + .invalidate_folio =3D netfs_invalidate_folio, > .launder_folio =3D v9fs_launder_folio, > .direct_IO =3D v9fs_direct_IO, > }; > diff --git a/fs/afs/file.c b/fs/afs/file.c > index 0c49b3b6f214..3fea5cd8ef13 100644 > --- a/fs/afs/file.c > +++ b/fs/afs/file.c > @@ -20,9 +20,6 @@ > =20 > static int afs_file_mmap(struct file *file, struct vm_area_struct *vma); > static int afs_symlink_read_folio(struct file *file, struct folio *folio= ); > -static void afs_invalidate_folio(struct folio *folio, size_t offset, > - size_t length); > -static bool afs_release_folio(struct folio *folio, gfp_t gfp_flags); > =20 > static ssize_t afs_file_read_iter(struct kiocb *iocb, struct iov_iter *i= ter); > static ssize_t afs_file_splice_read(struct file *in, loff_t *ppos, > @@ -57,8 +54,8 @@ const struct address_space_operations afs_file_aops =3D= { > .readahead =3D netfs_readahead, > .dirty_folio =3D afs_dirty_folio, > .launder_folio =3D afs_launder_folio, > - .release_folio =3D afs_release_folio, > - .invalidate_folio =3D afs_invalidate_folio, > + .release_folio =3D netfs_release_folio, > + .invalidate_folio =3D netfs_invalidate_folio, > .write_begin =3D afs_write_begin, > .write_end =3D afs_write_end, > .writepages =3D afs_writepages, > @@ -67,8 +64,8 @@ const struct address_space_operations afs_file_aops =3D= { > =20 > const struct address_space_operations afs_symlink_aops =3D { > .read_folio =3D afs_symlink_read_folio, > - .release_folio =3D afs_release_folio, > - .invalidate_folio =3D afs_invalidate_folio, > + .release_folio =3D netfs_release_folio, > + .invalidate_folio =3D netfs_invalidate_folio, > .migrate_folio =3D filemap_migrate_folio, > }; > =20 > @@ -405,48 +402,6 @@ int afs_write_inode(struct inode *inode, struct writ= eback_control *wbc) > return 0; > } > =20 > -/* > - * invalidate part or all of a page > - * - release a page and clean up its private data if offset is 0 (indica= ting > - * the entire page) > - */ > -static void afs_invalidate_folio(struct folio *folio, size_t offset, > - size_t length) > -{ > - _enter("{%lu},%zu,%zu", folio->index, offset, length); > - > - folio_wait_fscache(folio); > - _leave(""); > -} > - > -/* > - * release a page and clean up its private state if it's not busy > - * - return true if the page can now be released, false if not > - */ > -static bool afs_release_folio(struct folio *folio, gfp_t gfp) > -{ > - struct afs_vnode *vnode =3D AFS_FS_I(folio_inode(folio)); > - > - _enter("{{%llx:%llu}[%lu],%lx},%x", > - vnode->fid.vid, vnode->fid.vnode, folio_index(folio), folio->fla= gs, > - gfp); > - > - /* deny if folio is being written to the cache and the caller hasn't > - * elected to wait */ > -#ifdef CONFIG_AFS_FSCACHE > - if (folio_test_fscache(folio)) { > - if (current_is_kswapd() || !(gfp & __GFP_FS)) > - return false; > - folio_wait_fscache(folio); > - } > - fscache_note_page_release(afs_vnode_cache(vnode)); > -#endif > - > - /* Indicate that the folio can be released */ > - _leave(" =3D T"); > - return true; > -} > - > static void afs_add_open_mmap(struct afs_vnode *vnode) > { > if (atomic_inc_return(&vnode->cb_nr_mmap) =3D=3D 1) { > diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c > index f4863078f7fe..ced19ff08988 100644 > --- a/fs/ceph/addr.c > +++ b/fs/ceph/addr.c > @@ -160,27 +160,7 @@ static void ceph_invalidate_folio(struct folio *foli= o, size_t offset, > ceph_put_snap_context(snapc); > } > =20 > - folio_wait_fscache(folio); > -} > - > -static bool ceph_release_folio(struct folio *folio, gfp_t gfp) > -{ > - struct inode *inode =3D folio->mapping->host; > - > - dout("%llx:%llx release_folio idx %lu (%sdirty)\n", > - ceph_vinop(inode), > - folio->index, folio_test_dirty(folio) ? "" : "not "); > - > - if (folio_test_private(folio)) > - return false; > - > - if (folio_test_fscache(folio)) { > - if (current_is_kswapd() || !(gfp & __GFP_FS)) > - return false; > - folio_wait_fscache(folio); > - } > - ceph_fscache_note_page_release(inode); > - return true; > + netfs_invalidate_folio(folio, offset, length); > } > =20 > static void ceph_netfs_expand_readahead(struct netfs_io_request *rreq) > @@ -1563,7 +1543,7 @@ const struct address_space_operations ceph_aops =3D= { > .write_end =3D ceph_write_end, > .dirty_folio =3D ceph_dirty_folio, > .invalidate_folio =3D ceph_invalidate_folio, > - .release_folio =3D ceph_release_folio, > + .release_folio =3D netfs_release_folio, > .direct_IO =3D noop_direct_IO, > }; > =20 > diff --git a/fs/netfs/Makefile b/fs/netfs/Makefile > index 386d6fb92793..cd22554d9048 100644 > --- a/fs/netfs/Makefile > +++ b/fs/netfs/Makefile > @@ -5,6 +5,7 @@ netfs-y :=3D \ > io.o \ > iterator.o \ > main.o \ > + misc.o \ > objects.o > =20 > netfs-$(CONFIG_NETFS_STATS) +=3D stats.o > diff --git a/fs/netfs/misc.c b/fs/netfs/misc.c > new file mode 100644 > index 000000000000..c3baf2b247d9 > --- /dev/null > +++ b/fs/netfs/misc.c > @@ -0,0 +1,51 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* Miscellaneous routines. > + * > + * Copyright (C) 2022 Red Hat, Inc. All Rights Reserved. > + * Written by David Howells (dhowells@redhat.com) > + */ > + > +#include > +#include "internal.h" > + > +/** > + * netfs_invalidate_folio - Invalidate or partially invalidate a folio > + * @folio: Folio proposed for release > + * @offset: Offset of the invalidated region > + * @length: Length of the invalidated region > + * > + * Invalidate part or all of a folio for a network filesystem. The foli= o will > + * be removed afterwards if the invalidated region covers the entire fol= io. > + */ > +void netfs_invalidate_folio(struct folio *folio, size_t offset, size_t l= ength) > +{ > + _enter("{%lx},%zx,%zx", folio_index(folio), offset, length); > + > + folio_wait_fscache(folio); > +} > +EXPORT_SYMBOL(netfs_invalidate_folio); > + > +/** > + * netfs_release_folio - Try to release a folio > + * @folio: Folio proposed for release > + * @gfp: Flags qualifying the release > + * > + * Request release of a folio and clean up its private state if it's not= busy. > + * Returns true if the folio can now be released, false if not > + */ > +bool netfs_release_folio(struct folio *folio, gfp_t gfp) > +{ > + struct netfs_inode *ctx =3D netfs_inode(folio_inode(folio)); > + > + if (folio_test_private(folio)) > + return false; > + if (folio_test_fscache(folio)) { > + if (current_is_kswapd() || !(gfp & __GFP_FS)) > + return false; > + folio_wait_fscache(folio); > + } > + > + fscache_note_page_release(netfs_i_cookie(ctx)); > + return true; > +} > +EXPORT_SYMBOL(netfs_release_folio); > diff --git a/include/linux/netfs.h b/include/linux/netfs.h > index ed64d1034afa..daa431c4148d 100644 > --- a/include/linux/netfs.h > +++ b/include/linux/netfs.h > @@ -299,8 +299,10 @@ struct readahead_control; > void netfs_readahead(struct readahead_control *); > int netfs_read_folio(struct file *, struct folio *); > int netfs_write_begin(struct netfs_inode *, struct file *, > - struct address_space *, loff_t pos, unsigned int len, > - struct folio **, void **fsdata); > + struct address_space *, loff_t pos, unsigned int len, > + struct folio **, void **fsdata); > +void netfs_invalidate_folio(struct folio *folio, size_t offset, size_t l= ength); > +bool netfs_release_folio(struct folio *folio, gfp_t gfp); > =20 > void netfs_subreq_terminated(struct netfs_io_subrequest *, ssize_t, bool= ); > void netfs_get_subrequest(struct netfs_io_subrequest *subreq, >=20 Nice cleanup. Might can merge this in advance of the rest of the series. Reviewed-by: Jeff Layton