Difference between revisions of "Clear Memory Linux"
From MS Computech
Line 15: | Line 15: | ||
0 */2 * * * root echo 3 > /proc/sys/vm/drop_caches</pre> | 0 */2 * * * root echo 3 > /proc/sys/vm/drop_caches</pre> | ||
+ | |||
+ | <pre> | ||
+ | #!/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" | ||
+ | </pre> | ||
+ | <pre> | ||
+ | chmod 755 clearcache.sh | ||
+ | crontab -e | ||
+ | </pre> | ||
+ | Append the below line, save and exit to run it at 1am daily. | ||
+ | <pre> | ||
+ | 0 1 * * * /path/to/clearcache.sh | ||
+ | </pre> | ||
+ | |||
==========================<br> | ==========================<br> |
Latest revision as of 11:41, 11 January 2017
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
==========================