[compiler-rt] [scudo] Add EnableMultiRegions mode (PR #98076)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 17 12:14:25 PDT 2024
================
@@ -555,18 +715,208 @@ template <typename Config> class SizeClassAllocator64 {
bool isPopulatingFreeList GUARDED_BY(FLLock) = false;
};
struct RegionInfo : UnpaddedRegionInfo {
+ // This is only used when `Config::getEnableMultiRegions` is enabled and is
+ // guarded by the mutex in `RegionInfoManager`.
+ RegionInfo *Next = nullptr;
char Padding[SCUDO_CACHE_LINE_SIZE -
- (sizeof(UnpaddedRegionInfo) % SCUDO_CACHE_LINE_SIZE)] = {};
+ ((sizeof(UnpaddedRegionInfo) + sizeof(RegionInfo *)) %
+ SCUDO_CACHE_LINE_SIZE)] = {};
};
static_assert(sizeof(RegionInfo) % SCUDO_CACHE_LINE_SIZE == 0, "");
- RegionInfo *getRegionInfo(uptr ClassId) {
- DCHECK_LT(ClassId, NumClasses);
- return &RegionInfoArray[ClassId];
- }
+ template <bool IsMultiRegions = false> struct RegionInfoAlloc {
+ RegionInfo *allocate() {
+ UNREACHABLE("RegionInfo is statically allocated");
+ }
- uptr getRegionBaseByClassId(uptr ClassId) {
- RegionInfo *Region = getRegionInfo(ClassId);
+ void verifyTheNumberOfAllocatedRegionInfo(uptr NumRegionInfo) {
+ DCHECK_EQ(NumRegionInfo, NumClasses);
+ }
+ };
+
+ template <> struct RegionInfoAlloc</*isMultiRegions=*/true> {
+ RegionInfo *allocate() {
+ ScopedLock L(M);
+ return S.pop();
+ }
+
+ void verifyTheNumberOfAllocatedRegionInfo(uptr NumRegionInfo) {
+ ScopedLock L(M);
+ DCHECK_EQ(NumRegionInfo, S.Size);
+ }
+
+ HybridMutex M;
+ // According to the following,
+ // DR1351: If the brace-or-equal-initializer of a non-static data
+ // member invokes a defaulted default constructor of its class or of an
+ // enclosing class in a potentially evaluated subexpression, the program
+ // is ill-formed.
+ // So we have to `outline` the `Size`/`Array` into another struct `Storage`.
+ struct Storage {
+ RegionInfo *pop() {
+ if (Size == NumEntries)
+ return nullptr;
+ return &Array[Size++];
+ }
+ // The amount memory used by this allocator is about (NumEntries *
----------------
ChiaHungDuan wrote:
Done
https://github.com/llvm/llvm-project/pull/98076
More information about the llvm-commits
mailing list