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=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 55992C433B4 for ; Fri, 16 Apr 2021 15:56:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D93216113D for ; Fri, 16 Apr 2021 15:56:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D93216113D 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 4F7866B0070; Fri, 16 Apr 2021 11:56:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 481176B0071; Fri, 16 Apr 2021 11:56:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D37E6B0072; Fri, 16 Apr 2021 11:56:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0007.hostedemail.com [216.40.44.7]) by kanga.kvack.org (Postfix) with ESMTP id 0DC486B0070 for ; Fri, 16 Apr 2021 11:56:19 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BB1631E13 for ; Fri, 16 Apr 2021 15:56:18 +0000 (UTC) X-FDA: 78038682036.18.2713B97 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id 42F07C0007EA for ; Fri, 16 Apr 2021 15:56:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=0elJsKfBr0LULfuIg7oQtlPnnvqGhJmcDzk9w2kOzoY=; b=aSXpNqkcQLeVYDKEpFoTqnJVgH WGXVjW/RjyhC6LMIIHI8xLO2fqYXAzI7xNGUkSkKl3Ztg0Fd9QFzWvc5TU8IWeqxobqYdOfRzvFh9 FoYQSpx/v279Ah5FYiwfCI70nuQcbp1ml871nKqhXnOcv548gDMqy3OTXqvL+7fopzOaxa6kY42MY YilDboSJKiwUC6YGiezebdKOhAQGXq+zGxz3a0L7RSaLR5D3bdn1kC0l8tas7T9cx7ty8mF5GwIgU Lv0zQxGbAQaFH2JdEqcfX+RuQ3ZqsGiWfQCA1Ry+B3Ptn7emDBUSInT4i+TFY2wk5javu0vmiYde0 5xt+M/AQ==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lXQoO-00A9P7-AQ; Fri, 16 Apr 2021 15:55:50 +0000 Date: Fri, 16 Apr 2021 16:55:16 +0100 From: Matthew Wilcox To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cachefs@redhat.com, linux-afs@lists.infradead.org, Jeff Layton Subject: Re: [PATCH v7 02/28] mm: Introduce struct folio Message-ID: <20210416155516.GM2531743@casper.infradead.org> References: <20210409185105.188284-1-willy@infradead.org> <20210409185105.188284-3-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210409185105.188284-3-willy@infradead.org> X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 42F07C0007EA X-Stat-Signature: x3od3smt5ztqye5ejyjb8yzu83yn5zf5 Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf03; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618588574-444433 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, Apr 09, 2021 at 07:50:39PM +0100, Matthew Wilcox (Oracle) wrote: > A struct folio is a new abstraction to replace the venerable struct page. > A function which takes a struct folio argument declares that it will > operate on the entire (possibly compound) page, not just PAGE_SIZE bytes. > In return, the caller guarantees that the pointer it is passing does > not point to a tail page. > +++ b/include/linux/mm_types.h [...] > +static inline struct folio *page_folio(struct page *page) > +{ > + unsigned long head = READ_ONCE(page->compound_head); > + > + if (unlikely(head & 1)) > + return (struct folio *)(head - 1); > + return (struct folio *)page; > +} I'm looking at changing this for the next revision, and basing it on my recent patch to make compound_head() const-preserving: +#define page_folio(page) _Generic((page), \ + const struct page *: (const struct folio *)_compound_head(page), \ + struct page *: (struct folio *)_compound_head(page)) I've also noticed an awkward pattern occurring that I think this makes less awkward: +/** + * folio_page - Return a page from a folio. + * @folio: The folio. + * @n: The page number to return. + * + * @n is relative to the start of the folio. It should be between + * 0 and folio_nr_pages(@folio) - 1, but this is not checked for. + */ +#define folio_page(folio, n) nth_page(&(folio)->page, n) That lets me simplify folio_next(): +static inline struct folio *folio_next(struct folio *folio) +{ + return (struct folio *)folio_page(folio, folio_nr_pages(folio)); +} (it occurs to me this should also be const-preserving, but it's not clear that's needed yet)