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

How to switch to a different repository for CentOS 8 EOL

 CentOS 8 reached its end of life at the end of 2021. When using yum repositories for...

To change the network interface name in CentOS 7.x

一.modify GRUB 1.Edit the GRUB configuration file by running the command: `vi...

To modify the hostname on CentOS

Method One:   1.Open a terminal or SSH into the Linux system. 2.Log in to the system with...

An incorrect configuration in the /etc/fstab file on the Linux system is causing login issues

Encountering communication issues with the machine, I checked the system error messages through...

How to use the atop monitoring tool in Linux

Atop is a monitoring tool used to monitor resources and processes in Linux systems. It...