Skip to content

Commit 885cb59

Browse files
authored
[scudo] Release to OS if a large amount of memory is deallocated. (#160621)
Before this change, if large amounts of memory are deallocated within a release interval, the release is put off until the release interval occurs. Unfortunately, for larger class sizes, this could mean that a lot of this memory accumulates and is never released since no more deallocations occur in that size class. To fix this, if `RegionPushedBytesDelta` grows larger than a group size, immediately do a release. This work was originally done by ChiaHungDuan.
1 parent 302be34 commit 885cb59

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

compiler-rt/lib/scudo/standalone/primary64.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,13 @@ bool SizeClassAllocator64<Config>::hasChanceToReleasePages(
15651565
if (DiffSinceLastReleaseNs < 2 * IntervalNs)
15661566
return false;
15671567
} else if (DiffSinceLastReleaseNs < IntervalNs) {
1568+
// `TryReleaseThreshold` is capped by (1UL << GroupSizeLog) / 2). If
1569+
// RegionPushedBytesDelta grows to twice the threshold, it implies some
1570+
// huge deallocations have happened so we better try to release some
1571+
// pages. Note this tends to happen for larger block sizes.
1572+
if (RegionPushedBytesDelta > (1ULL << GroupSizeLog))
1573+
return true;
1574+
15681575
// In this case, we are over the threshold but we just did some page
15691576
// release in the same release interval. This is a hint that we may want
15701577
// a higher threshold so that we can release more memory at once.

0 commit comments

Comments
 (0)