linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Lance Yang <ioworker0@gmail.com>, akpm@linux-foundation.org
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, Lance Yang <lance.yang@linux.dev>
Subject: Re: [PATCH 1/1] mm/rmap: optimize MM-ID mapcount handling with union
Date: Sun, 20 Apr 2025 09:12:10 +0200	[thread overview]
Message-ID: <2e501e48-8604-4813-b76a-d467cad67f53@redhat.com> (raw)
In-Reply-To: <20250420055159.55851-1-lance.yang@linux.dev>


>   	/* Note: mapcounts start at -1. */
>   	atomic_set(&folio->_large_mapcount, mapcount - 1);
> diff --git a/mm/internal.h b/mm/internal.h
> index 838f840ded83..1505174178f4 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -772,8 +772,13 @@ static inline void prep_compound_head(struct page *page, unsigned int order)
>   		atomic_set(&folio->_nr_pages_mapped, 0);
>   	if (IS_ENABLED(CONFIG_MM_ID)) {
>   		folio->_mm_ids = 0;
> -		folio->_mm_id_mapcount[0] = -1;
> -		folio->_mm_id_mapcount[1] = -1;
> +		/*
> +		 * One-shot initialization of both mapcount slots to -1.
> +		 * Using 'unsigned long' ensures cross-arch compatibility:
> +		 * - 32-bit: Fills both short slots (0xFFFF each)
> +		 * - 64-bit: Fills both int slots (0xFFFFFFFF each)
> +		 */
> +		folio->_mm_id_mapcounts = -1UL;

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.

-- 
Cheers,

David / dhildenb



  reply	other threads:[~2025-04-20  7:12 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 [this message]
2025-04-20  8:33   ` Lance Yang
2025-04-21  7:40     ` David Hildenbrand
2025-04-21  8:02       ` Lance Yang

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=2e501e48-8604-4813-b76a-d467cad67f53@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=ioworker0@gmail.com \
    --cc=jackmanb@google.com \
    --cc=lance.yang@linux.dev \
    --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