How do I clean or disable the memory cache?
Note: Linux is NOT "eating" your RAM! Please take a look at Geirha's excellent answer below to understand why...
After the above note, if you still feel "cleaning" the cache could help, you can certainly try: it's a one-liner from the terminal:
sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
There's no easy way to disable the cache, but you can achieve the same effect by cleaning it as often as every minute, if you want to:
Make it a cron-job
Press
Alt-F2
, typegksudo gedit /etc/crontab
, and add this line near the bottom:*/15 * * * * root sync && echo 3 > /proc/sys/vm/drop_caches
This cleans every 15 minutes. You can set to 1 or 5 minutes if you really want to by changing the first parameter to
*
or*/5
instead of*/15
One liner to know REAL free RAM, excepting cache
Geirha's answer explains the details, but in short, you get the number of free megabytes with:
free -m | sed -n -e '3p' | grep -Po "\d+$"
which on my 2GB command-line server returns an extremely health 1835
.
Help! Linux ate my RAM!
www.linuxatemyram.com explains this beautifully in FAQ form, with the essentials being:
What's going on?
Linux is borrowing unused memory for disk caching. This makes it looks like you are low on memory, but you are not! Everything is fine!
Why is it doing this?
Disk caching makes the system much faster! There are no downsides, except for confusing newbies. It does not take memory away from applications in any way, ever!
What if I want to run more applications?
If your applications want more memory, they just take back a chunk that the disk cache borrowed. Disk cache can always be given back to applications immediately! You are not low on ram!
How do I see how much free ram I really have?
To see how much ram your applications could use without swapping, run free -m and look at the "available" column:
$ free -m total used free shared buff/cache available Mem: 1504 1491 13 0 855 792 Swap: 2047 6 2041This is your answer in mebibytes.
Source: as mentioned, the excellent www.linuxatemyram.com -- please visit for more information.
To Check your Current Memory Usage
watch -n 1 free -m
or
watch -n 1 cat /proc/meminfo
To Free Up Space
sudo sysctl -w vm.drop_caches=3
NOTE: this action won't make your system faster nor it will affect its stability and performance, it will just clean up memory used by the Linux Kernel on caches.
or
sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
NOTE: You can use cron jobs to schedule the commands above to run at specific time intervals.