Home > Uncategorized > Linux: HOWTO flush filesystem cache

Linux: HOWTO flush filesystem cache

Some time ago, I had to flush all cached filesystem pages in order to diagnose memory usage related problems. On Linux this is quite easy to achieve by writing to the /proc/sys/vm/drop_caches file:

  • To free the 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

This is a non-destructive operation and will not remove any dirty pages. So, if you want to clear the complete cache, you should sync all dirty objects first:

[root@linux01 ~]# free
             total       used       free     shared    buffers     cached
Mem:       1035064     942004      93060          0      21000     808428
-/+ buffers/cache:     112576     922488
Swap:      2097144        116    2097028
[root@linux01 ~]# sync; echo 3 > /proc/sys/vm/drop_caches
[root@linux01 ~]# free
             total       used       free     shared    buffers     cached
Mem:       1035064     102320     932744          0        192      22036
-/+ buffers/cache:      80092     954972
Swap:      2097144        116    2097028
[root@linux01 ~]#
Categories: Uncategorized Tags:
  1. No comments yet.
  1. No trackbacks yet.

Connect with Facebook