0
Follow
0
View

How to clear Cache in Linux?

xudong9 注册会员
2023-02-27 13:33
  • This article is very detailed, please see: Handle memory cache
  • Among other things, this blog post: 1 in the cache clearing/releasing command in linux. The section before clearing the cache may solve your problem, but you can read it carefully below or on the source blog:
  • Before releasing the cache, run the sync command to synchronize all unwritten system buffers to disk to ensure the integrity of the file system. Otherwise,

    , unsaved files may be lost.

    sync

czzw818 注册会员
2023-02-27 13:33

Free the system memory cache: /proc/sys/vm/drop_caches
Every Linux system has three options to clear the cache without interrupting any process or service. 1. Clear only the page cache(PageCache)
sync; echo 1 > /proc/sys/vm/drop_caches
2. Clear directory entries and inode
sync. echo 2 > /proc/sys/vm/drop_caches
3. Clear the page cache, directory entries, and inode
sync. echo 3 > /proc/sys/vm/drop_caches

eatras 注册会员
2023-02-27 13:33

Clearing the Cache in Linux can be done in the following ways:

Refresh the disk cache by using the sync command to write all data written to the cache to disk:

$ sync

Write "1" to the /proc/sys/vm/drop_caches file with the echo command to clear the page cache:


$ sudo sh -c "echo 1 > /proc/sys/vm/drop_caches"

Write "2" to the /proc/sys/vm/drop_caches file with the echo command to clear the directory entries and inode cache:

$ sudo sh -c "echo 2 > /proc/sys/vm/drop_caches"

Write "3" to the /proc/sys/vm/drop_caches file with the echo command to clear directory entries, inodes, and page caches:

$ sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"

Note that clearing the cache may adversely affect system performance. Therefore, exercise caution when performing this operation. You are advised to perform this operation when you need to perform performance tests or the system has cache problems.