From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B786C433FE for ; Tue, 8 Dec 2020 20:11:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 365B523A02 for ; Tue, 8 Dec 2020 20:11:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 365B523A02 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CB57E6B0068; Tue, 8 Dec 2020 15:11:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C67DF6B006C; Tue, 8 Dec 2020 15:11:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B54186B006E; Tue, 8 Dec 2020 15:11:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0131.hostedemail.com [216.40.44.131]) by kanga.kvack.org (Postfix) with ESMTP id 9F03C6B0068 for ; Tue, 8 Dec 2020 15:11:58 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 691EC180AD80F for ; Tue, 8 Dec 2020 20:11:58 +0000 (UTC) X-FDA: 77571211116.12.talk79_3e1163c273e9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 496FA18001F97 for ; Tue, 8 Dec 2020 20:11:58 +0000 (UTC) X-HE-Tag: talk79_3e1163c273e9 X-Filterd-Recvd-Size: 6126 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 20:11:57 +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=MU5rCpKmGXhiLqucBbIqDDGkng6QmmAdASzyNay4oBY=; b=h3L9nMuBrmeDfbKNSovSzbvMqm vCY+8SmGBTxB/iIbsiwS6qSFf88CsAvLf6KHr3fVfDraoxjNIBqchmUNR8hMDhNNimZgLsEEIofD1 djcVZuq+qaa1oba8EmjHYUKO101Y0u4SSAKxDsnAY1B14ucesBDybnajOKEltH2WroV+BKIqkoPFm xW0N9nUz5Ialk/+Z4pVDJ7+Q30hBoD/JmlAI84F+SMQcALPlAZRvwWD8fitI4bxACAiId5TbhX1U3 0oJAGb5vgIvvcW8fQps91ad5bmNiobVh2sskcxxY/b1PXb8/Ytm+1fO70OAsz8fsPTO1o0PM6LHyW MI4FlqdA==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmiwt-000515-P6; Tue, 08 Dec 2020 19:46:59 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org Subject: [RFC PATCH 09/11] mm/filemap: Convert mapping_get_entry and pagecache_get_page to folio Date: Tue, 8 Dec 2020 19:46:51 +0000 Message-Id: <20201208194653.19180-10-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201208194653.19180-1-willy@infradead.org> References: <20201208194653.19180-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: Convert mapping_get_entry() to return a folio and convert pagecache_get_page() to use the folio where possible. The seemingly dangerous cast of a page pointer to a folio pointer is safe because __page_cache_alloc() allocates an order-0 page, which is a folio by definition. Signed-off-by: Matthew Wilcox (Oracle) --- mm/filemap.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index f1b65f777539..56ff6aa24265 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1673,33 +1673,33 @@ EXPORT_SYMBOL(page_cache_prev_miss); * @index: The page cache index. * * Looks up the page cache slot at @mapping & @offset. If there is a - * page cache page, the head page is returned with an increased refcount= . + * page cache page, the folio is returned with an increased refcount. * * If the slot holds a shadow entry of a previously evicted page, or a * swap entry from shmem/tmpfs, it is returned. * - * Return: The head page or shadow entry, %NULL if nothing is found. + * Return: The folio or shadow entry, %NULL if nothing is found. */ -static struct page *mapping_get_entry(struct address_space *mapping, +static struct folio *mapping_get_entry(struct address_space *mapping, pgoff_t index) { XA_STATE(xas, &mapping->i_pages, index); - struct page *page; + struct folio *folio; =20 rcu_read_lock(); repeat: xas_reset(&xas); - page =3D xas_load(&xas); - if (xas_retry(&xas, page)) + folio =3D xas_load(&xas); + if (xas_retry(&xas, folio)) goto repeat; /* * A shadow entry of a recently evicted page, or a swap entry from * shmem/tmpfs. Return it without attempting to raise page count. */ - if (!page || xa_is_value(page)) + if (!folio || xa_is_value(folio)) goto out; =20 - if (!page_cache_get_speculative(page)) + if (!page_cache_get_speculative(&folio->page)) goto repeat; =20 /* @@ -1707,14 +1707,14 @@ static struct page *mapping_get_entry(struct addr= ess_space *mapping, * This is part of the lockless pagecache protocol. See * include/linux/pagemap.h for details. */ - if (unlikely(page !=3D xas_reload(&xas))) { - put_page(page); + if (unlikely(folio !=3D xas_reload(&xas))) { + put_folio(folio); goto repeat; } out: rcu_read_unlock(); =20 - return page; + return folio; } =20 /** @@ -1754,11 +1754,13 @@ static struct page *mapping_get_entry(struct addr= ess_space *mapping, struct page *pagecache_get_page(struct address_space *mapping, pgoff_t i= ndex, int fgp_flags, gfp_t gfp_mask) { + struct folio *folio; struct page *page; =20 repeat: - page =3D mapping_get_entry(mapping, index); - if (xa_is_value(page)) { + folio =3D mapping_get_entry(mapping, index); + page =3D &folio->page; + if (xa_is_value(folio)) { if (fgp_flags & FGP_ENTRY) return page; page =3D NULL; @@ -1768,18 +1770,18 @@ struct page *pagecache_get_page(struct address_sp= ace *mapping, pgoff_t index, =20 if (fgp_flags & FGP_LOCK) { if (fgp_flags & FGP_NOWAIT) { - if (!trylock_page(page)) { - put_page(page); + if (!trylock_folio(folio)) { + put_folio(folio); return NULL; } } else { - lock_page(page); + lock_folio(folio); } =20 /* Has the page been truncated? */ if (unlikely(page->mapping !=3D mapping)) { - unlock_page(page); - put_page(page); + unlock_folio(folio); + put_folio(folio); goto repeat; } VM_BUG_ON_PAGE(!thp_contains(page, index), page); @@ -1806,17 +1808,18 @@ struct page *pagecache_get_page(struct address_sp= ace *mapping, pgoff_t index, page =3D __page_cache_alloc(gfp_mask); if (!page) return NULL; + folio =3D (struct folio *)page; =20 if (WARN_ON_ONCE(!(fgp_flags & (FGP_LOCK | FGP_FOR_MMAP)))) fgp_flags |=3D FGP_LOCK; =20 /* Init accessed so avoid atomic mark_page_accessed later */ if (fgp_flags & FGP_ACCESSED) - __SetPageReferenced(page); + __SetFolioReferenced(folio); =20 err =3D add_to_page_cache_lru(page, mapping, index, gfp_mask); if (unlikely(err)) { - put_page(page); + put_folio(folio); page =3D NULL; if (err =3D=3D -EEXIST) goto repeat; @@ -1827,7 +1830,7 @@ struct page *pagecache_get_page(struct address_spac= e *mapping, pgoff_t index, * an unlocked page. */ if (page && (fgp_flags & FGP_FOR_MMAP)) - unlock_page(page); + unlock_folio(folio); } =20 return page; --=20 2.29.2