Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2645298pxv; Sun, 11 Jul 2021 21:18:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwICjKbA5brXDuEsOdyX7VrB6vmXsHHpeOdjKAD8dnzbI+T1U53n+qzcpTMBiuEOyRySwGf X-Received: by 2002:a17:906:b851:: with SMTP id ga17mr51118498ejb.86.1626063507453; Sun, 11 Jul 2021 21:18:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626063507; cv=none; d=google.com; s=arc-20160816; b=coz+k10YXRrDG4eXkDdxuSBNoAvAo2v7tWABhBU+5mA8Pka2lwx9H5lC94Llj+9NUG A4PkHaBml60Nnq2JvsO8e97FaZ//7MJPUSL+xtkdtRk/ASmxxrj1hr41sgzpCE4eL+7t lqPeJj4MAXkgEkAhyBi3JhQCQgHzeuUAbQ336JG1HOtIa5xXf2UCdZ5fng096isByhQx Rpc0jvfHAM3ONgOr1hnsYBzfw/zqOsfEF+fi+LmYeg7PNJzagg2binjyGc/Pn2IWHNPG WIrhwsYb78R2KO2gPWmmEMhR3laqTbIGYxBYh7gzclzcLL8PvBGoOar78A4FSwAZpMRF ck6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zn0/iCwWsCo/2/euB0DWs9Af4dwcp6xc3SXNP5raYIY=; b=nRuPxCITNH388EtP6CZUVQDFYEaP99IJuiofsbm6T9uVaAQkj2aVdNiW74NKvOyrrJ JSlFi0V/Bvx8dHuuiiXUyPg6XHcDldeSL8J31mneAFY8zj+yvaw98JGkqDdS9S6DEkNu pbQq0V0pMp3dfrIDo1Ete936IpFbSbpjHZCsXAzMGiz2VxI3jJ3A5Pwhr6tWgTQiXapl /MF3Q/SSirFk1r81FifyLRKSaL5FIp03Mrj9GjumXaSfPwthuYI1HK1BBkOkBFxbY0zQ TxkaS+eohsY6B4WFZh8yfP1l/smCOkf/Zm+RdtdqfecEPXcuhVcXct99uAOoYPa/X4cr 5QCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=qvMszYn3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kg2si2665854ejc.306.2021.07.11.21.18.04; Sun, 11 Jul 2021 21:18:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=qvMszYn3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231840AbhGLEQ6 (ORCPT + 99 others); Mon, 12 Jul 2021 00:16:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229465AbhGLEQ5 (ORCPT ); Mon, 12 Jul 2021 00:16:57 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58CA3C0613DD; Sun, 11 Jul 2021 21:14:10 -0700 (PDT) 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=zn0/iCwWsCo/2/euB0DWs9Af4dwcp6xc3SXNP5raYIY=; b=qvMszYn3wWbvfWsbeO7YjzUbjU QQXVrLfH4G4kza1uEDQKjDnq56YCH513G8Ibp8fHquber0Ut2TBlLItaPwsByf88aGfbpjLplBuqN eRN30aTxmmIZUyA+Iw1EvWyF089ogJs65CktBSNt+TWbEztc68WlVkMF2Uh12/j584ttGPi+MbjWW fYvMm+kBm1sYdNvTEqF635GETvcua47Ge7wcPtoYymOJw53sYGi5/RYu59c3K9kJty69ShqTgNKn8 GGuv3vvpTXm0egUZOqgFk1TKZKFYV+bXdYjVHkGOdymKwoLVbYi6ZVPV0G8BLoWVvPhxaD95rechH 26zL3cKA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2nJH-00GrPq-3h; Mon, 12 Jul 2021 04:12:58 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Jan Kara , William Kucharski Subject: [PATCH v13 125/137] mm/filemap: Return only head pages from find_get_entries Date: Mon, 12 Jul 2021 04:06:49 +0100 Message-Id: <20210712030701.4000097-126-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712030701.4000097-1-willy@infradead.org> References: <20210712030701.4000097-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 40 ++++++++++------------------------------ mm/internal.h | 2 ++ 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index e7539da390d2..90935f231419 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -502,8 +502,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 82f985f61224..aaed0396db28 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1955,49 +1955,29 @@ static inline struct folio *find_get_entry(struct xa_state *xas, pgoff_t max, * 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; + struct folio *folio; rcu_read_lock(); - while ((page = &find_get_entry(&xas, end, XA_PRESENT)->page)) { - /* - * 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) + while ((folio = find_get_entry(&xas, end, XA_PRESENT)) != NULL) { + indices[pvec->nr] = xas.xa_index; + if (!pagevec_add(pvec, &folio->page)) break; } rcu_read_unlock(); - pvec->nr = ret; - return ret; + return pagevec_count(pvec); } /** @@ -2016,8 +1996,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 4730e9267bfc..65314d4380d0 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -70,6 +70,8 @@ static inline void force_page_cache_readahead(struct address_space *mapping, unsigned find_lock_entries(struct address_space *mapping, pgoff_t start, pgoff_t end, struct pagevec *pvec, pgoff_t *indices); +unsigned find_get_entries(struct address_space *mapping, pgoff_t start, + pgoff_t end, struct pagevec *pvec, pgoff_t *indices); bool truncate_inode_partial_page(struct page *page, loff_t start, loff_t end); /** -- 2.30.2