This is an archive of the discontinued LLVM Phabricator instance.

Fix the configuration of the Primary allocator for Darwin ARM64
ClosedPublic

Authored by delcypher on Aug 23 2018, 10:13 AM.

Details

Summary

Fix the configuration of the Primary allocator for Darwin ARM64 by
changing the value of SANITIZER_MMAP_RANGE_SIZE to something more
sensible. The available VMA is at most 64GiB and not 256TiB that
was previously being used.

This change gives us several wins:

  • Drastically improves LeakSanitizer performance on Darwin ARM64 devices. On a simple synthentic benchmark this took leak detection time from ~30 seconds to 0.5 seconds due to the ForEachChunk(...) method enumerating a much smaller number of regions. Previously we would pointlessly iterate over a large portion of the SizeClassAllocator32's ByteMap that would could never be set due it being configured for a much larger VM space than is actually availble.
  • Decreases the memory required for the Primary allocator. Previously the ByteMap inside the the allocator used an array of pointers that took 512KiB of space. Now the required space for the array is 128 bytes.

rdar://problem/43509428

Diff Detail

Event Timeline

delcypher created this revision.Aug 23 2018, 10:13 AM
Herald added subscribers: Restricted Project, chrib, kristof.beyls. · View Herald Transcript
cryptoad accepted this revision.Aug 23 2018, 10:21 AM

LGTM with a nit.
Additional question but that doesn't require changes to the CL: if you have a ByteMap it means you are using the SizeClassAllocator32 in 64-bit mode (it's gated by a define, look for SANITIZER_CAN_USE_ALLOCATOR64).
Have you tried using the SizeClassAllocator64?

lib/sanitizer_common/sanitizer_platform.h
238

nit: use 1 space for define indentation to conform with the rest of the file.

This revision is now accepted and ready to land.Aug 23 2018, 10:21 AM

LGTM with a nit.
Additional question but that doesn't require changes to the CL: if you have a ByteMap it means you are using the SizeClassAllocator32 in 64-bit mode (it's gated by a define, look for SANITIZER_CAN_USE_ALLOCATOR64).
Have you tried using the SizeClassAllocator64?

@cryptoad

Yes I tried to use it and I couldn't get it to work with such a small VM space.

On the arm64 device I was using the "high mem" region is ~48GiB. This is portion of the VM space I wanted the SizeClassAllocator64 to use but it seems this region is too small for the allocator. The SizeClassAllocator64 has this compile time assert that I cannot satisfy.

// kRegionSize must be >= 2^32.
 COMPILER_CHECK((kRegionSize) >= (1ULL << (SANITIZER_WORDSIZE / 2)));

This is basically kRegionSize >= 4GiB. kRegionSize is computed as

static const uptr kRegionSize = kSpaceSize / kNumClassesRounded;

The smallest possible value for kNumClassesRounded is 32 which then implies we require that (kSpaceSize /32) >= 4GiB this then implies that kSpaceSize >= 128GiB. So the allocator needs at least 128GiB but we only have ~48GiB available at most. This means it's impossible to satisfy the requirements of the SizeClassAllocator64 on arm64 Darwin right now.

lib/sanitizer_common/sanitizer_platform.h
238

Oops I didn't notice that. I'll fix it.

delcypher updated this revision to Diff 162269.Aug 23 2018, 2:24 PM

Fix indentation of macros

This revision was automatically updated to reflect the committed changes.