From dbfde026d061f4d56cfae5d1a247f0ebd139f211 Mon Sep 17 00:00:00 2001 From: Bo Liu Date: Wed, 20 May 2015 16:45:57 -0700 Subject: [PATCH] branch 2403: 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 Review URL: https://codereview.chromium.org/1013533002 Cr-Commit-Position: refs/heads/master@{#330754} (cherry picked from commit df13fe318df46dc9955762da26c473e1d5f0e0ac) TBR=reveman@chromium.org Review URL: https://codereview.chromium.org/1148303003 Cr-Commit-Position: refs/branch-heads/2403@{#38} Cr-Branched-From: f54b8097a9c45ed4ad308133d49f05325d6c5070-refs/heads/master@{#330231} --- .../child/child_discardable_shared_memory_manager.cc | 5 ----- .../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 6c67be86edb8b..7c0f4d6201dcc 100644 --- a/content/child/child_discardable_shared_memory_manager.cc +++ b/content/child/child_discardable_shared_memory_manager.cc @@ -22,12 +22,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 99db11720c7c9..69f6e18e9d9f7 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,