linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Lance Yang" <lance.yang@linux.dev>
To: "David Hildenbrand" <david@redhat.com>
Cc: mingzhe.yang@ly.com, willy@infradead.org, ziy@nvidia.com,
	mhocko@suse.com, vbabka@suse.cz, surenb@google.com,
	linux-mm@kvack.org, jackmanb@google.com, hannes@cmpxchg.org,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	"Lance Yang" <ioworker0@gmail.com>
Subject: Re: [PATCH 1/1] mm/rmap: optimize MM-ID mapcount handling with union
Date: Mon, 21 Apr 2025 08:02:01 +0000	[thread overview]
Message-ID: <9e3e1f9d238c01bdeacb165501483ab666a766cd@linux.dev> (raw)
In-Reply-To: <e3c635ed-7d4b-4d07-80ad-75be950b803c@redhat.com>

April 21, 2025 at 3:40 PM, "David Hildenbrand" <david@redhat.com> wrote:



> 
> > 
> > > 
> > > Are we sure the compiler cannot optimize that itself?
> > > 
> > >  On x86-64 I get with gcc 14.2.1:
> > > 
> > >  ; folio->_mm_id_mapcount[0] = -1;
> > > 
> > >  3f2f: 48 c7 42 60 ff ff ff ff movq $-0x1, 0x60(%rdx)
> > > 
> > >  Which should be a quadword (64bit) setting, so exactly what you want to achieve.
> > > 
> > 
> >  > Yeah, the compiler should be as smart as we expect it to be.
> > 
> >  However, it seems that gcc 4.8.5 doesn't behave as expected
> > 
> >  with the -O2 optimization level on the x86-64 test machine.
> > 
> >  struct folio_array {
> > 
> >  int _mm_id_mapcount[2];
> > 
> >  };
> > 
> >  void init_array(struct folio_array *f) {
> > 
> >  f->_mm_id_mapcount[0] = -1;
> > 
> >  f->_mm_id_mapcount[1] = -1;
> > 
> >  }
> > 
> >  0000000000000000 <init_array>:
> > 
> >  0: c7 07 ff ff ff ff movl $0xffffffff,(%rdi)
> > 
> >  6: c7 47 04 ff ff ff ff movl $0xffffffff,0x4(%rdi)
> > 
> >  d: c3 retq
> > 
> >  ---
> > 
> >  struct folio_union {
> > 
> >  union {
> > 
> >  int _mm_id_mapcount[2];
> > 
> >  unsigned long _mm_id_mapcounts;
> > 
> >  };
> > 
> >  };
> > 
> >  void init_union(struct folio_union *f) {
> > 
> >  f->_mm_id_mapcounts = -1UL;
> > 
> >  }
> > 
> >  0000000000000010 <init_union>:
> > 
> >  10: 48 c7 07 ff ff ff ff movq $0xffffffffffffffff,(%rdi)
> > 
> >  17: c3 retq
> > 
> >  Hmm... I'm not sure if it's valuable for those compilers that
> > 
> >  are not very new.
> > 
> 
> Yeah, we shouldn't care about performance with rusty old compilers, especially if the gain would likely not even be measurable.

Ah, nice to know that ;)

> 
> Note that even Linux requires 5.1 ever since 2021. GCC seems to implement this optimization starting with 7.1 (at least when playing with the compiler explorer).


Thanks for the details. Let’s just drop it - no measurable gain.

Thanks,
Lance

> 
> -- Cheers,
> 
> David / dhildenb
>


      reply	other threads:[~2025-04-21  8:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-20  5:51 Lance Yang
2025-04-20  7:12 ` David Hildenbrand
2025-04-20  8:33   ` Lance Yang
2025-04-21  7:40     ` David Hildenbrand
2025-04-21  8:02       ` Lance Yang [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=9e3e1f9d238c01bdeacb165501483ab666a766cd@linux.dev \
    --to=lance.yang@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=ioworker0@gmail.com \
    --cc=jackmanb@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=mingzhe.yang@ly.com \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    --cc=ziy@nvidia.com \
    /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