src/os.cc
// Flush the page cache to ensure reads come from the disk.
Flush the page cache to ensure reads come from the disk.
Flush the page cache to ensure reads come from the disk .
bool OsLayer::FlushPageCache(void) {
  if (!use_flush_page_cache_)
    return true;
  sync();
  static const char *drop_caches_file = "/proc/sys/vm/drop_caches";
  int dcfile = open(drop_caches_file, O_WRONLY);
  if (dcfile < 0) {
    int err = errno;
    string errtxt = ErrorString(err);
    logprintf(3, "Log: failed to open %s - err %d (%s)\n",
              drop_caches_file, err, errtxt.c_str());
    return false;
  }
  ssize_t bytes_written = write(dcfile, "1", 1);
  close(dcfile);
  if (bytes_written != 1) {
    int err = errno;
    string errtxt = ErrorString(err);
    logprintf(3, "Log: failed to write %s - err %d (%s)\n",
              drop_caches_file, err, errtxt.c_str());
    return false;
  }
  return true;
}
bool OsLayer :: FlushPageCache ( void ) { if ( ! use_flush_page_cache_ ) return true ; sync ( ) ; static const char * drop_caches_file = " " ; int dcfile = open ( drop_caches_file , O_WRONLY ) ; if ( dcfile < 0 ) { int err = errno ; string errtxt = ErrorString ( err ) ; logprintf ( 3 , " \n " , drop_caches_file , err , errtxt . c_str ( ) ) ; return false ; } ssize_t bytes_written = write ( dcfile , " " , 1 ) ; close ( dcfile ) ; if ( bytes_written != 1 ) { int err = errno ; string errtxt = ErrorString ( err ) ; logprintf ( 3 , " \n " , drop_caches_file , err , errtxt . c_str ( ) ) ; return false ; } return true ; }
Flush the page cache to ensure reads come from the disk.
Flush the page cache to ensure reads come from the disk .
// First, ask the kernel to write the cache to the disk. // Second, ask the kernel to empty the cache by writing "1" to // "/proc/sys/vm/drop_caches".