This is an archive of the discontinued LLVM Phabricator instance.

[scudo] Do not grab a cache for secondary allocation & per related changes
ClosedPublic

Authored by cryptoad on Jul 13 2017, 8:24 AM.

Details

Summary

Secondary backed allocations do not require a cache. While it's not necessary
an issue when each thread has its cache, it becomes one with a shared pool of
caches (Android), as a Secondary backed allocation or deallocation holds a
cache that could be useful to another thread doing a Primary backed allocation.

We introduce an additional PRNG and its mutex (to avoid contention with the
Fallback one for Primary allocations) that will provide the Salt needed for
Secondary backed allocations.

I changed some of the code in a way that feels more readable to me (eg: using
some values directly rather than going through ternary assigned variables,
using directly true/false rather than FromPrimary). I will let reviewers
decide if it actually is.

An additional change is to mark CheckForCallocOverflow as UNLIKELY.

Event Timeline

cryptoad created this revision.Jul 13 2017, 8:24 AM
alekseyshl added inline comments.Jul 13 2017, 10:43 AM
lib/scudo/scudo_allocator.cpp
388

Now it feels like your combined allocator API should be AllocatePrimary/AllocateSecondary and the same for Deallocate/etc to do not pass useless params and branch on those.

389

Yep, it is more compact now, but I'd still add /*parameter name*/ comments next to those literals. They do help readability.

393

I believe you want to {} two lines above too.

428

Nit: I get why you did this, but now there's a logical disconnect between the size passed to the allocator and this statement.

cryptoad added inline comments.Jul 13 2017, 11:00 AM
lib/scudo/scudo_allocator.cpp
388

Sounds good.

389

Ok.

393

I am not sure I understand what you mean here.
The FallbackMutex encompasses both the Prng and the Cache, so I am using it for the whole else statement.

428

So bringing back AllocationSize here?

alekseyshl added inline comments.Jul 13 2017, 1:08 PM
lib/scudo/scudo_allocator.cpp
393

Ah, right, got carried away. Please ignore it.

428

If it does not affect performance (why should it, though?), yes, please bring it back.

cryptoad updated this revision to Diff 106510.Jul 13 2017, 1:28 PM
cryptoad marked 10 inline comments as done.

Addressing Aleksey's comments:

  • introduce allocate{Primary,Secondary} and their deallocation counterparts in the combined allocator. As explained in the comments, the Secondary functions do not require a Cache parameter, and the Primary allocation function doesn't require an Alignment parameter. That simplifies the prototypes;
  • bring back AllocSize, add /*xxx=*/ for "inlined" parameters (which now is really only one instance of getActuallyAllocatedSize);

One additional change:

  • the Combined functions were not compliant with the LLVM coding style, make them start with a lower case character. They were already "verb actions".
alekseyshl accepted this revision.Jul 13 2017, 1:41 PM
This revision is now accepted and ready to land.Jul 13 2017, 1:41 PM
cryptoad closed this revision.Jul 13 2017, 2:01 PM