[PATCH v2] arm64: clear_page[s] using memset
Catalin Marinas
catalin.marinas at arm.com
Wed Sep 23 09:14:15 PDT 2026
On Wed, Sep 16, 2026 at 04:54:09PM +0100, Leonardo Bras wrote:
> On Wed, Sep 16, 2026 at 04:28:51PM +0100, Leonardo Bras wrote:
> > On Wed, Sep 16, 2026 at 12:03:56PM +0200, Linus Walleij wrote:
> > > There is no need to try to second-guess the compiler when
> > > clearing memory. Just call memset() like everyone else.
> > >
> > > Since memset() already has an architecture-local MOPS
> > > optimization, we do not need to do anything else to preserve
> > > the MOPS optimization.
> > >
> > > While at it, implement the shorthand for directly calling
> > > the new prototype clear_pages() for larger page chunks.
> > >
> > > No performance regressions can be seen, the fastpath
> > > benchmarks differences are in the noise.
> > >
> > > Usama Anjum tested next-20260821 with one warm-up and three repeats
> > > in four sessions, for a total of 12 measured runs. The commands were:
> > >
> > > perf bench mem memset -k 1GB -f default -s 16GB
> > > perf bench mem mmap -p 1GB -f demand -s 32GB -l 5
> > > perf bench mem mmap -p 4KB -f demand -s 32GB -l 5
> > >
> > > The results were:
> > >
> > > aws-m7g.metal:
> > > Benchmark Base bytes/sec Change with patch
> > > memset 1GB 63932542232.12 1.92%
> > > mmap 1GB 63272579168.03 -0.57%
> > > mmap 4KB 49692830849.48 -1.11%
> > >
> > > cesw-aarch64-ampereone-1s-a192-32x:
> > > Benchmark Base bytes/sec Change with patch
> > > memset 1GB 33895562998.71 0.25%
> > > mmap 1GB 34338454210.17 1.16%
> > > mmap 4KB 25687107580.90 -0.85%
[...]
> > Looking on that, I see that the memset() implementation uses setp, setm,
> > sete, while the clear_page()'s uses setpn, setmn, setn for the case with
> > MOPS. But then, reading into the docs, the instructions seem pretty much
> > the same thing.
[...]
> Oh, I browsed a bit here, and IIUC none of the tested machines have
> FEAT_MOPS, is that right?
>
> If that's the case, the tests are exactly to what is different between
> patched and current versions. There should be no impact on MOPS version as
> the instructions are basically the same.
Logically, yes, they are the same. From a performance perspective, there
may be a difference between the temporal and non-temporal variants,
depending on the usage.
I think it would be good to run the benchmarks with the current
implementation without DC ZVA. I don't think we have an easy way to do
this on the command line, so we can simply hard-code the DZP=1 check and
fall back to the STP or STNP in both cases.
Otherwise I'm fine with the patch as well, good clean-up.
--
Catalin
More information about the linux-arm-kernel
mailing list