[PATCH] D100062: [scudo][standalone] Use BatchClassId in drain rather than 0

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 9 14:09:36 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG50979defc955: [scudo][standalone] Use BatchClassId in drain rather than 0 (authored by cryptoad).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100062/new/

https://reviews.llvm.org/D100062

Files:
  compiler-rt/lib/scudo/standalone/local_cache.h


Index: compiler-rt/lib/scudo/standalone/local_cache.h
===================================================================
--- compiler-rt/lib/scudo/standalone/local_cache.h
+++ compiler-rt/lib/scudo/standalone/local_cache.h
@@ -109,19 +109,21 @@
   }
 
   void drain() {
-    // Drain BatchClassId (0) the last as createBatch can refill it.
-    for (uptr I = NumClasses; I;) {
-      --I;
-      PerClass *C = &PerClassArray[I];
-      while (C->Count > 0)
-        drain(C, I);
+    // Drain BatchClassId last as createBatch can refill it.
+    for (uptr I = 0; I < NumClasses; ++I) {
+      if (I == BatchClassId)
+        continue;
+      while (PerClassArray[I].Count > 0)
+        drain(&PerClassArray[I], I);
     }
+    while (PerClassArray[BatchClassId].Count > 0)
+      drain(&PerClassArray[BatchClassId], BatchClassId);
     DCHECK(isEmpty());
   }
 
   TransferBatch *createBatch(uptr ClassId, void *B) {
-    if (ClassId != SizeClassMap::BatchClassId)
-      B = allocate(SizeClassMap::BatchClassId);
+    if (ClassId != BatchClassId)
+      B = allocate(BatchClassId);
     return reinterpret_cast<TransferBatch *>(B);
   }
 
@@ -129,6 +131,7 @@
 
 private:
   static const uptr NumClasses = SizeClassMap::NumClasses;
+  static const uptr BatchClassId = SizeClassMap::BatchClassId;
   struct PerClass {
     u32 Count;
     u32 MaxCount;
@@ -156,8 +159,8 @@
   }
 
   void destroyBatch(uptr ClassId, void *B) {
-    if (ClassId != SizeClassMap::BatchClassId)
-      deallocate(SizeClassMap::BatchClassId, B);
+    if (ClassId != BatchClassId)
+      deallocate(BatchClassId, B);
   }
 
   NOINLINE bool refill(PerClass *C, uptr ClassId) {
@@ -178,8 +181,7 @@
     TransferBatch *B =
         createBatch(ClassId, Allocator->decompactPtr(ClassId, C->Chunks[0]));
     if (UNLIKELY(!B))
-      reportOutOfMemory(
-          SizeClassAllocator::getSizeByClassId(SizeClassMap::BatchClassId));
+      reportOutOfMemory(SizeClassAllocator::getSizeByClassId(BatchClassId));
     B->setFromArray(&C->Chunks[0], Count);
     C->Count -= Count;
     for (uptr I = 0; I < C->Count; I++)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100062.336559.patch
Type: text/x-patch
Size: 2091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210409/cb2350d1/attachment.bin>


More information about the llvm-commits mailing list