How to View Memory Usage and Clear Cache in Linux System

Sometimes, when a server becomes unresponsive, it may not necessarily be due to high CPU usage. It could also be caused by insufficient memory. You can refer to the following methods to check the memory usage and clear it if necessary.

  

1.To check the usage of physical memory and swap space on a server, you can use the command: `free -h`.

 

 

  • - total: Total physical memory on the machine.
  • - used: Amount of memory currently in use.
  • - free: Amount of free (unused) physical memory.
  • - shared: Amount of memory shared by multiple processes.
  • - buff/cache: Memory used for file system buffers and cache.
  • - available: Estimated amount of memory that can be allocated to applications. This is calculated as free + buffer + cache (Note: This calculation is an approximation and may have some margin of error).

 

2.The command to clear cache is:

echo 1 > /proc/sys/vm/drop_caches       //To release page cache

 

 
echo 2 > /proc/sys/vm/drop_caches       //
To release dentries (directory cache) and inodes cache

 

 
echo 3 > /proc/sys/vm/drop_caches       //
To release page cache, dentries (directory cache), and inodes cache

 

 

Note: `echo $?` returns the execution result, where a return value of 0 indicates success.

  • - `echo 0` does not release the cache.
  • - `echo 1` releases the page cache (clears the cache of recently accessed file pages).
  • - `echo 2` releases the dentries (directory cache) and inodes cache (clears the cache of directory entries and file nodes).
  • - `echo 3` releases all caches mentioned in options 1 and 2.
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

CentOS 7.x Firewall: Enable/Disable and Add Ports

  In CentOS 7.x, the default firewall is firewalld. Here is an example using CentOS 7.6...

How to enable/disable ping on Linux system

To prevent others from discovering and potentially attacking your machine through network ping...

How to remotely access a Linux system using Putty tool

Introduction to Putty software PuTTY is a Telnet, SSH, rlogin, raw TCP, and serial interface...

Linux System RuiSu Installation Tutorial

Note: The prerequisite for installing RuiSu is to ensure that the network card is in the "eth"...

Resetting the password in CentOS 7.x system

Resetting the password in the CentOS 7.x system can usually be done automatically by accessing...