Is Your Server Memory Full? A Quick Linux Command to Free Up Memory!

If your server’s memory usage is too high, causing slow performance or crashes, you can try the following Linux command to quickly free up cached memory:

# This parameter can be used to instruct the kernel to actively free memory caches, but it will not affect running programs.
sync; echo 3 > /proc/sys/vm/drop_caches

Command Explanation

  • <span>sync</span>: Writes data from memory to disk to ensure that data is not lost due to cache release.
  • <span>echo 3 > /proc/sys/vm/drop_caches</span>:
    • <span>0</span> (default) does not free any caches, completely managed by the kernel.
    • <span>1</span> frees page cache
    • <span>2</span> frees directory entry cache and inode cache
    • <span>3</span> frees all of the above caches

Precautions

  1. Do not use frequently: This can affect system performance. The Linux caching mechanism is designed to speed up access, and manual clearing may be counterproductive.
  2. Only use when necessary: For example, when memory resources are very tight.
  3. Not a solution for memory leaks: If an application continuously grows in memory usage, this command is ineffective, and code or service investigation is needed.

You can use the following command to compare memory changes before and after

free -h

If you need technical support or want to join a discussion group, add me on WeChat: lige_linux

Previous Excellent Articles:

K8S Command Detailed Summary [Personal Collection]| K8S Cluster Deployment | K8S Storage Practical Cases |K8S Certificate Renewal for Ten Years | K8S Deployment of Prometheus | Rancher Deployment and Management of K8S |Jenkins Installation and Deployment | Gitlab Installation and Deployment | Service Mesh Istio Installation and Practice |Building an Enterprise-Level Harbor Repository | K8S Integration with Harbor Repository | Common Docker Commands Summary |Solutions for Docker Unable to Download Images | Three Methods to Install Docker | Summary of Basic Docker Concepts |Oracle 19C RAC Cluster Setup | Oracle Cluster Management Command Summary | MySQL Cluster Installation and Deployment | MySQL One-Click Backup Script | MySQL Cluster Directory Migration | Redis Three Masters and Three Slaves Cluster Deployment |150 Common Linux Commands | 8 Interesting Linux Commands | Summary of Network Card Configuration Methods for Mainstream Linux Operating System Versions, Recommended for Collection! |Detailed Explanation of Firewalld Firewall | Building Internal Yum Repository | Comprehensive Disk Expansion Methods | Out-of-Band Management Knowledge for Servers

Leave a Comment