summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/block_files.cc
diff options
context:
space:
mode:
authorhusky@chromium.org <husky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-26 13:38:02 +0000
committerhusky@chromium.org <husky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-26 13:38:02 +0000
commit9e079cb3fc680c2d6eb45ed2c073cbf9a95ff64e (patch)
tree78ad4516274b6c626fe4c5628b7034b47d11fef2 /net/disk_cache/block_files.cc
parent470cc4c60b55fc95f3638ff7b4c443300c60dfdd (diff)
downloadchromium_src-9e079cb3fc680c2d6eb45ed2c073cbf9a95ff64e.zip
chromium_src-9e079cb3fc680c2d6eb45ed2c073cbf9a95ff64e.tar.gz
chromium_src-9e079cb3fc680c2d6eb45ed2c073cbf9a95ff64e.tar.bz2
Optionally disable mmap() in the disk cache.
The disk cache mmaps the headers of certain important files (the main index file, plus block files). Unfortunately on some Android devices mmap performs badly on flash storage, and it's actually better to write the data manually. This patch adds the macro USE_MMAP_FOR_DISK_CACHE macro and the method disk_cache::MappedFile::FlushHeader(). By default, the macro is defined, the new method is a no-op, and there's no change in behavior. TEST=DiskCacheTest BUG= Review URL: https://chromiumcodereview.appspot.com/10573032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/block_files.cc')
-rw-r--r--net/disk_cache/block_files.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/net/disk_cache/block_files.cc b/net/disk_cache/block_files.cc
index 931599b..0f7b729 100644
--- a/net/disk_cache/block_files.cc
+++ b/net/disk_cache/block_files.cc
@@ -284,6 +284,7 @@ bool BlockFiles::CreateBlock(FileType block_type, int block_count,
if (!file)
return false;
+ ScopedFlush flush(file);
BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
int target_size = 0;
@@ -328,6 +329,7 @@ void BlockFiles::DeleteBlock(Addr address, bool deep) {
BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
DeleteMapBlock(address.start_block(), address.num_blocks(), header);
+ file->Flush();
if (!header->num_entries) {
// This file is now empty. Let's try to delete it.
@@ -467,6 +469,7 @@ bool BlockFiles::OpenBlockFile(int index) {
return false;
}
+ ScopedFlush flush(file);
DCHECK(!block_files_[index]);
file.swap(&block_files_[index]);
return true;
@@ -476,6 +479,7 @@ bool BlockFiles::GrowBlockFile(MappedFile* file, BlockFileHeader* header) {
if (kMaxBlocks == header->max_entries)
return false;
+ ScopedFlush flush(file);
DCHECK(!header->empty[3]);
int new_size = header->max_entries + 1024;
if (new_size > kMaxBlocks)
@@ -524,7 +528,8 @@ MappedFile* BlockFiles::FileForNewBlock(FileType block_type, int block_count) {
return file;
}
-MappedFile* BlockFiles::NextFile(const MappedFile* file) {
+MappedFile* BlockFiles::NextFile(MappedFile* file) {
+ ScopedFlush flush(file);
BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
int new_file = header->next_file;
if (!new_file) {
@@ -576,6 +581,7 @@ bool BlockFiles::RemoveEmptyFile(FileType block_type) {
int file_index = header->next_file;
header->next_file = next_header->next_file;
DCHECK(block_files_.size() >= static_cast<unsigned int>(file_index));
+ file->Flush();
// We get a new handle to the file and release the old one so that the
// file gets unmmaped... so we can delete it.
@@ -601,6 +607,7 @@ bool BlockFiles::RemoveEmptyFile(FileType block_type) {
// Note that we expect to be called outside of a FileLock... however, we cannot
// DCHECK on header->updating because we may be fixing a crash.
bool BlockFiles::FixBlockFileHeader(MappedFile* file) {
+ ScopedFlush flush(file);
BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
int file_size = static_cast<int>(file->GetLength());
if (file_size < static_cast<int>(sizeof(*header)))