blob: 240c8266a3205a79c541c7897b0f05ea049fcaf1 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2020 The Chromium Authors
Takashi Sakamoto0044f2f2020-06-04 04:19:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Takashi Sakamoto1b5312d2021-10-18 08:53:465#include "base/allocator/partition_alloc_features.h"
Takashi Sakamoto0044f2f2020-06-04 04:19:166
Mingyu Leif0cffc92023-10-18 18:20:077#include "base/allocator/miracle_parameter.h"
David Sanders6e709942022-04-05 06:49:268#include "base/base_export.h"
Takashi Sakamoto0044f2f2020-06-04 04:19:169#include "base/feature_list.h"
Takashi Sakamoto2e824dc2023-07-14 01:52:3510#include "base/features.h"
Mingyu Leiaf2e0d92023-09-07 06:35:0811#include "base/metrics/field_trial_params.h"
12#include "base/time/time.h"
Benoit Lize2e4a8f62022-01-12 13:35:2113#include "build/build_config.h"
Keishi Hattori50365c22023-04-27 08:09:2314#include "build/chromecast_buildflags.h"
Arthur Sonzognifd39d612024-06-26 08:16:2315#include "partition_alloc/buildflags.h"
Yuki Shiino985ab91e2024-03-14 07:20:4616#include "partition_alloc/partition_alloc_base/time/time.h"
Kalvin Leee76b3462024-05-15 00:47:1317#include "partition_alloc/partition_alloc_constants.h"
Yuki Shiino985ab91e2024-03-14 07:20:4618#include "partition_alloc/partition_root.h"
19#include "partition_alloc/shim/allocator_shim_dispatch_to_noop_on_free.h"
20#include "partition_alloc/thread_cache.h"
Takashi Sakamoto0044f2f2020-06-04 04:19:1621
Peter Kasting811504a72025-01-09 03:18:5022namespace base::features {
Takashi Sakamoto0044f2f2020-06-04 04:19:1623
Takashi Sakamoto9f590212024-09-20 04:58:4024namespace {
25
26static constexpr char kPAFeatureEnabledProcessesStr[] = "enabled-processes";
27static constexpr char kBrowserOnlyStr[] = "browser-only";
28static constexpr char kBrowserAndRendererStr[] = "browser-and-renderer";
29static constexpr char kNonRendererStr[] = "non-renderer";
30static constexpr char kAllProcessesStr[] = "all-processes";
31
32#if PA_CONFIG(ENABLE_SHADOW_METADATA)
33static constexpr char kRendererOnlyStr[] = "renderer-only";
34static constexpr char kAllChildProcessesStr[] = "all-child-processes";
35#endif // PA_CONFIG(ENABLE_SHADOW_METADATA)
36
37} // namespace
38
Paul Semelb0ce4842022-09-28 08:09:5339BASE_FEATURE(kPartitionAllocUnretainedDanglingPtr,
40 "PartitionAllocUnretainedDanglingPtr",
Paul Semel1c64c332023-06-13 12:52:3941 FEATURE_ENABLED_BY_DEFAULT);
Paul Semelb0ce4842022-09-28 08:09:5342
43constexpr FeatureParam<UnretainedDanglingPtrMode>::Option
44 kUnretainedDanglingPtrModeOption[] = {
45 {UnretainedDanglingPtrMode::kCrash, "crash"},
46 {UnretainedDanglingPtrMode::kDumpWithoutCrashing,
47 "dump_without_crashing"},
48};
Takashi Toyoshimacff0ce62025-01-17 14:32:1249// Note: Do not use the prepared macro as of no need for a local cache.
50constinit const FeatureParam<UnretainedDanglingPtrMode>
Paul Semelb0ce4842022-09-28 08:09:5351 kUnretainedDanglingPtrModeParam = {
52 &kPartitionAllocUnretainedDanglingPtr,
53 "mode",
Paul Semeldafc4e522024-03-07 15:11:4854 UnretainedDanglingPtrMode::kCrash,
Paul Semelb0ce4842022-09-28 08:09:5355 &kUnretainedDanglingPtrModeOption,
56};
57
Kalvin Lee8529bdde2024-10-25 14:10:4258// Note: DPD conflicts with no-op `free()` (see
59// `base::allocator::MakeFreeNoOp()`). No-op `free()` stands down in the
60// presence of DPD, but hypothetically fully launching DPD should prompt
61// a rethink of no-op `free()`.
Daniel Cheng0fff5c232022-09-21 17:43:3462BASE_FEATURE(kPartitionAllocDanglingPtr,
63 "PartitionAllocDanglingPtr",
Arthur Sonzogni62e877a2024-04-30 16:09:4364#if PA_BUILDFLAG(ENABLE_DANGLING_RAW_PTR_FEATURE_FLAG)
mikt164333072024-02-15 14:25:1365 FEATURE_ENABLED_BY_DEFAULT
66#else
67 FEATURE_DISABLED_BY_DEFAULT
68#endif
69);
Arthur Sonzognif6e556d02023-02-21 10:09:0570
Arthur Sonzognibe6f0132022-07-06 13:54:1271constexpr FeatureParam<DanglingPtrMode>::Option kDanglingPtrModeOption[] = {
72 {DanglingPtrMode::kCrash, "crash"},
Pârise90af2c2023-01-30 14:22:4173 {DanglingPtrMode::kLogOnly, "log_only"},
Arthur Sonzognibe6f0132022-07-06 13:54:1274};
Takashi Toyoshimacff0ce62025-01-17 14:32:1275// Note: Do not use the prepared macro as of no need for a local cache.
76constinit const FeatureParam<DanglingPtrMode> kDanglingPtrModeParam{
Arthur Sonzognibe6f0132022-07-06 13:54:1277 &kPartitionAllocDanglingPtr,
78 "mode",
79 DanglingPtrMode::kCrash,
80 &kDanglingPtrModeOption,
81};
Pârise90af2c2023-01-30 14:22:4182constexpr FeatureParam<DanglingPtrType>::Option kDanglingPtrTypeOption[] = {
83 {DanglingPtrType::kAll, "all"},
84 {DanglingPtrType::kCrossTask, "cross_task"},
85};
Takashi Toyoshimacff0ce62025-01-17 14:32:1286// Note: Do not use the prepared macro as of no need for a local cache.
87constinit const FeatureParam<DanglingPtrType> kDanglingPtrTypeParam{
Pârise90af2c2023-01-30 14:22:4188 &kPartitionAllocDanglingPtr,
89 "type",
90 DanglingPtrType::kAll,
91 &kDanglingPtrTypeOption,
92};
Arthur Sonzognibe6f0132022-07-06 13:54:1293
Arthur Sonzogni62e877a2024-04-30 16:09:4394#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
Benoit Lize006cfcb2021-03-29 16:18:5295// Use a larger maximum thread cache cacheable bucket size.
Daniel Cheng0fff5c232022-09-21 17:43:3496BASE_FEATURE(kPartitionAllocLargeThreadCacheSize,
97 "PartitionAllocLargeThreadCacheSize",
Bartek Nowierski4152aa62023-09-11 14:48:4098 FEATURE_ENABLED_BY_DEFAULT);
Benoit Lize006cfcb2021-03-29 16:18:5299
Kalvin Leee76b3462024-05-15 00:47:13100MIRACLE_PARAMETER_FOR_INT(GetPartitionAllocLargeThreadCacheSizeValue,
101 kPartitionAllocLargeThreadCacheSize,
102 "PartitionAllocLargeThreadCacheSizeValue",
103 ::partition_alloc::kThreadCacheLargeSizeThreshold)
Mingyu Leid313bb72023-09-06 02:23:28104
Mingyu Leif0cffc92023-10-18 18:20:07105MIRACLE_PARAMETER_FOR_INT(
106 GetPartitionAllocLargeThreadCacheSizeValueForLowRAMAndroid,
107 kPartitionAllocLargeThreadCacheSize,
108 "PartitionAllocLargeThreadCacheSizeValueForLowRAMAndroid",
Kalvin Leee76b3462024-05-15 00:47:13109 ::partition_alloc::kThreadCacheDefaultSizeThreshold)
Mingyu Leid313bb72023-09-06 02:23:28110
Daniel Cheng0fff5c232022-09-21 17:43:34111BASE_FEATURE(kPartitionAllocLargeEmptySlotSpanRing,
112 "PartitionAllocLargeEmptySlotSpanRing",
François Doray65df3e42024-12-13 21:06:44113#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
Scott Violetd802f822024-06-05 16:00:19114 FEATURE_ENABLED_BY_DEFAULT);
115#else
Daniel Cheng0fff5c232022-09-21 17:43:34116 FEATURE_DISABLED_BY_DEFAULT);
Scott Violetd802f822024-06-05 16:00:19117#endif
miktca35b70b2023-11-01 12:55:56118
mikt9e6b42c2024-09-10 07:59:30119BASE_FEATURE(kPartitionAllocWithAdvancedChecks,
120 "PartitionAllocWithAdvancedChecks",
121 FEATURE_DISABLED_BY_DEFAULT);
122constexpr FeatureParam<PartitionAllocWithAdvancedChecksEnabledProcesses>::Option
123 kPartitionAllocWithAdvancedChecksEnabledProcessesOptions[] = {
124 {PartitionAllocWithAdvancedChecksEnabledProcesses::kBrowserOnly,
Takashi Sakamoto9f590212024-09-20 04:58:40125 kBrowserOnlyStr},
mikt9e6b42c2024-09-10 07:59:30126 {PartitionAllocWithAdvancedChecksEnabledProcesses::kBrowserAndRenderer,
Takashi Sakamoto9f590212024-09-20 04:58:40127 kBrowserAndRendererStr},
mikt9e6b42c2024-09-10 07:59:30128 {PartitionAllocWithAdvancedChecksEnabledProcesses::kNonRenderer,
Takashi Sakamoto9f590212024-09-20 04:58:40129 kNonRendererStr},
mikt9e6b42c2024-09-10 07:59:30130 {PartitionAllocWithAdvancedChecksEnabledProcesses::kAllProcesses,
Takashi Sakamoto9f590212024-09-20 04:58:40131 kAllProcessesStr}};
Takashi Toyoshimacff0ce62025-01-17 14:32:12132// Note: Do not use the prepared macro as of no need for a local cache.
133constinit const FeatureParam<PartitionAllocWithAdvancedChecksEnabledProcesses>
mikt9e6b42c2024-09-10 07:59:30134 kPartitionAllocWithAdvancedChecksEnabledProcessesParam{
Takashi Sakamoto9f590212024-09-20 04:58:40135 &kPartitionAllocWithAdvancedChecks, kPAFeatureEnabledProcessesStr,
mikt9e6b42c2024-09-10 07:59:30136 PartitionAllocWithAdvancedChecksEnabledProcesses::kBrowserOnly,
137 &kPartitionAllocWithAdvancedChecksEnabledProcessesOptions};
138
miktca35b70b2023-11-01 12:55:56139BASE_FEATURE(kPartitionAllocSchedulerLoopQuarantine,
140 "PartitionAllocSchedulerLoopQuarantine",
141 FEATURE_DISABLED_BY_DEFAULT);
mikt4b233ef72024-04-17 02:17:04142// Scheduler Loop Quarantine's per-branch capacity in bytes.
Takashi Toyoshimacff0ce62025-01-17 14:32:12143// Note: Do not use the prepared macro as of no need for a local cache.
144constinit const FeatureParam<int>
mikt4b233ef72024-04-17 02:17:04145 kPartitionAllocSchedulerLoopQuarantineBranchCapacity{
146 &kPartitionAllocSchedulerLoopQuarantine,
147 "PartitionAllocSchedulerLoopQuarantineBranchCapacity", 0};
mikt0941a8e2025-01-08 15:02:48148// Scheduler Loop Quarantine's capacity for the UI thread in bytes.
Takashi Toyoshimacff0ce62025-01-17 14:32:12149BASE_FEATURE_PARAM(int,
150 kPartitionAllocSchedulerLoopQuarantineBrowserUICapacity,
151 &kPartitionAllocSchedulerLoopQuarantine,
152 "PartitionAllocSchedulerLoopQuarantineBrowserUICapacity",
153 0);
mikt95ad4ae2023-11-27 05:29:54154
155BASE_FEATURE(kPartitionAllocZappingByFreeFlags,
156 "PartitionAllocZappingByFreeFlags",
157 FEATURE_DISABLED_BY_DEFAULT);
Benoît Lizéb460d7e2024-10-30 13:17:48158
159BASE_FEATURE(kPartitionAllocEventuallyZeroFreedMemory,
160 "PartitionAllocEventuallyZeroFreedMemory",
161 FEATURE_DISABLED_BY_DEFAULT);
Benoît Lizé53690082025-01-09 12:26:03162
Benoît Lizé4d624322025-04-10 15:42:21163// Evaluated and positive stability and peformance-wise on Linux-based systems,
164// disabled elsewhere (for now). Does not apply to Windows.
Benoît Lizé53690082025-01-09 12:26:03165BASE_FEATURE(kPartitionAllocFewerMemoryRegions,
166 "PartitionAllocFewerMemoryRegions",
Benoît Lizé4d624322025-04-10 15:42:21167#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
Benoît Lizébe2cb9402025-04-09 17:34:09168 FEATURE_ENABLED_BY_DEFAULT);
Benoît Lizé4d624322025-04-10 15:42:21169#else
170 FEATURE_DISABLED_BY_DEFAULT);
171#endif
Arthur Sonzogni62e877a2024-04-30 16:09:43172#endif // PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
Benoit Lizef13d7932022-01-07 10:29:32173
Daniel Cheng0fff5c232022-09-21 17:43:34174BASE_FEATURE(kPartitionAllocBackupRefPtr,
175 "PartitionAllocBackupRefPtr",
Arthur Sonzogni647b65eb62024-09-12 09:52:30176#if PA_BUILDFLAG(ENABLE_BACKUP_REF_PTR_FEATURE_FLAG)
Daniel Cheng0fff5c232022-09-21 17:43:34177 FEATURE_ENABLED_BY_DEFAULT
Keishi Hattoriebb719d2022-05-13 09:40:30178#else
Daniel Cheng0fff5c232022-09-21 17:43:34179 FEATURE_DISABLED_BY_DEFAULT
Keishi Hattoriebb719d2022-05-13 09:40:30180#endif
Daniel Cheng0fff5c232022-09-21 17:43:34181);
Keishi Hattoriaf499ac2021-09-22 23:45:04182
183constexpr FeatureParam<BackupRefPtrEnabledProcesses>::Option
184 kBackupRefPtrEnabledProcessesOptions[] = {
Takashi Sakamoto9f590212024-09-20 04:58:40185 {BackupRefPtrEnabledProcesses::kBrowserOnly, kBrowserOnlyStr},
Keishi Hattoriaf499ac2021-09-22 23:45:04186 {BackupRefPtrEnabledProcesses::kBrowserAndRenderer,
Takashi Sakamoto9f590212024-09-20 04:58:40187 kBrowserAndRendererStr},
188 {BackupRefPtrEnabledProcesses::kNonRenderer, kNonRendererStr},
189 {BackupRefPtrEnabledProcesses::kAllProcesses, kAllProcessesStr}};
Keishi Hattoriaf499ac2021-09-22 23:45:04190
Takashi Toyoshimacff0ce62025-01-17 14:32:12191BASE_FEATURE_ENUM_PARAM(BackupRefPtrEnabledProcesses,
192 kBackupRefPtrEnabledProcessesParam,
193 &kPartitionAllocBackupRefPtr,
194 kPAFeatureEnabledProcessesStr,
Keishi Hattori9753766fde2025-05-02 03:07:52195#if PA_BUILDFLAG(IS_ANDROID)
Takashi Toyoshimacff0ce62025-01-17 14:32:12196 BackupRefPtrEnabledProcesses::kNonRenderer,
Keishi Hattori268fad42024-08-16 19:04:11197#else
Takashi Toyoshimacff0ce62025-01-17 14:32:12198 BackupRefPtrEnabledProcesses::kAllProcesses,
Keishi Hattori268fad42024-08-16 19:04:11199#endif
Takashi Toyoshimacff0ce62025-01-17 14:32:12200 &kBackupRefPtrEnabledProcessesOptions);
Keishi Hattoriaf499ac2021-09-22 23:45:04201
Bartek Nowierskida7d8f1c2021-12-08 19:30:59202constexpr FeatureParam<BackupRefPtrMode>::Option kBackupRefPtrModeOptions[] = {
Bartek Nowierskiea35aa522021-12-10 07:08:20203 {BackupRefPtrMode::kDisabled, "disabled"},
Bartek Nowierskida7d8f1c2021-12-08 19:30:59204 {BackupRefPtrMode::kEnabled, "enabled"},
Bartek Nowierskida7d8f1c2021-12-08 19:30:59205};
Bartek Nowierskie9ad8a7d2021-11-04 08:37:39206
Takashi Toyoshimacff0ce62025-01-17 14:32:12207BASE_FEATURE_ENUM_PARAM(BackupRefPtrMode,
208 kBackupRefPtrModeParam,
209 &kPartitionAllocBackupRefPtr,
210 "brp-mode",
211 BackupRefPtrMode::kEnabled,
212 &kBackupRefPtrModeOptions);
213// Note: Do not use the prepared macro as of no need for a local cache.
214constinit const FeatureParam<int> kBackupRefPtrExtraExtrasSizeParam{
mikt26445302024-12-18 06:42:16215 &kPartitionAllocBackupRefPtr, "brp-extra-extras-size", 0};
mikt3de81272025-06-19 06:25:47216constinit const FeatureParam<bool> kBackupRefPtrSuppressDoubleFreeDetectedCrash{
217 &kPartitionAllocBackupRefPtr, "brp-suppress-double-free-detected-crash",
218 false};
219constinit const FeatureParam<bool> kBackupRefPtrSuppressCorruptionDetectedCrash{
220 &kPartitionAllocBackupRefPtr, "brp-suppress-corruption-detected-crash",
221 false};
Bartek Nowierskie9ad8a7d2021-11-04 08:37:39222
Keishi Hattori5f94b5e02023-05-23 15:01:57223BASE_FEATURE(kPartitionAllocMemoryTagging,
224 "PartitionAllocMemoryTagging",
Keishi Hattoria600f3a2024-11-01 09:10:54225#if PA_BUILDFLAG(USE_FULL_MTE) || BUILDFLAG(IS_ANDROID)
Keishi Hattoriec5b03a2024-02-16 03:28:44226 FEATURE_ENABLED_BY_DEFAULT
227#else
228 FEATURE_DISABLED_BY_DEFAULT
229#endif
230);
Keishi Hattori5f94b5e02023-05-23 15:01:57231
232constexpr FeatureParam<MemtagMode>::Option kMemtagModeOptions[] = {
233 {MemtagMode::kSync, "sync"},
234 {MemtagMode::kAsync, "async"}};
235
Takashi Toyoshimacff0ce62025-01-17 14:32:12236// Note: Do not use the prepared macro as of no need for a local cache.
237constinit const FeatureParam<MemtagMode> kMemtagModeParam{
Keishi Hattoriec5b03a2024-02-16 03:28:44238 &kPartitionAllocMemoryTagging, "memtag-mode",
Arthur Sonzogni62e877a2024-04-30 16:09:43239#if PA_BUILDFLAG(USE_FULL_MTE)
Keishi Hattoriec5b03a2024-02-16 03:28:44240 MemtagMode::kSync,
241#else
242 MemtagMode::kAsync,
243#endif
Keishi Hattori5f94b5e02023-05-23 15:01:57244 &kMemtagModeOptions};
245
Keishi Hattori12263162024-07-31 08:22:54246constexpr FeatureParam<RetagMode>::Option kRetagModeOptions[] = {
247 {RetagMode::kIncrement, "increment"},
248 {RetagMode::kRandom, "random"},
249};
250
Takashi Toyoshimacff0ce62025-01-17 14:32:12251// Note: Do not use the prepared macro as of no need for a local cache.
252constinit const FeatureParam<RetagMode> kRetagModeParam{
Keishi Hattori12263162024-07-31 08:22:54253 &kPartitionAllocMemoryTagging, "retag-mode", RetagMode::kIncrement,
254 &kRetagModeOptions};
255
Keishi Hattori5f94b5e02023-05-23 15:01:57256constexpr FeatureParam<MemoryTaggingEnabledProcesses>::Option
257 kMemoryTaggingEnabledProcessesOptions[] = {
Takashi Sakamoto9f590212024-09-20 04:58:40258 {MemoryTaggingEnabledProcesses::kBrowserOnly, kBrowserOnlyStr},
259 {MemoryTaggingEnabledProcesses::kNonRenderer, kNonRendererStr},
260 {MemoryTaggingEnabledProcesses::kAllProcesses, kAllProcessesStr}};
Keishi Hattori5f94b5e02023-05-23 15:01:57261
Takashi Toyoshimacff0ce62025-01-17 14:32:12262// Note: Do not use the prepared macro as of no need for a local cache.
263constinit const FeatureParam<MemoryTaggingEnabledProcesses>
Keishi Hattori5f94b5e02023-05-23 15:01:57264 kMemoryTaggingEnabledProcessesParam{
Takashi Sakamoto9f590212024-09-20 04:58:40265 &kPartitionAllocMemoryTagging, kPAFeatureEnabledProcessesStr,
Arthur Sonzogni62e877a2024-04-30 16:09:43266#if PA_BUILDFLAG(USE_FULL_MTE)
Keishi Hattoriec5b03a2024-02-16 03:28:44267 MemoryTaggingEnabledProcesses::kAllProcesses,
268#else
Keishi Hattoria600f3a2024-11-01 09:10:54269 MemoryTaggingEnabledProcesses::kNonRenderer,
Keishi Hattoriec5b03a2024-02-16 03:28:44270#endif
Keishi Hattori5f94b5e02023-05-23 15:01:57271 &kMemoryTaggingEnabledProcessesOptions};
272
Keishi Hattori4dddbef22023-06-01 09:31:56273BASE_FEATURE(kKillPartitionAllocMemoryTagging,
274 "KillPartitionAllocMemoryTagging",
275 FEATURE_DISABLED_BY_DEFAULT);
276
Keishi Hattori806e3d8e2023-09-06 05:55:52277BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPermissiveMte);
278BASE_FEATURE(kPartitionAllocPermissiveMte,
279 "PartitionAllocPermissiveMte",
Arthur Sonzogni62e877a2024-04-30 16:09:43280#if PA_BUILDFLAG(USE_FULL_MTE)
Keishi Hattoriec5b03a2024-02-16 03:28:44281 // We want to actually crash if USE_FULL_MTE is enabled.
282 FEATURE_DISABLED_BY_DEFAULT
283#else
284 FEATURE_ENABLED_BY_DEFAULT
285#endif
286);
Keishi Hattori806e3d8e2023-09-06 05:55:52287
Arthur Sonzogni44bc44b2025-02-17 13:59:07288BASE_FEATURE(kAsanBrpDereferenceCheck,
289 "AsanBrpDereferenceCheck",
290 FEATURE_ENABLED_BY_DEFAULT);
291BASE_FEATURE(kAsanBrpExtractionCheck,
292 "AsanBrpExtractionCheck", // Not much noise at the moment to
293 FEATURE_DISABLED_BY_DEFAULT); // enable by default.
294BASE_FEATURE(kAsanBrpInstantiationCheck,
295 "AsanBrpInstantiationCheck",
296 FEATURE_ENABLED_BY_DEFAULT);
Anton Bikineevdb908de2020-12-08 14:48:13297
Thiabaud Engelbrecht179001b2023-05-30 15:46:42298// If enabled, switches the bucket distribution to a denser one.
Thiabaud Engelbrecht7cd1e4a2023-04-20 14:39:20299//
300// We enable this by default everywhere except for 32-bit Android, since we saw
301// regressions there.
Thiabaud Engelbrecht179001b2023-05-30 15:46:42302BASE_FEATURE(kPartitionAllocUseDenserDistribution,
303 "PartitionAllocUseDenserDistribution",
Thiabaud Engelbrecht7cd1e4a2023-04-20 14:39:20304#if BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_32_BITS)
305 FEATURE_DISABLED_BY_DEFAULT
306#else
307 FEATURE_ENABLED_BY_DEFAULT
308#endif // BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_32_BITS)
309);
Takashi Toyoshimacff0ce62025-01-17 14:32:12310const FeatureParam<BucketDistributionMode>::Option
Thiabaud Engelbrecht179001b2023-05-30 15:46:42311 kPartitionAllocBucketDistributionOption[] = {
312 {BucketDistributionMode::kDefault, "default"},
313 {BucketDistributionMode::kDenser, "denser"},
Thiabaud Engelbrecht05f8b8112022-09-16 02:18:29314};
Takashi Toyoshimacff0ce62025-01-17 14:32:12315// Note: Do not use the prepared macro as of no need for a local cache.
316constinit const FeatureParam<BucketDistributionMode>
Peter Kasting134ef9af2024-12-28 02:30:09317 kPartitionAllocBucketDistributionParam{
318 &kPartitionAllocUseDenserDistribution, "mode",
Thiabaud Engelbrecht179001b2023-05-30 15:46:42319#if BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_32_BITS)
Peter Kasting134ef9af2024-12-28 02:30:09320 BucketDistributionMode::kDefault,
Thiabaud Engelbrecht179001b2023-05-30 15:46:42321#else
Peter Kasting134ef9af2024-12-28 02:30:09322 BucketDistributionMode::kDenser,
Thiabaud Engelbrecht179001b2023-05-30 15:46:42323#endif // BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_32_BITS)
Peter Kasting134ef9af2024-12-28 02:30:09324 &kPartitionAllocBucketDistributionOption};
Thiabaud Engelbrecht1efe4372022-02-16 19:33:09325
Bartek Nowierski1992f4532023-07-11 15:06:35326BASE_FEATURE(kPartitionAllocMemoryReclaimer,
327 "PartitionAllocMemoryReclaimer",
328 FEATURE_ENABLED_BY_DEFAULT);
Takashi Toyoshimacff0ce62025-01-17 14:32:12329BASE_FEATURE_PARAM(TimeDelta,
330 kPartitionAllocMemoryReclaimerInterval,
331 &kPartitionAllocMemoryReclaimer,
332 "interval",
333 TimeDelta() // Defaults to zero.
334);
Bartek Nowierski1992f4532023-07-11 15:06:35335
Arthur Sonzognia570236352022-12-19 13:18:54336// Configures whether we set a lower limit for renderers that do not have a main
337// frame, similar to the limit that is already done for backgrounded renderers.
338BASE_FEATURE(kLowerPAMemoryLimitForNonMainRenderers,
339 "LowerPAMemoryLimitForNonMainRenderers",
340 FEATURE_DISABLED_BY_DEFAULT);
341
Bartek Nowierskiafd88212023-08-23 15:25:24342// Whether to straighten free lists for larger slot spans in PurgeMemory() ->
343// ... -> PartitionPurgeSlotSpan().
344BASE_FEATURE(kPartitionAllocStraightenLargerSlotSpanFreeLists,
345 "PartitionAllocStraightenLargerSlotSpanFreeLists",
346 FEATURE_ENABLED_BY_DEFAULT);
Takashi Toyoshimacff0ce62025-01-17 14:32:12347const FeatureParam<partition_alloc::StraightenLargerSlotSpanFreeListsMode>::
348 Option kPartitionAllocStraightenLargerSlotSpanFreeListsModeOption[] = {
Bartek Nowierski50750532023-08-25 05:26:17349 {partition_alloc::StraightenLargerSlotSpanFreeListsMode::
350 kOnlyWhenUnprovisioning,
351 "only-when-unprovisioning"},
352 {partition_alloc::StraightenLargerSlotSpanFreeListsMode::kAlways,
353 "always"},
354};
Takashi Toyoshimacff0ce62025-01-17 14:32:12355// Note: Do not use the prepared macro as of no need for a local cache.
356constinit const FeatureParam<
357 partition_alloc::StraightenLargerSlotSpanFreeListsMode>
Bartek Nowierski50750532023-08-25 05:26:17358 kPartitionAllocStraightenLargerSlotSpanFreeListsMode = {
359 &kPartitionAllocStraightenLargerSlotSpanFreeLists,
360 "mode",
361 partition_alloc::StraightenLargerSlotSpanFreeListsMode::
362 kOnlyWhenUnprovisioning,
363 &kPartitionAllocStraightenLargerSlotSpanFreeListsModeOption,
364};
Bartek Nowierskiafd88212023-08-23 15:25:24365
Bartek Nowierski3506afbc2023-08-18 03:58:38366// Whether to sort free lists for smaller slot spans in PurgeMemory().
Bartek Nowierski3506afbc2023-08-18 03:58:38367BASE_FEATURE(kPartitionAllocSortSmallerSlotSpanFreeLists,
368 "PartitionAllocSortSmallerSlotSpanFreeLists",
369 FEATURE_ENABLED_BY_DEFAULT);
370
Benoit Lizec9ec61492022-05-20 10:51:25371// Whether to sort the active slot spans in PurgeMemory().
Daniel Cheng0fff5c232022-09-21 17:43:34372BASE_FEATURE(kPartitionAllocSortActiveSlotSpans,
373 "PartitionAllocSortActiveSlotSpans",
374 FEATURE_DISABLED_BY_DEFAULT);
Benoit Lizec9ec61492022-05-20 10:51:25375
Benoit Lize7ebe3d42022-11-24 21:12:00376#if BUILDFLAG(IS_WIN)
377// Whether to retry allocations when commit fails.
378BASE_FEATURE(kPageAllocatorRetryOnCommitFailure,
379 "PageAllocatorRetryOnCommitFailure",
380 FEATURE_DISABLED_BY_DEFAULT);
381#endif
382
Erik Chen6968d882023-10-17 23:14:42383#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
Takashi Sakamoto2e824dc2023-07-14 01:52:35384// A parameter to exclude or not exclude PartitionAllocSupport from
385// PartialLowModeOnMidRangeDevices. This is used to see how it affects
386// renderer performances, e.g. blink_perf.parser benchmark.
387// The feature: kPartialLowEndModeOnMidRangeDevices is defined in
388// //base/features.cc. Since the following feature param is related to
389// PartitionAlloc, define the param here.
Takashi Toyoshimacff0ce62025-01-17 14:32:12390BASE_FEATURE_PARAM(bool,
391 kPartialLowEndModeExcludePartitionAllocSupport,
392 &kPartialLowEndModeOnMidRangeDevices,
393 "exclude-partition-alloc-support",
394 false);
Takashi Sakamoto2e824dc2023-07-14 01:52:35395#endif
396
Mingyu Lei247628542023-09-04 06:40:21397BASE_FEATURE(kEnableConfigurableThreadCacheMultiplier,
398 "EnableConfigurableThreadCacheMultiplier",
399 base::FEATURE_DISABLED_BY_DEFAULT);
400
Mingyu Lei21e0a642023-10-18 18:29:02401MIRACLE_PARAMETER_FOR_DOUBLE(GetThreadCacheMultiplier,
402 kEnableConfigurableThreadCacheMultiplier,
403 "ThreadCacheMultiplier",
404 2.)
Mingyu Lei247628542023-09-04 06:40:21405
Mingyu Lei21e0a642023-10-18 18:29:02406MIRACLE_PARAMETER_FOR_DOUBLE(GetThreadCacheMultiplierForAndroid,
407 kEnableConfigurableThreadCacheMultiplier,
408 "ThreadCacheMultiplierForAndroid",
409 1.)
Mingyu Lei247628542023-09-04 06:40:21410
Mingyu Leiaf2e0d92023-09-07 06:35:08411constexpr partition_alloc::internal::base::TimeDelta ToPartitionAllocTimeDelta(
Takashi Toyoshimacff0ce62025-01-17 14:32:12412 TimeDelta time_delta) {
Mingyu Leiaf2e0d92023-09-07 06:35:08413 return partition_alloc::internal::base::Microseconds(
414 time_delta.InMicroseconds());
415}
416
Takashi Toyoshimacff0ce62025-01-17 14:32:12417constexpr TimeDelta FromPartitionAllocTimeDelta(
Mingyu Leiaf2e0d92023-09-07 06:35:08418 partition_alloc::internal::base::TimeDelta time_delta) {
Takashi Toyoshimacff0ce62025-01-17 14:32:12419 return Microseconds(time_delta.InMicroseconds());
Mingyu Leiaf2e0d92023-09-07 06:35:08420}
421
422BASE_FEATURE(kEnableConfigurableThreadCachePurgeInterval,
423 "EnableConfigurableThreadCachePurgeInterval",
Takashi Toyoshimacff0ce62025-01-17 14:32:12424 FEATURE_DISABLED_BY_DEFAULT);
Mingyu Leiaf2e0d92023-09-07 06:35:08425
Mingyu Leidd8c3d52023-10-19 05:28:41426MIRACLE_PARAMETER_FOR_TIME_DELTA(
427 GetThreadCacheMinPurgeIntervalValue,
428 kEnableConfigurableThreadCachePurgeInterval,
429 "ThreadCacheMinPurgeInterval",
430 FromPartitionAllocTimeDelta(partition_alloc::kMinPurgeInterval))
Mingyu Leiaf2e0d92023-09-07 06:35:08431
Mingyu Leidd8c3d52023-10-19 05:28:41432MIRACLE_PARAMETER_FOR_TIME_DELTA(
433 GetThreadCacheMaxPurgeIntervalValue,
434 kEnableConfigurableThreadCachePurgeInterval,
435 "ThreadCacheMaxPurgeInterval",
436 FromPartitionAllocTimeDelta(partition_alloc::kMaxPurgeInterval))
Mingyu Leiaf2e0d92023-09-07 06:35:08437
Mingyu Leidd8c3d52023-10-19 05:28:41438MIRACLE_PARAMETER_FOR_TIME_DELTA(
439 GetThreadCacheDefaultPurgeIntervalValue,
440 kEnableConfigurableThreadCachePurgeInterval,
Mingyu Leiaf2e0d92023-09-07 06:35:08441 "ThreadCacheDefaultPurgeInterval",
Mingyu Leidd8c3d52023-10-19 05:28:41442 FromPartitionAllocTimeDelta(partition_alloc::kDefaultPurgeInterval))
Mingyu Leiaf2e0d92023-09-07 06:35:08443
444const partition_alloc::internal::base::TimeDelta
445GetThreadCacheMinPurgeInterval() {
Mingyu Leidd8c3d52023-10-19 05:28:41446 return ToPartitionAllocTimeDelta(GetThreadCacheMinPurgeIntervalValue());
Mingyu Leiaf2e0d92023-09-07 06:35:08447}
448
449const partition_alloc::internal::base::TimeDelta
450GetThreadCacheMaxPurgeInterval() {
Mingyu Leidd8c3d52023-10-19 05:28:41451 return ToPartitionAllocTimeDelta(GetThreadCacheMaxPurgeIntervalValue());
Mingyu Leiaf2e0d92023-09-07 06:35:08452}
453
454const partition_alloc::internal::base::TimeDelta
455GetThreadCacheDefaultPurgeInterval() {
Mingyu Leidd8c3d52023-10-19 05:28:41456 return ToPartitionAllocTimeDelta(GetThreadCacheDefaultPurgeIntervalValue());
Mingyu Leiaf2e0d92023-09-07 06:35:08457}
458
459BASE_FEATURE(kEnableConfigurableThreadCacheMinCachedMemoryForPurging,
460 "EnableConfigurableThreadCacheMinCachedMemoryForPurging",
Takashi Toyoshimacff0ce62025-01-17 14:32:12461 FEATURE_DISABLED_BY_DEFAULT);
Mingyu Leiaf2e0d92023-09-07 06:35:08462
Mingyu Lei597be2d2023-10-19 05:31:04463MIRACLE_PARAMETER_FOR_INT(
464 GetThreadCacheMinCachedMemoryForPurgingBytes,
465 kEnableConfigurableThreadCacheMinCachedMemoryForPurging,
Mingyu Leiaf2e0d92023-09-07 06:35:08466 "ThreadCacheMinCachedMemoryForPurgingBytes",
Mingyu Lei597be2d2023-10-19 05:31:04467 partition_alloc::kMinCachedMemoryForPurgingBytes)
Mingyu Leiaf2e0d92023-09-07 06:35:08468
Kalvin Leee933f3a2023-10-22 07:34:44469// An apparent quarantine leak in the buffer partition unacceptably
470// bloats memory when MiraclePtr is enabled in the renderer process.
471// We believe we have found and patched the leak, but out of an
472// abundance of caution, we provide this toggle that allows us to
473// wholly disable MiraclePtr in the buffer partition, if necessary.
474//
Alison Gale47d1537d2024-04-19 21:31:46475// TODO(crbug.com/40064499): this is unneeded once
Kalvin Leee933f3a2023-10-22 07:34:44476// MiraclePtr-for-Renderer launches.
477BASE_FEATURE(kPartitionAllocDisableBRPInBufferPartition,
478 "PartitionAllocDisableBRPInBufferPartition",
479 FEATURE_DISABLED_BY_DEFAULT);
480
Scott Violet493a9462024-03-13 19:18:58481BASE_FEATURE(kPartitionAllocAdjustSizeWhenInForeground,
482 "PartitionAllocAdjustSizeWhenInForeground",
François Doray65df3e42024-12-13 21:06:44483#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
Scott Violetd802f822024-06-05 16:00:19484 FEATURE_ENABLED_BY_DEFAULT);
485#else
486 FEATURE_DISABLED_BY_DEFAULT);
487#endif
Scott Violet493a9462024-03-13 19:18:58488
Takashi Sakamoto9f590212024-09-20 04:58:40489#if PA_CONFIG(ENABLE_SHADOW_METADATA)
490BASE_FEATURE(kPartitionAllocShadowMetadata,
491 "PartitionAllocShadowMetadata",
Takashi Sakamoto99941192025-05-27 23:05:30492#if BUILDFLAG(IS_LINUX)
493 FEATURE_ENABLED_BY_DEFAULT);
494#else
Takashi Toyoshimacff0ce62025-01-17 14:32:12495 FEATURE_DISABLED_BY_DEFAULT);
Takashi Sakamoto99941192025-05-27 23:05:30496#endif
Takashi Sakamoto9f590212024-09-20 04:58:40497
498constexpr FeatureParam<ShadowMetadataEnabledProcesses>::Option
499 kShadowMetadataEnabledProcessesOptions[] = {
500 {ShadowMetadataEnabledProcesses::kRendererOnly, kRendererOnlyStr},
501 {ShadowMetadataEnabledProcesses::kAllChildProcesses,
502 kAllChildProcessesStr}};
503
Takashi Toyoshimacff0ce62025-01-17 14:32:12504// Note: Do not use the prepared macro as of no need for a local cache.
505constinit const FeatureParam<ShadowMetadataEnabledProcesses>
Takashi Sakamoto9f590212024-09-20 04:58:40506 kShadowMetadataEnabledProcessesParam{
507 &kPartitionAllocShadowMetadata, kPAFeatureEnabledProcessesStr,
508 ShadowMetadataEnabledProcesses::kRendererOnly,
509 &kShadowMetadataEnabledProcessesOptions};
510#endif // PA_CONFIG(ENABLE_SHADOW_METADATA)
511
Anand Ravi426fc832025-04-17 17:21:37512#if PA_BUILDFLAG(ENABLE_PARTITION_LOCK_PRIORITY_INHERITANCE)
513BASE_FEATURE(kPartitionAllocUsePriorityInheritanceLocks,
514 "PartitionAllocUsePriorityInheritanceLocks",
515 FEATURE_DISABLED_BY_DEFAULT);
516#endif // PA_BUILDFLAG(ENABLE_PARTITION_LOCK_PRIORITY_INHERITANCE)
517
Peter Kasting811504a72025-01-09 03:18:50518} // namespace base::features