summaryrefslogtreecommitdiffstats
path: root/base/test
diff options
context:
space:
mode:
authornsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 21:53:46 +0000
committernsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 21:53:46 +0000
commit6edff081685c44d7dc266538640131321977fa39 (patch)
treecb9b7651a2568166779f76c1e874b50b977585cf /base/test
parent8938e4e53180b3892d5e853578d5333070c40cb2 (diff)
downloadchromium_src-6edff081685c44d7dc266538640131321977fa39.zip
chromium_src-6edff081685c44d7dc266538640131321977fa39.tar.gz
chromium_src-6edff081685c44d7dc266538640131321977fa39.tar.bz2
Make the eviction function faster by reading/writing 1MB blocks
instead of 4k. Review URL: http://codereview.chromium.org/442011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33129 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/test')
-rw-r--r--base/test/test_file_util_win.cc51
1 files changed, 25 insertions, 26 deletions
diff --git a/base/test/test_file_util_win.cc b/base/test/test_file_util_win.cc
index e7bfce8..4f561f6 100644
--- a/base/test/test_file_util_win.cc
+++ b/base/test/test_file_util_win.cc
@@ -16,9 +16,7 @@
namespace file_util {
-// We could use GetSystemInfo to get the page size, but this serves
-// our purpose fine since 4K is the page size on x86 as well as x64.
-static const ptrdiff_t kPageSize = 4096;
+static const ptrdiff_t kOneMB = 1024 * 1024;
bool DieFileDie(const FilePath& file, bool recurse) {
// It turns out that to not induce flakiness a long timeout is needed.
@@ -53,56 +51,57 @@ bool EvictFileFromSystemCache(const FilePath& file) {
// Execute in chunks. It could be optimized. We want to do few of these since
// these operations will be slow without the cache.
- // Non-buffered reads and writes need to be sector aligned and since sector
- // sizes typically range from 512-4096 bytes, we just use the page size.
- // The buffer size is twice the size of a page (minus one) since we need to
- // get an aligned pointer into the buffer that we can use.
- char buffer[2 * kPageSize - 1];
- // Get an aligned pointer into buffer.
- char* read_write = reinterpret_cast<char*>(
- reinterpret_cast<ptrdiff_t>(buffer + kPageSize - 1) & ~(kPageSize - 1));
- DCHECK((reinterpret_cast<int>(read_write) % kPageSize) == 0);
-
- // If the file size isn't a multiple of kPageSize, we'll need special
+ // Allocate a buffer for the reads and the writes.
+ char* buffer = reinterpret_cast<char*>(VirtualAlloc(NULL,
+ kOneMB,
+ MEM_COMMIT | MEM_RESERVE,
+ PAGE_READWRITE));
+
+ // If the file size isn't a multiple of kOneMB, we'll need special
// processing.
- bool file_is_page_aligned = true;
+ bool file_is_aligned = true;
int total_bytes = 0;
DWORD bytes_read, bytes_written;
for (;;) {
bytes_read = 0;
- ReadFile(file_handle, read_write, kPageSize, &bytes_read, NULL);
+ ReadFile(file_handle, buffer, kOneMB, &bytes_read, NULL);
if (bytes_read == 0)
break;
- if (bytes_read < kPageSize) {
+ if (bytes_read < kOneMB) {
// Zero out the remaining part of the buffer.
// WriteFile will fail if we provide a buffer size that isn't a
// sector multiple, so we'll have to write the entire buffer with
// padded zeros and then use SetEndOfFile to truncate the file.
- ZeroMemory(read_write + bytes_read, kPageSize - bytes_read);
- file_is_page_aligned = false;
+ ZeroMemory(buffer + bytes_read, kOneMB - bytes_read);
+ file_is_aligned = false;
}
// Move back to the position we just read from.
// Note that SetFilePointer will also fail if total_bytes isn't sector
// aligned, but that shouldn't happen here.
- DCHECK((total_bytes % kPageSize) == 0);
+ DCHECK((total_bytes % kOneMB) == 0);
SetFilePointer(file_handle, total_bytes, NULL, FILE_BEGIN);
- if (!WriteFile(file_handle, read_write, kPageSize, &bytes_written, NULL) ||
- bytes_written != kPageSize) {
- DCHECK(false);
+ if (!WriteFile(file_handle, buffer, kOneMB, &bytes_written, NULL) ||
+ bytes_written != kOneMB) {
+ BOOL freed = VirtualFree(buffer, 0, MEM_RELEASE);
+ DCHECK(freed);
+ NOTREACHED();
return false;
}
total_bytes += bytes_read;
// If this is false, then we just processed the last portion of the file.
- if (!file_is_page_aligned)
+ if (!file_is_aligned)
break;
}
- if (!file_is_page_aligned) {
- // The size of the file isn't a multiple of the page size, so we'll have
+ BOOL freed = VirtualFree(buffer, 0, MEM_RELEASE);
+ DCHECK(freed);
+
+ if (!file_is_aligned) {
+ // The size of the file isn't a multiple of 1 MB, so we'll have
// to open the file again, this time without the FILE_FLAG_NO_BUFFERING
// flag and use SetEndOfFile to mark EOF.
file_handle.Set(NULL);