From 81b43d35c1c51ef59445f217824565b17612395b Mon Sep 17 00:00:00 2001 From: David Reveman Date: Thu, 21 May 2015 18:02:56 -0400 Subject: content: Use at most 128MB of discardable memory on Android. 512MB is needed on desktop to not regress performance on some important benchmarks but this limit is much more than needed on Android. By reducing it to 128MB we can also avoid using a different allocation size on Android. This makes the discardable memory behavior more consistent across platforms and improves the browser's ability to purge memory on Android. This change also reduces the amount of discardable memory used on low end devices to 1/8th of the normal limit. BUG=489174,475226 Review URL: https://codereview.chromium.org/1013533002 Cr-Commit-Position: refs/heads/master@{#330754} (cherry picked from commit df13fe318df46dc9955762da26c473e1d5f0e0ac) Review URL: https://codereview.chromium.org/1150903003 Cr-Commit-Position: refs/branch-heads/2357@{#428} Cr-Branched-From: 59d4494849b405682265ed5d3f5164573b9a939b-refs/heads/master@{#323860} --- content/child/child_discardable_shared_memory_manager.cc | 5 ----- content/common/host_discardable_shared_memory_manager.cc | 11 ++++++++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/content/child/child_discardable_shared_memory_manager.cc b/content/child/child_discardable_shared_memory_manager.cc index 73b4cb1..937f53c 100644 --- a/content/child/child_discardable_shared_memory_manager.cc +++ b/content/child/child_discardable_shared_memory_manager.cc @@ -20,12 +20,7 @@ namespace content { namespace { // Default allocation size. -#if defined(OS_ANDROID) -// Larger allocation size on Android to avoid reaching the FD-limit. -const size_t kAllocationSize = 32 * 1024 * 1024; -#else const size_t kAllocationSize = 4 * 1024 * 1024; -#endif // Global atomic to generate unique discardable shared memory IDs. base::StaticAtomicSequenceNumber g_next_discardable_shared_memory_id; diff --git a/content/common/host_discardable_shared_memory_manager.cc b/content/common/host_discardable_shared_memory_manager.cc index 04c677e..2e7bb2b 100644 --- a/content/common/host_discardable_shared_memory_manager.cc +++ b/content/common/host_discardable_shared_memory_manager.cc @@ -68,7 +68,12 @@ class DiscardableMemoryImpl : public base::DiscardableMemory { base::LazyInstance g_discardable_shared_memory_manager = LAZY_INSTANCE_INITIALIZER; +#if defined(OS_ANDROID) +// Limits the number of FDs used to 32, assuming a 4MB allocation size. +const int64_t kMaxDefaultMemoryLimit = 128 * 1024 * 1024; +#else const int64_t kMaxDefaultMemoryLimit = 512 * 1024 * 1024; +#endif const int kEnforceMemoryPolicyDelayMs = 1000; @@ -89,7 +94,11 @@ HostDiscardableSharedMemoryManager::HostDiscardableSharedMemoryManager() : memory_limit_( // Allow 25% of physical memory to be used for discardable memory. std::min(base::SysInfo::AmountOfPhysicalMemory() / 4, - kMaxDefaultMemoryLimit)), + base::SysInfo::IsLowEndDevice() + ? + // Use 1/8th of discardable memory on low-end devices. + kMaxDefaultMemoryLimit / 8 + : kMaxDefaultMemoryLimit)), bytes_allocated_(0), memory_pressure_listener_(new base::MemoryPressureListener( base::Bind(&HostDiscardableSharedMemoryManager::OnMemoryPressure, -- cgit v1.1