Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1725017pxb; Thu, 4 Mar 2021 20:22:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdLwCGOQvlQ5Hc9cgJB5NG4ReSRfOpQwiFcV9ubFtAd8Nbt2puDKQy4IEa2Ei72LqZHKPQ X-Received: by 2002:a05:6e02:1545:: with SMTP id j5mr6868060ilu.296.1614918175369; Thu, 04 Mar 2021 20:22:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614918175; cv=none; d=google.com; s=arc-20160816; b=f++6HiGADWFM8BksWIUd+atmQNx8lvrbKD6R12v0CETGPby/3lvsRjJqNcwBfVR7Ho 2S375ksXF2ksknUXnIZC0Fi8goU3TaJHCxsTvJ2gLK/2g5MCYm5klmjRFXIFeavF2xVQ aXI2qdKe6JUEefVh0Op5eMbH+1I2luqR/Q26WXe/BG1nWUuDzgjW0mCOwkAOl5AUjzX7 g4hjqItZW/JhPSyjEtl1QKtW7Hq4ZcsbcoT1cqScbBLCtIXgJy8m2L4X2483khokYnZG omSW0oBAC88+n4yF2Es6Dwb5ApW1eNA5trcqjqUC3NLgnuEDDA9fn1PUikmW8wxG284T 8Ivg== 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=VD0Fvg6cmd14tiXkK8z0qmCk4W9zwnqQgUrYNW/arts=; b=KFTa2Jr7t6kYx4VhRwJLgcDYwoVK9gTiEv/Aba/yNQZw5TuqATARhsjZp3IlkVWOoQ IyH97Bf4vTlAf3SUnPolkmXhW52B5o+JhhnKbfdt8nmxHeVFE3o/m/WBhNMwZJNaG8fE PhmwXEH9HR9edbo0aKQv2V79vhJXq15AzH2oA1LHpispxIEP9ui25FKBRM9DIxj5Nvdr MCXOCNwAS+gZxNg5kWjR28YFO8SzTSoVm6BYDzPW8yIWbvAF86q1iD9kK1eqxDlfctKh oH/mP6FNLUaKiuur2YKxXhbtjPDGAWMUW3lGUf8lxGBRVrxvbrc2SJhtS0GAzAI0plZC Gr8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=JpUjN9GY; 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 v4si1305264iob.94.2021.03.04.20.22.42; Thu, 04 Mar 2021 20:22:55 -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=JpUjN9GY; 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 S229749AbhCEEWN (ORCPT + 99 others); Thu, 4 Mar 2021 23:22:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbhCEEWN (ORCPT ); Thu, 4 Mar 2021 23:22:13 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EF76C061574; Thu, 4 Mar 2021 20:22:13 -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=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 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 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 -- 2.30.0