How to clean cache in Linux

linux command to clean cache

 

View cached commands

  free -m

Command to clear cache 

     echo 1 > /proc/sys/vm/drop_caches

          echo 2 > /proc/sys/vm/drop_caches

          echo 3 > /proc/sys/vm/drop_caches

echo 0 does not release the cache

echo 1 is to release page cache

ehco 2 is to release dentries and inodes cache

Echo 3 is to release all the caches mentioned in 1 and 2

 

Description:
1>. /proc is a virtual file system, we can read and write to it as a means to communicate with the kernel entity. In other words, the current behavior of the kernel can be adjusted by modifying the files in /proc. In other words, we can release memory by adjusting /proc/sys/vm/drop_caches.
0-do not release
1-release page cache
2-release dentries and inodes
3-release all caches
The number 1 is used to clear the page cache of recently released files
The number 2 is used to clear the file node cache and directory item cache
The number 3 is used to clear the cache of all contents of 1 and 2.
2>. The official description of drop_caches is as follows:
Writing to this file causes the kernel to drop clean caches,dentries and inodes from memory, causing that memory to becomefree.
To free pagecache, use echo 1 > /proc/sys/vm/drop_caches;
to free  dentries and  inodes, use echo 2 > /proc/sys/vm/drop_caches;
to free pagecache, dentries and inodes, use echo 3 >/proc/sys/vm/drop_caches.
Because this is a non-destructive operation and dirty objects are not freeable, the user should run sync first.
 
The source resource comes from: https://www.cnblogs.com/zhehan/p/10716612.html

Guess you like

Origin blog.csdn.net/qq_45534098/article/details/112060802