All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Duyck <alexander.duyck@gmail.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,  linux-mm <linux-mm@kvack.org>
Subject: Re: [PATCH] mm: Make PageType more efficient
Date: Tue, 10 Mar 2020 14:50:50 -0700	[thread overview]
Message-ID: <CAKgT0Uf+6AEpMCewGogowCf_24cimFq5ChmjneiA62kwFCS4Rg@mail.gmail.com> (raw)
In-Reply-To: <20200310203732.GC22433@bombadil.infradead.org>

On Tue, Mar 10, 2020 at 1:37 PM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Tue, Mar 10, 2020 at 01:17:17PM -0700, Alexander Duyck wrote:
> > On Tue, Mar 10, 2020 at 11:56 AM Matthew Wilcox <willy@infradead.org> wrote:
> > > PageType is a little hard for GCC to reason about, By checking
> > > ((~A) & flag) instead of (flag & (A | MASK) == MASK), GCC can do
> > > better optimisations, saving 652 bytes in page_alloc.o (which is
> > > a heavy user of PageBuddy).
> > >
> > > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> > > ---
> > >  include/linux/page-flags.h | 6 +++---
> > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> > > index 1bf83c8fcaa7..8fc0876e2794 100644
> > > --- a/include/linux/page-flags.h
> > > +++ b/include/linux/page-flags.h
> > > @@ -725,14 +725,14 @@ PAGEFLAG_FALSE(DoubleMap)
> > >  #define PG_table       0x00000400
> > >  #define PG_guard       0x00000800
> > >
> > > -#define PageType(page, flag)                                           \
> > > -       ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE)
> > > -

From what I can tell this is the only consumer of PAGE_TYPE_BASE.
Since it is removed you can probably remove that definition as well.

> > >  static inline int page_has_type(struct page *page)
> > >  {
> > >         return (int)page->page_type < PAGE_MAPCOUNT_RESERVE;
> > >  }
> > >
> > > +#define PageType(page, flag)                                           \
> > > +       (page_has_type(page) && (~page->page_type & flag))
> > > +

You can probably spare a cycle or two here by testing for
"!(page->page_type & flag)". That way you avoid the extra bit flipping
since the compiler can just handle the result of the AND op as it sees
fit.

> > >  #define PAGE_TYPE_OPS(uname, lname)                                    \
> > >  static __always_inline int Page##uname(struct page *page)              \
> > >  {                                                                      \
> >
> > If I recall all the page type is doing is clearing a single bit to
> > indicate the page type, and only one page type is supposed to be set
> > at a time correct?
> >
> > Is there any reason why we couldn't just do an addition and test?
> > Basically just add the flag + 1 and see if the value rolls over to 0.
> > I would think that would reduce to an even simpler setup since that
> > would be an addition with a test for carry flag or zero.
>
> I think we already allow for both PageKmemcg and PageTable to be set
> on the same page.  I don't want to stop people from being able to do
> combinations like that in the future.

Okay, i wasn't aware of that. So that prevents us from simplifying this further.


  reply	other threads:[~2020-03-10 21:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-10 18:56 [PATCH] mm: Make PageType more efficient Matthew Wilcox
2020-03-10 20:17 ` Alexander Duyck
2020-03-10 20:37   ` Matthew Wilcox
2020-03-10 21:50     ` Alexander Duyck [this message]
2020-03-11 13:13       ` Matthew Wilcox
2020-03-11 17:14         ` Ira Weiny
2020-03-11 17:22         ` Alexander Duyck
2020-03-11  1:10 ` Andrew Morton
2020-03-11 13:21   ` Matthew Wilcox

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=CAKgT0Uf+6AEpMCewGogowCf_24cimFq5ChmjneiA62kwFCS4Rg@mail.gmail.com \
    --to=alexander.duyck@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.