[compiler-rt] [scudo] Reduce unsuccessful attempts of page releasing (PR #110583)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 1 11:38:09 PDT 2024


================
@@ -1310,12 +1323,36 @@ template <typename Config> class SizeClassAllocator64 {
     auto SkipRegion = [](UNUSED uptr RegionIndex) { return false; };
     releaseFreeMemoryToOS(Context, Recorder, SkipRegion);
     if (Recorder.getReleasedRangesCount() > 0) {
+      // This is the case that we didn't hit the release threshold but it has
+      // been past a certain period of time. Thus we try to release some pages
+      // and if it does release some additional pages, it's hint that we are
+      // able to lower the threshold.
+      // TODO(chiahungduan): Apply the same adjustment strategy to small blocks.
+      if (!isSmallBlock(BlockSize)) {
+        if (RegionPushedBytesDelta < Region->ReleaseInfo.TryReleaseThreshold &&
+            Recorder.getReleasedBytes() >
+                Region->ReleaseInfo.LastReleasedBytes +
+                    getMinReleaseAttemptSize(BlockSize)) {
+          Region->ReleaseInfo.TryReleaseThreshold =
+              Max(Region->ReleaseInfo.TryReleaseThreshold / 2,
+                  getMinReleaseAttemptSize(BlockSize));
+        }
+      }
+
       Region->ReleaseInfo.BytesInFreeListAtLastCheckpoint = BytesInFreeList;
       Region->ReleaseInfo.RangesReleased += Recorder.getReleasedRangesCount();
       Region->ReleaseInfo.LastReleasedBytes = Recorder.getReleasedBytes();
     }
     Region->ReleaseInfo.LastReleaseAtNs = getMonotonicTimeFast();
 
+    if (Region->ReleaseInfo.PendingPushedBytesDelta > 0) {
+      Region->ReleaseInfo.TryReleaseThreshold +=
----------------
ChiaHungDuan wrote:

Done

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


More information about the llvm-commits mailing list