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.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,USER_AGENT_GIT autolearn=unavailable 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 4DAAAC433DB for ; Fri, 5 Mar 2021 04:22:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D85766500C for ; Fri, 5 Mar 2021 04:22:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D85766500C 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 6F94D6B0007; Thu, 4 Mar 2021 23:22:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D0C96B000C; Thu, 4 Mar 2021 23:22:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5728A6B000D; Thu, 4 Mar 2021 23:22:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0112.hostedemail.com [216.40.44.112]) by kanga.kvack.org (Postfix) with ESMTP id 3EAAC6B0007 for ; Thu, 4 Mar 2021 23:22:52 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 05FA98249980 for ; Fri, 5 Mar 2021 04:22:52 +0000 (UTC) X-FDA: 77884524984.09.C2DAE4E Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id 7652C132 for ; Fri, 5 Mar 2021 04:22:50 +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=PJMDVzBGNFdjhf6t/3/5VE6jTBhydf1jdb3Lpx2OhtA=; b=JTROAvijqYfvnr+BFahul4HXq3 EsnBBVkU4zMVXGycqIDB1bN6gcx+NFJcCRG2tFUqDOUIGo9JzySGOAvIfGwvHTS9P5BKRYfzrr8L7 93QGCGwRvlxLquF2WmwTsXBdnWcA5523Bg0S242U4kX3YCiH53YETO/F5jlpu7dahaXjdO74twtDX vn92MZW+u0J0LAgZjM1yW176QThhrmWi3cTouEs+431OotR76T+VvF2ZWqC7pAZ5++zIArrqwIOVI M9YWGJVjbKB1eJPMqSIg52bnOnxolawt+NZqjIOsY+YCBKMvY4DaHa/PUfmlbijIR/WAYKnuKhUg4 46nVAI2w==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lI1y1-00A3fp-Al; Fri, 05 Mar 2021 04:21:50 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 10/25] mm/util: Add folio_mapping and folio_file_mapping Date: Fri, 5 Mar 2021 04:18:46 +0000 Message-Id: <20210305041901.2396498-11-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210305041901.2396498-1-willy@infradead.org> References: <20210305041901.2396498-1-willy@infradead.org> MIME-Version: 1.0 X-Stat-Signature: ky4qt9bo6ssqem7pge8bgh3hegf85mi1 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7652C132 Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614918170-118816 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: These are the folio equivalent of page_mapping() and page_file_mapping(). Add an out-of-line page_mapping() wrapper around folio_mapping() in order to prevent the page_folio() call from bloating every caller of page_mapping(). Adjust page_file_mapping() and page_mapping_file() to use folios internally. This ends up saving 102 bytes of text overall. folio_mapping() is 45 bytes shorter than page_mapping() was, but the compiler chooses to inline folio_mapping() into page_mapping_file(), for a net increase of 69 bytes in the core. This is made up for by a few bytes less in dozens of nfs functions (which call page_file_mapping()). The small amount of difference appears to be a slight change in gcc's register allocation decisions, which allow: 48 8b 56 08 mov 0x8(%rsi),%rdx 48 8d 42 ff lea -0x1(%rdx),%rax 83 e2 01 and $0x1,%edx 48 0f 44 c6 cmove %rsi,%rax to become: 48 8b 46 08 mov 0x8(%rsi),%rax 48 8d 78 ff lea -0x1(%rax),%rdi a8 01 test $0x1,%al 48 0f 44 fe cmove %rsi,%rdi Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/mm.h | 14 -------------- include/linux/pagemap.h | 17 +++++++++++++++++ mm/Makefile | 2 +- mm/folio-compat.c | 13 +++++++++++++ mm/swapfile.c | 6 +++--- mm/util.c | 20 ++++++++++---------- 6 files changed, 44 insertions(+), 28 deletions(-) create mode 100644 mm/folio-compat.c diff --git a/include/linux/mm.h b/include/linux/mm.h index 4595955805f8..9199b59ee8da 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1603,19 +1603,6 @@ void page_address_init(void); =20 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); - -extern struct address_space *__page_file_mapping(struct page *); - -static inline -struct address_space *page_file_mapping(struct page *page) -{ - if (unlikely(PageSwapCache(page))) - return __page_file_mapping(page); - - return page->mapping; -} - extern pgoff_t __page_file_index(struct page *page); =20 /* @@ -1630,7 +1617,6 @@ static inline pgoff_t page_index(struct page *page) } =20 bool page_mapped(struct page *page); -struct address_space *page_mapping(struct page *page); struct address_space *page_mapping_file(struct page *page); =20 /* diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 5094b50f7680..5a2c0764d7c0 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -157,6 +157,23 @@ static inline void filemap_nr_thps_dec(struct addres= s_space *mapping) =20 void release_pages(struct page **pages, int nr); =20 +struct address_space *page_mapping(struct page *); +struct address_space *folio_mapping(struct folio *); +struct address_space *__folio_file_mapping(struct folio *); + +static inline struct address_space *folio_file_mapping(struct folio *fol= io) +{ + if (unlikely(FolioSwapCache(folio))) + return __folio_file_mapping(folio); + + return folio->page.mapping; +} + +static inline struct address_space *page_file_mapping(struct page *page) +{ + return folio_file_mapping(page_folio(page)); +} + /* * speculatively take a reference to a page. * If the page is free (_refcount =3D=3D 0), then _refcount is untouched= , and 0 diff --git a/mm/Makefile b/mm/Makefile index 72227b24a616..ceb0089efd29 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -46,7 +46,7 @@ mmu-$(CONFIG_MMU) +=3D process_vm_access.o endif =20 obj-y :=3D filemap.o mempool.o oom_kill.o fadvise.o \ - maccess.o page-writeback.o \ + maccess.o page-writeback.o folio-compat.o \ readahead.o swap.o truncate.o vmscan.o shmem.o \ util.o mmzone.o vmstat.o backing-dev.o \ mm_init.o percpu.o slab_common.o \ diff --git a/mm/folio-compat.c b/mm/folio-compat.c new file mode 100644 index 000000000000..5e107aa30a62 --- /dev/null +++ b/mm/folio-compat.c @@ -0,0 +1,13 @@ +/* + * Compatibility functions which bloat the callers too much to make inli= ne. + * All of the callers of these functions should be converted to use foli= os + * eventually. + */ + +#include + +struct address_space *page_mapping(struct page *page) +{ + return folio_mapping(page_folio(page)); +} +EXPORT_SYMBOL(page_mapping); diff --git a/mm/swapfile.c b/mm/swapfile.c index 084a5b9a18e5..b80af7537d9e 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3535,11 +3535,11 @@ struct swap_info_struct *page_swap_info(struct pa= ge *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); =20 pgoff_t __page_file_index(struct page *page) { diff --git a/mm/util.c b/mm/util.c index 54870226cea6..9ab72cfa4aa1 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); } =20 -struct address_space *page_mapping(struct page *page) +struct address_space *folio_mapping(struct folio *folio) { struct address_space *mapping; =20 - page =3D compound_head(page); - /* This happens if someone calls flush_dcache_page on slab page */ - if (unlikely(PageSlab(page))) + if (unlikely(FolioSlab(folio))) return NULL; =20 - if (unlikely(PageSwapCache(page))) { + if (unlikely(FolioSwapCache(folio))) { swp_entry_t entry; =20 - entry.val =3D page_private(page); + entry.val =3D folio_private(folio); return swap_address_space(entry); } =20 - mapping =3D page->mapping; + mapping =3D folio->page.mapping; if ((unsigned long)mapping & PAGE_MAPPING_ANON) return NULL; =20 return (void *)((unsigned long)mapping & ~PAGE_MAPPING_FLAGS); } -EXPORT_SYMBOL(page_mapping); +EXPORT_SYMBOL(folio_mapping); =20 /* * 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 =3D page_folio(page); + + if (unlikely(FolioSwapCache(folio))) return NULL; - return page_mapping(page); + return folio_mapping(folio); } =20 /* Slow path of page_mapcount() for compound pages */ --=20 2.30.0