Skip to content

Commit ec175de

Browse files
committed
[scudo] On Android, only release when changing M_DECAY_TIME to 0.
There is no reason to make a force release to OS call when enabling the decay timer. When disabling, it's logical since the intent is to start using less memory. When enabling, it's not logical because it usually happens early in the process life cycle and a caller can do it themselves if necessary. This is in Android only code right now, so only affects Android devices.
1 parent 4629291 commit ec175de

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

compiler-rt/lib/scudo/standalone/wrappers_c.inc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,17 @@ void SCUDO_PREFIX(malloc_postinit)() {
247247
INTERFACE WEAK int SCUDO_PREFIX(mallopt)(int param, int value) {
248248
if (param == M_DECAY_TIME) {
249249
if (SCUDO_ANDROID) {
250-
// Before changing the interval, reset the memory usage status by doing a
251-
// M_PURGE call so that we can minimize the impact of any unreleased pages
252-
// introduced by interval transition.
253-
SCUDO_ALLOCATOR.releaseToOS(scudo::ReleaseToOS::Force);
254-
255250
// The values allowed on Android are {-1, 0, 1}. "1" means the longest
256251
// interval.
257252
CHECK(value >= -1 && value <= 1);
258253
if (value == 1)
259254
value = INT32_MAX;
255+
else if (value == 0) {
256+
// Before disabling the interval, reset the memory usage status by doing
257+
// a M_PURGE call so that we can minimize the impact of any unreleased
258+
// pages introduced by interval transition.
259+
SCUDO_ALLOCATOR.releaseToOS(scudo::ReleaseToOS::Force);
260+
}
260261
}
261262

262263
SCUDO_ALLOCATOR.setOption(scudo::Option::ReleaseInterval,

0 commit comments

Comments
 (0)