Linux memory usage and swap files

Jason Gurtz jason at
Wed Jul 7 13:09:23 PDT 2004

On 7/7/2004 15:03, Shane Shields wrote:

> Hi all,
> There was a recent thread about the need and wisdom of using a swap file and 
> some stated that if you have enough memory you don't need one and others 
> stated that it will always improve performance.

Having swap will mostly always improve performance.  However, there is a
case where having swap will definitely have a negative impact on your
running system.

Specifically, a process that walks the whole file system will invite
everything else to be swapped out.  For instance, a daily cron job that
updates the database used by the locate command will--in most
instances--cause most everything to be swapped out in favor of a large
file cache which is what the kernel assumes will give the user "the
highest performance".

That may be true for some users I imagine but I would be annoyed to come
back to my desktop and have to wait for everything to be paged back in.
 With a 2.6 kernel you can adjust /proc/sys/vm/swappiness from 100
(nearly always swap stuff out) to 0 (almost never swap stuff out).  A
good discussion of this is <>.

Another interesting case is :
 See the "Starvation with find" thread

So, if you run 2.4 you're pretty much SOL.  One could probably kludge
together a little script involving values in /proc/meminfo and the
swap[on,off] command for use before and after running such file system
intensive processes but it would seem a bit dangerous if one is prone to
approach OOM conditions.

It would be good to see a utility in the style of "nice" where you could
invoke a process with it's own "swapiness" value.  0 meaning never swap
this process out (hmm, dangerous?), 100 meaning I don't care how long
this little background task takes, swap it out at will.




More information about the lfs-chat mailing list