~$ free
             total       used       free     shared    buffers     cached
Mem:       3891076    1044972    2846104          0      82744     463876
-/+ buffers/cache:     498352    3392724
Swap:      4035580          0    4035580
  1. How to investigate what kind of data is buffered and cached.(not answered yet)
  2. How to clear buffers and cached? (answered)


This command provided by Chris did the trick:

sudo bash -c 'echo 3 > /proc/sys/vm/drop_caches && sleep 2 && free'
  • possible duplicate of real memory usage – strugee Dec 24 '13 at 9:05
  • 1
    @strugee Not a duplicate imo. The linked question just explains what the terms mean. It does not address any of the two questions. – Bernhard Dec 24 '13 at 10:05

The memory represented by "buffers/cache" in free is your disk and filesystem cache, respectively, which Linux caches to speed up reading data from your disk, as hitting the disk is generally a fairly slow way to access data repeatedly. As such, they are cached in memory, and transparently served from there if available.

You can see which blocks are currently in your cache by using fincore. Here is an example from the project page:

# fincore --pages=false --summarize --only-cached * 
stats for CLUSTER_LOG_2010_05_21.MYI: file size=93840384 , total pages=22910 , cached pages=1 , cached size=4096, cached perc=0.004365 
stats for CLUSTER_LOG_2010_05_22.MYI: file size=417792 , total pages=102 , cached pages=1 , cached size=4096, cached perc=0.980392 
stats for CLUSTER_LOG_2010_05_23.MYI: file size=826368 , total pages=201 , cached pages=1 , cached size=4096, cached perc=0.497512 
stats for CLUSTER_LOG_2010_05_24.MYI: file size=192512 , total pages=47 , cached pages=1 , cached size=4096, cached perc=2.127660 
stats for CLUSTER_LOG_2010_06_03.MYI: file size=345088 , total pages=84 , cached pages=43 , cached size=176128, cached perc=51.190476 

As for how to clear them, from man 5 proc:

/proc/sys/vm/drop_caches (since Linux 2.6.16)

Writing to this file causes the kernel to drop clean caches, dentries, and inodes from memory, causing that memory to become free. This can be useful for memory management testing and performing reproducible filesystem benchmarks. Because writing to this file causes the benefits of caching to be lost, it can degrade overall system performance.

  • To free pagecache, use: echo 1 > /proc/sys/vm/drop_caches
  • To free dentries and inodes, use: echo 2 > /proc/sys/vm/drop_caches
  • To free pagecache, dentries and inodes, use: echo 3 > /proc/sys/vm/drop_caches

Because writing to this file is a nondestructive operation and dirty objects are not freeable, the user should run sync(8) first.

You generally don't want to flush the cache, as its entire purpose is to improve performance, but for debugging purposes you can do so by using drop_caches like so (note: you must be root to use drop_caches, but sync can be done as any user):

# sync && echo 3 > /proc/sys/vm/drop_caches
  • sudo tee /proc/sys/vm/drop_caches >/dev/null <<< 3 no output as well. – user55072 Dec 24 '13 at 10:41
  • let us continue this discussion in chat – user55072 Dec 24 '13 at 10:42

Your Answer

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