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

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 17 12:20:22 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Sadaf Ebrahimi (sadafebrahimi)

<details>
<summary>Changes</summary>

Having the time of last page release can help us figure out if the page release is skipped or not.

---
Full diff: https://github.com/llvm/llvm-project/pull/164004.diff


1 Files Affected:

- (modified) compiler-rt/lib/scudo/standalone/primary64.h (+12-3) 


``````````diff
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

``````````

</details>


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


More information about the llvm-commits mailing list