Clear Memory Linux
From MS Computech
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
==========================