Skip to content

Commit 048ece4

Browse files
authored
[scudo] Calling initCache() in init() of SizeClassAllocatorLocalCache (#71427)
initCacheMaybe() will init all the size class arrays at once and it doesn't have much work to do even if it supports partial initialization. This avoids the call to initCacheMaybe in each allocate()/deallocate().
1 parent 34f83e8 commit 048ece4

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

compiler-rt/lib/scudo/standalone/local_cache.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
2828
if (LIKELY(S))
2929
S->link(&Stats);
3030
Allocator = A;
31+
initCache();
3132
}
3233

3334
void destroy(GlobalStats *S) {
@@ -40,8 +41,6 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
4041
DCHECK_LT(ClassId, NumClasses);
4142
PerClass *C = &PerClassArray[ClassId];
4243
if (C->Count == 0) {
43-
initCacheMaybe(C);
44-
4544
// Refill half of the number of max cached.
4645
DCHECK_GT(C->MaxCount / 2, 0U);
4746
if (UNLIKELY(!refill(C, ClassId, C->MaxCount / 2)))
@@ -61,9 +60,6 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
6160
bool deallocate(uptr ClassId, void *P) {
6261
CHECK_LT(ClassId, NumClasses);
6362
PerClass *C = &PerClassArray[ClassId];
64-
// We still have to initialize the cache in the event that the first heap
65-
// operation in a thread is a deallocation.
66-
initCacheMaybe(C);
6763

6864
// If the cache is full, drain half of blocks back to the main allocator.
6965
const bool NeedToDrainCache = C->Count == C->MaxCount;
@@ -150,13 +146,6 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
150146
LocalStats Stats;
151147
SizeClassAllocator *Allocator = nullptr;
152148

153-
ALWAYS_INLINE void initCacheMaybe(PerClass *C) {
154-
if (LIKELY(C->MaxCount))
155-
return;
156-
initCache();
157-
DCHECK_NE(C->MaxCount, 0U);
158-
}
159-
160149
NOINLINE void initCache() {
161150
for (uptr I = 0; I < NumClasses; I++) {
162151
PerClass *P = &PerClassArray[I];

0 commit comments

Comments
 (0)