summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-09 23:43:55 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-09 23:43:55 +0000
commitd58bf7801979f5ff8b9237ac82dd368b4930a7d3 (patch)
tree8fe1814bf142d5b0a63d65aff122ffd10a62375d /net/disk_cache
parent6e8299bdadc7109689ed7095acd6c5a0b6312b9d (diff)
downloadchromium_src-d58bf7801979f5ff8b9237ac82dd368b4930a7d3.zip
chromium_src-d58bf7801979f5ff8b9237ac82dd368b4930a7d3.tar.gz
chromium_src-d58bf7801979f5ff8b9237ac82dd368b4930a7d3.tar.bz2
Disk cache: Avoid using a block file to full capacity if there is
another file already chained to this one. The second timer of DiskCacheTest.BlockFilesPerformance (net_perftests) is reduced by ~60% (YMMV). Review URL: http://codereview.chromium.org/13677 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6660 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/block_files.cc20
1 files changed, 17 insertions, 3 deletions
diff --git a/net/disk_cache/block_files.cc b/net/disk_cache/block_files.cc
index 9389b61..84c03b9 100644
--- a/net/disk_cache/block_files.cc
+++ b/net/disk_cache/block_files.cc
@@ -135,8 +135,21 @@ void FixAllocationCounters(disk_cache::BlockFileHeader* header) {
}
}
+// Returns true if the current block file should not be used as-is to store more
+// records. |block_count| is the number of blocks to allocate, and
+// |use_next_file| is set to true on return if we should use the next file in
+// the chain, even though we could find empty space on the current file.
bool NeedToGrowBlockFile(const disk_cache::BlockFileHeader* header,
- int block_count) {
+ int block_count, bool* use_next_file) {
+ if ((header->max_entries > disk_cache::kMaxBlocks * 9 / 10) &&
+ header->next_file) {
+ // This file is almost full but we already created another one, don't use
+ // this file yet so that it is easier to find empty blocks when we start
+ // using this file again.
+ *use_next_file = true;
+ return true;
+ }
+ *use_next_file = false;
for (int i = block_count; i <= disk_cache::kMaxNumBlocks; i++) {
if (header->empty[i - 1])
return false;
@@ -296,8 +309,9 @@ MappedFile* BlockFiles::FileForNewBlock(FileType block_type, int block_count) {
BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
Time start = Time::Now();
- while (NeedToGrowBlockFile(header, block_count)) {
- if (kMaxBlocks == header->max_entries) {
+ bool use_next_file;
+ while (NeedToGrowBlockFile(header, block_count, &use_next_file)) {
+ if (use_next_file || kMaxBlocks == header->max_entries) {
file = NextFile(file);
if (!file)
return NULL;