From patchwork Wed Jan 18 09:43:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13106076 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 0AB9FC46467 for ; Wed, 18 Jan 2023 10:40:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229874AbjARKkQ (ORCPT ); Wed, 18 Jan 2023 05:40:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbjARKjO (ORCPT ); Wed, 18 Jan 2023 05:39:14 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E88874F85B; Wed, 18 Jan 2023 01:43:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=MhCSeZxb0+ckteL2o3EcN0B0EMYZcaQYxCAND8YfTVw=; b=zb1P9ij/tKigVouQ1O/C4uCAS7 +JypLZQNpDNL8SKR+sx/aWG6SqmtWucbKq/npM9f01Nx4vipYaGkmRmfWPM8//WBMOWyul+joXZdf kI5DelXAG5u3Mial8ZsWDnwcWoQEls3QmRsMZpx+Ma9ZXSGvSOElPAlQ+CVHpa0i0ip+rT5GjIbdg S5G36phYR1i2oNyuWdEu+/jo4jmYoCDTehy+LLF2qrMRA/2CXC2tH9oCz02ukaqRRI8A/Yxuj3r11 ZC3nBMs5rlV1N/an3gFPLb/4i4RUC1kPq64ESJTixD6mQn5Lrv1DKGai8eyUnSX8o2BGpovyOd4r7 +F3UHI8g==; Received: from 213-147-167-250.nat.highway.webapn.at ([213.147.167.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI4yo-0009vw-M1; Wed, 18 Jan 2023 09:43:39 +0000 From: Christoph Hellwig To: Andrew Morton , Matthew Wilcox , Hugh Dickins Cc: linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com, linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nilfs@vger.kernel.org Subject: [PATCH 1/9] mm: don't look at xarray value entries in split_huge_pages_in_file Date: Wed, 18 Jan 2023 10:43:21 +0100 Message-Id: <20230118094329.9553-2-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118094329.9553-1-hch@lst.de> References: <20230118094329.9553-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org split_huge_pages_in_file never wants to do anything with the special value enties. Switch to using filemap_get_folio to not even see them. Signed-off-by: Christoph Hellwig Reviewed-by: Matthew Wilcox (Oracle) --- mm/huge_memory.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 1d6977dc6b31ba..a2830019aaa017 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3100,11 +3100,10 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, mapping = candidate->f_mapping; for (index = off_start; index < off_end; index += nr_pages) { - struct folio *folio = __filemap_get_folio(mapping, index, - FGP_ENTRY, 0); + struct folio *folio = filemap_get_folio(mapping, index); nr_pages = 1; - if (xa_is_value(folio) || !folio) + if (!folio) continue; if (!folio_test_large(folio)) From patchwork Wed Jan 18 09:43:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13106084 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 16D56C32793 for ; Wed, 18 Jan 2023 10:41:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229909AbjARKl3 (ORCPT ); Wed, 18 Jan 2023 05:41:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229893AbjARKjY (ORCPT ); Wed, 18 Jan 2023 05:39:24 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7050166CDC; Wed, 18 Jan 2023 01:43:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=OEkmrOTp9bp0MHf7fBWQdFeBfwkVijLbFt/ZuD+SID8=; b=fWwuU2mFDmXn7LwEaystbVgNKf 6W93ZUCVYBEuM6BrPk3yZuB09IzyaYZNsTkpzicBlyvZKyWPX0ki0J49msMlHfuxugAu1eEpI689X y3CMYNJbf3x3e3glDVCfRkR2AGRlBUjvBFY2PU2onSO73vKdDz+4yihTQap94U2geZXsUIy3Nugm1 wwPypEDOLE1/EGs/LD+ckYeTYmWPL3OM5Ra2Ppy9xP69HNLk6e/o8aBvYgPktsz2IXYbniaEeToGZ 4S8+Y9JfE4TjlT4PHg3Q+l/NnOBJcLddPWjYBKnTtMY7K5Z+TnqSyyRu9ooFbBu2aIsdGxbH9f2oO xXZ8yYKQ==; Received: from 213-147-167-250.nat.highway.webapn.at ([213.147.167.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI4yt-0009wo-CP; Wed, 18 Jan 2023 09:43:43 +0000 From: Christoph Hellwig To: Andrew Morton , Matthew Wilcox , Hugh Dickins Cc: linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com, linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nilfs@vger.kernel.org Subject: [PATCH 2/9] mm: make mapping_get_entry available outside of filemap.c Date: Wed, 18 Jan 2023 10:43:22 +0100 Message-Id: <20230118094329.9553-3-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118094329.9553-1-hch@lst.de> References: <20230118094329.9553-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org mapping_get_entry is useful for page cache API users that need to know about xa_value internals. Rename it and make it available in pagemap.h. Signed-off-by: Christoph Hellwig Reviewed-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 1 + mm/filemap.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 9f108168377195..24dedf6b12be49 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -507,6 +507,7 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping, #define FGP_ENTRY 0x00000080 #define FGP_STABLE 0x00000100 +void *filemap_get_entry(struct address_space *mapping, pgoff_t index); 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/filemap.c b/mm/filemap.c index c915ded191f03f..ed0583f9e27512 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1834,7 +1834,7 @@ EXPORT_SYMBOL(page_cache_prev_miss); */ /* - * mapping_get_entry - Get a page cache entry. + * filemap_get_entry - Get a page cache entry. * @mapping: the address_space to search * @index: The page cache index. * @@ -1845,7 +1845,7 @@ EXPORT_SYMBOL(page_cache_prev_miss); * * Return: The folio, swap or shadow entry, %NULL if nothing is found. */ -static void *mapping_get_entry(struct address_space *mapping, pgoff_t index) +void *filemap_get_entry(struct address_space *mapping, pgoff_t index) { XA_STATE(xas, &mapping->i_pages, index); struct folio *folio; @@ -1915,7 +1915,7 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, struct folio *folio; repeat: - folio = mapping_get_entry(mapping, index); + folio = filemap_get_entry(mapping, index); if (xa_is_value(folio)) { if (fgp_flags & FGP_ENTRY) return folio; From patchwork Wed Jan 18 09:43:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13106083 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 E51D1C32793 for ; Wed, 18 Jan 2023 10:41:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230024AbjARKlZ (ORCPT ); Wed, 18 Jan 2023 05:41:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230004AbjARKje (ORCPT ); Wed, 18 Jan 2023 05:39:34 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9AF6C41C9; Wed, 18 Jan 2023 01:43:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=1tivNYnlYVjl+dCfTLCmKC5DzLdFgx18xVeklobnFOc=; b=oK86k6pKeZIcKg+Va0m3zSYnjp gdfBbtk752RFEObSR9dD/b0hSJZ+q6liwdtaOTuc+dZZjdn0uEBzCqUHQzMjPvwG/Uy75gc4xEjYT Zc6N0l/AGGagjNvK0usj0Ru2kn67AlvrxYxEIlLGFWVxDaD3WX4PRNuqYGnhJ+eTsWFF4cJ/nIic7 8ZA18lYUNGRHuUCEsd4YsVPU+DUCq5f/B4gOa9Vj5CrRRw+uKTHIiRdsE0s7zrKs48MkWSVwFXKmZ CcxQZeEif++QTTZv/8MNZaoq60DHPDo1DfYTsTFm1cnoaVz2hBTo7sJJbPBtPznpgeAWzzQ/Vqvco bg2FpGKQ==; Received: from 213-147-167-250.nat.highway.webapn.at ([213.147.167.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI4yx-0009xj-Fn; Wed, 18 Jan 2023 09:43:48 +0000 From: Christoph Hellwig To: Andrew Morton , Matthew Wilcox , Hugh Dickins Cc: linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com, linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nilfs@vger.kernel.org Subject: [PATCH 3/9] mm: use filemap_get_entry in filemap_get_incore_folio Date: Wed, 18 Jan 2023 10:43:23 +0100 Message-Id: <20230118094329.9553-4-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118094329.9553-1-hch@lst.de> References: <20230118094329.9553-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org filemap_get_incore_folio wants to look at the details of xa_is_value entries, but doesn't need any of the other logic in filemap_get_folio. Switch it to use the lower-level filemap_get_entry interface. Signed-off-by: Christoph Hellwig Reviewed-by: Matthew Wilcox (Oracle) --- mm/swap_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index cb9aaa00951d99..c39ea34bc4fc10 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -380,7 +380,7 @@ struct folio *filemap_get_incore_folio(struct address_space *mapping, { swp_entry_t swp; struct swap_info_struct *si; - struct folio *folio = __filemap_get_folio(mapping, index, FGP_ENTRY, 0); + struct folio *folio = filemap_get_entry(mapping, index); if (!xa_is_value(folio)) goto out; From patchwork Wed Jan 18 09:43:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13106081 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 C5C49C004D4 for ; Wed, 18 Jan 2023 10:41:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230122AbjARKlD (ORCPT ); Wed, 18 Jan 2023 05:41:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230127AbjARKj4 (ORCPT ); Wed, 18 Jan 2023 05:39:56 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D30B37F9AB; Wed, 18 Jan 2023 01:43:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=O83tPX7xDqfBHS0UmyQszE340fKZLFsVV7AVtaYRimc=; b=siItTvaO8AsDZE3ndylUPIO/O7 O8rbSLynnMNtdE+Stj5GPSclr0XcMLZj+dKghCCW91lanRkY7aH4RCo3QLiVUBRy+6YnE08rYe474 nYyWYpyVKCaiYpK2GGKX0C9Il9QGUIdNlez4FB93mChOl/ONhLOg14psRvpOcZfD0/x88ZoKZRjx4 Y9z9UDYRy4b0bASegjboX45Xi47n6T065RATsSq713wYwK/3AzncosVsQt3BXdHtlCUbg84/3QCkr obJDhpJGPXGRphz9ppkZYpG43bea+N0N/sTKMifzKhDvT4kVfxWKRrlPE5UM2N1ShnUoiRJGYZTmr eeFJ4fCQ==; Received: from 213-147-167-250.nat.highway.webapn.at ([213.147.167.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI4z2-0009zZ-Qn; Wed, 18 Jan 2023 09:43:53 +0000 From: Christoph Hellwig To: Andrew Morton , Matthew Wilcox , Hugh Dickins Cc: linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com, linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nilfs@vger.kernel.org Subject: [PATCH 4/9] shmem: remove shmem_get_partial_folio Date: Wed, 18 Jan 2023 10:43:24 +0100 Message-Id: <20230118094329.9553-5-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118094329.9553-1-hch@lst.de> References: <20230118094329.9553-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add a new SGP_FIND mode for shmem_get_partial_folio that works like SGP_READ, but does not check i_size. Use that instead of open coding the page cache lookup in shmem_get_partial_folio. Note that this is a behavior change in that it reads in swap cache entries for offsets outside i_size, possibly causing a little bit of extra work. Signed-off-by: Christoph Hellwig --- include/linux/shmem_fs.h | 1 + mm/shmem.c | 46 ++++++++++++---------------------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index d09d54be4ffd99..7ba160ac066e5e 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -105,6 +105,7 @@ enum sgp_type { SGP_CACHE, /* don't exceed i_size, may allocate page */ SGP_WRITE, /* may exceed i_size, may allocate !Uptodate page */ SGP_FALLOC, /* like SGP_WRITE, but make existing page Uptodate */ + SGP_FIND, /* like SGP_READ, but also read outside i_size */ }; int shmem_get_folio(struct inode *inode, pgoff_t index, struct folio **foliop, diff --git a/mm/shmem.c b/mm/shmem.c index 9e1015cbad29f9..e9500fea43a8dc 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -877,27 +877,6 @@ void shmem_unlock_mapping(struct address_space *mapping) } } -static struct folio *shmem_get_partial_folio(struct inode *inode, pgoff_t index) -{ - struct folio *folio; - - /* - * At first avoid shmem_get_folio(,,,SGP_READ): that fails - * beyond i_size, and reports fallocated pages as holes. - */ - folio = __filemap_get_folio(inode->i_mapping, index, - FGP_ENTRY | FGP_LOCK, 0); - if (!xa_is_value(folio)) - return folio; - /* - * But read a page back from swap if any of it is within i_size - * (although in some cases this is just a waste of time). - */ - folio = NULL; - shmem_get_folio(inode, index, &folio, SGP_READ); - return folio; -} - /* * Remove range of pages and swap entries from page cache, and free them. * If !unfalloc, truncate or punch hole; if unfalloc, undo failed fallocate. @@ -957,7 +936,8 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, goto whole_folios; same_folio = (lstart >> PAGE_SHIFT) == (lend >> PAGE_SHIFT); - folio = shmem_get_partial_folio(inode, lstart >> PAGE_SHIFT); + folio = NULL; + shmem_get_folio(inode, lstart >> PAGE_SHIFT, &folio, SGP_FIND); if (folio) { same_folio = lend < folio_pos(folio) + folio_size(folio); folio_mark_dirty(folio); @@ -971,14 +951,16 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, folio = NULL; } - if (!same_folio) - folio = shmem_get_partial_folio(inode, lend >> PAGE_SHIFT); - if (folio) { - folio_mark_dirty(folio); - if (!truncate_inode_partial_folio(folio, lstart, lend)) - end = folio->index; - folio_unlock(folio); - folio_put(folio); + if (!same_folio) { + folio = NULL; + shmem_get_folio(inode, lend >> PAGE_SHIFT, &folio, SGP_FIND); + if (folio) { + folio_mark_dirty(folio); + if (!truncate_inode_partial_folio(folio, lstart, lend)) + end = folio->index; + folio_unlock(folio); + folio_put(folio); + } } whole_folios: @@ -1900,7 +1882,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, if (folio_test_uptodate(folio)) goto out; /* fallocated folio */ - if (sgp != SGP_READ) + if (sgp != SGP_READ && sgp != SGP_FIND) goto clear; folio_unlock(folio); folio_put(folio); @@ -1911,7 +1893,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, * SGP_NOALLOC: fail on hole, with NULL folio, letting caller fail. */ *foliop = NULL; - if (sgp == SGP_READ) + if (sgp == SGP_READ || sgp == SGP_FIND) return 0; if (sgp == SGP_NOALLOC) return -ENOENT; From patchwork Wed Jan 18 09:43:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13106082 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 236FFC38147 for ; Wed, 18 Jan 2023 10:41:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbjARKlH (ORCPT ); Wed, 18 Jan 2023 05:41:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230125AbjARKj4 (ORCPT ); Wed, 18 Jan 2023 05:39:56 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D317183877; Wed, 18 Jan 2023 01:44:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=pFy30vhWl9l9ZgLMa817B3/6WEg0wrb2z/Np7E/EF8c=; b=UfEL4nxoIkflPHGo7FW/goZ6Ae xIpR/d0qI5IJrraY/1iGKXWGHdji2iuHKy5HnLQI8g45xl0egjQwt440BkyDBzLOtbS3WTE77JRoB YVbEr2AoQ50WmGx37VByiYGoCLP0d5MCV4wzb6443KaglnqflCP6aueRjRXiu9loX+HJZJVZbLoYZ 7L8+14Vq+wI6LGjevGMbFYs4iFg/sLVFkhIO9VUWEW0VoKzm/xPjwyPDaa3qLJ2urhMKmMYcXaer+ mXjsx+091criZqeGU7fbDpZee25pjlDMItJhPegKjbf5a4mRmpe2UFeAd60n54qiLHBmIq6wh9a1Q m2aDbOQw==; Received: from 213-147-167-250.nat.highway.webapn.at ([213.147.167.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI4z7-000A13-OH; Wed, 18 Jan 2023 09:43:59 +0000 From: Christoph Hellwig To: Andrew Morton , Matthew Wilcox , Hugh Dickins Cc: linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com, linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nilfs@vger.kernel.org Subject: [PATCH 5/9] shmem: open code the page cache lookup in shmem_get_folio_gfp Date: Wed, 18 Jan 2023 10:43:25 +0100 Message-Id: <20230118094329.9553-6-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118094329.9553-1-hch@lst.de> References: <20230118094329.9553-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the very low level filemap_get_entry helper to look up the entry in the xarray, and then: - don't bother locking the folio if only doing a userfault notification - open code locking the page and checking for truncation in a related code block This will allow to eventually remove the FGP_ENTRY flag. Signed-off-by: Christoph Hellwig --- mm/shmem.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index e9500fea43a8dc..769107f376562f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1856,12 +1856,10 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, sbinfo = SHMEM_SB(inode->i_sb); charge_mm = vma ? vma->vm_mm : NULL; - folio = __filemap_get_folio(mapping, index, FGP_ENTRY | FGP_LOCK, 0); + folio = filemap_get_entry(mapping, index); if (folio && vma && userfaultfd_minor(vma)) { - if (!xa_is_value(folio)) { - folio_unlock(folio); + if (!xa_is_value(folio)) folio_put(folio); - } *fault_type = handle_userfault(vmf, VM_UFFD_MINOR); return 0; } @@ -1877,6 +1875,14 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, } if (folio) { + folio_lock(folio); + + /* Has the page been truncated? */ + if (unlikely(folio->mapping != mapping)) { + folio_unlock(folio); + folio_put(folio); + goto repeat; + } if (sgp == SGP_WRITE) folio_mark_accessed(folio); if (folio_test_uptodate(folio)) From patchwork Wed Jan 18 09:43:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13106078 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 182D2C004D4 for ; Wed, 18 Jan 2023 10:40:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230305AbjARKkf (ORCPT ); Wed, 18 Jan 2023 05:40:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230160AbjARKkC (ORCPT ); Wed, 18 Jan 2023 05:40:02 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4B28C45AD; Wed, 18 Jan 2023 01:44:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=72dbPnQldghXJsWt6hBZ/ADNkiEKaZsKzxCkekJEdAU=; b=tjja759eWnm9v7J+IWUXZozttN OxM313yixMNrLZv2p6AMh7dEVQGQVttdzzpXCUjYtd/HJPHTDFptjOcJ/ztghPLG4FjwymkosilRR 71WeRyXnd9cVWvfYK3gwuP8UaCscXZDWNsVkdryui1LtBz7pHrZZlDwm9tOHPzeUWlqVpzLwqs/Nv mQ1wr0mKPRM1oh8fBHkrDd2dD+F4LxbURzWCJO9Qy9VO5kKDaaZ+uUch5hrYQMx04GTYHXBA0yLFD xDHDaJbPbxJzhcRQVGE0fXG65DXX8GVYqTbsMDsQUxetnUYXCE7Y+e2Jxxpl5o1Oq0PIR9p1np8O6 uUlibs6Q==; Received: from 213-147-167-250.nat.highway.webapn.at ([213.147.167.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI4zD-000A5d-GP; Wed, 18 Jan 2023 09:44:04 +0000 From: Christoph Hellwig To: Andrew Morton , Matthew Wilcox , Hugh Dickins Cc: linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com, linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nilfs@vger.kernel.org Subject: [PATCH 6/9] mm: remove FGP_ENTRY Date: Wed, 18 Jan 2023 10:43:26 +0100 Message-Id: <20230118094329.9553-7-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118094329.9553-1-hch@lst.de> References: <20230118094329.9553-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org FGP_ENTRY is unused now, so remove it. Signed-off-by: Christoph Hellwig --- include/linux/pagemap.h | 3 +-- mm/filemap.c | 7 +------ mm/folio-compat.c | 4 ++-- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 24dedf6b12be49..e2208ee36966ea 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -504,8 +504,7 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping, #define FGP_NOFS 0x00000010 #define FGP_NOWAIT 0x00000020 #define FGP_FOR_MMAP 0x00000040 -#define FGP_ENTRY 0x00000080 -#define FGP_STABLE 0x00000100 +#define FGP_STABLE 0x00000080 void *filemap_get_entry(struct address_space *mapping, pgoff_t index); struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, diff --git a/mm/filemap.c b/mm/filemap.c index ed0583f9e27512..35baadd130795c 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1889,8 +1889,6 @@ void *filemap_get_entry(struct address_space *mapping, pgoff_t index) * * * %FGP_ACCESSED - The folio will be marked accessed. * * %FGP_LOCK - The folio is returned locked. - * * %FGP_ENTRY - If there is a shadow / swap / DAX entry, return it - * instead of allocating a new folio to replace it. * * %FGP_CREAT - If no page is present then a new page is allocated using * @gfp and added to the page cache and the VM's LRU list. * The page is returned locked and with an increased refcount. @@ -1916,11 +1914,8 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, repeat: folio = filemap_get_entry(mapping, index); - if (xa_is_value(folio)) { - if (fgp_flags & FGP_ENTRY) - return folio; + if (xa_is_value(folio)) folio = NULL; - } if (!folio) goto no_page; diff --git a/mm/folio-compat.c b/mm/folio-compat.c index 18c48b55792635..f3841b4977b68e 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -97,8 +97,8 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index, struct folio *folio; folio = __filemap_get_folio(mapping, index, fgp_flags, gfp); - if (!folio || xa_is_value(folio)) - return &folio->page; + if (!folio) + return NULL; return folio_file_page(folio, index); } EXPORT_SYMBOL(pagecache_get_page); From patchwork Wed Jan 18 09:43:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13106077 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 E873CC46467 for ; Wed, 18 Jan 2023 10:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230222AbjARKke (ORCPT ); Wed, 18 Jan 2023 05:40:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230214AbjARKkJ (ORCPT ); Wed, 18 Jan 2023 05:40:09 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C460C4E87; Wed, 18 Jan 2023 01:44:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=4WwjtPTvg3dbfLBE9vX5iRJAtphGCEZEkdJLVGyAJuo=; b=U8yFVdeBOBI3AACbEFkiQ4355D kLv+LRYHlKEtA4P6BWETKJS4fAVkK8iUpRlBVj9bR3Z5JxNdzQrN7aBF2SXwp2ePM5gNif1cFI7cL DyUfxGZQ28zOPddZXEXlOfBeZcxkQhHcv1emVkZOzOmdX02aeXOEB1DkUHEQ2/7g4XZ+Fmx9l3UHI YMGHla2dEMTRRR/zKlZBZvvUFGurgIdckmw7tTsDDGQdh7vK99tqsGnmvLAIuksqS+qEGzkmWqgtR +53as9e9nNgosns1KccGTJVaRfjXJygIT64MdzQBaIAoGVFyt2ILegAxzv+cBLG4sjOlhTtqe7jpE HXxflEVw==; Received: from 213-147-167-250.nat.highway.webapn.at ([213.147.167.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI4zI-000A8d-6U; Wed, 18 Jan 2023 09:44:09 +0000 From: Christoph Hellwig To: Andrew Morton , Matthew Wilcox , Hugh Dickins Cc: linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com, linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nilfs@vger.kernel.org Subject: [PATCH 7/9] gfs2: handle a NULL folio in gfs2_jhead_process_page Date: Wed, 18 Jan 2023 10:43:27 +0100 Message-Id: <20230118094329.9553-8-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118094329.9553-1-hch@lst.de> References: <20230118094329.9553-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org filemap_get_folio can return NULL, so exit early for that case. Signed-off-by: Christoph Hellwig --- fs/gfs2/lops.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 1902413d5d123e..51d4b610127cdb 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -472,6 +472,8 @@ static void gfs2_jhead_process_page(struct gfs2_jdesc *jd, unsigned long index, struct folio *folio; folio = filemap_get_folio(jd->jd_inode->i_mapping, index); + if (!folio) + return; folio_wait_locked(folio); if (folio_test_error(folio)) From patchwork Wed Jan 18 09:43:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13106079 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 52B0FC004D4 for ; Wed, 18 Jan 2023 10:40:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229883AbjARKkt (ORCPT ); Wed, 18 Jan 2023 05:40:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229849AbjARKkQ (ORCPT ); Wed, 18 Jan 2023 05:40:16 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81EC1C4EB8; Wed, 18 Jan 2023 01:44:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=ewY31mbHxOfBtCPdgdKzYjQ0wPkqac5AmSjDkb40tFw=; b=mSCDCWinUY/HS19oiHLIYU7HTJ xzmM8Qtfxh3HIuymTISooTmX6MPgoflOa0QEqARdl58+fsr8DnAM2OmWVtGDhwxK56ZTcXRoTQBYc N7fS0PP9RlpPUqBe8Z+JfSMNivMFeCH8O7mEix/D9DJC2FhilwruTYNIfFp2CAtuxiaCqX8cB8ypc i6fXmBJvEW6wRvYpqVZjOFWDrJdIQ7/z/dJm65mWiD83UIjIo8LqP0ZpBFAIe1yPaI115hKSn+ooa r/wDnRGHqtfS0o2zlJoQ8uewHgGSm9sJ9WvQUpk1dqyVo0wKkPBdMHEn+BtUTrCt3neypSrdkLX+J OaMKoOxQ==; Received: from 213-147-167-250.nat.highway.webapn.at ([213.147.167.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI4zN-000ABI-Gv; Wed, 18 Jan 2023 09:44:14 +0000 From: Christoph Hellwig To: Andrew Morton , Matthew Wilcox , Hugh Dickins Cc: linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com, linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nilfs@vger.kernel.org Subject: [PATCH 8/9] btrfs: handle a NULL folio in extent_range_redirty_for_io Date: Wed, 18 Jan 2023 10:43:28 +0100 Message-Id: <20230118094329.9553-9-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118094329.9553-1-hch@lst.de> References: <20230118094329.9553-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org filemap_get_folio can return NULL, skip those cases. Signed-off-by: Christoph Hellwig --- fs/btrfs/extent_io.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index d55e4531ffd212..a54d2cf74ba020 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -230,6 +230,8 @@ void extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end) while (index <= end_index) { folio = filemap_get_folio(mapping, index); + if (!folio) + continue; filemap_dirty_folio(mapping, folio); folio_account_redirty(folio); index += folio_nr_pages(folio); From patchwork Wed Jan 18 09:43:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13106080 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 42A27C004D4 for ; Wed, 18 Jan 2023 10:41:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229685AbjARKlA (ORCPT ); Wed, 18 Jan 2023 05:41:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbjARKkL (ORCPT ); Wed, 18 Jan 2023 05:40:11 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75644C4EAA; Wed, 18 Jan 2023 01:44:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=J1bJRn8dMRq79u1+uHawGew6oUOcQ5MnfgpdoCFCIVE=; b=TQTt/SAbg4Elgy7FQ74N+cMV0y 8A+E+kNYML31DWmWs4Vll09VogMb8nddkG06zsPFdV8usGFtyocAqnXN57cmrApq8eZZjnL4n+ifZ WTSXrwV4tlafd1chRE92COzvQG7fg1aSkHlPqml0E6wNASis14pGRrZ4ApGcYImCTW6fX1CTWzUv2 bu3Rale/X80o1JAwkRlkaLUYwMlLzC4QSa5D1tLsDmBgZbAfJpqFOeq/9AzBGbfOUTNRSkmZdrP4t O3Z3gS4V0zEibcUY0AsGOZXdCIYf7ruz2tu+uNRuzijI7EEK8vCpT2jpVCQcGCF3fi9K3tobLD2K6 xqM08S8g==; Received: from 213-147-167-250.nat.highway.webapn.at ([213.147.167.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI4zR-000AD8-W6; Wed, 18 Jan 2023 09:44:18 +0000 From: Christoph Hellwig To: Andrew Morton , Matthew Wilcox , Hugh Dickins Cc: linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com, linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nilfs@vger.kernel.org Subject: [PATCH 9/9] mm: return an ERR_PTR from __filemap_get_folio Date: Wed, 18 Jan 2023 10:43:29 +0100 Message-Id: <20230118094329.9553-10-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118094329.9553-1-hch@lst.de> References: <20230118094329.9553-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Instead of returning NULL for all errors, distinguish between: - no entry found and not asked to allocated (-ENOENT) - failed to allocate memory (-ENOMEM) - would block (-EAGAIN) so that callers don't have to guess the error based on the passed in flags. Also pass through the error through the direct callers: filemap_get_folio, filemap_lock_folio filemap_grab_folio and filemap_get_incore_folio. Signed-off-by: Christoph Hellwig --- fs/afs/dir.c | 10 +++++----- fs/afs/dir_edit.c | 2 +- fs/afs/write.c | 4 ++-- fs/btrfs/disk-io.c | 2 +- fs/btrfs/extent_io.c | 2 +- fs/ext4/inode.c | 2 +- fs/ext4/move_extent.c | 8 ++++---- fs/gfs2/lops.c | 2 +- fs/hugetlbfs/inode.c | 2 +- fs/iomap/buffered-io.c | 6 +++--- fs/netfs/buffered_read.c | 4 ++-- fs/nilfs2/page.c | 6 +++--- mm/filemap.c | 14 ++++++++------ mm/folio-compat.c | 2 +- mm/huge_memory.c | 2 +- mm/memcontrol.c | 2 +- mm/mincore.c | 2 +- mm/shmem.c | 4 ++-- mm/swap_state.c | 15 ++++++++------- mm/swapfile.c | 4 ++-- mm/truncate.c | 15 ++++++++------- 21 files changed, 57 insertions(+), 53 deletions(-) diff --git a/fs/afs/dir.c b/fs/afs/dir.c index b7c1f8c84b38aa..41d0b4203870be 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c @@ -319,16 +319,16 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key) struct folio *folio; folio = filemap_get_folio(mapping, i); - if (!folio) { + if (IS_ERR(folio)) { if (test_and_clear_bit(AFS_VNODE_DIR_VALID, &dvnode->flags)) afs_stat_v(dvnode, n_inval); - - ret = -ENOMEM; folio = __filemap_get_folio(mapping, i, FGP_LOCK | FGP_CREAT, mapping->gfp_mask); - if (!folio) + if (IS_ERR(folio)) { + ret = PTR_ERR(folio); goto error; + } folio_attach_private(folio, (void *)1); folio_unlock(folio); } @@ -524,7 +524,7 @@ static int afs_dir_iterate(struct inode *dir, struct dir_context *ctx, */ folio = __filemap_get_folio(dir->i_mapping, ctx->pos / PAGE_SIZE, FGP_ACCESSED, 0); - if (!folio) { + if (IS_ERR(folio)) { ret = afs_bad(dvnode, afs_file_error_dir_missing_page); break; } diff --git a/fs/afs/dir_edit.c b/fs/afs/dir_edit.c index 0ab7752d1b758e..f0eddccbdd9541 100644 --- a/fs/afs/dir_edit.c +++ b/fs/afs/dir_edit.c @@ -115,7 +115,7 @@ static struct folio *afs_dir_get_folio(struct afs_vnode *vnode, pgoff_t index) folio = __filemap_get_folio(mapping, index, FGP_LOCK | FGP_ACCESSED | FGP_CREAT, mapping->gfp_mask); - if (!folio) + if (IS_ERR(folio)) clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags); else if (folio && !folio_test_private(folio)) folio_attach_private(folio, (void *)1); diff --git a/fs/afs/write.c b/fs/afs/write.c index 2d3b08b7406ca7..cf1eb0d122c275 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -232,7 +232,7 @@ static void afs_kill_pages(struct address_space *mapping, _debug("kill %lx (to %lx)", index, last); folio = filemap_get_folio(mapping, index); - if (!folio) { + if (IS_ERR(folio)) { next = index + 1; continue; } @@ -270,7 +270,7 @@ static void afs_redirty_pages(struct writeback_control *wbc, _debug("redirty %llx @%llx", len, start); folio = filemap_get_folio(mapping, index); - if (!folio) { + if (IS_ERR(folio)) { next = index + 1; continue; } diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 7d5da43a89ee7f..f1035e0bcf8c6a 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4034,7 +4034,7 @@ static int wait_dev_supers(struct btrfs_device *device, int max_mirrors) folio = filemap_get_folio(device->bdev->bd_inode->i_mapping, bytenr >> PAGE_SHIFT); - if (!folio) { + if (IS_ERR(folio)) { errors++; if (i == 0) primary_failed = true; diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index a54d2cf74ba020..faaab9fae66d66 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -230,7 +230,7 @@ void extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end) while (index <= end_index) { folio = filemap_get_folio(mapping, index); - if (!folio) + if (IS_ERR(folio)) continue; filemap_dirty_folio(mapping, folio); folio_account_redirty(folio); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index fb6cd994e59afa..ee8f82c7acf9ff 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5391,7 +5391,7 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode) while (1) { struct folio *folio = filemap_lock_folio(inode->i_mapping, inode->i_size >> PAGE_SHIFT); - if (!folio) + if (IS_ERR(folio)) return; ret = __ext4_journalled_invalidate_folio(folio, offset, folio_size(folio) - offset); diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 2de9829aed63bf..7bf6d069199cbb 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -141,18 +141,18 @@ mext_folio_double_lock(struct inode *inode1, struct inode *inode2, flags = memalloc_nofs_save(); folio[0] = __filemap_get_folio(mapping[0], index1, fgp_flags, mapping_gfp_mask(mapping[0])); - if (!folio[0]) { + if (IS_ERR(folio[0])) { memalloc_nofs_restore(flags); - return -ENOMEM; + return PTR_ERR(folio[0]); } folio[1] = __filemap_get_folio(mapping[1], index2, fgp_flags, mapping_gfp_mask(mapping[1])); memalloc_nofs_restore(flags); - if (!folio[1]) { + if (IS_ERR(folio[1])) { folio_unlock(folio[0]); folio_put(folio[0]); - return -ENOMEM; + return PTR_ERR(folio[1]); } /* * __filemap_get_folio() may not wait on folio's writeback if diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 51d4b610127cdb..9e8a00cee8afc1 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -472,7 +472,7 @@ static void gfs2_jhead_process_page(struct gfs2_jdesc *jd, unsigned long index, struct folio *folio; folio = filemap_get_folio(jd->jd_inode->i_mapping, index); - if (!folio) + if (IS_ERR(folio)) return; folio_wait_locked(folio); diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 48f1a8ad22431e..19dac1fbcd3705 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -697,7 +697,7 @@ static void hugetlbfs_zero_partial_page(struct hstate *h, struct folio *folio; folio = filemap_lock_folio(mapping, idx); - if (!folio) + if (IS_ERR(folio)) return; start = start & ~huge_page_mask(h); diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 356193e44cf07f..ab5a5a5a3e0283 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -614,8 +614,8 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, folio = __filemap_get_folio(iter->inode->i_mapping, pos >> PAGE_SHIFT, fgp, mapping_gfp_mask(iter->inode->i_mapping)); - if (!folio) { - status = (iter->flags & IOMAP_NOWAIT) ? -EAGAIN : -ENOMEM; + if (IS_ERR(folio)) { + status = PTR_ERR(folio); goto out_no_page; } @@ -882,7 +882,7 @@ static int iomap_write_delalloc_scan(struct inode *inode, /* grab locked page */ folio = filemap_lock_folio(inode->i_mapping, start_byte >> PAGE_SHIFT); - if (!folio) { + if (IS_ERR(folio)) { start_byte = ALIGN_DOWN(start_byte, PAGE_SIZE) + PAGE_SIZE; continue; diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c index 7679a68e819307..209726a9cfdb9c 100644 --- a/fs/netfs/buffered_read.c +++ b/fs/netfs/buffered_read.c @@ -350,8 +350,8 @@ int netfs_write_begin(struct netfs_inode *ctx, retry: folio = __filemap_get_folio(mapping, index, fgp_flags, mapping_gfp_mask(mapping)); - if (!folio) - return -ENOMEM; + if (IS_ERR(folio)) + return PTR_ERR(folio); if (ctx->ops->check_write_begin) { /* Allow the netfs (eg. ceph) to flush conflicts. */ diff --git a/fs/nilfs2/page.c b/fs/nilfs2/page.c index 41ccd43cd9797f..5cf30827f244c4 100644 --- a/fs/nilfs2/page.c +++ b/fs/nilfs2/page.c @@ -259,10 +259,10 @@ int nilfs_copy_dirty_pages(struct address_space *dmap, NILFS_PAGE_BUG(&folio->page, "inconsistent dirty state"); dfolio = filemap_grab_folio(dmap, folio->index); - if (unlikely(!dfolio)) { + if (unlikely(IS_ERR(dfolio))) { /* No empty page is added to the page cache */ - err = -ENOMEM; folio_unlock(folio); + err = PTR_ERR(dfolio); break; } if (unlikely(!folio_buffers(folio))) @@ -311,7 +311,7 @@ void nilfs_copy_back_pages(struct address_space *dmap, folio_lock(folio); dfolio = filemap_lock_folio(dmap, index); - if (dfolio) { + if (!IS_ERR(dfolio)) { /* overwrite existing folio in the destination cache */ WARN_ON(folio_test_dirty(dfolio)); nilfs_copy_page(&dfolio->page, &folio->page, 0); diff --git a/mm/filemap.c b/mm/filemap.c index 35baadd130795c..4037a132f7adcc 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1905,7 +1905,7 @@ void *filemap_get_entry(struct address_space *mapping, pgoff_t index) * * If there is a page cache page, it is returned with an increased refcount. * - * Return: The found folio or %NULL otherwise. + * Return: The found folio or an ERR_PTR() otherwise. */ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, int fgp_flags, gfp_t gfp) @@ -1923,7 +1923,7 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, if (fgp_flags & FGP_NOWAIT) { if (!folio_trylock(folio)) { folio_put(folio); - return NULL; + return ERR_PTR(-EAGAIN); } } else { folio_lock(folio); @@ -1962,7 +1962,7 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, folio = filemap_alloc_folio(gfp, 0); if (!folio) - return NULL; + return ERR_PTR(-ENOMEM); if (WARN_ON_ONCE(!(fgp_flags & (FGP_LOCK | FGP_FOR_MMAP)))) fgp_flags |= FGP_LOCK; @@ -1987,6 +1987,8 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, folio_unlock(folio); } + if (!folio) + return ERR_PTR(-ENOENT); return folio; } EXPORT_SYMBOL(__filemap_get_folio); @@ -3126,7 +3128,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) * Do we have something in the page cache already? */ folio = filemap_get_folio(mapping, index); - if (likely(folio)) { + if (likely(!IS_ERR(folio))) { /* * We found the page, so try async readahead before waiting for * the lock. @@ -3155,7 +3157,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) folio = __filemap_get_folio(mapping, index, FGP_CREAT|FGP_FOR_MMAP, vmf->gfp_mask); - if (!folio) { + if (IS_ERR(folio)) { if (fpin) goto out_retry; filemap_invalidate_unlock_shared(mapping); @@ -3506,7 +3508,7 @@ static struct folio *do_read_cache_folio(struct address_space *mapping, filler = mapping->a_ops->read_folio; repeat: folio = filemap_get_folio(mapping, index); - if (!folio) { + if (IS_ERR(folio)) { folio = filemap_alloc_folio(gfp, 0); if (!folio) return ERR_PTR(-ENOMEM); diff --git a/mm/folio-compat.c b/mm/folio-compat.c index f3841b4977b68e..4cd173336d8589 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -97,7 +97,7 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index, struct folio *folio; folio = __filemap_get_folio(mapping, index, fgp_flags, gfp); - if (!folio) + if (IS_ERR(folio)) return NULL; return folio_file_page(folio, index); } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index a2830019aaa017..b0c9170632e37c 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3103,7 +3103,7 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, struct folio *folio = filemap_get_folio(mapping, index); nr_pages = 1; - if (!folio) + if (IS_ERR(folio)) continue; if (!folio_test_large(folio)) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 893427aded0191..8bcea91099d218 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5693,7 +5693,7 @@ static struct page *mc_handle_file_pte(struct vm_area_struct *vma, /* shmem/tmpfs may report page out on swap: account for that too. */ index = linear_page_index(vma, addr); folio = filemap_get_incore_folio(vma->vm_file->f_mapping, index); - if (!folio) + if (IS_ERR(folio)) return NULL; return folio_file_page(folio, index); } diff --git a/mm/mincore.c b/mm/mincore.c index a085a2aeabd8e6..386c1aed1a8aef 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -61,7 +61,7 @@ static unsigned char mincore_page(struct address_space *mapping, pgoff_t index) * tmpfs's .fault). So swapped out tmpfs mappings are tested here. */ folio = filemap_get_incore_folio(mapping, index); - if (folio) { + if (!IS_ERR(folio)) { present = folio_test_uptodate(folio); folio_put(folio); } diff --git a/mm/shmem.c b/mm/shmem.c index 769107f376562f..676318f95f7b40 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -603,7 +603,7 @@ static unsigned long shmem_unused_huge_shrink(struct shmem_sb_info *sbinfo, index = (inode->i_size & HPAGE_PMD_MASK) >> PAGE_SHIFT; folio = filemap_get_folio(inode->i_mapping, index); - if (!folio) + if (IS_ERR(folio)) goto drop; /* No huge page at the end of the file: nothing to split */ @@ -3187,7 +3187,7 @@ static const char *shmem_get_link(struct dentry *dentry, if (!dentry) { folio = filemap_get_folio(inode->i_mapping, 0); - if (!folio) + if (IS_ERR(folio)) return ERR_PTR(-ECHILD); if (PageHWPoison(folio_page(folio, 0)) || !folio_test_uptodate(folio)) { diff --git a/mm/swap_state.c b/mm/swap_state.c index c39ea34bc4fc10..e853d3eecf55bb 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -330,7 +330,7 @@ struct folio *swap_cache_get_folio(swp_entry_t entry, struct folio *folio; folio = filemap_get_folio(swap_address_space(entry), swp_offset(entry)); - if (folio) { + if (!IS_ERR(folio)) { bool vma_ra = swap_use_vma_readahead(); bool readahead; @@ -360,6 +360,8 @@ struct folio *swap_cache_get_folio(swp_entry_t entry, if (!vma || !vma_ra) atomic_inc(&swapin_readahead_hits); } + } else { + folio = NULL; } return folio; @@ -383,22 +385,21 @@ struct folio *filemap_get_incore_folio(struct address_space *mapping, struct folio *folio = filemap_get_entry(mapping, index); if (!xa_is_value(folio)) - goto out; + return folio; if (!shmem_mapping(mapping)) - return NULL; + return ERR_PTR(-ENOENT); swp = radix_to_swp_entry(folio); /* There might be swapin error entries in shmem mapping. */ if (non_swap_entry(swp)) - return NULL; + return ERR_PTR(-ENOENT); /* Prevent swapoff from happening to us */ si = get_swap_device(swp); if (!si) - return NULL; + return ERR_PTR(-ENOENT); index = swp_offset(swp); folio = filemap_get_folio(swap_address_space(swp), index); put_swap_device(si); -out: return folio; } @@ -425,7 +426,7 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, folio = filemap_get_folio(swap_address_space(entry), swp_offset(entry)); put_swap_device(si); - if (folio) + if (!IS_ERR(folio)) return folio_file_page(folio, swp_offset(entry)); /* diff --git a/mm/swapfile.c b/mm/swapfile.c index a5729273480e07..a128b61b6b8c91 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -136,7 +136,7 @@ static int __try_to_reclaim_swap(struct swap_info_struct *si, int ret = 0; folio = filemap_get_folio(swap_address_space(entry), offset); - if (!folio) + if (IS_ERR(folio)) return 0; /* * When this function is called from scan_swap_map_slots() and it's @@ -2096,7 +2096,7 @@ static int try_to_unuse(unsigned int type) entry = swp_entry(type, i); folio = filemap_get_folio(swap_address_space(entry), i); - if (!folio) + if (IS_ERR(folio)) continue; /* diff --git a/mm/truncate.c b/mm/truncate.c index 7b4ea4c4a46b20..86de31ed4d3238 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -375,7 +375,7 @@ void truncate_inode_pages_range(struct address_space *mapping, same_folio = (lstart >> PAGE_SHIFT) == (lend >> PAGE_SHIFT); folio = __filemap_get_folio(mapping, lstart >> PAGE_SHIFT, FGP_LOCK, 0); - if (folio) { + if (!IS_ERR(folio)) { same_folio = lend < folio_pos(folio) + folio_size(folio); if (!truncate_inode_partial_folio(folio, lstart, lend)) { start = folio->index + folio_nr_pages(folio); @@ -387,14 +387,15 @@ void truncate_inode_pages_range(struct address_space *mapping, folio = NULL; } - if (!same_folio) + if (!same_folio) { folio = __filemap_get_folio(mapping, lend >> PAGE_SHIFT, FGP_LOCK, 0); - if (folio) { - if (!truncate_inode_partial_folio(folio, lstart, lend)) - end = folio->index; - folio_unlock(folio); - folio_put(folio); + if (!IS_ERR(folio)) { + if (!truncate_inode_partial_folio(folio, lstart, lend)) + end = folio->index; + folio_unlock(folio); + folio_put(folio); + } } index = start;