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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS 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 BA91FC433E0 for ; Sat, 13 Mar 2021 20:37:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5C24864EC4 for ; Sat, 13 Mar 2021 20:37:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C24864EC4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0020C6B0071; Sat, 13 Mar 2021 15:37:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F1A546B0072; Sat, 13 Mar 2021 15:37:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E09D46B0073; Sat, 13 Mar 2021 15:37:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0103.hostedemail.com [216.40.44.103]) by kanga.kvack.org (Postfix) with ESMTP id C4F1E6B0071 for ; Sat, 13 Mar 2021 15:37:19 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 82E64824999B for ; Sat, 13 Mar 2021 20:37:19 +0000 (UTC) X-FDA: 77916010998.23.2F0608C Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf10.hostedemail.com (Postfix) with ESMTP id 21D384000347 for ; Sat, 13 Mar 2021 20:37:19 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id B8BB664ECD; Sat, 13 Mar 2021 20:37:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1615667836; bh=a+bgrH0JujcMhS3lCPeeuyib36jjyyn038EZGI2s/IM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=C1W0+23kv6UgGDUQ1g2wVzwyPM5CpFtnBx7E7McqCO3FFHqn4PAVL0En16axkIBKL KauS+uwBBgVJQN+TtTQLqjkGE711ieFcpHCShJJkvAgSAGcWiILSnQbXuMfVWwcyUJ ABzaE96msq+1OaGpH4JjpHn4UsTbR8G7iieio75k= Date: Sat, 13 Mar 2021 12:37:16 -0800 From: Andrew Morton To: "Matthew Wilcox (Oracle)" Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v4 09/25] mm: Add folio_index, folio_page and folio_contains Message-Id: <20210313123716.a4f9403e9f6ebbd719dac2a8@linux-foundation.org> In-Reply-To: <20210305041901.2396498-10-willy@infradead.org> References: <20210305041901.2396498-1-willy@infradead.org> <20210305041901.2396498-10-willy@infradead.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 21D384000347 X-Stat-Signature: k5ohr75gbug6sbd5y6wafhk5cer41tgp Received-SPF: none (linux-foundation.org>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=mail.kernel.org; client-ip=198.145.29.99 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615667839-663232 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 Fri, 5 Mar 2021 04:18:45 +0000 "Matthew Wilcox (Oracle)" wrote: > folio_index() is the equivalent of page_index() for folios. folio_page() > finds the page in a folio for a page cache index. folio_contains() > tells you whether a folio contains a particular page cache index. > copy-paste changelog into each function's covering comment? > --- > include/linux/pagemap.h | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h > index f07c03da83f6..5094b50f7680 100644 > --- a/include/linux/pagemap.h > +++ b/include/linux/pagemap.h > @@ -447,6 +447,29 @@ static inline bool thp_contains(struct page *head, pgoff_t index) > return page_index(head) == (index & ~(thp_nr_pages(head) - 1UL)); > } > > +static inline pgoff_t folio_index(struct folio *folio) > +{ > + if (unlikely(FolioSwapCache(folio))) > + return __page_file_index(&folio->page); > + return folio->page.index; > +} > + > +static inline struct page *folio_page(struct folio *folio, pgoff_t index) > +{ > + index -= folio_index(folio); > + VM_BUG_ON_FOLIO(index >= folio_nr_pages(folio), folio); > + return &folio->page + index; > +} One would expect folio_page() to be the reverse of page_folio(), only it isn't anything like that. > +/* Does this folio contain this index? */ > +static inline bool folio_contains(struct folio *folio, pgoff_t index) > +{ > + /* HugeTLBfs indexes the page cache in units of hpage_size */ > + if (PageHuge(&folio->page)) > + return folio->page.index == index; > + return index - folio_index(folio) < folio_nr_pages(folio); > +} > + > /* > * Given the page we found in the page cache, return the page corresponding > * to this index in the file