From patchwork Mon Jan 18 17:01:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12027831 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.6 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 9CEDAC433E0 for ; Mon, 18 Jan 2021 17:02:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 32F36222BB for ; Mon, 18 Jan 2021 17:02:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32F36222BB 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 23D4C6B00E3; Mon, 18 Jan 2021 12:02:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F09F6B00E5; Mon, 18 Jan 2021 12:02:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1080E6B00E7; Mon, 18 Jan 2021 12:02:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0194.hostedemail.com [216.40.44.194]) by kanga.kvack.org (Postfix) with ESMTP id DC9A46B00E3 for ; Mon, 18 Jan 2021 12:02:10 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 9C5164DD8 for ; Mon, 18 Jan 2021 17:02:10 +0000 (UTC) X-FDA: 77719513620.08.lock34_2e0e4822754a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 5F5621819E627 for ; Mon, 18 Jan 2021 17:02:10 +0000 (UTC) X-HE-Tag: lock34_2e0e4822754a X-Filterd-Recvd-Size: 5689 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Mon, 18 Jan 2021 17:02:09 +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=6YK8dxrIi6WHXmqxTYcAlqgkXxY6OI1r+h3iSsQcrI0=; b=C3raeL3Kn0g4dP57UwlPf+W+w1 ASPS/ph0PPLk1lgQZSN/QUf9GAS7hOISsupaAtKqlnnUSnkdFPekYxYrvlvbhJdi0LAyJS2C96Ho0 CQR7vQqZvS9L7t5gO37j7uy/Giixv3ZY2PYPlcU/PPNd4QyHuRfa7DPlZvaGfO0w+l9l/6GcP7pwe 53OlfOQFz81F3x9OEhRNtacl6pHmBhipXMC7iOuC9xFTW/vWXjtUtX3GvVhhYte3EXUwfzAxp5SZj LvOKX7ERIP0GzFHjICjw052chJUNhQZOOHWh6CmHzdRwdxa3HGc5lVzxaqHXU7LksNxIHFDn+pSmT NyUJteVQ==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1l1Xum-00D7Iv-FV; Mon, 18 Jan 2021 17:02:05 +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: [PATCH v2 10/27] mm/util: Add folio_mapping and folio_file_mapping Date: Mon, 18 Jan 2021 17:01:31 +0000 Message-Id: <20210118170148.3126186-11-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210118170148.3126186-1-willy@infradead.org> References: <20210118170148.3126186-1-willy@infradead.org> MIME-Version: 1.0 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: These are the folio equivalent of page_mapping() and page_file_mapping(). Adjust page_file_mapping() and page_mapping_file() to use folios internally. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/mm.h | 23 +++++++++++++++-------- mm/swapfile.c | 6 +++--- mm/util.c | 20 ++++++++++---------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 380328930d6c..46cee44c0c68 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1586,17 +1586,25 @@ void page_address_init(void); extern void *page_rmapping(struct page *page); extern struct anon_vma *page_anon_vma(struct page *page); -extern struct address_space *page_mapping(struct page *page); +struct address_space *folio_mapping(struct folio *); +struct address_space *__folio_file_mapping(struct folio *); -extern struct address_space *__page_file_mapping(struct page *); +static inline struct address_space *page_mapping(struct page *page) +{ + return folio_mapping(page_folio(page)); +} -static inline -struct address_space *page_file_mapping(struct page *page) +static inline struct address_space *folio_file_mapping(struct folio *folio) { - if (unlikely(PageSwapCache(page))) - return __page_file_mapping(page); + if (unlikely(FolioSwapCache(folio))) + return __folio_file_mapping(folio); - return page->mapping; + return folio->page.mapping; +} + +static inline struct address_space *page_file_mapping(struct page *page) +{ + return folio_file_mapping(page_folio(page)); } extern pgoff_t __page_file_index(struct page *page); @@ -1613,7 +1621,6 @@ static inline pgoff_t page_index(struct page *page) } bool page_mapped(struct page *page); -struct address_space *page_mapping(struct page *page); struct address_space *page_mapping_file(struct page *page); /* diff --git a/mm/swapfile.c b/mm/swapfile.c index 9fffc5af29d1..ddb734fccfc3 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3551,11 +3551,11 @@ struct swap_info_struct *page_swap_info(struct page *page) /* * out-of-line __page_file_ methods to avoid include hell. */ -struct address_space *__page_file_mapping(struct page *page) +struct address_space *__folio_file_mapping(struct folio *folio) { - return page_swap_info(page)->swap_file->f_mapping; + return page_swap_info(&folio->page)->swap_file->f_mapping; } -EXPORT_SYMBOL_GPL(__page_file_mapping); +EXPORT_SYMBOL_GPL(__folio_file_mapping); pgoff_t __page_file_index(struct page *page) { diff --git a/mm/util.c b/mm/util.c index c37e24d5fa43..c052c39b9f1c 100644 --- a/mm/util.c +++ b/mm/util.c @@ -686,39 +686,39 @@ struct anon_vma *page_anon_vma(struct page *page) return __page_rmapping(page); } -struct address_space *page_mapping(struct page *page) +struct address_space *folio_mapping(struct folio *folio) { struct address_space *mapping; - page = compound_head(page); - /* This happens if someone calls flush_dcache_page on slab page */ - if (unlikely(PageSlab(page))) + if (unlikely(FolioSlab(folio))) return NULL; - if (unlikely(PageSwapCache(page))) { + if (unlikely(FolioSwapCache(folio))) { swp_entry_t entry; - entry.val = page_private(page); + entry.val = folio_private(folio); return swap_address_space(entry); } - mapping = page->mapping; + mapping = folio->page.mapping; if ((unsigned long)mapping & PAGE_MAPPING_ANON) return NULL; return (void *)((unsigned long)mapping & ~PAGE_MAPPING_FLAGS); } -EXPORT_SYMBOL(page_mapping); +EXPORT_SYMBOL(folio_mapping); /* * For file cache pages, return the address_space, otherwise return NULL */ struct address_space *page_mapping_file(struct page *page) { - if (unlikely(PageSwapCache(page))) + struct folio *folio = page_folio(page); + + if (unlikely(FolioSwapCache(folio))) return NULL; - return page_mapping(page); + return folio_mapping(folio); } /* Slow path of page_mapcount() for compound pages */