cancel
Showing results for 
Search instead for 
Did you mean: 
Oleksandr
Sisense Team Member
Sisense Team Member

Clean cached RAM

This article will discuss how to clean cached RAM on a Linux system.  We’ll see how to carry out the clean-up process manually. We’ll make use of tools such as Grafana and echo.

Linux is borrowing unused memory for disk caching. This makes it look like you need more memory, but you do not. 

In Sisense, you can check it in Grafana Dashboard Node Exporter / Nodes.

Memory_Before_Clean.png

Disk caching makes the system much faster and more responsive. It does not take memory away from applications in any way, ever.

If your applications want more memory, they will take back a chunk that the disk cache borrowed. The disk cache can always be given back to applications immediately-- you are not low on ram.

You cannot disable disk caching; the only reason anyone wants to disable disk caching is that they think it takes memory away from their applications, which it doesn't. Disk cache makes applications load faster and run smoother, but it never takes memory away. So, there's no reason for you to disable it.

Kernels 2.6.16 and newer provide a mechanism to have the kernel drop the page cache and/or inode and dentry caches on command, which can help free up a lot of memory. 

To use /proc/sys/vm/drop_caches, just echo a number to it.

To free pagecache:

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


To free dentries and inodes:

"# echo 2 > /proc/sys/vm/drop_caches


To free pagecache, dentries and inodes:

echo 3 > /proc/sys/vm/drop_caches


This is a non-destructive operation, and will only free things that are completely unused. Dirty objects will continue to be in use until written out to disk and are not freeable. If you run "sync" first to flush them out to disk, these drop operations will tend to free more memory.

After Memory Clean with the echo 3 > /proc/sys/vm/drop_caches , you`ll observe the free RAM increase in Grafana:

Memory.png


This article discussed how we could clean up the 
cached RAM of our Linux system. Once you need to clear some RAM quickly to workaround another issue, like a VM misbehaving, you can force Linux to drop caches non-destructively. 

Rate this article:
Version history
Last update:
‎03-17-2023 08:57 AM
Updated by:
Contributors