Clear Memory Linux

From MS Computech
Revision as of 11:41, 11 January 2017 by Snifer (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Clear Memory Linux

Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.

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

As this is a non-destructive operation, and dirty objects are not freeable, the user should run "sync" first in order to make sure all cached objects are freed.

Run every 2 hour

nano /etc/crontab

0 */2 * * * root echo 3 > /proc/sys/vm/drop_caches
#!/bin/bash
# Note, we are using "echo 3", but it is not recommended in production instead use "echo 1"
echo "echo 3 > /proc/sys/vm/drop_caches"
chmod 755 clearcache.sh
crontab -e

Append the below line, save and exit to run it at 1am daily.

0  1  *  *  *  /path/to/clearcache.sh

==========================