One-line command to clear Linux memory cache

Cache is a temporary storage area used to store frequently accessed data for quick access. The cache in Linux is called Page Cache, and the Linux caching method is called write-back cache.

View buffer and cache details

free -h

  • Clean page cache only (pagecache)
sync; echo 1 > /proc/sys/vm/drop_caches

Note: In Linux, write operations are usually delayed to improve file system performance. This means that written data is first cached in memory rather than immediately written to disk. The system will then write the buffer data to disk as needed, which can reduce the number of disk accesses and improve performance.

sync The command forces the data in the buffer to be written to disk immediately. It flushes the file system cache and writes data from memory to physical disk to ensure data durability.

  • Clean dentry and inode
sync; echo 2 > /proc/sys/vm/drop_caches
  • Clean page cache, dentry and inode
sync; echo 3 > /proc/sys/vm/drop_caches

Note: In Linux, a file system is a structure used to organize and manage files and directories. File systems store files and directories on disk and provide access to and management of them.

Directory entry (dentry): A directory entry is a data structure in the file system that is used to represent the names, locations, and other attributes of files and directories. Each directory entry contains the name of a file or directory and a reference to the corresponding index node.

Index node (inode): An inode is another data structure in the file system that is used to store metadata of a file or directory (such as file size, access permissions, owner, etc.) and the location of the file data.

Simply put, a directory entry is the name and reference of a file or directory, while an inode is the location of the file or directory's metadata and data.

  • Clean cache and buffer at the same time
sync && echo 3 > /proc/sys/vm/drop_caches

Guess you like

Origin blog.csdn.net/m0_56572447/article/details/131148175