From patchwork Wed Dec 8 04:22:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12663695 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 D04F9C433EF for ; Wed, 8 Dec 2021 06:19:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 901C16B0073; Wed, 8 Dec 2021 01:18:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B02A6B007D; Wed, 8 Dec 2021 01:18:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 778D76B007E; Wed, 8 Dec 2021 01:18:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay026.a.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 6809D6B0073 for ; Wed, 8 Dec 2021 01:18:38 -0500 (EST) Received: by unirelay02.hostedemail.com (Postfix, from userid 108) id EA637210A3; Wed, 8 Dec 2021 05:32:57 +0000 (UTC) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 300242107A for ; Wed, 8 Dec 2021 04:29:13 +0000 (UTC) X-FDA: 78893347386.12.56A5B00 Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by imf16.hostedemail.com (Postfix) with ESMTP id C78EBF00008F for ; Wed, 8 Dec 2021 04:29:12 +0000 (UTC) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 34831213A0 for ; Wed, 8 Dec 2021 04:23:16 +0000 (UTC) X-FDA: 78893332392.18.8264C7B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf05.hostedemail.com (Postfix) with ESMTP id B85D2100005 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=HmCkLmM73d68sFeDxuolEllAHZE5BSsg2WY8bvzzTFU=; b=GETSPJyRFuJqsMvXyRm+P1Lwlv AfTlnrLL1Jmnr6Zc3Mr6VQOD2hH7FZ9wvo7KmbUZhu+cuMe+j7/wZcaMcVl5Nyls6mrJ6vXocaTBi gbMEM7mfbB1nCYm1B4a3CJ4Uyc5939G77ahZL1EYl/1eKiq+Ki4eSNpGqLOk9xRO0ALsBJaA6J4JI DFvD0u2OyPG96ggBWZXRAJaSP1H/2j56vCisr2P2LcbvMiwwGAvvbVdhWYfmuvYDjAECZNL2cv7L2 FmFM/iQ0FGskhIBXu8E3WVqSNlLLgI4NKDcWr5D2Hlgvi0g0aBl8EDieDLKwaMy8/1KCvn6j0NC2U ldqa9yOA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1muoU5-0084Zd-9k; Wed, 08 Dec 2021 04:23:13 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 29/48] filemap: Use a folio in filemap_map_pages Date: Wed, 8 Dec 2021 04:22:37 +0000 Message-Id: <20211208042256.1923824-30-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-HE-Tag-Orig: 1638937395-857090 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C78EBF00008F X-Stat-Signature: 9pdfsux1xwqn3csrg6jiwhqskh8s4zp5 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=GETSPJyR; spf=none (imf16.hostedemail.com: domain of FILTER%willy@infradead.org has no SPF policy when checking 64.99.140.24) smtp.mailfrom=FILTER%willy@infradead.org; dmarc=none X-HE-Tag: 1638937752-330882 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: Saves 61 bytes due to fewer calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/filemap.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 47880ec789f4..8cca04a79808 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3227,7 +3227,7 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct page *page) return false; } -static struct page *next_uptodate_page(struct folio *folio, +static struct folio *next_uptodate_page(struct folio *folio, struct address_space *mapping, struct xa_state *xas, pgoff_t end_pgoff) { @@ -3258,7 +3258,7 @@ static struct page *next_uptodate_page(struct folio *folio, max_idx = DIV_ROUND_UP(i_size_read(mapping->host), PAGE_SIZE); if (xas->xa_index >= max_idx) goto unlock; - return &folio->page; + return folio; unlock: folio_unlock(folio); skip: @@ -3268,7 +3268,7 @@ static struct page *next_uptodate_page(struct folio *folio, return NULL; } -static inline struct page *first_map_page(struct address_space *mapping, +static inline struct folio *first_map_page(struct address_space *mapping, struct xa_state *xas, pgoff_t end_pgoff) { @@ -3276,7 +3276,7 @@ static inline struct page *first_map_page(struct address_space *mapping, mapping, xas, end_pgoff); } -static inline struct page *next_map_page(struct address_space *mapping, +static inline struct folio *next_map_page(struct address_space *mapping, struct xa_state *xas, pgoff_t end_pgoff) { @@ -3293,16 +3293,17 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, pgoff_t last_pgoff = start_pgoff; unsigned long addr; XA_STATE(xas, &mapping->i_pages, start_pgoff); - struct page *head, *page; + struct folio *folio; + struct page *page; unsigned int mmap_miss = READ_ONCE(file->f_ra.mmap_miss); vm_fault_t ret = 0; rcu_read_lock(); - head = first_map_page(mapping, &xas, end_pgoff); - if (!head) + folio = first_map_page(mapping, &xas, end_pgoff); + if (!folio) goto out; - if (filemap_map_pmd(vmf, head)) { + if (filemap_map_pmd(vmf, &folio->page)) { ret = VM_FAULT_NOPAGE; goto out; } @@ -3310,7 +3311,7 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, addr = vma->vm_start + ((start_pgoff - vma->vm_pgoff) << PAGE_SHIFT); vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, addr, &vmf->ptl); do { - page = find_subpage(head, xas.xa_index); + page = folio_file_page(folio, xas.xa_index); if (PageHWPoison(page)) goto unlock; @@ -3331,12 +3332,12 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, do_set_pte(vmf, page, addr); /* no need to invalidate: a not-present page won't be cached */ update_mmu_cache(vma, addr, vmf->pte); - unlock_page(head); + folio_unlock(folio); continue; unlock: - unlock_page(head); - put_page(head); - } while ((head = next_map_page(mapping, &xas, end_pgoff)) != NULL); + folio_unlock(folio); + folio_put(folio); + } while ((folio = next_map_page(mapping, &xas, end_pgoff)) != NULL); pte_unmap_unlock(vmf->pte, vmf->ptl); out: rcu_read_unlock();