netfs: Allocate multipage folios in the writepath
authorDavid Howells <dhowells@redhat.com>
Fri, 29 Sep 2023 19:11:31 +0000 (20:11 +0100)
committerDavid Howells <dhowells@redhat.com>
Thu, 28 Dec 2023 09:45:23 +0000 (09:45 +0000)
Allocate a multipage folio when copying data into the pagecache if possible
if there's sufficient data to warrant it.

Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: linux-cachefs@redhat.com
cc: linux-fsdevel@vger.kernel.org
cc: linux-mm@kvack.org

fs/netfs/buffered_write.c

index 6e7f06d9962db87120929f116ba607fe058c9bcf..b76688e98f819e24f381a5d32fe91545badf671e 100644 (file)
@@ -84,14 +84,19 @@ static enum netfs_how_to_modify netfs_how_to_modify(struct netfs_inode *ctx,
 }
 
 /*
- * Grab a folio for writing and lock it.
+ * Grab a folio for writing and lock it.  Attempt to allocate as large a folio
+ * as possible to hold as much of the remaining length as possible in one go.
  */
 static struct folio *netfs_grab_folio_for_write(struct address_space *mapping,
                                                loff_t pos, size_t part)
 {
        pgoff_t index = pos / PAGE_SIZE;
+       fgf_t fgp_flags = FGP_WRITEBEGIN;
 
-       return __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
+       if (mapping_large_folio_support(mapping))
+               fgp_flags |= fgf_set_order(pos % PAGE_SIZE + part);
+
+       return __filemap_get_folio(mapping, index, fgp_flags,
                                   mapping_gfp_mask(mapping));
 }