[PATCH] D44261: [sanitizer] Align & pad the allocator structures to the cacheline size

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 9 08:21:00 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL327145: [sanitizer] Align & pad the allocator structures to the cacheline size (authored by cryptoad, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D44261

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary32.h
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary64.h
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary64.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary64.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary64.h
@@ -80,6 +80,8 @@
     }
     SetReleaseToOSIntervalMs(release_to_os_interval_ms);
     MapWithCallbackOrDie(SpaceEnd(), AdditionalSize());
+    // Check that the RegionInfo array is aligned on the CacheLine size.
+    DCHECK_EQ(SpaceEnd() & (kCacheLineSize - 1), 0);
   }
 
   s32 ReleaseToOSIntervalMs() const {
@@ -302,7 +304,7 @@
 
   static uptr AdditionalSize() {
     return RoundUpTo(sizeof(RegionInfo) * kNumClassesRounded,
-                     GetPageSizeCached());
+        GetPageSizeCached());
   }
 
   typedef SizeClassMap SizeClassMapT;
@@ -584,7 +586,7 @@
     u64 last_released_bytes;
   };
 
-  struct RegionInfo {
+  struct ALIGNED(kCacheLineSize) RegionInfo {
     BlockingMutex mutex;
     uptr num_freed_chunks;  // Number of elements in the freearray.
     uptr mapped_free_array;  // Bytes mapped for freearray.
@@ -597,12 +599,11 @@
     Stats stats;
     ReleaseToOsInfo rtoi;
   };
-  COMPILER_CHECK(sizeof(RegionInfo) >= kCacheLineSize);
+  COMPILER_CHECK(sizeof(RegionInfo) % kCacheLineSize == 0);
 
   RegionInfo *GetRegionInfo(uptr class_id) const {
-    CHECK_LT(class_id, kNumClasses);
-    RegionInfo *regions =
-        reinterpret_cast<RegionInfo *>(SpaceBeg() + kSpaceSize);
+    DCHECK_LT(class_id, kNumClasses);
+    RegionInfo *regions = reinterpret_cast<RegionInfo *>(SpaceEnd());
     return &regions[class_id];
   }
 
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary32.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary32.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary32.h
@@ -266,14 +266,12 @@
   static const uptr kRegionSize = 1 << kRegionSizeLog;
   static const uptr kNumPossibleRegions = kSpaceSize / kRegionSize;
 
-  struct SizeClassInfo {
+  struct ALIGNED(kCacheLineSize) SizeClassInfo {
     SpinMutex mutex;
     IntrusiveList<TransferBatch> free_list;
     u32 rand_state;
-    char padding[kCacheLineSize - 2 * sizeof(uptr) -
-                 sizeof(IntrusiveList<TransferBatch>)];
   };
-  COMPILER_CHECK(sizeof(SizeClassInfo) == kCacheLineSize);
+  COMPILER_CHECK(sizeof(SizeClassInfo) % kCacheLineSize == 0);
 
   uptr ComputeRegionId(uptr mem) {
     const uptr res = mem >> kRegionSizeLog;
@@ -299,7 +297,7 @@
   }
 
   SizeClassInfo *GetSizeClassInfo(uptr class_id) {
-    CHECK_LT(class_id, kNumClasses);
+    DCHECK_LT(class_id, kNumClasses);
     return &size_class_info_array[class_id];
   }
 
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
@@ -40,10 +40,12 @@
 const uptr kWordSizeInBits = 8 * kWordSize;
 
 #if defined(__powerpc__) || defined(__powerpc64__)
-  const uptr kCacheLineSize = 128;
+  constexpr uptr kCacheLineSize = 128;
 #else
-  const uptr kCacheLineSize = 64;
+  constexpr uptr kCacheLineSize = 64;
 #endif
+// Check that the CacheLine size is a power-of-two.
+COMPILER_CHECK((kCacheLineSize & (kCacheLineSize - 1)) == 0);
 
 const uptr kMaxPathLength = 4096;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44261.137758.patch
Type: text/x-patch
Size: 3497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180309/673988d2/attachment.bin>


More information about the llvm-commits mailing list