Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(627)

Side by Side Diff: content/common/host_discardable_shared_memory_manager.cc

Issue 1013533002: content: Use at most 128MB of discardable memory on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include low-end device tuning Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/child/child_discardable_shared_memory_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/common/host_discardable_shared_memory_manager.h" 5 #include "content/common/host_discardable_shared_memory_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/atomic_sequence_num.h" 9 #include "base/atomic_sequence_num.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 scoped_ptr<base::DiscardableSharedMemory> shared_memory_; 61 scoped_ptr<base::DiscardableSharedMemory> shared_memory_;
62 const base::Closure deleted_callback_; 62 const base::Closure deleted_callback_;
63 bool is_locked_; 63 bool is_locked_;
64 64
65 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryImpl); 65 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryImpl);
66 }; 66 };
67 67
68 base::LazyInstance<HostDiscardableSharedMemoryManager> 68 base::LazyInstance<HostDiscardableSharedMemoryManager>
69 g_discardable_shared_memory_manager = LAZY_INSTANCE_INITIALIZER; 69 g_discardable_shared_memory_manager = LAZY_INSTANCE_INITIALIZER;
70 70
71 #if defined(OS_ANDROID)
72 // Limits the number of FDs used to 32, assuming a 4MB allocation size.
73 const int64_t kMaxDefaultMemoryLimit = 128 * 1024 * 1024;
74 #else
71 const int64_t kMaxDefaultMemoryLimit = 512 * 1024 * 1024; 75 const int64_t kMaxDefaultMemoryLimit = 512 * 1024 * 1024;
76 #endif
72 77
73 const int kEnforceMemoryPolicyDelayMs = 1000; 78 const int kEnforceMemoryPolicyDelayMs = 1000;
74 79
75 // Global atomic to generate unique discardable shared memory IDs. 80 // Global atomic to generate unique discardable shared memory IDs.
76 base::StaticAtomicSequenceNumber g_next_discardable_shared_memory_id; 81 base::StaticAtomicSequenceNumber g_next_discardable_shared_memory_id;
77 82
78 } // namespace 83 } // namespace
79 84
80 HostDiscardableSharedMemoryManager::MemorySegment::MemorySegment( 85 HostDiscardableSharedMemoryManager::MemorySegment::MemorySegment(
81 scoped_ptr<base::DiscardableSharedMemory> memory) 86 scoped_ptr<base::DiscardableSharedMemory> memory)
82 : memory_(memory.Pass()) { 87 : memory_(memory.Pass()) {
83 } 88 }
84 89
85 HostDiscardableSharedMemoryManager::MemorySegment::~MemorySegment() { 90 HostDiscardableSharedMemoryManager::MemorySegment::~MemorySegment() {
86 } 91 }
87 92
88 HostDiscardableSharedMemoryManager::HostDiscardableSharedMemoryManager() 93 HostDiscardableSharedMemoryManager::HostDiscardableSharedMemoryManager()
89 : memory_limit_( 94 : memory_limit_(
90 // Allow 25% of physical memory to be used for discardable memory. 95 // Allow 25% of physical memory to be used for discardable memory.
91 std::min(base::SysInfo::AmountOfPhysicalMemory() / 4, 96 std::min(base::SysInfo::AmountOfPhysicalMemory() / 4,
92 kMaxDefaultMemoryLimit)), 97 base::SysInfo::IsLowEndDevice()
98 ?
99 // Use 1/8th of discardable memory on low-end devices.
100 kMaxDefaultMemoryLimit / 8
101 : kMaxDefaultMemoryLimit)),
93 bytes_allocated_(0), 102 bytes_allocated_(0),
94 memory_pressure_listener_(new base::MemoryPressureListener( 103 memory_pressure_listener_(new base::MemoryPressureListener(
95 base::Bind(&HostDiscardableSharedMemoryManager::OnMemoryPressure, 104 base::Bind(&HostDiscardableSharedMemoryManager::OnMemoryPressure,
96 base::Unretained(this)))), 105 base::Unretained(this)))),
97 enforce_memory_policy_pending_(false), 106 enforce_memory_policy_pending_(false),
98 weak_ptr_factory_(this) { 107 weak_ptr_factory_(this) {
99 DCHECK_NE(memory_limit_, 0u); 108 DCHECK_NE(memory_limit_, 0u);
100 } 109 }
101 110
102 HostDiscardableSharedMemoryManager::~HostDiscardableSharedMemoryManager() { 111 HostDiscardableSharedMemoryManager::~HostDiscardableSharedMemoryManager() {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 400
392 enforce_memory_policy_pending_ = true; 401 enforce_memory_policy_pending_ = true;
393 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 402 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
394 FROM_HERE, 403 FROM_HERE,
395 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, 404 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy,
396 weak_ptr_factory_.GetWeakPtr()), 405 weak_ptr_factory_.GetWeakPtr()),
397 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); 406 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs));
398 } 407 }
399 408
400 } // namespace content 409 } // namespace content
OLDNEW
« no previous file with comments | « content/child/child_discardable_shared_memory_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698