Script to clear swap and free memory...opinions

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware
Author Message
Masterman
DD-WRT Guru


Joined: 24 Aug 2009
Posts: 2070
Location: South Florida

PostPosted: Wed May 04, 2011 16:41    Post subject: Script to clear swap and free memory...opinions Reply with quote
After reading heavily on how kernel 2.6 manages memory, buffers and swaps, I stumbled upon this link where a user has implemented a simple bash script and has added it to his cronjobs:


http://ubuntuforums.org/showthread.php?t=1518922



In the OTRW thread, a user has posted a command that frees memory using the safe "sync" command:

Code:

sync; echo 3 > /proc/sys/vm/drop_caches; free


If this command is executed, the memory is freed, but the data on the swap partition is not, which could cause problems.

Here is the command before and after:

Code:
# free
             total         used         free       shared      buffers
Mem:        127036       115240        11796            0        47968
-/+ buffers:              67272        59764
Swap:       522072         4368       517704


Code:
# sync; echo 3 > /proc/sys/vm/drop_caches; free
             total         used         free       shared      buffers
Mem:        127036        18780       108256            0          216
-/+ buffers:              18564       108472
Swap:       522072         4360       517712


I am a heavy user of Samba and other memory intensive applications. Aside from a reboot, the used RAM always stays in the cache and is never freed.

Would running a cronjob like the example listed above, say every 12 hours (and at like 3 A.M) be a wise idea?

I can certainly understand that it could cause major issues if an application was running (say a user D/Ling from my FTP), so I am asking for your opinions.

Thanks,

Masterman

_________________
Optware, the Right Way
Asus RT-AC68U
Asus RT-N66U
Asus RT-N10
Asus RT-N12
Asus RT-N16 x5
Asus WL520gU
Engenious ECB350
Linksys WRT600Nv1.1
Linksys WRT610Nv1
Linksys E2000
Netgear WNDR3300
SonicWall NSA220W
SonicWall TZ215W
SonicWall TZ205W
SonicWall TZ105W
Sponsor
oxygenx
DD-WRT Guru


Joined: 11 Nov 2007
Posts: 566

PostPosted: Thu May 05, 2011 8:32    Post subject: Re: Script to clear swap and free memory...opinions Reply with quote
Masterman wrote:

I am a heavy user of Samba and other memory intensive applications. Aside from a reboot, the used RAM always stays in the cache and is never freed.

Sure, because free memory is useless memory.
Quote:

Would running a cronjob like the example listed above, say every 12 hours (and at like 3 A.M) be a wise idea?

Probably not. If you have the feeling that your system uses to much ram for caches you can adjust the vm.vfs_cache_pressure sysctl, but looking at your # free "screenshot" that's not the case.

_________________
Router: WNDR3300 (wl0: n-Only 5Ghz, WPA2-AES, wl1: g-Only, WPA-Mixed-Mixed)
WDS Node 1: WNDR3300 (wl0: n-Only 5Ghz, WPA2-AES, WDS-connected Router, wl1: g-Only WPA-Mixed-Mixed)
WDS Node 2: WRT54GL (g-Only, WPA-Mixed-Mixed WDS-connected to Router)
Modem: Cisco EPC3202
clients: Notebook 1, D-Link 323, PS3 Slim, Kathrein UFC960 connected to WDS Node 1 via Gigabit Switch. Notebook 2, Deskjet 6980 connected to WDS Node 2
Masterman
DD-WRT Guru


Joined: 24 Aug 2009
Posts: 2070
Location: South Florida

PostPosted: Thu May 05, 2011 11:18    Post subject: Reply with quote
Thanks, I have read about the vfs_cache_pressure and have done the following:


Code:
root@Asus:~# echo 50 > /proc/sys/vm/vfs_cache_pressure
root@Asus:~# free
             total       used       free     shared    buffers     cached
Mem:        124708     117056       7652          0       1352      99492
-/+ buffers/cache:      16212     108496
Swap:      1052248          0    1052248


My free RAM is slowly being increased

_________________
Optware, the Right Way
Asus RT-AC68U
Asus RT-N66U
Asus RT-N10
Asus RT-N12
Asus RT-N16 x5
Asus WL520gU
Engenious ECB350
Linksys WRT600Nv1.1
Linksys WRT610Nv1
Linksys E2000
Netgear WNDR3300
SonicWall NSA220W
SonicWall TZ215W
SonicWall TZ205W
SonicWall TZ105W
oxygenx
DD-WRT Guru


Joined: 11 Nov 2007
Posts: 566

PostPosted: Thu May 05, 2011 15:41    Post subject: Reply with quote
i doubt it will help you in any way, but if so i'd be glad to hear.
_________________
Router: WNDR3300 (wl0: n-Only 5Ghz, WPA2-AES, wl1: g-Only, WPA-Mixed-Mixed)
WDS Node 1: WNDR3300 (wl0: n-Only 5Ghz, WPA2-AES, WDS-connected Router, wl1: g-Only WPA-Mixed-Mixed)
WDS Node 2: WRT54GL (g-Only, WPA-Mixed-Mixed WDS-connected to Router)
Modem: Cisco EPC3202
clients: Notebook 1, D-Link 323, PS3 Slim, Kathrein UFC960 connected to WDS Node 1 via Gigabit Switch. Notebook 2, Deskjet 6980 connected to WDS Node 2
ReDaLeRt
DD-WRT User


Joined: 26 Oct 2010
Posts: 80
Location: Portugal

PostPosted: Thu May 05, 2011 20:50    Post subject: Re: Script to clear swap and free memory...opinions Reply with quote
Masterman wrote:

http://ubuntuforums.org/showthread.php?t=1518922


WoW! Huge improvement on available memory.

I'll run this on the next weeks and give feedback.

Thanks m8!

[[]]

_________________
DD-WRT powered:
RT-N16 + WRT54G v2 + FON 2201 & 2100
drk2276
DD-WRT Novice


Joined: 04 Jan 2019
Posts: 1

PostPosted: Mon Mar 23, 2020 12:18    Post subject: excellent script!!!! Reply with quote
although its a really old thread i would like to confirm that this script solved my problem with transmission!!
thank you!!!
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum