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.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 91EE5C4363D for ; Wed, 21 Oct 2020 04:19:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ACC0D22242 for ; Wed, 21 Oct 2020 04:19:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W93uJsRh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ACC0D22242 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7F33D6B005C; Wed, 21 Oct 2020 00:19:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A2DE6B0062; Wed, 21 Oct 2020 00:19:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6920A6B0068; Wed, 21 Oct 2020 00:19:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0030.hostedemail.com [216.40.44.30]) by kanga.kvack.org (Postfix) with ESMTP id 3BD386B005C for ; Wed, 21 Oct 2020 00:19:32 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C5B9D181AEF00 for ; Wed, 21 Oct 2020 04:19:31 +0000 (UTC) X-FDA: 77394628542.18.toad57_0d0372527245 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id A91A61027DDF2 for ; Wed, 21 Oct 2020 04:19:31 +0000 (UTC) X-HE-Tag: toad57_0d0372527245 X-Filterd-Recvd-Size: 5624 Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Wed, 21 Oct 2020 04:19:31 +0000 (UTC) Received: by mail-qk1-f196.google.com with SMTP id k9so1121848qki.6 for ; Tue, 20 Oct 2020 21:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fltLg7p8olmPSrPebFnn/kjNBcZ60UXPyDG5Tj6QA30=; b=W93uJsRhYuAW0NaI2zLhIzGo9PXTH81OF+Q9aA9L9P/S4em4WNWQNaN1FOh05AveMs 0R7IqXXCc1uVg2lsqjts09eFuwQnC67d8gmv0bPjHd3nPl85DgQnfcq70SMDjnPZ77mt jB3l5VoQ0G1P7hT7nPgjapPhACPZy11RnFW/QYT25jT2BrriTOVUKbH7DtuNJY5sTl+l nAj8XfuMzJxRqM1n8zKFyYUU2k6Tg6G8+M64SWy+9PKQWSwNs9IqCkyAei0VPZ4mu+1k 3Ky2yvZMICDlE6qr5RAJxSt97jJGgHhqvavJMoyMerdGfWHtLkvAwO3X/3VokBMLasg2 8q3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fltLg7p8olmPSrPebFnn/kjNBcZ60UXPyDG5Tj6QA30=; b=rMc5wdk/PZPc0P3QvUkUqBL9jgEQoAcSxMcjj9BjmuaXMbuav5DLxNcxlgpLrBKrlG D6tXP+ifTd5n7kMr49A4U3rzMjmBQa56zoPlVu6MYIM/we0rYJGrTfzPlABA8keu95z4 afMAakLyfVol3/frT+QObVWyhYtdqqAAJAdgX0A70doK5q983oc1QLLmN7DO/khW1Cm5 8rru6w9sKxE0xSe2dLDUvh3w6NO4fOeno9BqyLIi2YC/ZbkSbvGYvZOrd51vOjoLacD5 L9nB0/JSFYLILf9uYXZvu1EcXoVNgg+97yd5aq8FK42RvqaDcaMy5omkeSUbJ1sqfyz6 MPMw== X-Gm-Message-State: AOAM533/TiOa+TBxs4wiqBGrOh0N/q+6uFJ1U8YY6AGg7arSHJAsAE0S ppvN+s8Ujrd+IDiPfPMy1w== X-Google-Smtp-Source: ABdhPJxu7uh8w0wzFCloFLtLURpSS/Y1T/f7OHAtmmG38JlQTLpwVlYG2wfdrEX/aQHHWqUMBVQpKA== X-Received: by 2002:a37:67d8:: with SMTP id b207mr1526065qkc.174.1603253970629; Tue, 20 Oct 2020 21:19:30 -0700 (PDT) Received: from zaphod.evilpiepirate.org ([2601:19b:c500:a1:d1eb:cfce:9b0b:f9e0]) by smtp.gmail.com with ESMTPSA id n57sm578781qtf.52.2020.10.20.21.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Oct 2020 21:19:29 -0700 (PDT) Date: Wed, 21 Oct 2020 00:19:26 -0400 From: Kent Overstreet To: Matthew Wilcox Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, David Howells Subject: Re: [RFC] find_get_heads_contig Message-ID: <20201021041926.GA2597465@zaphod.evilpiepirate.org> References: <20201021012630.GG20115@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201021012630.GG20115@casper.infradead.org> 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: On Wed, Oct 21, 2020 at 02:26:30AM +0100, Matthew Wilcox wrote: > 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? Perfect, looks like exactly what we need - at some point I can change my vectorized pagecache stuff to use 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