• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/allocator/partition_alloc_features.h"
6 
7 #include "base/allocator/partition_allocator/partition_alloc_buildflags.h"
8 #include "base/base_export.h"
9 #include "base/feature_list.h"
10 #include "build/build_config.h"
11 
12 namespace base {
13 namespace features {
14 
15 BASE_FEATURE(kPartitionAllocUnretainedDanglingPtr,
16              "PartitionAllocUnretainedDanglingPtr",
17              FEATURE_DISABLED_BY_DEFAULT);
18 
19 constexpr FeatureParam<UnretainedDanglingPtrMode>::Option
20     kUnretainedDanglingPtrModeOption[] = {
21         {UnretainedDanglingPtrMode::kCrash, "crash"},
22         {UnretainedDanglingPtrMode::kDumpWithoutCrashing,
23          "dump_without_crashing"},
24 };
25 const base::FeatureParam<UnretainedDanglingPtrMode>
26     kUnretainedDanglingPtrModeParam = {
27         &kPartitionAllocUnretainedDanglingPtr,
28         "mode",
29         UnretainedDanglingPtrMode::kDumpWithoutCrashing,
30         &kUnretainedDanglingPtrModeOption,
31 };
32 
33 BASE_FEATURE(kPartitionAllocDanglingPtr,
34              "PartitionAllocDanglingPtr",
35 #if BUILDFLAG(ENABLE_DANGLING_RAW_PTR_FEATURE_FLAG)
36              FEATURE_ENABLED_BY_DEFAULT
37 #else
38              FEATURE_DISABLED_BY_DEFAULT
39 #endif
40 );
41 
42 constexpr FeatureParam<DanglingPtrMode>::Option kDanglingPtrModeOption[] = {
43     {DanglingPtrMode::kCrash, "crash"},
44     {DanglingPtrMode::kLogOnly, "log_only"},
45 };
46 const base::FeatureParam<DanglingPtrMode> kDanglingPtrModeParam{
47     &kPartitionAllocDanglingPtr,
48     "mode",
49     DanglingPtrMode::kCrash,
50     &kDanglingPtrModeOption,
51 };
52 constexpr FeatureParam<DanglingPtrType>::Option kDanglingPtrTypeOption[] = {
53     {DanglingPtrType::kAll, "all"},
54     {DanglingPtrType::kCrossTask, "cross_task"},
55 };
56 const base::FeatureParam<DanglingPtrType> kDanglingPtrTypeParam{
57     &kPartitionAllocDanglingPtr,
58     "type",
59     DanglingPtrType::kAll,
60     &kDanglingPtrTypeOption,
61 };
62 
63 #if BUILDFLAG(USE_STARSCAN)
64 // If enabled, PCScan is turned on by default for all partitions that don't
65 // disable it explicitly.
66 BASE_FEATURE(kPartitionAllocPCScan,
67              "PartitionAllocPCScan",
68              FEATURE_DISABLED_BY_DEFAULT);
69 #endif  // BUILDFLAG(USE_STARSCAN)
70 
71 #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
72 // If enabled, PCScan is turned on only for the browser's malloc partition.
73 BASE_FEATURE(kPartitionAllocPCScanBrowserOnly,
74              "PartitionAllocPCScanBrowserOnly",
75              FEATURE_DISABLED_BY_DEFAULT);
76 
77 // If enabled, PCScan is turned on only for the renderer's malloc partition.
78 BASE_FEATURE(kPartitionAllocPCScanRendererOnly,
79              "PartitionAllocPCScanRendererOnly",
80              FEATURE_DISABLED_BY_DEFAULT);
81 
82 // If enabled, this instance belongs to the Control group of the BackupRefPtr
83 // binary experiment.
84 BASE_FEATURE(kPartitionAllocBackupRefPtrControl,
85              "PartitionAllocBackupRefPtrControl",
86              FEATURE_DISABLED_BY_DEFAULT);
87 
88 // Use a larger maximum thread cache cacheable bucket size.
89 BASE_FEATURE(kPartitionAllocLargeThreadCacheSize,
90              "PartitionAllocLargeThreadCacheSize",
91 #if BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_32_BITS)
92              // Not unconditionally enabled on 32 bit Android, since it is a
93              // more memory-constrained platform.
94              FEATURE_DISABLED_BY_DEFAULT
95 #else
96              FEATURE_ENABLED_BY_DEFAULT
97 #endif
98 );
99 
100 BASE_FEATURE(kPartitionAllocLargeEmptySlotSpanRing,
101              "PartitionAllocLargeEmptySlotSpanRing",
102              FEATURE_DISABLED_BY_DEFAULT);
103 #endif  // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
104 
105 BASE_FEATURE(kPartitionAllocBackupRefPtr,
106              "PartitionAllocBackupRefPtr",
107 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN) ||    \
108     BUILDFLAG(ENABLE_BACKUP_REF_PTR_FEATURE_FLAG) || \
109     (BUILDFLAG(USE_ASAN_BACKUP_REF_PTR) && BUILDFLAG(IS_LINUX))
110              FEATURE_ENABLED_BY_DEFAULT
111 #else
112              FEATURE_DISABLED_BY_DEFAULT
113 #endif
114 );
115 
116 constexpr FeatureParam<BackupRefPtrEnabledProcesses>::Option
117     kBackupRefPtrEnabledProcessesOptions[] = {
118         {BackupRefPtrEnabledProcesses::kBrowserOnly, "browser-only"},
119         {BackupRefPtrEnabledProcesses::kBrowserAndRenderer,
120          "browser-and-renderer"},
121         {BackupRefPtrEnabledProcesses::kNonRenderer, "non-renderer"},
122         {BackupRefPtrEnabledProcesses::kAllProcesses, "all-processes"}};
123 
124 const base::FeatureParam<BackupRefPtrEnabledProcesses>
125     kBackupRefPtrEnabledProcessesParam {
126   &kPartitionAllocBackupRefPtr, "enabled-processes",
127 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN) ||    \
128     BUILDFLAG(ENABLE_BACKUP_REF_PTR_FEATURE_FLAG) || \
129     (BUILDFLAG(USE_ASAN_BACKUP_REF_PTR) && BUILDFLAG(IS_LINUX))
130       BackupRefPtrEnabledProcesses::kNonRenderer,
131 #else
132       BackupRefPtrEnabledProcesses::kBrowserOnly,
133 #endif
134       &kBackupRefPtrEnabledProcessesOptions
135 };
136 
137 constexpr FeatureParam<BackupRefPtrMode>::Option kBackupRefPtrModeOptions[] = {
138     {BackupRefPtrMode::kDisabled, "disabled"},
139     {BackupRefPtrMode::kEnabled, "enabled"},
140     {BackupRefPtrMode::kEnabledWithoutZapping, "enabled-without-zapping"},
141     {BackupRefPtrMode::kEnabledWithMemoryReclaimer,
142      "enabled-with-memory-reclaimer"},
143     {BackupRefPtrMode::kDisabledButSplitPartitions2Way,
144      "disabled-but-2-way-split"},
145     {BackupRefPtrMode::kDisabledButSplitPartitions2WayWithMemoryReclaimer,
146      "disabled-but-2-way-split-with-memory-reclaimer"},
147     {BackupRefPtrMode::kDisabledButSplitPartitions3Way,
148      "disabled-but-3-way-split"},
149     {BackupRefPtrMode::kDisabledButAddDummyRefCount,
150      "disabled-but-add-dummy-ref-count"},
151 };
152 
153 const base::FeatureParam<BackupRefPtrMode> kBackupRefPtrModeParam{
154     &kPartitionAllocBackupRefPtr, "brp-mode", BackupRefPtrMode::kEnabled,
155     &kBackupRefPtrModeOptions};
156 
157 const base::FeatureParam<bool> kBackupRefPtrAsanEnableDereferenceCheckParam{
158     &kPartitionAllocBackupRefPtr, "asan-enable-dereference-check", true};
159 const base::FeatureParam<bool> kBackupRefPtrAsanEnableExtractionCheckParam{
160     &kPartitionAllocBackupRefPtr, "asan-enable-extraction-check",
161     false};  // Not much noise at the moment to enable by default.
162 const base::FeatureParam<bool> kBackupRefPtrAsanEnableInstantiationCheckParam{
163     &kPartitionAllocBackupRefPtr, "asan-enable-instantiation-check", true};
164 
165 // If enabled, switches the bucket distribution to an alternate one.
166 //
167 // We enable this by default everywhere except for 32-bit Android, since we saw
168 // regressions there.
169 BASE_FEATURE(kPartitionAllocUseAlternateDistribution,
170              "PartitionAllocUseAlternateDistribution",
171 #if BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_32_BITS)
172              FEATURE_DISABLED_BY_DEFAULT
173 #else
174              FEATURE_ENABLED_BY_DEFAULT
175 #endif  // BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_32_BITS)
176 );
177 const base::FeatureParam<AlternateBucketDistributionMode>::Option
178     kPartitionAllocAlternateDistributionOption[] = {
179         {AlternateBucketDistributionMode::kDefault, "default"},
180         {AlternateBucketDistributionMode::kDenser, "denser"},
181 };
182 const base::FeatureParam<AlternateBucketDistributionMode>
183     kPartitionAllocAlternateBucketDistributionParam{
184         &kPartitionAllocUseAlternateDistribution, "mode",
185         AlternateBucketDistributionMode::kDefault,
186         &kPartitionAllocAlternateDistributionOption};
187 
188 // Configures whether we set a lower limit for renderers that do not have a main
189 // frame, similar to the limit that is already done for backgrounded renderers.
190 BASE_FEATURE(kLowerPAMemoryLimitForNonMainRenderers,
191              "LowerPAMemoryLimitForNonMainRenderers",
192              FEATURE_DISABLED_BY_DEFAULT);
193 
194 // If enabled, switches PCScan scheduling to a mutator-aware scheduler. Does not
195 // affect whether PCScan is enabled itself.
196 BASE_FEATURE(kPartitionAllocPCScanMUAwareScheduler,
197              "PartitionAllocPCScanMUAwareScheduler",
198              FEATURE_ENABLED_BY_DEFAULT);
199 
200 // If enabled, PCScan frees unconditionally all quarantined objects.
201 // This is a performance testing feature.
202 BASE_FEATURE(kPartitionAllocPCScanImmediateFreeing,
203              "PartitionAllocPCScanImmediateFreeing",
204              FEATURE_DISABLED_BY_DEFAULT);
205 
206 // If enabled, PCScan clears eagerly (synchronously) on free().
207 BASE_FEATURE(kPartitionAllocPCScanEagerClearing,
208              "PartitionAllocPCScanEagerClearing",
209              FEATURE_DISABLED_BY_DEFAULT);
210 
211 // In addition to heap, scan also the stack of the current mutator.
212 BASE_FEATURE(kPartitionAllocPCScanStackScanning,
213              "PartitionAllocPCScanStackScanning",
214 #if BUILDFLAG(PCSCAN_STACK_SUPPORTED)
215              FEATURE_ENABLED_BY_DEFAULT
216 #else
217              FEATURE_DISABLED_BY_DEFAULT
218 #endif  // BUILDFLAG(PCSCAN_STACK_SUPPORTED)
219 );
220 
221 BASE_FEATURE(kPartitionAllocDCScan,
222              "PartitionAllocDCScan",
223              FEATURE_DISABLED_BY_DEFAULT);
224 
225 // Whether to sort the active slot spans in PurgeMemory().
226 BASE_FEATURE(kPartitionAllocSortActiveSlotSpans,
227              "PartitionAllocSortActiveSlotSpans",
228              FEATURE_DISABLED_BY_DEFAULT);
229 
230 #if BUILDFLAG(IS_WIN)
231 // Whether to retry allocations when commit fails.
232 BASE_FEATURE(kPageAllocatorRetryOnCommitFailure,
233              "PageAllocatorRetryOnCommitFailure",
234              FEATURE_DISABLED_BY_DEFAULT);
235 #endif
236 
237 }  // namespace features
238 }  // namespace base
239