Clear Memory in Linux
Clear Memory in Linux
1 2 3 4 5 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
nano /temp/clearmem.sh
.)nd *aste the following code.
#!/bin/bash # Clear/Dump Cache Memory, to increase ree memory, use ul or !"#$D proxy %& or # !yed 'ahan(aib / )mail* aacable+hotmail.com ,eb* http*//aacable.-ordpress.com # Make sure you are .ogged in -ith user root. # !etting variables or script set /0date1 time23date 4a-k 56print /7853 # 9ction . . . sync: echo ; < /proc/sys/vm/drop=caches
# 9dd entry in /var/log/cron.log to make record. echo >'(? Cache Memory Clear, 9ction .ogged at /@A/BA/; /time < /var/log/cron.log
1
.
ree Am
and note down the free memory, (ow execute the file by running + /temp/clearmem.sh chec# the log file by cat %var%log%cron.log (ow again chec# the free amount from terminal with the command
ree Am
.)nd you will see the changes before and after running the file clearmem.sh .Howto schedule this file to run daily/hourly using crontab To run this file on hourly basis, open terminal, ,ma#e sure you are logged in with the root user. type crontab -e ,if it as#s for text editor, select nano ,(ow paste following code + @dail /temp/clearmem.sh ! "#n Dail in ni$ht at %%&%% ho#rs
! @ho#rl
/temp/clearmem.sh ! Enable this i' o# (ant to r#n the script on ho#rl basis
(ow, based on above selection, cron .ob will run this command at selected scheduled timings and clear any memory cache (ow some /xplanation of what above script do . . . It will cause the #ernel to drop clean caches, dentries and inodes from memory, causing that memory to become free. ) s nc only ma#es dirty cache to clean cache. cache is still preserved. ) drop*caches doesn0t touch dirty caches and only drops clean caches. So to ma#e all memory free, it is necessary to do sync first before drop*caches in case flushing daemons hasn0t written the changes to dis#. This is in generally a non1destructive operation.