Difference between revisions of "Clear Memory Linux"

From MS Computech
Jump to: navigation, search
(New page: ==== 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: <pre>* ec...)
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
==== Clear Memory Linux ====
+
==== 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.
+
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:
+
To free pagecache:  
 
<pre>* echo 1 &gt; /proc/sys/vm/drop_caches</pre>
 
<pre>* echo 1 &gt; /proc/sys/vm/drop_caches</pre>
To free dentries and inodes:
+
To free dentries and inodes:  
 
<pre>* echo 2 &gt; /proc/sys/vm/drop_caches</pre>
 
<pre>* echo 2 &gt; /proc/sys/vm/drop_caches</pre>
To free pagecache, dentries and inodes:
+
To free pagecache, dentries and inodes:  
 
<pre>* echo 3 &gt; /proc/sys/vm/drop_caches</pre>
 
<pre>* echo 3 &gt; /proc/sys/vm/drop_caches</pre>
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.
+
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
 +
<pre>nano /etc/crontab
 +
 
 +
0 */2 * * * root echo 3 &gt; /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

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