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

Side by Side Diff: gpu/command_buffer/service/memory_program_cache.cc

Issue 2921653005: GLES ProgramCache listens to memory pressure (Closed)
Patch Set: change limits. Created 3 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "gpu/command_buffer/service/memory_program_cache.h" 5 #include "gpu/command_buffer/service/memory_program_cache.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/metrics/histogram_functions.h"
12 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
13 #include "base/sha1.h" 15 #include "base/sha1.h"
14 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
15 #include "gpu/command_buffer/common/activity_flags.h" 17 #include "gpu/command_buffer/common/activity_flags.h"
16 #include "gpu/command_buffer/common/constants.h" 18 #include "gpu/command_buffer/common/constants.h"
17 #include "gpu/command_buffer/service/disk_cache_proto.pb.h" 19 #include "gpu/command_buffer/service/disk_cache_proto.pb.h"
18 #include "gpu/command_buffer/service/gl_utils.h" 20 #include "gpu/command_buffer/service/gl_utils.h"
19 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 21 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
20 #include "gpu/command_buffer/service/gpu_preferences.h" 22 #include "gpu/command_buffer/service/gpu_preferences.h"
21 #include "gpu/command_buffer/service/shader_manager.h" 23 #include "gpu/command_buffer/service/shader_manager.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 size_t max_cache_size_bytes, 215 size_t max_cache_size_bytes,
214 bool disable_gpu_shader_disk_cache, 216 bool disable_gpu_shader_disk_cache,
215 bool disable_program_caching_for_transform_feedback, 217 bool disable_program_caching_for_transform_feedback,
216 GpuProcessActivityFlags* activity_flags) 218 GpuProcessActivityFlags* activity_flags)
217 : max_size_bytes_(max_cache_size_bytes), 219 : max_size_bytes_(max_cache_size_bytes),
218 disable_gpu_shader_disk_cache_(disable_gpu_shader_disk_cache), 220 disable_gpu_shader_disk_cache_(disable_gpu_shader_disk_cache),
219 disable_program_caching_for_transform_feedback_( 221 disable_program_caching_for_transform_feedback_(
220 disable_program_caching_for_transform_feedback), 222 disable_program_caching_for_transform_feedback),
221 curr_size_bytes_(0), 223 curr_size_bytes_(0),
222 store_(ProgramMRUCache::NO_AUTO_EVICT), 224 store_(ProgramMRUCache::NO_AUTO_EVICT),
223 activity_flags_(activity_flags) {} 225 activity_flags_(activity_flags),
226 memory_pressure_listener_(
227 base::Bind(&MemoryProgramCache::HandleMemoryPressure,
228 base::Unretained(this))) {}
224 229
225 MemoryProgramCache::~MemoryProgramCache() {} 230 MemoryProgramCache::~MemoryProgramCache() {}
226 231
227 void MemoryProgramCache::ClearBackend() { 232 void MemoryProgramCache::ClearBackend() {
228 store_.Clear(); 233 store_.Clear();
229 DCHECK_EQ(0U, curr_size_bytes_); 234 DCHECK_EQ(0U, curr_size_bytes_);
230 } 235 }
231 236
232 ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram( 237 ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram(
233 GLuint program, 238 GLuint program,
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 fragment_attribs, fragment_uniforms, fragment_varyings, 469 fragment_attribs, fragment_uniforms, fragment_varyings,
465 fragment_output_variables, fragment_interface_blocks, this)); 470 fragment_output_variables, fragment_interface_blocks, this));
466 471
467 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.MemorySizeAfterKb", 472 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.MemorySizeAfterKb",
468 curr_size_bytes_ / 1024); 473 curr_size_bytes_ / 1024);
469 } else { 474 } else {
470 LOG(ERROR) << "Failed to parse proto file."; 475 LOG(ERROR) << "Failed to parse proto file.";
471 } 476 }
472 } 477 }
473 478
479 void MemoryProgramCache::HandleMemoryPressure(
480 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
481 // Set a low limit on cache size for MEMORY_PRESSURE_LEVEL_MODERATE.
482 size_t limit = max_size_bytes_ / 4;
483 if (memory_pressure_level ==
484 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
485 limit = 0;
486 }
487 if (curr_size_bytes_ <= limit)
488 return;
489 size_t initial_size = curr_size_bytes_;
490 while (curr_size_bytes_ > limit && !store_.empty())
491 store_.Erase(store_.rbegin());
492 base::UmaHistogramCounts100000("GPU.ProgramCache.MemoryReleasedOnPressure",
Ilya Sherman 2017/06/08 01:11:38 Optional nit: It's slightly more efficient to use
ssid 2017/06/08 01:18:44 Ah yes. Thanks! I should remember when to use the
493 (initial_size - curr_size_bytes_) / 1024);
494 }
495
474 MemoryProgramCache::ProgramCacheValue::ProgramCacheValue( 496 MemoryProgramCache::ProgramCacheValue::ProgramCacheValue(
475 GLsizei length, 497 GLsizei length,
476 GLenum format, 498 GLenum format,
477 const char* data, 499 const char* data,
478 const std::string& program_hash, 500 const std::string& program_hash,
479 const char* shader_0_hash, 501 const char* shader_0_hash,
480 const AttributeMap& attrib_map_0, 502 const AttributeMap& attrib_map_0,
481 const UniformMap& uniform_map_0, 503 const UniformMap& uniform_map_0,
482 const VaryingMap& varying_map_0, 504 const VaryingMap& varying_map_0,
483 const OutputVariableList& output_variable_list_0, 505 const OutputVariableList& output_variable_list_0,
(...skipping 26 matching lines...) Expand all
510 program_cache_->LinkedProgramCacheSuccess(program_hash); 532 program_cache_->LinkedProgramCacheSuccess(program_hash);
511 } 533 }
512 534
513 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() { 535 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() {
514 program_cache_->curr_size_bytes_ -= length_; 536 program_cache_->curr_size_bytes_ -= length_;
515 program_cache_->Evict(program_hash_); 537 program_cache_->Evict(program_hash_);
516 } 538 }
517 539
518 } // namespace gles2 540 } // namespace gles2
519 } // namespace gpu 541 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/memory_program_cache.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698