Linux uses instructions to release the cache step

  
                

After the Linux system has been in operation for a long time, it will generate a lot of caches for watching videos and downloading files. If it is not regularly cleaned, it will cause the system to become very slow. The following small series will introduce you to the Linux release cache method.

caching mechanism

Linux system is quite advanced, he will for the dentry (for VFS, accelerated file pathname to inode conversion), Buffer Cache (for read and write disk blocks) and Page Cache (read and write for file inodes) performs caching operations. But after a lot of file operations, the cache will run out of memory resources. But in fact, our file operation has been completed, and this part of the cache is no longer used. At this time, can we only watch the cache occupy the memory space?

So, we still need to manually release the memory under Linux, in fact, is to release the cache operation.

To achieve the purpose of releasing the cache, we first need to understand the key configuration file /proc/sys/vm/drop_caches. The cache release parameter is recorded in this file. The default value is 0, that is, the cache is not released. His value can be any number between 0 and 3, which means different meanings:

0 – does not release

1 – release page cache

2 – Release dentries and inodes

3 – Release all caches

Once we know the parameters, we can use the following instructions to operate according to our needs.

First we need to use the sync command to write all unwritten system buffers to disk, including modified i-nodes, delayed block I/Os, and read-write mapping files. Otherwise, unsaved files may be lost during the release of the cache.

#sync

Next, we need to write the required parameters into the /proc/sys/vm/drop_caches file. For example, if we need to release all caches, enter the following command: Br>

#echo 3 》 /proc/sys/vm/drop_caches

This command takes effect immediately after it is entered. It can be queried that the available memory is significantly more.

To query the parameters of the current cache release, you can enter the following command:

#cat /proc/sys/vm/drop_caches

The above is the use of Linux to release the cache. The method is introduced. If you think your computer is getting more and more cards, then your memory may be occupied a lot. You may want to clean up the computer garbage.

Copyright © Windows knowledge All Rights Reserved