Chromium Code Reviews| Index: base/test_file_util_mac.cc |
| =================================================================== |
| --- base/test_file_util_mac.cc (revision 12089) |
| +++ base/test_file_util_mac.cc (working copy) |
| @@ -4,14 +4,36 @@ |
| #include "base/test_file_util.h" |
| +#include <sys/mman.h> |
|
Mark Mentovai
2009/03/19 14:50:07
Come on, what alphabet are we using today?
|
| +#include <errno.h> |
| #include "base/logging.h" |
| +#include "base/file_util.h" |
| namespace file_util { |
| bool EvictFileFromSystemCache(const FilePath& file) { |
| - // There is no way that we can think of to dump something from the UBC. You |
| - // can add something so when you open it, it doesn't go in, but that won't |
| - // work here. |
| + // There aren't any really direct ways to purge a file from the UBC. From |
| + // talking w/ Amit Singh, the safest is to mmap the file, do a msync to |
|
Mark Mentovai
2009/03/19 14:50:07
I would do "an" msync unless you have a novel way
|
| + // invalidate the memory. The next open should then have to load the |
| + // file from disk. |
| + |
| + // We use MemoryMappedFile because it mmaps MAP_FILE | MAP_SHARED (it doesn't |
|
Mark Mentovai
2009/03/19 14:50:07
That's kind of obvious from reading MemoryMappedFi
|
| + // list MAP_FILE, but that's the default and it doesn't use MAP_ANON to avoid |
| + // that default). |
| + |
| + file_util::MemoryMappedFile mmap; |
|
Mark Mentovai
2009/03/19 14:50:07
I would not name a variable mmap, mmap is the name
|
| + if (!mmap.Initialize(file)) { |
| + DLOG(WARNING) << "failed to memory map " << file.value(); |
| + return false; |
| + } |
| + |
| + if (msync(const_cast<uint8*>(mmap.data()), mmap.length(), |
| + MS_INVALIDATE) != 0) { |
| + DLOG(WARNING) << "failed to invalidate memory map of " << file.value() |
| + << ", errno: " << errno; |
| + return false; |
| + } |
| + |
| return true; |
| } |