Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2238715pxf; Sat, 13 Mar 2021 12:41:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxAntVoqbHP9jclgQmfFlOY4g4ooZp9AJWWVa7I/FNXElbBTXodhiCHTvIHBHuOuFD+Dy4c X-Received: by 2002:a05:6402:447:: with SMTP id p7mr21746465edw.89.1615668062515; Sat, 13 Mar 2021 12:41:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615668062; cv=none; d=google.com; s=arc-20160816; b=ozKYP+WY2ieKqkDGreoxWtOko/aHQ+kFMuSE0tPx/Efw4qyqlITIhAOO/QhTxjNGkk zJ4wg3hpMeFDDL6JE2DcyCM9YlABAcWi5X/yb7ad6NxRnezmDhJkVZJamrhutdoZOYdE L1GET1kpZl1ytpnCc79FIC0FaE4qaeErmjmUy85BgKnELIrDbLo50ttAGfup3GH5AesL NuTa19uNV/1Hbnoq0IPxZvrwbG9SrHJPSs5czzE0xMtidhmxrZAn/DD4qdLkntu0r4E/ aKoZ0052lJihpCO5FpIQrBYd4tHDogxxf4Sh+OkL4SvomzEDrf+bEIbOwBobVqTm2tRj PMxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=waVYqKoKBklynpf5mCTvHrhCxHwVfYtbFG13acLcVzo=; b=ymPk6bdeGRcT2HBAFhG9vpcquLXrU4EZanhRKxR4jKKLMAECG4v5FIWzFvyZkTcSr2 hAat/lH7v2yo4QEOOpDVBbgVE56BfIBMujD7F7tUEkRmisD76IsgczNmVHp3WvsIPzY4 1By66kdt0frZSNbk6q454xbpBecKC9AErAHFIb5yx6/o6Y0shHDw5UafOXq16Q00jUcR QxhYGfhEpUKMLn17WPO3DrrW6OvaeRrjQ94Ukf39J8IXoEYs2I6OHA87JPd4Yz66eSDM dTJsXARvBmlzuXJ+1sKiQY/iRmpwqkElotC7yHGaqO9FsOgS/ccMiW1f3no57tmb+gd8 cL7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=C1W0+23k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d22si7728392ejk.139.2021.03.13.12.40.40; Sat, 13 Mar 2021 12:41:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=C1W0+23k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234669AbhCMUhf (ORCPT + 99 others); Sat, 13 Mar 2021 15:37:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:36768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234535AbhCMUhR (ORCPT ); Sat, 13 Mar 2021 15:37:17 -0500 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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