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.6 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 03DA7C433B4 for ; Tue, 6 Apr 2021 12:48:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 75E636120E for ; Tue, 6 Apr 2021 12:48:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 75E636120E 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 0B6736B007E; Tue, 6 Apr 2021 08:48:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 067876B0080; Tue, 6 Apr 2021 08:48:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E70D16B0081; Tue, 6 Apr 2021 08:48:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0212.hostedemail.com [216.40.44.212]) by kanga.kvack.org (Postfix) with ESMTP id C704F6B007E for ; Tue, 6 Apr 2021 08:48:41 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7A946180178BB for ; Tue, 6 Apr 2021 12:48:41 +0000 (UTC) X-FDA: 78001921242.32.07D0FF6 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id A032C20001D6 for ; Tue, 6 Apr 2021 12:48:40 +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=CA9+GCPN3x6Z5hKcYRzM3r8Ts3deLeZx5UJVoF7+tNE=; b=wR3a+Y4XXolRLqwzrQyiky8UUC pAJ5CpX/TpwCDY1hw2XJH07o/43t5sM9R4Pcb4W1JBVJUnvf50TFWsSjz9HTSGklLw2aQFXMDPlEo w/k4IWIGr6GFOiwYaEl7HBAiVkr0U0EQqye/rLfyvNdQgGhy+JZS4bFZTSfnzgDu86vtlcVYxIVkb cKcqhjLSGLdsFDqrUz8abYZHUIy4DZsZrNzxAbOXWY0I2s0k7k/RW2IrVffvJTBZLrEmm+mnWwOwf HQtaugWjj5yq9EPRp8CaJE/XCiXxi0fV3U3ruHurV+fyLRLnsXDwHcJjXAaYQbCFKxXLb85QlZTQJ FvETcUFA==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lTl7n-00CoN1-SM; Tue, 06 Apr 2021 12:48:27 +0000 Date: Tue, 6 Apr 2021 13:48:07 +0100 From: Matthew Wilcox To: "Kirill A. Shutemov" Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cachefs@redhat.com, linux-afs@lists.infradead.org Subject: Re: [PATCH v6 01/27] mm: Introduce struct folio Message-ID: <20210406124807.GO2531743@casper.infradead.org> References: <20210331184728.1188084-1-willy@infradead.org> <20210331184728.1188084-2-willy@infradead.org> <20210406122918.h5dsnbjhmwpfasf4@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210406122918.h5dsnbjhmwpfasf4@box.shutemov.name> X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: A032C20001D6 X-Stat-Signature: 39ispsoeb66gf6jaob97oe6s4jybwhb6 Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617713320-220141 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 Tue, Apr 06, 2021 at 03:29:18PM +0300, Kirill A. Shutemov wrote: > On Wed, Mar 31, 2021 at 07:47:02PM +0100, Matthew Wilcox (Oracle) wrote: > > +/** > > + * folio_next - Move to the next physical folio. > > + * @folio: The folio we're currently operating on. > > + * > > + * If you have physically contiguous memory which may span more than > > + * one folio (eg a &struct bio_vec), use this function to move from one > > + * folio to the next. Do not use it if the memory is only virtually > > + * contiguous as the folios are almost certainly not adjacent to each > > + * other. This is the folio equivalent to writing ``page++``. > > + * > > + * Context: We assume that the folios are refcounted and/or locked at a > > + * higher level and do not adjust the reference counts. > > + * Return: The next struct folio. > > + */ > > +static inline struct folio *folio_next(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 > > Do we really need the #if here? > > >From quick look at nth_page() and memory_model.h, compiler should be able > to simplify calculation for FLATMEM or SPARSEMEM_VMEMMAP to what you do in > the #else. No? No. 0000000000001180 : struct page *a(struct page *p, unsigned long n) { 1180: e8 00 00 00 00 callq 1185 1181: R_X86_64_PLT32 __fentry__-0x4 1185: 55 push %rbp return nth_page(p, n); 1186: 48 2b 3d 00 00 00 00 sub 0x0(%rip),%rdi 1189: R_X86_64_PC32 vmemmap_base-0x4 118d: 48 c1 ff 06 sar $0x6,%rdi 1191: 48 8d 04 37 lea (%rdi,%rsi,1),%rax 1195: 48 89 e5 mov %rsp,%rbp return nth_page(p, n); 1198: 48 c1 e0 06 shl $0x6,%rax 119c: 48 03 05 00 00 00 00 add 0x0(%rip),%rax 119f: R_X86_64_PC32 vmemmap_base-0x4 11a3: 5d pop %rbp 11a4: c3 retq vs 00000000000011b0 : struct page *b(struct page *p, unsigned long n) { 11b0: e8 00 00 00 00 callq 11b5 11b1: R_X86_64_PLT32 __fentry__-0x4 11b5: 55 push %rbp return p + n; 11b6: 48 c1 e6 06 shl $0x6,%rsi 11ba: 48 8d 04 37 lea (%rdi,%rsi,1),%rax 11be: 48 89 e5 mov %rsp,%rbp 11c1: 5d pop %rbp 11c2: c3 retq Now, maybe we should put this optimisation into the definition of nth_page? > > +struct folio { > > + /* private: don't document the anon union */ > > + union { > > + struct { > > + /* public: */ > > + unsigned long flags; > > + struct list_head lru; > > + struct address_space *mapping; > > + pgoff_t index; > > + unsigned long private; > > + atomic_t _mapcount; > > + atomic_t _refcount; > > +#ifdef CONFIG_MEMCG > > + unsigned long memcg_data; > > +#endif > > As Christoph, I'm not a fan of this :/ What would you prefer?