This post explains how to clear buff/cache memory in Linux to free up memory in Linux without rebooting.
Before you clear memory in Linux to free resources and free memory without rebooting, you must understand that a buffer is an area of memory used to temporarily store data while being moved from one place to another. Whereas, a cache is a temporary storage area to store frequently accessed data for rapid access.
The cache in Linux is called Page Cache and the Linux cache approach is called a write-back cache.
See Buffer and Cache Memory Details in Linux
To analyze the amount of system memory and the memory allocated to buffer and cache of the said system, use the free command:
free -m
Clear Memory In Linux
To clear pagecache only:
sync; echo 1 > /proc/sys/vm/drop_caches
To clear dentries and inodes:
sync; echo 2 > /proc/sys/vm/drop_caches
To clear pagecache, dentries and inodes:
sync; echo 3 > /proc/sys/vm/drop_caches
You can also use the following chain of commands to empty buffer and cache:
free && sync && echo 3 > /proc/sys/vm/drop_caches && free
NOTE:
- use echo 1 to free page cache:
- use echo 2 to free dentries and inodes:
- use echo 3 to free page cache, dentries, and inodes:
Clear RAM In Linux
sudo sync; echo 3 > /proc/sys/vm/drop_caches
sudo apt-get clean
sudo apt-get autoclean
sudo apt-get autoremove
Clear Swap Memory In Linux
swapoff -a && swapon -a
That’s all for now.