Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Takashi Sakamoto | 1b5312d | 2021-10-18 08:53:46 | [diff] [blame] | 5 | #include "base/allocator/partition_alloc_features.h" |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 6 | |
Mingyu Lei | f0cffc9 | 2023-10-18 18:20:07 | [diff] [blame] | 7 | #include "base/allocator/miracle_parameter.h" |
Arthur Sonzogni | 0bcc023 | 2023-10-03 08:48:32 | [diff] [blame] | 8 | #include "base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/time/time.h" |
| 9 | #include "base/allocator/partition_allocator/src/partition_alloc/partition_alloc_buildflags.h" |
| 10 | #include "base/allocator/partition_allocator/src/partition_alloc/partition_root.h" |
| 11 | #include "base/allocator/partition_allocator/src/partition_alloc/thread_cache.h" |
David Sanders | 6e70994 | 2022-04-05 06:49:26 | [diff] [blame] | 12 | #include "base/base_export.h" |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 13 | #include "base/feature_list.h" |
Takashi Sakamoto | 2e824dc | 2023-07-14 01:52:35 | [diff] [blame] | 14 | #include "base/features.h" |
Mingyu Lei | af2e0d9 | 2023-09-07 06:35:08 | [diff] [blame] | 15 | #include "base/metrics/field_trial_params.h" |
| 16 | #include "base/time/time.h" |
Benoit Lize | 2e4a8f6 | 2022-01-12 13:35:21 | [diff] [blame] | 17 | #include "build/build_config.h" |
Keishi Hattori | 50365c2 | 2023-04-27 08:09:23 | [diff] [blame] | 18 | #include "build/chromecast_buildflags.h" |
| 19 | #include "build/chromeos_buildflags.h" |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 20 | |
| 21 | namespace base { |
Takashi Sakamoto | 0c9274d | 2020-10-08 04:17:37 | [diff] [blame] | 22 | namespace features { |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 23 | |
Paul Semel | b0ce484 | 2022-09-28 08:09:53 | [diff] [blame] | 24 | BASE_FEATURE(kPartitionAllocUnretainedDanglingPtr, |
| 25 | "PartitionAllocUnretainedDanglingPtr", |
Paul Semel | 1c64c33 | 2023-06-13 12:52:39 | [diff] [blame] | 26 | FEATURE_ENABLED_BY_DEFAULT); |
Paul Semel | b0ce484 | 2022-09-28 08:09:53 | [diff] [blame] | 27 | |
| 28 | constexpr FeatureParam<UnretainedDanglingPtrMode>::Option |
| 29 | kUnretainedDanglingPtrModeOption[] = { |
| 30 | {UnretainedDanglingPtrMode::kCrash, "crash"}, |
| 31 | {UnretainedDanglingPtrMode::kDumpWithoutCrashing, |
| 32 | "dump_without_crashing"}, |
| 33 | }; |
| 34 | const base::FeatureParam<UnretainedDanglingPtrMode> |
| 35 | kUnretainedDanglingPtrModeParam = { |
| 36 | &kPartitionAllocUnretainedDanglingPtr, |
| 37 | "mode", |
| 38 | UnretainedDanglingPtrMode::kDumpWithoutCrashing, |
| 39 | &kUnretainedDanglingPtrModeOption, |
| 40 | }; |
| 41 | |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 42 | BASE_FEATURE(kPartitionAllocDanglingPtr, |
| 43 | "PartitionAllocDanglingPtr", |
Paul Semel | 14afb20 | 2023-06-29 14:52:29 | [diff] [blame] | 44 | #if BUILDFLAG(ENABLE_DANGLING_RAW_PTR_FEATURE_FLAG) || \ |
| 45 | (BUILDFLAG(ENABLE_DANGLING_RAW_PTR_CHECKS) && BUILDFLAG(IS_LINUX) && \ |
Paul Semel | a55ad50 | 2023-07-28 13:47:49 | [diff] [blame] | 46 | !defined(OFFICIAL_BUILD) && (!defined(NDEBUG) || DCHECK_IS_ON())) |
Arthur Sonzogni | f6e556d0 | 2023-02-21 10:09:05 | [diff] [blame] | 47 | FEATURE_ENABLED_BY_DEFAULT |
| 48 | #else |
| 49 | FEATURE_DISABLED_BY_DEFAULT |
| 50 | #endif |
| 51 | ); |
| 52 | |
Arthur Sonzogni | be6f013 | 2022-07-06 13:54:12 | [diff] [blame] | 53 | constexpr FeatureParam<DanglingPtrMode>::Option kDanglingPtrModeOption[] = { |
| 54 | {DanglingPtrMode::kCrash, "crash"}, |
Pâris | e90af2c | 2023-01-30 14:22:41 | [diff] [blame] | 55 | {DanglingPtrMode::kLogOnly, "log_only"}, |
Arthur Sonzogni | be6f013 | 2022-07-06 13:54:12 | [diff] [blame] | 56 | }; |
| 57 | const base::FeatureParam<DanglingPtrMode> kDanglingPtrModeParam{ |
| 58 | &kPartitionAllocDanglingPtr, |
| 59 | "mode", |
| 60 | DanglingPtrMode::kCrash, |
| 61 | &kDanglingPtrModeOption, |
| 62 | }; |
Pâris | e90af2c | 2023-01-30 14:22:41 | [diff] [blame] | 63 | constexpr FeatureParam<DanglingPtrType>::Option kDanglingPtrTypeOption[] = { |
| 64 | {DanglingPtrType::kAll, "all"}, |
| 65 | {DanglingPtrType::kCrossTask, "cross_task"}, |
| 66 | }; |
| 67 | const base::FeatureParam<DanglingPtrType> kDanglingPtrTypeParam{ |
| 68 | &kPartitionAllocDanglingPtr, |
| 69 | "type", |
| 70 | DanglingPtrType::kAll, |
| 71 | &kDanglingPtrTypeOption, |
| 72 | }; |
Arthur Sonzogni | be6f013 | 2022-07-06 13:54:12 | [diff] [blame] | 73 | |
Bartek Nowierski | bc01b711 | 2023-02-01 14:11:42 | [diff] [blame] | 74 | #if BUILDFLAG(USE_STARSCAN) |
Anton Bikineev | 9d8b21b | 2020-10-09 08:11:58 | [diff] [blame] | 75 | // If enabled, PCScan is turned on by default for all partitions that don't |
| 76 | // disable it explicitly. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 77 | BASE_FEATURE(kPartitionAllocPCScan, |
| 78 | "PartitionAllocPCScan", |
| 79 | FEATURE_DISABLED_BY_DEFAULT); |
Bartek Nowierski | bc01b711 | 2023-02-01 14:11:42 | [diff] [blame] | 80 | #endif // BUILDFLAG(USE_STARSCAN) |
Anton Bikineev | 9d8b21b | 2020-10-09 08:11:58 | [diff] [blame] | 81 | |
Anton Bikineev | db908de | 2020-12-08 14:48:13 | [diff] [blame] | 82 | #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) |
| 83 | // If enabled, PCScan is turned on only for the browser's malloc partition. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 84 | BASE_FEATURE(kPartitionAllocPCScanBrowserOnly, |
| 85 | "PartitionAllocPCScanBrowserOnly", |
| 86 | FEATURE_DISABLED_BY_DEFAULT); |
Benoit Lize | 6ae0027 | 2021-02-25 15:56:53 | [diff] [blame] | 87 | |
Anton Bikineev | d250933 | 2021-09-16 17:14:57 | [diff] [blame] | 88 | // If enabled, PCScan is turned on only for the renderer's malloc partition. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 89 | BASE_FEATURE(kPartitionAllocPCScanRendererOnly, |
| 90 | "PartitionAllocPCScanRendererOnly", |
| 91 | FEATURE_DISABLED_BY_DEFAULT); |
Anton Bikineev | d250933 | 2021-09-16 17:14:57 | [diff] [blame] | 92 | |
Benoit Lize | 006cfcb | 2021-03-29 16:18:52 | [diff] [blame] | 93 | // Use a larger maximum thread cache cacheable bucket size. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 94 | BASE_FEATURE(kPartitionAllocLargeThreadCacheSize, |
| 95 | "PartitionAllocLargeThreadCacheSize", |
Bartek Nowierski | 4152aa6 | 2023-09-11 14:48:40 | [diff] [blame] | 96 | FEATURE_ENABLED_BY_DEFAULT); |
Benoit Lize | 006cfcb | 2021-03-29 16:18:52 | [diff] [blame] | 97 | |
Mingyu Lei | f0cffc9 | 2023-10-18 18:20:07 | [diff] [blame] | 98 | MIRACLE_PARAMETER_FOR_INT( |
| 99 | GetPartitionAllocLargeThreadCacheSizeValue, |
| 100 | kPartitionAllocLargeThreadCacheSize, |
Mingyu Lei | d313bb7 | 2023-09-06 02:23:28 | [diff] [blame] | 101 | "PartitionAllocLargeThreadCacheSizeValue", |
Mingyu Lei | f0cffc9 | 2023-10-18 18:20:07 | [diff] [blame] | 102 | ::partition_alloc::ThreadCacheLimits::kLargeSizeThreshold) |
Mingyu Lei | d313bb7 | 2023-09-06 02:23:28 | [diff] [blame] | 103 | |
Mingyu Lei | f0cffc9 | 2023-10-18 18:20:07 | [diff] [blame] | 104 | MIRACLE_PARAMETER_FOR_INT( |
| 105 | GetPartitionAllocLargeThreadCacheSizeValueForLowRAMAndroid, |
| 106 | kPartitionAllocLargeThreadCacheSize, |
| 107 | "PartitionAllocLargeThreadCacheSizeValueForLowRAMAndroid", |
| 108 | ::partition_alloc::ThreadCacheLimits::kDefaultSizeThreshold) |
Mingyu Lei | d313bb7 | 2023-09-06 02:23:28 | [diff] [blame] | 109 | |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 110 | BASE_FEATURE(kPartitionAllocLargeEmptySlotSpanRing, |
| 111 | "PartitionAllocLargeEmptySlotSpanRing", |
| 112 | FEATURE_DISABLED_BY_DEFAULT); |
mikt | ca35b70b | 2023-11-01 12:55:56 | [diff] [blame^] | 113 | |
| 114 | BASE_FEATURE(kPartitionAllocSchedulerLoopQuarantine, |
| 115 | "PartitionAllocSchedulerLoopQuarantine", |
| 116 | FEATURE_DISABLED_BY_DEFAULT); |
| 117 | // Scheduler Loop Quarantine's capacity in bytes. |
| 118 | const base::FeatureParam<int> kPartitionAllocSchedulerLoopQuarantineCapacity{ |
| 119 | &kPartitionAllocSchedulerLoopQuarantine, |
| 120 | "PartitionAllocSchedulerLoopQuarantineCapacity", 0}; |
Sergei Glazunov | 7afc89b9 | 2022-05-31 19:31:29 | [diff] [blame] | 121 | #endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) |
Benoit Lize | f13d793 | 2022-01-07 10:29:32 | [diff] [blame] | 122 | |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 123 | BASE_FEATURE(kPartitionAllocBackupRefPtr, |
| 124 | "PartitionAllocBackupRefPtr", |
Keishi Hattori | 50365c2 | 2023-04-27 08:09:23 | [diff] [blame] | 125 | #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || \ |
Keishi Hattori | 663c81f | 2023-08-11 06:40:17 | [diff] [blame] | 126 | BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS) || \ |
Keishi Hattori | 50365c2 | 2023-04-27 08:09:23 | [diff] [blame] | 127 | (BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CASTOS)) || \ |
Bartek Nowierski | eed1139 | 2023-08-04 10:32:04 | [diff] [blame] | 128 | BUILDFLAG(ENABLE_BACKUP_REF_PTR_FEATURE_FLAG) |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 129 | FEATURE_ENABLED_BY_DEFAULT |
Keishi Hattori | ebb719d | 2022-05-13 09:40:30 | [diff] [blame] | 130 | #else |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 131 | FEATURE_DISABLED_BY_DEFAULT |
Keishi Hattori | ebb719d | 2022-05-13 09:40:30 | [diff] [blame] | 132 | #endif |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 133 | ); |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 134 | |
Bartek Nowierski | dd71552 | 2023-05-04 11:13:44 | [diff] [blame] | 135 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtrForAsh); |
| 136 | BASE_FEATURE(kPartitionAllocBackupRefPtrForAsh, |
| 137 | "PartitionAllocBackupRefPtrForAsh", |
Bartek Nowierski | 7ccccb5 | 2023-08-30 20:37:57 | [diff] [blame] | 138 | FEATURE_ENABLED_BY_DEFAULT); |
Bartek Nowierski | dd71552 | 2023-05-04 11:13:44 | [diff] [blame] | 139 | |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 140 | constexpr FeatureParam<BackupRefPtrEnabledProcesses>::Option |
| 141 | kBackupRefPtrEnabledProcessesOptions[] = { |
| 142 | {BackupRefPtrEnabledProcesses::kBrowserOnly, "browser-only"}, |
| 143 | {BackupRefPtrEnabledProcesses::kBrowserAndRenderer, |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 144 | "browser-and-renderer"}, |
Bartek Nowierski | 7668047 | 2021-12-09 17:58:25 | [diff] [blame] | 145 | {BackupRefPtrEnabledProcesses::kNonRenderer, "non-renderer"}, |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 146 | {BackupRefPtrEnabledProcesses::kAllProcesses, "all-processes"}}; |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 147 | |
| 148 | const base::FeatureParam<BackupRefPtrEnabledProcesses> |
Bartek Nowierski | 0100c001 | 2023-06-21 06:37:51 | [diff] [blame] | 149 | kBackupRefPtrEnabledProcessesParam{ |
| 150 | &kPartitionAllocBackupRefPtr, "enabled-processes", |
| 151 | BackupRefPtrEnabledProcesses::kNonRenderer, |
| 152 | &kBackupRefPtrEnabledProcessesOptions}; |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 153 | |
Bartek Nowierski | f726420 | 2023-05-17 00:23:52 | [diff] [blame] | 154 | constexpr FeatureParam<BackupRefPtrRefCountSize>::Option |
| 155 | kBackupRefPtrRefCountSizeOptions[] = { |
| 156 | {BackupRefPtrRefCountSize::kNatural, "natural"}, |
| 157 | {BackupRefPtrRefCountSize::k4B, "4B"}, |
| 158 | {BackupRefPtrRefCountSize::k8B, "8B"}, |
| 159 | {BackupRefPtrRefCountSize::k16B, "16B"}}; |
| 160 | |
| 161 | const base::FeatureParam<BackupRefPtrRefCountSize> |
| 162 | kBackupRefPtrRefCountSizeParam{ |
| 163 | &kPartitionAllocBackupRefPtr, "ref-count-size", |
| 164 | BackupRefPtrRefCountSize::kNatural, &kBackupRefPtrRefCountSizeOptions}; |
| 165 | |
Bartek Nowierski | ccb1929b | 2023-07-21 02:35:55 | [diff] [blame] | 166 | // Map -with-memory-reclaimer modes onto their counterpars without the suffix. |
| 167 | // They are the same, as memory reclaimer is now controlled independently. |
| 168 | // However, we need to keep both option strings, as there is a long tail of |
| 169 | // clients that may have an old field trial config, which used these modes. |
| 170 | // |
| 171 | // DO NOT USE -with-memory-reclaimer modes in new configs! |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 172 | constexpr FeatureParam<BackupRefPtrMode>::Option kBackupRefPtrModeOptions[] = { |
Bartek Nowierski | ea35aa52 | 2021-12-10 07:08:20 | [diff] [blame] | 173 | {BackupRefPtrMode::kDisabled, "disabled"}, |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 174 | {BackupRefPtrMode::kEnabled, "enabled"}, |
Bartek Nowierski | ccb1929b | 2023-07-21 02:35:55 | [diff] [blame] | 175 | {BackupRefPtrMode::kEnabled, "enabled-with-memory-reclaimer"}, |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 176 | {BackupRefPtrMode::kDisabledButSplitPartitions2Way, |
| 177 | "disabled-but-2-way-split"}, |
Bartek Nowierski | ccb1929b | 2023-07-21 02:35:55 | [diff] [blame] | 178 | {BackupRefPtrMode::kDisabledButSplitPartitions2Way, |
| 179 | "disabled-but-2-way-split-with-memory-reclaimer"}, |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 180 | {BackupRefPtrMode::kDisabledButSplitPartitions3Way, |
| 181 | "disabled-but-3-way-split"}, |
| 182 | }; |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 183 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 184 | const base::FeatureParam<BackupRefPtrMode> kBackupRefPtrModeParam{ |
Bartek Nowierski | 1992f453 | 2023-07-11 15:06:35 | [diff] [blame] | 185 | &kPartitionAllocBackupRefPtr, "brp-mode", BackupRefPtrMode::kEnabled, |
| 186 | &kBackupRefPtrModeOptions}; |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 187 | |
Keishi Hattori | 5f94b5e0 | 2023-05-23 15:01:57 | [diff] [blame] | 188 | BASE_FEATURE(kPartitionAllocMemoryTagging, |
| 189 | "PartitionAllocMemoryTagging", |
| 190 | FEATURE_DISABLED_BY_DEFAULT); |
| 191 | |
| 192 | constexpr FeatureParam<MemtagMode>::Option kMemtagModeOptions[] = { |
| 193 | {MemtagMode::kSync, "sync"}, |
| 194 | {MemtagMode::kAsync, "async"}}; |
| 195 | |
| 196 | const base::FeatureParam<MemtagMode> kMemtagModeParam{ |
| 197 | &kPartitionAllocMemoryTagging, "memtag-mode", MemtagMode::kAsync, |
| 198 | &kMemtagModeOptions}; |
| 199 | |
| 200 | constexpr FeatureParam<MemoryTaggingEnabledProcesses>::Option |
| 201 | kMemoryTaggingEnabledProcessesOptions[] = { |
| 202 | {MemoryTaggingEnabledProcesses::kBrowserOnly, "browser-only"}, |
| 203 | {MemoryTaggingEnabledProcesses::kNonRenderer, "non-renderer"}, |
| 204 | {MemoryTaggingEnabledProcesses::kAllProcesses, "all-processes"}}; |
| 205 | |
| 206 | const base::FeatureParam<MemoryTaggingEnabledProcesses> |
| 207 | kMemoryTaggingEnabledProcessesParam{ |
| 208 | &kPartitionAllocMemoryTagging, "enabled-processes", |
| 209 | MemoryTaggingEnabledProcesses::kBrowserOnly, |
| 210 | &kMemoryTaggingEnabledProcessesOptions}; |
| 211 | |
Keishi Hattori | 4dddbef2 | 2023-06-01 09:31:56 | [diff] [blame] | 212 | BASE_FEATURE(kKillPartitionAllocMemoryTagging, |
| 213 | "KillPartitionAllocMemoryTagging", |
| 214 | FEATURE_DISABLED_BY_DEFAULT); |
| 215 | |
Keishi Hattori | 806e3d8e | 2023-09-06 05:55:52 | [diff] [blame] | 216 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPermissiveMte); |
| 217 | BASE_FEATURE(kPartitionAllocPermissiveMte, |
| 218 | "PartitionAllocPermissiveMte", |
| 219 | FEATURE_ENABLED_BY_DEFAULT); |
| 220 | |
Sergei Glazunov | 7afc89b9 | 2022-05-31 19:31:29 | [diff] [blame] | 221 | const base::FeatureParam<bool> kBackupRefPtrAsanEnableDereferenceCheckParam{ |
| 222 | &kPartitionAllocBackupRefPtr, "asan-enable-dereference-check", true}; |
| 223 | const base::FeatureParam<bool> kBackupRefPtrAsanEnableExtractionCheckParam{ |
| 224 | &kPartitionAllocBackupRefPtr, "asan-enable-extraction-check", |
| 225 | false}; // Not much noise at the moment to enable by default. |
| 226 | const base::FeatureParam<bool> kBackupRefPtrAsanEnableInstantiationCheckParam{ |
| 227 | &kPartitionAllocBackupRefPtr, "asan-enable-instantiation-check", true}; |
Anton Bikineev | db908de | 2020-12-08 14:48:13 | [diff] [blame] | 228 | |
Thiabaud Engelbrecht | 179001b | 2023-05-30 15:46:42 | [diff] [blame] | 229 | // If enabled, switches the bucket distribution to a denser one. |
Thiabaud Engelbrecht | 7cd1e4a | 2023-04-20 14:39:20 | [diff] [blame] | 230 | // |
| 231 | // We enable this by default everywhere except for 32-bit Android, since we saw |
| 232 | // regressions there. |
Thiabaud Engelbrecht | 179001b | 2023-05-30 15:46:42 | [diff] [blame] | 233 | BASE_FEATURE(kPartitionAllocUseDenserDistribution, |
| 234 | "PartitionAllocUseDenserDistribution", |
Thiabaud Engelbrecht | 7cd1e4a | 2023-04-20 14:39:20 | [diff] [blame] | 235 | #if BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_32_BITS) |
| 236 | FEATURE_DISABLED_BY_DEFAULT |
| 237 | #else |
| 238 | FEATURE_ENABLED_BY_DEFAULT |
| 239 | #endif // BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_32_BITS) |
| 240 | ); |
Thiabaud Engelbrecht | 179001b | 2023-05-30 15:46:42 | [diff] [blame] | 241 | const base::FeatureParam<BucketDistributionMode>::Option |
| 242 | kPartitionAllocBucketDistributionOption[] = { |
| 243 | {BucketDistributionMode::kDefault, "default"}, |
| 244 | {BucketDistributionMode::kDenser, "denser"}, |
Thiabaud Engelbrecht | 05f8b811 | 2022-09-16 02:18:29 | [diff] [blame] | 245 | }; |
Thiabaud Engelbrecht | 179001b | 2023-05-30 15:46:42 | [diff] [blame] | 246 | const base::FeatureParam<BucketDistributionMode> |
| 247 | kPartitionAllocBucketDistributionParam { |
| 248 | &kPartitionAllocUseDenserDistribution, "mode", |
| 249 | #if BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_32_BITS) |
| 250 | BucketDistributionMode::kDefault, |
| 251 | #else |
| 252 | BucketDistributionMode::kDenser, |
| 253 | #endif // BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_32_BITS) |
| 254 | &kPartitionAllocBucketDistributionOption |
| 255 | }; |
Thiabaud Engelbrecht | 1efe437 | 2022-02-16 19:33:09 | [diff] [blame] | 256 | |
Bartek Nowierski | 1992f453 | 2023-07-11 15:06:35 | [diff] [blame] | 257 | BASE_FEATURE(kPartitionAllocMemoryReclaimer, |
| 258 | "PartitionAllocMemoryReclaimer", |
| 259 | FEATURE_ENABLED_BY_DEFAULT); |
Yuki Shiino | b127d75b | 2023-08-08 09:52:16 | [diff] [blame] | 260 | const base::FeatureParam<TimeDelta> kPartitionAllocMemoryReclaimerInterval = { |
| 261 | &kPartitionAllocMemoryReclaimer, "interval", |
| 262 | TimeDelta(), // Defaults to zero. |
| 263 | }; |
Bartek Nowierski | 1992f453 | 2023-07-11 15:06:35 | [diff] [blame] | 264 | |
Arthur Sonzogni | a57023635 | 2022-12-19 13:18:54 | [diff] [blame] | 265 | // Configures whether we set a lower limit for renderers that do not have a main |
| 266 | // frame, similar to the limit that is already done for backgrounded renderers. |
| 267 | BASE_FEATURE(kLowerPAMemoryLimitForNonMainRenderers, |
| 268 | "LowerPAMemoryLimitForNonMainRenderers", |
| 269 | FEATURE_DISABLED_BY_DEFAULT); |
| 270 | |
Michael Lippautz | d34f7b2c | 2021-04-21 08:32:26 | [diff] [blame] | 271 | // If enabled, switches PCScan scheduling to a mutator-aware scheduler. Does not |
| 272 | // affect whether PCScan is enabled itself. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 273 | BASE_FEATURE(kPartitionAllocPCScanMUAwareScheduler, |
| 274 | "PartitionAllocPCScanMUAwareScheduler", |
| 275 | FEATURE_ENABLED_BY_DEFAULT); |
Michael Lippautz | d34f7b2c | 2021-04-21 08:32:26 | [diff] [blame] | 276 | |
Hannes Payer | a33df7f | 2021-06-22 18:44:14 | [diff] [blame] | 277 | // If enabled, PCScan frees unconditionally all quarantined objects. |
| 278 | // This is a performance testing feature. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 279 | BASE_FEATURE(kPartitionAllocPCScanImmediateFreeing, |
| 280 | "PartitionAllocPCScanImmediateFreeing", |
| 281 | FEATURE_DISABLED_BY_DEFAULT); |
Hannes Payer | a33df7f | 2021-06-22 18:44:14 | [diff] [blame] | 282 | |
Anton Bikineev | 7f11c21 | 2021-08-24 12:03:09 | [diff] [blame] | 283 | // If enabled, PCScan clears eagerly (synchronously) on free(). |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 284 | BASE_FEATURE(kPartitionAllocPCScanEagerClearing, |
| 285 | "PartitionAllocPCScanEagerClearing", |
| 286 | FEATURE_DISABLED_BY_DEFAULT); |
Anton Bikineev | 7f11c21 | 2021-08-24 12:03:09 | [diff] [blame] | 287 | |
Anton Bikineev | ea8859b | 2021-04-29 19:17:22 | [diff] [blame] | 288 | // In addition to heap, scan also the stack of the current mutator. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 289 | BASE_FEATURE(kPartitionAllocPCScanStackScanning, |
| 290 | "PartitionAllocPCScanStackScanning", |
Bartek Nowierski | 92974a9 | 2023-02-02 08:12:30 | [diff] [blame] | 291 | #if BUILDFLAG(PCSCAN_STACK_SUPPORTED) |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 292 | FEATURE_ENABLED_BY_DEFAULT |
Anton Bikineev | ea8859b | 2021-04-29 19:17:22 | [diff] [blame] | 293 | #else |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 294 | FEATURE_DISABLED_BY_DEFAULT |
Bartek Nowierski | 92974a9 | 2023-02-02 08:12:30 | [diff] [blame] | 295 | #endif // BUILDFLAG(PCSCAN_STACK_SUPPORTED) |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 296 | ); |
Anton Bikineev | ea8859b | 2021-04-29 19:17:22 | [diff] [blame] | 297 | |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 298 | BASE_FEATURE(kPartitionAllocDCScan, |
| 299 | "PartitionAllocDCScan", |
| 300 | FEATURE_DISABLED_BY_DEFAULT); |
Anton Bikineev | 6b5ab95 | 2021-05-19 23:57:57 | [diff] [blame] | 301 | |
Bartek Nowierski | afd8821 | 2023-08-23 15:25:24 | [diff] [blame] | 302 | // Whether to straighten free lists for larger slot spans in PurgeMemory() -> |
| 303 | // ... -> PartitionPurgeSlotSpan(). |
| 304 | BASE_FEATURE(kPartitionAllocStraightenLargerSlotSpanFreeLists, |
| 305 | "PartitionAllocStraightenLargerSlotSpanFreeLists", |
| 306 | FEATURE_ENABLED_BY_DEFAULT); |
Bartek Nowierski | 5075053 | 2023-08-25 05:26:17 | [diff] [blame] | 307 | const base::FeatureParam< |
| 308 | partition_alloc::StraightenLargerSlotSpanFreeListsMode>::Option |
| 309 | kPartitionAllocStraightenLargerSlotSpanFreeListsModeOption[] = { |
| 310 | {partition_alloc::StraightenLargerSlotSpanFreeListsMode:: |
| 311 | kOnlyWhenUnprovisioning, |
| 312 | "only-when-unprovisioning"}, |
| 313 | {partition_alloc::StraightenLargerSlotSpanFreeListsMode::kAlways, |
| 314 | "always"}, |
| 315 | }; |
| 316 | const base::FeatureParam<partition_alloc::StraightenLargerSlotSpanFreeListsMode> |
| 317 | kPartitionAllocStraightenLargerSlotSpanFreeListsMode = { |
| 318 | &kPartitionAllocStraightenLargerSlotSpanFreeLists, |
| 319 | "mode", |
| 320 | partition_alloc::StraightenLargerSlotSpanFreeListsMode:: |
| 321 | kOnlyWhenUnprovisioning, |
| 322 | &kPartitionAllocStraightenLargerSlotSpanFreeListsModeOption, |
| 323 | }; |
Bartek Nowierski | afd8821 | 2023-08-23 15:25:24 | [diff] [blame] | 324 | |
Bartek Nowierski | 3506afbc | 2023-08-18 03:58:38 | [diff] [blame] | 325 | // Whether to sort free lists for smaller slot spans in PurgeMemory(). |
Bartek Nowierski | 3506afbc | 2023-08-18 03:58:38 | [diff] [blame] | 326 | BASE_FEATURE(kPartitionAllocSortSmallerSlotSpanFreeLists, |
| 327 | "PartitionAllocSortSmallerSlotSpanFreeLists", |
| 328 | FEATURE_ENABLED_BY_DEFAULT); |
| 329 | |
Benoit Lize | c9ec6149 | 2022-05-20 10:51:25 | [diff] [blame] | 330 | // Whether to sort the active slot spans in PurgeMemory(). |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 331 | BASE_FEATURE(kPartitionAllocSortActiveSlotSpans, |
| 332 | "PartitionAllocSortActiveSlotSpans", |
| 333 | FEATURE_DISABLED_BY_DEFAULT); |
Benoit Lize | c9ec6149 | 2022-05-20 10:51:25 | [diff] [blame] | 334 | |
Benoit Lize | 7ebe3d4 | 2022-11-24 21:12:00 | [diff] [blame] | 335 | #if BUILDFLAG(IS_WIN) |
| 336 | // Whether to retry allocations when commit fails. |
| 337 | BASE_FEATURE(kPageAllocatorRetryOnCommitFailure, |
| 338 | "PageAllocatorRetryOnCommitFailure", |
| 339 | FEATURE_DISABLED_BY_DEFAULT); |
| 340 | #endif |
| 341 | |
Erik Chen | 6968d88 | 2023-10-17 23:14:42 | [diff] [blame] | 342 | #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS) |
Takashi Sakamoto | 2e824dc | 2023-07-14 01:52:35 | [diff] [blame] | 343 | // A parameter to exclude or not exclude PartitionAllocSupport from |
| 344 | // PartialLowModeOnMidRangeDevices. This is used to see how it affects |
| 345 | // renderer performances, e.g. blink_perf.parser benchmark. |
| 346 | // The feature: kPartialLowEndModeOnMidRangeDevices is defined in |
| 347 | // //base/features.cc. Since the following feature param is related to |
| 348 | // PartitionAlloc, define the param here. |
| 349 | const FeatureParam<bool> kPartialLowEndModeExcludePartitionAllocSupport{ |
| 350 | &kPartialLowEndModeOnMidRangeDevices, "exclude-partition-alloc-support", |
| 351 | false}; |
| 352 | #endif |
| 353 | |
Mingyu Lei | 24762854 | 2023-09-04 06:40:21 | [diff] [blame] | 354 | BASE_FEATURE(kEnableConfigurableThreadCacheMultiplier, |
| 355 | "EnableConfigurableThreadCacheMultiplier", |
| 356 | base::FEATURE_DISABLED_BY_DEFAULT); |
| 357 | |
Mingyu Lei | 21e0a64 | 2023-10-18 18:29:02 | [diff] [blame] | 358 | MIRACLE_PARAMETER_FOR_DOUBLE(GetThreadCacheMultiplier, |
| 359 | kEnableConfigurableThreadCacheMultiplier, |
| 360 | "ThreadCacheMultiplier", |
| 361 | 2.) |
Mingyu Lei | 24762854 | 2023-09-04 06:40:21 | [diff] [blame] | 362 | |
Mingyu Lei | 21e0a64 | 2023-10-18 18:29:02 | [diff] [blame] | 363 | MIRACLE_PARAMETER_FOR_DOUBLE(GetThreadCacheMultiplierForAndroid, |
| 364 | kEnableConfigurableThreadCacheMultiplier, |
| 365 | "ThreadCacheMultiplierForAndroid", |
| 366 | 1.) |
Mingyu Lei | 24762854 | 2023-09-04 06:40:21 | [diff] [blame] | 367 | |
Mingyu Lei | af2e0d9 | 2023-09-07 06:35:08 | [diff] [blame] | 368 | constexpr partition_alloc::internal::base::TimeDelta ToPartitionAllocTimeDelta( |
| 369 | base::TimeDelta time_delta) { |
| 370 | return partition_alloc::internal::base::Microseconds( |
| 371 | time_delta.InMicroseconds()); |
| 372 | } |
| 373 | |
| 374 | constexpr base::TimeDelta FromPartitionAllocTimeDelta( |
| 375 | partition_alloc::internal::base::TimeDelta time_delta) { |
| 376 | return base::Microseconds(time_delta.InMicroseconds()); |
| 377 | } |
| 378 | |
| 379 | BASE_FEATURE(kEnableConfigurableThreadCachePurgeInterval, |
| 380 | "EnableConfigurableThreadCachePurgeInterval", |
| 381 | base::FEATURE_DISABLED_BY_DEFAULT); |
| 382 | |
Mingyu Lei | dd8c3d5 | 2023-10-19 05:28:41 | [diff] [blame] | 383 | MIRACLE_PARAMETER_FOR_TIME_DELTA( |
| 384 | GetThreadCacheMinPurgeIntervalValue, |
| 385 | kEnableConfigurableThreadCachePurgeInterval, |
| 386 | "ThreadCacheMinPurgeInterval", |
| 387 | FromPartitionAllocTimeDelta(partition_alloc::kMinPurgeInterval)) |
Mingyu Lei | af2e0d9 | 2023-09-07 06:35:08 | [diff] [blame] | 388 | |
Mingyu Lei | dd8c3d5 | 2023-10-19 05:28:41 | [diff] [blame] | 389 | MIRACLE_PARAMETER_FOR_TIME_DELTA( |
| 390 | GetThreadCacheMaxPurgeIntervalValue, |
| 391 | kEnableConfigurableThreadCachePurgeInterval, |
| 392 | "ThreadCacheMaxPurgeInterval", |
| 393 | FromPartitionAllocTimeDelta(partition_alloc::kMaxPurgeInterval)) |
Mingyu Lei | af2e0d9 | 2023-09-07 06:35:08 | [diff] [blame] | 394 | |
Mingyu Lei | dd8c3d5 | 2023-10-19 05:28:41 | [diff] [blame] | 395 | MIRACLE_PARAMETER_FOR_TIME_DELTA( |
| 396 | GetThreadCacheDefaultPurgeIntervalValue, |
| 397 | kEnableConfigurableThreadCachePurgeInterval, |
Mingyu Lei | af2e0d9 | 2023-09-07 06:35:08 | [diff] [blame] | 398 | "ThreadCacheDefaultPurgeInterval", |
Mingyu Lei | dd8c3d5 | 2023-10-19 05:28:41 | [diff] [blame] | 399 | FromPartitionAllocTimeDelta(partition_alloc::kDefaultPurgeInterval)) |
Mingyu Lei | af2e0d9 | 2023-09-07 06:35:08 | [diff] [blame] | 400 | |
| 401 | const partition_alloc::internal::base::TimeDelta |
| 402 | GetThreadCacheMinPurgeInterval() { |
Mingyu Lei | dd8c3d5 | 2023-10-19 05:28:41 | [diff] [blame] | 403 | return ToPartitionAllocTimeDelta(GetThreadCacheMinPurgeIntervalValue()); |
Mingyu Lei | af2e0d9 | 2023-09-07 06:35:08 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | const partition_alloc::internal::base::TimeDelta |
| 407 | GetThreadCacheMaxPurgeInterval() { |
Mingyu Lei | dd8c3d5 | 2023-10-19 05:28:41 | [diff] [blame] | 408 | return ToPartitionAllocTimeDelta(GetThreadCacheMaxPurgeIntervalValue()); |
Mingyu Lei | af2e0d9 | 2023-09-07 06:35:08 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | const partition_alloc::internal::base::TimeDelta |
| 412 | GetThreadCacheDefaultPurgeInterval() { |
Mingyu Lei | dd8c3d5 | 2023-10-19 05:28:41 | [diff] [blame] | 413 | return ToPartitionAllocTimeDelta(GetThreadCacheDefaultPurgeIntervalValue()); |
Mingyu Lei | af2e0d9 | 2023-09-07 06:35:08 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | BASE_FEATURE(kEnableConfigurableThreadCacheMinCachedMemoryForPurging, |
| 417 | "EnableConfigurableThreadCacheMinCachedMemoryForPurging", |
| 418 | base::FEATURE_DISABLED_BY_DEFAULT); |
| 419 | |
Mingyu Lei | 597be2d | 2023-10-19 05:31:04 | [diff] [blame] | 420 | MIRACLE_PARAMETER_FOR_INT( |
| 421 | GetThreadCacheMinCachedMemoryForPurgingBytes, |
| 422 | kEnableConfigurableThreadCacheMinCachedMemoryForPurging, |
Mingyu Lei | af2e0d9 | 2023-09-07 06:35:08 | [diff] [blame] | 423 | "ThreadCacheMinCachedMemoryForPurgingBytes", |
Mingyu Lei | 597be2d | 2023-10-19 05:31:04 | [diff] [blame] | 424 | partition_alloc::kMinCachedMemoryForPurgingBytes) |
Mingyu Lei | af2e0d9 | 2023-09-07 06:35:08 | [diff] [blame] | 425 | |
Kalvin Lee | e933f3a | 2023-10-22 07:34:44 | [diff] [blame] | 426 | // An apparent quarantine leak in the buffer partition unacceptably |
| 427 | // bloats memory when MiraclePtr is enabled in the renderer process. |
| 428 | // We believe we have found and patched the leak, but out of an |
| 429 | // abundance of caution, we provide this toggle that allows us to |
| 430 | // wholly disable MiraclePtr in the buffer partition, if necessary. |
| 431 | // |
| 432 | // TODO(crbug.com/1444624): this is unneeded once |
| 433 | // MiraclePtr-for-Renderer launches. |
| 434 | BASE_FEATURE(kPartitionAllocDisableBRPInBufferPartition, |
| 435 | "PartitionAllocDisableBRPInBufferPartition", |
| 436 | FEATURE_DISABLED_BY_DEFAULT); |
| 437 | |
Takashi Sakamoto | 0c9274d | 2020-10-08 04:17:37 | [diff] [blame] | 438 | } // namespace features |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 439 | } // namespace base |