From: "Garg, Shivank" <shivankg@amd.com>
To: Borislav Petkov <bp@alien8.de>,
"David Hildenbrand (Arm)" <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Thomas Gleixner <tglx@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H . Peter Anvin" <hpa@zytor.com>,
Ankur Arora <ankur.a.arora@oracle.com>,
Bharata B Rao <bharata@amd.com>,
Hrushikesh Salunke <hsalunke@amd.com>,
David Rientjes <rientjes@google.com>,
sandipan.das@amd.com, torvalds@linuxfoundation.org
Subject: Re: [RFC PATCH 1/1] mm: batch page copies in folio_copy() and folio_mc_copy()
Date: Tue, 19 May 2026 13:14:58 +0530 [thread overview]
Message-ID: <0558da9e-1d5c-45b9-b69f-99d50d22d090@amd.com> (raw)
In-Reply-To: <20260518160036.GAags3pIMyN8YN7fPw@fat_crate.local>
On 5/18/2026 9:31 PM, Borislav Petkov wrote:
> On Mon, May 18, 2026 at 10:43:22AM +0200, David Hildenbrand (Arm) wrote:
>> I was wondering whether optimizing memcpy() further would be of value elsewhere.
>>
>> Of course, we wouldn't want to degrade it :)
>>
>> Some direction from x86 folks would be nice.
>
> We can talk about it... :)
>
> With the proper perf numbers to back the changes up and if we don't regress
> others, we could look at improving the !FSRM situation.
>
> Make sure to CC Linus on those patches as he likes to look at optimizations
> there, as one can see from who changed things around that area.
>
> :-)
>
Hi Boris,
Sure, I'll keep Linus in CC.
So, the story so far:
- Current folio_copy/folio_mc_copy() do not fully utilize the potential of rep
movsb for large pages (up to 2X speedup with FSRM)
- On Zen 3 (no FSRM), memcpy falls back to unrolled movq (memcpy_orig). (using
rep movsq instead would give 1.4-2X speedups over mempcy_orig for >= 1K blocks)
- folio_copy and the mc variant are asymmetric in their primitive selection
(memcpy, rep movsq):
folio_copy -> copy_highpage() -> copy_page() = rep movsq [REP_GOOD]
= unrolled movq [otherwise]
folio_mc_copy -> copy_mc_highpage() -> copy_mc_to_kernel() = copy_mc_fragile [if enabled]
= copy_mc_enhanced_fast_string (rep movsb) [ERMS]
= memcpy() [otherwise]
= rep movsb [FSRM]
= unrolled movq [otherwise]
Introducing a new "copy_pages()" helper can make this symmetric and
optimize the bulk path.
memcpy() and copy_page*() are fundamentally different in that memcpy
callers don't guarantee alighment.
However, David suggested avoiding the new helper would be nice.
The direction from thread is to improve memcpy for !FSRM situation
(without regressing others), this would address the Zen3 regression
we see when folio_copy switches to bulk memcpy(), while keeping the
gains on FSRM CPUs.
What if we modify memcpy to ALTERNATIVE_2, adding a rep movsq for
REP_GOOD between the FSRM path and unrolled movq fallback?
I'll gather more data for memcpy experiment.
Thanks,
Shivank
prev parent reply other threads:[~2026-05-19 7:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 14:20 [RFC PATCH 0/1] batch page copies in folio_copy() and folio_mc_copy() Shivank Garg
2026-04-27 14:20 ` [RFC PATCH 1/1] mm: " Shivank Garg
2026-05-12 9:31 ` David Hildenbrand (Arm)
2026-05-14 5:17 ` Garg, Shivank
2026-05-18 8:43 ` David Hildenbrand (Arm)
2026-05-18 14:20 ` David Laight
2026-05-19 5:43 ` Garg, Shivank
2026-05-18 16:01 ` Borislav Petkov
2026-05-19 7:44 ` Garg, Shivank [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=0558da9e-1d5c-45b9-b69f-99d50d22d090@amd.com \
--to=shivankg@amd.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=ankur.a.arora@oracle.com \
--cc=bharata@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=hpa@zytor.com \
--cc=hsalunke@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=sandipan.das@amd.com \
--cc=surenb@google.com \
--cc=tglx@kernel.org \
--cc=torvalds@linuxfoundation.org \
--cc=vbabka@kernel.org \
--cc=x86@kernel.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