As you know any operating system performs its processes and also increases the operating speed of system use from cache, buffer &, etc. Linux is no exception and maybe it can be said that it uses this subject much better than other operating systems. Accordingly to manage and clear the cache, buffer, and swap in Linux, provide a solution for your users to delete if needed. Now In this article, we are going to teach commands and solutions for Clear cache, buffer, and swap in Linux. Use them if you need or fill the RAM and slow down the system to empty more space in the RAM. It should note that you can visit the packages available in Eldernode to purchase a Linux VPS server.
Table of Contents
Tutorial Clear cache, Buffer, and Swap in Linux
Follow us on how to clear memory cache, buffer, and swap in Linux.
What is Clear cache, Buffer, and Swap?
The cache is a type of SRAM or DRAM memory. This memory is using to prevent processing time delays between the processor and the computer’s RAM. Memory cache usually has less capacity and faster speed than other memory used in computers.
A Buffer is a temporary location for storing data from a specific application that is not using by other applications. Buffer is like the concept of bandwidth. When you try to pass a large amount of data through a network that the network card is unable to pass (ie does not have the required speed), the network card holds that data as a buffer. By doing this, the data transfer will be done continuously and continuously at a lower speed.
Swap space is a part of the system hard drive that can introduce as a partition or file to the Linux kernel. When the Linux kernel needs more RAM, it uses the Swapping feature to copy the less-used parts of the RAM into the swap space and create free space for itself in the RAM. If the part of the RAM copied into the swap space is required, the reverse of the previous operation occurs, in other words, the Linux kernel uses the swap space as a complement to the RAM. Using Swap space in Linux allows systems with low RAM to run heavier programs. It should also note that copying from RAM to swap space and vice versa may slow down the system.
In the next section, join us to teach you how to clear memory cache, buffer, and swap in Linux.
How to Clear memory cache, buffer, and swap in Linux Server
There are three ways to remove cache, buffer, etc., which are:
1) To delete only PageCache, you can enter the following command :
sync; echo 1 > /proc/sys/vm/drop_caches
2) Now if you need to delete Dentries and Inodes created, you must enter the command:
sync; echo 2 > /proc/sys/vm/drop_caches
3) Finally, if you consider deleting all page Cache, Dentries, and Indoes, you must enter the command as follows:
sync; echo 3 > /proc/sys/vm/drop_caches
In this way, you are familiar with the function of the Sync command and From now on, you can use it to clear the cache. Finally, it is worth noting that you can use this command at certain times and when a Linux server has not been restarted for a long time.
Note: Repeated use of this command may interrupt the performance of Linux and run kernel processes, so avoid using it continuously.
You can also use this command in Cron to automatically clear, after 24 or 48 hours of high pressure on the server.
In this article, we tried to teach you useful information about Clear cache, buffer, and Swap in Linux. You can refer to the article How to add Swap Space on Ubuntu 20.04 if you wish.