| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/metrics/field_trial.h" | 5 #include "base/metrics/field_trial.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // Use shared memory to communicate field trial (experiment) state. Set to false | 37 // Use shared memory to communicate field trial (experiment) state. Set to false |
| 38 // for now while the implementation is fleshed out (e.g. data format, single | 38 // for now while the implementation is fleshed out (e.g. data format, single |
| 39 // shared memory segment). See https://codereview.chromium.org/2365273004/ and | 39 // shared memory segment). See https://codereview.chromium.org/2365273004/ and |
| 40 // crbug.com/653874 | 40 // crbug.com/653874 |
| 41 const bool kUseSharedMemoryForFieldTrials = true; | 41 const bool kUseSharedMemoryForFieldTrials = true; |
| 42 | 42 |
| 43 // Constants for the field trial allocator. | 43 // Constants for the field trial allocator. |
| 44 const char kAllocatorName[] = "FieldTrialAllocator"; | 44 const char kAllocatorName[] = "FieldTrialAllocator"; |
| 45 const uint32_t kFieldTrialType = 0xABA17E13 + 2; // SHA1(FieldTrialEntry) v2 | 45 const uint32_t kFieldTrialType = 0xABA17E13 + 2; // SHA1(FieldTrialEntry) v2 |
| 46 | 46 |
| 47 // We allocate 64 KiB to hold all the field trial data. This should be enough, | 47 // We allocate 128 KiB to hold all the field trial data. This should be enough, |
| 48 // as currently we use ~8KiB for the field trials, and ~10KiB for experiment | 48 // as most people use 3 - 25 KiB for field trials (as of 11/25/2016). |
| 49 // parameters (as of 9/11/2016). This also doesn't allocate all 64 KiB at once | 49 // This also doesn't allocate all 128 KiB at once -- the pages only get mapped |
| 50 // -- the pages only get mapped to physical memory when they are touched. If the | 50 // to physical memory when they are touched. If the size of the allocated field |
| 51 // size of the allocated field trials does get larger than 64 KiB, then we will | 51 // trials does get larger than 128 KiB, then we will drop some field trials in |
| 52 // drop some field trials in child processes, leading to an inconsistent view | 52 // child processes, leading to an inconsistent view between browser and child |
| 53 // between browser and child processes and possibly causing crashes (see | 53 // processes and possibly causing crashes (see crbug.com/661617). |
| 54 // crbug.com/661617). | |
| 55 #if !defined(OS_NACL) | 54 #if !defined(OS_NACL) |
| 56 const size_t kFieldTrialAllocationSize = 64 << 10; // 64 KiB | 55 const size_t kFieldTrialAllocationSize = 128 << 10; // 128 KiB |
| 57 #endif | 56 #endif |
| 58 | 57 |
| 59 // We create one FieldTrialEntry per field trial in shared memory, via | 58 // We create one FieldTrialEntry per field trial in shared memory, via |
| 60 // AddToAllocatorWhileLocked. The FieldTrialEntry is followed by a base::Pickle | 59 // AddToAllocatorWhileLocked. The FieldTrialEntry is followed by a base::Pickle |
| 61 // object that we unpickle and read from. Any changes to this structure requires | 60 // object that we unpickle and read from. Any changes to this structure requires |
| 62 // a bump in kFieldTrialType id defined above. | 61 // a bump in kFieldTrialType id defined above. |
| 63 struct FieldTrialEntry { | 62 struct FieldTrialEntry { |
| 64 // Expected size for 32/64-bit check. | 63 // Expected size for 32/64-bit check. |
| 65 static constexpr size_t kExpectedInstanceSize = 8; | 64 static constexpr size_t kExpectedInstanceSize = 8; |
| 66 | 65 |
| (...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 return; | 1107 return; |
| 1109 } | 1108 } |
| 1110 AutoLock auto_lock(global_->lock_); | 1109 AutoLock auto_lock(global_->lock_); |
| 1111 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); | 1110 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); |
| 1112 trial->AddRef(); | 1111 trial->AddRef(); |
| 1113 trial->SetTrialRegistered(); | 1112 trial->SetTrialRegistered(); |
| 1114 global_->registered_[trial->trial_name()] = trial; | 1113 global_->registered_[trial->trial_name()] = trial; |
| 1115 } | 1114 } |
| 1116 | 1115 |
| 1117 } // namespace base | 1116 } // namespace base |
| OLD | NEW |