linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Vlastimil Babka <vbabka@suse.cz>,
	linux-mm@kvack.org, Alexander Duyck <alexander.duyck@gmail.com>
Subject: Re: [PATCH] mm: Make PageType more efficient
Date: Wed, 11 Mar 2020 06:21:14 -0700	[thread overview]
Message-ID: <20200311132114.GE22433@bombadil.infradead.org> (raw)
In-Reply-To: <20200310181027.232cff5b00600e1f056a4177@linux-foundation.org>

On Tue, Mar 10, 2020 at 06:10:27PM -0700, Andrew Morton wrote:
> On Tue, 10 Mar 2020 11:56:09 -0700 Matthew Wilcox <willy@infradead.org> wrote:
> 
> > From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
> > 
> > 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).
> > 
> > ...
> >
> > --- 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)
> > -
> >  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))
> > +
> 
> `flag' should be parenthesized here.  As should `page' if one is even
> more paranoid.

I suppose so.  The thing is, the flag name isn't specified by the user;
users say 'if (PageBuddy(page))' and the flag gets expanded through
PAGE_TYPE_OPS.  We also don't need to worry about the user doing 'if
(PageBuddy(page++))' as it'll expand into a call to

static __always_inline int PageBuddy(struct page *page)
{
	return PageType(page, PG_buddy)
}

> I tried this:
> 
> --- a/include/linux/page-flags.h~mm-make-pagetype-more-efficient-fix
> +++ a/include/linux/page-flags.h
> @@ -731,7 +731,7 @@ static inline int page_has_type(struct p
>  }
>  
>  #define PageType(page, flag)						\
> -	(page_has_type(page) && (~page->page_type & flag))
> +	(page_has_type(page) && !(page->page_type & ~(flag)))

Mr Boole would like to let you know you misapplied his rules of algebra.
~flag is going to expand into 0xfffffff7f and then gcc will figure out
the expression as a whole is always false, and so no page is ever a
buddy page, and ..

> and page_alloc.o shrunk by 6782 bytes, half of it in
> get_page_from_freelist().  Something crazy is going on.  gcc-7.2.0.


      reply	other threads:[~2020-03-11 13:21 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
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 [this message]

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=20200311132114.GE22433@bombadil.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.duyck@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=vbabka@suse.cz \
    /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).