Skip to content

Conversation

ChiaHungDuan
Copy link
Contributor

When there are huge deallocation happened in a short period of time (less than the release interval), we will leave all PendingPushedBytesDelta unreleased and it needs to wait until the next releaseToOSMaybe() (which has to be called after the release interval).

Thus we set a limitation for PendingPushedBytesDelta to avoid keeping too many unused pages.

When there are huge deallocation happened in a short period of time
(less than the release interval), we will leave all
PendingPushedBytesDelta unreleased and it needs to wait until the next
releaseToOSMaybe() (which has to be called after the release interval).

Thus we set a limitation for PendingPushedBytesDelta to avoid keeping
too many unused pages.
@ChiaHungDuan
Copy link
Contributor Author

@cferris1000, FYI

@llvmbot
Copy link
Member

llvmbot commented Sep 12, 2025

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

Author: None (ChiaHungDuan)

Changes

When there are huge deallocation happened in a short period of time (less than the release interval), we will leave all PendingPushedBytesDelta unreleased and it needs to wait until the next releaseToOSMaybe() (which has to be called after the release interval).

Thus we set a limitation for PendingPushedBytesDelta to avoid keeping too many unused pages.


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

1 Files Affected:

  • (modified) compiler-rt/lib/scudo/standalone/primary64.h (+7)
diff --git a/compiler-rt/lib/scudo/standalone/primary64.h b/compiler-rt/lib/scudo/standalone/primary64.h
index 7727049426b47..6d46c02691c83 100644
--- a/compiler-rt/lib/scudo/standalone/primary64.h
+++ b/compiler-rt/lib/scudo/standalone/primary64.h
@@ -1561,6 +1561,13 @@ bool SizeClassAllocator64<Config>::hasChanceToReleasePages(
       if (DiffSinceLastReleaseNs < 2 * IntervalNs)
         return false;
     } else if (DiffSinceLastReleaseNs < IntervalNs) {
+      // `TryReleaseThreshold` is capped by (1UL << GroupSizeLog) / 2). If
+      // RegionPushedBytesDelta grows twice of the threshold, it implies some
+      // huge deallocations happening so we'd better still try to release some
+      // pages. Note that this is likely happened with large blocks.
+      if (RegionPushedBytesDelta > (1ULL << GroupSizeLog))
+        return true;
+
       // In this case, we are over the threshold but we just did some page
       // release in the same release interval. This is a hint that we may want
       // a higher threshold so that we can release more memory at once.

@cferris1000
Copy link
Contributor

Pushed as #160621

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