Skip to content
Theresa Hradilak edited this page Nov 4, 2022 · 1 revision

An important factor in file I/O for operating systems and relevant for us in regard to:

  • benchmarking (it's pain)
  • persistence of data (we cannot risk data loss of data that wasn't written from buffer to disk)

This wiki page aims to collect knowledge about different operating system caches and how we can deal with them.

Benchmarking

Disk caches can distort benchmarks and should be flushed between each benchmark run measuring File I/O. As a first approach, we use a system call to drop caches as documented in the Linux Kernel doc of /proc/sys/vm/. Writing 3 to /proc/sys/vm/drop_caches frees slab objects (dentries and inodes) and the pagecache. As a non-destructive operation, it only frees clean cache and doesn't flush dirty objects in the cache. To reduce the amount of dirty objects as much as possible we call sync() which forces the writing of cache elements before attempting to drop it.

void clear_cache() {
    sync();
    std::ofstream ofs("/proc/sys/vm/drop_caches");
    ofs << "3" << std::endl;
}
Clone this wiki locally