Index: lib/sanitizer_common/sanitizer_allocator_local_cache.h =================================================================== --- lib/sanitizer_common/sanitizer_allocator_local_cache.h +++ lib/sanitizer_common/sanitizer_allocator_local_cache.h @@ -180,7 +180,7 @@ PerClass *c = &per_class_[class_id]; InitCache(c); if (UNLIKELY(c->count == c->max_count)) - Drain(c, allocator, class_id); + Drain(c, allocator, class_id, c->max_count / 2); c->batch[c->count++] = p; stats_.Sub(AllocatorStatAllocated, c->class_size); } @@ -189,7 +189,7 @@ for (uptr i = 1; i < kNumClasses; i++) { PerClass *c = &per_class_[i]; while (c->count > 0) - Drain(c, allocator, i); + Drain(c, allocator, i, Min(c->max_count / 2, c->count)); } } @@ -253,8 +253,7 @@ } NOINLINE void Drain(PerClass *c, SizeClassAllocator *allocator, - uptr class_id) { - const uptr count = Min(c->max_count / 2, c->count); + uptr class_id, uptr count) { const uptr first_idx_to_drain = c->count - count; TransferBatch *b = CreateBatch( class_id, allocator, (TransferBatch *)c->batch[first_idx_to_drain]); Index: lib/sanitizer_common/sanitizer_allocator_primary32.h =================================================================== --- lib/sanitizer_common/sanitizer_allocator_primary32.h +++ lib/sanitizer_common/sanitizer_allocator_primary32.h @@ -64,8 +64,8 @@ struct TransferBatch { static const uptr kMaxNumCached = SizeClassMap::kMaxNumCachedHint - 2; void SetFromArray(void *batch[], uptr count) { + DCHECK_LE(count, kMaxNumCached); count_ = count; - CHECK_LE(count_, kMaxNumCached); for (uptr i = 0; i < count; i++) batch_[i] = batch[i]; } @@ -73,9 +73,9 @@ void Clear() { count_ = 0; } void Add(void *ptr) { batch_[count_++] = ptr; - CHECK_LE(count_, kMaxNumCached); + DCHECK_LE(count_, kMaxNumCached); } - void CopyToArray(void *to_batch[]) { + void CopyToArray(void *to_batch[]) const { for (uptr i = 0, n = Count(); i < n; i++) to_batch[i] = batch_[i]; } @@ -153,7 +153,7 @@ NOINLINE TransferBatch *AllocateBatch(AllocatorStats *stat, AllocatorCache *c, uptr class_id) { - CHECK_LT(class_id, kNumClasses); + DCHECK_LT(class_id, kNumClasses); SizeClassInfo *sci = GetSizeClassInfo(class_id); SpinMutexLock l(&sci->mutex); if (sci->free_list.empty()) { @@ -168,15 +168,13 @@ NOINLINE void DeallocateBatch(AllocatorStats *stat, uptr class_id, TransferBatch *b) { - CHECK_LT(class_id, kNumClasses); + DCHECK_LT(class_id, kNumClasses); CHECK_GT(b->Count(), 0); SizeClassInfo *sci = GetSizeClassInfo(class_id); SpinMutexLock l(&sci->mutex); sci->free_list.push_front(b); } - uptr GetRegionBeginBySizeClass(uptr class_id) { return 0; } - bool PointerIsMine(const void *p) { uptr mem = reinterpret_cast(p); if (mem < kSpaceBeg || mem >= kSpaceBeg + kSpaceSize) @@ -252,12 +250,9 @@ } } - void PrintStats() { - } + void PrintStats() {} - static uptr AdditionalSize() { - return 0; - } + static uptr AdditionalSize() { return 0; } typedef SizeClassMap SizeClassMapT; static const uptr kNumClasses = SizeClassMap::kNumClasses; @@ -267,7 +262,7 @@ static const uptr kNumPossibleRegions = kSpaceSize / kRegionSize; struct ALIGNED(SANITIZER_CACHE_LINE_SIZE) SizeClassInfo { - SpinMutex mutex; + StaticSpinMutex mutex; IntrusiveList free_list; u32 rand_state; }; @@ -284,8 +279,8 @@ } uptr AllocateRegion(AllocatorStats *stat, uptr class_id) { - CHECK_LT(class_id, kNumClasses); - uptr res = reinterpret_cast(MmapAlignedOrDieOnFatalError( + DCHECK_LT(class_id, kNumClasses); + const uptr res = reinterpret_cast(MmapAlignedOrDieOnFatalError( kRegionSize, kRegionSize, PrimaryAllocatorName)); if (UNLIKELY(!res)) return 0; @@ -306,8 +301,11 @@ uptr *pointers_array, uptr count) { // If using a separate class for batches, we do not need to shuffle it. if (kRandomShuffleChunks && (!kUseSeparateSizeClassForBatch || - class_id != SizeClassMap::kBatchClassID)) - RandomShuffle(pointers_array, count, &sci->rand_state); + class_id != SizeClassMap::kBatchClassID)) { + u32 rand_state = sci->rand_state; + RandomShuffle(pointers_array, count, &rand_state); + sci->rand_state = rand_state; + } TransferBatch *b = *current_batch; for (uptr i = 0; i < count; i++) { if (!b) {