From patchwork Sat Jan 21 06:57:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13110983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 557B3C38159 for ; Sat, 21 Jan 2023 06:58:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47D656B0074; Sat, 21 Jan 2023 01:58:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FD286B0073; Sat, 21 Jan 2023 01:58:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C5066B0074; Sat, 21 Jan 2023 01:58:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1DBA56B0072 for ; Sat, 21 Jan 2023 01:58:11 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D9EBA40F94 for ; Sat, 21 Jan 2023 06:58:10 +0000 (UTC) X-FDA: 80377901940.09.EC44CA0 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf15.hostedemail.com (Postfix) with ESMTP id BA1D2A0011 for ; Sat, 21 Jan 2023 06:58:06 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=SDkUBU1W; spf=none (imf15.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674284287; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=B8D0bWeotdFdx7oIYHTSXz6cye3hjLZS5m2/hvamHXo=; b=FqXGg3D58b6wo5u+6UnDUlH1BT+cYUe6YjzJzQlNCvYjA/sj0x3XbuQgeUHcz9KvcwupLX JXm63e20ITeWedWUdEsP0tOqMRrd3K0gHgtsgRug+cH+Bu2Cl/yuLxMbx4UZ0sjREt9JtQ T1zP0GW47XcG5VUvBNQj9wW1lBy5tBU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=SDkUBU1W; spf=none (imf15.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674284287; a=rsa-sha256; cv=none; b=LUotAB6yZ3jIxuPgW6wHGhFzkugRtle7k9Ru9cw2pVAKImPI1GunOFblZu0W/DBCTS32Rd ZC8yIoTzVxepBEFQ3Hio+Y8vV+a487ZmpbFbayHj1GWCwkOrHaIssnYMUGo/RhkQWjXgNj /BpstEnJ3y+x+evOOJPBgbx/Ez9pDmw= 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=B8D0bWeotdFdx7oIYHTSXz6cye3hjLZS5m2/hvamHXo=; b=SDkUBU1WsXxnF7FBjrDRJ4xZZ8 TP3/Mu5FLI87eWKaj4CbwLn/sCwMzyOAC/rrj97FZ/LQomNPWkqgUgmWd/7kDho1tK5yhdhyfsyRQ bIT6z4zRDSoyIta29wHgJFACKI7JJfa2HvSBLOuGiYOCdn0yoQrEQ/qMjGro/wX78HdLrvaIa+sn4 1340LweDytR9Qfhq4madCwpHeJ2oRGbLCDV5eEv/JIHKlFKiqC1gpvhXYQ6PrfYFg4gBpcUMsT9Tr UJLgfO+msrUhr9nmvs+j0mVysX5SCFr897BNqOhJ+cYqiRwv4bOlm3DNEF20F9fUO/dtZoZFLisPN TxKzpxzA==; Received: from [2001:4bb8:19a:2039:6754:cc81:9ace:36fc] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJ7pA-00DSMD-AR; Sat, 21 Jan 2023 06:58:00 +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/7] mm: don't look at xarray value entries in split_huge_pages_in_file Date: Sat, 21 Jan 2023 07:57:49 +0100 Message-Id: <20230121065755.1140136-2-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121065755.1140136-1-hch@lst.de> References: <20230121065755.1140136-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 X-Rspamd-Queue-Id: BA1D2A0011 X-Stat-Signature: xwhbfc4qgghd3y4uzjtinuhjcxoi1jsf X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1674284286-312994 X-HE-Meta: U2FsdGVkX1/pkocdquIbsPzKUQPT9fzi9KFZzjancBPTIOIonbHoxNyYbTy5V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gted8Yz1Th1UCH7tra8U/pVeCR0TtM6Kkfb9sNFGfgnv3o4zHf5pva0kz5KKF6CiBpo+TUiwywTBes5NgXO5aVfF0dZASZ7aKAyYCwI87gx3ZqZYgGKf7VhuIDz+GAd6ZNqgdVsurIrDt4kG4SfBdwFY/88wZ062rIsbv8qM76gD8ehWjO9asRO9bPpvPXPC0gq7EyE3C23UC2HrhfAK42B4tW3BGo16DI+YpsMNrIfYQdKrjasknjo+0lxoq1oVoNA47T9V0HI7M7kZt/x+MAJr5P2rFg/4KV8oqUVKVDUZ6IQuHeu4Aq6ww4K5MbY19HUg1uLTTyXklB3ALO/8LaaO6NT1ZUe/BeO4Xp5DZBwZc8dn7LioWBlLEqAn72DD6NDi36bEv2UJ4 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Sat Jan 21 06:57:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13110984 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A6D6C38A23 for ; Sat, 21 Jan 2023 06:58:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81E066B0072; Sat, 21 Jan 2023 01:58:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CD966B0075; Sat, 21 Jan 2023 01:58:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 674E96B0073; Sat, 21 Jan 2023 01:58:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4728C6B0072 for ; Sat, 21 Jan 2023 01:58:11 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 156681A0F70 for ; Sat, 21 Jan 2023 06:58:11 +0000 (UTC) X-FDA: 80377901982.06.F6FD63E Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf10.hostedemail.com (Postfix) with ESMTP id 53852C0002 for ; Sat, 21 Jan 2023 06:58:09 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="o85/NWmc"; spf=none (imf10.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674284289; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bHu6JRelc+qZi6VORfZamvMyu/HPfdmrjb1TOTy3Elw=; b=OufWn8ssRwfTv94N3WzhqQC4EiBB4/fKfWkiompi1rPXDLBtsoVOHswfXk4ExQo+MoyzbF R8k4HhFlQe9BYhq5ekZPS/If15tz3GOybf1NLX/4KlOQviYXavQN/L13Y5a4Piinmhla6E P/E/K1ijDfm8i+NGHJ8NVdW/tgvtCrs= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="o85/NWmc"; spf=none (imf10.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674284289; a=rsa-sha256; cv=none; b=AgF2EfMW/t8LWjVbhDVOmS+WQKGDYY1e1ADmH2cIb54ufzGG651erZrxN1pg2re7BCMEQF JMBzmB+Vycw/PNQ2xDkR+/OncSlZDjqIcsFFEMfvUeAn17R4APUadhvLUiuEhZsUSlHFbM 17Gfh/h+Nl2wkzZUHYwIYU3JrrpRXuE= 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=bHu6JRelc+qZi6VORfZamvMyu/HPfdmrjb1TOTy3Elw=; b=o85/NWmcxDB/Xm7nZyJ0u/OaV4 ggW//BSlYDr37PRhsjTqUedxbeyHbfv86D0FnsnWS/acgHDwbC7vRGBjt++MRUgQ/3pbPOeeMsEB+ yjRRjbsrkonl6kRfgvlX4vfhstx9bcDnXebOYT7/I0dFKcfOFG+xhP8bJ1sS4rofk1BV3nKNKtCGc HP9YgxyOp5ORr9AQtDyrxpJvPs+obr8M5TM+rXPqQkOu3400e818tBxrWdFkj8ktdzJIM00uyH77B JKhwoaJWyaUV/XVYcRHjxVXq35tjpdi8v6cqJRfKVL3Oajn10ei14YSeO22Z6+5oB5hPcuEztJVSc Ss7hYuVg==; Received: from [2001:4bb8:19a:2039:6754:cc81:9ace:36fc] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJ7pC-00DSMf-Vk; Sat, 21 Jan 2023 06:58:03 +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/7] mm: make mapping_get_entry available outside of filemap.c Date: Sat, 21 Jan 2023 07:57:50 +0100 Message-Id: <20230121065755.1140136-3-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121065755.1140136-1-hch@lst.de> References: <20230121065755.1140136-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 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 53852C0002 X-Rspam-User: X-Stat-Signature: do9jf4f4ot3yzwpsmxs9t3aigk41ftzr X-HE-Tag: 1674284289-185983 X-HE-Meta: U2FsdGVkX18p/UlKC9B+sF55l9l/KJ3DGR+5vbMiGinyUyUE5i4pKjSXxQHqgKJcDdJx97lCBO2tdlDUjEKekZQtsvwilYEwS9OJge4Mq/D2vKkiigr48fx0HSkVFNjq2adZboLSYn7d2WoeyEeCmOpQqtKkJ7MCAmkwDtli8Hp5LfW3KlAZye+oZtNCNR6gaacDbe5bZoV/2UZujh1lbsfi04SdEKp7uc5I9k+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xmoL/Wczl9xC0HRLDutnwMK/ZsQn5vzZzz8YUdHDpXoE4j1oQ/Fr+wI2b1FbD3I0BEY+N5ZoACU0ZcKfzdl205OsmKU+3CIRDgFHeN/2acQeg+2RFKK/Oc0cNwcZHsWsRanTWvYob54v+ZDZKsUAGSSZ1K04X2Tr4LB7F+Co7E8FAJbFU4nKV48qBrN76R0XAWAd3+V9aFwc0rCQTaW6Xt2iticstYs X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Sat Jan 21 06:57:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13110985 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81A65C004D4 for ; Sat, 21 Jan 2023 06:58:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FB876B0075; Sat, 21 Jan 2023 01:58:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A75D6B0078; Sat, 21 Jan 2023 01:58:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6964D6B007B; Sat, 21 Jan 2023 01:58:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 54A3A6B0075 for ; Sat, 21 Jan 2023 01:58:14 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7B62E1C6798 for ; Sat, 21 Jan 2023 06:58:13 +0000 (UTC) X-FDA: 80377902066.29.FF4B63D Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf29.hostedemail.com (Postfix) with ESMTP id D095812000A for ; Sat, 21 Jan 2023 06:58:11 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=EFQReJCG; spf=none (imf29.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674284291; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=g004efh7mFIQFWAsl+3c2q8E/FcH/R7MUAbwiN542N0=; b=1s+b//6DGl0+03nG/w/U+zrwgpR9Pp9eZ6XL8kC/yJk5RJXpvSgeQtwCJO0L0shcnzbTuK zWG2yF8Rx0UwClKtMFU+K5Kavj8VY2M3SucLpDwY00j6aIVDip9504OEJQDGf/MgIC4W4A a0GPxVfOKO1uEGPFPe2030hwRQA7Wv8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=EFQReJCG; spf=none (imf29.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674284291; a=rsa-sha256; cv=none; b=DgkBi8UH1vfRX9PNyxwIZ55pHZtX3zYLhqoalEtdcCq95F1eHp/r+8cAgm+WjNX1DHrzGI Gx9N8J7ncPeUUODlGtM4N7Z4AzU1u3LfihIxazYQajmRxgW+qFo439UXfcLlvQg7zM63Bw lExCjnEUH+9aYandy90iDJIzupVcgaY= 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=g004efh7mFIQFWAsl+3c2q8E/FcH/R7MUAbwiN542N0=; b=EFQReJCGAHigmumIVdPSAnGEMd 0BEyWnOTe6MMfLiZZZWSDU+kxTtOtBdnWxlmMO4ZVIhfVXKjivQaQoR24A6MscZ8gbOXsIN1QbDFY YQiGUX4r74o04uv+ms2CIVnYZd/hAbX2FbOT9TN0Sq045YI7N30YhMyQz/kHHKPeZ5O0O5DABSOTj o815QuZz+UAg2PTh9fDIUapX3xSlFSHFfpu2Y+3GS5lPoUXtvTXVIOWGw3Y0HjO4mgvlsIMl6Bv1E sQkL6QPK80o820hufzXGWywa5Xslcbu0/FrdUhfoLA4GaPF9TiVQhE7w6/kHBSsT8UG4o36gVQpWT HBvPxLxA==; Received: from [2001:4bb8:19a:2039:6754:cc81:9ace:36fc] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJ7pF-00DSNS-Go; Sat, 21 Jan 2023 06:58:06 +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/7] mm: use filemap_get_entry in filemap_get_incore_folio Date: Sat, 21 Jan 2023 07:57:51 +0100 Message-Id: <20230121065755.1140136-4-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121065755.1140136-1-hch@lst.de> References: <20230121065755.1140136-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 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D095812000A X-Rspam-User: X-Stat-Signature: rr3gzqwpid4rz1rpir1yct7qgu74fabb X-HE-Tag: 1674284291-502038 X-HE-Meta: U2FsdGVkX18q81XsK7fMsg681K9LmLWJxlEbbdn93WM0HibNWmYDrOEY3rBb/Lg3JYLWBSJMeFXsuAs56ZRzuqRs4KixxR6+XxdFqbgEQI99XrBfBJgs8q+y1VphEiO6eiPE8HNqBBQSyMhneLcX4px3vdMbl+PnsgjPESQIRN0fqpG4XXThPlxrrU5N/B/5uCHAebG8Ewj5I3cP0jLVYFjWr3Rf+VXRcSCmpC4kCUzp89rsKQa12LrEu6yxLG2r49DqWY+XPZPHv6QoCvmqVa2MLgZbAJFtE+xWZ3BJ6lo2Cd2tcFV2BDxGp1U9Jh9D6aJPDANvmSKy44mwH1okf2o6xCV+eg80snd0hAsxQdHUjhImc+U4txjaOabiNSfE4nQyr9E6ZDh9Nn3Z3TlBHb+Eh3l1o7n9yF1loxdt76InIoJgpO8JaJaTtuzDhvW1G4ZQ57OmoAguiKfogf/txkqPQQr2zJ2iJU3swLW3jsROXftlvIQCFWaIgmOiDO7jpPqoiHQuU8+Edf74Im3So3zbZis+lvdCJQGGnanb81GKd0bYPCU20LMqY3E3K1ZH7QLq7Tmq+CTk++5tVgyp8wgxmw6CFnfzaBbCaP2I6/RBIOqxh66h1T9KIvUpuFRtexhl05AeI4FfoKrItE4Z3f+ips/5rY78T27AMXKxd2YaiezcUm0x+qcmz6HDRqFUfEDGmTo+WvSKnMSxkQB6faUN32fDYtQMVXecUbdCha+sccxCIfMzqodSKteFjZEC9OKVEgNNpPihcOkIcPAT6IvFh9aL7b0uZKaC82ELokRdDiPijp8v3Pp/W64Wa3f0QJUzlPAwISt1YpwIvdoRO1FRvz4MbmMpe0pTkjzExccA3uVuXG+4biERpvnhJEmZtjqy+nw0wt+ty7wny8TnBQwyrYnOsbaN25y11xeZnWL22gThCk7eEndutbls/wWzwEu/TEqr4WYooM+WZdE VxRyQbTa AnKYQ3LudGkrM/irU8H/pCpvhmUekRmsdm6ichasPLOy2U85Hhq71bai0MLWlSfpobVZEkJhqNf81prVGvW68UR4qhD1JZ7k1vRLZ+bxIgNxV/quMFrbbHGmIGb7enp6Tq7rDhmsKUHbukZqoOhlEA9cwRQMKcLMzYotW7rHrs1FAbevXCaAREonehYPZMvR3DFv9XONnExBdPII+LTVtfQ2xWI96U97CPWlvnbKZ4B+RWHUdVm7Q0ynsSau/O1js6NaOoJZasycF5lnF1Vt3mg3mawZm/OthltZXZwGze0kSNijLG/CQMZj8d2W24/9LtzTOgjkzhiKDYfZAlTr4yuWn+gsXvhw1MN+I2TiC3oIq4bsymf6jeks9EInpXXAeaexH4pWJWXWVDzZr9tJdEp7TmWt58wnoyMxykXG7nzT3YfWVEXbCx3BTaHqCh9AUpppkqJ6MEqT3bMa8X7rn1uPTAP+4D1cLtZwNpB7pHOHihZz/grdTFXfFpitPJ3Q3Gi1+JuO7YXMBQKBHfbr1+OL5Oiq0sFGiXM0M X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 7a003d8abb37bc..92234f4b51d29a 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -386,7 +386,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 Sat Jan 21 06:57:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13110986 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F437C38142 for ; Sat, 21 Jan 2023 06:58:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CB9D6B007D; Sat, 21 Jan 2023 01:58:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 97C756B007B; Sat, 21 Jan 2023 01:58:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86ACF6B007D; Sat, 21 Jan 2023 01:58:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7810F6B0078 for ; Sat, 21 Jan 2023 01:58:18 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4B14A140552 for ; Sat, 21 Jan 2023 06:58:18 +0000 (UTC) X-FDA: 80377902276.18.C070E06 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf10.hostedemail.com (Postfix) with ESMTP id A5BD8C0002 for ; Sat, 21 Jan 2023 06:58:16 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=i34OoNOi; spf=none (imf10.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674284296; a=rsa-sha256; cv=none; b=BJE3D9HzVmaWl3Qb2MSPCaV3IE1TcSuhmDCZVrpJZHEt3bYJF+q8+1QuJJE8aVkEx3F7qv 8dcFO26ClxEwbkLgx+uiSOh7X2nGGUBloYfCCBoWhagrN370JjaeXeFkUooRewWzbe/mqz tiuuy7pECYKuX8pT4Sjfan80EBkL9qM= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=i34OoNOi; spf=none (imf10.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674284296; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YYpS3Y5p5Tks64mwSZy8Ca3HveuDUE7eUAUp6nFbmxA=; b=TP257Bwj40aLZ+5hLoiewAyvHOJ55WlCBh0PETyHQyEhgoEWkIwWtsJEC4v9mjGexKK3ww laIipIRgChFOLRLECEouYEZ0IIse4P2JzZ+y5wTkmiTArKoNrPtDJeTxs2RCV/CPi5J58t 4xEE2EjRI3W2zEgJV9g+4ECtvWFiWNY= 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=YYpS3Y5p5Tks64mwSZy8Ca3HveuDUE7eUAUp6nFbmxA=; b=i34OoNOiuOAMqsVR5goGoV7AAN 68Fu9N8d4Dw7F1z2fIjIM+x1l580f1YXaquY4Wcl9zjTXWB6O/JrNkq55Pe95jE7djhGlJa6sDDvk CAUzPFbOqqw6RhDYLJUEnFXlj6vPwYQWaLCHnfMcnwurzh6cv9vB+okzKJoHtlY3dHYFk2Sjh8ZJ2 AvAENi9Ag/pAooPiFgszDIENS+ujLdYXF5Ajyjr46LHZ9X+EojW2hDgdnAyu1mF8ueZvkO+J2isnX y07MeXsZtQ4PV15Zxm2OTXsFJhWD28Muv18kQZKaxIVXaCsqF5IKhlIatUTuFgyOGZcDXns7qhVXX huf1HbyA==; Received: from [2001:4bb8:19a:2039:6754:cc81:9ace:36fc] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJ7pI-00DSPB-Bf; Sat, 21 Jan 2023 06:58:08 +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/7] shmem: remove shmem_get_partial_folio Date: Sat, 21 Jan 2023 07:57:52 +0100 Message-Id: <20230121065755.1140136-5-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121065755.1140136-1-hch@lst.de> References: <20230121065755.1140136-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 X-Rspam-User: X-Rspamd-Queue-Id: A5BD8C0002 X-Rspamd-Server: rspam01 X-Stat-Signature: 3zzxztc6zokt9epm5ddwsyx4wzqwwcfr X-HE-Tag: 1674284296-954031 X-HE-Meta: U2FsdGVkX18ndZn2vrPxaKQC1Xi+9npcdE6mntcV6D1ZLUg8723cd9zM8kruBn3EArNwbWjlNcu+diRs8Q7VWGJDGxYS7uZXgCQ5neV2u/36r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FejeNBUlmgmyC9S6YB60q3WQeQ9g8X1LZatJYElEfERNRCo7cA0q2F0savH7+FcrJWPUALBYwlKjcLIqGuXuOoUFSAIWW+IHnu7sCs7szs8m79XHsXXyaxch6RuqFmpV6OdpGbuhcloxrs7k/mZaBxnx1C3non5r3KKfac+6ryTrhE7R2DKG53WQHIN4akKnIpJbjyNJ+nqsndJFhDJedoOtxmY94/UBcYlLjJuZnvutp1NcD1V3rlYIKuB8jIcP4k2g5f9rczQQR/RW0bq6S+5sJDckl30 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 de6fa3980c7d6b..a8371ffeeee54a 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 Sat Jan 21 06:57:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13110987 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B14CAC38141 for ; Sat, 21 Jan 2023 06:58:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C3066B0078; Sat, 21 Jan 2023 01:58:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 473396B007B; Sat, 21 Jan 2023 01:58:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C67C6B007E; Sat, 21 Jan 2023 01:58:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1AAA76B0078 for ; Sat, 21 Jan 2023 01:58:21 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 885A9120F3E for ; Sat, 21 Jan 2023 06:58:20 +0000 (UTC) X-FDA: 80377902360.06.F63FE2C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf19.hostedemail.com (Postfix) with ESMTP id E5BDE1A000C for ; Sat, 21 Jan 2023 06:58:18 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=G9w5jE7N; spf=none (imf19.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674284299; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dhtgDUov3OaCzjD6ZOk7Y/bvFnZoNJ17iYtVJ43FaOw=; b=RbQ36tzyQ0dh5KBH9lMChtaNnopO+iujJR0cMFQL/pRoAYOlQng340uMLKaI1q442yExgH AJQM01zfI0dI3DiCmraZi8PmTevDB4ycXaf2XK6phWvKx9HTerEPrnyWqv6RyZn+wkOuOV Cvi8a6/+Gi7mPZkNcGDxjkJ5NgTvcxw= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=G9w5jE7N; spf=none (imf19.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674284299; a=rsa-sha256; cv=none; b=BxT59B6OFFEM6EwcaHX13jfjDvlh3Gx/GwpzbLjYr+W5C8CkF65QMbQMJArLfMQrCsAGKN mcOeNHmDhDhDs+/6NLzJehEx8LZxmVeTi9EAkRkiv6D8Xq8HD2Glfg+gm69p93e5uhdfVc jB2oQSJ3kOJCYTQPF2Xbttl4CBrW/SY= 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=dhtgDUov3OaCzjD6ZOk7Y/bvFnZoNJ17iYtVJ43FaOw=; b=G9w5jE7NAr6MGb6I4pPFsKkkAm hVCeH1b4Wgh3QV9bwBJ8bkT95rJ46kFwdgWOYMTr+kI3hra+yQTnwpWBeCyMGYKam8JO8qWTMNbfe +lMtDZbvsZGFtOmweGumZ4lNQrAnjTiwAv5iagQOpIelFLsbE653QMuO963iXvXWjsa7djg1G7Lna NwBQGQb09jXICVz2SQmpO8/IoE027GRBPFi47VNrzL/u0CpYEfWlHyQHtI4Mhmzl0tdzD/VADXX4W A5WlMHN64X6E85Hc1LBuISuR6TXSib0ti87LzYDn3DbeXlzUVUlxSHuGfrDyaxa1F16tBiEQIms/d flCIkwBA==; Received: from [2001:4bb8:19a:2039:6754:cc81:9ace:36fc] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJ7pK-00DSQK-T2; Sat, 21 Jan 2023 06:58:11 +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/7] shmem: open code the page cache lookup in shmem_get_folio_gfp Date: Sat, 21 Jan 2023 07:57:53 +0100 Message-Id: <20230121065755.1140136-6-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121065755.1140136-1-hch@lst.de> References: <20230121065755.1140136-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 X-Rspamd-Queue-Id: E5BDE1A000C X-Stat-Signature: nx9inkg57qqdcunqyah97whi836ehyo1 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1674284298-291292 X-HE-Meta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kpWA9ARpTodmR6vVob3TyZsjybNN+4TTHzqwxV1PXUN7bdRWl1XHU4c60smBLqOXsHxomALJ+mlUpImx8XC4SNSvLNWgwAUTCg/uA03r97CXkBNIaCtkaoJRc1HoBAKKDAj3+P/NX5znONL6s1ay5iqNt9oh0zSgs2zMsGPSzQduXdJVwCePUpuO/yJDg7OMm7/ukL4nc8A6R02+Cde1mglZue50dFiXQF7mVh5X722WeM8WTCv49YLMD3H+x8QXc9Wx2lT2fvm1yzCLBX/OEOyyZYNSENSdha/C9lqj2lh96o8N/RxMbpV6agMnjJo6A2yShbDNzdV5z1PIiMy00v8w606o/LTI2mblYBxiVXPj3X08x7fMilr6KudaxpMuYctvcd2YJQTd08rh X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 a8371ffeeee54a..23d5cf8182cb1f 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 Sat Jan 21 06:57:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13110988 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8424C38A23 for ; Sat, 21 Jan 2023 06:58:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5605F6B007B; Sat, 21 Jan 2023 01:58:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C0A36B007E; Sat, 21 Jan 2023 01:58:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C5FD8E0001; Sat, 21 Jan 2023 01:58:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 188076B007B for ; Sat, 21 Jan 2023 01:58:23 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id ACCC61A05BD for ; Sat, 21 Jan 2023 06:58:22 +0000 (UTC) X-FDA: 80377902444.29.6D2CD90 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf12.hostedemail.com (Postfix) with ESMTP id 1129C4000B for ; Sat, 21 Jan 2023 06:58:20 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=EwtGJdYh; spf=none (imf12.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674284301; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=72dbPnQldghXJsWt6hBZ/ADNkiEKaZsKzxCkekJEdAU=; b=KsJYUKCBPxMXQNHi3WnL4RA6ftOvpH5p5PgVWYGya7ALN7y6QjYnCFZatWpSxLch31qc31 ByCiysRY/aIBYZy74G8habcBPeMwd84WFAlexNz94P4bllN3xBCFu0XEwEnCiYwZUDU1XU 3s3dmbyMt0AirL0LT06/hYlOwJs6BWU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=EwtGJdYh; spf=none (imf12.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674284301; a=rsa-sha256; cv=none; b=f4qOlvFxICQ0soIuNEpJ/EdPRU1plHg3qf4EgN8FhUHQGBuigNEYDfII5TeTvndB/S16uD JwbTCkaYdsWWXvBm1vPaEoOhpbroN6st1oEQ9bbMocj3oROxQEDd/molz2yOAWRcQfhlKo fph4xfjvIteuxbaLcZgyBzUxuuhiaA4= 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=EwtGJdYhbY2t5msbayuhoiWkpe t6MwHMua7C4MCPLQpu3tFasW+WmUYj7lC4AOYQnwz08fambYeKpMPRiROaZQd5HO+QYqJCB1TNKNy NDrFLEbFZd7oXPqhg22FKmQ/iZyvTzrfDVoCr7fi/kMrj5I5xwyScolm4xH6P4xCA8wakx0Djui6w 5gGQm0cHzgcYY4fVBu0uPaBIxMKCzwsH1+EMy0qjvlNu7sv+t/x+2tPkuaoQrrof7B6CQmFfx/lm6 cNXGZSlwSjg0xTj8OBxNz35zWnQF3+xHMG9XkqAuteCgpWjW/af6YwE6nakL4Pe/4B+KdbLazR4zp PKWk1kjg==; Received: from [2001:4bb8:19a:2039:6754:cc81:9ace:36fc] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJ7pN-00DSRH-Cq; Sat, 21 Jan 2023 06:58: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 6/7] mm: remove FGP_ENTRY Date: Sat, 21 Jan 2023 07:57:54 +0100 Message-Id: <20230121065755.1140136-7-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121065755.1140136-1-hch@lst.de> References: <20230121065755.1140136-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 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1129C4000B X-Stat-Signature: ozo8xsq4xos8p6t8bwgiiem3rd1psrtn X-Rspam-User: X-HE-Tag: 1674284300-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OAN6xAkoZzsrAs52kR8J6MZ0tLcrDbWMr+S+IBECami/HDyz36BL11n/ZdaT9GMHSlhjM/NRAXcsJDAkZjeMmdszUwX78zkxBApFkc2XViRnm7BAyt+NWb1IxWnMMIMEoNL3SYn7b7Jp6aC2By1Jeuzb7jCiiZtgf4HFDQ1NB0XReqJU9HKq5C+BGAvGhidQxaobX1upPhcHo/F9s4jQG9YphTFpzI38x+kglLtRmCp4z1q/EVAuN1qh3HpkWB1Y2agAGP0WjLU6/H5EzilzpQoTfLdGuEEZXcYGCXDKrzSJpuJMgRbgg3lnuCX2IrSJWGQ4qnUrwjEtVt+WoZ7fw/bmRquHrBRCgnkBqML1zWff3VUW5n01dp9mV6d8dXAtuJ36WpDle3hrQhzFEhNgt X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Sat Jan 21 06:57:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13110989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08098C004D4 for ; Sat, 21 Jan 2023 06:58:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 956556B007E; Sat, 21 Jan 2023 01:58:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DF0F6B0080; Sat, 21 Jan 2023 01:58:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AFF48E0001; Sat, 21 Jan 2023 01:58:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6947E6B007E for ; Sat, 21 Jan 2023 01:58:25 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4533340F92 for ; Sat, 21 Jan 2023 06:58:25 +0000 (UTC) X-FDA: 80377902570.21.CB2EF94 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id 5A8C7180003 for ; Sat, 21 Jan 2023 06:58:23 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fYGoNYgZ; dmarc=none; spf=none (imf24.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674284303; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SIk/EpIKI6OVNH30Vsk1L+zEVx6KaLoR+ruMm5fgkbo=; b=1ws8JJrCIgXUxdPc2usdoEr5t2E+JzET27fsHj2OXrNjH178rTSHH4C1KeUC1ouOsmh5TW RtqXdDuTIDAZlh1G7eRFZjeqElj2DYzOYGlxuh6DF861kJbZyO0bZzSLM7Je/ASr5H5Pg0 0hdgUEqQnhlIYGsn26ietAZaCYzRxn0= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fYGoNYgZ; dmarc=none; spf=none (imf24.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674284303; a=rsa-sha256; cv=none; b=2gMWZvxE0TAmfQ+weQaQryDjhtOjpinN64XcIoAWAxJF6Ko3VS4WRFZhrBoQMVmdg3dv2Q TCKlKemsUaWJAurMPid1wHrgrgdCmIOlNOqzMoM+ybSFVG5EB+hlDRHqc4LP2iA5UhgXdD nHQzE6Flxle/YSW4EDE/EZ652n9SIiY= 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=SIk/EpIKI6OVNH30Vsk1L+zEVx6KaLoR+ruMm5fgkbo=; b=fYGoNYgZZLNVZO+sNlhn3I0TBh m8kaAqBgXEv9iOTVK9Yxd4dhaDqaTc5rbzeZBhJERodTlL99wURJW+vzZzF4D3k1hlYGHE0cDX/7T SDuDKMIIh+ZoA2SYjSt+2kEspUIge6am5enh3SOqI08anH2Hzj9yRb2SuhFtMNH7KDilpS0TIW659 Sfa1r7B5vQZzmJbE4huG5HN5bJ8+3TE/by4tBHbomsmuq5jRfdv6brSOw1Ei/t8qUVsQMo3M85MWh EG/dMY5KKaqPUMgl7QcqVPum8Be3sOJSmyXuz1MDvLw+7ZjKdb2S+AxgHwh2YQRh9npFf3rZhcimr iCepEeEA==; Received: from [2001:4bb8:19a:2039:6754:cc81:9ace:36fc] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJ7pQ-00DSSt-Ab; Sat, 21 Jan 2023 06:58:16 +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/7] mm: return an ERR_PTR from __filemap_get_folio Date: Sat, 21 Jan 2023 07:57:55 +0100 Message-Id: <20230121065755.1140136-8-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121065755.1140136-1-hch@lst.de> References: <20230121065755.1140136-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 X-Rspamd-Queue-Id: 5A8C7180003 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: sb6mb48hoa9kq5s3zwrad4sk67z6ep95 X-HE-Tag: 1674284303-107566 X-HE-Meta: U2FsdGVkX1/sTzMJvA8RJyXKGtFHr/e7lfLT9HekOopetP/DE+VAFe/9If9ZDSINCNGBz0l/KVaUaNOFBUPki0nbDaKxYNJVwuqjCep6R0fEL7Gyr/vFk7Z6ajWEm9RMWjU1u0KbGN27yvy0OGNaPr0QpNZD4HuebqUaVtgTns11SDMf/x+iyQeGuV5jINl5KZ//uPnxc2snEY5D/JvmJK2Bdkm0RAZLW8+22KaXjUGDx4fvwTec8OnYnm2yhcosGwQmNPeAl+mA8ZPckeDJb05S46sS01tZ/riUFcdb75byzvzcthZkPfm5179xs6H7bfflUkinnQQDQn7rsShepMnAOAdEfeIcVt8mXuDI2fHyfuzXibRYeJJmDa6xHaRmhpVOwHdFTXF7LRxSESmt//Kox1FGl8xe9nJxX2krlSUWYi1F7N9XhtMFkxk5WLRUynLQf6+jqLa5t+k0LbUsh5WaQfA4eJ+0PRRrKs72ZRx0FZR1ALFauUfuCu5He1ClKJ0XdJ60nTbzjXgEq0WXjvn8e1MyFX3Kdm3ezK43cCAMf2fmv+S5NS5S0uzXvtHZSRDKiteslTaJYxHcxQVAqUfEw6fNHe0RCcGe8RgDk6/EQ0L43XH9CNEVTYiB19se8vcj75FGUqZMGVs3QChMAu6WNVbMjcnfULoDXMB/PGUZ4ekfZJZD/YVNwSeXGG7OPoOagQ1TsMHk+TDYxeI6e0XWLMZeYPJPdYFYtg0eeYIv4c+Py7zqVSMjoYi0ZT0bUS7Jgn8/oDFqTV31CZPRrQ4m2SLz6Fkg4oOYsd2qgDugNI1roDkUXvrYtc+VrqCJhLEUOCEmrmHB7FkILS8ug3jxYz4qRUqRC/xkJDsxwA24y63bwphu6UMZceNzBqDyEZ/yqyCeyYwU2mxzXuwBPTVWPoHYChI0XNdiML0joTK1rAVhMnucktG5RyRttaxWTf4xAlzguLWNHmR7c17 DYNiQiYX RO8WHvJgl5murSXMi5lbeYpRSJ708zzv5/IXMKwceGLpIBpL3iWHAWZSv+qdY9x44z7Q3FGrWvkGilWYvMsLL8o0SKf28QRyPhXUToVMLwIRIyt+a99iXOdzo3WM0UeqzH7+SuOzakPlR/j8Evd0eSCpwG911pCOE8n8OuCm4+YxHrgrrZ8StSC6/jcgm5ec8NRZgA9dOzYeKC97G0wMWVDD+S+D6idXUI8XUOC9gdCW4eARuvR9l3QtsaBese+I6hmhLflk0PUFc1gjDA5/JVz4BPK7zjZKtOz0isO5RS6Dm3CGxvtw/henjCZ/PU4h/tUIlk//mkg/1m2XWrR13+l4/oCNZA4eRicfqms9Bj1g6nqV5kHTYDtkZIcU9iHjvDsoZ2PM9bq+/j+Sa+E4T/43jMttD6y86YEpTAUWdHGxKst79MfdE8le6AUYnhioPWacDQSB2HS7ohhmc75Dx31dFvIoPhJZ6boUv X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: David Sterba Acked-by: Ryusuke Konishi --- fs/afs/dir.c | 10 +++++----- fs/afs/dir_edit.c | 2 +- fs/afs/write.c | 4 ++-- fs/btrfs/disk-io.c | 2 +- fs/ext4/inode.c | 2 +- fs/ext4/move_extent.c | 8 ++++---- fs/hugetlbfs/inode.c | 2 +- fs/iomap/buffered-io.c | 15 ++------------- fs/netfs/buffered_read.c | 4 ++-- fs/nilfs2/page.c | 6 +++--- include/linux/pagemap.h | 11 ++++++----- 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 ++++++++------- 20 files changed, 60 insertions(+), 66 deletions(-) diff --git a/fs/afs/dir.c b/fs/afs/dir.c index 82690d1dd49a02..f92b9e62d567b9 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 27abe8fdfd92b3..e888abee119fd6 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4037,7 +4037,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/ext4/inode.c b/fs/ext4/inode.c index 0f6f24bb8e8fba..b4c65e6aa360d2 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/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index fb810664448787..6cac1b92520af1 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 d3c300563eb8ff..94a4d2e66ac66d 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -468,19 +468,12 @@ 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; - struct folio *folio; if (iter->flags & IOMAP_NOWAIT) fgp |= FGP_NOWAIT; - folio = __filemap_get_folio(iter->inode->i_mapping, pos >> PAGE_SHIFT, + return __filemap_get_folio(iter->inode->i_mapping, pos >> PAGE_SHIFT, fgp, mapping_gfp_mask(iter->inode->i_mapping)); - if (folio) - return folio; - - if (iter->flags & IOMAP_NOWAIT) - return ERR_PTR(-EAGAIN); - return ERR_PTR(-ENOMEM); } EXPORT_SYMBOL_GPL(iomap_get_folio); @@ -653,10 +646,6 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, if (!mapping_large_folio_support(iter->inode->i_mapping)) len = min_t(size_t, len, PAGE_SIZE - offset_in_page(pos)); - folio = __iomap_get_folio(iter, pos, len); - if (IS_ERR(folio)) - return PTR_ERR(folio); - /* * Now we have a locked folio, before we do anything with it we need to * check that the iomap we have cached is not stale. The inode extent @@ -911,7 +900,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/include/linux/pagemap.h b/include/linux/pagemap.h index e2208ee36966ea..6e07ba2ef18327 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -520,7 +520,8 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index, * Looks up the page cache entry at @mapping & @index. If a folio is * present, it is returned with an increased refcount. * - * Otherwise, %NULL is returned. + * Return: A folio or ERR_PTR(-ENOENT) if there is no folio in the cache for + * this index. Will not return a shadow, swap or DAX entry. */ static inline struct folio *filemap_get_folio(struct address_space *mapping, pgoff_t index) @@ -537,8 +538,8 @@ static inline struct folio *filemap_get_folio(struct address_space *mapping, * present, it is returned locked with an increased refcount. * * Context: May sleep. - * Return: A folio or %NULL if there is no folio in the cache for this - * index. Will not return a shadow, swap or DAX entry. + * Return: A folio or ERR_PTR(-ENOENT) if there is no folio in the cache for + * this index. Will not return a shadow, swap or DAX entry. */ static inline struct folio *filemap_lock_folio(struct address_space *mapping, pgoff_t index) @@ -555,8 +556,8 @@ static inline struct folio *filemap_lock_folio(struct address_space *mapping, * a new folio is created. The folio is locked, marked as accessed, and * returned. * - * Return: A found or created folio. NULL if no folio is found and failed to - * create a folio. + * Return: A found or created folio. ERR_PTR(-ENOMEM) if no folio is found + * and failed to create a folio. */ static inline struct folio *filemap_grab_folio(struct address_space *mapping, pgoff_t index) 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 17335459d8dc72..7ecebdd2c23391 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5689,7 +5689,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 cd69b9db008126..5437e584b208bf 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 23d5cf8182cb1f..8589ab4abd2b11 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 92234f4b51d29a..c7160070b9daa9 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -336,7 +336,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; @@ -366,6 +366,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; @@ -389,22 +391,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; } @@ -431,7 +432,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;