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 8E946C2B9F4 for ; Tue, 22 Jun 2021 12:56:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3CD7060720 for ; Tue, 22 Jun 2021 12:56:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3CD7060720 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 D0ACF6B0070; Tue, 22 Jun 2021 08:56:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CBA926B00A2; Tue, 22 Jun 2021 08:56:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B34D06B00A3; Tue, 22 Jun 2021 08:56:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0040.hostedemail.com [216.40.44.40]) by kanga.kvack.org (Postfix) with ESMTP id 7DE5D6B0070 for ; Tue, 22 Jun 2021 08:56:22 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1C96211931 for ; Tue, 22 Jun 2021 12:56:22 +0000 (UTC) X-FDA: 78281358204.18.775F1DE Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id A6530C0201C4 for ; Tue, 22 Jun 2021 12:56:21 +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=vRXrSxkOBgeAyweC+9pXXZ5AHBpEbng5q4ATizxSzA4=; b=hIqbwAUT0HThfuR7w6vLAXTw0b Q9p+VGQgZkNpVR00CvF1QiruW8grwrEEtNZBs+pHgfbiPQZ8HH3kBy8mnZe7SskUS+NvftCQcA+Ye KqowBHSj6PPvw79DctmV9iCtfxyluZM6Q2T8HPcRBgT9a+dAWDd655iDyo6uCGcCZrl+GJaA+8poj XXdlUQlA1ff1glZ34RgfOtghRKfau8pfWjkAAtpSyaB7mxJGCdMcduahJD2SL/NK3wQYSnzWJYTiH XeTxfJZO8DefbT4EZB1LZZLIM8WNPmFxIr19uGuhOlysYZYihvI4crz9hFsmCioIbphWwaERq8Y94 d37qOmJA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1lvfvh-00EJ97-U6; Tue, 22 Jun 2021 12:55:10 +0000 From: "Matthew Wilcox (Oracle)" To: akpm@linux-foundation.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 45/46] mm/filemap: Add filemap_get_folio Date: Tue, 22 Jun 2021 13:15:50 +0100 Message-Id: <20210622121551.3398730-46-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210622121551.3398730-1-willy@infradead.org> References: <20210622121551.3398730-1-willy@infradead.org> MIME-Version: 1.0 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hIqbwAUT; spf=none (imf14.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-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A6530C0201C4 X-Stat-Signature: itwk1cqed8ifb3qfup9s8bq9zum34ouw X-HE-Tag: 1624366581-107860 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: filemap_get_folio() is a replacement for find_get_page(). Turn pagecache_get_page() into a wrapper around __filemap_get_folio(). Remove find_lock_head() as this use case is now covered by filemap_get_folio(). Reduces overall kernel size by 209 bytes. __filemap_get_folio() is 316 bytes shorter than pagecache_get_page() was, but the new pagecache_get_page() is 99 bytes. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 41 +++++++++---------- mm/filemap.c | 90 +++++++++++++++++++---------------------- mm/folio-compat.c | 12 ++++++ 3 files changed, 74 insertions(+), 69 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index b0c1d24fb01b..669bdebe2861 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -302,8 +302,26 @@ pgoff_t page_cache_prev_miss(struct address_space *m= apping, #define FGP_HEAD 0x00000080 #define FGP_ENTRY 0x00000100 =20 -struct page *pagecache_get_page(struct address_space *mapping, pgoff_t o= ffset, - int fgp_flags, gfp_t cache_gfp_mask); +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 i= ndex, + int fgp_flags, gfp_t gfp); + +/** + * filemap_get_folio - Find and get a folio. + * @mapping: The address_space to search. + * @index: The page 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. + */ +static inline struct folio *filemap_get_folio(struct address_space *mapp= ing, + pgoff_t index) +{ + return __filemap_get_folio(mapping, index, 0, 0); +} =20 /** * find_get_page - find and get a page reference @@ -346,25 +364,6 @@ static inline struct page *find_lock_page(struct add= ress_space *mapping, return pagecache_get_page(mapping, index, FGP_LOCK, 0); } =20 -/** - * find_lock_head - Locate, pin and lock a pagecache page. - * @mapping: The address_space to search. - * @index: The page index. - * - * Looks up the page cache entry at @mapping & @index. If there is a - * page cache page, its head page is returned locked and with an increas= ed - * refcount. - * - * Context: May sleep. - * Return: A struct page which is !PageTail, or %NULL if there is no pag= e - * in the cache for this index. - */ -static inline struct page *find_lock_head(struct address_space *mapping, - pgoff_t index) -{ - return pagecache_get_page(mapping, index, FGP_LOCK | FGP_HEAD, 0); -} - /** * find_or_create_page - locate or add a pagecache page * @mapping: the page's address_space diff --git a/mm/filemap.c b/mm/filemap.c index 7d0b51f30223..e431461279c3 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1794,95 +1794,89 @@ static struct folio *mapping_get_entry(struct add= ress_space *mapping, } =20 /** - * pagecache_get_page - Find and get a reference to a page. + * __filemap_get_folio - Find and get a reference to a folio. * @mapping: The address_space to search. * @index: The page index. - * @fgp_flags: %FGP flags modify how the page is returned. - * @gfp_mask: Memory allocation flags to use if %FGP_CREAT is specified. + * @fgp_flags: %FGP flags modify how the folio is returned. + * @gfp: Memory allocation flags to use if %FGP_CREAT is specified. * * Looks up the page cache entry at @mapping & @index. * * @fgp_flags can be zero or more of these flags: * - * * %FGP_ACCESSED - The page will be marked accessed. - * * %FGP_LOCK - The page is returned locked. - * * %FGP_HEAD - If the page is present and a THP, return the head page - * rather than the exact page specified by the 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 page to replace it. + * instead of allocating a new folio to replace it. * * %FGP_CREAT - If no page is present then a new page is allocated usi= ng - * @gfp_mask and added to the page cache and the VM's LRU list. + * @gfp and added to the page cache and the VM's LRU list. * The page is returned locked and with an increased refcount. * * %FGP_FOR_MMAP - The caller wants to do its own locking dance if the * page is already in cache. If the page was allocated, unlock it bef= ore * returning so the caller can do the same dance. - * * %FGP_WRITE - The page will be written - * * %FGP_NOFS - __GFP_FS will get cleared in gfp mask - * * %FGP_NOWAIT - Don't get blocked by page lock + * * %FGP_WRITE - The page will be written to by the caller. + * * %FGP_NOFS - __GFP_FS will get cleared in gfp. + * * %FGP_NOWAIT - Don't get blocked by page lock. * * If %FGP_LOCK or %FGP_CREAT are specified then the function may sleep = even * if the %GFP flags specified for %FGP_CREAT are atomic. * * If there is a page cache page, it is returned with an increased refco= unt. * - * Return: The found page or %NULL otherwise. + * Return: The found folio or %NULL otherwise. */ -struct page *pagecache_get_page(struct address_space *mapping, pgoff_t i= ndex, - int fgp_flags, gfp_t gfp_mask) +struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t= index, + int fgp_flags, gfp_t gfp) { struct folio *folio; - struct page *page; =20 repeat: folio =3D mapping_get_entry(mapping, index); - page =3D &folio->page; - if (xa_is_value(page)) { + if (xa_is_value(folio)) { if (fgp_flags & FGP_ENTRY) - return page; - page =3D NULL; + return folio; + folio =3D NULL; } - if (!page) + if (!folio) goto no_page; =20 if (fgp_flags & FGP_LOCK) { if (fgp_flags & FGP_NOWAIT) { - if (!trylock_page(page)) { - put_page(page); + if (!folio_trylock(folio)) { + folio_put(folio); return NULL; } } else { - lock_page(page); + folio_lock(folio); } =20 /* Has the page been truncated? */ - if (unlikely(page->mapping !=3D mapping)) { - unlock_page(page); - put_page(page); + if (unlikely(folio->mapping !=3D mapping)) { + folio_unlock(folio); + folio_put(folio); goto repeat; } - VM_BUG_ON_PAGE(!thp_contains(page, index), page); + VM_BUG_ON_FOLIO(!folio_contains(folio, index), folio); } =20 if (fgp_flags & FGP_ACCESSED) - mark_page_accessed(page); + folio_mark_accessed(folio); else if (fgp_flags & FGP_WRITE) { /* Clear idle flag for buffer write */ - if (page_is_idle(page)) - clear_page_idle(page); + if (folio_idle(folio)) + folio_clear_idle_flag(folio); } - if (!(fgp_flags & FGP_HEAD)) - page =3D find_subpage(page, index); =20 no_page: - if (!page && (fgp_flags & FGP_CREAT)) { + if (!folio && (fgp_flags & FGP_CREAT)) { int err; if ((fgp_flags & FGP_WRITE) && mapping_can_writeback(mapping)) - gfp_mask |=3D __GFP_WRITE; + gfp |=3D __GFP_WRITE; if (fgp_flags & FGP_NOFS) - gfp_mask &=3D ~__GFP_FS; + gfp &=3D ~__GFP_FS; =20 - page =3D __page_cache_alloc(gfp_mask); - if (!page) + folio =3D filemap_alloc_folio(gfp, 0); + if (!folio) return NULL; =20 if (WARN_ON_ONCE(!(fgp_flags & (FGP_LOCK | FGP_FOR_MMAP)))) @@ -1890,27 +1884,27 @@ struct page *pagecache_get_page(struct address_sp= ace *mapping, pgoff_t index, =20 /* Init accessed so avoid atomic mark_page_accessed later */ if (fgp_flags & FGP_ACCESSED) - __SetPageReferenced(page); + __folio_set_referenced_flag(folio); =20 - err =3D add_to_page_cache_lru(page, mapping, index, gfp_mask); + err =3D filemap_add_folio(mapping, folio, index, gfp); if (unlikely(err)) { - put_page(page); - page =3D NULL; + folio_put(folio); + folio =3D NULL; if (err =3D=3D -EEXIST) goto repeat; } =20 /* - * add_to_page_cache_lru locks the page, and for mmap we expect - * an unlocked page. + * filemap_add_folio locks the page, and for mmap + * we expect an unlocked page. */ - if (page && (fgp_flags & FGP_FOR_MMAP)) - unlock_page(page); + if (folio && (fgp_flags & FGP_FOR_MMAP)) + folio_unlock(folio); } =20 - return page; + return folio; } -EXPORT_SYMBOL(pagecache_get_page); +EXPORT_SYMBOL(__filemap_get_folio); =20 static inline struct page *find_get_entry(struct xa_state *xas, pgoff_t = max, xa_mark_t mark) diff --git a/mm/folio-compat.c b/mm/folio-compat.c index 0a8bdd3f8d91..78365eaee7d3 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -114,3 +114,15 @@ void lru_cache_add(struct page *page) folio_add_lru(page_folio(page)); } EXPORT_SYMBOL(lru_cache_add); + +struct page *pagecache_get_page(struct address_space *mapping, pgoff_t i= ndex, + int fgp_flags, gfp_t gfp) +{ + struct folio *folio; + + folio =3D __filemap_get_folio(mapping, index, fgp_flags, gfp); + if ((fgp_flags & FGP_HEAD) || !folio || xa_is_value(folio)) + return &folio->page; + return folio_file_page(folio, index); +} +EXPORT_SYMBOL(pagecache_get_page); --=20 2.30.2