Cleaning cache and Swap space management
Efficiently managing system resources is critical for running a Linux server smoothly and consistently. Clearing the cache and resetting swap space is an excellent approach to ensure optimal memory use. Clean Cache and Swap Space Management
Clean Cache and Swap Space important of clearing the cache and swap
Free up RAM used by cache data
More memory is available for critical applications
Improve the performance of the server.
Prerequisites
Before We begin, make sure we have the prerequisites:
Root Access
Basic Linux Knowledge
Action plan clear the cache and Reset the swap space
Step 1
Check the initial memory used in the server and use the below commands
free -g
OR
free -m
Step 2
in the server
Clean Cache and Swap Space To free up the Memory. use the below commands
sync; echo 1 > /proc/sys/vm/drop_caches sync; echo 2 > /proc/sys/vm/drop_caches sync; echo 3 > /proc/sys/vm/drop_caches
Step 3
Verify the After-cache clearance.
It will increase memory and decrease the buff/cache.
free -g
OR
free -m
Step 4
Reset the swap and clear it.
Disable the swap space
swapoff -a
Enable the swap space
swapon -a
OR
swapoff -a && swapon -a
Step 5
Verify the swap clearance
free -g
OR
free -m
Example output
- Initial Memory and Swap Usage
- After Dropping Caches
- After Resetting Swap
We have successfully cleared the cache and made some space available.
Thank You