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

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

Issue 1018743003: Re-land: base: Replace PurgeAndTruncate with Shrink function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo 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 | « base/memory/discardable_shared_memory_unittest.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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 break; 352 break;
353 353
354 // Stop eviction attempts when the LRU segment is currently in use. 354 // Stop eviction attempts when the LRU segment is currently in use.
355 if (segments_.front()->memory()->last_known_usage() >= current_time) 355 if (segments_.front()->memory()->last_known_usage() >= current_time)
356 break; 356 break;
357 357
358 std::pop_heap(segments_.begin(), segments_.end(), CompareMemoryUsageTime); 358 std::pop_heap(segments_.begin(), segments_.end(), CompareMemoryUsageTime);
359 scoped_refptr<MemorySegment> segment = segments_.back(); 359 scoped_refptr<MemorySegment> segment = segments_.back();
360 segments_.pop_back(); 360 segments_.pop_back();
361 361
362 // Attempt to purge and truncate LRU segment. When successful, as much 362 // Attempt to purge LRU segment. When successful, released the memory.
363 // memory as possible will be released to the OS. How much memory is 363 if (segment->memory()->Purge(current_time)) {
364 // released depends on the platform. The child process should perform 364 #if defined(DISCARDABLE_SHARED_MEMORY_SHRINKING)
365 // periodic cleanup to ensure that all memory is release within a 365 size_t size = segment->memory()->mapped_size();
366 // reasonable amount of time. 366 DCHECK_GE(bytes_allocated_, size);
367 if (segment->memory()->PurgeAndTruncate(current_time)) { 367 bytes_allocated_ -= size;
368 // Shrink memory segment. This will immediately release the memory to
369 // the OS.
370 segment->memory()->Shrink();
371 DCHECK_EQ(segment->memory()->mapped_size(), 0u);
372 #endif
368 ReleaseMemory(segment->memory()); 373 ReleaseMemory(segment->memory());
369 continue; 374 continue;
370 } 375 }
371 376
372 // Add memory segment (with updated usage timestamp) back on heap after 377 // Add memory segment (with updated usage timestamp) back on heap after
373 // failed attempt to purge it. 378 // failed attempt to purge it.
374 segments_.push_back(segment.get()); 379 segments_.push_back(segment.get());
375 std::push_heap(segments_.begin(), segments_.end(), CompareMemoryUsageTime); 380 std::push_heap(segments_.begin(), segments_.end(), CompareMemoryUsageTime);
376 } 381 }
377 382
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 424
420 enforce_memory_policy_pending_ = true; 425 enforce_memory_policy_pending_ = true;
421 base::MessageLoop::current()->PostDelayedTask( 426 base::MessageLoop::current()->PostDelayedTask(
422 FROM_HERE, 427 FROM_HERE,
423 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, 428 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy,
424 weak_ptr_factory_.GetWeakPtr()), 429 weak_ptr_factory_.GetWeakPtr()),
425 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); 430 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs));
426 } 431 }
427 432
428 } // namespace content 433 } // namespace content
OLDNEW
« no previous file with comments | « base/memory/discardable_shared_memory_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698