[compiler-rt] [scudo] Fix the misused Exhausted in region allocation (PR #89852)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 23 18:11:08 PDT 2024


https://github.com/ChiaHungDuan created https://github.com/llvm/llvm-project/pull/89852

`Region->Exhausted` indicates that we don't have more pages to create new blocks in the region. It has different meaning from region allocation failure.

Also fix a minor lint in popBlocks()

>From e6bb3d336f1d1d4db7c0a7ab235ee34ae6b18a5d Mon Sep 17 00:00:00 2001
From: Chia-hung Duan <chiahungduan at google.com>
Date: Wed, 24 Apr 2024 01:05:54 +0000
Subject: [PATCH] [scudo] Fix the misused Exhausted in region allocation

`Region->Exhausted` indicates that we don't have more pages to create
new blocks in the region. It has different meaning from region
allocation failure.

Also fix a minor lint in popBlocks()
---
 compiler-rt/lib/scudo/standalone/primary64.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/scudo/standalone/primary64.h b/compiler-rt/lib/scudo/standalone/primary64.h
index 61d57976ae43b6..d6119051b1622f 100644
--- a/compiler-rt/lib/scudo/standalone/primary64.h
+++ b/compiler-rt/lib/scudo/standalone/primary64.h
@@ -884,9 +884,10 @@ template <typename Config> class SizeClassAllocator64 {
         ScopedLock ML(Region->MMLock);
 
         const bool RegionIsExhausted = Region->Exhausted;
-        if (!RegionIsExhausted)
+        if (!RegionIsExhausted) {
           PopCount = populateFreeListAndPopBlocks(C, ClassId, Region, ToArray,
                                                   MaxBlockCount);
+        }
         ReportRegionExhausted = !RegionIsExhausted && Region->Exhausted;
 
         {
@@ -1019,7 +1020,6 @@ template <typename Config> class SizeClassAllocator64 {
                                           MAP_ALLOWNOMEM))) {
         Printf("Can't reserve pages for size class %zu.\n",
                getSizeByClassId(ClassId));
-        Region->Exhausted = true;
         return 0U;
       }
       initRegion(Region, ClassId,



More information about the llvm-commits mailing list