[compiler-rt] r337557 - [scudo] Simplify internal names (NFC)

Kostya Kortchinsky via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 20 08:07:17 PDT 2018


Author: cryptoad
Date: Fri Jul 20 08:07:17 2018
New Revision: 337557

URL: http://llvm.org/viewvc/llvm-project?rev=337557&view=rev
Log:
[scudo] Simplify internal names (NFC)

Summary:
There is currently too much redundancy in the class/variable/* names in Scudo:
- we are in the namespace `__scudo`, so there is no point in having something
  named `ScudoX` to end up with a final name of `__scudo::ScudoX`;
- there are a lot of types/* that have `Allocator` in the name, given that
  Scudo is an allocator I figure this doubles up as well.

So change a bunch of the Scudo names to make them shorter, less redundant, and
overall simpler. They should still be pretty self explaining (or at least it
looks so to me).

The TSD part will be done in another CL (eg `__scudo::ScudoTSD`).

Reviewers: alekseyshl, eugenis

Reviewed By: alekseyshl

Subscribers: delcypher, #sanitizers, llvm-commits

Differential Revision: https://reviews.llvm.org/D49505

Modified:
    compiler-rt/trunk/lib/scudo/scudo_allocator.cpp
    compiler-rt/trunk/lib/scudo/scudo_allocator.h
    compiler-rt/trunk/lib/scudo/scudo_allocator_combined.h
    compiler-rt/trunk/lib/scudo/scudo_allocator_secondary.h
    compiler-rt/trunk/lib/scudo/scudo_tsd.h

Modified: compiler-rt/trunk/lib/scudo/scudo_allocator.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_allocator.cpp?rev=337557&r1=337556&r2=337557&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_allocator.cpp (original)
+++ compiler-rt/trunk/lib/scudo/scudo_allocator.cpp Fri Jul 20 08:07:17 2018
@@ -62,7 +62,7 @@ INLINE u32 computeCRC32(u32 Crc, uptr Va
 #endif  // defined(__SSE4_2__) || defined(__ARM_FEATURE_CRC32)
 }
 
-static ScudoBackendAllocator &getBackendAllocator();
+static BackendT &getBackend();
 
 namespace Chunk {
   static INLINE AtomicPackedHeader *getAtomicHeader(void *Ptr) {
@@ -92,9 +92,9 @@ namespace Chunk {
   static INLINE uptr getUsableSize(const void *Ptr, UnpackedHeader *Header) {
     const uptr ClassId = Header->ClassId;
     if (ClassId)
-      return PrimaryAllocator::ClassIdToSize(ClassId) - getHeaderSize() -
+      return PrimaryT::ClassIdToSize(ClassId) - getHeaderSize() -
           (Header->Offset << MinAlignmentLog);
-    return SecondaryAllocator::GetActuallyAllocatedSize(
+    return SecondaryT::GetActuallyAllocatedSize(
         getBackendPtr(Ptr, Header)) - getHeaderSize();
   }
 
@@ -103,7 +103,7 @@ namespace Chunk {
     const uptr SizeOrUnusedBytes = Header->SizeOrUnusedBytes;
     if (Header->ClassId)
       return SizeOrUnusedBytes;
-    return SecondaryAllocator::GetActuallyAllocatedSize(
+    return SecondaryT::GetActuallyAllocatedSize(
         getBackendPtr(Ptr, Header)) - getHeaderSize() - SizeOrUnusedBytes;
   }
 
@@ -175,7 +175,7 @@ namespace Chunk {
 }  // namespace Chunk
 
 struct QuarantineCallback {
-  explicit QuarantineCallback(AllocatorCache *Cache)
+  explicit QuarantineCallback(AllocatorCacheT *Cache)
     : Cache_(Cache) {}
 
   // Chunk recycling function, returns a quarantined chunk to the backend,
@@ -188,10 +188,9 @@ struct QuarantineCallback {
     Chunk::eraseHeader(Ptr);
     void *BackendPtr = Chunk::getBackendPtr(Ptr, &Header);
     if (Header.ClassId)
-      getBackendAllocator().deallocatePrimary(Cache_, BackendPtr,
-                                              Header.ClassId);
+      getBackend().deallocatePrimary(Cache_, BackendPtr, Header.ClassId);
     else
-      getBackendAllocator().deallocateSecondary(BackendPtr);
+      getBackend().deallocateSecondary(BackendPtr);
   }
 
   // Internal quarantine allocation and deallocation functions. We first check
@@ -199,34 +198,33 @@ struct QuarantineCallback {
   // TODO(kostyak): figure out the best way to protect the batches.
   void *Allocate(uptr Size) {
     const uptr BatchClassId = SizeClassMap::ClassID(sizeof(QuarantineBatch));
-    return getBackendAllocator().allocatePrimary(Cache_, BatchClassId);
+    return getBackend().allocatePrimary(Cache_, BatchClassId);
   }
 
   void Deallocate(void *Ptr) {
     const uptr BatchClassId = SizeClassMap::ClassID(sizeof(QuarantineBatch));
-    getBackendAllocator().deallocatePrimary(Cache_, Ptr, BatchClassId);
+    getBackend().deallocatePrimary(Cache_, Ptr, BatchClassId);
   }
 
-  AllocatorCache *Cache_;
+  AllocatorCacheT *Cache_;
   COMPILER_CHECK(sizeof(QuarantineBatch) < SizeClassMap::kMaxSize);
 };
 
-typedef Quarantine<QuarantineCallback, void> ScudoQuarantine;
-typedef ScudoQuarantine::Cache ScudoQuarantineCache;
-COMPILER_CHECK(sizeof(ScudoQuarantineCache) <=
+typedef Quarantine<QuarantineCallback, void> QuarantineT;
+typedef QuarantineT::Cache QuarantineCacheT;
+COMPILER_CHECK(sizeof(QuarantineCacheT) <=
                sizeof(ScudoTSD::QuarantineCachePlaceHolder));
 
-ScudoQuarantineCache *getQuarantineCache(ScudoTSD *TSD) {
-  return reinterpret_cast<ScudoQuarantineCache *>(
-      TSD->QuarantineCachePlaceHolder);
+QuarantineCacheT *getQuarantineCache(ScudoTSD *TSD) {
+  return reinterpret_cast<QuarantineCacheT *>(TSD->QuarantineCachePlaceHolder);
 }
 
-struct ScudoAllocator {
+struct Allocator {
   static const uptr MaxAllowedMallocSize =
       FIRST_32_SECOND_64(2UL << 30, 1ULL << 40);
 
-  ScudoBackendAllocator BackendAllocator;
-  ScudoQuarantine AllocatorQuarantine;
+  BackendT Backend;
+  QuarantineT Quarantine;
 
   u32 QuarantineChunksUpToSize;
 
@@ -240,8 +238,8 @@ struct ScudoAllocator {
   atomic_uint8_t RssLimitExceeded;
   atomic_uint64_t RssLastCheckedAtNS;
 
-  explicit ScudoAllocator(LinkerInitialized)
-    : AllocatorQuarantine(LINKER_INITIALIZED) {}
+  explicit Allocator(LinkerInitialized)
+    : Quarantine(LINKER_INITIALIZED) {}
 
   NOINLINE void performSanityChecks();
 
@@ -260,10 +258,10 @@ struct ScudoAllocator {
       atomic_store_relaxed(&HashAlgorithm, CRC32Hardware);
 
     SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);
-    BackendAllocator.init(common_flags()->allocator_release_to_os_interval_ms);
+    Backend.init(common_flags()->allocator_release_to_os_interval_ms);
     HardRssLimitMb = common_flags()->hard_rss_limit_mb;
     SoftRssLimitMb = common_flags()->soft_rss_limit_mb;
-    AllocatorQuarantine.Init(
+    Quarantine.Init(
         static_cast<uptr>(getFlags()->QuarantineSizeKb) << 10,
         static_cast<uptr>(getFlags()->ThreadLocalQuarantineSizeKb) << 10);
     QuarantineChunksUpToSize = getFlags()->QuarantineChunksUpToSize;
@@ -329,18 +327,18 @@ struct ScudoAllocator {
     void *BackendPtr;
     uptr BackendSize;
     u8 ClassId;
-    if (PrimaryAllocator::CanAllocate(AlignedSize, MinAlignment)) {
+    if (PrimaryT::CanAllocate(AlignedSize, MinAlignment)) {
       BackendSize = AlignedSize;
       ClassId = SizeClassMap::ClassID(BackendSize);
       bool UnlockRequired;
       ScudoTSD *TSD = getTSDAndLock(&UnlockRequired);
-      BackendPtr = BackendAllocator.allocatePrimary(&TSD->Cache, ClassId);
+      BackendPtr = Backend.allocatePrimary(&TSD->Cache, ClassId);
       if (UnlockRequired)
         TSD->unlock();
     } else {
       BackendSize = NeededSize;
       ClassId = 0;
-      BackendPtr = BackendAllocator.allocateSecondary(BackendSize, Alignment);
+      BackendPtr = Backend.allocateSecondary(BackendSize, Alignment);
     }
     if (UNLIKELY(!BackendPtr)) {
       SetAllocatorOutOfMemory();
@@ -351,7 +349,7 @@ struct ScudoAllocator {
 
     // If requested, we will zero out the entire contents of the returned chunk.
     if ((ForceZeroContents || ZeroContents) && ClassId)
-      memset(BackendPtr, 0, PrimaryAllocator::ClassIdToSize(ClassId));
+      memset(BackendPtr, 0, PrimaryT::ClassIdToSize(ClassId));
 
     UnpackedHeader Header = {};
     uptr UserPtr = reinterpret_cast<uptr>(BackendPtr) + Chunk::getHeaderSize();
@@ -391,7 +389,7 @@ struct ScudoAllocator {
   // quarantine chunk size threshold.
   void quarantineOrDeallocateChunk(void *Ptr, UnpackedHeader *Header,
                                    uptr Size) {
-    const bool BypassQuarantine = (AllocatorQuarantine.GetCacheSize() == 0) ||
+    const bool BypassQuarantine = (Quarantine.GetCacheSize() == 0) ||
         (Size > QuarantineChunksUpToSize);
     if (BypassQuarantine) {
       Chunk::eraseHeader(Ptr);
@@ -399,12 +397,12 @@ struct ScudoAllocator {
       if (Header->ClassId) {
         bool UnlockRequired;
         ScudoTSD *TSD = getTSDAndLock(&UnlockRequired);
-        getBackendAllocator().deallocatePrimary(&TSD->Cache, BackendPtr,
-                                                Header->ClassId);
+        getBackend().deallocatePrimary(&TSD->Cache, BackendPtr,
+                                       Header->ClassId);
         if (UnlockRequired)
           TSD->unlock();
       } else {
-        getBackendAllocator().deallocateSecondary(BackendPtr);
+        getBackend().deallocateSecondary(BackendPtr);
       }
     } else {
       // If a small memory amount was allocated with a larger alignment, we want
@@ -418,9 +416,8 @@ struct ScudoAllocator {
       Chunk::compareExchangeHeader(Ptr, &NewHeader, Header);
       bool UnlockRequired;
       ScudoTSD *TSD = getTSDAndLock(&UnlockRequired);
-      AllocatorQuarantine.Put(getQuarantineCache(TSD),
-                              QuarantineCallback(&TSD->Cache), Ptr,
-                              EstimatedSize);
+      Quarantine.Put(getQuarantineCache(TSD), QuarantineCallback(&TSD->Cache),
+                     Ptr, EstimatedSize);
       if (UnlockRequired)
         TSD->unlock();
     }
@@ -530,15 +527,14 @@ struct ScudoAllocator {
   }
 
   void commitBack(ScudoTSD *TSD) {
-    AllocatorQuarantine.Drain(getQuarantineCache(TSD),
-                              QuarantineCallback(&TSD->Cache));
-    BackendAllocator.destroyCache(&TSD->Cache);
+    Quarantine.Drain(getQuarantineCache(TSD), QuarantineCallback(&TSD->Cache));
+    Backend.destroyCache(&TSD->Cache);
   }
 
   uptr getStats(AllocatorStat StatType) {
     initThreadMaybe();
     uptr stats[AllocatorStatCount];
-    BackendAllocator.getStats(stats);
+    Backend.getStats(stats);
     return stats[StatType];
   }
 
@@ -557,11 +553,11 @@ struct ScudoAllocator {
 
   void printStats() {
     initThreadMaybe();
-    BackendAllocator.printStats();
+    Backend.printStats();
   }
 };
 
-NOINLINE void ScudoAllocator::performSanityChecks() {
+NOINLINE void Allocator::performSanityChecks() {
   // Verify that the header offset field can hold the maximum offset. In the
   // case of the Secondary allocator, it takes care of alignment and the
   // offset will always be 0. In the case of the Primary, the worst case
@@ -596,7 +592,7 @@ NOINLINE void ScudoAllocator::performSan
 
 // Opportunistic RSS limit check. This will update the RSS limit status, if
 // it can, every 100ms, otherwise it will just return the current one.
-NOINLINE bool ScudoAllocator::isRssLimitExceeded() {
+NOINLINE bool Allocator::isRssLimitExceeded() {
   u64 LastCheck = atomic_load_relaxed(&RssLastCheckedAtNS);
   const u64 CurrentCheck = MonotonicNanoTime();
   if (LIKELY(CurrentCheck < LastCheck + (100ULL * 1000000ULL)))
@@ -626,10 +622,10 @@ NOINLINE bool ScudoAllocator::isRssLimit
   return atomic_load_relaxed(&RssLimitExceeded);
 }
 
-static ScudoAllocator Instance(LINKER_INITIALIZED);
+static Allocator Instance(LINKER_INITIALIZED);
 
-static ScudoBackendAllocator &getBackendAllocator() {
-  return Instance.BackendAllocator;
+static BackendT &getBackend() {
+  return Instance.Backend;
 }
 
 void initScudo() {
@@ -637,7 +633,7 @@ void initScudo() {
 }
 
 void ScudoTSD::init() {
-  getBackendAllocator().initCache(&Cache);
+  getBackend().initCache(&Cache);
   memset(QuarantineCachePlaceHolder, 0, sizeof(QuarantineCachePlaceHolder));
 }
 

Modified: compiler-rt/trunk/lib/scudo/scudo_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_allocator.h?rev=337557&r1=337556&r2=337557&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_allocator.h (original)
+++ compiler-rt/trunk/lib/scudo/scudo_allocator.h Fri Jul 20 08:07:17 2018
@@ -82,7 +82,7 @@ struct AP64 {
   static const uptr kFlags =
       SizeClassAllocator64FlagMasks::kRandomShuffleChunks;
 };
-typedef SizeClassAllocator64<AP64> PrimaryAllocator;
+typedef SizeClassAllocator64<AP64> PrimaryT;
 #else
 static const uptr NumRegions = SANITIZER_MMAP_RANGE_SIZE >> RegionSizeLog;
 # if SANITIZER_WORDSIZE == 32
@@ -102,16 +102,15 @@ struct AP32 {
       SizeClassAllocator32FlagMasks::kRandomShuffleChunks |
       SizeClassAllocator32FlagMasks::kUseSeparateSizeClassForBatch;
 };
-typedef SizeClassAllocator32<AP32> PrimaryAllocator;
+typedef SizeClassAllocator32<AP32> PrimaryT;
 #endif  // SANITIZER_CAN_USE_ALLOCATOR64
 
 #include "scudo_allocator_secondary.h"
 #include "scudo_allocator_combined.h"
 
-typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
-typedef ScudoLargeMmapAllocator SecondaryAllocator;
-typedef ScudoCombinedAllocator<PrimaryAllocator, AllocatorCache,
-    SecondaryAllocator> ScudoBackendAllocator;
+typedef SizeClassAllocatorLocalCache<PrimaryT> AllocatorCacheT;
+typedef LargeMmapAllocator SecondaryT;
+typedef CombinedAllocator<PrimaryT, AllocatorCacheT, SecondaryT> BackendT;
 
 void initScudo();
 

Modified: compiler-rt/trunk/lib/scudo/scudo_allocator_combined.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_allocator_combined.h?rev=337557&r1=337556&r2=337557&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_allocator_combined.h (original)
+++ compiler-rt/trunk/lib/scudo/scudo_allocator_combined.h Fri Jul 20 08:07:17 2018
@@ -16,12 +16,12 @@
 #define SCUDO_ALLOCATOR_COMBINED_H_
 
 #ifndef SCUDO_ALLOCATOR_H_
-#error "This file must be included inside scudo_allocator.h."
+# error "This file must be included inside scudo_allocator.h."
 #endif
 
 template <class PrimaryAllocator, class AllocatorCache,
     class SecondaryAllocator>
-class ScudoCombinedAllocator {
+class CombinedAllocator {
  public:
   void init(s32 ReleaseToOSIntervalMs) {
     Primary.Init(ReleaseToOSIntervalMs);

Modified: compiler-rt/trunk/lib/scudo/scudo_allocator_secondary.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_allocator_secondary.h?rev=337557&r1=337556&r2=337557&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_allocator_secondary.h (original)
+++ compiler-rt/trunk/lib/scudo/scudo_allocator_secondary.h Fri Jul 20 08:07:17 2018
@@ -66,7 +66,7 @@ namespace LargeChunk {
   }
 }  // namespace LargeChunk
 
-class ScudoLargeMmapAllocator {
+class LargeMmapAllocator {
  public:
   void Init() {
     internal_memset(this, 0, sizeof(*this));

Modified: compiler-rt/trunk/lib/scudo/scudo_tsd.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_tsd.h?rev=337557&r1=337556&r2=337557&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_tsd.h (original)
+++ compiler-rt/trunk/lib/scudo/scudo_tsd.h Fri Jul 20 08:07:17 2018
@@ -24,7 +24,7 @@
 namespace __scudo {
 
 struct ALIGNED(SANITIZER_CACHE_LINE_SIZE) ScudoTSD {
-  AllocatorCache Cache;
+  AllocatorCacheT Cache;
   uptr QuarantineCachePlaceHolder[4];
 
   void init();




More information about the llvm-commits mailing list