diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-04-30 23:14:09 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-04-30 23:14:09 +0000 |
commit | f1f33365fd141e6ce94dab2649edad9c99fd2bcc (patch) | |
tree | 9b37a20091e43640d27289a05712fb880bdaf020 | |
parent | 23a183f5f4e90438547130a41caa7fc585162c2c (diff) | |
parent | 4515d3be41056889ce4cba7513f2eff62fcecccc (diff) | |
download | scudo-sdk-release.tar.gz |
Snap for 11785460 from 4515d3be41056889ce4cba7513f2eff62fcecccc to sdk-releasesdk-release
Change-Id: Ifb23c102619a18fc59e8b8afd8dc303f1865deb9
-rw-r--r-- | config/custom_scudo_config.h | 6 | ||||
-rw-r--r-- | standalone/allocator_config.def | 2 | ||||
-rw-r--r-- | standalone/combined.h | 3 | ||||
-rw-r--r-- | standalone/flags.inc | 2 | ||||
-rw-r--r-- | standalone/mem_map_fuchsia.cpp | 34 | ||||
-rw-r--r-- | standalone/primary32.h | 4 | ||||
-rw-r--r-- | standalone/primary64.h | 7 | ||||
-rw-r--r-- | standalone/secondary.h | 3 | ||||
-rw-r--r-- | standalone/wrappers_c.inc | 10 |
9 files changed, 43 insertions, 28 deletions
diff --git a/config/custom_scudo_config.h b/config/custom_scudo_config.h index 5e85d0fe1a7..26f590e3c25 100644 --- a/config/custom_scudo_config.h +++ b/config/custom_scudo_config.h @@ -107,8 +107,9 @@ struct AndroidNormalConfig { static const uptr GroupSizeLog = 18U; typedef uptr CompactPtrT; #endif - static const s32 MinReleaseToOsIntervalMs = 1000; + static const s32 MinReleaseToOsIntervalMs = -1; static const s32 MaxReleaseToOsIntervalMs = 1000; + static const s32 DefaultReleaseToOsIntervalMs = 1000; }; #if SCUDO_CAN_USE_PRIMARY64 template <typename Config> using PrimaryT = SizeClassAllocator64<Config>; @@ -122,8 +123,9 @@ struct AndroidNormalConfig { static const u32 QuarantineSize = 32U; static const u32 DefaultMaxEntriesCount = 32U; static const uptr DefaultMaxEntrySize = 2UL << 20; - static const s32 MinReleaseToOsIntervalMs = 0; + static const s32 MinReleaseToOsIntervalMs = -1; static const s32 MaxReleaseToOsIntervalMs = 1000; + static const s32 DefaultReleaseToOsIntervalMs = 0; }; template <typename Config> using CacheT = MapAllocatorCache<Config>; }; diff --git a/standalone/allocator_config.def b/standalone/allocator_config.def index 9691a007eed..dcd130ac449 100644 --- a/standalone/allocator_config.def +++ b/standalone/allocator_config.def @@ -89,6 +89,7 @@ PRIMARY_REQUIRED(const s32, MaxReleaseToOsIntervalMs) // Indicates support for offsetting the start of a region by a random number of // pages. This is only used if `EnableContiguousRegions` is enabled. PRIMARY_OPTIONAL(const bool, EnableRandomOffset, false) +PRIMARY_OPTIONAL(const s32, DefaultReleaseToOsIntervalMs, INT32_MIN) // When `EnableContiguousRegions` is true, all regions will be be arranged in // adjacency. This will reduce the fragmentation caused by region allocations @@ -118,6 +119,7 @@ SECONDARY_CACHE_OPTIONAL(const u32, DefaultMaxEntriesCount, 0) SECONDARY_CACHE_OPTIONAL(const uptr, DefaultMaxEntrySize, 0) SECONDARY_CACHE_OPTIONAL(const s32, MinReleaseToOsIntervalMs, INT32_MIN) SECONDARY_CACHE_OPTIONAL(const s32, MaxReleaseToOsIntervalMs, INT32_MAX) +SECONDARY_CACHE_OPTIONAL(const s32, DefaultReleaseToOsIntervalMs, INT32_MIN) #undef SECONDARY_CACHE_OPTIONAL #undef SECONDARY_REQUIRED_TEMPLATE_TYPE diff --git a/standalone/combined.h b/standalone/combined.h index e7bc90cd096..927513dea92 100644 --- a/standalone/combined.h +++ b/standalone/combined.h @@ -173,6 +173,9 @@ public: static_cast<u32>(getFlags()->quarantine_max_chunk_size); Stats.init(); + // TODO(chiahungduan): Given that we support setting the default value in + // the PrimaryConfig and CacheConfig, consider to deprecate the use of + // `release_to_os_interval_ms` flag. const s32 ReleaseToOsIntervalMs = getFlags()->release_to_os_interval_ms; Primary.init(ReleaseToOsIntervalMs); Secondary.init(&Stats, ReleaseToOsIntervalMs); diff --git a/standalone/flags.inc b/standalone/flags.inc index f5a2bab5057..ff0c28e1db7 100644 --- a/standalone/flags.inc +++ b/standalone/flags.inc @@ -42,7 +42,7 @@ SCUDO_FLAG(bool, may_return_null, true, "returning NULL in otherwise non-fatal error scenarios, eg: OOM, " "invalid allocation alignments, etc.") -SCUDO_FLAG(int, release_to_os_interval_ms, SCUDO_ANDROID ? INT32_MIN : 5000, +SCUDO_FLAG(int, release_to_os_interval_ms, 5000, "Interval (in milliseconds) at which to attempt release of unused " "memory to the OS. Negative values disable the feature.") diff --git a/standalone/mem_map_fuchsia.cpp b/standalone/mem_map_fuchsia.cpp index 5f3c8b81c07..fc793abf44c 100644 --- a/standalone/mem_map_fuchsia.cpp +++ b/standalone/mem_map_fuchsia.cpp @@ -108,9 +108,9 @@ bool MemMapFuchsia::mapImpl(UNUSED uptr Addr, uptr Size, const char *Name, // Create the VMO. zx_status_t Status = _zx_vmo_create(Size, 0, &Vmo); if (UNLIKELY(Status != ZX_OK)) { - if (!IsNoMemError(Status) || !AllowNoMem) - dieOnError(Status, "zx_vmo_create", Size); - return false; + if (AllowNoMem && IsNoMemError(Status)) + return false; + dieOnError(Status, "zx_vmo_create", Size); } if (Name != nullptr) @@ -123,15 +123,15 @@ bool MemMapFuchsia::mapImpl(UNUSED uptr Addr, uptr Size, const char *Name, Status = _zx_vmar_map(_zx_vmar_root_self(), MapFlags, 0, Vmo, 0, Size, &MapAddr); if (UNLIKELY(Status != ZX_OK)) { - if (!IsNoMemError(Status) || !AllowNoMem) - dieOnError(Status, "zx_vmar_map", Size); - - Status = _zx_handle_close(Vmo); - CHECK_EQ(Status, ZX_OK); + if (AllowNoMem && IsNoMemError(Status)) { + Status = _zx_handle_close(Vmo); + CHECK_EQ(Status, ZX_OK); - MapAddr = 0; - Vmo = ZX_HANDLE_INVALID; - return false; + MapAddr = 0; + Vmo = ZX_HANDLE_INVALID; + return false; + } + dieOnError(Status, "zx_vmar_map", Size); } if (PreCommit) { @@ -194,9 +194,9 @@ bool MemMapFuchsia::remapImpl(uptr Addr, uptr Size, const char *Name, _zx_vmar_map(_zx_vmar_root_self(), MapFlags, Addr - getRootVmarBase(), Vmo, Addr - MapAddr, Size, &MappedAddr); if (UNLIKELY(Status != ZX_OK)) { - if (!IsNoMemError(Status) || !AllowNoMem) - dieOnError(Status, "zx_vmar_map", Size); - return false; + if (AllowNoMem && IsNoMemError(Status)) + return false; + dieOnError(Status, "zx_vmar_map", Size); } DCHECK_EQ(Addr, MappedAddr); @@ -234,9 +234,9 @@ bool ReservedMemoryFuchsia::createImpl(UNUSED uptr Addr, uptr Size, zx_status_t Status = _zx_vmar_map(_zx_vmar_root_self(), ZX_VM_ALLOW_FAULTS, 0, getPlaceholderVmo(), 0, Size, &Base); if (UNLIKELY(Status != ZX_OK)) { - if (!IsNoMemError(Status) || !AllowNoMem) - dieOnError(Status, "zx_vmar_map", Size); - return false; + if (AllowNoMem && IsNoMemError(Status)) + return false; + dieOnError(Status, "zx_vmar_map", Size); } Capacity = Size; diff --git a/standalone/primary32.h b/standalone/primary32.h index 1d8a77b73e5..ebfb8dfe0a3 100644 --- a/standalone/primary32.h +++ b/standalone/primary32.h @@ -88,6 +88,10 @@ public: Sci->MinRegionIndex = NumRegions; Sci->ReleaseInfo.LastReleaseAtNs = Time; } + + // The default value in the primary config has the higher priority. + if (Config::getDefaultReleaseToOsIntervalMs() != INT32_MIN) + ReleaseToOsInterval = Config::getDefaultReleaseToOsIntervalMs(); setOption(Option::ReleaseInterval, static_cast<sptr>(ReleaseToOsInterval)); } diff --git a/standalone/primary64.h b/standalone/primary64.h index 61d57976ae4..bed2ccb8b99 100644 --- a/standalone/primary64.h +++ b/standalone/primary64.h @@ -147,6 +147,9 @@ public: for (uptr I = 0; I < NumClasses; I++) getRegionInfo(I)->FLLockCV.bindTestOnly(getRegionInfo(I)->FLLock); + // The default value in the primary config has the higher priority. + if (Config::getDefaultReleaseToOsIntervalMs() != INT32_MIN) + ReleaseToOsInterval = Config::getDefaultReleaseToOsIntervalMs(); setOption(Option::ReleaseInterval, static_cast<sptr>(ReleaseToOsInterval)); } @@ -884,9 +887,10 @@ private: ScopedLock ML(Region->MMLock); const bool RegionIsExhausted = Region->Exhausted; - if (!RegionIsExhausted) + if (!RegionIsExhausted) { PopCount = populateFreeListAndPopBlocks(C, ClassId, Region, ToArray, MaxBlockCount); + } ReportRegionExhausted = !RegionIsExhausted && Region->Exhausted; { @@ -1019,7 +1023,6 @@ private: MAP_ALLOWNOMEM))) { Printf("Can't reserve pages for size class %zu.\n", getSizeByClassId(ClassId)); - Region->Exhausted = true; return 0U; } initRegion(Region, ClassId, diff --git a/standalone/secondary.h b/standalone/secondary.h index 674af507177..d8c9f5bcfca 100644 --- a/standalone/secondary.h +++ b/standalone/secondary.h @@ -209,6 +209,9 @@ public: static_cast<sptr>(Config::getDefaultMaxEntriesCount())); setOption(Option::MaxCacheEntrySize, static_cast<sptr>(Config::getDefaultMaxEntrySize())); + // The default value in the cache config has the higher priority. + if (Config::getDefaultReleaseToOsIntervalMs() != INT32_MIN) + ReleaseToOsInterval = Config::getDefaultReleaseToOsIntervalMs(); setOption(Option::ReleaseInterval, static_cast<sptr>(ReleaseToOsInterval)); } diff --git a/standalone/wrappers_c.inc b/standalone/wrappers_c.inc index 21d5b7add51..59f3fb0962f 100644 --- a/standalone/wrappers_c.inc +++ b/standalone/wrappers_c.inc @@ -252,13 +252,11 @@ INTERFACE WEAK int SCUDO_PREFIX(mallopt)(int param, int value) { // introduced by interval transition. SCUDO_ALLOCATOR.releaseToOS(scudo::ReleaseToOS::Force); - if (value == 0) { - // Will set the release values to their minimum values. - value = INT32_MIN; - } else { - // Will set the release values to their maximum values. + // The values allowed on Android are {-1, 0, 1}. "1" means the longest + // interval. + CHECK(value >= -1 && value <= 1); + if (value == 1) value = INT32_MAX; - } } SCUDO_ALLOCATOR.setOption(scudo::Option::ReleaseInterval, |