How to clear Linux cache

It is quite well known that Linux (and other unices) tends to use as much as memory as possible. Once you read a file or a block on disk, it will be put in cache on memory, just in case...

Then, you may have some issues with free memory. For example, on a machine with 4GB of RAM:

 free -m
             total       used       free     shared    buffers     cached
Mem:          3950       3540        409          0        698       1472
-/+ buffers/cache:       1368       2581
Swap:         4000         15       3984

We see / think that only 400 MB are free, and all is used (but we see that 1472 MB are cached).

In fact, a simple command can clean the memory cache. Run, as root:

sync; echo 3 > /proc/sys/vm/drop_caches

Once this is done, the memory used is much more comfortable:

 free -m
             total       used       free     shared    buffers     cached
Mem:          3950       1407       2542          0          1        101
-/+ buffers/cache:       1304       2645
Swap:         4000         15       3984
Catégorie
Tag