clear memory in linux

2
Cl ear Memory in Linux Box Clear Memory in Linux (specially for squid servers) If you are hosting SQUID proxy server on your Linux box, you may have noticed that SQUID as a proxy server is very greedy with memory. Over the period of time, it consumes large amount of memory , even in some cases 98-99%. This script will clear the memory so that it be used by system or SQI! again. "a#e sure you are logged in with root  user in order to continue. $ust create a new script and put it in any folder li#e %temp &reate 'ile by following command 1 2 3 4 5 mkdir /temp cd /temp touch clearmem.sh touch /var/log/cron.log chmod +x clearmem.sh (ow edit the file by 1 nano /temp/clearmem.sh .)nd *aste the following code. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #!/bin/bash # Clear/Dump Cache Memory, to increase ree memory, useul or "$D proxy %& or # yed 'ahan(aib / )mail* aacablehotmail.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 @ABA; time < /var/log/cron.lo .Save, and Exit. (ow change the permission so it can be executed. 1 chmod /temp/clearmem.sh .

Upload: shah-paran

Post on 04-Jun-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

8/13/2019 Clear Memory in Linux

http://slidepdf.com/reader/full/clear-memory-in-linux 1/2

Clear Memory in Linux Box

Clear Memory in Linux (specially for squid servers)

If you are hosting SQUID proxy server on your Linux box, you may have noticed that SQUID as a proxy

server is very greedy with memory. Over the period of time, it consumes large amount of memory , even in

some cases 98-99%.

This script will clear the memory so that it be used by system or SQI! again. "a#e sure you are logged in

with root  user in order to continue.

$ust create a new script and put it in any folder li#e %temp

&reate 'ile by following command

1

2

3

4

5

mkdir /temp

cd /temptouch clearmem.shtouch /var/log/cron.logchmod +x clearmem.sh

(ow edit the file by

1 nano /temp/clearmem.sh

.)nd *aste the following code.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

#!/bin/bash# Clear/Dump Cache Memory, to increase ree memory, useul or "$D proxy

# yed 'ahan(aib / )mail* aacablehotmail.com eb* http*//aacable.-ordpres# Make sure you are ogged in -ith user root.

 

# etting variables or scriptset 0date1time23date 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 @ABA; time < /var/log/c

.Save, and Exit.

(ow change the permission so it can be executed.

1 chmod /temp/clearmem.sh

.

8/13/2019 Clear Memory in Linux

http://slidepdf.com/reader/full/clear-memory-in-linux 2/2

(ow first execute

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

1 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.

) snc 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.