This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Add macro for specifying number of pages to allocate for LowLevelAllocator
ClosedPublic

Authored by leonardchan on Aug 24 2023, 2:41 PM.

Details

Summary

The LowLevelAllocator is a helper class used by many sanitizer internals for anonymously mmaping stuff. The allocator (usually) maps one page at a time, but this can lead to a lot of fragmentation if the allocator is heavily used. The flag parser is an example of this where it needs to do lots of string copying that need to exist for a variable length of time.

This adds a macro for specifying the number of pages the LowLevelAllocator can make at a time, which locally I've found to significantly help reduce fragmentation and help run the scudo allocator tests in an asan-instrumented build on riscv Sv39. This is a static macro rather than a value that could be provided via an env variable because flag parsing is one of the earliest consumers of the LowLevelAllocator, so this should be set before its ever used.

Note this will mainly help instances of the LowLevelAllocator that are heavily used, but instances of the LowLevelAllocator that do a small fixed number of allocations won't benefit as much from this. This can be alleviated though if we instead consolidate all of them to one single LowLevelAllocator (D158786).

Diff Detail

Event Timeline

leonardchan created this revision.Aug 24 2023, 2:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2023, 2:41 PM
leonardchan requested review of this revision.Aug 24 2023, 2:41 PM
vitalybuka accepted this revision.Aug 25 2023, 3:15 PM
vitalybuka added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp
150–151

I don't know good reasons to keep 1 page by default, just make 16 for everyone.

compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
92 ↗(On Diff #553265)

it does not need to be in common headers

This revision is now accepted and ready to land.Aug 25 2023, 3:15 PM
MaskRay added inline comments.Aug 26 2023, 4:52 PM
compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp
150–151

If the page size is 16k or 64k, 16 pages seems too much.

MaskRay added inline comments.Aug 26 2023, 4:55 PM
compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp
150–151

Perhaps min(GetPageSizeCached()*16, 65536)

This revision was automatically updated to reflect the committed changes.
leonardchan marked 4 inline comments as done.