Re: [PATCH v3 1/4] x86/clear_page: extend clear_page*() for multi-page clearing
From: Ankur Arora
Date: Tue Apr 15 2025 - 16:02:33 EST
Mateusz Guzik <mjguzik@xxxxxxxxx> writes:
> On Tue, Apr 15, 2025 at 8:14 AM Ankur Arora <ankur.a.arora@xxxxxxxxxx> wrote:
>>
>>
>> Mateusz Guzik <mjguzik@xxxxxxxxx> writes:
>> > With that sucker out of the way, an optional quest is to figure out if
>> > rep stosq vs rep stosb makes any difference for pages -- for all I know
>> > rep stosq is the way. This would require testing on quite a few uarchs
>> > and I'm not going to blame anyone for not being interested.
>>
>> IIRC some recent AMD models (Rome?) did expose REP_GOOD but not ERMS.
>>
>
> The uarch does not have it or the bit magically fails to show up?
> Worst case, should rep stosb be faster on that uarch, the kernel can
> pretend the bit is set.
It's a synthetic bit so the uarch has both. I think REP STOSB is optimized
post FSRS (AIUI Zen3)
if (c->x86 >= 0x10)
set_cpu_cap(c, X86_FEATURE_REP_GOOD);
/* AMD FSRM also implies FSRS */
if (cpu_has(c, X86_FEATURE_FSRM))
set_cpu_cap(c, X86_FEATURE_FSRS);
>> > Let's say nobody bothered OR rep stosb provides a win. In that case this
>> > can trivially ALTERNATIVE between rep stosb and rep stosq based on ERMS,
>> > no func calls necessary.
>>
>> We shouldn't need any function calls for ERMS and REP_GOOD.
>>
>> I think something like this untested code should work:
>>
>> asm volatile(
>> ALTERNATIVE_2("call clear_pages_orig",
>> "rep stosb", X86_FEATURE_REP_GOOD,
>> "shrl $3,%ecx; rep stosq", X86_FEATURE_ERMS,
>> : "+c" (size), "+D" (addr), ASM_CALL_CONSTRAINT
>> : "a" (0)))
>>
>
> That's what I'm suggesting, with one difference: whack
> clear_pages_orig altogether.
What do we gain by getting rid of it? Maybe there's old hardware with
unoptimized rep; stos*.
--
ankur