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=-6.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 B21C5C4363D for ; Wed, 21 Oct 2020 01:26:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 01C3D21D6C for ; Wed, 21 Oct 2020 01:26:35 +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="N/cyk/PK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 01C3D21D6C 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 06A1F6B005C; Tue, 20 Oct 2020 21:26:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 01AF66B0062; Tue, 20 Oct 2020 21:26:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4BA56B0068; Tue, 20 Oct 2020 21:26:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id B4CC66B005C for ; Tue, 20 Oct 2020 21:26:34 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 46F95824CD8A for ; Wed, 21 Oct 2020 01:26:34 +0000 (UTC) X-FDA: 77394192708.03.fear44_520411c27244 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id 2185528A4E8 for ; Wed, 21 Oct 2020 01:26:34 +0000 (UTC) X-HE-Tag: fear44_520411c27244 X-Filterd-Recvd-Size: 3761 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Wed, 21 Oct 2020 01:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=8+DsgjTXhuE0aBWL3ircZHfQncOPhdktt3A/RofKQJ4=; b=N/cyk/PKBEJ9YDV5WS8J3O6nJS 5T+zWf+JGQDwsxnLlnFWPHjZ71IKi6ZelvLj4UDtJDlXb0VJUZt4f3SyGsZFwQhpf3TNFu1t78uj8 UiJvsIuCg41UtWd1k8en3RizGjmUeep6Vs+K4VcRYucmoz+vmHBhXtxOE6mf1DiORy3NdQRxPGqLW e3HjnV4GTIk0GaK6Ph+Rdfs66Uzcm2zzb3ZaaGxf3l4BJDWyN40iQ5tOYvFqVcJK+nQJw3ok2LIrG p9n3nZ4C4by3QPABG+1UZK3waQKeGYA7wbXAj8CJy2BsV/ySmAACEPi4LvAgNt87kmqXFyesfX/jq m5hlYwxA==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kV2ta-00045B-LD; Wed, 21 Oct 2020 01:26:30 +0000 Date: Wed, 21 Oct 2020 02:26:30 +0100 From: Matthew Wilcox To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Cc: Kent Overstreet , David Howells Subject: [RFC] find_get_heads_contig Message-ID: <20201021012630.GG20115@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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: I was going to convert find_get_pages_contig() to only return head pages, but I want to change the API to take a pagevec like the other find_* functions have or will have. And it'd be nice if the name of the function reminded callers that it only returns head pages. So comments on this? diff --git a/mm/filemap.c b/mm/filemap.c index 31ba06409dfa..b7dd2523fe79 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2093,6 +2093,58 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index, } EXPORT_SYMBOL(find_get_pages_contig); +/** + * find_get_heads_contig - Return head pages for a contiguous byte range. + * @mapping: The address_space to search. + * @start: The starting page index. + * @end: The final page index (inclusive). + * @pvec: Where the resulting pages are placed. + * + * find_get_heads_contig() will return a batch of head pages from + * @mapping. Pages are returned with an incremented refcount. Only the + * head page of a THP is returned. In contrast to find_get_entries(), + * pages which are partially outside the range are returned. The head + * pages have ascending indices. The indices may not be consecutive, + * but the bytes represented by the pages are contiguous. If there is + * no page at @start, no pages will be returned. + * + * Return: The number of pages which were found. + */ +unsigned find_get_heads_contig(struct address_space *mapping, pgoff_t start, + pgoff_t end, struct pagevec *pvec) +{ + XA_STATE(xas, &mapping->i_pages, start); + struct page *page; + + rcu_read_lock(); + for (page = xas_load(&xas); page; page = xas_next(&xas)) { + if (xas.xa_index > end) + break; + if (xas_retry(&xas, page) || xa_is_sibling(page)) + continue; + if (xa_is_value(page)) + break; + + if (!page_cache_get_speculative(page)) + goto retry; + + /* Has the page moved or been split? */ + if (unlikely(page != xas_reload(&xas))) + goto put_page; + + if (!pagevec_add(pvec, page)) + break; + continue; +put_page: + put_page(page); +retry: + xas_reset(&xas); + } + rcu_read_unlock(); + return pagevec_count(pvec); +} +EXPORT_SYMBOL(find_get_heads_contig); + /** * find_get_pages_range_tag - Find and return head pages matching @tag. * @mapping: the address_space to search