Page 1 of 1

Script to flush cache in ram?

Posted: Wed Mar 03, 2010 7:20 pm
by njtuneguy
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!! :)

Re: Script to flush cache in ram?

Posted: Wed Mar 03, 2010 10:36 pm
by njtuneguy
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

Re: Script to flush cache in ram?

Posted: Thu Mar 04, 2010 12:46 am
by moredruid
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

Re: Script to flush cache in ram?

Posted: Thu Mar 04, 2010 1:23 am
by cpg
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.

Re: Script to flush cache in ram?

Posted: Thu Mar 04, 2010 4:44 am
by moredruid
hmm how is power management defined in the BIOS? APM? ACPI? disabled?

Re: Script to flush cache in ram?

Posted: Thu Mar 04, 2010 12:53 pm
by cpg
power management is defined mainly in ACPI (but also through some cpu registers).