From patchwork Mon Oct 26 04:14:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 11855649 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A04B561C for ; Mon, 26 Oct 2020 04:14:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4745A2073A for ; Mon, 26 Oct 2020 04:14:30 +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="YcfZjdNN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4745A2073A 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 724956B006E; Mon, 26 Oct 2020 00:14:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5C3196B0070; Mon, 26 Oct 2020 00:14:20 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 483846B0071; Mon, 26 Oct 2020 00:14:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0228.hostedemail.com [216.40.44.228]) by kanga.kvack.org (Postfix) with ESMTP id 109BD6B006E for ; Mon, 26 Oct 2020 00:14:20 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A474C180AD815 for ; Mon, 26 Oct 2020 04:14:19 +0000 (UTC) X-FDA: 77412759438.17.cook88_320218027270 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 8BF25180D0180 for ; Mon, 26 Oct 2020 04:14:19 +0000 (UTC) X-Spam-Summary: 1,0,0,78760c361c786138,d41d8cd98f00b204,willy@infradead.org,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1544:1605:1711:1730:1747:1777:1792:2393:2553:2559:2562:2689:2898:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3874:4031:4117:4321:4605:5007:6119:6261:6653:8957:9592:10004:11026:11658:11914:12043:12296:12297:12438:12555:12683:12895:13894:14096:14181:14394:14721:21063:21080:21324:21451:21627:21740:21990:30034:30054:30064:30070:30090,0,RBL:90.155.50.34:@infradead.org:.lbl8.mailshell.net-64.201.201.201 62.8.15.100;04ygxaboq3ht7rqqzzwe5aqdmy3wzoc3yb3yh3omj9h6s5axy35bawkk5yteux8.j437n7xs1dgsmbhcq9qnngbardm67ca86s99ax8rs4yoiy83jfpkkors3t87pmx.o-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:144,LUA_SUMMARY:none X-HE-Tag: cook88_320218027270 X-Filterd-Recvd-Size: 6503 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Oct 2020 04:14:16 +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=kpUczdeKYi1+38xZwHEXixHpdmrDrWMrdTwGd2Ba8x0=; b=YcfZjdNN1aDe/LcHqu+I3/RUD7 ZB/2qcxmUEd0z/Z+O9YaxXNnWUummKleEY3HmDXPF9Z9OOL/EfnAFqBUH5T9hRUaOQTScouC78Aq3 xw8jSrszyqXqn+fwCOXxEUMcOyXHpzE8nFgzbwL/2K7eVO4HPakPOm+rnQy6p2csVx+4pPDsObLRm OZKyyMBUt4CJHQbpNVhyAGYa00xjzg9iaQ0UP/sx8iI2v8g0Ng5KC4SMhk37oLj49g8y97KRZo4Y9 keDM8o968FrKmDot2d98jRh6+ozGlQarsJz4VWaUjUssDqRLKqQCDReXLZw7XEU3VvvmQOfpsEwMJ prUEKttw==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kWttd-0006as-1o; Mon, 26 Oct 2020 04:14:13 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, Andrew Morton , Hugh Dickins , Johannes Weiner , Yang Shi , Dave Chinner , linux-kernel@vger.kernel.org, Jan Kara , William Kucharski Subject: [PATCH v3 12/12] mm/filemap: Return only head pages from find_get_entries Date: Mon, 26 Oct 2020 04:14:08 +0000 Message-Id: <20201026041408.25230-13-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201026041408.25230-1-willy@infradead.org> References: <20201026041408.25230-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: All callers now expect head (and base) pages, and can handle multiple head pages in a single batch, so make find_get_entries() behave that way. Also take the opportunity to make it use the pagevec infrastructure instead of open-coding how pvecs behave. This has the side-effect of being able to append to a pagevec with existing contents, although we don't make use of that functionality anywhere yet. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Jan Kara Reviewed-by: William Kucharski --- include/linux/pagemap.h | 2 -- mm/filemap.c | 36 ++++++++---------------------------- mm/internal.h | 2 ++ 3 files changed, 10 insertions(+), 30 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index f0bbe29de732..8938c64f418b 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -449,8 +449,6 @@ static inline struct page *find_subpage(struct page *head, pgoff_t index) return head + (index & (thp_nr_pages(head) - 1)); } -unsigned find_get_entries(struct address_space *mapping, pgoff_t start, - pgoff_t end, struct pagevec *pvec, pgoff_t *indices); unsigned find_get_pages_range(struct address_space *mapping, pgoff_t *start, pgoff_t end, unsigned int nr_pages, struct page **pages); diff --git a/mm/filemap.c b/mm/filemap.c index e0fa943011d8..a117718ec1a8 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1905,49 +1905,29 @@ static inline struct page *xas_find_get_entry(struct xa_state *xas, * the mapping. The entries are placed in @pvec. find_get_entries() * takes a reference on any actual pages it returns. * - * The search returns a group of mapping-contiguous page cache entries - * with ascending indexes. There may be holes in the indices due to - * not-present pages. + * The entries have ascending indexes. The indices may not be consecutive + * due to not-present entries or THPs. * * Any shadow entries of evicted pages, or swap entries from * shmem/tmpfs, are included in the returned array. * - * If it finds a Transparent Huge Page, head or tail, find_get_entries() - * stops at that page: the caller is likely to have a better way to handle - * the compound page as a whole, and then skip its extent, than repeatedly - * calling find_get_entries() to return all its tails. - * - * Return: the number of pages and shadow entries which were found. + * Return: The number of entries which were found. */ unsigned find_get_entries(struct address_space *mapping, pgoff_t start, pgoff_t end, struct pagevec *pvec, pgoff_t *indices) { XA_STATE(xas, &mapping->i_pages, start); struct page *page; - unsigned int ret = 0; - unsigned nr_entries = PAGEVEC_SIZE; rcu_read_lock(); while ((page = xas_find_get_entry(&xas, end, XA_PRESENT))) { - /* - * Terminate early on finding a THP, to allow the caller to - * handle it all at once; but continue if this is hugetlbfs. - */ - if (!xa_is_value(page) && PageTransHuge(page) && - !PageHuge(page)) { - page = find_subpage(page, xas.xa_index); - nr_entries = ret + 1; - } - - indices[ret] = xas.xa_index; - pvec->pages[ret] = page; - if (++ret == nr_entries) + indices[pvec->nr] = xas.xa_index; + if (!pagevec_add(pvec, page)) break; } rcu_read_unlock(); - pvec->nr = ret; - return ret; + return pagevec_count(pvec); } /** @@ -1966,8 +1946,8 @@ unsigned find_get_entries(struct address_space *mapping, pgoff_t start, * not returned. * * The entries have ascending indexes. The indices may not be consecutive - * due to not-present entries, THP pages, pages which could not be locked - * or pages under writeback. + * due to not-present entries, THPs, pages which could not be locked or + * pages under writeback. * * Return: The number of entries which were found. */ diff --git a/mm/internal.h b/mm/internal.h index 194572e1ab49..5aca7d7bc57c 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -62,6 +62,8 @@ static inline void force_page_cache_readahead(struct address_space *mapping, struct page *find_get_entry(struct address_space *mapping, pgoff_t index); struct page *find_lock_entry(struct address_space *mapping, pgoff_t index); +unsigned find_get_entries(struct address_space *mapping, pgoff_t start, + pgoff_t end, struct pagevec *pvec, pgoff_t *indices); unsigned find_lock_entries(struct address_space *mapping, pgoff_t start, pgoff_t end, struct pagevec *pvec, pgoff_t *indices);