primary32.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. //===-- primary32.h ---------------------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef SCUDO_PRIMARY32_H_
  9. #define SCUDO_PRIMARY32_H_
  10. #include "bytemap.h"
  11. #include "common.h"
  12. #include "list.h"
  13. #include "local_cache.h"
  14. #include "options.h"
  15. #include "release.h"
  16. #include "report.h"
  17. #include "stats.h"
  18. #include "string_utils.h"
  19. namespace scudo {
  20. // SizeClassAllocator32 is an allocator for 32 or 64-bit address space.
  21. //
  22. // It maps Regions of 2^RegionSizeLog bytes aligned on a 2^RegionSizeLog bytes
  23. // boundary, and keeps a bytemap of the mappable address space to track the size
  24. // class they are associated with.
  25. //
  26. // Mapped regions are split into equally sized Blocks according to the size
  27. // class they belong to, and the associated pointers are shuffled to prevent any
  28. // predictable address pattern (the predictability increases with the block
  29. // size).
  30. //
  31. // Regions for size class 0 are special and used to hold TransferBatches, which
  32. // allow to transfer arrays of pointers from the global size class freelist to
  33. // the thread specific freelist for said class, and back.
  34. //
  35. // Memory used by this allocator is never unmapped but can be partially
  36. // reclaimed if the platform allows for it.
  37. template <typename Config> class SizeClassAllocator32 {
  38. public:
  39. typedef typename Config::PrimaryCompactPtrT CompactPtrT;
  40. typedef typename Config::SizeClassMap SizeClassMap;
  41. // The bytemap can only track UINT8_MAX - 1 classes.
  42. static_assert(SizeClassMap::LargestClassId <= (UINT8_MAX - 1), "");
  43. // Regions should be large enough to hold the largest Block.
  44. static_assert((1UL << Config::PrimaryRegionSizeLog) >= SizeClassMap::MaxSize,
  45. "");
  46. typedef SizeClassAllocator32<Config> ThisT;
  47. typedef SizeClassAllocatorLocalCache<ThisT> CacheT;
  48. typedef typename CacheT::TransferBatch TransferBatch;
  49. static uptr getSizeByClassId(uptr ClassId) {
  50. return (ClassId == SizeClassMap::BatchClassId)
  51. ? sizeof(TransferBatch)
  52. : SizeClassMap::getSizeByClassId(ClassId);
  53. }
  54. static bool canAllocate(uptr Size) { return Size <= SizeClassMap::MaxSize; }
  55. void init(s32 ReleaseToOsInterval) {
  56. if (SCUDO_FUCHSIA)
  57. reportError("SizeClassAllocator32 is not supported on Fuchsia");
  58. if (SCUDO_TRUSTY)
  59. reportError("SizeClassAllocator32 is not supported on Trusty");
  60. DCHECK(isAligned(reinterpret_cast<uptr>(this), alignof(ThisT)));
  61. PossibleRegions.init();
  62. u32 Seed;
  63. const u64 Time = getMonotonicTime();
  64. if (!getRandom(reinterpret_cast<void *>(&Seed), sizeof(Seed)))
  65. Seed = static_cast<u32>(
  66. Time ^ (reinterpret_cast<uptr>(SizeClassInfoArray) >> 6));
  67. for (uptr I = 0; I < NumClasses; I++) {
  68. SizeClassInfo *Sci = getSizeClassInfo(I);
  69. Sci->RandState = getRandomU32(&Seed);
  70. // Sci->MaxRegionIndex is already initialized to 0.
  71. Sci->MinRegionIndex = NumRegions;
  72. Sci->ReleaseInfo.LastReleaseAtNs = Time;
  73. }
  74. setOption(Option::ReleaseInterval, static_cast<sptr>(ReleaseToOsInterval));
  75. }
  76. void unmapTestOnly() {
  77. while (NumberOfStashedRegions > 0)
  78. unmap(reinterpret_cast<void *>(RegionsStash[--NumberOfStashedRegions]),
  79. RegionSize);
  80. uptr MinRegionIndex = NumRegions, MaxRegionIndex = 0;
  81. for (uptr I = 0; I < NumClasses; I++) {
  82. SizeClassInfo *Sci = getSizeClassInfo(I);
  83. if (Sci->MinRegionIndex < MinRegionIndex)
  84. MinRegionIndex = Sci->MinRegionIndex;
  85. if (Sci->MaxRegionIndex > MaxRegionIndex)
  86. MaxRegionIndex = Sci->MaxRegionIndex;
  87. *Sci = {};
  88. }
  89. for (uptr I = MinRegionIndex; I < MaxRegionIndex; I++)
  90. if (PossibleRegions[I])
  91. unmap(reinterpret_cast<void *>(I * RegionSize), RegionSize);
  92. PossibleRegions.unmapTestOnly();
  93. }
  94. CompactPtrT compactPtr(UNUSED uptr ClassId, uptr Ptr) const {
  95. return static_cast<CompactPtrT>(Ptr);
  96. }
  97. void *decompactPtr(UNUSED uptr ClassId, CompactPtrT CompactPtr) const {
  98. return reinterpret_cast<void *>(static_cast<uptr>(CompactPtr));
  99. }
  100. TransferBatch *popBatch(CacheT *C, uptr ClassId) {
  101. DCHECK_LT(ClassId, NumClasses);
  102. SizeClassInfo *Sci = getSizeClassInfo(ClassId);
  103. ScopedLock L(Sci->Mutex);
  104. TransferBatch *B = Sci->FreeList.front();
  105. if (B) {
  106. Sci->FreeList.pop_front();
  107. } else {
  108. B = populateFreeList(C, ClassId, Sci);
  109. if (UNLIKELY(!B))
  110. return nullptr;
  111. }
  112. DCHECK_GT(B->getCount(), 0);
  113. Sci->Stats.PoppedBlocks += B->getCount();
  114. return B;
  115. }
  116. void pushBatch(uptr ClassId, TransferBatch *B) {
  117. DCHECK_LT(ClassId, NumClasses);
  118. DCHECK_GT(B->getCount(), 0);
  119. SizeClassInfo *Sci = getSizeClassInfo(ClassId);
  120. ScopedLock L(Sci->Mutex);
  121. Sci->FreeList.push_front(B);
  122. Sci->Stats.PushedBlocks += B->getCount();
  123. if (ClassId != SizeClassMap::BatchClassId)
  124. releaseToOSMaybe(Sci, ClassId);
  125. }
  126. void disable() {
  127. // The BatchClassId must be locked last since other classes can use it.
  128. for (sptr I = static_cast<sptr>(NumClasses) - 1; I >= 0; I--) {
  129. if (static_cast<uptr>(I) == SizeClassMap::BatchClassId)
  130. continue;
  131. getSizeClassInfo(static_cast<uptr>(I))->Mutex.lock();
  132. }
  133. getSizeClassInfo(SizeClassMap::BatchClassId)->Mutex.lock();
  134. RegionsStashMutex.lock();
  135. PossibleRegions.disable();
  136. }
  137. void enable() {
  138. PossibleRegions.enable();
  139. RegionsStashMutex.unlock();
  140. getSizeClassInfo(SizeClassMap::BatchClassId)->Mutex.unlock();
  141. for (uptr I = 0; I < NumClasses; I++) {
  142. if (I == SizeClassMap::BatchClassId)
  143. continue;
  144. getSizeClassInfo(I)->Mutex.unlock();
  145. }
  146. }
  147. template <typename F> void iterateOverBlocks(F Callback) {
  148. uptr MinRegionIndex = NumRegions, MaxRegionIndex = 0;
  149. for (uptr I = 0; I < NumClasses; I++) {
  150. SizeClassInfo *Sci = getSizeClassInfo(I);
  151. if (Sci->MinRegionIndex < MinRegionIndex)
  152. MinRegionIndex = Sci->MinRegionIndex;
  153. if (Sci->MaxRegionIndex > MaxRegionIndex)
  154. MaxRegionIndex = Sci->MaxRegionIndex;
  155. }
  156. for (uptr I = MinRegionIndex; I <= MaxRegionIndex; I++)
  157. if (PossibleRegions[I] &&
  158. (PossibleRegions[I] - 1U) != SizeClassMap::BatchClassId) {
  159. const uptr BlockSize = getSizeByClassId(PossibleRegions[I] - 1U);
  160. const uptr From = I * RegionSize;
  161. const uptr To = From + (RegionSize / BlockSize) * BlockSize;
  162. for (uptr Block = From; Block < To; Block += BlockSize)
  163. Callback(Block);
  164. }
  165. }
  166. void getStats(ScopedString *Str) {
  167. // TODO(kostyak): get the RSS per region.
  168. uptr TotalMapped = 0;
  169. uptr PoppedBlocks = 0;
  170. uptr PushedBlocks = 0;
  171. for (uptr I = 0; I < NumClasses; I++) {
  172. SizeClassInfo *Sci = getSizeClassInfo(I);
  173. TotalMapped += Sci->AllocatedUser;
  174. PoppedBlocks += Sci->Stats.PoppedBlocks;
  175. PushedBlocks += Sci->Stats.PushedBlocks;
  176. }
  177. Str->append("Stats: SizeClassAllocator32: %zuM mapped in %zu allocations; "
  178. "remains %zu\n",
  179. TotalMapped >> 20, PoppedBlocks, PoppedBlocks - PushedBlocks);
  180. for (uptr I = 0; I < NumClasses; I++)
  181. getStats(Str, I, 0);
  182. }
  183. bool setOption(Option O, sptr Value) {
  184. if (O == Option::ReleaseInterval) {
  185. const s32 Interval = Max(
  186. Min(static_cast<s32>(Value), Config::PrimaryMaxReleaseToOsIntervalMs),
  187. Config::PrimaryMinReleaseToOsIntervalMs);
  188. atomic_store_relaxed(&ReleaseToOsIntervalMs, Interval);
  189. return true;
  190. }
  191. // Not supported by the Primary, but not an error either.
  192. return true;
  193. }
  194. uptr releaseToOS() {
  195. uptr TotalReleasedBytes = 0;
  196. for (uptr I = 0; I < NumClasses; I++) {
  197. if (I == SizeClassMap::BatchClassId)
  198. continue;
  199. SizeClassInfo *Sci = getSizeClassInfo(I);
  200. ScopedLock L(Sci->Mutex);
  201. TotalReleasedBytes += releaseToOSMaybe(Sci, I, /*Force=*/true);
  202. }
  203. return TotalReleasedBytes;
  204. }
  205. const char *getRegionInfoArrayAddress() const { return nullptr; }
  206. static uptr getRegionInfoArraySize() { return 0; }
  207. static BlockInfo findNearestBlock(UNUSED const char *RegionInfoData,
  208. UNUSED uptr Ptr) {
  209. return {};
  210. }
  211. AtomicOptions Options;
  212. private:
  213. static const uptr NumClasses = SizeClassMap::NumClasses;
  214. static const uptr RegionSize = 1UL << Config::PrimaryRegionSizeLog;
  215. static const uptr NumRegions =
  216. SCUDO_MMAP_RANGE_SIZE >> Config::PrimaryRegionSizeLog;
  217. static const u32 MaxNumBatches = SCUDO_ANDROID ? 4U : 8U;
  218. typedef FlatByteMap<NumRegions> ByteMap;
  219. struct SizeClassStats {
  220. uptr PoppedBlocks;
  221. uptr PushedBlocks;
  222. };
  223. struct ReleaseToOsInfo {
  224. uptr PushedBlocksAtLastRelease;
  225. uptr RangesReleased;
  226. uptr LastReleasedBytes;
  227. u64 LastReleaseAtNs;
  228. };
  229. struct alignas(SCUDO_CACHE_LINE_SIZE) SizeClassInfo {
  230. HybridMutex Mutex;
  231. SinglyLinkedList<TransferBatch> FreeList;
  232. uptr CurrentRegion;
  233. uptr CurrentRegionAllocated;
  234. SizeClassStats Stats;
  235. u32 RandState;
  236. uptr AllocatedUser;
  237. // Lowest & highest region index allocated for this size class, to avoid
  238. // looping through the whole NumRegions.
  239. uptr MinRegionIndex;
  240. uptr MaxRegionIndex;
  241. ReleaseToOsInfo ReleaseInfo;
  242. };
  243. static_assert(sizeof(SizeClassInfo) % SCUDO_CACHE_LINE_SIZE == 0, "");
  244. uptr computeRegionId(uptr Mem) {
  245. const uptr Id = Mem >> Config::PrimaryRegionSizeLog;
  246. CHECK_LT(Id, NumRegions);
  247. return Id;
  248. }
  249. uptr allocateRegionSlow() {
  250. uptr MapSize = 2 * RegionSize;
  251. const uptr MapBase = reinterpret_cast<uptr>(
  252. map(nullptr, MapSize, "scudo:primary", MAP_ALLOWNOMEM));
  253. if (!MapBase)
  254. return 0;
  255. const uptr MapEnd = MapBase + MapSize;
  256. uptr Region = MapBase;
  257. if (isAligned(Region, RegionSize)) {
  258. ScopedLock L(RegionsStashMutex);
  259. if (NumberOfStashedRegions < MaxStashedRegions)
  260. RegionsStash[NumberOfStashedRegions++] = MapBase + RegionSize;
  261. else
  262. MapSize = RegionSize;
  263. } else {
  264. Region = roundUpTo(MapBase, RegionSize);
  265. unmap(reinterpret_cast<void *>(MapBase), Region - MapBase);
  266. MapSize = RegionSize;
  267. }
  268. const uptr End = Region + MapSize;
  269. if (End != MapEnd)
  270. unmap(reinterpret_cast<void *>(End), MapEnd - End);
  271. return Region;
  272. }
  273. uptr allocateRegion(SizeClassInfo *Sci, uptr ClassId) {
  274. DCHECK_LT(ClassId, NumClasses);
  275. uptr Region = 0;
  276. {
  277. ScopedLock L(RegionsStashMutex);
  278. if (NumberOfStashedRegions > 0)
  279. Region = RegionsStash[--NumberOfStashedRegions];
  280. }
  281. if (!Region)
  282. Region = allocateRegionSlow();
  283. if (LIKELY(Region)) {
  284. // Sci->Mutex is held by the caller, updating the Min/Max is safe.
  285. const uptr RegionIndex = computeRegionId(Region);
  286. if (RegionIndex < Sci->MinRegionIndex)
  287. Sci->MinRegionIndex = RegionIndex;
  288. if (RegionIndex > Sci->MaxRegionIndex)
  289. Sci->MaxRegionIndex = RegionIndex;
  290. PossibleRegions.set(RegionIndex, static_cast<u8>(ClassId + 1U));
  291. }
  292. return Region;
  293. }
  294. SizeClassInfo *getSizeClassInfo(uptr ClassId) {
  295. DCHECK_LT(ClassId, NumClasses);
  296. return &SizeClassInfoArray[ClassId];
  297. }
  298. NOINLINE TransferBatch *populateFreeList(CacheT *C, uptr ClassId,
  299. SizeClassInfo *Sci) {
  300. uptr Region;
  301. uptr Offset;
  302. // If the size-class currently has a region associated to it, use it. The
  303. // newly created blocks will be located after the currently allocated memory
  304. // for that region (up to RegionSize). Otherwise, create a new region, where
  305. // the new blocks will be carved from the beginning.
  306. if (Sci->CurrentRegion) {
  307. Region = Sci->CurrentRegion;
  308. DCHECK_GT(Sci->CurrentRegionAllocated, 0U);
  309. Offset = Sci->CurrentRegionAllocated;
  310. } else {
  311. DCHECK_EQ(Sci->CurrentRegionAllocated, 0U);
  312. Region = allocateRegion(Sci, ClassId);
  313. if (UNLIKELY(!Region))
  314. return nullptr;
  315. C->getStats().add(StatMapped, RegionSize);
  316. Sci->CurrentRegion = Region;
  317. Offset = 0;
  318. }
  319. const uptr Size = getSizeByClassId(ClassId);
  320. const u32 MaxCount = TransferBatch::getMaxCached(Size);
  321. DCHECK_GT(MaxCount, 0U);
  322. // The maximum number of blocks we should carve in the region is dictated
  323. // by the maximum number of batches we want to fill, and the amount of
  324. // memory left in the current region (we use the lowest of the two). This
  325. // will not be 0 as we ensure that a region can at least hold one block (via
  326. // static_assert and at the end of this function).
  327. const u32 NumberOfBlocks =
  328. Min(MaxNumBatches * MaxCount,
  329. static_cast<u32>((RegionSize - Offset) / Size));
  330. DCHECK_GT(NumberOfBlocks, 0U);
  331. constexpr u32 ShuffleArraySize =
  332. MaxNumBatches * TransferBatch::MaxNumCached;
  333. // Fill the transfer batches and put them in the size-class freelist. We
  334. // need to randomize the blocks for security purposes, so we first fill a
  335. // local array that we then shuffle before populating the batches.
  336. CompactPtrT ShuffleArray[ShuffleArraySize];
  337. DCHECK_LE(NumberOfBlocks, ShuffleArraySize);
  338. uptr P = Region + Offset;
  339. for (u32 I = 0; I < NumberOfBlocks; I++, P += Size)
  340. ShuffleArray[I] = reinterpret_cast<CompactPtrT>(P);
  341. // No need to shuffle the batches size class.
  342. if (ClassId != SizeClassMap::BatchClassId)
  343. shuffle(ShuffleArray, NumberOfBlocks, &Sci->RandState);
  344. for (u32 I = 0; I < NumberOfBlocks;) {
  345. TransferBatch *B =
  346. C->createBatch(ClassId, reinterpret_cast<void *>(ShuffleArray[I]));
  347. if (UNLIKELY(!B))
  348. return nullptr;
  349. const u32 N = Min(MaxCount, NumberOfBlocks - I);
  350. B->setFromArray(&ShuffleArray[I], N);
  351. Sci->FreeList.push_back(B);
  352. I += N;
  353. }
  354. TransferBatch *B = Sci->FreeList.front();
  355. Sci->FreeList.pop_front();
  356. DCHECK(B);
  357. DCHECK_GT(B->getCount(), 0);
  358. const uptr AllocatedUser = Size * NumberOfBlocks;
  359. C->getStats().add(StatFree, AllocatedUser);
  360. DCHECK_LE(Sci->CurrentRegionAllocated + AllocatedUser, RegionSize);
  361. // If there is not enough room in the region currently associated to fit
  362. // more blocks, we deassociate the region by resetting CurrentRegion and
  363. // CurrentRegionAllocated. Otherwise, update the allocated amount.
  364. if (RegionSize - (Sci->CurrentRegionAllocated + AllocatedUser) < Size) {
  365. Sci->CurrentRegion = 0;
  366. Sci->CurrentRegionAllocated = 0;
  367. } else {
  368. Sci->CurrentRegionAllocated += AllocatedUser;
  369. }
  370. Sci->AllocatedUser += AllocatedUser;
  371. return B;
  372. }
  373. void getStats(ScopedString *Str, uptr ClassId, uptr Rss) {
  374. SizeClassInfo *Sci = getSizeClassInfo(ClassId);
  375. if (Sci->AllocatedUser == 0)
  376. return;
  377. const uptr InUse = Sci->Stats.PoppedBlocks - Sci->Stats.PushedBlocks;
  378. const uptr AvailableChunks = Sci->AllocatedUser / getSizeByClassId(ClassId);
  379. Str->append(" %02zu (%6zu): mapped: %6zuK popped: %7zu pushed: %7zu "
  380. "inuse: %6zu avail: %6zu rss: %6zuK releases: %6zu\n",
  381. ClassId, getSizeByClassId(ClassId), Sci->AllocatedUser >> 10,
  382. Sci->Stats.PoppedBlocks, Sci->Stats.PushedBlocks, InUse,
  383. AvailableChunks, Rss >> 10, Sci->ReleaseInfo.RangesReleased);
  384. }
  385. NOINLINE uptr releaseToOSMaybe(SizeClassInfo *Sci, uptr ClassId,
  386. bool Force = false) {
  387. const uptr BlockSize = getSizeByClassId(ClassId);
  388. const uptr PageSize = getPageSizeCached();
  389. DCHECK_GE(Sci->Stats.PoppedBlocks, Sci->Stats.PushedBlocks);
  390. const uptr BytesInFreeList =
  391. Sci->AllocatedUser -
  392. (Sci->Stats.PoppedBlocks - Sci->Stats.PushedBlocks) * BlockSize;
  393. if (BytesInFreeList < PageSize)
  394. return 0; // No chance to release anything.
  395. const uptr BytesPushed =
  396. (Sci->Stats.PushedBlocks - Sci->ReleaseInfo.PushedBlocksAtLastRelease) *
  397. BlockSize;
  398. if (BytesPushed < PageSize)
  399. return 0; // Nothing new to release.
  400. // Releasing smaller blocks is expensive, so we want to make sure that a
  401. // significant amount of bytes are free, and that there has been a good
  402. // amount of batches pushed to the freelist before attempting to release.
  403. if (BlockSize < PageSize / 16U) {
  404. if (!Force && BytesPushed < Sci->AllocatedUser / 16U)
  405. return 0;
  406. // We want 8x% to 9x% free bytes (the larger the block, the lower the %).
  407. if ((BytesInFreeList * 100U) / Sci->AllocatedUser <
  408. (100U - 1U - BlockSize / 16U))
  409. return 0;
  410. }
  411. if (!Force) {
  412. const s32 IntervalMs = atomic_load_relaxed(&ReleaseToOsIntervalMs);
  413. if (IntervalMs < 0)
  414. return 0;
  415. if (Sci->ReleaseInfo.LastReleaseAtNs +
  416. static_cast<u64>(IntervalMs) * 1000000 >
  417. getMonotonicTime()) {
  418. return 0; // Memory was returned recently.
  419. }
  420. }
  421. const uptr First = Sci->MinRegionIndex;
  422. const uptr Last = Sci->MaxRegionIndex;
  423. DCHECK_NE(Last, 0U);
  424. DCHECK_LE(First, Last);
  425. uptr TotalReleasedBytes = 0;
  426. const uptr Base = First * RegionSize;
  427. const uptr NumberOfRegions = Last - First + 1U;
  428. ReleaseRecorder Recorder(Base);
  429. auto SkipRegion = [this, First, ClassId](uptr RegionIndex) {
  430. return (PossibleRegions[First + RegionIndex] - 1U) != ClassId;
  431. };
  432. auto DecompactPtr = [](CompactPtrT CompactPtr) {
  433. return reinterpret_cast<uptr>(CompactPtr);
  434. };
  435. releaseFreeMemoryToOS(Sci->FreeList, RegionSize, NumberOfRegions, BlockSize,
  436. &Recorder, DecompactPtr, SkipRegion);
  437. if (Recorder.getReleasedRangesCount() > 0) {
  438. Sci->ReleaseInfo.PushedBlocksAtLastRelease = Sci->Stats.PushedBlocks;
  439. Sci->ReleaseInfo.RangesReleased += Recorder.getReleasedRangesCount();
  440. Sci->ReleaseInfo.LastReleasedBytes = Recorder.getReleasedBytes();
  441. TotalReleasedBytes += Sci->ReleaseInfo.LastReleasedBytes;
  442. }
  443. Sci->ReleaseInfo.LastReleaseAtNs = getMonotonicTime();
  444. return TotalReleasedBytes;
  445. }
  446. SizeClassInfo SizeClassInfoArray[NumClasses] = {};
  447. // Track the regions in use, 0 is unused, otherwise store ClassId + 1.
  448. ByteMap PossibleRegions = {};
  449. atomic_s32 ReleaseToOsIntervalMs = {};
  450. // Unless several threads request regions simultaneously from different size
  451. // classes, the stash rarely contains more than 1 entry.
  452. static constexpr uptr MaxStashedRegions = 4;
  453. HybridMutex RegionsStashMutex;
  454. uptr NumberOfStashedRegions = 0;
  455. uptr RegionsStash[MaxStashedRegions] = {};
  456. };
  457. } // namespace scudo
  458. #endif // SCUDO_PRIMARY32_H_