[compiler-rt] 78c5754 - [sanitizer] Uninline slow path of PersistentAllocator::alloc
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 7 13:54:17 PDT 2021
Author: Vitaly Buka
Date: 2021-10-07T13:54:01-07:00
New Revision: 78c5754813f3525ff249780a19198894bd336b78
URL: https://github.com/llvm/llvm-project/commit/78c5754813f3525ff249780a19198894bd336b78
DIFF: https://github.com/llvm/llvm-project/commit/78c5754813f3525ff249780a19198894bd336b78.diff
LOG: [sanitizer] Uninline slow path of PersistentAllocator::alloc
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp
compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp
index 1ca0375b8a54c..04d4c2829a540 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 de4fb6ebc3cf8..ae3a023d0786c 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;
More information about the llvm-commits
mailing list