[PATCH] D44326: [sanitizer] Align & pad the allocator structures to the cacheline size v2
Kostya Kortchinsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 9 14:01:17 PST 2018
cryptoad created this revision.
cryptoad added reviewers: alekseyshl, thakis.
Herald added subscribers: Sanitizers, delcypher, kubamracek.
This is a new version of https://reviews.llvm.org/D44261, which broke some builds with older gcc, as
they can't align on a constexpr, but rather require an integer (see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56859) among others.
We introduce `SANITIZER_CACHE_LINE_SIZE` in `sanitizer_platform.h` to be
used in `ALIGNED` attributes instead of using directly `kCacheLineSize`.
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D44326
Files:
lib/sanitizer_common/sanitizer_allocator_primary32.h
lib/sanitizer_common/sanitizer_allocator_primary64.h
lib/sanitizer_common/sanitizer_common.h
lib/sanitizer_common/sanitizer_platform.h
Index: lib/sanitizer_common/sanitizer_platform.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform.h
+++ lib/sanitizer_common/sanitizer_platform.h
@@ -309,4 +309,12 @@
# define SANITIZER_MADVISE_DONTNEED MADV_DONTNEED
#endif
+// Older gcc have issues aligning to a constexpr, and require an integer.
+// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56859 among others.
+#if defined(__powerpc__) || defined(__powerpc64__)
+# define SANITIZER_CACHE_LINE_SIZE 128
+#else
+# define SANITIZER_CACHE_LINE_SIZE 64
+#endif
+
#endif // SANITIZER_PLATFORM_H
Index: lib/sanitizer_common/sanitizer_common.h
===================================================================
--- lib/sanitizer_common/sanitizer_common.h
+++ lib/sanitizer_common/sanitizer_common.h
@@ -39,11 +39,9 @@
const uptr kWordSize = SANITIZER_WORDSIZE / 8;
const uptr kWordSizeInBits = 8 * kWordSize;
-#if defined(__powerpc__) || defined(__powerpc64__)
- const uptr kCacheLineSize = 128;
-#else
- const uptr kCacheLineSize = 64;
-#endif
+const uptr kCacheLineSize = SANITIZER_CACHE_LINE_SIZE;
+// Check that the CacheLine size is a power-of-two.
+COMPILER_CHECK((kCacheLineSize & (kCacheLineSize - 1)) == 0);
const uptr kMaxPathLength = 4096;
Index: lib/sanitizer_common/sanitizer_allocator_primary64.h
===================================================================
--- lib/sanitizer_common/sanitizer_allocator_primary64.h
+++ 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 {
@@ -584,7 +586,7 @@
u64 last_released_bytes;
};
- struct RegionInfo {
+ struct ALIGNED(SANITIZER_CACHE_LINE_SIZE) RegionInfo {
BlockingMutex mutex;
uptr num_freed_chunks; // Number of elements in the freearray.
uptr mapped_free_array; // Bytes mapped for freearray.
@@ -597,7 +599,7 @@
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);
Index: lib/sanitizer_common/sanitizer_allocator_primary32.h
===================================================================
--- lib/sanitizer_common/sanitizer_allocator_primary32.h
+++ 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(SANITIZER_CACHE_LINE_SIZE) 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44326.137835.patch
Type: text/x-patch
Size: 3307 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180309/632c30b0/attachment.bin>
More information about the llvm-commits
mailing list