0

When you want to empty disk caches/buffers, you usually issue the following command:

# sync && echo 3 > /proc/sys/vm/drop_caches

But after typing that command, free doesn't really report 0 in the buff/cache column. Here's an example:

# free -m
              total        used        free      shared  buff/cache   available
Mem:          7.6Gi       2.9Gi       3.6Gi       238Mi       1.1Gi       4.1Gi
Swap:         9.8Gi       1.0Mi       9.8Gi
Total:         17Gi       2.9Gi        13Gi
                                                                                                                 
# sync && echo 3 > /proc/sys/vm/drop_caches

# free -m
              total        used        free      shared  buff/cache   available
Mem:          7.6Gi       2.8Gi       4.2Gi       224Mi       588Mi       4.2Gi
Swap:         9.8Gi       1.0Mi       9.8Gi
Total:         17Gi       2.8Gi        13Gi

So, there was 1.1G in cache, and it droped to 588M .

Can this 588M drop to 0? If (probably) not, why? And, Is there a way to find out how much caches/buffers will be left in advance after issuing sync and writing to the /proc/sys/vm/drop_caches file?

1 Answer 1

1

No, it won't drop to zero ever because cache includes not just buffers for (normally open) files but also the disk images of running applications and libraries.

And, Is there a way to find out how much caches/buffers will be left in advance after issuing sync and writing to the /proc/sys/vm/drop_caches file?

This looks like a very non-trivial task to me but probably it has a solution. Counting the sizes of open applications/libraries files may get you in the right direction but not really because e.g. if you're running Google Chrome its binary weighs in at 160MB but it's not entirely cached because you're not running every function at once.

You can probably count memory ranges from /proc/$PID/maps which must get you close to the required answer and will also allow you to see which ranges are shared between running applications.

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.