From patchwork Fri Mar 5 04:18:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12117565 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 CEB03C433E0 for ; Fri, 5 Mar 2021 04:22:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7505165016 for ; Fri, 5 Mar 2021 04:22:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7505165016 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 0E0EA6B000A; Thu, 4 Mar 2021 23:22:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B91C6B000C; Thu, 4 Mar 2021 23:22:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC33F6B000E; Thu, 4 Mar 2021 23:22:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0215.hostedemail.com [216.40.44.215]) by kanga.kvack.org (Postfix) with ESMTP id D015F6B000A for ; Thu, 4 Mar 2021 23:22:13 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 994E1180ACC44 for ; Fri, 5 Mar 2021 04:22:13 +0000 (UTC) X-FDA: 77884523346.07.3B79766 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id E19BEC0001EE for ; Fri, 5 Mar 2021 04:22:10 +0000 (UTC) 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=VD0Fvg6cmd14tiXkK8z0qmCk4W9zwnqQgUrYNW/arts=; b=JpUjN9GY8ZgJniUfRJZmlBURQ2 nIgf3UKyig4Swhl+XLzue7r1CE7cw/LigQZDDdEXQPrgenhmeC15rneYkVY4QPkvV18CaSDbox2bX 7RxVqgp8CLAY+9zduAnD5qo1j1OBj30DLKOiZVSIgpDa9OsIS0WPmwZtMZVSAwsIsNuQU6tMqkhQu 2mAec1BSqPl4qVSd3GTHhdWYoTzgI/xGdofk9SgsAVNRcAM4QBeQb4PoB+8R7/wZNbbAxFSaV4psK bCH2eSemJ3JmZelTPpYNbt0Tm06aBUWRSKEXQsYcDr/xkC8mgpbPfZdHn2ljUDfmi/AFb8pBvSDky v0fDfY2w==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lI1xU-00A3cR-Fh; Fri, 05 Mar 2021 04:21:13 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 09/25] mm: Add folio_index, folio_page and folio_contains Date: Fri, 5 Mar 2021 04:18:45 +0000 Message-Id: <20210305041901.2396498-10-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210305041901.2396498-1-willy@infradead.org> References: <20210305041901.2396498-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E19BEC0001EE X-Stat-Signature: np3p9hujzhjfxzgqdhpgnnqpttrdgw1e Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf14; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614918130-542317 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: 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 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; +} + +/* 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