Script to flush cache in ram?

njtuneguy
Posts: 12
Joined: Tue Feb 23, 2010 8:08 pm

Script to flush cache in ram?

Postby njtuneguy » Wed Mar 03, 2010 7:20 pm

I've noticed that when I'm streaming videos over my wireless network that after a short period of time watching, and/or after transferring a large file from my hda, that the transfers slow significantly (ie., slow transfers or stalled video streaming).

One thing that seems to solve the problem is clearing the cache from my ram using the following:

Code: Select all

sync; echo 3 > /proc/sys/vm/drop_caches
This seems to speed the system right back up, so I don't think it's a network issue. Got the code from here :http://www.scottklarr.com/topic/134/lin ... om-memory/

MY QUESTION IS:

Does anyone know how to insert this into a bash script that would clear the cache when it reaches a certain percentage of ram usage (eg.,50%)? That way I could insert the script at startup and keep my speed all spiffy and shiny like new!!! :mrgreen:

Example equation (logic):

Code: Select all

#! /bin/bash IF="% of cache using ram >/=50%" THEN="sync; echo 3 > /proc/sys/vm/drop_caches"
I know the code is nowhere near correct :roll: but the logic is simple enough.

P.S. I've got plenty of ram (4x1gb) so I'm certain I'm not the only one (at least I think...) that experiences this, plenty of other Amahi users would benefit greatly from a solution to this!! :)
Headless HDA: Fedora 12, AMDx2 3800+, 4gb DDR 3200, 40gb HDD (Boot & 8.4gb Swap, mounted at "/boot"), 2x1tb 7200rpm HDD SoftwareRaid-0 (mounted at "/"). Linksys WRT54G v.5, 100mbit LAN to HDA. WLAN clients: Macbook 2,1 OSX 10.6.2; Windows XP SP3. Comcast 15mbit.

njtuneguy
Posts: 12
Joined: Tue Feb 23, 2010 8:08 pm

Re: Script to flush cache in ram?

Postby njtuneguy » Wed Mar 03, 2010 10:36 pm

Server-side I'm just opening files from the standard smb shares mounted on desktop thru OSX finder.
Client-side is my Macbook, I'm using VLC 1.0.2 (Intel x64), Quicktime 10.0 (90.3.1).

Code: Select all

VMStat output: procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 516936 39348 2987108 0 0 124 4 244 184 2 1 98 0 0
Headless HDA: Fedora 12, AMDx2 3800+, 4gb DDR 3200, 40gb HDD (Boot & 8.4gb Swap, mounted at "/boot"), 2x1tb 7200rpm HDD SoftwareRaid-0 (mounted at "/"). Linksys WRT54G v.5, 100mbit LAN to HDA. WLAN clients: Macbook 2,1 OSX 10.6.2; Windows XP SP3. Comcast 15mbit.

User avatar
moredruid
Expert
Posts: 791
Joined: Tue Jan 20, 2009 1:33 am
Location: Netherlands
Contact:

Re: Script to flush cache in ram?

Postby moredruid » Thu Mar 04, 2010 12:46 am

hmm not sure about the scripting but what happens if you echo 2 to that parameter?

or like this with the proper command:

Code: Select all

root@host# sysctl -w vm.drop_caches=2
echo '16i[q]sa[ln0=aln100%Pln100/snlbx]sbA0D2173656C7572206968616D41snlbxq' | dc
Galileo - HP Proliant ML110 G6 quad core Xeon 2.4GHz, 4GB RAM, 2x750GB RAID1 + 2x1TB RAID1 HDD

User avatar
cpg
Administrator
Posts: 2618
Joined: Wed Dec 03, 2008 7:40 am
Contact:

Re: Script to flush cache in ram?

Postby cpg » Thu Mar 04, 2010 1:23 am

good point.

this looks weird. we debugged it a bit, but it was not reproducible at the time.

one thing, though, is that the board has ACPI errors in dmesg and has power management enabled. that could be at issue.

other than that, i'm not sure what's going on.
My HDA: Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz on MSI board, 8GB RAM, 1TBx2+3TBx1

User avatar
moredruid
Expert
Posts: 791
Joined: Tue Jan 20, 2009 1:33 am
Location: Netherlands
Contact:

Re: Script to flush cache in ram?

Postby moredruid » Thu Mar 04, 2010 4:44 am

hmm how is power management defined in the BIOS? APM? ACPI? disabled?
echo '16i[q]sa[ln0=aln100%Pln100/snlbx]sbA0D2173656C7572206968616D41snlbxq' | dc
Galileo - HP Proliant ML110 G6 quad core Xeon 2.4GHz, 4GB RAM, 2x750GB RAID1 + 2x1TB RAID1 HDD

User avatar
cpg
Administrator
Posts: 2618
Joined: Wed Dec 03, 2008 7:40 am
Contact:

Re: Script to flush cache in ram?

Postby cpg » Thu Mar 04, 2010 12:53 pm

power management is defined mainly in ACPI (but also through some cpu registers).
My HDA: Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz on MSI board, 8GB RAM, 1TBx2+3TBx1

Who is online

Users browsing this forum: No registered users and 2 guests