Commit 1bb18a94 authored by Bill Budge's avatar Bill Budge Committed by Commit Bot

[net][disk_cache] Make Wasm code cache size limit 50% larger.

- Adds cache type parameter to disk_cache::PreferredSize.
- Changes implementation to make default cap size 50% larger in
  if cache type is net::GENERATED_NATIVE_CODE_CACHE.

Bug: chromium:917510, chromium:1019999
Change-Id: Ieb5dd21aa76e387774659131a3d3aa3e6eed2889
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1937852
Commit-Queue: Bill Budge <bbudge@chromium.org>
Reviewed-by: default avatarMaksim Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720678}
parent a920361b
...@@ -1456,7 +1456,7 @@ void BackendImpl::AdjustMaxCacheSize(int table_len) { ...@@ -1456,7 +1456,7 @@ void BackendImpl::AdjustMaxCacheSize(int table_len) {
if (table_len) if (table_len)
available += data_->header.num_bytes; available += data_->header.num_bytes;
max_size_ = PreferredCacheSize(available); max_size_ = PreferredCacheSize(available, GetCacheType());
if (!table_len) if (!table_len)
return; return;
......
...@@ -153,7 +153,7 @@ bool DelayedCacheCleanup(const base::FilePath& full_path) { ...@@ -153,7 +153,7 @@ bool DelayedCacheCleanup(const base::FilePath& full_path) {
// Returns the preferred maximum number of bytes for the cache given the // Returns the preferred maximum number of bytes for the cache given the
// number of available bytes. // number of available bytes.
int PreferredCacheSize(int64_t available) { int PreferredCacheSize(int64_t available, net::CacheType type) {
// Percent of cache size to use, relative to the default size. "100" means to // Percent of cache size to use, relative to the default size. "100" means to
// use 100% of the default size. // use 100% of the default size.
int percent_relative_size; int percent_relative_size;
...@@ -173,6 +173,7 @@ int PreferredCacheSize(int64_t available) { ...@@ -173,6 +173,7 @@ int PreferredCacheSize(int64_t available) {
int64_t scaled_default_disk_cache_size = int64_t scaled_default_disk_cache_size =
static_cast<int64_t>(disk_cache::kDefaultCacheSize) * static_cast<int64_t>(disk_cache::kDefaultCacheSize) *
percent_relative_size / 100; percent_relative_size / 100;
if (available < 0) if (available < 0)
return static_cast<int32_t>(scaled_default_disk_cache_size); return static_cast<int32_t>(scaled_default_disk_cache_size);
...@@ -186,6 +187,12 @@ int PreferredCacheSize(int64_t available) { ...@@ -186,6 +187,12 @@ int PreferredCacheSize(int64_t available) {
preferred_cache_size = available / 5; preferred_cache_size = available / 5;
} }
// Native code entries can be large, so we would like a larger cache.
// Make the size limit 50% larger in that case.
if (type == net::GENERATED_NATIVE_CODE_CACHE) {
scaled_default_disk_cache_size = (scaled_default_disk_cache_size / 2) * 3;
}
// Limit cache size to somewhat less than kint32max to avoid potential // Limit cache size to somewhat less than kint32max to avoid potential
// integer overflows in cache backend implementations. // integer overflows in cache backend implementations.
DCHECK_LT(scaled_default_disk_cache_size * 4, DCHECK_LT(scaled_default_disk_cache_size * 4,
......
...@@ -40,8 +40,11 @@ NET_EXPORT_PRIVATE bool DeleteCacheFile(const base::FilePath& name); ...@@ -40,8 +40,11 @@ NET_EXPORT_PRIVATE bool DeleteCacheFile(const base::FilePath& name);
// task. Used by cache creator itself or by backends for self-restart on error. // task. Used by cache creator itself or by backends for self-restart on error.
bool DelayedCacheCleanup(const base::FilePath& full_path); bool DelayedCacheCleanup(const base::FilePath& full_path);
// Returns the preferred max cache size given the available disk space. // Returns the preferred max cache size given the available disk space and
NET_EXPORT_PRIVATE int PreferredCacheSize(int64_t available); // cache type.
NET_EXPORT_PRIVATE int PreferredCacheSize(
int64_t available,
net::CacheType type = net::DISK_CACHE);
// The default cache size should not ideally be exposed, but the blockfile // The default cache size should not ideally be exposed, but the blockfile
// backend uses it for reasons that include testing. // backend uses it for reasons that include testing.
......
...@@ -133,6 +133,11 @@ TEST_F(CacheUtilTest, PreferredCacheSize) { ...@@ -133,6 +133,11 @@ TEST_F(CacheUtilTest, PreferredCacheSize) {
PreferredCacheSize(test_case.available)); PreferredCacheSize(test_case.available));
} }
// Check that the cache size cap is 50% higher for native code caches.
EXPECT_EQ(((320 * 1024 * 1024) / 2) * 3,
PreferredCacheSize(50000 * 1024 * 1024LL,
net::GENERATED_NATIVE_CODE_CACHE));
// Check 100 "percent_relative_size" matches default behavior. // Check 100 "percent_relative_size" matches default behavior.
{ {
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
...@@ -144,6 +149,10 @@ TEST_F(CacheUtilTest, PreferredCacheSize) { ...@@ -144,6 +149,10 @@ TEST_F(CacheUtilTest, PreferredCacheSize) {
EXPECT_EQ(test_case.expected_without_trial, EXPECT_EQ(test_case.expected_without_trial,
PreferredCacheSize(test_case.available)); PreferredCacheSize(test_case.available));
} }
// Check that the cache size cap is 50% higher for native code caches.
EXPECT_EQ(((320 * 1024 * 1024) / 2) * 3,
PreferredCacheSize(50000 * 1024 * 1024LL,
net::GENERATED_NATIVE_CODE_CACHE));
} }
// Check 200 "percent_relative_size". // Check 200 "percent_relative_size".
...@@ -157,6 +166,10 @@ TEST_F(CacheUtilTest, PreferredCacheSize) { ...@@ -157,6 +166,10 @@ TEST_F(CacheUtilTest, PreferredCacheSize) {
EXPECT_EQ(test_case.expected_with_200_trial, EXPECT_EQ(test_case.expected_with_200_trial,
PreferredCacheSize(test_case.available)); PreferredCacheSize(test_case.available));
} }
// Check that the cache size cap is 50% higher for native code caches.
EXPECT_EQ(((640 * 1024 * 1024) / 2) * 3,
PreferredCacheSize(50000 * 1024 * 1024LL,
net::GENERATED_NATIVE_CODE_CACHE));
} }
} }
......
...@@ -773,7 +773,7 @@ SimpleBackendImpl::DiskStatResult SimpleBackendImpl::InitCacheStructureOnDisk( ...@@ -773,7 +773,7 @@ SimpleBackendImpl::DiskStatResult SimpleBackendImpl::InitCacheStructureOnDisk(
result.net_error = net::ERR_FAILED; result.net_error = net::ERR_FAILED;
} else if (!result.max_size) { } else if (!result.max_size) {
int64_t available = base::SysInfo::AmountOfFreeDiskSpace(path); int64_t available = base::SysInfo::AmountOfFreeDiskSpace(path);
result.max_size = disk_cache::PreferredCacheSize(available); result.max_size = disk_cache::PreferredCacheSize(available, cache_type);
DCHECK(result.max_size); DCHECK(result.max_size);
} }
} }
......
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