Help Center> Elastic Cloud Server> Troubleshooting> Disk Space Management Issues> Why the Buffer and Cache Occupy Too Much Memory of a Linux ECS?
Updated on 2022-07-15 GMT+08:00

Why the Buffer and Cache Occupy Too Much Memory of a Linux ECS?

Symptom

When querying the system memory usage using free after the Linux ECS runs for a long period of time, you have found that most of the memory is used by buffer and cache.

Possible Causes

In Linux memory management, buffer refers to the buffer cache, and cache refers to the page cache.

  • Buffer cache, which caches data that is read from and written to disk blocks

    For example, if the system writes a file, respective page cache pages will be modified, and buffer cache buffers will be marked as dirty. When writing dirty data back to the disk, the kernel only writes back the changes, rather than the entire page, to the disk.

  • Page cache, which caches file data that is read from and written to files in file systems By default, Linux caches the read file data in the memory to facilitate quick data access.

Normally, Linux automatically releases buffers and cache if the system requires more memory, and a high cache memory usage does not affect the system performance.

Solution

Buffers and cache are necessary for the smooth running of systems and devices in Linux. If the cache is forcibly cleared, disk data needs to be read from the disk, which decreases the system performance.

To clear the buffers and cache, run the following command:

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

The command execution may take several seconds, depending on the memory size. After the command is executed, the occupied memory will be released.