Clearing Linux File System cache

Category: linux, year: 2020

The Linux kernel has a file system cache which can significantly speed up repeated file operations made by applications on the same file, both in terms of file / directory stat() calls (for metadata) and reading the contents. This cache makes use of unused system memory (RAM) to store the metadata and contents of previously-accessed files.

However, when testing or benchmarking file I/O performance on Linux, this file system caching system can obfuscate performance of file operations because the first time a stat() or read operation is done on a file can take some time, and then repeated subsequent tries can then be almost instant due to the file system cache.

In this situation, clearing (or ‘dropping’) the file system cache is the solution, whereby this operation is done before every test run.

The command to do this and completely flush / drop the file system cache (using sudo) is:

echo 3 | sudo tee /proc/sys/vm/drop_caches



Archive
Full Index

linux (4)
cpp (3)
rust (2)
macos (1)
matplotlib (1)
unix (1)


Tags List