Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Unified Diff: base/test_file_util_mac.cc

Issue 42391: Add some UBC eviction code after talking to Amit (and it doesn't even require... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698