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=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 82591C1B08C for ; Thu, 15 Jul 2021 05:19:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C87916100A for ; Thu, 15 Jul 2021 05:19:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C87916100A 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 26C9D8D0085; Thu, 15 Jul 2021 01:19:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2437F8D0065; Thu, 15 Jul 2021 01:19:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E46A8D0085; Thu, 15 Jul 2021 01:19:53 -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 DF2A68D0065 for ; Thu, 15 Jul 2021 01:19:52 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id CF9A522BF7 for ; Thu, 15 Jul 2021 05:19:51 +0000 (UTC) X-FDA: 78363670182.25.F195F79 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf24.hostedemail.com (Postfix) with ESMTP id 859E9B0000A7 for ; Thu, 15 Jul 2021 05:19:51 +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=yjcEYbnvFGiVk+7puh1H29FSvNpW0YK7ifZztKTx7lg=; b=FQxNhg7Wn0LNyLYKbKRdKOfilp /AW4j46ohSUsNlXkocsnQLLGMkm7l6LoNe3yq5kbSweuE++WQ/HK4mTx+1kyQFjOJMp9Br8KnDdJT hQ+adeSK5OgiS5rRHfjqBdNzyidQjo9gQEQUu5KL6B/Uv3uxnjedVKDBpiSauJau7lvlRxeBj/Vao 4RLsF52P7NIcwyQOLEox4mhmZHBViypmXPnvRR+4aadcNDLRANtRll2QpurnfUqNTumfeZN6mSkoT 2f4jcmh9/xejER8ZFwtHaqp7fjAKafdVPYNzd82XV7whgJ6Qd/ZS3dhpOc4W2JTtPcZglDSULvEKk ZqsK5DXQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3tlM-0030h0-7z; Thu, 15 Jul 2021 05:18:38 +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 v14 126/138] mm/filemap: Return only head pages from find_get_entries Date: Thu, 15 Jul 2021 04:36:52 +0100 Message-Id: <20210715033704.692967-127-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715033704.692967-1-willy@infradead.org> References: <20210715033704.692967-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 859E9B0000A7 X-Stat-Signature: wrby8zmr1orq3arkc9n44zyfhjpb4bz4 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=FQxNhg7W; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-HE-Tag: 1626326391-393235 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: 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 842d130fd6d3..bf8e978a48f2 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)); } =20 -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 *st= art, pgoff_t end, unsigned int nr_pages, struct page **pages); diff --git a/mm/filemap.c b/mm/filemap.c index 1c0c2663c57d..20434d7bdad8 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 consecuti= ve + * 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 hand= le - * the compound page as a whole, and then skip its extent, than repeated= ly - * 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 =3D 0; - unsigned nr_entries =3D PAGEVEC_SIZE; + struct folio *folio; =20 rcu_read_lock(); - while ((page =3D &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 =3D find_subpage(page, xas.xa_index); - nr_entries =3D ret + 1; - } - - indices[ret] =3D xas.xa_index; - pvec->pages[ret] =3D page; - if (++ret =3D=3D nr_entries) + while ((folio =3D find_get_entry(&xas, end, XA_PRESENT)) !=3D NULL) { + indices[pvec->nr] =3D xas.xa_index; + if (!pagevec_add(pvec, &folio->page)) break; } rcu_read_unlock(); =20 - pvec->nr =3D ret; - return ret; + return pagevec_count(pvec); } =20 /** @@ -2016,8 +1996,8 @@ unsigned find_get_entries(struct address_space *map= ping, pgoff_t start, * not returned. * * The entries have ascending indexes. The indices may not be consecuti= ve - * due to not-present entries, THP pages, pages which could not be locke= d - * 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 3c0c807eddc6..3e32064df18d 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -70,6 +70,8 @@ static inline void force_page_cache_readahead(struct ad= dress_space *mapping, =20 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); =20 /** --=20 2.30.2