Skip to content

Commit b53ff43

Browse files
authored
[scudo] Improve the message of region exhaustion (#68444)
In this CL, we move the printing of allocator stats from primary.h to combined.h. This will also dump the secondary stats and reduce the log spam when an OOM happens Also change the symbol `F` to `E` to indicate region pages exhausted. It means the region can't map more pages for blocks but it may still have free blocks to allocate. `F` may hint the failure of fatel error in the region. Also update the related comments.
1 parent 0637440 commit b53ff43

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

compiler-rt/lib/scudo/standalone/combined.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,9 @@ class Allocator {
367367
auto *TSD = TSDRegistry.getTSDAndLock(&UnlockRequired);
368368
TSD->assertLocked(/*BypassCheck=*/!UnlockRequired);
369369
Block = TSD->getCache().allocate(ClassId);
370-
// If the allocation failed, the most likely reason with a 32-bit primary
371-
// is the region being full. In that event, retry in each successively
372-
// larger class until it fits. If it fails to fit in the largest class,
373-
// fallback to the Secondary.
370+
// If the allocation failed, retry in each successively larger class until
371+
// it fits. If it fails to fit in the largest class, fallback to the
372+
// Secondary.
374373
if (UNLIKELY(!Block)) {
375374
while (ClassId < SizeClassMap::LargestClassId && !Block)
376375
Block = TSD->getCache().allocate(++ClassId);
@@ -388,6 +387,7 @@ class Allocator {
388387
if (UNLIKELY(!Block)) {
389388
if (Options.get(OptionBit::MayReturnNull))
390389
return nullptr;
390+
printStats();
391391
reportOutOfMemory(NeededSize);
392392
}
393393

compiler-rt/lib/scudo/standalone/primary64.h

+6-12
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ template <typename Config> class SizeClassAllocator64 {
214214
return B;
215215
}
216216

217-
bool PrintStats = false;
217+
bool ReportRegionExhausted = false;
218218
TransferBatch *B = nullptr;
219219

220220
while (true) {
@@ -235,19 +235,13 @@ template <typename Config> class SizeClassAllocator64 {
235235
const bool RegionIsExhausted = Region->Exhausted;
236236
if (!RegionIsExhausted)
237237
B = populateFreeListAndPopBatch(C, ClassId, Region);
238-
PrintStats = !RegionIsExhausted && Region->Exhausted;
238+
ReportRegionExhausted = !RegionIsExhausted && Region->Exhausted;
239239
break;
240240
}
241241

242-
// Note that `getStats()` requires locking each region so we can't call it
243-
// while locking the Region->Mutex in the above.
244-
if (UNLIKELY(PrintStats)) {
245-
ScopedString Str;
246-
getStats(&Str);
247-
Str.append(
248-
"Scudo OOM: The process has exhausted %zuM for size class %zu.\n",
249-
RegionSize >> 20, getSizeByClassId(ClassId));
250-
Str.output();
242+
if (UNLIKELY(ReportRegionExhausted)) {
243+
Printf("Can't populate more pages for size class %zu.\n",
244+
getSizeByClassId(ClassId));
251245

252246
// Theoretically, BatchClass shouldn't be used up. Abort immediately when
253247
// it happens.
@@ -978,7 +972,7 @@ template <typename Config> class SizeClassAllocator64 {
978972
"%s %02zu (%6zu): mapped: %6zuK popped: %7zu pushed: %7zu "
979973
"inuse: %6zu total: %6zu releases: %6zu last "
980974
"released: %6zuK latest pushed bytes: %6zuK region: 0x%zx (0x%zx)\n",
981-
Region->Exhausted ? "F" : " ", ClassId, getSizeByClassId(ClassId),
975+
Region->Exhausted ? "E" : " ", ClassId, getSizeByClassId(ClassId),
982976
Region->MemMapInfo.MappedUser >> 10, Region->FreeListInfo.PoppedBlocks,
983977
Region->FreeListInfo.PushedBlocks, InUseBlocks, TotalChunks,
984978
Region->ReleaseInfo.RangesReleased,

0 commit comments

Comments
 (0)