Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Learn how to clear cache in Linux, including RAM, buffer, and swap space, to boost system performance and keep your system responsive with simple commands.

Tahneet Kanwal
January 11, 2026
In Linux, cache memory, swap space, and buffers are used to speed up data access and enhance system performance. However, as these areas accumulate outdated or unnecessary data, they can start to slow down the system.
Much like clearing the cache in a browser, knowing how to clear cache in Linux is crucial for maintaining optimal performance. Regularly clearing these caches ensures that your system remains responsive and efficient.
Clearing RAM memory cache on Linux can help improve system performance by freeing up memory used by cached data. Most Linux systems provide three different ways to clear the cache. These methods can be used without affecting running processes or services.
Most Linux systems provide three ways to clear the cache. These methods can be used without affecting running processes or services.
Below are the three different ways:
The PageCache stores recently used data and files. Clearing it doesn’t affect running processes and is the safest method. To clear only the PageCache, use the following command:
Command:
sync; echo 1 > /proc/sys/vm/drop_caches
Steps:
free
This command shows memory usage, including swap and available memory. Run this before and after clearing the cache to see changes.
sync; echo 1 > /proc/sys/vm/drop_cachesThis will clean the PageCache and free up memory used by cached file data.
Dentries and inodes are used by the system to manage files and directories. Clearing these entries can help when the system’s filesystem holds a large number of files in memory. To clear only dentries and inodes, use:
Command:
sync; echo 2 > /proc/sys/vm/drop_caches
Steps:
freeTo clear dentries and inodes, type:
sync; echo 2 > /proc/sys/vm/drop_cachesThis will remove the cached directory and file metadata from memory.
This method clears the PageCache, dentries, and inodes, freeing up the most memory. However, it’s not recommended for production environments or frequent use as it can impact system performance.
Command:
sync; echo 3 > /proc/sys/vm/drop_caches
Steps:
freesync; echo 3 > /proc/sys/vm/drop_cachesThis will clear the PageCache, dentries, and inodes, freeing up memory.
Clearing the swap space in Linux involves turning off the swap, which moves the data from the swap partition back into RAM. This process can help free up memory and potentially improve system performance, especially when your system has been using swap space heavily.
swapoff. This will transfer data from the swap back into RAM.Command:
Steps:
sudo swapoff -a swapon command. This will allow the system to start using swap space again.Command:
sudo swapon -a
Steps:
Swappiness is a kernel parameter that controls how aggressively the system uses swap space. By default, it is set to 60, meaning the system will begin swapping when memory usage exceeds 60%. Adjusting this value can help you optimize memory usage based on your system’s needs.
Here are the steps to adjust swappiness:
1. View Current Swappiness Value: To check the current swappiness value, run the following command:
cat /proc/sys/vm/swappiness
This will display the current swappiness value, which is typically set to 60 by default.
2. Change Swappiness Value: To change the swappiness value, you can use the sysctl command. The swappiness value can be set anywhere between 0 and 100:
sudo sysctl vm.swappiness=x
Replace x with a value between 0 and 100. For example, to set swappiness to 20:
sudo sysctl vm.swappiness=20
This command will change the swappiness value for the current session.
3. Verify the Change: To ensure the swappiness value has been successfully changed, run:
This will display the new swappiness value.
To automate the process of clearing memory, you can set up a cron job to run the commands at regular intervals. This way, the cache and swap space will be cleared automatically without doing it manually.
Follow these steps:
Clearing the buffer cache in Linux can help free up memory resources used by the system for caching files and directory metadata. To clear the buffer cache in Linux, follow these steps:
Clearing cache for RAM, buffer, and swap space in Linux can significantly enhance system performance by freeing up resources. While it’s safe to clear these areas when needed, it may cause a brief slowdown as the system rebuilds the cache.
To streamline the process, automating cache management with cron jobs ensures your system stays efficient without manual intervention. Regularly clearing the cache in Linux helps maintain smooth performance and ensures that your system remains responsive.
sudo swapoff -a
free -m
crontab -e
30 3 * * * sudo sync; echo 3 > /proc/sys/vm/drop_caches
30 3 * * * sudo swapoff -a && sudo swapon -a
crontab -l
sudo sync
sudo sh -c 'echo 1 > /proc/sys/vm/drop_caches'
Did you find this page helpful?
More Related Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance