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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS 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 0D415C433E0 for ; Sat, 13 Mar 2021 20:37:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 72A4C64ECD for ; Sat, 13 Mar 2021 20:37:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 72A4C64ECD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 13A756B006E; Sat, 13 Mar 2021 15:37:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EF586B0070; Sat, 13 Mar 2021 15:37:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F1B716B0071; Sat, 13 Mar 2021 15:37:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id D88EB6B006E for ; Sat, 13 Mar 2021 15:37:04 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9CD1F181AEF30 for ; Sat, 13 Mar 2021 20:37:04 +0000 (UTC) X-FDA: 77916010368.19.BB051B5 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf11.hostedemail.com (Postfix) with ESMTP id 2A9782000380 for ; Sat, 13 Mar 2021 20:37:04 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 4CEB164ED0; Sat, 13 Mar 2021 20:37:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1615667823; bh=UI0HkP9X7m07NOz6hRKQi+21yPSkfnX0o3Xglae/BtQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dCMb52FA4ze5ATLxcnEX79RIo5szz29rAuSnwieARL7fT0w7DNki4dnSI2iKfASOy Ps9aaCqGLE6bGv8fmNj2zrvQaloRQLTwvIOGM96DpG4954zZUkmKul+B9wiMX03o04 aUOwiGFWsvFhz2qLsOw2Q0peInLNEEUamw3J8fjM= Date: Sat, 13 Mar 2021 12:37:02 -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 01/25] mm: Introduce struct folio Message-Id: <20210313123702.b7724b84d955ab6669d4417a@linux-foundation.org> In-Reply-To: <20210305041901.2396498-2-willy@infradead.org> References: <20210305041901.2396498-1-willy@infradead.org> <20210305041901.2396498-2-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 X-Stat-Signature: sy5i4o5nd3aeopeccmn9n3bcgd1a75ih X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2A9782000380 Received-SPF: none (linux-foundation.org>: No applicable sender policy available) receiver=imf11; identity=mailfrom; envelope-from=""; helo=mail.kernel.org; client-ip=198.145.29.99 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615667824-957192 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, 5 Mar 2021 04:18:37 +0000 "Matthew Wilcox (Oracle)" wrote: > A struct folio refers to an entire (possibly compound) page. A function > which takes a struct folio argument declares that it will operate on the > entire 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. > > Signed-off-by: Matthew Wilcox (Oracle) > --- > include/linux/mm.h | 30 ++++++++++++++++++++++++++++++ > include/linux/mm_types.h | 17 +++++++++++++++++ Perhaps a new folio.h would be neater. > @@ -1518,6 +1523,30 @@ static inline void set_page_links(struct page *page, enum zone_type zone, > #endif > } > > +static inline unsigned long folio_nr_pages(struct folio *folio) > +{ > + return compound_nr(&folio->page); > +} > + > +static inline struct folio *next_folio(struct folio *folio) > +{ > +#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) > + return (struct folio *)nth_page(&folio->page, folio_nr_pages(folio)); > +#else > + return folio + folio_nr_pages(folio); > +#endif > +} It's a shame this isn't called folio_something(), like the rest of the API. Unclear what this does. Some comments would help. > +static inline unsigned int folio_shift(struct folio *folio) > +{ > + return PAGE_SHIFT + folio_order(folio); > +} > + > +static inline size_t folio_size(struct folio *folio) > +{ > + return PAGE_SIZE << folio_order(folio); > +} Why size_t? That's pretty rare in this space and I'd have expected unsigned long. > @@ -1623,6 +1652,7 @@ extern void pagefault_out_of_memory(void); > > #define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK) > #define offset_in_thp(page, p) ((unsigned long)(p) & (thp_size(page) - 1)) > +#define offset_in_folio(folio, p) ((unsigned long)(p) & (folio_size(folio) - 1)) > > /* > * Flags passed to show_mem() and show_free_areas() to suppress output in > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > index 0974ad501a47..a311cb48526f 100644 > --- a/include/linux/mm_types.h > +++ b/include/linux/mm_types.h > @@ -223,6 +223,23 @@ struct page { > #endif > } _struct_page_alignment; > > +/* > + * A struct folio is either a base (order-0) page or the head page of > + * a compound page. > + */ > +struct folio { > + struct page page; > +}; > + > +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; > +} What purpose does the READ_ONCE() serve?