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

Unified Diff: components/web_cache/browser/web_cache_manager.cc

Issue 2435603002: [WeakMemoryCache] Remove dead/live distinction of Resource outside core/fetch (Closed)
Patch Set: Rebase Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: components/web_cache/browser/web_cache_manager.cc
diff --git a/components/web_cache/browser/web_cache_manager.cc b/components/web_cache/browser/web_cache_manager.cc
index 97d1e196e632100490bb7342c69697b5d444e32e..fe215e6a3c3da7fe78c6e1f13ff121b27c700c23 100644
--- a/components/web_cache/browser/web_cache_manager.cc
+++ b/components/web_cache/browser/web_cache_manager.cc
@@ -135,21 +135,15 @@ void WebCacheManager::ObserveActivity(int renderer_id) {
}
void WebCacheManager::ObserveStats(int renderer_id,
- uint64_t min_dead_capacity,
- uint64_t max_dead_capacity,
uint64_t capacity,
- uint64_t live_size,
- uint64_t dead_size) {
+ uint64_t size) {
StatsMap::iterator entry = stats_.find(renderer_id);
if (entry == stats_.end())
return; // We might see stats for a renderer that has been destroyed.
// Record the updated stats.
entry->second.capacity = capacity;
- entry->second.dead_size = dead_size;
- entry->second.live_size = live_size;
- entry->second.max_dead_capacity = max_dead_capacity;
- entry->second.min_dead_capacity = min_dead_capacity;
+ entry->second.size = size;
}
void WebCacheManager::SetGlobalSizeLimit(uint64_t bytes) {
@@ -199,62 +193,47 @@ uint64_t WebCacheManager::GetDefaultGlobalSizeLimit() {
void WebCacheManager::GatherStats(const std::set<int>& renderers,
uint64_t* capacity,
- uint64_t* live_size,
- uint64_t* dead_size) {
- *capacity = *live_size = *dead_size = 0;
+ uint64_t* size) {
+ *capacity = *size = 0;
std::set<int>::const_iterator iter = renderers.begin();
while (iter != renderers.end()) {
StatsMap::iterator elmt = stats_.find(*iter);
if (elmt != stats_.end()) {
*capacity += elmt->second.capacity;
- *live_size += elmt->second.live_size;
- *dead_size += elmt->second.dead_size;
+ *size += elmt->second.size;
}
++iter;
}
}
// static
-uint64_t WebCacheManager::GetSize(AllocationTactic tactic,
- uint64_t live_size,
- uint64_t dead_size) {
+uint64_t WebCacheManager::GetSize(AllocationTactic tactic, uint64_t size) {
switch (tactic) {
case DIVIDE_EVENLY:
// We aren't going to reserve any space for existing objects.
return 0;
case KEEP_CURRENT_WITH_HEADROOM:
// We need enough space for our current objects, plus some headroom.
- return 3 * GetSize(KEEP_CURRENT, live_size, dead_size) / 2;
+ return 3 * GetSize(KEEP_CURRENT, size) / 2;
case KEEP_CURRENT:
// We need enough space to keep our current objects.
- return live_size + dead_size;
- case KEEP_LIVE_WITH_HEADROOM:
- // We need enough space to keep out live resources, plus some headroom.
- return 3 * GetSize(KEEP_LIVE, live_size, dead_size) / 2;
- case KEEP_LIVE:
- // We need enough space to keep our live resources.
- return live_size;
+ return size;
default:
NOTREACHED() << "Unknown cache allocation tactic";
return 0;
}
}
-bool WebCacheManager::AttemptTactic(
- AllocationTactic active_tactic,
- uint64_t active_live_size,
- uint64_t active_dead_size,
- AllocationTactic inactive_tactic,
- uint64_t inactive_live_size,
- uint64_t inactive_dead_size,
- AllocationStrategy* strategy) {
+bool WebCacheManager::AttemptTactic(AllocationTactic active_tactic,
+ uint64_t active_used_size,
+ AllocationTactic inactive_tactic,
+ uint64_t inactive_used_size,
+ AllocationStrategy* strategy) {
DCHECK(strategy);
- uint64_t active_size = GetSize(active_tactic, active_live_size,
- active_dead_size);
- uint64_t inactive_size = GetSize(inactive_tactic, inactive_live_size,
- inactive_dead_size);
+ uint64_t active_size = GetSize(active_tactic, active_used_size);
+ uint64_t inactive_size = GetSize(inactive_tactic, inactive_used_size);
// Give up if we don't have enough space to use this tactic.
if (global_size_limit_ < active_size + inactive_size)
@@ -307,8 +286,7 @@ void WebCacheManager::AddToStrategy(const std::set<int>& renderers,
// Add in the space required to implement |tactic|.
StatsMap::iterator elmt = stats_.find(*iter);
if (elmt != stats_.end()) {
- cache_size += GetSize(tactic, elmt->second.live_size,
- elmt->second.dead_size);
+ cache_size += GetSize(tactic, elmt->second.size);
}
// Record the allocation in our strategy.
@@ -327,25 +305,12 @@ void WebCacheManager::EnactStrategy(const AllocationStrategy& strategy) {
// This is the capacity this renderer has been allocated.
uint64_t capacity = allocation->second;
- // We don't reserve any space for dead objects in the cache. Instead, we
- // prefer to keep live objects around. There is probably some performance
- // tuning to be done here.
- uint64_t min_dead_capacity = 0;
-
- // We allow the dead objects to consume up to half of the cache capacity.
- uint64_t max_dead_capacity = capacity / 2;
- if (base::SysInfo::IsLowEndDevice()) {
- max_dead_capacity = std::min(static_cast<uint64_t>(512 * 1024u),
- max_dead_capacity);
- }
-
// Find the WebCachePtr by renderer process id.
auto it = web_cache_services_.find(allocation->first);
DCHECK(it != web_cache_services_.end());
const mojom::WebCachePtr& service = it->second;
DCHECK(service);
- service->SetCacheCapacities(min_dead_capacity, max_dead_capacity,
- capacity);
+ service->SetCacheCapacity(capacity);
}
++allocation;
}
@@ -383,27 +348,19 @@ void WebCacheManager::ReviseAllocationStrategy() {
FindInactiveRenderers();
// Gather statistics
- uint64_t active_capacity, active_live_size, active_dead_size,
- inactive_capacity, inactive_live_size, inactive_dead_size;
- GatherStats(active_renderers_, &active_capacity, &active_live_size,
- &active_dead_size);
- GatherStats(inactive_renderers_, &inactive_capacity, &inactive_live_size,
- &inactive_dead_size);
+ uint64_t active_capacity, active_size, inactive_capacity, inactive_size;
+ GatherStats(active_renderers_, &active_capacity, &active_size);
+ GatherStats(inactive_renderers_, &inactive_capacity, &inactive_size);
UMA_HISTOGRAM_COUNTS_100("Cache.ActiveTabs", active_renderers_.size());
UMA_HISTOGRAM_COUNTS_100("Cache.InactiveTabs", inactive_renderers_.size());
UMA_HISTOGRAM_MEMORY_MB("Cache.ActiveCapacityMB",
active_capacity / 1024 / 1024);
- UMA_HISTOGRAM_MEMORY_MB("Cache.ActiveDeadSizeMB",
- active_dead_size / 1024 / 1024);
- UMA_HISTOGRAM_MEMORY_MB("Cache.ActiveLiveSizeMB",
- active_live_size / 1024 / 1024);
+ UMA_HISTOGRAM_MEMORY_MB("Cache.ActiveLiveSizeMB", active_size / 1024 / 1024);
UMA_HISTOGRAM_MEMORY_MB("Cache.InactiveCapacityMB",
inactive_capacity / 1024 / 1024);
- UMA_HISTOGRAM_MEMORY_MB("Cache.InactiveDeadSizeMB",
- inactive_dead_size / 1024 / 1024);
UMA_HISTOGRAM_MEMORY_MB("Cache.InactiveLiveSizeMB",
- inactive_live_size / 1024 / 1024);
+ inactive_size / 1024 / 1024);
// Compute an allocation strategy.
//
@@ -420,30 +377,21 @@ void WebCacheManager::ReviseAllocationStrategy() {
// we've found a workable strategy.
AllocationStrategy strategy;
if ( // Ideally, we'd like to give the active renderers some headroom and
- // keep all our current objects.
- AttemptTactic(KEEP_CURRENT_WITH_HEADROOM, active_live_size,
- active_dead_size, KEEP_CURRENT, inactive_live_size,
- inactive_dead_size, &strategy) ||
- // If we can't have that, then we first try to evict the dead objects in
- // the caches of inactive renderers.
- AttemptTactic(KEEP_CURRENT_WITH_HEADROOM, active_live_size,
- active_dead_size, KEEP_LIVE, inactive_live_size,
- inactive_dead_size, &strategy) ||
- // Next, we try to keep the live objects in the active renders (with some
- // room for new objects) and give whatever is left to the inactive
+ // keep all our current objects.
+ AttemptTactic(KEEP_CURRENT_WITH_HEADROOM, active_size, KEEP_CURRENT,
+ inactive_size, &strategy) ||
+ // Next, we try to keep the current objects in the active renders (with
+ // some room for new objects) and give whatever is left to the inactive
// renderers.
- AttemptTactic(KEEP_LIVE_WITH_HEADROOM, active_live_size,
- active_dead_size, DIVIDE_EVENLY, inactive_live_size,
- inactive_dead_size, &strategy) ||
+ AttemptTactic(KEEP_CURRENT_WITH_HEADROOM, active_size, DIVIDE_EVENLY,
+ inactive_size, &strategy) ||
// If we've gotten this far, then we are very tight on memory. Let's try
// to at least keep around the live objects for the active renderers.
- AttemptTactic(KEEP_LIVE, active_live_size, active_dead_size,
- DIVIDE_EVENLY, inactive_live_size, inactive_dead_size,
+ AttemptTactic(KEEP_CURRENT, active_size, DIVIDE_EVENLY, inactive_size,
&strategy) ||
// We're basically out of memory. The best we can do is just divide up
// what we have and soldier on.
- AttemptTactic(DIVIDE_EVENLY, active_live_size, active_dead_size,
- DIVIDE_EVENLY, inactive_live_size, inactive_dead_size,
+ AttemptTactic(DIVIDE_EVENLY, active_size, DIVIDE_EVENLY, inactive_size,
&strategy)) {
// Having found a workable strategy, we enact it.
EnactStrategy(strategy);
« no previous file with comments | « components/web_cache/browser/web_cache_manager.h ('k') | components/web_cache/browser/web_cache_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698