linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
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
Date: Tue, 6 Apr 2021 13:48:07 +0100	[thread overview]
Message-ID: <20210406124807.GO2531743@casper.infradead.org> (raw)
In-Reply-To: <20210406122918.h5dsnbjhmwpfasf4@box.shutemov.name>

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 <a>:
struct page *a(struct page *p, unsigned long n)
{
    1180:       e8 00 00 00 00          callq  1185 <a+0x5>
                        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 <b>:

struct page *b(struct page *p, unsigned long n)
{
    11b0:       e8 00 00 00 00          callq  11b5 <b+0x5>
                        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?


  reply	other threads:[~2021-04-06 12:48 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-31 18:47 [PATCH v6 00/27] Memory Folios Matthew Wilcox (Oracle)
2021-03-31 18:47 ` [PATCH v6 01/27] mm: Introduce struct folio Matthew Wilcox (Oracle)
2021-04-06 12:29   ` Kirill A. Shutemov
2021-04-06 12:48     ` Matthew Wilcox [this message]
2021-04-06 14:21       ` Kirill A. Shutemov
2021-04-06 14:31       ` Christoph Hellwig
2021-04-06 14:40         ` Matthew Wilcox
2021-04-06 14:47           ` Christoph Hellwig
2021-04-06 14:55             ` Matthew Wilcox
2021-04-06 15:05               ` Christoph Hellwig
2021-04-06 16:25                 ` Matthew Wilcox
2021-04-07  6:09                   ` Christoph Hellwig
2021-04-08  9:01   ` Rasmus Villemoes
2021-03-31 18:47 ` [PATCH v6 02/27] mm: Add folio_pgdat and folio_zone Matthew Wilcox (Oracle)
2021-04-06 13:23   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 03/27] mm/vmstat: Add functions to account folio statistics Matthew Wilcox (Oracle)
2021-04-06 13:25   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 04/27] mm/debug: Add VM_BUG_ON_FOLIO and VM_WARN_ON_ONCE_FOLIO Matthew Wilcox (Oracle)
2021-04-06 13:26   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 05/27] mm: Add folio reference count functions Matthew Wilcox (Oracle)
2021-04-06 13:30   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 06/27] mm: Add put_folio Matthew Wilcox (Oracle)
2021-04-06 13:31   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 07/27] mm: Add get_folio Matthew Wilcox (Oracle)
2021-04-06 13:32   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 08/27] mm: Create FolioFlags Matthew Wilcox (Oracle)
2021-04-06 13:34   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 09/27] mm: Handle per-folio private data Matthew Wilcox (Oracle)
2021-04-06 13:37   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 10/27] mm/filemap: Add folio_index, folio_file_page and folio_contains Matthew Wilcox (Oracle)
2021-04-06 13:39   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 11/27] mm/filemap: Add folio_next_index Matthew Wilcox (Oracle)
2021-04-06 13:40   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 12/27] mm/filemap: Add folio_offset and folio_file_offset Matthew Wilcox (Oracle)
2021-04-06 13:42   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 13/27] mm/util: Add folio_mapping and folio_file_mapping Matthew Wilcox (Oracle)
2021-04-06 13:45   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 14/27] mm: Add folio_mapcount Matthew Wilcox (Oracle)
2021-04-06 13:46   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 15/27] mm/memcg: Add folio wrappers for various functions Matthew Wilcox (Oracle)
2021-04-06 13:48   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 16/27] mm/filemap: Add unlock_folio Matthew Wilcox (Oracle)
2021-04-06 13:51   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 17/27] mm/filemap: Add lock_folio Matthew Wilcox (Oracle)
2021-04-06 13:52   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 18/27] mm/filemap: Add lock_folio_killable Matthew Wilcox (Oracle)
2021-04-06 13:53   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 19/27] mm/filemap: Add __lock_folio_async Matthew Wilcox (Oracle)
2021-04-06 13:55   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 20/27] mm/filemap: Add __lock_folio_or_retry Matthew Wilcox (Oracle)
2021-04-06 13:57   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 21/27] mm/filemap: Add wait_on_folio_locked Matthew Wilcox (Oracle)
2021-04-06 14:11   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 22/27] mm/filemap: Add end_folio_writeback Matthew Wilcox (Oracle)
2021-04-06 14:13   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 23/27] mm/writeback: Add wait_on_folio_writeback Matthew Wilcox (Oracle)
2021-04-06 14:15   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 24/27] mm/writeback: Add wait_for_stable_folio Matthew Wilcox (Oracle)
2021-04-06 14:18   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 25/27] mm/filemap: Convert wait_on_page_bit to wait_on_folio_bit Matthew Wilcox (Oracle)
2021-04-06 14:19   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 26/27] mm/filemap: Convert wake_up_page_bit to wake_up_folio_bit Matthew Wilcox (Oracle)
2021-04-06 14:23   ` Christoph Hellwig
2021-03-31 18:47 ` [PATCH v6 27/27] mm/filemap: Convert page wait queues to be folios Matthew Wilcox (Oracle)
2021-04-06 14:25   ` Christoph Hellwig
2021-04-01  7:05 ` [PATCH v6 00/27] Memory Folios Christoph Hellwig
2021-04-01 11:26   ` Matthew Wilcox
2021-04-01 12:28     ` Jason Gunthorpe
2021-04-01 12:52       ` Matthew Wilcox
2021-04-01 13:30         ` Jason Gunthorpe
2021-04-02 14:37     ` Christoph Hellwig
2021-04-02 14:49       ` Matthew Wilcox
2021-04-03  0:31 ` Kent Overstreet
2021-04-05 19:14 ` Jeff Layton
2021-04-05 19:31   ` Matthew Wilcox
2021-04-06 15:14     ` Jeff Layton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210406124807.GO2531743@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=kirill@shutemov.name \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-cachefs@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).