summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/backend_impl.cc
diff options
context:
space:
mode:
authornsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-06 20:23:05 +0000
committernsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-06 20:23:05 +0000
commit4b738f399ad3cdeee808531e18ccf2b44dea85d3 (patch)
treea0df936b6d3a0ba9d77f1320b81a1a4682d71305 /net/disk_cache/backend_impl.cc
parent4f1696861fc8185064bd81ac31fd1856b56ee57b (diff)
downloadchromium_src-4b738f399ad3cdeee808531e18ccf2b44dea85d3.zip
chromium_src-4b738f399ad3cdeee808531e18ccf2b44dea85d3.tar.gz
chromium_src-4b738f399ad3cdeee808531e18ccf2b44dea85d3.tar.bz2
Make PreferredCacheSize(avail) <= avail*0.8 and f(x) <= f(x+1).
Contributed by slamm@google.com BUG=40079 TEST=DiskCacheTest.AutomaticMaxSize http://codereview.chromium.org/1564007 Review URL: http://codereview.chromium.org/1566021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43749 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/backend_impl.cc')
-rw-r--r--net/disk_cache/backend_impl.cc29
1 files changed, 16 insertions, 13 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 534c33f..98b8804a 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -183,30 +183,33 @@ int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes,
return *backend ? net::OK : net::ERR_FAILED;
}
+// Returns the preferred maximum number of bytes for the cache given the
+// number of available bytes.
int PreferedCacheSize(int64 available) {
- // If there is not enough space to use kDefaultCacheSize, use 80% of the
- // available space.
- if (available < kDefaultCacheSize)
+ // Return 80% of the available space if there is not enough space to use
+ // kDefaultCacheSize.
+ if (available < kDefaultCacheSize * 10 / 8)
return static_cast<int32>(available * 8 / 10);
- // Don't use more than 10% of the available space.
- if (available < 10 * kDefaultCacheSize)
+ // Return kDefaultCacheSize if it uses 80% to 10% of the available space.
+ if (available < kDefaultCacheSize * 10)
return kDefaultCacheSize;
- // Use 10% of the free space until we reach 2.5 * kDefaultCacheSize.
+ // Return 10% of the available space if the target size
+ // (2.5 * kDefaultCacheSize) is more than 10%.
if (available < static_cast<int64>(kDefaultCacheSize) * 25)
return static_cast<int32>(available / 10);
- // After reaching our target size (2.5 * kDefaultCacheSize), attempt to use
- // 1% of the availabe space.
- if (available < static_cast<int64>(kDefaultCacheSize) * 100)
+ // Return the target size (2.5 * kDefaultCacheSize) if it uses 10% to 1%
+ // of the available space.
+ if (available < static_cast<int64>(kDefaultCacheSize) * 250)
return kDefaultCacheSize * 5 / 2;
- int64 one_percent = available / 100;
- if (one_percent > kint32max)
- return kint32max;
+ // Return 1% of the available space if it does not exceed kint32max.
+ if (available < static_cast<int64>(kint32max) * 100)
+ return static_cast<int32>(available / 100);
- return static_cast<int32>(one_percent);
+ return kint32max;
}
// ------------------------------------------------------------------------