1 // Copyright 2019 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 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_INTERNAL_H_ 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_INTERNAL_H_ 7 8 #include <array> 9 10 #include "base/base_export.h" 11 #include "base/feature_list.h" 12 #include "base/metrics/field_trial_params.h" 13 #include "build/build_config.h" 14 15 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) 16 17 namespace base { 18 19 // Enumeration of the possible experiment groups in the discardable memory 20 // backing trial. Note that |kAshmem| and |kEmulatedSharedMemory| both map to 21 // discardable shared memory, except the former allows for the use of ashmem for 22 // unpinning memory. Ensure that the order of the enum values matches those in 23 // |kDiscardableMemoryBackingParamOptions|. 24 enum DiscardableMemoryTrialGroup : int { 25 kEmulatedSharedMemory = 0, 26 kMadvFree, 27 // Only Android devices will be assigned to the ashmem group. 28 kAshmem, 29 }; 30 31 namespace features { 32 // Feature flag enabling the discardable memory backing trial. 33 BASE_EXPORT BASE_DECLARE_FEATURE(kDiscardableMemoryBackingTrial); 34 35 // Association of trial group names to trial group enum. Array order must match 36 // order of DiscardableMemoryTrialGroup enum. 37 constexpr inline auto kDiscardableMemoryBackingParamOptions = 38 std::to_array<base::FeatureParam<DiscardableMemoryTrialGroup>::Option>({ 39 {DiscardableMemoryTrialGroup::kEmulatedSharedMemory, "shmem"}, 40 {DiscardableMemoryTrialGroup::kMadvFree, "madvfree"}, 41 {DiscardableMemoryTrialGroup::kAshmem, "ashmem"}, 42 }); 43 44 constexpr inline base::FeatureParam<DiscardableMemoryTrialGroup> 45 kDiscardableMemoryBackingParam( 46 &kDiscardableMemoryBackingTrial, 47 "DiscardableMemoryBacking", 48 DiscardableMemoryTrialGroup::kEmulatedSharedMemory, 49 kDiscardableMemoryBackingParamOptions); 50 51 } // namespace features 52 53 // Whether we should do the discardable memory backing trial for this session. 54 BASE_EXPORT bool DiscardableMemoryBackingFieldTrialIsEnabled(); 55 56 // If we should do the discardable memory backing trial, then get the trial 57 // group this session belongs in. 58 BASE_EXPORT DiscardableMemoryTrialGroup 59 GetDiscardableMemoryBackingFieldTrialGroup(); 60 61 } // namespace base 62 63 #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || 64 // BUILDFLAG(IS_ANDROID) 65 66 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_INTERNAL_H_ 67