Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp56526pxf; Tue, 6 Apr 2021 14:53:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBt58Oq+4k9uxOBgGufNBK+AdWflGDWSrgMT3QL/6fExAKo/c9BbQTNBb1J7W5Dz6Wz2cg X-Received: by 2002:a17:906:f159:: with SMTP id gw25mr88212ejb.309.1617746037944; Tue, 06 Apr 2021 14:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617746037; cv=none; d=google.com; s=arc-20160816; b=I0ngyKGLcS6ZAZcNaUuuRgxe0w61yRXsGR74coVnTC7ITsvs0KvZZEKOaPnZ/hT2HW Y1pS3/SrhXtOtdEXKnk+y0jK7MVo6HOMPq1RI3SfKF41xH4Dyc+djpHxWl5HhORzKnh6 Vn2e4cxq9DuaFY+Yp+mPeAWSCvCc4elSckyKAtRm9Jb73Jrt2UcS24cMNw89oO1EOppA InhSH8CS1f2hd2mzXAMEg8OhTpApOzV2i/XM1Q3eqMRsyABwDIDHWpAsyr4lUWylr+hm cGzU6RdV2u3LabpTVBaj8vu4aJcygj/Ib1KcKYarmLvr+O0nPt8rgh+Kcq54VwLQSdwP fzWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=CA9+GCPN3x6Z5hKcYRzM3r8Ts3deLeZx5UJVoF7+tNE=; b=iznaoeErNb8u8oK7FHbjvmn9uUYvE3NDZWUYmtxJurR8SFzeYk538e3WwSnpAjSexw +vyBUf/YVfwHX9RmLlI2I1hAlvrmtA46h8siEzjlrVs6H5pcLLKZGfrh4eMEq6/TqRWP o2UvzWVTK4r8QL4n/2TweV43gE2r/wCClQJD7VbImeyQprx6DEGo7kb+Sdf2AB794EPt /0rOD4hzQpYU2QgPZQVAMBAv4fhl/aofsdl3OMUpemAm4Oy417ByoTS/SGY/H4Q99XFo GPv0HzckgYk7DYKnRziJOuW6MGmzoHUB3247LySpwm0DPZMLXG6TwjsnGdBKOEOaSyqp QN7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=wR3a+Y4X; 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 e12si3387917edz.568.2021.04.06.14.53.34; Tue, 06 Apr 2021 14:53:57 -0700 (PDT) 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=wR3a+Y4X; 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 S1344230AbhDFMs5 (ORCPT + 99 others); Tue, 6 Apr 2021 08:48:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344206AbhDFMss (ORCPT ); Tue, 6 Apr 2021 08:48:48 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 825F0C06174A; Tue, 6 Apr 2021 05:48:40 -0700 (PDT) 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?