From patchwork Wed Oct 21 01:26:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 11848155 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 4565E61C for ; Wed, 21 Oct 2020 01:26:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 526762098B for ; Wed, 21 Oct 2020 01:26:36 +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 526762098B 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) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 01AF66B0062; Tue, 20 Oct 2020 21:26:34 -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 E4BA56B0068; Tue, 20 Oct 2020 21:26:34 -0400 (EDT) X-Original-To: linux-mm@kvack.org 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-Spam-Summary: 1,0,0,67133ba5174d1dd9,d41d8cd98f00b204,willy@infradead.org,,RULES_HIT:41:355:379:973:988:989:1260:1277:1312:1313:1314:1345:1437:1516:1518:1519:1534:1542:1593:1594:1595:1596:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:2898:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:5007:6119:6261:6653:7875:7903:10004:10400:11026:11658:11914:12043:12114:12296:12297:12438:12555:13439:13618:13895:14096:14097:14721:21080:21324:21433:21627:21990:30029:30034:30054:30070:30090,0,RBL:90.155.50.34:@infradead.org:.lbl8.mailshell.net-64.201.201.201 62.8.15.100;04yriuxzga9hme74gcffrq48pypibophw4h835r1gcs8p7oczy8sbz8q9a7ssb1.b3ic79mbxnit49qpm34tj3yuzzoi1g6797pjguifiqy4ubfy3axp4dzi5ay6xs5.r-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:24,LUA_SUMMARY:none 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-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? Reviewed-by: Kent Overstreet 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