Skip to content

Commit 11f4f45

Browse files
authored
[scudo] Support setting default value of ReleaseToOsIntervalMs in config (#90256)
1 parent 1563a87 commit 11f4f45

File tree

6 files changed

+16
-1
lines changed

6 files changed

+16
-1
lines changed

compiler-rt/lib/scudo/standalone/allocator_config.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ PRIMARY_REQUIRED(const s32, MaxReleaseToOsIntervalMs)
8989
// Indicates support for offsetting the start of a region by a random number of
9090
// pages. This is only used if `EnableContiguousRegions` is enabled.
9191
PRIMARY_OPTIONAL(const bool, EnableRandomOffset, false)
92+
PRIMARY_OPTIONAL(const s32, DefaultReleaseToOsIntervalMs, INT32_MIN)
9293

9394
// When `EnableContiguousRegions` is true, all regions will be be arranged in
9495
// adjacency. This will reduce the fragmentation caused by region allocations
@@ -118,6 +119,7 @@ SECONDARY_CACHE_OPTIONAL(const u32, DefaultMaxEntriesCount, 0)
118119
SECONDARY_CACHE_OPTIONAL(const uptr, DefaultMaxEntrySize, 0)
119120
SECONDARY_CACHE_OPTIONAL(const s32, MinReleaseToOsIntervalMs, INT32_MIN)
120121
SECONDARY_CACHE_OPTIONAL(const s32, MaxReleaseToOsIntervalMs, INT32_MAX)
122+
SECONDARY_CACHE_OPTIONAL(const s32, DefaultReleaseToOsIntervalMs, INT32_MIN)
121123

122124
#undef SECONDARY_CACHE_OPTIONAL
123125
#undef SECONDARY_REQUIRED_TEMPLATE_TYPE

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ class Allocator {
173173
static_cast<u32>(getFlags()->quarantine_max_chunk_size);
174174

175175
Stats.init();
176+
// TODO(chiahungduan): Given that we support setting the default value in
177+
// the PrimaryConfig and CacheConfig, consider to deprecate the use of
178+
// `release_to_os_interval_ms` flag.
176179
const s32 ReleaseToOsIntervalMs = getFlags()->release_to_os_interval_ms;
177180
Primary.init(ReleaseToOsIntervalMs);
178181
Secondary.init(&Stats, ReleaseToOsIntervalMs);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ SCUDO_FLAG(bool, may_return_null, true,
4242
"returning NULL in otherwise non-fatal error scenarios, eg: OOM, "
4343
"invalid allocation alignments, etc.")
4444

45-
SCUDO_FLAG(int, release_to_os_interval_ms, SCUDO_ANDROID ? INT32_MIN : 5000,
45+
SCUDO_FLAG(int, release_to_os_interval_ms, 5000,
4646
"Interval (in milliseconds) at which to attempt release of unused "
4747
"memory to the OS. Negative values disable the feature.")
4848

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ template <typename Config> class SizeClassAllocator32 {
8888
Sci->MinRegionIndex = NumRegions;
8989
Sci->ReleaseInfo.LastReleaseAtNs = Time;
9090
}
91+
92+
// The default value in the primary config has the higher priority.
93+
if (Config::getDefaultReleaseToOsIntervalMs() != INT32_MIN)
94+
ReleaseToOsInterval = Config::getDefaultReleaseToOsIntervalMs();
9195
setOption(Option::ReleaseInterval, static_cast<sptr>(ReleaseToOsInterval));
9296
}
9397

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ template <typename Config> class SizeClassAllocator64 {
147147
for (uptr I = 0; I < NumClasses; I++)
148148
getRegionInfo(I)->FLLockCV.bindTestOnly(getRegionInfo(I)->FLLock);
149149

150+
// The default value in the primary config has the higher priority.
151+
if (Config::getDefaultReleaseToOsIntervalMs() != INT32_MIN)
152+
ReleaseToOsInterval = Config::getDefaultReleaseToOsIntervalMs();
150153
setOption(Option::ReleaseInterval, static_cast<sptr>(ReleaseToOsInterval));
151154
}
152155

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ template <typename Config> class MapAllocatorCache {
209209
static_cast<sptr>(Config::getDefaultMaxEntriesCount()));
210210
setOption(Option::MaxCacheEntrySize,
211211
static_cast<sptr>(Config::getDefaultMaxEntrySize()));
212+
// The default value in the cache config has the higher priority.
213+
if (Config::getDefaultReleaseToOsIntervalMs() != INT32_MIN)
214+
ReleaseToOsInterval = Config::getDefaultReleaseToOsIntervalMs();
212215
setOption(Option::ReleaseInterval, static_cast<sptr>(ReleaseToOsInterval));
213216
}
214217

0 commit comments

Comments
 (0)