| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/memory/discardable_memory_android.h" | 5 #include "base/memory/discardable_memory_android.h" |
| 6 | 6 |
| 7 #include <sys/mman.h> | 7 #include <sys/mman.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| 11 | 11 |
| 12 #include "base/android/sys_utils.h" | |
| 13 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 14 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 15 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 16 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 17 #include "base/logging.h" | 16 #include "base/logging.h" |
| 18 #include "base/memory/discardable_memory_allocator_android.h" | 17 #include "base/memory/discardable_memory_allocator_android.h" |
| 19 #include "base/memory/discardable_memory_emulated.h" | 18 #include "base/memory/discardable_memory_emulated.h" |
| 19 #include "base/sys_utils.h" |
| 20 #include "third_party/ashmem/ashmem.h" | 20 #include "third_party/ashmem/ashmem.h" |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const char kAshmemAllocatorName[] = "DiscardableMemoryAllocator"; | 25 const char kAshmemAllocatorName[] = "DiscardableMemoryAllocator"; |
| 26 | 26 |
| 27 struct DiscardableMemoryAllocatorWrapper { | 27 struct DiscardableMemoryAllocatorWrapper { |
| 28 DiscardableMemoryAllocatorWrapper() | 28 DiscardableMemoryAllocatorWrapper() |
| 29 : allocator(kAshmemAllocatorName, | 29 : allocator(kAshmemAllocatorName, |
| 30 GetOptimalAshmemRegionSizeForAllocator()) { | 30 GetOptimalAshmemRegionSizeForAllocator()) { |
| 31 } | 31 } |
| 32 | 32 |
| 33 internal::DiscardableMemoryAllocator allocator; | 33 internal::DiscardableMemoryAllocator allocator; |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 // Returns 64 MBytes for a 512 MBytes device, 128 MBytes for 1024 MBytes... | 36 // Returns 64 MBytes for a 512 MBytes device, 128 MBytes for 1024 MBytes... |
| 37 static size_t GetOptimalAshmemRegionSizeForAllocator() { | 37 static size_t GetOptimalAshmemRegionSizeForAllocator() { |
| 38 // Note that this may do some I/O (without hitting the disk though) so it | 38 // Note that this may do some I/O (without hitting the disk though) so it |
| 39 // should not be called on the critical path. | 39 // should not be called on the critical path. |
| 40 return base::android::SysUtils::AmountOfPhysicalMemoryKB() * 1024 / 8; | 40 return base::SysUtils::AmountOfPhysicalMemoryKB() * 1024 / 8; |
| 41 } | 41 } |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 LazyInstance<DiscardableMemoryAllocatorWrapper>::Leaky g_context = | 44 LazyInstance<DiscardableMemoryAllocatorWrapper>::Leaky g_context = |
| 45 LAZY_INSTANCE_INITIALIZER; | 45 LAZY_INSTANCE_INITIALIZER; |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 namespace internal { | 49 namespace internal { |
| 50 | 50 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 bool DiscardableMemory::PurgeForTestingSupported() { | 159 bool DiscardableMemory::PurgeForTestingSupported() { |
| 160 return false; | 160 return false; |
| 161 } | 161 } |
| 162 | 162 |
| 163 // static | 163 // static |
| 164 void DiscardableMemory::PurgeForTesting() { | 164 void DiscardableMemory::PurgeForTesting() { |
| 165 NOTIMPLEMENTED(); | 165 NOTIMPLEMENTED(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 } // namespace base | 168 } // namespace base |
| OLD | NEW |