diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp @@ -145,7 +145,8 @@ // Align allocation size. size = RoundUpTo(size, low_level_alloc_min_alignment); if (allocated_end_ - allocated_current_ < (sptr)size) { - uptr size_to_allocate = RoundUpTo(size, GetPageSizeCached()); + uptr size_to_allocate = RoundUpTo( + size, GetPageSizeCached() * SANITIZER_LOW_LEVEL_ALLOCATOR_NUM_PAGES); allocated_current_ = (char *)MmapOrDie(size_to_allocate, __func__); allocated_end_ = allocated_current_ + size_to_allocate; if (low_level_alloc_callback) { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h @@ -86,6 +86,17 @@ // And then use it as: if (compare_hook) compare_hook(a, b); //----------------------------------------------------------------------------// +// This defines the minimum number of pages the LowLevelAllocator will mmap when +// it needs more space for an allocation. Increasing this will reduce +// fragmentation for heavily used LowLevelAllocators but less space-efficient +// for allocators used a few times. +#ifndef SANITIZER_LOW_LEVEL_ALLOCATOR_NUM_PAGES +# if SANITIZER_FUCHSIA +# define SANITIZER_LOW_LEVEL_ALLOCATOR_NUM_PAGES 16 +# else +# define SANITIZER_LOW_LEVEL_ALLOCATOR_NUM_PAGES 1 +# endif +#endif // defined(SANITIZER_LOW_LEVEL_ALLOCATOR_NUM_PAGES) // We can use .preinit_array section on Linux to call sanitizer initialization // functions very early in the process startup (unless PIC macro is defined).