Purge file system cache in Linux
Purge file system cache in Linux
Introduction
As we use our Linux systems, the file system cache keeps track of frequently accessed files. It stores them in memory to speed up access times. However, over time, the cache can become too large, which can lead to system slowdowns. In this blog post, we will discuss how to purge the file system cache in Linux.
Method 1: Using the sync Command
The sync
command forces all modified data to be written to the disk and then clears the file system cache. To use this command, open the terminal and enter the following command:
sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
## or
sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
This command will write any data that is still in the cache to the disk and then clear the cache. The echo 3
command tells the system to purge all caches. You will need to enter your password when prompted.
Method 2: Using the sysctl Command
The sysctl
command is used to modify kernel parameters at runtime. To use this command to purge the file system cache, open the terminal and enter the following command:
sudo sysctl -w vm.drop_caches=3
This command will clear the file system cache. The value 3
tells the system to purge all caches.
Method 3: Using the Swapoff Command
The swapoff
command disables swapping on the system. When you disable swapping, the file system cache is automatically cleared. To use this command, open the terminal and enter the following command:
sudo swapoff -a && sudo swapon -a
This command will turn off swap and then turn it back on. This will clear the file system cache.
Conclusion
The file system cache is an essential part of the Linux operating system. However, when it becomes too large, it can lead to system slowdowns. In this blog post, we discussed three methods to purge the file system cache in Linux. Using any of these methods will help keep your system running smoothly.
Small world. Big idea!
- Welcome to visit the knowledge base of SRE and DevOps!
- License under CC BY-NC 4.0
- No personal information is collected
- Made with Material for MkDocs and generative AI tools
- Copyright issue feedback me#imzye.com, replace # with @
- Get latest SRE news and discuss on Discord Channel