[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] tuning kernel memory usage



"Noah L. Meyerhans" <frodo@morgul.net> writes:

> Hey folks.  This question has been nagging at me for a while now, and
> it's about time I asked.  I've got a Debian box (potato, upgraded to
> kernel 2.4.1, but that's irrelevant).  I'm seeing swap usage that I
> don't understand.  Here's the output of 'free':
> 
>              total       used       free     shared    buffers cached
> Mem:         78024      70932       7092          0        980 43628
> -/+ buffers/cache:      26324      51700
> Swap:       289160       5372     283788
> 
> So you see that there is some swap usage (5372k).  You also see that
> over 43 megs of RAM are used as cache and over 7 megs are completely
> free.  So my question is: Why is any swap being used at all?
> 
...

Your computer has probably needed the swap space sometime, and it doesn't reload from swap again until you actually need the data.
You could easily use up the available memory again, a lot of programs are rather quick in and out of memory, so why should the system swap data to and from disk more than necessarily? 
Also note, when programs loaded directly from disk are swapped out from memory they aren't loaded to the swap disk, they are "forgotten" and then read from disk again when needed. More could be swapped out than you know..

A lot programs and data are rather seldom needed, even if they are loaded to memory. 
"init" should be a perfect example. Always loaded but only needed when you do thing like change runlevels, log in and out of a text console, or do other things mentioned in inittab. 
Rather rare, actually. 
And most of the time it could just as well be out of your main memory. 
Same thing with text-console login prompts and daemons you don't actually need at the time. 
How often do you use your mail server? 
If not very often, can you wait the decisecond it takes to reload?

The seven megabytes free means the kernel always keeps a small amount of memory free so it doesn't have to always put something out when it loads something in. The cached area I don't know so much about, but it's always smart to leave some area for programs recently being used but "just not now". If you had a script using the same small(?) program a hundred times, would you like to have it reload this program from disk every time it was called again? Remember, on a unix/linux system, even 'ls' is a program.

So, let it be. The kernel uses your memory rather well when all comes to all.
If in doubt, monitor what actually happens over a longer period of time.
A combination of top and xosview is what I have used, in case of interest.

Harald



Reply to: