This source file includes following definitions.
- EvictFileFromSystemCache
#include "base/test/test_file_util.h"
#include <sys/mman.h>
#include <errno.h>
#include "base/logging.h"
#include "base/file_util.h"
#include "base/files/memory_mapped_file.h"
namespace base {
bool EvictFileFromSystemCache(const FilePath& file) {
int64 length;
if (!GetFileSize(file, &length)) {
DLOG(ERROR) << "failed to get size of " << file.value();
return false;
}
if (length == 0) {
DLOG(WARNING) << "file size is zero, will not attempt to map to memory";
return true;
}
MemoryMappedFile mapped_file;
if (!mapped_file.Initialize(file)) {
DLOG(WARNING) << "failed to memory map " << file.value();
return false;
}
if (msync(const_cast<uint8*>(mapped_file.data()), mapped_file.length(),
MS_INVALIDATE) != 0) {
DLOG(WARNING) << "failed to invalidate memory map of " << file.value()
<< ", errno: " << errno;
return false;
}
return true;
}
}