2

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?

1

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

0

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.

0

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
1
$ time cat test > /dev/null

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.