From patchwork Wed Dec 8 04:22:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12663759 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 8B2E2C433EF for ; Wed, 8 Dec 2021 06:46:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A20D6B007B; Wed, 8 Dec 2021 01:43:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 250356B007D; Wed, 8 Dec 2021 01:43:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13E716B007E; Wed, 8 Dec 2021 01:43:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay036.a.hostedemail.com [64.99.140.36]) by kanga.kvack.org (Postfix) with ESMTP id 04E0C6B007B for ; Wed, 8 Dec 2021 01:43:37 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 7AA4512019C for ; Wed, 8 Dec 2021 04:23:16 +0000 (UTC) X-FDA: 78893332392.10.962853C Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP id 2492030000A8 for ; Wed, 8 Dec 2021 04:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=AMdXWqM9y2naxpi8sOt9C2UydZsRiUJuoqUPrvDFvVk=; b=ByebKbQ1Gn0JnlxAc57DWSS9Ff Cc3iOKVahJoBfHov4cJb+ytLbC3XERdLjG1wLH5fkj/CO986sltyZgmUNUYBtC6b2n+Wa+xhZ+wbX PzYHzbmc/ZjhQtIwCZdjEqRSGyadsj0qjbQ6ca4Qd5O4CeeRyl5C2RoxCoybIwrP8YndDmRb9aYYo rGLA4ubMV4bwH7Q4byEX0oNFPIFEhVKi3AwADwxbozACEx3Jt/+dK4U6EfXkBeKDtVsBx3AYlwXXy 1MOzHPQMQkBAzNgQgcFn4AczCnKYCMItIIIR6b7n1iB074x0TB2xxanZIZb68/hufQF+xP7WtQhQr GhyvAcjA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1muoU6-0084br-Oc; Wed, 08 Dec 2021 04:23:14 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 37/48] truncate: Convert invalidate_inode_pages2_range() to use a folio Date: Wed, 8 Dec 2021 04:22:45 +0000 Message-Id: <20211208042256.1923824-38-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211208042256.1923824-1-willy@infradead.org> References: <20211208042256.1923824-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2492030000A8 X-Stat-Signature: kthkdkontswghf4h96dnzpoupbujkduf Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ByebKbQ1; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-HE-Tag: 1638937395-557160 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: If we're going to unmap a folio, we have to be sure to unmap the entire folio, not just the part of it which lies after the search index. We cannot yet remove the struct page from invalidate_inode_pages2_range() because the page pointer in the pvec might be a shadow/dax/swap entry instead of actually a page. Signed-off-by: Matthew Wilcox (Oracle) --- mm/truncate.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/mm/truncate.c b/mm/truncate.c index 0df420c1cf5b..ef6980b240e2 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -642,8 +642,9 @@ int invalidate_inode_pages2_range(struct address_space *mapping, while (find_get_entries(mapping, index, end, &pvec, indices)) { for (i = 0; i < pagevec_count(&pvec); i++) { struct page *page = pvec.pages[i]; + struct folio *folio; - /* We rely upon deletion not changing page->index */ + /* We rely upon deletion not changing folio->index */ index = indices[i]; if (xa_is_value(page)) { @@ -652,10 +653,11 @@ int invalidate_inode_pages2_range(struct address_space *mapping, ret = -EBUSY; continue; } + folio = page_folio(page); - if (!did_range_unmap && page_mapped(page)) { + if (!did_range_unmap && folio_mapped(folio)) { /* - * If page is mapped, before taking its lock, + * If folio is mapped, before taking its lock, * zap the rest of the file in one hit. */ unmap_mapping_pages(mapping, index, @@ -663,26 +665,27 @@ int invalidate_inode_pages2_range(struct address_space *mapping, did_range_unmap = 1; } - lock_page(page); - WARN_ON(page_to_index(page) != index); - if (page->mapping != mapping) { - unlock_page(page); + folio_lock(folio); + VM_BUG_ON_FOLIO(!folio_contains(folio, index), folio); + if (folio->mapping != mapping) { + folio_unlock(folio); continue; } - wait_on_page_writeback(page); + folio_wait_writeback(folio); - if (page_mapped(page)) - unmap_mapping_folio(page_folio(page)); - BUG_ON(page_mapped(page)); + if (folio_mapped(folio)) + unmap_mapping_folio(folio); + BUG_ON(folio_mapped(folio)); - ret2 = do_launder_page(mapping, page); + ret2 = do_launder_page(mapping, &folio->page); if (ret2 == 0) { - if (!invalidate_complete_page2(mapping, page)) + if (!invalidate_complete_page2(mapping, + &folio->page)) ret2 = -EBUSY; } if (ret2 < 0) ret = ret2; - unlock_page(page); + folio_unlock(folio); } pagevec_remove_exceptionals(&pvec); pagevec_release(&pvec);