I am aware that sync command flushes the dirty cache into disk. I have run free command first, then sync, and then free again. The result of latter free command shows more free memory available than the former one.

Does this mean that the dirty caches are removed from memory when performing sync? Can anybody give me a more solid proof?


3 Answers 3


No, It don't. I checked it myself many times, but don't worry, Linux kernel takes care of your precious memory very smartly. read Content cached in RAM while writing to disk - Linux and http://linuxatemyram.com


They are not :-). Here is solid proof:

$ dd if=/dev/zero of=test bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0.409106 s, 256 MB/s
$ sync
$ time cat test > /dev/null

real    0m0.027s
user    0m0.000s
sys 0m0.026s

The data was still cached after sync. You can tell it was cached by looking at the time to read the file. (I have a spinning hard drive, max read speed is around 100MB/s). Compare this to the combination of sync and drop_caches:

$ sync
$ echo 1 | sudo tee /proc/sys/vm/drop_caches
$ time cat test > /dev/null

real    0m1.030s
user    0m0.001s
sys 0m0.073s

This will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.

To free pagecache:

echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes:

echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:

echo 3 > /proc/sys/vm/drop_caches

As this is a non-destructive operation, and dirty objects are not freeable, the user should run "sync" first in order to make sure all cached objects are freed.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .