Is running sync before drop_caches necessary?

caching, linux-kernel, performance

Solution

Writing to `drop_caches` frees only clean caches.

Executing `sync` writes back changed data, i.e., converts dirty caches into clean caches.

Problem

I have read a lot of docs saying, it is good idea to do a "sync" before doing echo [1,2,3] > /proc/sys/vm/drop_caches. I am not able to understand why it is needed, drop_cache is a non-destructive operation, dirty data is not going to be deleted by drop_cache. I have also seen a behavior where echo 1 > /proc/sys/vm/drop_caches first commit dirty data back to disk and then frees the cache. This is seen through /proc/meminfo "Dirty" & "Writeback".

Original source