[PATCH] benchtests: Add random strlen benchmark

Noah Goldstein goldstein.w.n@gmail.com
Mon Aug 12 19:04:38 GMT 2024


On Mon, Aug 12, 2024 at 10:04 PM Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:
>
> Hi Noah,
>
> >> I don't believe the page offsets are useful - it would be quite complex to try to use
> >> page offsets with nul-terminated strings. And I think you end up with something that
> >> is less general - for example your data shows that over 55% of strlen calls use just 3
> >> different page offsets, and offsets are extremely skewed towards the end of a page.
> >> Different options, compiler or target will give wildly different results.
> >>
> > agreed it would make the implementation more complex. Likewise I can get behind
> > getting profiles from multiple compilers (although you could probably make that
> > case about lower alignments as well). I don't, however, agree that we
> > should just pretend it's random when that may not be the case.
>
> My point is that all data will be aligned to a minimum alignment (which can't change).
> This directly affects performance because of unaligned accesses. On the other hand the
> offset within a page is random and doesn't affect performance - even if you consider
> implementations that are affected by page crossing (since the chance of page crossing
> is so low that it hardly matters in reality).
>
> If ASLR was implemented correctly, we'd do a alloca (rand() & 4095) and
> malloc (rand() & 4095) at startup to randomize the stack and heap offsets within a page.

But we dont... any it's definitely not ubiquitous among malloc implementations.
These benchmarks are meant to be representative of how the world is, not how it
should be.

> Then multiple runs of the same binary would show completely different offsets each run
> while the distribution of alignment would remain essentially the same.
>
> Hence I just don't get why you see any significance in page offsets.
>
I can see your argument that page offsets will vary depending on environment
in ways a single profile doesn't capture.
Likewise that we really need page-cross rate (which is probably much lower).
But either way, alignment will be captured by page offset, so I don't really see
how it could be worse than what we have with this patch.

What about instead of generating based on these paired down histograms we
just grab N random samples from an actual run?

> Cheers,
> Wilco


More information about the Libc-alpha mailing list