Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp804570pxb; Wed, 27 Jan 2021 23:59:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQWC/GBSPmTEvU8glWhn5rq/0A5dCKeH4nB2ER3lfcggCn9kopCWCVRWMePf4/dqpDJxNU X-Received: by 2002:aa7:dace:: with SMTP id x14mr12803307eds.300.1611820787659; Wed, 27 Jan 2021 23:59:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611820787; cv=none; d=google.com; s=arc-20160816; b=rEt2afmY+YrpB+RGu+TuPFnt3fgFItoqz9hAKqPvrofkAfjroauqQglwgs9DcIXq19 Mu8yL2ZKfBjN4EJv3ffgPG9pdO3e+44in+ci56qyreOAk/Heqp9cbW8o2G44kX1FOYnt CeRP/k/jntpcqD3OHRc0hpykTb2XWKaKLi2249ad1xOYEr/6LH/Ry9V6LCKHIn16B8yt mBT4sGiAEpMJ3lUzTovqFkutWNdaK4FrkLd9YhfexktfogzFXfX2vyQhTZLAJrb3z67u ByhvKcSKTLIpGpNnPTxRxnZVL4mdCuykJ3Yd6hU+IQCbXEIPc3KqwkvEPQPzuZzs1MDu c4cA== 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:date:subject:cc:to:from :dkim-signature; bh=CxWQAtXy3I5lAmgNKcG2Me1pceWaP119juUXd37vOB0=; b=TOoWfu0A/gXs+y+EAcvQZBdXkJFI7DA1jIOqpU6YDPRr2LhOkz4K/OKJOruuS14hso dB/R15QNox9hRtIkagHi03RMyUx7YUzFzR/2Kp86uVDqof102AR3zpXOBY/6Is4gyJxs ywNuljHV3mBgZ9n5RPj+4eIzJi+uKLWN3yybfQ8EeC8Ia7SJ4vgCWu3U3iHpunpy61v9 YVEQllQkDCfeVfFV8RtRSIai7oWx6rC/hpZMs7cVfFLSNUAGHF9yv23VsAhZxdAJMGOS 1QiKHQX1XsQyl9m1o9aBK2psgQHG9AihBmHVuVw4lN6Sy4Kkvx0q97uOwpguh6PojQ19 KAPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=O+0Akf1A; 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 g12si2009228ejr.429.2021.01.27.23.59.24; Wed, 27 Jan 2021 23:59:47 -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=@infradead.org header.s=casper.20170209 header.b=O+0Akf1A; 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 S232336AbhA1H6k (ORCPT + 99 others); Thu, 28 Jan 2021 02:58:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231148AbhA1HFd (ORCPT ); Thu, 28 Jan 2021 02:05:33 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4D3FC06178B; Wed, 27 Jan 2021 23:04:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=CxWQAtXy3I5lAmgNKcG2Me1pceWaP119juUXd37vOB0=; b=O+0Akf1AaopB68IjGsMsfPRYER jlSVynuejYtvR5pZldi6C6xIU88xCQn9wG52bUrJlPVuOwAX1hvA9vH2ESN5L4CUf1YPO2rBVXo48 xl+h5iXc++BIFSi6HqytNWZqAbp8gvRXyoPBEOga29LjSLzwox3oxWMhqPnmz3t9WJm/VOydPvTzo IoUE7LtDZhL8MT+ByIfsuPegVNTKu/eFjQZmwLQxY8SPdDvPpDbS38wKPmax7TiSs4sBeumx3YC4y vq0Q4PRTk1UBWGwWdizC/QepOiVnNwJ4utpo9LKRc9Suxd1GHEWi+o0VyYwCaj5RE2XMAiyPeorud fyYyDh9Q==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1l51Lo-00847T-RK; Thu, 28 Jan 2021 07:04:21 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org Subject: [PATCH v3 09/25] mm: Add folio_index, folio_page and folio_contains Date: Thu, 28 Jan 2021 07:03:48 +0000 Message-Id: <20210128070404.1922318-10-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210128070404.1922318-1-willy@infradead.org> References: <20210128070404.1922318-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 83d24b41fb04..86956e97cd5e 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; +} + +/* 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 -- 2.29.2