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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14CA2C4332F for ; Wed, 19 Oct 2022 18:33:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7780B6B0074; Wed, 19 Oct 2022 14:33:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 726276B0075; Wed, 19 Oct 2022 14:33:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59E7D6B0078; Wed, 19 Oct 2022 14:33:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4C37A6B0074 for ; Wed, 19 Oct 2022 14:33:39 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 26B86C107F for ; Wed, 19 Oct 2022 18:33:39 +0000 (UTC) X-FDA: 80038547358.08.FB5083D Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP id AF7B8140034 for ; Wed, 19 Oct 2022 18:33:36 +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=AQTLH3SOCgsg4fRr1xIfZ6pIw1FyqAhjwDuq1uBRYyk=; b=lT6O4vnk20VbfGf/hu9rGfCPx5 5r+VuDM8fagp2CgHo7fX+NAmFcnEkFYijIi4qd/JMxnea3BtO0xI1s5E7fP75uolEwOiSxY9scZog mLvRkI0hgl7aSc0p7ts4Nt0O1lS3m3lFXybiB1Jp9h8i6HaCULR70ce9CGyYsxrtSILROv1nVSHM2 gN6UyqftYtZvE8Jv+VLodRsWd+xBeP7XkeU2tN4rBl3oVWKA8OTjM3DwwY4LFr/Mqe433GtYcyX5n NUuNyGaBZjYpgzvamDkYjhPMCR8kreljSL5ZVveWAIVGCdSgogXevGyHI3Qqx1bDqdRbDfveiAKW4 XoOwvICA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1olDsm-00BkzG-Q2; Wed, 19 Oct 2022 18:33:36 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH 3/4] mm: Convert find_get_incore_page() to filemap_get_incore_folio() Date: Wed, 19 Oct 2022 19:33:31 +0100 Message-Id: <20221019183332.2802139-4-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20221019183332.2802139-1-willy@infradead.org> References: <20221019183332.2802139-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666204418; a=rsa-sha256; cv=none; b=1fTaAvf9NrMmBiPri1L5lDD6ogSyVuNdPfZf25i9wQxNe2Z/Rl9/j9Gq+20Z/33NafaFqF PR/cph8oBV32YqSIVAqAHul5hwfIX4xOx0nxvgwelCjWdCqpUquxFcn+wHOjgQ2WKLmX0N TCAl5/H7UNh83DJtAhqrQn2MLOFJwC4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=lT6O4vnk; spf=none (imf23.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666204418; 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=AQTLH3SOCgsg4fRr1xIfZ6pIw1FyqAhjwDuq1uBRYyk=; b=xD6adgw6GQJn7fIVNj98IcXpEZMU1t6k2+pdgkPBJJJndYoMTbX8+oxRqfvtfrvbjA+AiL z8CxCNl20oRIIbhWRZj2c9O+7EEQGzF3JE9e1tlmEW970R1M/4UN6B99+xr/srFoDpd0hl 4xKwaYtMjjT4eseEcpN2ymqLQIUPPKw= X-Stat-Signature: bzchikqjk9o8pwkpqphu49c7bicp7jj1 X-Rspamd-Queue-Id: AF7B8140034 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=lT6O4vnk; spf=none (imf23.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-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1666204416-819346 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: Return the containing folio instead of the precise page. One of the callers wants the folio and the other can do the folio->page conversion itself. Nets 442 bytes of text size reduction, 478 bytes removed and 36 bytes added. Signed-off-by: Matthew Wilcox (Oracle) --- mm/memcontrol.c | 12 +++++++++--- mm/mincore.c | 10 +++++----- mm/swap.h | 8 +++++--- mm/swap_state.c | 15 +++++++-------- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 2d8549ae1b30..2e6e8bce1f60 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5648,15 +5648,21 @@ static struct page *mc_handle_swap_pte(struct vm_area_struct *vma, static struct page *mc_handle_file_pte(struct vm_area_struct *vma, unsigned long addr, pte_t ptent) { + unsigned long index; + struct folio *folio; + if (!vma->vm_file) /* anonymous vma */ return NULL; if (!(mc.flags & MOVE_FILE)) return NULL; - /* page is moved even if it's not RSS of this task(page-faulted). */ + /* folio is moved even if it's not RSS of this task(page-faulted). */ /* shmem/tmpfs may report page out on swap: account for that too. */ - return find_get_incore_page(vma->vm_file->f_mapping, - linear_page_index(vma, addr)); + index = linear_page_index(vma, addr); + folio = filemap_get_incore_folio(vma->vm_file->f_mapping, index); + if (!folio) + return NULL; + return folio_file_page(folio, index); } /** diff --git a/mm/mincore.c b/mm/mincore.c index fa200c14185f..7bf2803e03c6 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -52,7 +52,7 @@ static int mincore_hugetlb(pte_t *pte, unsigned long hmask, unsigned long addr, static unsigned char mincore_page(struct address_space *mapping, pgoff_t index) { unsigned char present = 0; - struct page *page; + struct folio *folio; /* * When tmpfs swaps out a page from a file, any process mapping that @@ -60,10 +60,10 @@ static unsigned char mincore_page(struct address_space *mapping, pgoff_t index) * any other file mapping (ie. marked !present and faulted in with * tmpfs's .fault). So swapped out tmpfs mappings are tested here. */ - page = find_get_incore_page(mapping, index); - if (page) { - present = PageUptodate(page); - put_page(page); + folio = filemap_get_incore_folio(mapping, index); + if (folio) { + present = folio_test_uptodate(folio); + folio_put(folio); } return present; diff --git a/mm/swap.h b/mm/swap.h index cc08c459c619..f78065c8ef52 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -41,7 +41,8 @@ void clear_shadow_from_swap_cache(int type, unsigned long begin, unsigned long end); struct folio *swap_cache_get_folio(swp_entry_t entry, struct vm_area_struct *vma, unsigned long addr); -struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index); +struct folio *filemap_get_incore_folio(struct address_space *mapping, + pgoff_t index); struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, struct vm_area_struct *vma, @@ -105,9 +106,10 @@ static inline struct folio *swap_cache_get_folio(swp_entry_t entry, } static inline -struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index) +struct folio *filemap_get_incore_folio(struct address_space *mapping, + pgoff_t index) { - return find_get_page(mapping, index); + return filemap_get_folio(mapping, index); } static inline bool add_to_swap(struct folio *folio) diff --git a/mm/swap_state.c b/mm/swap_state.c index 44e3530520e8..40fe6f23e105 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -373,16 +373,17 @@ struct folio *swap_cache_get_folio(swp_entry_t entry, } /** - * find_get_incore_page - Find and get a page from the page or swap caches. + * filemap_get_incore_folio - Find and get a folio from the page or swap caches. * @mapping: The address_space to search. * @index: The page cache index. * - * This differs from find_get_page() in that it will also look for the - * page in the swap cache. + * This differs from filemap_get_folio() in that it will also look for the + * folio in the swap cache. * - * Return: The found page or %NULL. + * Return: The found folio or %NULL. */ -struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index) +struct folio *filemap_get_incore_folio(struct address_space *mapping, + pgoff_t index) { swp_entry_t swp; struct swap_info_struct *si; @@ -405,9 +406,7 @@ struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index) folio = filemap_get_folio(swap_address_space(swp), index); put_swap_device(si); out: - if (!folio) - return NULL; - return folio_file_page(folio, index); + return folio; } struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, -- 2.35.1