From patchwork Thu Jan 26 20:23:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117733 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79260C05027 for ; Thu, 26 Jan 2023 20:24:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232897AbjAZUYt (ORCPT ); Thu, 26 Jan 2023 15:24:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232819AbjAZUY1 (ORCPT ); Thu, 26 Jan 2023 15:24:27 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16810521D8; Thu, 26 Jan 2023 12:24:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=2sAKchd+/xLc3BTWuGB2vL7TWMKySAwLf+zsISLSa+4=; b=XrvaJPi5N4vo6xrhVJNQNLbi+p sixnmZflWuhamZzLSk0LhcfdB8zy0TifCcHG1SxfbuWaxNP4LHJ5NBCsF4/hGnN6Ys8hIoU3ECYGM IpBJskeN82izFHNAUwzpz0fJIlvHrRWTm1wl1lKfH/SJFPhFoY/tXfCJI89/SV5ryGXwZ52wbB9dI MzlxjIqFaFJSYv25pioFkoicbFrfFy8W14mFqzgP0s3PtrVffafrpYfCVLhsluPHPCL6y7288lklq y612KmKTXQ/wwDIdAZIJt2j94zHxHzGh1jGLdJJX3XJhcZbJOCt44YosbK/9muXbH2uIJ7x+h05oY bkQmj4FA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nC-0073jM-Id; Thu, 26 Jan 2023 20:24:18 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 01/31] fs: Add FGP_WRITEBEGIN Date: Thu, 26 Jan 2023 20:23:45 +0000 Message-Id: <20230126202415.1682629-2-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This particular combination of flags is used by most filesystems in their ->write_begin method, although it does find use in a few other places. Before folios, it warranted its own function (grab_cache_page_write_begin()), but I think that just having specialised flags is enough. It certainly helps the few places that have been converted from grab_cache_page_write_begin() to __filemap_get_folio(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Ritesh Harjani (IBM) Reviewed-by: Theodore Ts'o --- fs/ext4/move_extent.c | 5 ++--- fs/iomap/buffered-io.c | 2 +- fs/netfs/buffered_read.c | 3 +-- include/linux/pagemap.h | 2 ++ mm/folio-compat.c | 4 +--- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 2de9829aed63..0cb361f0a4fe 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -126,7 +126,6 @@ mext_folio_double_lock(struct inode *inode1, struct inode *inode2, { struct address_space *mapping[2]; unsigned int flags; - unsigned fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE; BUG_ON(!inode1 || !inode2); if (inode1 < inode2) { @@ -139,14 +138,14 @@ mext_folio_double_lock(struct inode *inode1, struct inode *inode2, } flags = memalloc_nofs_save(); - folio[0] = __filemap_get_folio(mapping[0], index1, fgp_flags, + folio[0] = __filemap_get_folio(mapping[0], index1, FGP_WRITEBEGIN, mapping_gfp_mask(mapping[0])); if (!folio[0]) { memalloc_nofs_restore(flags); return -ENOMEM; } - folio[1] = __filemap_get_folio(mapping[1], index2, fgp_flags, + folio[1] = __filemap_get_folio(mapping[1], index2, FGP_WRITEBEGIN, mapping_gfp_mask(mapping[1])); memalloc_nofs_restore(flags); if (!folio[1]) { diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 6f4c97a6d7e9..10a203515583 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -467,7 +467,7 @@ EXPORT_SYMBOL_GPL(iomap_is_partially_uptodate); */ struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos) { - unsigned fgp = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE | FGP_NOFS; + unsigned fgp = FGP_WRITEBEGIN | FGP_NOFS; struct folio *folio; if (iter->flags & IOMAP_NOWAIT) diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c index 7679a68e8193..e3d754a9e1b0 100644 --- a/fs/netfs/buffered_read.c +++ b/fs/netfs/buffered_read.c @@ -341,14 +341,13 @@ int netfs_write_begin(struct netfs_inode *ctx, { struct netfs_io_request *rreq; struct folio *folio; - unsigned int fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE; pgoff_t index = pos >> PAGE_SHIFT; int ret; DEFINE_READAHEAD(ractl, file, NULL, mapping, index); retry: - folio = __filemap_get_folio(mapping, index, fgp_flags, + folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN, mapping_gfp_mask(mapping)); if (!folio) return -ENOMEM; diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 9f1081683771..47069662f4b8 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -507,6 +507,8 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping, #define FGP_ENTRY 0x00000080 #define FGP_STABLE 0x00000100 +#define FGP_WRITEBEGIN (FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE) + struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, int fgp_flags, gfp_t gfp); struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index, diff --git a/mm/folio-compat.c b/mm/folio-compat.c index 18c48b557926..668350748828 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -106,9 +106,7 @@ EXPORT_SYMBOL(pagecache_get_page); struct page *grab_cache_page_write_begin(struct address_space *mapping, pgoff_t index) { - unsigned fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE; - - return pagecache_get_page(mapping, index, fgp_flags, + return pagecache_get_page(mapping, index, FGP_WRITEBEGIN, mapping_gfp_mask(mapping)); } EXPORT_SYMBOL(grab_cache_page_write_begin); From patchwork Thu Jan 26 20:23:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117710 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B47EAC61DA3 for ; Thu, 26 Jan 2023 20:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232781AbjAZUYX (ORCPT ); Thu, 26 Jan 2023 15:24:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229851AbjAZUYW (ORCPT ); Thu, 26 Jan 2023 15:24:22 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DDE1227B3; Thu, 26 Jan 2023 12:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=JxIQZn3422NDRY12n3JlUPEqNl1W1UN0M9UUk/21xXM=; b=T6Ay8mfAYuSc+NIdbPNt/22zLu GwR8VR1dDxaZtsSonYe/KSslkeADUfr7xnd1gcytQamWjAObCqCSPPCoX/EzWnuSEJrR+u5+eNbui R/trHdABnl2oBfjhIyV2c50fuVZnoPCdpvb0jJpngzOO3gkC9DghE5o/wPkQFXuTvkeBI6T49319x cNMuVf1Qibh1eOQ3N5IenEg93En0+gPdLgY/zdPMQ7r5fW2oNQ49tFx0U21DujCzKpKecM25KaFJN 8LGGMzIcICQh9urodOyJW9lsTQVRIO3pzgEZs4KHciiHPLH7o7IQ+vIxJ++sFOZFWFjXr9WUnnlSB z/stQl9g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nC-0073jO-Kn; Thu, 26 Jan 2023 20:24:18 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 02/31] fscrypt: Add some folio helper functions Date: Thu, 26 Jan 2023 20:23:46 +0000 Message-Id: <20230126202415.1682629-3-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org fscrypt_is_bounce_folio() is the equivalent of fscrypt_is_bounce_page() and fscrypt_pagecache_folio() is the equivalent of fscrypt_pagecache_page(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Ritesh Harjani (IBM) --- include/linux/fscrypt.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h index 4f5f8a651213..c2c07d36fb3a 100644 --- a/include/linux/fscrypt.h +++ b/include/linux/fscrypt.h @@ -273,6 +273,16 @@ static inline struct page *fscrypt_pagecache_page(struct page *bounce_page) return (struct page *)page_private(bounce_page); } +static inline bool fscrypt_is_bounce_folio(struct folio *folio) +{ + return folio->mapping == NULL; +} + +static inline struct folio *fscrypt_pagecache_folio(struct folio *bounce_folio) +{ + return bounce_folio->private; +} + void fscrypt_free_bounce_page(struct page *bounce_page); /* policy.c */ @@ -448,6 +458,17 @@ static inline struct page *fscrypt_pagecache_page(struct page *bounce_page) return ERR_PTR(-EINVAL); } +static inline bool fscrypt_is_bounce_folio(struct folio *folio) +{ + return false; +} + +static inline struct folio *fscrypt_pagecache_folio(struct folio *bounce_folio) +{ + WARN_ON_ONCE(1); + return ERR_PTR(-EINVAL); +} + static inline void fscrypt_free_bounce_page(struct page *bounce_page) { } From patchwork Thu Jan 26 20:23:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117736 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C0A7C61DA3 for ; Thu, 26 Jan 2023 20:25:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232903AbjAZUZN (ORCPT ); Thu, 26 Jan 2023 15:25:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232841AbjAZUYf (ORCPT ); Thu, 26 Jan 2023 15:24:35 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5CD64B4B0; Thu, 26 Jan 2023 12:24:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=7RNlhF8CRIANN0d8CRWQ0o803TuHroT7WJqd3rajUk4=; b=Mmy/sKUFAN+RkaB5RN6pK8ftND iy4+3icZ4q8wA6tUIVjXnocvgcA/lStN2pGmRbqUzzDEvPVL/Jn65lnV+Rj/F24FPd4LCbuVv6oTm 3B3sEwtTc969wKLxagJCj5lDABynaL6rTFR8aoS0ekcr8i3NrKu5rRe/GleO7S7J530i2nbX5wCH+ f96PIzONNaVqp6eeHaC4/wGXRNnQQt0l/HfVBZWhlAAcWiSBoCmpixh9dGEiVKob1NiJZL+2ppRD0 C1Tv4QbOU7lxj11Hlj40jppEJmGD+jKbVBsIKZ8Tr9GuPXPZ4iv78UupeE1RI4usKU835X+IhwBJt 0VPvkktg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nC-0073jQ-N1; Thu, 26 Jan 2023 20:24:18 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 03/31] ext4: Convert ext4_bio_write_page() to use a folio Date: Thu, 26 Jan 2023 20:23:47 +0000 Message-Id: <20230126202415.1682629-4-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Remove several calls to compound_head() and the last caller of set_page_writeback_keepwrite(), so remove the wrapper too. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Ritesh Harjani (IBM) Reviewed-by: Theodore Ts'o --- fs/ext4/page-io.c | 58 ++++++++++++++++++-------------------- include/linux/page-flags.h | 5 ---- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c index beaec6d81074..982791050892 100644 --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -409,11 +409,9 @@ static void io_submit_init_bio(struct ext4_io_submit *io, static void io_submit_add_bh(struct ext4_io_submit *io, struct inode *inode, - struct page *page, + struct folio *folio, struct buffer_head *bh) { - int ret; - if (io->io_bio && (bh->b_blocknr != io->io_next_block || !fscrypt_mergeable_bio_bh(io->io_bio, bh))) { submit_and_retry: @@ -421,10 +419,9 @@ static void io_submit_add_bh(struct ext4_io_submit *io, } if (io->io_bio == NULL) io_submit_init_bio(io, bh); - ret = bio_add_page(io->io_bio, page, bh->b_size, bh_offset(bh)); - if (ret != bh->b_size) + if (!bio_add_folio(io->io_bio, folio, bh->b_size, bh_offset(bh))) goto submit_and_retry; - wbc_account_cgroup_owner(io->io_wbc, page, bh->b_size); + wbc_account_cgroup_owner(io->io_wbc, &folio->page, bh->b_size); io->io_next_block++; } @@ -432,8 +429,9 @@ int ext4_bio_write_page(struct ext4_io_submit *io, struct page *page, int len) { - struct page *bounce_page = NULL; - struct inode *inode = page->mapping->host; + struct folio *folio = page_folio(page); + struct folio *io_folio = folio; + struct inode *inode = folio->mapping->host; unsigned block_start; struct buffer_head *bh, *head; int ret = 0; @@ -441,30 +439,30 @@ int ext4_bio_write_page(struct ext4_io_submit *io, struct writeback_control *wbc = io->io_wbc; bool keep_towrite = false; - BUG_ON(!PageLocked(page)); - BUG_ON(PageWriteback(page)); + BUG_ON(!folio_test_locked(folio)); + BUG_ON(folio_test_writeback(folio)); - ClearPageError(page); + folio_clear_error(folio); /* * Comments copied from block_write_full_page: * - * The page straddles i_size. It must be zeroed out on each and every + * The folio straddles i_size. It must be zeroed out on each and every * writepage invocation because it may be mmapped. "A file is mapped * in multiples of the page size. For a file that is not a multiple of * the page size, the remaining memory is zeroed when mapped, and * writes to that region are not written out to the file." */ - if (len < PAGE_SIZE) - zero_user_segment(page, len, PAGE_SIZE); + if (len < folio_size(folio)) + folio_zero_segment(folio, len, folio_size(folio)); /* * In the first loop we prepare and mark buffers to submit. We have to - * mark all buffers in the page before submitting so that - * end_page_writeback() cannot be called from ext4_end_bio() when IO + * mark all buffers in the folio before submitting so that + * folio_end_writeback() cannot be called from ext4_end_bio() when IO * on the first buffer finishes and we are still working on submitting * the second buffer. */ - bh = head = page_buffers(page); + bh = head = folio_buffers(folio); do { block_start = bh_offset(bh); if (block_start >= len) { @@ -479,14 +477,14 @@ int ext4_bio_write_page(struct ext4_io_submit *io, clear_buffer_dirty(bh); /* * Keeping dirty some buffer we cannot write? Make sure - * to redirty the page and keep TOWRITE tag so that - * racing WB_SYNC_ALL writeback does not skip the page. + * to redirty the folio and keep TOWRITE tag so that + * racing WB_SYNC_ALL writeback does not skip the folio. * This happens e.g. when doing writeout for * transaction commit. */ if (buffer_dirty(bh)) { - if (!PageDirty(page)) - redirty_page_for_writepage(wbc, page); + if (!folio_test_dirty(folio)) + folio_redirty_for_writepage(wbc, folio); keep_towrite = true; } continue; @@ -498,11 +496,11 @@ int ext4_bio_write_page(struct ext4_io_submit *io, nr_to_submit++; } while ((bh = bh->b_this_page) != head); - /* Nothing to submit? Just unlock the page... */ + /* Nothing to submit? Just unlock the folio... */ if (!nr_to_submit) goto unlock; - bh = head = page_buffers(page); + bh = head = folio_buffers(folio); /* * If any blocks are being written to an encrypted file, encrypt them @@ -514,6 +512,7 @@ int ext4_bio_write_page(struct ext4_io_submit *io, if (fscrypt_inode_uses_fs_layer_crypto(inode) && nr_to_submit) { gfp_t gfp_flags = GFP_NOFS; unsigned int enc_bytes = round_up(len, i_blocksize(inode)); + struct page *bounce_page; /* * Since bounce page allocation uses a mempool, we can only use @@ -540,7 +539,7 @@ int ext4_bio_write_page(struct ext4_io_submit *io, } printk_ratelimited(KERN_ERR "%s: ret = %d\n", __func__, ret); - redirty_page_for_writepage(wbc, page); + folio_redirty_for_writepage(wbc, folio); do { if (buffer_async_write(bh)) { clear_buffer_async_write(bh); @@ -550,21 +549,18 @@ int ext4_bio_write_page(struct ext4_io_submit *io, } while (bh != head); goto unlock; } + io_folio = page_folio(bounce_page); } - if (keep_towrite) - set_page_writeback_keepwrite(page); - else - set_page_writeback(page); + __folio_start_writeback(folio, keep_towrite); /* Now submit buffers to write */ do { if (!buffer_async_write(bh)) continue; - io_submit_add_bh(io, inode, - bounce_page ? bounce_page : page, bh); + io_submit_add_bh(io, inode, io_folio, bh); } while ((bh = bh->b_this_page) != head); unlock: - unlock_page(page); + folio_unlock(folio); return ret; } diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 0425f22a9c82..bba2a32031a2 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -766,11 +766,6 @@ bool set_page_writeback(struct page *page); #define folio_start_writeback_keepwrite(folio) \ __folio_start_writeback(folio, true) -static inline void set_page_writeback_keepwrite(struct page *page) -{ - folio_start_writeback_keepwrite(page_folio(page)); -} - static inline bool test_set_page_writeback(struct page *page) { return set_page_writeback(page); From patchwork Thu Jan 26 20:23:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117738 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B158C61DA3 for ; Thu, 26 Jan 2023 20:25:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232494AbjAZUZW (ORCPT ); Thu, 26 Jan 2023 15:25:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232892AbjAZUYs (ORCPT ); Thu, 26 Jan 2023 15:24:48 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB91B728FF; Thu, 26 Jan 2023 12:24:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=JdCYJMco6hlB0IW965/2KYMMtiwws4SrqZg6+IdXOU8=; b=HUNjVvUGuJx+0HAEp/2gLDOZxE RcmyaRg5NCoRNoGam7b35KkOKvSC5Qdkb72ViFg0SU7jLNu39v6X+HTLsv+yDGk71xOgfI5i92ZEV malEiNHT1QgcZTERKPVfyeoLvm3WByKh+iRk4XMv6+J08xNg0EhQv8YcZw8+jBYJB65M9+XARuQJQ wxVcMoXRyGs2bFAkTTUmv9WuEyZShRrJ5k0LRoZGGnXLZiCw7j8cnlUr2SI+IrDPMUrTpCPnyHo7o QTcTzgcQuMhphMdifrpTxSJmwA+nWAcaZRgWa5nHA5gTz/31B3FcTq7a3n2YySpfF2iahlPKAO+wi c/oc2scQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nC-0073jS-Pu; Thu, 26 Jan 2023 20:24:18 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 04/31] ext4: Convert ext4_finish_bio() to use folios Date: Thu, 26 Jan 2023 20:23:48 +0000 Message-Id: <20230126202415.1682629-5-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Prepare ext4 to support large folios in the page writeback path. Also set the actual error in the mapping, not just -EIO. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Ritesh Harjani (IBM) Reviewed-by: Theodore Ts'o --- fs/ext4/page-io.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c index 982791050892..fd6c0dca24b9 100644 --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -99,30 +99,30 @@ static void buffer_io_error(struct buffer_head *bh) static void ext4_finish_bio(struct bio *bio) { - struct bio_vec *bvec; - struct bvec_iter_all iter_all; + struct folio_iter fi; - bio_for_each_segment_all(bvec, bio, iter_all) { - struct page *page = bvec->bv_page; - struct page *bounce_page = NULL; + bio_for_each_folio_all(fi, bio) { + struct folio *folio = fi.folio; + struct folio *io_folio = NULL; struct buffer_head *bh, *head; - unsigned bio_start = bvec->bv_offset; - unsigned bio_end = bio_start + bvec->bv_len; + size_t bio_start = fi.offset; + size_t bio_end = bio_start + fi.length; unsigned under_io = 0; unsigned long flags; - if (fscrypt_is_bounce_page(page)) { - bounce_page = page; - page = fscrypt_pagecache_page(bounce_page); + if (fscrypt_is_bounce_folio(folio)) { + io_folio = folio; + folio = fscrypt_pagecache_folio(folio); } if (bio->bi_status) { - SetPageError(page); - mapping_set_error(page->mapping, -EIO); + int err = blk_status_to_errno(bio->bi_status); + folio_set_error(folio); + mapping_set_error(folio->mapping, err); } - bh = head = page_buffers(page); + bh = head = folio_buffers(folio); /* - * We check all buffers in the page under b_uptodate_lock + * We check all buffers in the folio under b_uptodate_lock * to avoid races with other end io clearing async_write flags */ spin_lock_irqsave(&head->b_uptodate_lock, flags); @@ -141,8 +141,8 @@ static void ext4_finish_bio(struct bio *bio) } while ((bh = bh->b_this_page) != head); spin_unlock_irqrestore(&head->b_uptodate_lock, flags); if (!under_io) { - fscrypt_free_bounce_page(bounce_page); - end_page_writeback(page); + fscrypt_free_bounce_page(&io_folio->page); + folio_end_writeback(folio); } } } From patchwork Thu Jan 26 20:23:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117737 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55256C54EAA for ; Thu, 26 Jan 2023 20:25:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232920AbjAZUZQ (ORCPT ); Thu, 26 Jan 2023 15:25:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232879AbjAZUYr (ORCPT ); Thu, 26 Jan 2023 15:24:47 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E51E45CFF5; Thu, 26 Jan 2023 12:24:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Is+CzdfeZTOFVXgC1e+4dswS9N91ktanRCcZICGzugo=; b=fq0qVPC4reDzxrrLeF5yX7aC1Z H9LjsQO+LR1umR/s03fJqYyhzv80fJyhOKpcarR8Cy7wSLcplnwUJlbrM9Me+IILje6LaMKmkwnv/ +YTwHj/vZanxmHv+HRw6xOsgvisjJ3AqYSkSBa1p5QYNukzjoRYtXgqdG0OvLfaLBmJeSiw+KtkN8 zBo2cFwwq7SWBAnNn8Vd5Cwetlmq1jGFv9YFZ/YzLkjUHcJVtWcEwn3trCyLNc5dJkaUxWOmaUYbx EoAOUFc1F6Pc/ry8D4r3DqRSH6w7sBK109PEeR8YJ6jjvJMRKEzLLZqyyEJGezJOQT26vcRAsfHhw 3wd+VMxQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nC-0073jU-Sb; Thu, 26 Jan 2023 20:24:18 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 05/31] ext4: Convert ext4_writepage() to use a folio Date: Thu, 26 Jan 2023 20:23:49 +0000 Message-Id: <20230126202415.1682629-6-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Prepare for multi-page folios and save some instructions by converting to the folio API. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Ritesh Harjani (IBM) --- fs/ext4/inode.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index b8b3e2e0d9fd..8e3d2cca1e0c 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2027,26 +2027,25 @@ static int ext4_writepage(struct page *page, trace_ext4_writepage(page); size = i_size_read(inode); - if (page->index == size >> PAGE_SHIFT && + len = folio_size(folio); + if (folio_pos(folio) + len > size && !ext4_verity_in_progress(inode)) - len = size & ~PAGE_MASK; - else - len = PAGE_SIZE; + len = size - folio_pos(folio); + page_bufs = folio_buffers(folio); /* Should never happen but for bugs in other kernel subsystems */ - if (!page_has_buffers(page)) { + if (!page_bufs) { ext4_warning_inode(inode, - "page %lu does not have buffers attached", page->index); - ClearPageDirty(page); - unlock_page(page); + "page %lu does not have buffers attached", folio->index); + folio_clear_dirty(folio); + folio_unlock(folio); return 0; } - page_bufs = page_buffers(page); /* * We cannot do block allocation or other extent handling in this * function. If there are buffers needing that, we have to redirty - * the page. But we may reach here when we do a journal commit via + * the folio. But we may reach here when we do a journal commit via * journal_submit_inode_data_buffers() and in that case we must write * allocated buffers to achieve data=ordered mode guarantees. * @@ -2062,7 +2061,7 @@ static int ext4_writepage(struct page *page, */ if (ext4_walk_page_buffers(NULL, inode, page_bufs, 0, len, NULL, ext4_bh_delay_or_unwritten)) { - redirty_page_for_writepage(wbc, page); + folio_redirty_for_writepage(wbc, folio); if ((current->flags & PF_MEMALLOC) || (inode->i_sb->s_blocksize == PAGE_SIZE)) { /* @@ -2072,12 +2071,12 @@ static int ext4_writepage(struct page *page, */ WARN_ON_ONCE((current->flags & (PF_MEMALLOC|PF_KSWAPD)) == PF_MEMALLOC); - unlock_page(page); + folio_unlock(folio); return 0; } } - if (PageChecked(page) && ext4_should_journal_data(inode)) + if (folio_test_checked(folio) && ext4_should_journal_data(inode)) /* * It's mmapped pagecache. Add buffers and journal it. There * doesn't seem much point in redirtying the page here. @@ -2087,8 +2086,8 @@ static int ext4_writepage(struct page *page, ext4_io_submit_init(&io_submit, wbc); io_submit.io_end = ext4_init_io_end(inode, GFP_NOFS); if (!io_submit.io_end) { - redirty_page_for_writepage(wbc, page); - unlock_page(page); + folio_redirty_for_writepage(wbc, folio); + folio_unlock(folio); return -ENOMEM; } ret = ext4_bio_write_page(&io_submit, page, len); From patchwork Thu Jan 26 20:23:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117734 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7AB9C61DA7 for ; Thu, 26 Jan 2023 20:24:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232913AbjAZUYx (ORCPT ); Thu, 26 Jan 2023 15:24:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232822AbjAZUY3 (ORCPT ); Thu, 26 Jan 2023 15:24:29 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03DB64CE57; Thu, 26 Jan 2023 12:24:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=GDuQ6wQ/bfAds1LW0fa92iuTDGoEEIeE4XVRE+IKeFU=; b=SD5fRj4pO4RQr88pcufpYuq1Ee zaNRUubk0tBfj8BhRFGidDiF4vpjpxUSZNWdJiELEe+RR/hJUQ7hUixSKiciYdtyEnQvKBDtvYguB iReH10mrFyMmn9cnhC7e0XBx17rKenopPgqT71ynE9j4yEs+45zlMJz0/4X+WSMCkATuQpQaJSQSR UtbC81C75FsHAhWdzzhcCnzQB4lLGq4wlUhnuf4yDAxyxSEi4A1qvtQOfnj3FrtyNB+i/tciBumG/ 3Js3+0rRaqVtuMaGhmYUslDCZpPMSj8oCHAAmKhAop8E9SBQwUBiMjzeQG3TO1o1g54UJVaiOmZbG CzgBra2w==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nC-0073jW-Vg; Thu, 26 Jan 2023 20:24:19 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 06/31] ext4: Turn mpage_process_page() into mpage_process_folio() Date: Thu, 26 Jan 2023 20:23:50 +0000 Message-Id: <20230126202415.1682629-7-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The page/folio is only used to extract the buffers, so this is a simple change. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Theodore Ts'o --- fs/ext4/inode.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 8e3d2cca1e0c..e8f2918fd854 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2250,21 +2250,22 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd, } /* - * mpage_process_page - update page buffers corresponding to changed extent and - * may submit fully mapped page for IO - * - * @mpd - description of extent to map, on return next extent to map - * @m_lblk - logical block mapping. - * @m_pblk - corresponding physical mapping. - * @map_bh - determines on return whether this page requires any further + * mpage_process_folio - update folio buffers corresponding to changed extent + * and may submit fully mapped page for IO + * @mpd: description of extent to map, on return next extent to map + * @folio: Contains these buffers. + * @m_lblk: logical block mapping. + * @m_pblk: corresponding physical mapping. + * @map_bh: determines on return whether this page requires any further * mapping or not. - * Scan given page buffers corresponding to changed extent and update buffer + * + * Scan given folio buffers corresponding to changed extent and update buffer * state according to new extent state. * We map delalloc buffers to their physical location, clear unwritten bits. - * If the given page is not fully mapped, we update @map to the next extent in - * the given page that needs mapping & return @map_bh as true. + * If the given folio is not fully mapped, we update @mpd to the next extent in + * the given folio that needs mapping & return @map_bh as true. */ -static int mpage_process_page(struct mpage_da_data *mpd, struct page *page, +static int mpage_process_folio(struct mpage_da_data *mpd, struct folio *folio, ext4_lblk_t *m_lblk, ext4_fsblk_t *m_pblk, bool *map_bh) { @@ -2277,14 +2278,14 @@ static int mpage_process_page(struct mpage_da_data *mpd, struct page *page, ssize_t io_end_size = 0; struct ext4_io_end_vec *io_end_vec = ext4_last_io_end_vec(io_end); - bh = head = page_buffers(page); + bh = head = folio_buffers(folio); do { if (lblk < mpd->map.m_lblk) continue; if (lblk >= mpd->map.m_lblk + mpd->map.m_len) { /* * Buffer after end of mapped extent. - * Find next buffer in the page to map. + * Find next buffer in the folio to map. */ mpd->map.m_len = 0; mpd->map.m_flags = 0; @@ -2357,9 +2358,9 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd) if (nr == 0) break; for (i = 0; i < nr; i++) { - struct page *page = &fbatch.folios[i]->page; + struct folio *folio = fbatch.folios[i]; - err = mpage_process_page(mpd, page, &lblk, &pblock, + err = mpage_process_folio(mpd, folio, &lblk, &pblock, &map_bh); /* * If map_bh is true, means page may require further bh @@ -2369,7 +2370,7 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd) if (err < 0 || map_bh) goto out; /* Page fully mapped - let IO run! */ - err = mpage_submit_page(mpd, page); + err = mpage_submit_page(mpd, &folio->page); if (err < 0) goto out; } From patchwork Thu Jan 26 20:23:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117739 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76763C54EAA for ; Thu, 26 Jan 2023 20:25:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232931AbjAZUZa (ORCPT ); Thu, 26 Jan 2023 15:25:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232893AbjAZUYs (ORCPT ); Thu, 26 Jan 2023 15:24:48 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD9DA61875; Thu, 26 Jan 2023 12:24:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=0j9u/ZuPqTgqTR+4p+jCsICMT8bSmT1HNBvq/sPzFs8=; b=YFXGF/UdiPBrSYza7smljAWmsQ w1b2lnIV+YKTNXkPc3/D2A6n9qKz3R4pGwHj8p39k/7LTfoPhoGbV7Yb+74tDvwChMl9ILSZ1vly4 XQj9d5LjxVqT5mkG3w7EidznxhlPk6H/yxd69ins0rqMEXs377qi4M/Fdjn6CE/FWGc+7sbJ90/kr dpHiJwhEpFVVPXOjS+dYHPo774KSNBZAKI3m5ekY4qquI62+gHrYXLZzYWDEAV2+meDElTN2Cz8cL bcgAhHfK/0EFPF2SdICONp/9Swesk78XON/bOIFSVpdsjVlq/0WHrgaK/cuijTcqn5c0C9naUHFNt b2tdeZmQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nD-0073jY-2Q; Thu, 26 Jan 2023 20:24:19 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 07/31] ext4: Convert mpage_submit_page() to mpage_submit_folio() Date: Thu, 26 Jan 2023 20:23:51 +0000 Message-Id: <20230126202415.1682629-8-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org All callers now have a folio so we can pass one in and use the folio APIs to support large folios as well as save instructions by eliminating calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Theodore Ts'o --- fs/ext4/inode.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index e8f2918fd854..8b91e325492f 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2097,34 +2097,33 @@ static int ext4_writepage(struct page *page, return ret; } -static int mpage_submit_page(struct mpage_da_data *mpd, struct page *page) +static int mpage_submit_folio(struct mpage_da_data *mpd, struct folio *folio) { - int len; + size_t len; loff_t size; int err; - BUG_ON(page->index != mpd->first_page); - clear_page_dirty_for_io(page); + BUG_ON(folio->index != mpd->first_page); + folio_clear_dirty_for_io(folio); /* * We have to be very careful here! Nothing protects writeback path * against i_size changes and the page can be writeably mapped into * page tables. So an application can be growing i_size and writing - * data through mmap while writeback runs. clear_page_dirty_for_io() + * data through mmap while writeback runs. folio_clear_dirty_for_io() * write-protects our page in page tables and the page cannot get - * written to again until we release page lock. So only after - * clear_page_dirty_for_io() we are safe to sample i_size for + * written to again until we release folio lock. So only after + * folio_clear_dirty_for_io() we are safe to sample i_size for * ext4_bio_write_page() to zero-out tail of the written page. We rely * on the barrier provided by TestClearPageDirty in - * clear_page_dirty_for_io() to make sure i_size is really sampled only + * folio_clear_dirty_for_io() to make sure i_size is really sampled only * after page tables are updated. */ size = i_size_read(mpd->inode); - if (page->index == size >> PAGE_SHIFT && + len = folio_size(folio); + if (folio_pos(folio) + len > size && !ext4_verity_in_progress(mpd->inode)) len = size & ~PAGE_MASK; - else - len = PAGE_SIZE; - err = ext4_bio_write_page(&mpd->io_submit, page, len); + err = ext4_bio_write_page(&mpd->io_submit, &folio->page, len); if (!err) mpd->wbc->nr_to_write--; mpd->first_page++; @@ -2238,7 +2237,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd, } while (lblk++, (bh = bh->b_this_page) != head); /* So far everything mapped? Submit the page for IO. */ if (mpd->map.m_len == 0) { - err = mpage_submit_page(mpd, head->b_page); + err = mpage_submit_folio(mpd, head->b_folio); if (err < 0) return err; } @@ -2370,7 +2369,7 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd) if (err < 0 || map_bh) goto out; /* Page fully mapped - let IO run! */ - err = mpage_submit_page(mpd, &folio->page); + err = mpage_submit_folio(mpd, folio); if (err < 0) goto out; } @@ -2680,7 +2679,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) */ if (!mpd->can_map) { if (ext4_page_nomap_can_writeout(&folio->page)) { - err = mpage_submit_page(mpd, &folio->page); + err = mpage_submit_folio(mpd, folio); if (err < 0) goto out; } else { From patchwork Thu Jan 26 20:23:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117741 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23E05C61DB3 for ; Thu, 26 Jan 2023 20:25:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232827AbjAZUZu (ORCPT ); Thu, 26 Jan 2023 15:25:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232770AbjAZUZG (ORCPT ); Thu, 26 Jan 2023 15:25:06 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2058599A6; Thu, 26 Jan 2023 12:24:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=cZMF8LX59CrJPnQgJl9xKeli/V3bk+yesVg+QEOrOmY=; b=VVzbR2x8SocNaTlkE8+Ouz/rMd O4X+hY+5R1MMqR98ouhRJEdYDHbPuVr3m2MC+gNiNoJ8QNA9haSprw8/HTyoMt/lYXDq7ALa39Vho 8cQ6L1drr9IO4ml3idh5NgW3bj6pFje9XgPQQT7WPx6+p/7fw6kMyEvXRBgGS3fsxOE4lizrMOqXD Y8ySmxXtBJTQCSq0MNAiwOdPgHBxgKaWP9/VymSxEGUKrPuFbvD/j/SHks/4Pa9YheonhpYo3E8FY Z0tysQ0sC/UwgULyIjWkPaJlemCJAHFdrblTtje7Ekrv9wNb0m6KBySIK+v7M0qPu3c0gvvwXL2U3 4Dl9o3Gg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nD-0073ja-5N; Thu, 26 Jan 2023 20:24:19 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 08/31] ext4: Convert ext4_bio_write_page() to ext4_bio_write_folio() Date: Thu, 26 Jan 2023 20:23:52 +0000 Message-Id: <20230126202415.1682629-9-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Both callers now have a folio so pass it in directly and avoid the call to page_folio() at the beginning. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Theodore Ts'o --- fs/ext4/ext4.h | 5 ++--- fs/ext4/inode.c | 18 +++++++++--------- fs/ext4/page-io.c | 10 ++++------ 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 43e26e6f6e42..7a132e8648f4 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3756,9 +3756,8 @@ extern void ext4_io_submit_init(struct ext4_io_submit *io, struct writeback_control *wbc); extern void ext4_end_io_rsv_work(struct work_struct *work); extern void ext4_io_submit(struct ext4_io_submit *io); -extern int ext4_bio_write_page(struct ext4_io_submit *io, - struct page *page, - int len); +int ext4_bio_write_folio(struct ext4_io_submit *io, struct folio *page, + size_t len); extern struct ext4_io_end_vec *ext4_alloc_io_end_vec(ext4_io_end_t *io_end); extern struct ext4_io_end_vec *ext4_last_io_end_vec(ext4_io_end_t *io_end); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 8b91e325492f..fcd904123384 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2014,9 +2014,9 @@ static int ext4_writepage(struct page *page, struct folio *folio = page_folio(page); int ret = 0; loff_t size; - unsigned int len; + size_t len; struct buffer_head *page_bufs = NULL; - struct inode *inode = page->mapping->host; + struct inode *inode = folio->mapping->host; struct ext4_io_submit io_submit; if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) { @@ -2052,12 +2052,12 @@ static int ext4_writepage(struct page *page, * Also, if there is only one buffer per page (the fs block * size == the page size), if one buffer needs block * allocation or needs to modify the extent tree to clear the - * unwritten flag, we know that the page can't be written at + * unwritten flag, we know that the folio can't be written at * all, so we might as well refuse the write immediately. * Unfortunately if the block size != page size, we can't as * easily detect this case using ext4_walk_page_buffers(), but * for the extremely common case, this is an optimization that - * skips a useless round trip through ext4_bio_write_page(). + * skips a useless round trip through ext4_bio_write_folio(). */ if (ext4_walk_page_buffers(NULL, inode, page_bufs, 0, len, NULL, ext4_bh_delay_or_unwritten)) { @@ -2079,7 +2079,7 @@ static int ext4_writepage(struct page *page, if (folio_test_checked(folio) && ext4_should_journal_data(inode)) /* * It's mmapped pagecache. Add buffers and journal it. There - * doesn't seem much point in redirtying the page here. + * doesn't seem much point in redirtying the folio here. */ return __ext4_journalled_writepage(page, len); @@ -2090,7 +2090,7 @@ static int ext4_writepage(struct page *page, folio_unlock(folio); return -ENOMEM; } - ret = ext4_bio_write_page(&io_submit, page, len); + ret = ext4_bio_write_folio(&io_submit, folio, len); ext4_io_submit(&io_submit); /* Drop io_end reference we got from init */ ext4_put_io_end_defer(io_submit.io_end); @@ -2113,8 +2113,8 @@ static int mpage_submit_folio(struct mpage_da_data *mpd, struct folio *folio) * write-protects our page in page tables and the page cannot get * written to again until we release folio lock. So only after * folio_clear_dirty_for_io() we are safe to sample i_size for - * ext4_bio_write_page() to zero-out tail of the written page. We rely - * on the barrier provided by TestClearPageDirty in + * ext4_bio_write_folio() to zero-out tail of the written page. We rely + * on the barrier provided by folio_test_clear_dirty() in * folio_clear_dirty_for_io() to make sure i_size is really sampled only * after page tables are updated. */ @@ -2123,7 +2123,7 @@ static int mpage_submit_folio(struct mpage_da_data *mpd, struct folio *folio) if (folio_pos(folio) + len > size && !ext4_verity_in_progress(mpd->inode)) len = size & ~PAGE_MASK; - err = ext4_bio_write_page(&mpd->io_submit, &folio->page, len); + err = ext4_bio_write_folio(&mpd->io_submit, folio, len); if (!err) mpd->wbc->nr_to_write--; mpd->first_page++; diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c index fd6c0dca24b9..c6da8800a49f 100644 --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -425,11 +425,9 @@ static void io_submit_add_bh(struct ext4_io_submit *io, io->io_next_block++; } -int ext4_bio_write_page(struct ext4_io_submit *io, - struct page *page, - int len) +int ext4_bio_write_folio(struct ext4_io_submit *io, struct folio *folio, + size_t len) { - struct folio *folio = page_folio(page); struct folio *io_folio = folio; struct inode *inode = folio->mapping->host; unsigned block_start; @@ -522,8 +520,8 @@ int ext4_bio_write_page(struct ext4_io_submit *io, if (io->io_bio) gfp_flags = GFP_NOWAIT | __GFP_NOWARN; retry_encrypt: - bounce_page = fscrypt_encrypt_pagecache_blocks(page, enc_bytes, - 0, gfp_flags); + bounce_page = fscrypt_encrypt_pagecache_blocks(&folio->page, + enc_bytes, 0, gfp_flags); if (IS_ERR(bounce_page)) { ret = PTR_ERR(bounce_page); if (ret == -ENOMEM && From patchwork Thu Jan 26 20:23:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117740 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B30EC05027 for ; Thu, 26 Jan 2023 20:25:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231651AbjAZUZt (ORCPT ); Thu, 26 Jan 2023 15:25:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232292AbjAZUYz (ORCPT ); Thu, 26 Jan 2023 15:24:55 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A8A5728ED; Thu, 26 Jan 2023 12:24:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=6nWGi4oOmhc7aGpc2yEDO3lz/Me2HXzFePEcirx6YtI=; b=CxVl80kA21lvOFu1Hj125JMKiP wYNNTNaeeJ/q6X1aRe9Dwdw81zNTD3eGJEzYnEpc9O3sAw4HJugtuJLEOgXttaslJ79a/zQUA3OUq 1Uk/3KPr+OKBW7RycbiJLbWK3t+TPw5Jm6cDlchnmgNGPnXWrmPaclQB+fkxwhI+Mj5F4XA2WLZF2 xcxLoz/IS9LHmci0gciNMzohWUk60B4dHdxwCRN836GmOTh18f60C37DOHnlzzmXh5A9sJ4PI8R+g KxXlkKK2cRbAtfoOsyHZ6f2UxaK2BW1HH41BADzY1c2mHKuI4wPQgvT7LEzMCDJMvkH/JspwWlrkW 7ZtYK9JQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nD-0073jc-8H; Thu, 26 Jan 2023 20:24:19 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 09/31] ext4: Convert ext4_readpage_inline() to take a folio Date: Thu, 26 Jan 2023 20:23:53 +0000 Message-Id: <20230126202415.1682629-10-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the folio API in this function, saves a few calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Theodore Ts'o --- fs/ext4/ext4.h | 2 +- fs/ext4/inline.c | 14 +++++++------- fs/ext4/inode.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 7a132e8648f4..d2998800855c 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3549,7 +3549,7 @@ extern int ext4_init_inline_data(handle_t *handle, struct inode *inode, unsigned int len); extern int ext4_destroy_inline_data(handle_t *handle, struct inode *inode); -extern int ext4_readpage_inline(struct inode *inode, struct page *page); +int ext4_readpage_inline(struct inode *inode, struct folio *folio); extern int ext4_try_to_write_inline_data(struct address_space *mapping, struct inode *inode, loff_t pos, unsigned len, diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 2b42ececa46d..38f6282cc012 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -502,7 +502,7 @@ static int ext4_read_inline_page(struct inode *inode, struct page *page) return ret; } -int ext4_readpage_inline(struct inode *inode, struct page *page) +int ext4_readpage_inline(struct inode *inode, struct folio *folio) { int ret = 0; @@ -516,16 +516,16 @@ int ext4_readpage_inline(struct inode *inode, struct page *page) * Current inline data can only exist in the 1st page, * So for all the other pages, just set them uptodate. */ - if (!page->index) - ret = ext4_read_inline_page(inode, page); - else if (!PageUptodate(page)) { - zero_user_segment(page, 0, PAGE_SIZE); - SetPageUptodate(page); + if (!folio->index) + ret = ext4_read_inline_page(inode, &folio->page); + else if (!folio_test_uptodate(folio)) { + folio_zero_segment(folio, 0, PAGE_SIZE); + folio_mark_uptodate(folio); } up_read(&EXT4_I(inode)->xattr_sem); - unlock_page(page); + folio_unlock(folio); return ret >= 0 ? 0 : ret; } diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index fcd904123384..c627686295e0 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3300,7 +3300,7 @@ static int ext4_read_folio(struct file *file, struct folio *folio) trace_ext4_readpage(page); if (ext4_has_inline_data(inode)) - ret = ext4_readpage_inline(inode, page); + ret = ext4_readpage_inline(inode, folio); if (ret == -EAGAIN) return ext4_mpage_readpages(inode, NULL, page); From patchwork Thu Jan 26 20:23:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117711 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E588DC61DA7 for ; Thu, 26 Jan 2023 20:24:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232796AbjAZUYY (ORCPT ); Thu, 26 Jan 2023 15:24:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232348AbjAZUYX (ORCPT ); Thu, 26 Jan 2023 15:24:23 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AFE149952; Thu, 26 Jan 2023 12:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Ega2nPk6JyEOJ/yX+Ll6lvh5JFeML9DVVsy1UgiysaI=; b=W11c6TgYvIrAvAX6geT5vrTlVF 7+VDUABsqY6HvbcWaN/cLQZwKTk7RWMZNpqk15A5j6AqJyHZH+4uCCs4aYFj3cYq3fQpIDDzJ/uLv JoxjshFA1qNcB7H7h2F2pYnQMSQoqeuqAGs/W2Sid09onGRqEi+4jAWY5ivv7JA1ifoDLmoEeEod+ +GhIEcw+ZYnWxAO4HjyNsbnyYcJH6y6LDERhZNApdG2LzGzSLbBirD82NeC/aeugkNu51YEi7Tt8S DxNFoUvrhkI5N1yznEroxW8nEy04XCHMBfEg3vE6dv0KAb8icFpY00flBjrPDJtI2hQA24NvUXOQR SGpnK4Fg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nD-0073je-B0; Thu, 26 Jan 2023 20:24:19 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 10/31] ext4: Convert ext4_convert_inline_data_to_extent() to use a folio Date: Thu, 26 Jan 2023 20:23:54 +0000 Message-Id: <20230126202415.1682629-11-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Saves a number of calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/inline.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 38f6282cc012..2091077e37dc 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -535,8 +535,7 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, int ret, needed_blocks, no_expand; handle_t *handle = NULL; int retries = 0, sem_held = 0; - struct page *page = NULL; - unsigned int flags; + struct folio *folio = NULL; unsigned from, to; struct ext4_iloc iloc; @@ -565,10 +564,9 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, /* We cannot recurse into the filesystem as the transaction is already * started */ - flags = memalloc_nofs_save(); - page = grab_cache_page_write_begin(mapping, 0); - memalloc_nofs_restore(flags); - if (!page) { + folio = __filemap_get_folio(mapping, 0, FGP_WRITEBEGIN | FGP_NOFS, + mapping_gfp_mask(mapping)); + if (!folio) { ret = -ENOMEM; goto out; } @@ -583,8 +581,8 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, from = 0; to = ext4_get_inline_size(inode); - if (!PageUptodate(page)) { - ret = ext4_read_inline_page(inode, page); + if (!folio_test_uptodate(folio)) { + ret = ext4_read_inline_page(inode, &folio->page); if (ret < 0) goto out; } @@ -594,21 +592,21 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, goto out; if (ext4_should_dioread_nolock(inode)) { - ret = __block_write_begin(page, from, to, + ret = __block_write_begin(&folio->page, from, to, ext4_get_block_unwritten); } else - ret = __block_write_begin(page, from, to, ext4_get_block); + ret = __block_write_begin(&folio->page, from, to, ext4_get_block); if (!ret && ext4_should_journal_data(inode)) { - ret = ext4_walk_page_buffers(handle, inode, page_buffers(page), - from, to, NULL, - do_journal_get_write_access); + ret = ext4_walk_page_buffers(handle, inode, + folio_buffers(folio), from, to, + NULL, do_journal_get_write_access); } if (ret) { - unlock_page(page); - put_page(page); - page = NULL; + folio_unlock(folio); + folio_put(folio); + folio = NULL; ext4_orphan_add(handle, inode); ext4_write_unlock_xattr(inode, &no_expand); sem_held = 0; @@ -628,12 +626,12 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) goto retry; - if (page) - block_commit_write(page, from, to); + if (folio) + block_commit_write(&folio->page, from, to); out: - if (page) { - unlock_page(page); - put_page(page); + if (folio) { + folio_unlock(folio); + folio_put(folio); } if (sem_held) ext4_write_unlock_xattr(inode, &no_expand); From patchwork Thu Jan 26 20:23:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117712 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6973C61DB3 for ; Thu, 26 Jan 2023 20:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232809AbjAZUYZ (ORCPT ); Thu, 26 Jan 2023 15:24:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232770AbjAZUYX (ORCPT ); Thu, 26 Jan 2023 15:24:23 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4268A49954; Thu, 26 Jan 2023 12:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=eRdVjrXjCbsfnXq/P5UITQIPfitOB84uZkudpPQpvRI=; b=dOEAdlfR7LrVqTsxal7rq0vVqo pnGruQvnm/Njw+TzuGcmgsV3VH+tfeokmzNbizx9QIcgnS2i6W+XLPwR5j1V0UZqx7miQP2YjLmbJ MSIshv/qyb1E2F156QoO/IXdk/2cueRtH0p8K03up9Xrp6qJMEUJCyD6KRVzhS+I3i7U7prFKOs83 wrYDm3YTTsEH8OH4s3bWvgZXPYCfrSnD+kW+yYYmSCyOfjyyLG2ZQJf4igvwIme4JYi3ihNRhrbt8 Sxaf+XzIfHaWXn6vRlB4TiP4LZVHMW+aFQyDeA5j9WmHoLJCoNS2EvDHg/1ke57HCxjrd2FTqB3Pu dLF/CmBw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nD-0073jt-Fv; Thu, 26 Jan 2023 20:24:19 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 11/31] ext4: Convert ext4_try_to_write_inline_data() to use a folio Date: Thu, 26 Jan 2023 20:23:55 +0000 Message-Id: <20230126202415.1682629-12-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Saves a number of calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/inline.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 2091077e37dc..6d136353ccc2 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -654,8 +654,7 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, { int ret; handle_t *handle; - unsigned int flags; - struct page *page; + struct folio *folio; struct ext4_iloc iloc; if (pos + len > ext4_get_max_inline_size(inode)) @@ -692,28 +691,27 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, if (ret) goto out; - flags = memalloc_nofs_save(); - page = grab_cache_page_write_begin(mapping, 0); - memalloc_nofs_restore(flags); - if (!page) { + folio = __filemap_get_folio(mapping, 0, FGP_WRITEBEGIN | FGP_NOFS, + mapping_gfp_mask(mapping)); + if (!folio) { ret = -ENOMEM; goto out; } - *pagep = page; + *pagep = &folio->page; down_read(&EXT4_I(inode)->xattr_sem); if (!ext4_has_inline_data(inode)) { ret = 0; - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); goto out_up_read; } - if (!PageUptodate(page)) { - ret = ext4_read_inline_page(inode, page); + if (!folio_test_uptodate(folio)) { + ret = ext4_read_inline_page(inode, &folio->page); if (ret < 0) { - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); goto out_up_read; } } From patchwork Thu Jan 26 20:23:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117714 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1E30C54EAA for ; Thu, 26 Jan 2023 20:24:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232815AbjAZUY1 (ORCPT ); Thu, 26 Jan 2023 15:24:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232782AbjAZUYX (ORCPT ); Thu, 26 Jan 2023 15:24:23 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A06A04AA49; Thu, 26 Jan 2023 12:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=VlaXoQTjOKuL56Vm7lVE3emEdqOQU4UkXh98jLQo7SQ=; b=rRUYxIkfc7aXhsx2YPaasFSahL zU6w6tdjoXRPLbUpmKa8yY2VuLszht2OFek+4kitNAqmkZmjbRnd2Jc5p9uPE0ZpCTObfPATRt8DP 246fqJkJYZu7xOx4pp81dliTrm//CFxdf6TZXoQR7kCtRa23g8Lx2tEMe13limZgD0GY/oKn4BdUq Zy/I3W8iH28mFQGMvqb+S5G+04dlIpsxhNQIn4DEFqYhfJQQ62AUbC3QsvjVWYjjIGTaXyOgPZcuI wf5/K8rOr9kgdla0mDLbgi39V54mb7uCAVstCl/En/HE1hf7WHSkQHH/AYxDhlFFTtWA5OVsF8R56 O832S9Kg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nD-0073jz-KV; Thu, 26 Jan 2023 20:24:19 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 12/31] ext4: Convert ext4_da_convert_inline_data_to_extent() to use a folio Date: Thu, 26 Jan 2023 20:23:56 +0000 Message-Id: <20230126202415.1682629-13-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Saves a number of calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/inline.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 6d136353ccc2..99c77dd519f0 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -849,10 +849,11 @@ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping, void **fsdata) { int ret = 0, inline_size; - struct page *page; + struct folio *folio; - page = grab_cache_page_write_begin(mapping, 0); - if (!page) + folio = __filemap_get_folio(mapping, 0, FGP_WRITEBEGIN, + mapping_gfp_mask(mapping)); + if (!folio) return -ENOMEM; down_read(&EXT4_I(inode)->xattr_sem); @@ -863,32 +864,32 @@ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping, inline_size = ext4_get_inline_size(inode); - if (!PageUptodate(page)) { - ret = ext4_read_inline_page(inode, page); + if (!folio_test_uptodate(folio)) { + ret = ext4_read_inline_page(inode, &folio->page); if (ret < 0) goto out; } - ret = __block_write_begin(page, 0, inline_size, + ret = __block_write_begin(&folio->page, 0, inline_size, ext4_da_get_block_prep); if (ret) { up_read(&EXT4_I(inode)->xattr_sem); - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); ext4_truncate_failed_write(inode); return ret; } - SetPageDirty(page); - SetPageUptodate(page); + folio_mark_dirty(folio); + folio_mark_uptodate(folio); ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA); *fsdata = (void *)CONVERT_INLINE_DATA; out: up_read(&EXT4_I(inode)->xattr_sem); - if (page) { - unlock_page(page); - put_page(page); + if (folio) { + folio_unlock(folio); + folio_put(folio); } return ret; } From patchwork Thu Jan 26 20:23:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117717 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21422C636CB for ; Thu, 26 Jan 2023 20:24:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232831AbjAZUYb (ORCPT ); Thu, 26 Jan 2023 15:24:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232783AbjAZUYX (ORCPT ); Thu, 26 Jan 2023 15:24:23 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6649B4996E; Thu, 26 Jan 2023 12:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=GVHnYKlWroCQt1vq8X/m3nZwxtJ1hxutRRN2IluE1Lg=; b=mxtrTwwQ5buP+bfuGhkgVjul+B /VRyWhbjZHbI4t85AOAoogW01ETn5DdJqSQcsjvMdcnDlT0q2E5zrfeFBgSLrVKORuN6Dhxg/z+PM ToCki5mZ8vPVQnzZ281NOi8b4nUpWsIPApVjoHx+UQCBhUPMi2Fx08fEVhAXKQpqPna9deBBvWNK2 DLM2/rUbD+GWlaZ1vRmptpJs90gOvWduV5aRNg+ht4+DMigp6dIFwxBuCGJbYnN1f5qpsrC4vOgsY I/+UW87dI51snV8SZu0EMQUMf0n+Q1/EZMGp9pRV+BlQMZ/B9o0ywe5M4PAwNVsYdSA6dQenYq+Dd /7b0+iGg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nD-0073k5-OJ; Thu, 26 Jan 2023 20:24:19 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 13/31] ext4: Convert ext4_da_write_inline_data_begin() to use a folio Date: Thu, 26 Jan 2023 20:23:57 +0000 Message-Id: <20230126202415.1682629-14-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Saves a number of calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/inline.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 99c77dd519f0..b8e22348dad2 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -910,10 +910,9 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping, { int ret; handle_t *handle; - struct page *page; + struct folio *folio; struct ext4_iloc iloc; int retries = 0; - unsigned int flags; ret = ext4_get_inode_loc(inode, &iloc); if (ret) @@ -945,10 +944,9 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping, * We cannot recurse into the filesystem as the transaction * is already started. */ - flags = memalloc_nofs_save(); - page = grab_cache_page_write_begin(mapping, 0); - memalloc_nofs_restore(flags); - if (!page) { + folio = __filemap_get_folio(mapping, 0, FGP_WRITEBEGIN | FGP_NOFS, + mapping_gfp_mask(mapping)); + if (!folio) { ret = -ENOMEM; goto out_journal; } @@ -959,8 +957,8 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping, goto out_release_page; } - if (!PageUptodate(page)) { - ret = ext4_read_inline_page(inode, page); + if (!folio_test_uptodate(folio)) { + ret = ext4_read_inline_page(inode, &folio->page); if (ret < 0) goto out_release_page; } @@ -970,13 +968,13 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping, goto out_release_page; up_read(&EXT4_I(inode)->xattr_sem); - *pagep = page; + *pagep = &folio->page; brelse(iloc.bh); return 1; out_release_page: up_read(&EXT4_I(inode)->xattr_sem); - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); out_journal: ext4_journal_stop(handle); out: From patchwork Thu Jan 26 20:23:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117715 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 874A4C61DA7 for ; Thu, 26 Jan 2023 20:24:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232823AbjAZUY3 (ORCPT ); Thu, 26 Jan 2023 15:24:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232785AbjAZUYY (ORCPT ); Thu, 26 Jan 2023 15:24:24 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7F724B19E; Thu, 26 Jan 2023 12:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=QEa1GRU5rQ0cClZFzZmq/IyyK2MNca1Te7OmO60R5o0=; b=jC/vEvNN4HP6Uz5Q4GcthvG8jm voc3/dWff+or/c9BtIAX/vV7Tzue8PPz00VevT6rITLlkFmk1h1v1Rv2yRj6vMnN9wBW3IOW6oevf OLqinqfbgF0ShTd0/fYeMQo02jndn+bYiCpMZSn41a5MC5MeHzabKJyXWnb26gxw+DjqkB2iFLY4Y tjxOPai2sCA20syQy3W7CaTpaCHT5iGpExpmYLYIyW9PzyZEXQMyttfi0vvD3GV1gO+dI/V7Liwb+ f9tYp0ZVs+k+BMS7OYKrP8XZU7AKkVoIRPb2+1JWNhCEm9IQqYYbleUq+FFjB6PlsveKlBZn/qOp2 BMANa1Hw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nD-0073kB-Rn; Thu, 26 Jan 2023 20:24:19 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 14/31] ext4: Convert ext4_read_inline_page() to ext4_read_inline_folio() Date: Thu, 26 Jan 2023 20:23:58 +0000 Message-Id: <20230126202415.1682629-15-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org All callers now have a folio, so pass it and use it. The folio may be large, although I doubt we'll want to use a large folio for an inline file. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Theodore Ts'o --- fs/ext4/inline.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index b8e22348dad2..29294caa20a1 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -468,16 +468,16 @@ static int ext4_destroy_inline_data_nolock(handle_t *handle, return error; } -static int ext4_read_inline_page(struct inode *inode, struct page *page) +static int ext4_read_inline_folio(struct inode *inode, struct folio *folio) { void *kaddr; int ret = 0; size_t len; struct ext4_iloc iloc; - BUG_ON(!PageLocked(page)); + BUG_ON(!folio_test_locked(folio)); BUG_ON(!ext4_has_inline_data(inode)); - BUG_ON(page->index); + BUG_ON(folio->index); if (!EXT4_I(inode)->i_inline_off) { ext4_warning(inode->i_sb, "inode %lu doesn't have inline data.", @@ -490,12 +490,13 @@ static int ext4_read_inline_page(struct inode *inode, struct page *page) goto out; len = min_t(size_t, ext4_get_inline_size(inode), i_size_read(inode)); - kaddr = kmap_atomic(page); + BUG_ON(len > PAGE_SIZE); + kaddr = kmap_local_folio(folio, 0); ret = ext4_read_inline_data(inode, kaddr, len, &iloc); - flush_dcache_page(page); - kunmap_atomic(kaddr); - zero_user_segment(page, len, PAGE_SIZE); - SetPageUptodate(page); + flush_dcache_folio(folio); + kunmap_local(kaddr); + folio_zero_segment(folio, len, folio_size(folio)); + folio_mark_uptodate(folio); brelse(iloc.bh); out: @@ -517,7 +518,7 @@ int ext4_readpage_inline(struct inode *inode, struct folio *folio) * So for all the other pages, just set them uptodate. */ if (!folio->index) - ret = ext4_read_inline_page(inode, &folio->page); + ret = ext4_read_inline_folio(inode, folio); else if (!folio_test_uptodate(folio)) { folio_zero_segment(folio, 0, PAGE_SIZE); folio_mark_uptodate(folio); @@ -582,7 +583,7 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, from = 0; to = ext4_get_inline_size(inode); if (!folio_test_uptodate(folio)) { - ret = ext4_read_inline_page(inode, &folio->page); + ret = ext4_read_inline_folio(inode, folio); if (ret < 0) goto out; } @@ -708,7 +709,7 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, } if (!folio_test_uptodate(folio)) { - ret = ext4_read_inline_page(inode, &folio->page); + ret = ext4_read_inline_folio(inode, folio); if (ret < 0) { folio_unlock(folio); folio_put(folio); @@ -865,7 +866,7 @@ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping, inline_size = ext4_get_inline_size(inode); if (!folio_test_uptodate(folio)) { - ret = ext4_read_inline_page(inode, &folio->page); + ret = ext4_read_inline_folio(inode, folio); if (ret < 0) goto out; } @@ -958,7 +959,7 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping, } if (!folio_test_uptodate(folio)) { - ret = ext4_read_inline_page(inode, &folio->page); + ret = ext4_read_inline_folio(inode, folio); if (ret < 0) goto out_release_page; } From patchwork Thu Jan 26 20:23:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117713 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E88B8C636CB for ; Thu, 26 Jan 2023 20:24:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232812AbjAZUY0 (ORCPT ); Thu, 26 Jan 2023 15:24:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232772AbjAZUYX (ORCPT ); Thu, 26 Jan 2023 15:24:23 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6D154B19D; Thu, 26 Jan 2023 12:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=DVlcNZBut+DtNK9F+iP982TEiyv3KpnKHUgwVzUcsfQ=; b=PAOlf7iZiNIxrW59v6BYibTJz5 R2fba8d66xrSs62DEfSWsjg/f6QN1+FGuOcDHwFkeJ9D2YuGZyxZe1VqH1giu9EJSfVlzEM23feK2 bbKuVxW06qaLGq6b1Kd9Ed4sf7rCqa3AnHZw6j342Ai/ZaI0WOweepcJwm28LcCUCutJ5A9cqw57u 2Q3ZBJbjkG/o7tJ4u+fDhf/KmffqTjRjfbS0bTC9nr4KQrv3+Zdn0tuI+uxG9DTd4q+by/WI0BtpT V2nlSLuOKGZk6KkUlLh8ljIWB3kEv832QaWXB0AnmFLBODQcNaCN1Bdrfd9QGU+nEB4T3Wrro+q37 XmZ3wJug==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nD-0073kH-VM; Thu, 26 Jan 2023 20:24:20 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 15/31] ext4: Convert ext4_write_inline_data_end() to use a folio Date: Thu, 26 Jan 2023 20:23:59 +0000 Message-Id: <20230126202415.1682629-16-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Convert the incoming page to a folio so that we call compound_head() only once instead of seven times. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Theodore Ts'o --- fs/ext4/inline.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 29294caa20a1..a06dd4f0d17b 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -733,20 +733,21 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, unsigned copied, struct page *page) { + struct folio *folio = page_folio(page); handle_t *handle = ext4_journal_current_handle(); int no_expand; void *kaddr; struct ext4_iloc iloc; int ret = 0, ret2; - if (unlikely(copied < len) && !PageUptodate(page)) + if (unlikely(copied < len) && !folio_test_uptodate(folio)) copied = 0; if (likely(copied)) { ret = ext4_get_inode_loc(inode, &iloc); if (ret) { - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); ext4_std_error(inode->i_sb, ret); goto out; } @@ -760,30 +761,30 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, */ (void) ext4_find_inline_data_nolock(inode); - kaddr = kmap_atomic(page); + kaddr = kmap_local_folio(folio, 0); ext4_write_inline_data(inode, &iloc, kaddr, pos, copied); - kunmap_atomic(kaddr); - SetPageUptodate(page); - /* clear page dirty so that writepages wouldn't work for us. */ - ClearPageDirty(page); + kunmap_local(kaddr); + folio_mark_uptodate(folio); + /* clear dirty flag so that writepages wouldn't work for us. */ + folio_clear_dirty(folio); ext4_write_unlock_xattr(inode, &no_expand); brelse(iloc.bh); /* - * It's important to update i_size while still holding page + * It's important to update i_size while still holding folio * lock: page writeout could otherwise come in and zero * beyond i_size. */ ext4_update_inode_size(inode, pos + copied); } - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); /* - * Don't mark the inode dirty under page lock. First, it unnecessarily - * makes the holding time of page lock longer. Second, it forces lock - * ordering of page lock and transaction start for journaling + * Don't mark the inode dirty under folio lock. First, it unnecessarily + * makes the holding time of folio lock longer. Second, it forces lock + * ordering of folio lock and transaction start for journaling * filesystems. */ if (likely(copied)) From patchwork Thu Jan 26 20:24:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117718 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFEDEC636CD for ; Thu, 26 Jan 2023 20:24:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232783AbjAZUYc (ORCPT ); Thu, 26 Jan 2023 15:24:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232786AbjAZUYY (ORCPT ); Thu, 26 Jan 2023 15:24:24 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBDB74B4B0; Thu, 26 Jan 2023 12:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=yAoys4dBl+8BQmn25O6SNEK7s+nZO9rSb1qSFkT15mg=; b=OTeTcS2lohbDE+SOs0t9SnhyLx 1prRKQuAvenp+fP5/vVAzbVEAQ2Ekjz1RpeSdWlVBAHVnPLwOEFijil2YQdntZWmmGo6LC3KVbk// 1Yn3cBiQ6ZB8edf2VihSA7MWV1cbpzvD+SFPJWGEeaPAOIax2BeR1GVjVItlVEsb42jOtRVNHUTsG aJiFuWxF9kRCPgMumB0/qkclXmtjeLDebZMewOm3Tj6liSLYKN6H1vIQtAltNBVjfh9vWaUyW9Xvg KAzIwZhfN+aG4JTei0M1Mm48zbRLK6SXSSjUHEHcPlG/7nyOGOsi9sP5urVKJ4fk6FllANVtxNpYU QrhHr6lw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nE-0073kN-3D; Thu, 26 Jan 2023 20:24:20 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 16/31] ext4: Convert ext4_write_begin() to use a folio Date: Thu, 26 Jan 2023 20:24:00 +0000 Message-Id: <20230126202415.1682629-17-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Remove a lot of calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/inode.c | 53 +++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index c627686295e0..9233d6b68ebe 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1156,7 +1156,7 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, int ret, needed_blocks; handle_t *handle; int retries = 0; - struct page *page; + struct folio *folio; pgoff_t index; unsigned from, to; @@ -1183,68 +1183,69 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, } /* - * grab_cache_page_write_begin() can take a long time if the - * system is thrashing due to memory pressure, or if the page + * __filemap_get_folio() can take a long time if the + * system is thrashing due to memory pressure, or if the folio * is being written back. So grab it first before we start * the transaction handle. This also allows us to allocate - * the page (if needed) without using GFP_NOFS. + * the folio (if needed) without using GFP_NOFS. */ retry_grab: - page = grab_cache_page_write_begin(mapping, index); - if (!page) + folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN, + mapping_gfp_mask(mapping)); + if (!folio) return -ENOMEM; /* * The same as page allocation, we prealloc buffer heads before * starting the handle. */ - if (!page_has_buffers(page)) - create_empty_buffers(page, inode->i_sb->s_blocksize, 0); + if (!folio_buffers(folio)) + create_empty_buffers(&folio->page, inode->i_sb->s_blocksize, 0); - unlock_page(page); + folio_unlock(folio); retry_journal: handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, needed_blocks); if (IS_ERR(handle)) { - put_page(page); + folio_put(folio); return PTR_ERR(handle); } - lock_page(page); - if (page->mapping != mapping) { - /* The page got truncated from under us */ - unlock_page(page); - put_page(page); + folio_lock(folio); + if (folio->mapping != mapping) { + /* The folio got truncated from under us */ + folio_unlock(folio); + folio_put(folio); ext4_journal_stop(handle); goto retry_grab; } - /* In case writeback began while the page was unlocked */ - wait_for_stable_page(page); + /* In case writeback began while the folio was unlocked */ + folio_wait_stable(folio); #ifdef CONFIG_FS_ENCRYPTION if (ext4_should_dioread_nolock(inode)) - ret = ext4_block_write_begin(page, pos, len, + ret = ext4_block_write_begin(&folio->page, pos, len, ext4_get_block_unwritten); else - ret = ext4_block_write_begin(page, pos, len, + ret = ext4_block_write_begin(&folio->page, pos, len, ext4_get_block); #else if (ext4_should_dioread_nolock(inode)) - ret = __block_write_begin(page, pos, len, + ret = __block_write_begin(&folio->page, pos, len, ext4_get_block_unwritten); else - ret = __block_write_begin(page, pos, len, ext4_get_block); + ret = __block_write_begin(&folio->page, pos, len, ext4_get_block); #endif if (!ret && ext4_should_journal_data(inode)) { ret = ext4_walk_page_buffers(handle, inode, - page_buffers(page), from, to, NULL, - do_journal_get_write_access); + folio_buffers(folio), from, to, + NULL, do_journal_get_write_access); } if (ret) { bool extended = (pos + len > inode->i_size) && !ext4_verity_in_progress(inode); - unlock_page(page); + folio_unlock(folio); /* * __block_write_begin may have instantiated a few blocks * outside i_size. Trim these off again. Don't need @@ -1272,10 +1273,10 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) goto retry_journal; - put_page(page); + folio_put(folio); return ret; } - *pagep = page; + *pagep = &folio->page; return ret; } From patchwork Thu Jan 26 20:24:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117716 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54490C636BD for ; Thu, 26 Jan 2023 20:24:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232829AbjAZUYa (ORCPT ); Thu, 26 Jan 2023 15:24:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232787AbjAZUYY (ORCPT ); Thu, 26 Jan 2023 15:24:24 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED8834B742; Thu, 26 Jan 2023 12:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=PBBtjBBiY58Cfnr4orOrudpaRGHxJsqxIc2cgSFCcg0=; b=P7eQPsiWNouaWyX4ZsFeuNbHuJ WRHrkxb9zouUTtvz7iEpZ0gVP7L67w2JilfKhFCDn4tGDEBXRME38qnu/8LQIUs0aOipggFYUbI6x yRVa5ugxAnRyq4/oNHMYKEJhaLx9DgFpxK7WPlZ9knkpVma7kaFcFJSzPCq5mv7eLZpMXi4gKVKri VEUVclMjytIxpZ8EsxEzjoO4x4Q+KJfVOCFj+Wg8h7L9e5zcQm9vSnqYejCyMeqZTyElDtAmd/rps 1u0ReBfLIAlnUU8cy+XSdg/3eCWlRrTEo+w4Ab7YNS/U2EvCmP+MHaTwek1Qy5IjeX/AiuSWmtulD el1c4kpA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nE-0073kT-7q; Thu, 26 Jan 2023 20:24:20 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 17/31] ext4: Convert ext4_write_end() to use a folio Date: Thu, 26 Jan 2023 20:24:01 +0000 Message-Id: <20230126202415.1682629-18-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Convert the incoming struct page to a folio. Replaces two implicit calls to compound_head() with one explicit call. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Theodore Ts'o --- fs/ext4/inode.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 9233d6b68ebe..ab6eb85a9506 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1306,6 +1306,7 @@ static int ext4_write_end(struct file *file, loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata) { + struct folio *folio = page_folio(page); handle_t *handle = ext4_journal_current_handle(); struct inode *inode = mapping->host; loff_t old_size = inode->i_size; @@ -1321,7 +1322,7 @@ static int ext4_write_end(struct file *file, copied = block_write_end(file, mapping, pos, len, copied, page, fsdata); /* - * it's important to update i_size while still holding page lock: + * it's important to update i_size while still holding folio lock: * page writeout could otherwise come in and zero beyond i_size. * * If FS_IOC_ENABLE_VERITY is running on this inode, then Merkle tree @@ -1329,15 +1330,15 @@ static int ext4_write_end(struct file *file, */ if (!verity) i_size_changed = ext4_update_inode_size(inode, pos + copied); - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); if (old_size < pos && !verity) pagecache_isize_extended(inode, old_size, pos); /* - * Don't mark the inode dirty under page lock. First, it unnecessarily - * makes the holding time of page lock longer. Second, it forces lock - * ordering of page lock and transaction start for journaling + * Don't mark the inode dirty under folio lock. First, it unnecessarily + * makes the holding time of folio lock longer. Second, it forces lock + * ordering of folio lock and transaction start for journaling * filesystems. */ if (i_size_changed) From patchwork Thu Jan 26 20:24:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117719 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D2A6C61DA7 for ; Thu, 26 Jan 2023 20:24:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232834AbjAZUYc (ORCPT ); Thu, 26 Jan 2023 15:24:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232792AbjAZUYY (ORCPT ); Thu, 26 Jan 2023 15:24:24 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 103C64B75A; Thu, 26 Jan 2023 12:24:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=C0op9GL8E8wnJM/315LimsaHG2hcURzC771kGAlL4Xg=; b=MY20wf7DlA7+6FfUrz4nLQsEXF CiZ6rjMn2oS6SOBwO3DoUqDlltk141AwSN5LfBhpCzZPofVrs8HQbdhkuAAxu7d/EKMMYDvI3Gd00 +Li6sdHUF2MbOJpSHCpNND5GgKvwETOV27McLcoZLZR0QofI/vKtFH6Bqh2zChhu4W004JYde2J7e /XzLKn5Ijk2W15U9H0quugFyWCFhr7eNhw9CnMKv5wjWmTtCQ025BLmn8U0REdhcggDvdHeQ0mfZp SmgfSbc9W03eSqRVfzrBhClRKbGb2XMrzLAXdcpOQUsa1y+NJ/gGg/gNxUtSATjkfk2bo/D82BXNn CO+IXnyQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nE-0073kZ-C8; Thu, 26 Jan 2023 20:24:20 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 18/31] ext4: Use a folio in ext4_journalled_write_end() Date: Thu, 26 Jan 2023 20:24:02 +0000 Message-Id: <20230126202415.1682629-19-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Convert the incoming page to a folio to remove a few calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Theodore Ts'o --- fs/ext4/inode.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index ab6eb85a9506..4f43d7434965 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1409,6 +1409,7 @@ static int ext4_journalled_write_end(struct file *file, loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata) { + struct folio *folio = page_folio(page); handle_t *handle = ext4_journal_current_handle(); struct inode *inode = mapping->host; loff_t old_size = inode->i_size; @@ -1427,25 +1428,26 @@ static int ext4_journalled_write_end(struct file *file, if (ext4_has_inline_data(inode)) return ext4_write_inline_data_end(inode, pos, len, copied, page); - if (unlikely(copied < len) && !PageUptodate(page)) { + if (unlikely(copied < len) && !folio_test_uptodate(folio)) { copied = 0; ext4_journalled_zero_new_buffers(handle, inode, page, from, to); } else { if (unlikely(copied < len)) ext4_journalled_zero_new_buffers(handle, inode, page, from + copied, to); - ret = ext4_walk_page_buffers(handle, inode, page_buffers(page), + ret = ext4_walk_page_buffers(handle, inode, + folio_buffers(folio), from, from + copied, &partial, write_end_fn); if (!partial) - SetPageUptodate(page); + folio_mark_uptodate(folio); } if (!verity) size_changed = ext4_update_inode_size(inode, pos + copied); ext4_set_inode_state(inode, EXT4_STATE_JDATA); EXT4_I(inode)->i_datasync_tid = handle->h_transaction->t_tid; - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); if (old_size < pos && !verity) pagecache_isize_extended(inode, old_size, pos); From patchwork Thu Jan 26 20:24:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117720 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B1FBC05027 for ; Thu, 26 Jan 2023 20:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232792AbjAZUYe (ORCPT ); Thu, 26 Jan 2023 15:24:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232788AbjAZUYY (ORCPT ); Thu, 26 Jan 2023 15:24:24 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75013227B3; Thu, 26 Jan 2023 12:24:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=/Ja8vadzBHz2ZdVgW/VI/XY3kcR3lQVt/q1ut0HAdJ8=; b=lTxGnXtC9ti2GmfcgvIMYNtydW tADZSr8URUvI49/Lu5qMB99gV/06m+dUgvDt/nYQqp+bkLnDQDZIROt+mKr3IArZ3I/Fmc9T1eSuI 2hmKqeer5eI/rjYuFUW8qE7XZri6qKtqWMwQ5c2MX5JCSgysOzGSvlfUzDexoF7JBHkpXi3RzwwQZ MBsoiTSu+yEqWZi+h9QTrUSkUjF7EfojVjXrnN9NDWPTVt/IJElElhxRl09wtkLS30KECEgQ1ost/ dlh/ysYOgsIzcUQ7TmwjgBwb4TSuvGc4cOuyC6tecSOWNPNKiAH2pysIn+GAncfkUsv0QMyHwaiOX asY9SRCg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nE-0073kh-Gj; Thu, 26 Jan 2023 20:24:20 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 19/31] ext4: Convert ext4_journalled_zero_new_buffers() to use a folio Date: Thu, 26 Jan 2023 20:24:03 +0000 Message-Id: <20230126202415.1682629-20-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Remove a call to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/inode.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 4f43d7434965..b79e591b7c8e 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1376,24 +1376,24 @@ static int ext4_write_end(struct file *file, */ static void ext4_journalled_zero_new_buffers(handle_t *handle, struct inode *inode, - struct page *page, + struct folio *folio, unsigned from, unsigned to) { unsigned int block_start = 0, block_end; struct buffer_head *head, *bh; - bh = head = page_buffers(page); + bh = head = folio_buffers(folio); do { block_end = block_start + bh->b_size; if (buffer_new(bh)) { if (block_end > from && block_start < to) { - if (!PageUptodate(page)) { + if (!folio_test_uptodate(folio)) { unsigned start, size; start = max(from, block_start); size = min(to, block_end) - start; - zero_user(page, start, size); + folio_zero_range(folio, start, size); write_end_fn(handle, inode, bh); } clear_buffer_new(bh); @@ -1430,10 +1430,11 @@ static int ext4_journalled_write_end(struct file *file, if (unlikely(copied < len) && !folio_test_uptodate(folio)) { copied = 0; - ext4_journalled_zero_new_buffers(handle, inode, page, from, to); + ext4_journalled_zero_new_buffers(handle, inode, folio, + from, to); } else { if (unlikely(copied < len)) - ext4_journalled_zero_new_buffers(handle, inode, page, + ext4_journalled_zero_new_buffers(handle, inode, folio, from + copied, to); ret = ext4_walk_page_buffers(handle, inode, folio_buffers(folio), From patchwork Thu Jan 26 20:24:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117722 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DEBAC61DB3 for ; Thu, 26 Jan 2023 20:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232850AbjAZUYg (ORCPT ); Thu, 26 Jan 2023 15:24:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232797AbjAZUYY (ORCPT ); Thu, 26 Jan 2023 15:24:24 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EB634B765; Thu, 26 Jan 2023 12:24:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=2BOzDK6pCDMgwyThNN8pM/V+Fp6gQ9QaiOWEuZvfoMo=; b=Hgxk1OmIJAntbg5fYpMqnXFSrj 3/fqOZRtZx6YEcxSEJ6Zv9MCohDBDi/jkKMX1AljlICbOc1m3nI27O1QBAo1A1K5sdmA161Lo3WFD RetILdnqkn7tFLXW60ePDWKFJI7ms2ltDESl9Ba8XLr3RwdTbre6gL/QWPE3EqN6gHncjHioFdxmo AbmDtH5vJ/EqxaHRRyVJp9+N8RxtJz1aay7TVUjJKdW5Cp3cNZlUvRcioqCFat0iEYS1azgdQNp3A SeXXraztbdVVUFlPH55oqkGWcf7a90A5DDIaKL7l/eBE/PaxVWNAZhA3dFnfNiHq3aUmWXDET6V21 ThrzQwNA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nE-0073kp-KG; Thu, 26 Jan 2023 20:24:20 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 20/31] ext4: Convert __ext4_block_zero_page_range() to use a folio Date: Thu, 26 Jan 2023 20:24:04 +0000 Message-Id: <20230126202415.1682629-21-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use folio APIs throughout. Saves many calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Ritesh Harjani (IBM) --- fs/ext4/inode.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index b79e591b7c8e..727aa2e51a9d 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3812,23 +3812,26 @@ static int __ext4_block_zero_page_range(handle_t *handle, ext4_lblk_t iblock; struct inode *inode = mapping->host; struct buffer_head *bh; - struct page *page; + struct folio *folio; int err = 0; - page = find_or_create_page(mapping, from >> PAGE_SHIFT, - mapping_gfp_constraint(mapping, ~__GFP_FS)); - if (!page) + folio = __filemap_get_folio(mapping, from >> PAGE_SHIFT, + FGP_LOCK | FGP_ACCESSED | FGP_CREAT, + mapping_gfp_constraint(mapping, ~__GFP_FS)); + if (!folio) return -ENOMEM; blocksize = inode->i_sb->s_blocksize; iblock = index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits); - if (!page_has_buffers(page)) - create_empty_buffers(page, blocksize, 0); + bh = folio_buffers(folio); + if (!bh) { + create_empty_buffers(&folio->page, blocksize, 0); + bh = folio_buffers(folio); + } /* Find the buffer that contains "offset" */ - bh = page_buffers(page); pos = blocksize; while (offset >= pos) { bh = bh->b_this_page; @@ -3850,7 +3853,7 @@ static int __ext4_block_zero_page_range(handle_t *handle, } /* Ok, it's mapped. Make sure it's up-to-date */ - if (PageUptodate(page)) + if (folio_test_uptodate(folio)) set_buffer_uptodate(bh); if (!buffer_uptodate(bh)) { @@ -3860,7 +3863,8 @@ static int __ext4_block_zero_page_range(handle_t *handle, if (fscrypt_inode_uses_fs_layer_crypto(inode)) { /* We expect the key to be set. */ BUG_ON(!fscrypt_has_encryption_key(inode)); - err = fscrypt_decrypt_pagecache_blocks(page, blocksize, + err = fscrypt_decrypt_pagecache_blocks(&folio->page, + blocksize, bh_offset(bh)); if (err) { clear_buffer_uptodate(bh); @@ -3875,7 +3879,7 @@ static int __ext4_block_zero_page_range(handle_t *handle, if (err) goto unlock; } - zero_user(page, offset, length); + folio_zero_range(folio, offset, length); BUFFER_TRACE(bh, "zeroed end of block"); if (ext4_should_journal_data(inode)) { @@ -3889,8 +3893,8 @@ static int __ext4_block_zero_page_range(handle_t *handle, } unlock: - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); return err; } From patchwork Thu Jan 26 20:24:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117729 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D034EC61DA7 for ; Thu, 26 Jan 2023 20:24:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232874AbjAZUYo (ORCPT ); Thu, 26 Jan 2023 15:24:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232798AbjAZUYY (ORCPT ); Thu, 26 Jan 2023 15:24:24 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DE5749952; Thu, 26 Jan 2023 12:24:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Yp1hifiEATrURCYketbD6BQMeHyHPE7j4pW3CSdtzfM=; b=Ywr/wpTTJM9J2sODBgsVk4tFI7 JwOIzUxqqaG0kiJjtgre/K/HQEgxH3wnDdkkCobqs//J5ttfZF6w1XFbHGze1OqqSC2XBq/ZpCHo8 mpIAG3k2IQyNLIW/CZwv/7TgJuoJDHKOg2uuLJJFJ3ND1jz2RBj4T4EOJNA3MmMEal8LeYsN5sl5k ILYxENWT+wx8CreqQKkuSUDwwVyatpOwyIVUgRsjGjUHE9xfEGYvsGn1HkPieW7lazOIXn0LJsaso k0Y6OPOQ6+bAmuGP6F9xlaPWuGQujSzgg7wAh5LoBwZQxcHpmrGdWHggWO8aof965M/14oyYZrNsi NFbfGfYA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nE-0073kx-Ob; Thu, 26 Jan 2023 20:24:20 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 21/31] ext4: Convert __ext4_journalled_writepage() to take a folio Date: Thu, 26 Jan 2023 20:24:05 +0000 Message-Id: <20230126202415.1682629-22-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the folio APIs throughout and remove a PAGE_SIZE assumption. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/inode.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 727aa2e51a9d..9b2c21d0e1f3 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -136,7 +136,7 @@ static inline int ext4_begin_ordered_truncate(struct inode *inode, new_size); } -static int __ext4_journalled_writepage(struct page *page, unsigned int len); +static int __ext4_journalled_writepage(struct folio *folio, unsigned int len); static int ext4_meta_trans_blocks(struct inode *inode, int lblocks, int pextents); @@ -1891,10 +1891,10 @@ int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, return 0; } -static int __ext4_journalled_writepage(struct page *page, +static int __ext4_journalled_writepage(struct folio *folio, unsigned int len) { - struct address_space *mapping = page->mapping; + struct address_space *mapping = folio->mapping; struct inode *inode = mapping->host; handle_t *handle = NULL; int ret = 0, err = 0; @@ -1902,37 +1902,38 @@ static int __ext4_journalled_writepage(struct page *page, struct buffer_head *inode_bh = NULL; loff_t size; - ClearPageChecked(page); + folio_clear_checked(folio); if (inline_data) { - BUG_ON(page->index != 0); + BUG_ON(folio->index != 0); BUG_ON(len > ext4_get_max_inline_size(inode)); - inode_bh = ext4_journalled_write_inline_data(inode, len, page); + inode_bh = ext4_journalled_write_inline_data(inode, len, + &folio->page); if (inode_bh == NULL) goto out; } /* - * We need to release the page lock before we start the - * journal, so grab a reference so the page won't disappear + * We need to release the folio lock before we start the + * journal, so grab a reference so the folio won't disappear * out from under us. */ - get_page(page); - unlock_page(page); + folio_get(folio); + folio_unlock(folio); handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, ext4_writepage_trans_blocks(inode)); if (IS_ERR(handle)) { ret = PTR_ERR(handle); - put_page(page); + folio_put(folio); goto out_no_pagelock; } BUG_ON(!ext4_handle_valid(handle)); - lock_page(page); - put_page(page); + folio_lock(folio); + folio_put(folio); size = i_size_read(inode); - if (page->mapping != mapping || page_offset(page) > size) { - /* The page got truncated from under us */ + if (folio->mapping != mapping || folio_pos(folio) > size) { + /* The folio got truncated from under us */ ext4_journal_stop(handle); ret = 0; goto out; @@ -1941,12 +1942,11 @@ static int __ext4_journalled_writepage(struct page *page, if (inline_data) { ret = ext4_mark_inode_dirty(handle, inode); } else { - struct buffer_head *page_bufs = page_buffers(page); + struct buffer_head *page_bufs = folio_buffers(folio); - if (page->index == size >> PAGE_SHIFT) - len = size & ~PAGE_MASK; - else - len = PAGE_SIZE; + len = folio_size(folio); + if (folio_pos(folio) + len > size) + len = size - folio_pos(folio); ret = ext4_walk_page_buffers(handle, inode, page_bufs, 0, len, NULL, do_journal_get_write_access); @@ -1956,7 +1956,7 @@ static int __ext4_journalled_writepage(struct page *page, } if (ret == 0) ret = err; - err = ext4_jbd2_inode_add_write(handle, inode, page_offset(page), len); + err = ext4_jbd2_inode_add_write(handle, inode, folio_pos(folio), len); if (ret == 0) ret = err; EXT4_I(inode)->i_datasync_tid = handle->h_transaction->t_tid; @@ -1966,7 +1966,7 @@ static int __ext4_journalled_writepage(struct page *page, ext4_set_inode_state(inode, EXT4_STATE_JDATA); out: - unlock_page(page); + folio_unlock(folio); out_no_pagelock: brelse(inode_bh); return ret; @@ -2086,7 +2086,7 @@ static int ext4_writepage(struct page *page, * It's mmapped pagecache. Add buffers and journal it. There * doesn't seem much point in redirtying the folio here. */ - return __ext4_journalled_writepage(page, len); + return __ext4_journalled_writepage(folio, len); ext4_io_submit_init(&io_submit, wbc); io_submit.io_end = ext4_init_io_end(inode, GFP_NOFS); From patchwork Thu Jan 26 20:24:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117721 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A871C636BD for ; Thu, 26 Jan 2023 20:24:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232844AbjAZUYf (ORCPT ); Thu, 26 Jan 2023 15:24:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232793AbjAZUYY (ORCPT ); Thu, 26 Jan 2023 15:24:24 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 914B44B769; Thu, 26 Jan 2023 12:24:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=UEz9pyzC/zJuznnpiO8NJUu6xULxxn7l/UWQvd4w6/o=; b=dNiswVhYSmAZ7+Adzs5mGBDDtP JSAB134gOg3HJqVvzcGFIn3KACowbmWe6OK43LLubznsY++TrvCorBXSY9ebwha46olxEOFioUGe2 i/Qw+QQoygSEJKjYD2yw1BNCSAccHZWa+Oc4IIxSvjkYIeofNRSKj+J+VzDbsUmQKontZBPkpOtAW INGQLZNFeTUND84WTa7kEpKA6X0TSjxxwitXvVonkzbJ+1z0UEKMI8mC8NunJV/1FsLgpzx/JtRUa Oz38l2vGao8DQiYD+4FGnHsUWVm0PDjJ2VZ3AqVSnd6sy5cIpijvChEB9iX5cfwr95cNC72lZ+1Lx HQqtBaHA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nE-0073l5-S6; Thu, 26 Jan 2023 20:24:20 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 22/31] ext4: Convert ext4_page_nomap_can_writeout() to take a folio Date: Thu, 26 Jan 2023 20:24:06 +0000 Message-Id: <20230126202415.1682629-23-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Its one caller is already using a folio. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Theodore Ts'o --- fs/ext4/inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 9b2c21d0e1f3..e7e8f2946012 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2563,11 +2563,11 @@ static int ext4_da_writepages_trans_blocks(struct inode *inode) } /* Return true if the page needs to be written as part of transaction commit */ -static bool ext4_page_nomap_can_writeout(struct page *page) +static bool ext4_page_nomap_can_writeout(struct folio *folio) { struct buffer_head *bh, *head; - bh = head = page_buffers(page); + bh = head = folio_buffers(folio); do { if (buffer_dirty(bh) && buffer_mapped(bh) && !buffer_delay(bh)) return true; @@ -2683,7 +2683,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) * modify metadata is simple. Just submit the page. */ if (!mpd->can_map) { - if (ext4_page_nomap_can_writeout(&folio->page)) { + if (ext4_page_nomap_can_writeout(folio)) { err = mpage_submit_folio(mpd, folio); if (err < 0) goto out; From patchwork Thu Jan 26 20:24:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117724 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2587C61DA3 for ; Thu, 26 Jan 2023 20:24:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232855AbjAZUYi (ORCPT ); Thu, 26 Jan 2023 15:24:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232799AbjAZUYY (ORCPT ); Thu, 26 Jan 2023 15:24:24 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD4EB49954; Thu, 26 Jan 2023 12:24:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=bUmnptUoiyyV9s9VNe8+i6VzP5JZO1CccQPGrLeqfzk=; b=Or9xS/22gf8YWDIrqz0fC3yypQ /cHKtRkxj4qpPiQJd1xbokNjr3oTeMUuhLaXM+KW6Yq2ofUQ14fY+an9D7gRIZ+r/s3Pq1o2YDKBu LBmx/FZ7nMmyLg8nlR+sVY4lISirQ1/hO2XEeLW/s4o/p6t2kddlxXwShyemrpJTn+tJbwYknKIWT e1bFyvQgLa7HCA18CvVvhTMHaddiQ0B6LrIN4Y4zo+n96ZrhN9kfDL3nNN9yV34l18FVibiR68i1d icliu7WbOwpCfbLoAtNHEBxBYWLI20/uXhEITYsnOHDXztfRBkqDn4Yie7btkXUBeoW9lNGsTHYwN ri0jxJIw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nE-0073lD-Vu; Thu, 26 Jan 2023 20:24:21 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 23/31] ext4: Use a folio in ext4_da_write_begin() Date: Thu, 26 Jan 2023 20:24:07 +0000 Message-Id: <20230126202415.1682629-24-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Remove a few calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/inode.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index e7e8f2946012..8929add6808a 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3046,7 +3046,7 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping, struct page **pagep, void **fsdata) { int ret, retries = 0; - struct page *page; + struct folio *folio; pgoff_t index; struct inode *inode = mapping->host; @@ -3073,22 +3073,23 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping, } retry: - page = grab_cache_page_write_begin(mapping, index); - if (!page) + folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN, + mapping_gfp_mask(mapping)); + if (!folio) return -ENOMEM; - /* In case writeback began while the page was unlocked */ - wait_for_stable_page(page); + /* In case writeback began while the folio was unlocked */ + folio_wait_stable(folio); #ifdef CONFIG_FS_ENCRYPTION - ret = ext4_block_write_begin(page, pos, len, + ret = ext4_block_write_begin(&folio->page, pos, len, ext4_da_get_block_prep); #else - ret = __block_write_begin(page, pos, len, ext4_da_get_block_prep); + ret = __block_write_begin(&folio->page, pos, len, ext4_da_get_block_prep); #endif if (ret < 0) { - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); /* * block_write_begin may have instantiated a few blocks * outside i_size. Trim these off again. Don't need @@ -3103,7 +3104,7 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping, return ret; } - *pagep = page; + *pagep = &folio->page; return ret; } From patchwork Thu Jan 26 20:24:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117728 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 641CBC61DA3 for ; Thu, 26 Jan 2023 20:24:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232867AbjAZUYn (ORCPT ); Thu, 26 Jan 2023 15:24:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232806AbjAZUYZ (ORCPT ); Thu, 26 Jan 2023 15:24:25 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0016A4B76C; Thu, 26 Jan 2023 12:24:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=EeaPNEObsha+AWBX8R4Y4ZrKu6zLMBpNN7SqkKmdALs=; b=pruIDXeh6ee4FkxCdrpK8QyZmK lt3hVxfxXuyXALqwxERt+j/qLl+MaC8xYrXgPlPyHJ1fsoCAMh+yjthH2cJXx3wRftQjnb9iI+5du Kd4o5odr7E+/uDa+YbIb+FFdG/KP4X487UsJTfqLzLaPIC+3clFBC8kmI2IdUvY4TYy/SQkYiZ6O6 cLr4AIug+eXMBPyOanM3V+BTF57EuSTECm9jFHeTtyyN3CRO2PBOfzX7tKfadFRL4WLCB+jDsOEp7 87HrGcdUgwDgsOjsZUjcEd+GgT0HFJwQ7fBDv1syYw15BW4jRaA7XqtjdLL/400A/fKALJnCY1IvS 6fY1KSNA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nF-0073lM-58; Thu, 26 Jan 2023 20:24:21 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 24/31] ext4: Convert ext4_mpage_readpages() to work on folios Date: Thu, 26 Jan 2023 20:24:08 +0000 Message-Id: <20230126202415.1682629-25-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This definitely doesn't include support for large folios; there are all kinds of assumptions about the number of buffers attached to a folio. But it does remove several calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/ext4.h | 2 +- fs/ext4/inode.c | 7 +++--- fs/ext4/readpage.c | 58 +++++++++++++++++++++------------------------- 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index d2998800855c..faa54035dbc8 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3646,7 +3646,7 @@ static inline void ext4_set_de_type(struct super_block *sb, /* readpages.c */ extern int ext4_mpage_readpages(struct inode *inode, - struct readahead_control *rac, struct page *page); + struct readahead_control *rac, struct folio *folio); extern int __init ext4_init_post_read_processing(void); extern void ext4_exit_post_read_processing(void); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 8929add6808a..dbfc0670de75 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3299,17 +3299,16 @@ static sector_t ext4_bmap(struct address_space *mapping, sector_t block) static int ext4_read_folio(struct file *file, struct folio *folio) { - struct page *page = &folio->page; int ret = -EAGAIN; - struct inode *inode = page->mapping->host; + struct inode *inode = folio->mapping->host; - trace_ext4_readpage(page); + trace_ext4_readpage(&folio->page); if (ext4_has_inline_data(inode)) ret = ext4_readpage_inline(inode, folio); if (ret == -EAGAIN) - return ext4_mpage_readpages(inode, NULL, page); + return ext4_mpage_readpages(inode, NULL, folio); return ret; } diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c index c61dc8a7c014..8092d2ace75e 100644 --- a/fs/ext4/readpage.c +++ b/fs/ext4/readpage.c @@ -218,7 +218,7 @@ static inline loff_t ext4_readpage_limit(struct inode *inode) } int ext4_mpage_readpages(struct inode *inode, - struct readahead_control *rac, struct page *page) + struct readahead_control *rac, struct folio *folio) { struct bio *bio = NULL; sector_t last_block_in_bio = 0; @@ -247,16 +247,15 @@ int ext4_mpage_readpages(struct inode *inode, int fully_mapped = 1; unsigned first_hole = blocks_per_page; - if (rac) { - page = readahead_page(rac); - prefetchw(&page->flags); - } + if (rac) + folio = readahead_folio(rac); + prefetchw(&folio->flags); - if (page_has_buffers(page)) + if (folio_buffers(folio)) goto confused; block_in_file = next_block = - (sector_t)page->index << (PAGE_SHIFT - blkbits); + (sector_t)folio->index << (PAGE_SHIFT - blkbits); last_block = block_in_file + nr_pages * blocks_per_page; last_block_in_file = (ext4_readpage_limit(inode) + blocksize - 1) >> blkbits; @@ -290,7 +289,7 @@ int ext4_mpage_readpages(struct inode *inode, /* * Then do more ext4_map_blocks() calls until we are - * done with this page. + * done with this folio. */ while (page_block < blocks_per_page) { if (block_in_file < last_block) { @@ -299,11 +298,11 @@ int ext4_mpage_readpages(struct inode *inode, if (ext4_map_blocks(NULL, inode, &map, 0) < 0) { set_error_page: - SetPageError(page); - zero_user_segment(page, 0, - PAGE_SIZE); - unlock_page(page); - goto next_page; + folio_set_error(folio); + folio_zero_segment(folio, 0, + folio_size(folio)); + folio_unlock(folio); + continue; } } if ((map.m_flags & EXT4_MAP_MAPPED) == 0) { @@ -333,22 +332,22 @@ int ext4_mpage_readpages(struct inode *inode, } } if (first_hole != blocks_per_page) { - zero_user_segment(page, first_hole << blkbits, - PAGE_SIZE); + folio_zero_segment(folio, first_hole << blkbits, + folio_size(folio)); if (first_hole == 0) { - if (ext4_need_verity(inode, page->index) && - !fsverity_verify_page(page)) + if (ext4_need_verity(inode, folio->index) && + !fsverity_verify_page(&folio->page)) goto set_error_page; - SetPageUptodate(page); - unlock_page(page); - goto next_page; + folio_mark_uptodate(folio); + folio_unlock(folio); + continue; } } else if (fully_mapped) { - SetPageMappedToDisk(page); + folio_set_mappedtodisk(folio); } /* - * This page will go to BIO. Do we need to send this + * This folio will go to BIO. Do we need to send this * BIO off first? */ if (bio && (last_block_in_bio != blocks[0] - 1 || @@ -366,7 +365,7 @@ int ext4_mpage_readpages(struct inode *inode, REQ_OP_READ, GFP_KERNEL); fscrypt_set_bio_crypt_ctx(bio, inode, next_block, GFP_KERNEL); - ext4_set_bio_post_read_ctx(bio, inode, page->index); + ext4_set_bio_post_read_ctx(bio, inode, folio->index); bio->bi_iter.bi_sector = blocks[0] << (blkbits - 9); bio->bi_end_io = mpage_end_io; if (rac) @@ -374,7 +373,7 @@ int ext4_mpage_readpages(struct inode *inode, } length = first_hole << blkbits; - if (bio_add_page(bio, page, length, 0) < length) + if (!bio_add_folio(bio, folio, length, 0)) goto submit_and_realloc; if (((map.m_flags & EXT4_MAP_BOUNDARY) && @@ -384,19 +383,16 @@ int ext4_mpage_readpages(struct inode *inode, bio = NULL; } else last_block_in_bio = blocks[blocks_per_page - 1]; - goto next_page; + continue; confused: if (bio) { submit_bio(bio); bio = NULL; } - if (!PageUptodate(page)) - block_read_full_folio(page_folio(page), ext4_get_block); + if (!folio_test_uptodate(folio)) + block_read_full_folio(folio, ext4_get_block); else - unlock_page(page); - next_page: - if (rac) - put_page(page); + folio_unlock(folio); } if (bio) submit_bio(bio); From patchwork Thu Jan 26 20:24:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117723 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61240C05027 for ; Thu, 26 Jan 2023 20:24:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232852AbjAZUYh (ORCPT ); Thu, 26 Jan 2023 15:24:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232801AbjAZUYZ (ORCPT ); Thu, 26 Jan 2023 15:24:25 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EADB4B88D; Thu, 26 Jan 2023 12:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=07jZVgnshAtXEL+2qn3RaXP+/v3Z8FnGfbVeAWNPvp8=; b=YdP3KGeVrX3PlhQjWiiFiGBmUL 89ShociKKWDjzI5TA2+ueXa8ryD/IkJ3LvE2KcQLot31lApvCVmrEL6DozrUKRe0tWyLAlheVecjU DAPfxMaeCajYG2i94dxk2dxUKavXdQ5kwLYQ2qOzDw2Gc8WQh10JkRCyT4t7NRBrQ/ERElM3fLQiP I83SVaiHmYhrtO5UQGffutc7T1eBLe8sV1Dj51WwxUc8/M2koOvH6tGb+WjHRZAzpTFXSPvxpt9Pg V+sK38tiFSI1kIQryh3hWlsxzKwGEwNzPDM6DAwRIvdlkUvRx15s04bl71P07y6qbqsNkJcTOnUXG NwyPTakA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nF-0073lV-An; Thu, 26 Jan 2023 20:24:21 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 25/31] ext4: Convert ext4_block_write_begin() to take a folio Date: Thu, 26 Jan 2023 20:24:09 +0000 Message-Id: <20230126202415.1682629-26-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org All the callers now have a folio, so pass that in and operate on folios. Removes four calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Ritesh Harjani (IBM) --- fs/ext4/inode.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index dbfc0670de75..507c7f88d737 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1055,12 +1055,12 @@ int do_journal_get_write_access(handle_t *handle, struct inode *inode, } #ifdef CONFIG_FS_ENCRYPTION -static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len, +static int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len, get_block_t *get_block) { unsigned from = pos & (PAGE_SIZE - 1); unsigned to = from + len; - struct inode *inode = page->mapping->host; + struct inode *inode = folio->mapping->host; unsigned block_start, block_end; sector_t block; int err = 0; @@ -1070,22 +1070,24 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len, int nr_wait = 0; int i; - BUG_ON(!PageLocked(page)); + BUG_ON(!folio_test_locked(folio)); BUG_ON(from > PAGE_SIZE); BUG_ON(to > PAGE_SIZE); BUG_ON(from > to); - if (!page_has_buffers(page)) - create_empty_buffers(page, blocksize, 0); - head = page_buffers(page); + head = folio_buffers(folio); + if (!head) { + create_empty_buffers(&folio->page, blocksize, 0); + head = folio_buffers(folio); + } bbits = ilog2(blocksize); - block = (sector_t)page->index << (PAGE_SHIFT - bbits); + block = (sector_t)folio->index << (PAGE_SHIFT - bbits); for (bh = head, block_start = 0; bh != head || !block_start; block++, block_start = block_end, bh = bh->b_this_page) { block_end = block_start + blocksize; if (block_end <= from || block_start >= to) { - if (PageUptodate(page)) { + if (folio_test_uptodate(folio)) { set_buffer_uptodate(bh); } continue; @@ -1098,19 +1100,20 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len, if (err) break; if (buffer_new(bh)) { - if (PageUptodate(page)) { + if (folio_test_uptodate(folio)) { clear_buffer_new(bh); set_buffer_uptodate(bh); mark_buffer_dirty(bh); continue; } if (block_end > to || block_start < from) - zero_user_segments(page, to, block_end, - block_start, from); + folio_zero_segments(folio, to, + block_end, + block_start, from); continue; } } - if (PageUptodate(page)) { + if (folio_test_uptodate(folio)) { set_buffer_uptodate(bh); continue; } @@ -1130,13 +1133,13 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len, err = -EIO; } if (unlikely(err)) { - page_zero_new_buffers(page, from, to); + page_zero_new_buffers(&folio->page, from, to); } else if (fscrypt_inode_uses_fs_layer_crypto(inode)) { for (i = 0; i < nr_wait; i++) { int err2; - err2 = fscrypt_decrypt_pagecache_blocks(page, blocksize, - bh_offset(wait[i])); + err2 = fscrypt_decrypt_pagecache_blocks(&folio->page, + blocksize, bh_offset(wait[i])); if (err2) { clear_buffer_uptodate(wait[i]); err = err2; @@ -1223,11 +1226,10 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, #ifdef CONFIG_FS_ENCRYPTION if (ext4_should_dioread_nolock(inode)) - ret = ext4_block_write_begin(&folio->page, pos, len, + ret = ext4_block_write_begin(folio, pos, len, ext4_get_block_unwritten); else - ret = ext4_block_write_begin(&folio->page, pos, len, - ext4_get_block); + ret = ext4_block_write_begin(folio, pos, len, ext4_get_block); #else if (ext4_should_dioread_nolock(inode)) ret = __block_write_begin(&folio->page, pos, len, @@ -3082,8 +3084,7 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping, folio_wait_stable(folio); #ifdef CONFIG_FS_ENCRYPTION - ret = ext4_block_write_begin(&folio->page, pos, len, - ext4_da_get_block_prep); + ret = ext4_block_write_begin(folio, pos, len, ext4_da_get_block_prep); #else ret = __block_write_begin(&folio->page, pos, len, ext4_da_get_block_prep); #endif From patchwork Thu Jan 26 20:24:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117725 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3088BC61DA7 for ; Thu, 26 Jan 2023 20:24:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232858AbjAZUYj (ORCPT ); Thu, 26 Jan 2023 15:24:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232802AbjAZUYZ (ORCPT ); Thu, 26 Jan 2023 15:24:25 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 323E54B8AE; Thu, 26 Jan 2023 12:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=5mlgMvqIZNbmGESykCx2U0lIh2Wy+L5n/rR+hSRI+8s=; b=LSzJbp6OyUeJ93wtuiU4gMcyXR tGIzw19LOzJiZaBL6g+gu4Rw2Aw7sX5kElrC+XGgX9dHtCsCYu2+sxgxCZ8lYedz+USEOcKJN4Jwz 1a/Em/KZS0Vkojb7JW/Hj/5GRdzZfztp1kYZ3SeB4EKf/fmqtidkrnE+nolxMPKamx1gvIGU2oOSD +pP46HjPh7oMcm597CxdGAcw2DoMb7TQKhxJMYuv7+AkNF7aNW2Qxk8/caIc4F2tFDyjyUd0ikONB uXfoA2B7TEncsavlLKB0izTS4+ATjG2wacl3RILTTLMNh3XjiYdcYppIzv9cqPxqk9n7fCQUaGKqi CTVUgMXw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nF-0073le-Fv; Thu, 26 Jan 2023 20:24:21 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 26/31] ext4: Convert ext4_writepage() to take a folio Date: Thu, 26 Jan 2023 20:24:10 +0000 Message-Id: <20230126202415.1682629-27-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Its one caller already has a folio. Saves a call to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 507c7f88d737..9bcf7459a0c0 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2015,10 +2015,9 @@ static int __ext4_journalled_writepage(struct folio *folio, * But since we don't do any block allocation we should not deadlock. * Page also have the dirty flag cleared so we don't get recurive page_lock. */ -static int ext4_writepage(struct page *page, +static int ext4_writepage(struct folio *folio, struct writeback_control *wbc) { - struct folio *folio = page_folio(page); int ret = 0; loff_t size; size_t len; @@ -2032,7 +2031,7 @@ static int ext4_writepage(struct page *page, return -EIO; } - trace_ext4_writepage(page); + trace_ext4_writepage(&folio->page); size = i_size_read(inode); len = folio_size(folio); if (folio_pos(folio) + len > size && @@ -2719,7 +2718,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) static int ext4_writepage_cb(struct folio *folio, struct writeback_control *wbc, void *data) { - return ext4_writepage(&folio->page, wbc); + return ext4_writepage(folio, wbc); } static int ext4_do_writepages(struct mpage_da_data *mpd) From patchwork Thu Jan 26 20:24:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117727 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F441C05027 for ; Thu, 26 Jan 2023 20:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232864AbjAZUYm (ORCPT ); Thu, 26 Jan 2023 15:24:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232808AbjAZUYZ (ORCPT ); Thu, 26 Jan 2023 15:24:25 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7694E4AA49; Thu, 26 Jan 2023 12:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=kEXYXbsM0fDELA034BmJN/Q2NbhIEm6ZfcGpwk7oDVY=; b=mLcquS0ppn9TSucOfF8R/FH4l5 FykYbPiUsQv7/Li4nCSYIetf+8eL8XSpnVIk+Hv3WqhksU7xC/wOv7nmh2UPmWLhelEd/LkZXsn88 k0iG6iGqyjZmrUxaddSQuMUATmfIiwe/gEUHQQ0JlM3nAfJWMamrw4k7TXiBtWCwCjcWPcVC3zGK8 8C05hutgaeLmeAJ43AggmGOAZ3QY6CxWemCBjjztuYTPCz4T14iV2sqsSl7xCoe5LxzKuSdeDxqtF esh0YK9Tkg9sJkMUi2J1O0GgbQ5Rp1XDGmnVuhjYRB09Eop7qsePQOh8F3uMUQh4zhjmvHnlTxk1l yTEfyXiw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nF-0073ln-M6; Thu, 26 Jan 2023 20:24:21 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 27/31] ext4: Use a folio in ext4_page_mkwrite() Date: Thu, 26 Jan 2023 20:24:11 +0000 Message-Id: <20230126202415.1682629-28-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Convert to the folio API, saving a few calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/inode.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 9bcf7459a0c0..dcb99121f1c1 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -6215,7 +6215,7 @@ static int ext4_bh_unmapped(handle_t *handle, struct inode *inode, vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; - struct page *page = vmf->page; + struct folio *folio = page_folio(vmf->page); loff_t size; unsigned long len; int err; @@ -6259,19 +6259,18 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) goto out_ret; } - lock_page(page); + folio_lock(folio); size = i_size_read(inode); /* Page got truncated from under us? */ - if (page->mapping != mapping || page_offset(page) > size) { - unlock_page(page); + if (folio->mapping != mapping || folio_pos(folio) > size) { + folio_unlock(folio); ret = VM_FAULT_NOPAGE; goto out; } - if (page->index == size >> PAGE_SHIFT) - len = size & ~PAGE_MASK; - else - len = PAGE_SIZE; + len = folio_size(folio); + if (folio_pos(folio) + len > size) + len = size - folio_pos(folio); /* * Return if we have all the buffers mapped. This avoids the need to do * journal_start/journal_stop which can block and take a long time @@ -6279,17 +6278,17 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) * This cannot be done for data journalling, as we have to add the * inode to the transaction's list to writeprotect pages on commit. */ - if (page_has_buffers(page)) { - if (!ext4_walk_page_buffers(NULL, inode, page_buffers(page), + if (folio_buffers(folio)) { + if (!ext4_walk_page_buffers(NULL, inode, folio_buffers(folio), 0, len, NULL, ext4_bh_unmapped)) { /* Wait so that we don't change page under IO */ - wait_for_stable_page(page); + folio_wait_stable(folio); ret = VM_FAULT_LOCKED; goto out; } } - unlock_page(page); + folio_unlock(folio); /* OK, we need to fill the hole... */ if (ext4_should_dioread_nolock(inode)) get_block = ext4_get_block_unwritten; @@ -6310,36 +6309,35 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) if (!ext4_should_journal_data(inode)) { err = block_page_mkwrite(vma, vmf, get_block); } else { - lock_page(page); + folio_lock(folio); size = i_size_read(inode); /* Page got truncated from under us? */ - if (page->mapping != mapping || page_offset(page) > size) { + if (folio->mapping != mapping || folio_pos(folio) > size) { ret = VM_FAULT_NOPAGE; goto out_error; } - if (page->index == size >> PAGE_SHIFT) - len = size & ~PAGE_MASK; - else - len = PAGE_SIZE; + len = folio_size(folio); + if (folio_pos(folio) + len > size) + len = size - folio_pos(folio); - err = __block_write_begin(page, 0, len, ext4_get_block); + err = __block_write_begin(&folio->page, 0, len, ext4_get_block); if (!err) { ret = VM_FAULT_SIGBUS; if (ext4_walk_page_buffers(handle, inode, - page_buffers(page), 0, len, NULL, + folio_buffers(folio), 0, len, NULL, do_journal_get_write_access)) goto out_error; if (ext4_walk_page_buffers(handle, inode, - page_buffers(page), 0, len, NULL, + folio_buffers(folio), 0, len, NULL, write_end_fn)) goto out_error; if (ext4_jbd2_inode_add_write(handle, inode, - page_offset(page), len)) + folio_pos(folio), len)) goto out_error; ext4_set_inode_state(inode, EXT4_STATE_JDATA); } else { - unlock_page(page); + folio_unlock(folio); } } ext4_journal_stop(handle); @@ -6352,7 +6350,7 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) sb_end_pagefault(inode->i_sb); return ret; out_error: - unlock_page(page); + folio_unlock(folio); ext4_journal_stop(handle); goto out; } From patchwork Thu Jan 26 20:24:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117726 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46DF2C54EAA for ; Thu, 26 Jan 2023 20:24:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232860AbjAZUYk (ORCPT ); Thu, 26 Jan 2023 15:24:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232807AbjAZUYZ (ORCPT ); Thu, 26 Jan 2023 15:24:25 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ACE14C0D9; Thu, 26 Jan 2023 12:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=GNjx3dnJGxVhFqH4q5lVhBk6E+7IfMU9GlJw/UIY2j4=; b=cyh9ex1iU7eX2iRFWcp+dErSNd 6WB+sTvrB2FcZwXSROYwcxYr09r+HaE8Y5FCxk4RiFHIlduetzkvtoT09XhoVwYAih5vR+ofj6T7F UWubPsP3TP7qu2OORK0VN8tflbc08B1ESueSJp/kKgj2++ZjQxcriP6xPc8lWsQ4a9bOCJWa55G6T f/sQ4747hj3FXj66L2N2nY/ZsBPNsaXkyU8GcMHDboA6QfX3UorAUq5rLz/P29+7LN+E0KKv/JESC D2HP0DWheg+FzcmOi8VqyCHhEvsWc0cPy6K9h73fEjXWkLnORCWjzlW8W3ckqOo4pPigDWNjqwRRQ Y5bjB25Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nF-0073lt-Pk; Thu, 26 Jan 2023 20:24:21 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 28/31] ext4: Use a folio iterator in __read_end_io() Date: Thu, 26 Jan 2023 20:24:12 +0000 Message-Id: <20230126202415.1682629-29-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Iterate once per folio, not once per page. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/readpage.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c index 8092d2ace75e..442f6c507016 100644 --- a/fs/ext4/readpage.c +++ b/fs/ext4/readpage.c @@ -68,18 +68,16 @@ struct bio_post_read_ctx { static void __read_end_io(struct bio *bio) { - struct page *page; - struct bio_vec *bv; - struct bvec_iter_all iter_all; + struct folio_iter fi; - bio_for_each_segment_all(bv, bio, iter_all) { - page = bv->bv_page; + bio_for_each_folio_all(fi, bio) { + struct folio *folio = fi.folio; if (bio->bi_status) - ClearPageUptodate(page); + folio_clear_uptodate(folio); else - SetPageUptodate(page); - unlock_page(page); + folio_mark_uptodate(folio); + folio_unlock(folio); } if (bio->bi_private) mempool_free(bio->bi_private, bio_post_read_ctx_pool); From patchwork Thu Jan 26 20:24:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117730 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83EE3C636BD for ; Thu, 26 Jan 2023 20:24:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232875AbjAZUYp (ORCPT ); Thu, 26 Jan 2023 15:24:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232813AbjAZUY1 (ORCPT ); Thu, 26 Jan 2023 15:24:27 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B97B24996E; Thu, 26 Jan 2023 12:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=5jhXruLPTjV4jnzqjiicBJgcR5CbK9TLgTzbBD00gmc=; b=SSOfATmVX8WNvGThd35CmIdYxk OzU3I/25ZUHoVg9S9Wlw3GVzh2rCS0zlKTrgXzs4eaPr2yVKSVMHx4QEgf7AjXEzUlgeVNfVDnPkA vWHJNVi5F19ypT/9KfrcJ0RhTDxUegCB85FMDAqi+tpVJZi7O+zuhCSKHnwkH2tRO1MO4sL2wkG/X JdL88xvD0Ly41ypc5SpizaHHxCMVHqAFE24lh40Zd98O/xRjUPXxHHExGg1JoOgLp5NnL0JyIJTNo WUMWvo4yD8GULSIQbtYSv3dYLNy+NbAaw+zlPK6rYvEzS4Ahommaup1sRAsX4IaN0OjrCkHJm6Bfk GD7eYcEA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nF-0073m3-Tt; Thu, 26 Jan 2023 20:24:21 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 29/31] ext4: Convert mext_page_mkuptodate() to take a folio Date: Thu, 26 Jan 2023 20:24:13 +0000 Message-Id: <20230126202415.1682629-30-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use a folio throughout. Does not support large folios due to an array sized for MAX_BUF_PER_PAGE, but it does remove a few calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/move_extent.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 0cb361f0a4fe..e509c22a21ed 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -168,25 +168,27 @@ mext_folio_double_lock(struct inode *inode1, struct inode *inode2, /* Force page buffers uptodate w/o dropping page's lock */ static int -mext_page_mkuptodate(struct page *page, unsigned from, unsigned to) +mext_page_mkuptodate(struct folio *folio, unsigned from, unsigned to) { - struct inode *inode = page->mapping->host; + struct inode *inode = folio->mapping->host; sector_t block; struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE]; unsigned int blocksize, block_start, block_end; int i, err, nr = 0, partial = 0; - BUG_ON(!PageLocked(page)); - BUG_ON(PageWriteback(page)); + BUG_ON(!folio_test_locked(folio)); + BUG_ON(folio_test_writeback(folio)); - if (PageUptodate(page)) + if (folio_test_uptodate(folio)) return 0; blocksize = i_blocksize(inode); - if (!page_has_buffers(page)) - create_empty_buffers(page, blocksize, 0); + head = folio_buffers(folio); + if (!head) { + create_empty_buffers(&folio->page, blocksize, 0); + head = folio_buffers(folio); + } - head = page_buffers(page); - block = (sector_t)page->index << (PAGE_SHIFT - inode->i_blkbits); + block = (sector_t)folio->index << (PAGE_SHIFT - inode->i_blkbits); for (bh = head, block_start = 0; bh != head || !block_start; block++, block_start = block_end, bh = bh->b_this_page) { block_end = block_start + blocksize; @@ -200,11 +202,11 @@ mext_page_mkuptodate(struct page *page, unsigned from, unsigned to) if (!buffer_mapped(bh)) { err = ext4_get_block(inode, block, bh, 0); if (err) { - SetPageError(page); + folio_set_error(folio); return err; } if (!buffer_mapped(bh)) { - zero_user(page, block_start, blocksize); + folio_zero_range(folio, block_start, blocksize); set_buffer_uptodate(bh); continue; } @@ -226,7 +228,7 @@ mext_page_mkuptodate(struct page *page, unsigned from, unsigned to) } out: if (!partial) - SetPageUptodate(page); + folio_mark_uptodate(folio); return 0; } @@ -354,7 +356,7 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode, goto unlock_folios; } data_copy: - *err = mext_page_mkuptodate(&folio[0]->page, from, from + replaced_size); + *err = mext_page_mkuptodate(folio[0], from, from + replaced_size); if (*err) goto unlock_folios; From patchwork Thu Jan 26 20:24:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117731 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 530E5C54EAA for ; Thu, 26 Jan 2023 20:24:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232878AbjAZUYr (ORCPT ); Thu, 26 Jan 2023 15:24:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232814AbjAZUY1 (ORCPT ); Thu, 26 Jan 2023 15:24:27 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DABF64E530; Thu, 26 Jan 2023 12:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=WTuEV+v2QAuZHEKsjDbJY0gaIFuqsdJFbqMpvu3aCW8=; b=QXqIZC3Y51EOe4da4Sl4rQ4Sb4 cIZC1FK2XCt18qJMJCKTfkVoF7f1us+Jl7tyl9GjJYXkm8UOhLbmoDs94hyhHX2r1eHcIV2bDQVD9 cyCpiDzgTaxvRv++bPKE0vcJtJbi8ZZcurlH+aHJift91mwScRYtP49iItY5KppMR2NOaMJuNcegh uzA6bH0XRB6NPf92CkEPaXKz3HDiQcQcLAieO73+n4cwJ9rA1Fswlr/dwk/8LEw+5SwfVbhffBbRF OqZ30/6pjs06oRY+tZ0s223BBmaJh09hlSy7E4EPy3uQVg+0PH82pyNKGUXZLkiCiF0iQqvOEkBO2 4uzBU5lw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nG-0073mC-1t; Thu, 26 Jan 2023 20:24:22 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 30/31] ext4: Convert pagecache_read() to use a folio Date: Thu, 26 Jan 2023 20:24:14 +0000 Message-Id: <20230126202415.1682629-31-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the folio API and support folios of arbitrary sizes. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/verity.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/ext4/verity.c b/fs/ext4/verity.c index e4da1704438e..afe847c967a4 100644 --- a/fs/ext4/verity.c +++ b/fs/ext4/verity.c @@ -42,18 +42,16 @@ static int pagecache_read(struct inode *inode, void *buf, size_t count, loff_t pos) { while (count) { - size_t n = min_t(size_t, count, - PAGE_SIZE - offset_in_page(pos)); - struct page *page; + struct folio *folio; + size_t n; - page = read_mapping_page(inode->i_mapping, pos >> PAGE_SHIFT, + folio = read_mapping_folio(inode->i_mapping, pos >> PAGE_SHIFT, NULL); - if (IS_ERR(page)) - return PTR_ERR(page); - - memcpy_from_page(buf, page, offset_in_page(pos), n); + if (IS_ERR(folio)) + return PTR_ERR(folio); - put_page(page); + n = memcpy_from_file_folio(buf, folio, pos, count); + folio_put(folio); buf += n; pos += n; From patchwork Thu Jan 26 20:24:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13117732 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23FCCC636CB for ; Thu, 26 Jan 2023 20:24:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232887AbjAZUYs (ORCPT ); Thu, 26 Jan 2023 15:24:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232817AbjAZUY1 (ORCPT ); Thu, 26 Jan 2023 15:24:27 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1600F521CC; Thu, 26 Jan 2023 12:24:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=SGFGC12Z+ymBcv5e0zP1PI9n9QX5NFVw+YtLBtPI3gA=; b=YHgd7mAsWjQRAPVKDcCPaubHIC 816gwbuIimsAaGYh62Xw3szc+2KJcfyONOYlDzvhSy9+WaCLK1LsGnXz/jIT0d1EhtJeuXxNvLRme tZbiUeFUvGaY3pto0ziN38YyPcZClSHIf2F8g30FiZfMPk0m7zJtdU5JxiS0Ug9uwpaXOF7Dq6zrF Jyq1+h98kh93pWuGF2fKfDuSXR1/XD66RqtPxmr9FzF2RqPjVCa5z8OxKxik0cF9ihKz2ogBaTs7n azVngSBgYr/9Yf+0RKJ7kNsZX9tcBHTjdVrB1kPy2xYJCphF0pc7qRsZWhcbkxeduP506jfE8gVNg Em8KxtzA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL8nG-0073mM-6G; Thu, 26 Jan 2023 20:24:22 +0000 From: "Matthew Wilcox (Oracle)" To: "Theodore Tso" , Andreas Dilger Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 31/31] ext4: Use a folio in ext4_read_merkle_tree_page Date: Thu, 26 Jan 2023 20:24:15 +0000 Message-Id: <20230126202415.1682629-32-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230126202415.1682629-1-willy@infradead.org> References: <20230126202415.1682629-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is an implementation of fsverity_operations read_merkle_tree_page, so it must still return the precise page asked for, but we can use the folio API to reduce the number of conversions between folios & pages. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/verity.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/ext4/verity.c b/fs/ext4/verity.c index afe847c967a4..3b01247066dd 100644 --- a/fs/ext4/verity.c +++ b/fs/ext4/verity.c @@ -361,21 +361,21 @@ static struct page *ext4_read_merkle_tree_page(struct inode *inode, pgoff_t index, unsigned long num_ra_pages) { - struct page *page; + struct folio *folio; index += ext4_verity_metadata_pos(inode) >> PAGE_SHIFT; - page = find_get_page_flags(inode->i_mapping, index, FGP_ACCESSED); - if (!page || !PageUptodate(page)) { + folio = __filemap_get_folio(inode->i_mapping, index, FGP_ACCESSED, 0); + if (!folio || !folio_test_uptodate(folio)) { DEFINE_READAHEAD(ractl, NULL, NULL, inode->i_mapping, index); - if (page) - put_page(page); + if (folio) + folio_put(folio); else if (num_ra_pages > 1) page_cache_ra_unbounded(&ractl, num_ra_pages, 0); - page = read_mapping_page(inode->i_mapping, index, NULL); + folio = read_mapping_folio(inode->i_mapping, index, NULL); } - return page; + return folio_file_page(folio, index); } static int ext4_write_merkle_tree_block(struct inode *inode, const void *buf,