Commit 4b583d19 authored by Bill Budge's avatar Bill Budge Committed by Commit Bot

[code caching] Allow native code entries to take up to half the cache

- Adds new net::CacheType values so the JS code cache can be distinguished
  from the WASM code cache. GENERATED_BYTE_CODE_CACHE refers to Javascript,
  GENERATED_NATIVE_CODE_CACHE refers to WebAssembly.
- Changes SimpleBackendImpl::MaxFileSize to allow PNACL and WASM cache
  entries to take up to 1/2 of the cache. The previous limit was 1/8 of
  the cache.

This CL makes it possible for apps with large WASM modules (150 MB) to
benefit from code caching on desktop. The limit of 1/2 the cache size is
somewhat conservative. PNACL entries are also native code and can occupy
the entire cache (see BackEndImpl::MaxFileSize).

Bug: chromium:719172
Change-Id: Id177862f00c138034d43a5256d317928a48aa467
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1636648Reviewed-by: default avatarMaks Orlovich <morlovich@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMythri Alle <mythria@chromium.org>
Commit-Queue: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665925}
parent 92ef3061
...@@ -312,9 +312,11 @@ void GeneratedCodeCache::CreateBackend() { ...@@ -312,9 +312,11 @@ void GeneratedCodeCache::CreateBackend() {
// If the initialization of the existing cache fails, this call would delete // If the initialization of the existing cache fails, this call would delete
// all the contents and recreates a new one. // all the contents and recreates a new one.
int rv = disk_cache::CreateCacheBackend( int rv = disk_cache::CreateCacheBackend(
net::GENERATED_CODE_CACHE, net::CACHE_BACKEND_SIMPLE, path_, cache_type_ == GeneratedCodeCache::CodeCacheType::kJavaScript
max_size_bytes_, true, nullptr, &shared_backend_ptr->data, ? net::GENERATED_BYTE_CODE_CACHE
std::move(create_backend_complete)); : net::GENERATED_NATIVE_CODE_CACHE,
net::CACHE_BACKEND_SIMPLE, path_, max_size_bytes_, true, nullptr,
&shared_backend_ptr->data, std::move(create_backend_complete));
if (rv != net::ERR_IO_PENDING) { if (rv != net::ERR_IO_PENDING) {
DidCreateBackend(shared_backend_ptr, rv); DidCreateBackend(shared_backend_ptr, rv);
} }
......
...@@ -9,14 +9,16 @@ namespace net { ...@@ -9,14 +9,16 @@ namespace net {
// The types of caches that can be created. // The types of caches that can be created.
enum CacheType { enum CacheType {
DISK_CACHE, // Disk is used as the backing storage. DISK_CACHE, // Disk is used as the backing storage.
MEMORY_CACHE, // Data is stored only in memory. MEMORY_CACHE, // Data is stored only in memory.
MEDIA_CACHE, // Optimized to handle media files. MEDIA_CACHE, // Optimized to handle media files.
APP_CACHE, // Backing store for an AppCache. APP_CACHE, // Backing store for an AppCache.
SHADER_CACHE, // Backing store for the GL shader cache. SHADER_CACHE, // Backing store for the GL shader cache.
PNACL_CACHE, // Backing store the PNaCl translation cache PNACL_CACHE, // Backing store the PNaCl translation cache
GENERATED_CODE_CACHE, // Backing store for data (like code for JavaScript) GENERATED_BYTE_CODE_CACHE, // Backing store for renderer generated data like
// generated by renderer. // bytecode for JavaScript.
GENERATED_NATIVE_CODE_CACHE, // Backing store for renderer generated data
// like native code for WebAssembly.
}; };
// The types of disk cache backend, only used at backend instantiation. // The types of disk cache backend, only used at backend instantiation.
......
...@@ -102,7 +102,8 @@ ...@@ -102,7 +102,8 @@
case net::PNACL_CACHE: \ case net::PNACL_CACHE: \
CACHE_HISTOGRAM_##type(my_name.data(), sample); \ CACHE_HISTOGRAM_##type(my_name.data(), sample); \
break; \ break; \
case net::GENERATED_CODE_CACHE: \ case net::GENERATED_BYTE_CODE_CACHE: \
case net::GENERATED_NATIVE_CODE_CACHE: \
break; \ break; \
} \ } \
} }
......
...@@ -270,9 +270,13 @@ net::CacheType GetCacheTypeAndPrint( ...@@ -270,9 +270,13 @@ net::CacheType GetCacheTypeAndPrint(
MAYBE_PRINT << "Cache type = PNACL_CACHE." << std::endl; MAYBE_PRINT << "Cache type = PNACL_CACHE." << std::endl;
return net::CacheType::PNACL_CACHE; return net::CacheType::PNACL_CACHE;
break; break;
case disk_cache_fuzzer::FuzzCommands::GENERATED_CODE_CACHE: case disk_cache_fuzzer::FuzzCommands::GENERATED_BYTE_CODE_CACHE:
MAYBE_PRINT << "Cache type = GENERATED_CODE_CACHE." << std::endl; MAYBE_PRINT << "Cache type = GENERATED_BYTE_CODE_CACHE." << std::endl;
return net::CacheType::GENERATED_CODE_CACHE; return net::CacheType::GENERATED_BYTE_CODE_CACHE;
break;
case disk_cache_fuzzer::FuzzCommands::GENERATED_NATIVE_CODE_CACHE:
MAYBE_PRINT << "Cache type = GENERATED_NATIVE_CODE_CACHE." << std::endl;
return net::CacheType::GENERATED_NATIVE_CODE_CACHE;
break; break;
case disk_cache_fuzzer::FuzzCommands::DISK_CACHE: case disk_cache_fuzzer::FuzzCommands::DISK_CACHE:
MAYBE_PRINT << "Cache type = DISK_CACHE." << std::endl; MAYBE_PRINT << "Cache type = DISK_CACHE." << std::endl;
......
...@@ -28,8 +28,9 @@ message FuzzCommands { ...@@ -28,8 +28,9 @@ message FuzzCommands {
MEDIA_CACHE = 2; MEDIA_CACHE = 2;
SHADER_CACHE = 3; SHADER_CACHE = 3;
PNACL_CACHE = 4; PNACL_CACHE = 4;
GENERATED_CODE_CACHE = 5; GENERATED_BYTE_CODE_CACHE = 5;
DISK_CACHE = 6; DISK_CACHE = 6;
GENERATED_NATIVE_CODE_CACHE = 7;
} }
required CacheType cache_type = 4; required CacheType cache_type = 4;
......
...@@ -61,6 +61,10 @@ namespace { ...@@ -61,6 +61,10 @@ namespace {
// Maximum fraction of the cache that one entry can consume. // Maximum fraction of the cache that one entry can consume.
const int kMaxFileRatio = 8; const int kMaxFileRatio = 8;
// Native code entries can be large. Rather than increasing the overall cache
// size, allow an individual entry to occupy up to half of the cache.
const int kMaxNativeCodeFileRatio = 2;
// Overrides the above. // Overrides the above.
const int64_t kMinFileSizeLimit = 5 * 1024 * 1024; const int64_t kMinFileSizeLimit = 5 * 1024 * 1024;
...@@ -247,7 +251,8 @@ SimpleBackendImpl::SimpleBackendImpl( ...@@ -247,7 +251,8 @@ SimpleBackendImpl::SimpleBackendImpl(
base::TaskShutdownBehavior::BLOCK_SHUTDOWN})), base::TaskShutdownBehavior::BLOCK_SHUTDOWN})),
orig_max_size_(max_bytes), orig_max_size_(max_bytes),
entry_operations_mode_((cache_type == net::DISK_CACHE || entry_operations_mode_((cache_type == net::DISK_CACHE ||
cache_type == net::GENERATED_CODE_CACHE) cache_type == net::GENERATED_BYTE_CODE_CACHE ||
cache_type == net::GENERATED_NATIVE_CODE_CACHE)
? SimpleEntryImpl::OPTIMISTIC_OPERATIONS ? SimpleEntryImpl::OPTIMISTIC_OPERATIONS
: SimpleEntryImpl::NON_OPTIMISTIC_OPERATIONS), : SimpleEntryImpl::NON_OPTIMISTIC_OPERATIONS),
net_log_(net_log) { net_log_(net_log) {
...@@ -306,8 +311,11 @@ bool SimpleBackendImpl::SetMaxSize(int64_t max_bytes) { ...@@ -306,8 +311,11 @@ bool SimpleBackendImpl::SetMaxSize(int64_t max_bytes) {
} }
int64_t SimpleBackendImpl::MaxFileSize() const { int64_t SimpleBackendImpl::MaxFileSize() const {
uint64_t file_size_ratio = GetCacheType() == net::GENERATED_NATIVE_CODE_CACHE
? kMaxNativeCodeFileRatio
: kMaxFileRatio;
return std::max( return std::max(
base::saturated_cast<int64_t>(index_->max_size() / kMaxFileRatio), base::saturated_cast<int64_t>(index_->max_size() / file_size_ratio),
kMinFileSizeLimit); kMinFileSizeLimit);
} }
......
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
SIMPLE_CACHE_THUNK(uma_type, \ SIMPLE_CACHE_THUNK(uma_type, \
("SimpleCache.Media." uma_name, ##__VA_ARGS__)); \ ("SimpleCache.Media." uma_name, ##__VA_ARGS__)); \
break; \ break; \
case net::GENERATED_CODE_CACHE: \ case net::GENERATED_BYTE_CODE_CACHE: \
case net::GENERATED_NATIVE_CODE_CACHE: \
case net::SHADER_CACHE: \ case net::SHADER_CACHE: \
break; \ break; \
default: \ default: \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment