[compiler-rt] [scudo] Reduce unsuccessful attempts of page releasing (PR #110583)
Christopher Ferris via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 1 15:00:09 PDT 2024
================
@@ -1354,34 +1398,45 @@ template <typename Config> class SizeClassAllocator64 {
const uptr RegionPushedBytesDelta =
BytesInFreeList - Region->ReleaseInfo.BytesInFreeListAtLastCheckpoint;
- if (RegionPushedBytesDelta < PageSize)
- return false;
-
- // Releasing smaller blocks is expensive, so we want to make sure that a
- // significant amount of bytes are free, and that there has been a good
- // amount of batches pushed to the freelist before attempting to release.
- if (isSmallBlock(BlockSize) && ReleaseType == ReleaseToOS::Normal)
- if (RegionPushedBytesDelta < Region->TryReleaseThreshold)
- return false;
if (ReleaseType == ReleaseToOS::Normal) {
- const s32 IntervalMs = atomic_load_relaxed(&ReleaseToOsIntervalMs);
- if (IntervalMs < 0)
+ if (RegionPushedBytesDelta < Region->ReleaseInfo.TryReleaseThreshold / 2)
+ return false;
+
+ const u64 IntervalNs =
+ static_cast<u64>(atomic_load_relaxed(&ReleaseToOsIntervalMs)) *
+ 1000000;
+ if (IntervalNs < 0)
return false;
- // The constant 8 here is selected from profiling some apps and the number
- // of unreleased pages in the large size classes is around 16 pages or
- // more. Choose half of it as a heuristic and which also avoids page
- // release every time for every pushBlocks() attempt by large blocks.
- const bool ByPassReleaseInterval =
- isLargeBlock(BlockSize) && RegionPushedBytesDelta > 8 * PageSize;
- if (!ByPassReleaseInterval) {
- if (Region->ReleaseInfo.LastReleaseAtNs +
- static_cast<u64>(IntervalMs) * 1000000 >
- getMonotonicTimeFast()) {
- // Memory was returned recently.
+ const u64 CurTimeNs = getMonotonicTimeFast();
+ const u64 DiffSinceLastReleaseNs =
+ CurTimeNs - Region->ReleaseInfo.LastReleaseAtNs;
+
+ // At here, `RegionPushedBytesDelta` is more than half of
+ // `TryReleaseThreshold`. If the last release was happened 2 release
+ // interval before, we will still try to see if there's any chance to
+ // release some memory even it doesn't exceed the threshold.
+ if (RegionPushedBytesDelta < Region->ReleaseInfo.TryReleaseThreshold) {
+ // We want the threshold to have a shorter response time to the variant
+ // memory usage patterns. By having some experiments (which was done
+ // with 1, 2, 4, 8 intervals), `2` strikes the better balance between
+ // the memory usage and number of page release attempts.
+ if (DiffSinceLastReleaseNs < 2 * IntervalNs)
return false;
- }
+ } else if (DiffSinceLastReleaseNs < IntervalNs) {
+ // In this case, we are over the threshold but we just did some page
----------------
cferris1000 wrote:
we just did some page -> we just released some pages in the same release interval.
https://github.com/llvm/llvm-project/pull/110583
More information about the llvm-commits
mailing list