How to force release/free cached memory via ssh command on linux

Command free via ssh only shows how many memory used, but people always seem to forget about that. Cached memory is still techincaly *free* memory that can be used. The Linux OS just doesn't free it, it keeps it there to help speed up other applications that may need the data there. If you still want force release those cached memory/ram, and it bothers you that its not really *freeing* the memory, you can force to free the cached/buffered memory to clear out by ssh command: echo 1 > /proc/sys/vm/drop_caches 

Example:

[root @ www.ComfortVPS.com ]# free
             total       used       free     shared    buffers     cached
Mem:        248488     183244      65244          0      29136     112964
-/+ buffers/cache:      41144     207344
Swap:       262136      17940     244196
[root @ www.ComfortVPS.com ]# echo 1 > /proc/sys/vm/drop_caches
[root @ www.ComfortVPS.com ]# free
             total       used       free     shared    buffers     cached
Mem:        248488      46896     201592          0        112       7384
-/+ buffers/cache:      39400     209088
Swap:       262136      17940     244196

 

Something More:

Flush file system buffers by executing,

# sync

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

To free page cache:

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

To free dentries and inodes:

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

To free page cache, dentries and inodes:

echo 3 > /proc/sys/vm/drop_caches

Above commands are non-destructive and will only release unused memory. As we have used sync, so it will flush all Dirty Objects which are not free able and make it as unused memory.

  • 0 Users Found This Useful
這篇文章有幫助嗎?

相關文章

A-Z Index of the Linux BASH command line

An A-Z Index of the Linux BASH command line alias Create an aliasapropos Search Help manual...

Changing The SSH Port

While there are many ways to make sure your server is as secure as possible there are some basic...

Check and open ports in CentOS / Fedora / Redhat

  If you want to open or close a port for a Linux firewall you have to edit the rules in...

Clear Memory Cache on Linux Server

By default the Linux OS has a very efficient memory management process that should be freeing any...

Create email accounts using ssh

/scripts/addpop user_id@yourdomains.com user_password Do below mentioned steps for configuration...