diff options
| author | Kostya Kortchinsky <kostyak@google.com> | 2017-09-22 15:35:37 +0000 |
|---|---|---|
| committer | Kostya Kortchinsky <kostyak@google.com> | 2017-09-22 15:35:37 +0000 |
| commit | 392480952c4e0081a932eb9ea093bd54f15e47ff (patch) | |
| tree | 352d746681808e6837e177988a73fd27696bce11 /compiler-rt/lib/scudo/scudo_allocator.cpp | |
| parent | ae42181db46e20055e7581ca94380ed0886fe2df (diff) | |
| download | bcm5719-llvm-392480952c4e0081a932eb9ea093bd54f15e47ff.tar.gz bcm5719-llvm-392480952c4e0081a932eb9ea093bd54f15e47ff.zip | |
[scudo] Scudo thread specific data refactor, part 1
Summary:
We are going through an overhaul of Scudo's TSD, to allow for new platforms
to be integrated more easily, and make the code more sound.
This first part is mostly renaming, preferring some shorter names, correcting
some comments. I removed `getPrng` and `getAllocatorCache` to directly access
the members, there was not really any benefit to them (and it was suggested by
Dmitry in D37590).
The only functional change is in `scudo_tls_android.cpp`: we enforce bounds to
the `NumberOfTSDs` and most of the logic in `getTSDAndLockSlow` is skipped if we
only have 1 TSD.
Reviewers: alekseyshl, dvyukov, kcc
Reviewed By: dvyukov
Subscribers: llvm-commits, srhines
Differential Revision: https://reviews.llvm.org/D38139
llvm-svn: 313987
Diffstat (limited to 'compiler-rt/lib/scudo/scudo_allocator.cpp')
| -rw-r--r-- | compiler-rt/lib/scudo/scudo_allocator.cpp | 60 |
1 files changed, 24 insertions, 36 deletions
diff --git a/compiler-rt/lib/scudo/scudo_allocator.cpp b/compiler-rt/lib/scudo/scudo_allocator.cpp index 9d65b86832f..e490a469d87 100644 --- a/compiler-rt/lib/scudo/scudo_allocator.cpp +++ b/compiler-rt/lib/scudo/scudo_allocator.cpp @@ -250,19 +250,11 @@ struct QuarantineCallback { typedef Quarantine<QuarantineCallback, ScudoChunk> ScudoQuarantine; typedef ScudoQuarantine::Cache ScudoQuarantineCache; COMPILER_CHECK(sizeof(ScudoQuarantineCache) <= - sizeof(ScudoThreadContext::QuarantineCachePlaceHolder)); + sizeof(ScudoTSD::QuarantineCachePlaceHolder)); -AllocatorCache *getAllocatorCache(ScudoThreadContext *ThreadContext) { - return &ThreadContext->Cache; -} - -ScudoQuarantineCache *getQuarantineCache(ScudoThreadContext *ThreadContext) { - return reinterpret_cast< - ScudoQuarantineCache *>(ThreadContext->QuarantineCachePlaceHolder); -} - -ScudoPrng *getPrng(ScudoThreadContext *ThreadContext) { - return &ThreadContext->Prng; +ScudoQuarantineCache *getQuarantineCache(ScudoTSD *TSD) { + return reinterpret_cast<ScudoQuarantineCache *>( + TSD->QuarantineCachePlaceHolder); } struct ScudoAllocator { @@ -381,12 +373,11 @@ struct ScudoAllocator { uptr AllocSize; if (FromPrimary) { AllocSize = AlignedSize; - ScudoThreadContext *ThreadContext = getThreadContextAndLock(); - if (LIKELY(ThreadContext)) { - Salt = getPrng(ThreadContext)->getU8(); - Ptr = BackendAllocator.allocatePrimary(getAllocatorCache(ThreadContext), - AllocSize); - ThreadContext->unlock(); + ScudoTSD *TSD = getTSDAndLock(); + if (LIKELY(TSD)) { + Salt = TSD->Prng.getU8(); + Ptr = BackendAllocator.allocatePrimary(&TSD->Cache, AllocSize); + TSD->unlock(); } else { SpinMutexLock l(&FallbackMutex); Salt = FallbackPrng.getU8(); @@ -454,11 +445,10 @@ struct ScudoAllocator { Chunk->eraseHeader(); void *Ptr = Chunk->getAllocBeg(Header); if (Header->FromPrimary) { - ScudoThreadContext *ThreadContext = getThreadContextAndLock(); - if (LIKELY(ThreadContext)) { - getBackendAllocator().deallocatePrimary( - getAllocatorCache(ThreadContext), Ptr); - ThreadContext->unlock(); + ScudoTSD *TSD = getTSDAndLock(); + if (LIKELY(TSD)) { + getBackendAllocator().deallocatePrimary(&TSD->Cache, Ptr); + TSD->unlock(); } else { SpinMutexLock Lock(&FallbackMutex); getBackendAllocator().deallocatePrimary(&FallbackAllocatorCache, Ptr); @@ -476,13 +466,12 @@ struct ScudoAllocator { UnpackedHeader NewHeader = *Header; NewHeader.State = ChunkQuarantine; Chunk->compareExchangeHeader(&NewHeader, Header); - ScudoThreadContext *ThreadContext = getThreadContextAndLock(); - if (LIKELY(ThreadContext)) { - AllocatorQuarantine.Put(getQuarantineCache(ThreadContext), - QuarantineCallback( - getAllocatorCache(ThreadContext)), + ScudoTSD *TSD = getTSDAndLock(); + if (LIKELY(TSD)) { + AllocatorQuarantine.Put(getQuarantineCache(TSD), + QuarantineCallback(&TSD->Cache), Chunk, EstimatedSize); - ThreadContext->unlock(); + TSD->unlock(); } else { SpinMutexLock l(&FallbackMutex); AllocatorQuarantine.Put(&FallbackQuarantineCache, @@ -607,11 +596,10 @@ struct ScudoAllocator { return allocate(NMemB * Size, MinAlignment, FromMalloc, true); } - void commitBack(ScudoThreadContext *ThreadContext) { - AllocatorCache *Cache = getAllocatorCache(ThreadContext); - AllocatorQuarantine.Drain(getQuarantineCache(ThreadContext), - QuarantineCallback(Cache)); - BackendAllocator.destroyCache(Cache); + void commitBack(ScudoTSD *TSD) { + AllocatorQuarantine.Drain(getQuarantineCache(TSD), + QuarantineCallback(&TSD->Cache)); + BackendAllocator.destroyCache(&TSD->Cache); } uptr getStats(AllocatorStat StatType) { @@ -637,13 +625,13 @@ static void initScudoInternal(const AllocatorOptions &Options) { Instance.init(Options); } -void ScudoThreadContext::init() { +void ScudoTSD::init() { getBackendAllocator().initCache(&Cache); Prng.init(); memset(QuarantineCachePlaceHolder, 0, sizeof(QuarantineCachePlaceHolder)); } -void ScudoThreadContext::commitBack() { +void ScudoTSD::commitBack() { Instance.commitBack(this); } |

