Introduction
Cache memory in Ubuntu Linux is like a quick-access storage area that helps your computer run faster. It stores frequently used information so that the operating system and programs can access it more quickly than retrieving it from the main storage (like your hard drive).
Prerequisites
- Up and running ubuntu 22.04 LTS machine.
- Basic knowledge in linux commands.
In this post, We will show you how to clear the cache, buffer, swap space memory on ubuntu 22.04 LTS.
Step 1: Clearing the PageCache
To clear the PageCache on Ubuntu Linux, you can use the following command. Open a terminal and enter the command with administrative privileges:
sudo sync && echo 1 | sudo tee /proc/sys/vm/drop_caches
Step 2: Clearing the Dentries and Inodes
To clear Dentries and Inodes on Ubuntu Linux, you can use the following command in the terminal with administrative privileges:
sudo sync && echo 2 | sudo tee /proc/sys/vm/drop_caches
Step 3: Clearing the PageCache, Dentries, and Inodes
To clear the PageCache, Dentries, and Inodes on Ubuntu Linux, you can use the following command in the terminal with administrative privileges:
sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
Breaking down the command:
- sudo: This is used to execute the command with administrative (superuser) privileges.
- sync: This command ensures that all disk writes are completed before proceeding.
- echo 1: This sends the value ‘1’ to the /proc/sys/vm/drop_caches file. The value ‘1’ specifically instructs the kernel to drop the PageCache.
- echo 2: Send the value ‘2’ to the /proc/sys/vm/drop_caches file. The value ‘2’ specifically instructs the kernel to drop Dentries and Inodes.
- echo 3: Send the value ‘3’ to the /proc/sys/vm/drop_caches file. The value ‘3’ specifically instructs the kernel to drop PageCache, Dentries, and Inodes.
- tee: Write to files. sudo tee allows writing to a file with superuser privileges.
- /proc/sys/vm/drop_caches: This is the special file that controls the dropping of different types of caches.
Keep in mind that manually clearing caches, including PageCache, Dentries, and Inodes, is generally safe but may not be necessary for routine system maintenance. The Linux kernel is designed to manage these caches effectively. Clearing caches is usually done in specific troubleshooting scenarios
Conclusion
We have successfully clear the memory cache, buffer cache on ubuntu 22.04 LTS Debian machine, If you still have questions, please post them in the comments section below.