howto flush cache and buffers ?
kwan at digitalhermit.com
Tue Mar 27 16:17:00 UTC 2007
> I'm interested to know if it is possible to forcibly flush the caches
> and/or buffers ?
> I googled and found a good article on how the buffers/caches are used,
> and that with kernel tuning, the builder can change the behaviour. Also,
> you can write a program that grabs all of memory causing the caches or
> buffers to be flushed, then the program releases the memory it grabbed,
> leaving large amounts of free memory.
What specifically are you trying to tune/do? I.f., if you run a program that sweeps
the disk it will change the cache, but this is not necessarily desirable. In fact,
there was a kernel paramer (O_STREAMING) that specifically prevented programs that
sweep the disk from invalidating the cache.
You might have stumbled on the "swappiness" kernel tuning parameter. It will let you
change how Linux will page out to disk. The tuning changes whether you want Linux to
keep applications in memory at the expense of cache or vice versa. I.e., some people
prefer that if they leave their machine for a few hours, when they come back there
won't be a pause as Linux brings in those apps from pagespace. For a server this
would be reverse of what's usually desirable.
> But are there more direct ways to make memory available (even though it
> is not always a good idea - I understand the kernel does a good job at
> using all available memory with just a small amount ready for immediate
> assignment as required.):
You won't be actually making memory available though.. E.g., if your programs sweeps
the disk and (inadvertently) flushes the cache with one-time data, then the cache
will just get repopulated but there's no memory gain just a short-term worsening.
> Does it hurt to do: swapoff -a && swapon -a ?
> How about buffers ?
> How about cache ?
> Also it would seem that trashapplet and beagled is consuming large
> amounts of memory: is this really the case ?
* The Digital Hermit http://www.digitalhermit.com
* Unix and Linux Solutions kwan at digitalhermit.com
More information about the users