[compiler-rt] [scudo] Add time of last page release to getStats() (PR #164004)

Sadaf Ebrahimi via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 17 08:50:06 PST 2025


https://github.com/sadafebrahimi updated https://github.com/llvm/llvm-project/pull/164004

>From eed1e1d539ab32c623f3674d042b36d69b4bd69d Mon Sep 17 00:00:00 2001
From: Sadaf Ebrahimi <sadafebrahimi at google.com>
Date: Fri, 17 Oct 2025 19:06:12 +0000
Subject: [PATCH] [scudo] Add time of last page release to getStats()

Having the time of last page release can help us figure out if the page
release is skipped or not.
---
 compiler-rt/lib/scudo/standalone/primary64.h | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/lib/scudo/standalone/primary64.h b/compiler-rt/lib/scudo/standalone/primary64.h
index 747b1a2233d32..27a9f851dcde7 100644
--- a/compiler-rt/lib/scudo/standalone/primary64.h
+++ b/compiler-rt/lib/scudo/standalone/primary64.h
@@ -24,6 +24,8 @@
 #include "thread_annotations.h"
 #include "tracing.h"
 
+#include <inttypes.h>
+
 namespace scudo {
 
 // SizeClassAllocator64 is an allocator tuned for 64-bit address space.
@@ -1146,17 +1148,24 @@ void SizeClassAllocator64<Config>::getStats(ScopedString *Str, uptr ClassId,
         BytesInFreeList - Region->ReleaseInfo.BytesInFreeListAtLastCheckpoint;
   }
   const uptr TotalChunks = Region->MemMapInfo.AllocatedUser / BlockSize;
+  const u64 CurTimeNs = getMonotonicTime();
+  const u64 DiffSinceLastReleaseNs =
+      CurTimeNs - Region->ReleaseInfo.LastReleaseAtNs;
+  const u64 LastReleaseSecAgo = DiffSinceLastReleaseNs / 1000000000;
+  const u64 LastReleaseMsAgo = (DiffSinceLastReleaseNs % 1000000000) / 1000000;
+
   Str->append(
       "%s %02zu (%6zu): mapped: %6zuK popped: %7zu pushed: %7zu "
       "inuse: %6zu total: %6zu releases attempted: %6zu last "
       "released: %6zuK latest pushed bytes: %6zuK region: 0x%zx "
-      "(0x%zx)\n",
+      "(0x%zx) Latest release: %" PRIu64 ":%" PRIu64 " seconds ago\n",
       Region->Exhausted ? "E" : " ", ClassId, getSizeByClassId(ClassId),
       Region->MemMapInfo.MappedUser >> 10, Region->FreeListInfo.PoppedBlocks,
       Region->FreeListInfo.PushedBlocks, InUseBlocks, TotalChunks,
       Region->ReleaseInfo.NumReleasesAttempted,
       Region->ReleaseInfo.LastReleasedBytes >> 10, RegionPushedBytesDelta >> 10,
-      Region->RegionBeg, getRegionBaseByClassId(ClassId));
+      Region->RegionBeg, getRegionBaseByClassId(ClassId), LastReleaseSecAgo,
+      LastReleaseMsAgo);
 }
 
 template <typename Config>
@@ -1486,7 +1495,7 @@ uptr SizeClassAllocator64<Config>::releaseToOSMaybe(RegionInfo *Region,
     Region->ReleaseInfo.BytesInFreeListAtLastCheckpoint = BytesInFreeList;
     Region->ReleaseInfo.LastReleasedBytes = Recorder.getReleasedBytes();
   }
-  Region->ReleaseInfo.LastReleaseAtNs = getMonotonicTimeFast();
+  Region->ReleaseInfo.LastReleaseAtNs = getMonotonicTime();
 
   if (Region->ReleaseInfo.PendingPushedBytesDelta > 0) {
     // Instead of increasing the threshold by the amount of



More information about the llvm-commits mailing list