Skip to content

Conversation

sadafebrahimi
Copy link

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

sadafebrahimi and others added 2 commits October 17, 2025 19:06
Having the time of last page release can help us figure out if the page
release is skipped or not.
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Oct 17, 2025

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

Author: Sadaf Ebrahimi (sadafebrahimi)

Changes

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

Region->ReleaseInfo.LastReleasedBytes = Recorder.getReleasedBytes();
}
Region->ReleaseInfo.LastReleaseAtNs = getMonotonicTimeFast();
Region->ReleaseInfo.LastReleaseAtNs = getMonotonicTime();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to keep this with the fast version as long as we have the precise one in getStats

Comment on lines +1154 to +1156
const u64 LastReleaseSecAgo = DiffSinceLastReleaseNs / 1000000000;
const u64 LastReleaseMsAgo = (DiffSinceLastReleaseNs % 1000000000) / 1000000;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a new thought about this, given that we have ReleaseToOsInterval, can we print something like > ReleaseToOsInterval < ReleaseToOsInterval?

If we hit the threshold to do the page release but it's too close (diff time less than ReleaseToOsInterval) then we will skip the page release. Thus I think longer/shorter than the interval gives us enough information about why the pages aren't released.

Sorry I didn't think about this while came up with the work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's chat this offline for more details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants