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=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,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 08D62C433E2 for ; Thu, 10 Sep 2020 18:33:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7C7DF2080A for ; Thu, 10 Sep 2020 18:33:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BA9fXgzR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C7DF2080A 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 0F9C2900004; Thu, 10 Sep 2020 14:33:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0ABFA900002; Thu, 10 Sep 2020 14:33:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB23F900004; Thu, 10 Sep 2020 14:33:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id D1EED900002 for ; Thu, 10 Sep 2020 14:33:33 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 9FDA62476 for ; Thu, 10 Sep 2020 18:33:33 +0000 (UTC) X-FDA: 77247999906.25.fish99_5e0a059270e8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 65A5E1804E3A1 for ; Thu, 10 Sep 2020 18:33:33 +0000 (UTC) X-HE-Tag: fish99_5e0a059270e8 X-Filterd-Recvd-Size: 6002 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Sep 2020 18:33:32 +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=iUQLI4IkKhxmuIt5IQ92wfzZNFFmlqJHR5Mjgm7VnoA=; b=BA9fXgzR2ABZNFehO2jFdouN4b iatHnAm3X02YEDHBkg5V7kpzguGHl7vVWOOyszawHEkfApPAg1CVxxTQddRDUlB2DXtjsIPebRC0H +RSun9FiyBLil2BxMQTak8vbiwPaq02YTFwtoCHfj3fHL9EVOeHaJFkRRGNvBNMkGf76k2ekSGR8w q+6P8md5vudIkfhhBaRydUlngTJBq7gdHAIuO2S8Wb8c5A7bhSSLnSPs5HtyvAHjness9QKziYg+o 4Su2kksd56Fv0Rz0NaXC5CIngX3owPQbylFWO6K+Gq+ygUkjYDxRzGzapwO8XsA13+zclT89KPb0o e7QRA3hQ==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kGRNq-0005Ge-AD; Thu, 10 Sep 2020 18:33:22 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Andrew Morton , Hugh Dickins , William Kucharski , Jani Nikula , Alexey Dobriyan , Johannes Weiner , Chris Wilson , Matthew Auld , Huang Ying , intel-gfx@lists.freedesktop.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 8/8] mm: Add find_lock_head Date: Thu, 10 Sep 2020 19:33:18 +0100 Message-Id: <20200910183318.20139-9-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200910183318.20139-1-willy@infradead.org> References: <20200910183318.20139-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 65A5E1804E3A1 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: Add a new FGP_HEAD flag which avoids calling find_subpage() and add a convenience wrapper for it. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 32 ++++++++++++++++++++++++++------ mm/filemap.c | 9 ++++++--- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index f374618b2c93..4e52a3ff92fb 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -278,6 +278,7 @@ pgoff_t page_cache_prev_miss(struct address_space *ma= pping, #define FGP_NOFS 0x00000010 #define FGP_NOWAIT 0x00000020 #define FGP_FOR_MMAP 0x00000040 +#define FGP_HEAD 0x00000080 =20 struct page *pagecache_get_page(struct address_space *mapping, pgoff_t o= ffset, int fgp_flags, gfp_t cache_gfp_mask); @@ -309,18 +310,37 @@ static inline struct page *find_get_page_flags(stru= ct address_space *mapping, * @mapping: the address_space to search * @offset: the page index * - * Looks up the page cache slot at @mapping & @offset. If there is a + * Looks up the page cache entry at @mapping & @offset. If there is a * page cache page, it is returned locked and with an increased * refcount. * - * Otherwise, %NULL is returned. - * - * find_lock_page() may sleep. + * Context: May sleep. + * Return: A struct page or %NULL if there is no page in the cache for t= his + * index. */ static inline struct page *find_lock_page(struct address_space *mapping, - pgoff_t offset) + pgoff_t index) +{ + return pagecache_get_page(mapping, index, FGP_LOCK, 0); +} + +/** + * find_lock_head - Locate, pin and lock a pagecache page. + * @mapping: The address_space to search. + * @offset: The page index. + * + * Looks up the page cache entry at @mapping & @offset. 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, offset, FGP_LOCK, 0); + return pagecache_get_page(mapping, index, FGP_LOCK | FGP_HEAD, 0); } =20 /** diff --git a/mm/filemap.c b/mm/filemap.c index 453535170b8d..e429e02317ef 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1659,6 +1659,8 @@ struct page *find_lock_entry(struct address_space *= mapping, pgoff_t index) * * * %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_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. * The page is returned locked and with an increased refcount. @@ -1687,7 +1689,6 @@ struct page *pagecache_get_page(struct address_spac= e *mapping, pgoff_t index, page =3D NULL; if (!page) goto no_page; - page =3D find_subpage(page, index); =20 if (fgp_flags & FGP_LOCK) { if (fgp_flags & FGP_NOWAIT) { @@ -1700,12 +1701,12 @@ struct page *pagecache_get_page(struct address_sp= ace *mapping, pgoff_t index, } =20 /* Has the page been truncated? */ - if (unlikely(compound_head(page)->mapping !=3D mapping)) { + if (unlikely(page->mapping !=3D mapping)) { unlock_page(page); put_page(page); goto repeat; } - VM_BUG_ON_PAGE(page->index !=3D index, page); + VM_BUG_ON_PAGE(!thp_contains(page, index), page); } =20 if (fgp_flags & FGP_ACCESSED) @@ -1715,6 +1716,8 @@ struct page *pagecache_get_page(struct address_spac= e *mapping, pgoff_t index, if (page_is_idle(page)) clear_page_idle(page); } + if (!(fgp_flags & FGP_HEAD)) + page =3D find_subpage(page, index); =20 no_page: if (!page && (fgp_flags & FGP_CREAT)) { --=20 2.28.0