From 78c5754813f3525ff249780a19198894bd336b78 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Thu, 7 Oct 2021 10:13:00 -0700 Subject: [PATCH] [sanitizer] Uninline slow path of PersistentAllocator::alloc --- .../sanitizer_persistent_allocator.cpp | 17 +++++++++++++++++ .../sanitizer_persistent_allocator.h | 14 ++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp index 1ca0375b8a54..04d4c2829a54 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp @@ -15,4 +15,21 @@ namespace __sanitizer { PersistentAllocator thePersistentAllocator; +void *PersistentAllocator::refillAndAlloc(uptr size) { + // If failed, lock, retry and alloc new superblock. + SpinMutexLock l(&mtx); + for (;;) { + void *s = tryAlloc(size); + if (s) + return s; + atomic_store(®ion_pos, 0, memory_order_relaxed); + uptr allocsz = 64 * 1024; + if (allocsz < size) + allocsz = size; + uptr mem = (uptr)MmapOrDie(allocsz, "stack depot"); + atomic_store(®ion_end, mem + allocsz, memory_order_release); + atomic_store(®ion_pos, mem, memory_order_release); + } +} + } // namespace __sanitizer diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h b/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h index de4fb6ebc3cf..ae3a023d0786 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h @@ -26,6 +26,7 @@ class PersistentAllocator { private: void *tryAlloc(uptr size); + void *refillAndAlloc(uptr size); StaticSpinMutex mtx; // Protects alloc of new blocks for region allocator. atomic_uintptr_t region_pos; // Region allocator for Node's. atomic_uintptr_t region_end; @@ -47,18 +48,7 @@ inline void *PersistentAllocator::alloc(uptr size) { // First, try to allocate optimisitically. void *s = tryAlloc(size); if (s) return s; - // If failed, lock, retry and alloc new superblock. - SpinMutexLock l(&mtx); - for (;;) { - s = tryAlloc(size); - if (s) return s; - atomic_store(®ion_pos, 0, memory_order_relaxed); - uptr allocsz = 64 * 1024; - if (allocsz < size) allocsz = size; - uptr mem = (uptr)MmapOrDie(allocsz, "stack depot"); - atomic_store(®ion_end, mem + allocsz, memory_order_release); - atomic_store(®ion_pos, mem, memory_order_release); - } + return refillAndAlloc(size); } extern PersistentAllocator thePersistentAllocator;