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

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

Issue 1060173002: Remove scoped trackers from OnAllocateLockedDiscardableSharedMemory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 | « no previous file | 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"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/debug/crash_logging.h" 12 #include "base/debug/crash_logging.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/memory/discardable_memory.h" 14 #include "base/memory/discardable_memory.h"
15 #include "base/numerics/safe_math.h" 15 #include "base/numerics/safe_math.h"
16 #include "base/profiler/scoped_tracker.h"
17 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
18 #include "base/sys_info.h" 17 #include "base/sys_info.h"
19 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
20 19
21 namespace content { 20 namespace content {
22 namespace { 21 namespace {
23 22
24 class DiscardableMemoryImpl : public base::DiscardableMemory { 23 class DiscardableMemoryImpl : public base::DiscardableMemory {
25 public: 24 public:
26 DiscardableMemoryImpl(scoped_ptr<base::DiscardableSharedMemory> shared_memory, 25 DiscardableMemoryImpl(scoped_ptr<base::DiscardableSharedMemory> shared_memory,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 base::AutoLock lock(lock_); 182 base::AutoLock lock(lock_);
184 183
185 return bytes_allocated_; 184 return bytes_allocated_;
186 } 185 }
187 186
188 void HostDiscardableSharedMemoryManager::AllocateLockedDiscardableSharedMemory( 187 void HostDiscardableSharedMemoryManager::AllocateLockedDiscardableSharedMemory(
189 base::ProcessHandle process_handle, 188 base::ProcessHandle process_handle,
190 size_t size, 189 size_t size,
191 DiscardableSharedMemoryId id, 190 DiscardableSharedMemoryId id,
192 base::SharedMemoryHandle* shared_memory_handle) { 191 base::SharedMemoryHandle* shared_memory_handle) {
193 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466405
194 // is fixed.
195 tracked_objects::ScopedTracker tracking_profile1(
196 FROM_HERE_WITH_EXPLICIT_FUNCTION(
197 "466405 AllocateLockedDiscardableSharedMemory::Start"));
198 base::AutoLock lock(lock_); 192 base::AutoLock lock(lock_);
199 193
200 // Make sure |id| is not already in use. 194 // Make sure |id| is not already in use.
201 MemorySegmentMap& process_segments = processes_[process_handle]; 195 MemorySegmentMap& process_segments = processes_[process_handle];
202 if (process_segments.find(id) != process_segments.end()) { 196 if (process_segments.find(id) != process_segments.end()) {
203 LOG(ERROR) << "Invalid discardable shared memory ID"; 197 LOG(ERROR) << "Invalid discardable shared memory ID";
204 *shared_memory_handle = base::SharedMemory::NULLHandle(); 198 *shared_memory_handle = base::SharedMemory::NULLHandle();
205 return; 199 return;
206 } 200 }
207 201
208 // Memory usage must be reduced to prevent the addition of |size| from 202 // Memory usage must be reduced to prevent the addition of |size| from
209 // taking usage above the limit. Usage should be reduced to 0 in cases 203 // taking usage above the limit. Usage should be reduced to 0 in cases
210 // where |size| is greater than the limit. 204 // where |size| is greater than the limit.
211 size_t limit = 0; 205 size_t limit = 0;
212 // Note: the actual mapped size can be larger than requested and cause 206 // Note: the actual mapped size can be larger than requested and cause
213 // |bytes_allocated_| to temporarily be larger than |memory_limit_|. The 207 // |bytes_allocated_| to temporarily be larger than |memory_limit_|. The
214 // error is minimized by incrementing |bytes_allocated_| with the actual 208 // error is minimized by incrementing |bytes_allocated_| with the actual
215 // mapped size rather than |size| below. 209 // mapped size rather than |size| below.
216 if (size < memory_limit_) 210 if (size < memory_limit_)
217 limit = memory_limit_ - size; 211 limit = memory_limit_ - size;
218 212
219 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466405
220 // is fixed.
221 tracked_objects::ScopedTracker tracking_profile2(
222 FROM_HERE_WITH_EXPLICIT_FUNCTION(
223 "466405 AllocateLockedDiscardableSharedMemory::ReduceMemoryUsage"));
224 if (bytes_allocated_ > limit) 213 if (bytes_allocated_ > limit)
225 ReduceMemoryUsageUntilWithinLimit(limit); 214 ReduceMemoryUsageUntilWithinLimit(limit);
226 215
227 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466405
228 // is fixed.
229 tracked_objects::ScopedTracker tracking_profile3(
230 FROM_HERE_WITH_EXPLICIT_FUNCTION(
231 "466405 AllocateLockedDiscardableSharedMemory::NewMemory"));
232 scoped_ptr<base::DiscardableSharedMemory> memory( 216 scoped_ptr<base::DiscardableSharedMemory> memory(
233 new base::DiscardableSharedMemory); 217 new base::DiscardableSharedMemory);
234 if (!memory->CreateAndMap(size)) { 218 if (!memory->CreateAndMap(size)) {
235 *shared_memory_handle = base::SharedMemory::NULLHandle(); 219 *shared_memory_handle = base::SharedMemory::NULLHandle();
236 return; 220 return;
237 } 221 }
238 222
239 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466405
240 // is fixed.
241 tracked_objects::ScopedTracker tracking_profile4(
242 FROM_HERE_WITH_EXPLICIT_FUNCTION(
243 "466405 AllocateLockedDiscardableSharedMemory::ShareToProcess"));
244 if (!memory->ShareToProcess(process_handle, shared_memory_handle)) { 223 if (!memory->ShareToProcess(process_handle, shared_memory_handle)) {
245 LOG(ERROR) << "Cannot share discardable memory segment"; 224 LOG(ERROR) << "Cannot share discardable memory segment";
246 *shared_memory_handle = base::SharedMemory::NULLHandle(); 225 *shared_memory_handle = base::SharedMemory::NULLHandle();
247 return; 226 return;
248 } 227 }
249 228
250 base::CheckedNumeric<size_t> checked_bytes_allocated = bytes_allocated_; 229 base::CheckedNumeric<size_t> checked_bytes_allocated = bytes_allocated_;
251 checked_bytes_allocated += memory->mapped_size(); 230 checked_bytes_allocated += memory->mapped_size();
252 if (!checked_bytes_allocated.IsValid()) { 231 if (!checked_bytes_allocated.IsValid()) {
253 *shared_memory_handle = base::SharedMemory::NULLHandle(); 232 *shared_memory_handle = base::SharedMemory::NULLHandle();
254 return; 233 return;
255 } 234 }
256 235
257 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466405
258 // is fixed.
259 tracked_objects::ScopedTracker tracking_profile5(
260 FROM_HERE_WITH_EXPLICIT_FUNCTION(
261 "466405 "
262 "AllocateLockedDiscardableSharedMemory::BytesAllocatedChanged"));
263 bytes_allocated_ = checked_bytes_allocated.ValueOrDie(); 236 bytes_allocated_ = checked_bytes_allocated.ValueOrDie();
264 BytesAllocatedChanged(bytes_allocated_); 237 BytesAllocatedChanged(bytes_allocated_);
265 238
266 scoped_refptr<MemorySegment> segment(new MemorySegment(memory.Pass())); 239 scoped_refptr<MemorySegment> segment(new MemorySegment(memory.Pass()));
267 process_segments[id] = segment.get(); 240 process_segments[id] = segment.get();
268 segments_.push_back(segment.get()); 241 segments_.push_back(segment.get());
269 std::push_heap(segments_.begin(), segments_.end(), CompareMemoryUsageTime); 242 std::push_heap(segments_.begin(), segments_.end(), CompareMemoryUsageTime);
270 243
271 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466405
272 // is fixed.
273 tracked_objects::ScopedTracker tracking_profile6(
274 FROM_HERE_WITH_EXPLICIT_FUNCTION(
275 "466405 "
276 "AllocateLockedDiscardableSharedMemory::"
277 "ScheduleEnforceMemoryPolicy"));
278 if (bytes_allocated_ > memory_limit_) 244 if (bytes_allocated_ > memory_limit_)
279 ScheduleEnforceMemoryPolicy(); 245 ScheduleEnforceMemoryPolicy();
280 } 246 }
281 247
282 void HostDiscardableSharedMemoryManager::DeletedDiscardableSharedMemory( 248 void HostDiscardableSharedMemoryManager::DeletedDiscardableSharedMemory(
283 DiscardableSharedMemoryId id, 249 DiscardableSharedMemoryId id,
284 base::ProcessHandle process_handle) { 250 base::ProcessHandle process_handle) {
285 base::AutoLock lock(lock_); 251 base::AutoLock lock(lock_);
286 252
287 MemorySegmentMap& process_segments = processes_[process_handle]; 253 MemorySegmentMap& process_segments = processes_[process_handle];
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 385
420 enforce_memory_policy_pending_ = true; 386 enforce_memory_policy_pending_ = true;
421 base::MessageLoop::current()->PostDelayedTask( 387 base::MessageLoop::current()->PostDelayedTask(
422 FROM_HERE, 388 FROM_HERE,
423 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, 389 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy,
424 weak_ptr_factory_.GetWeakPtr()), 390 weak_ptr_factory_.GetWeakPtr()),
425 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); 391 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs));
426 } 392 }
427 393
428 } // namespace content 394 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698