[H-GEN] Is swap space working?

Martin Pool mbp at samba.org
Fri Apr 20 22:48:14 EDT 2001


[ Humbug *General* list - semi-serious discussions about Humbug and  ]
[ Unix-related topics.  Please observe the list's charter.           ]
[ Worthwhile understanding: http://www.humbug.org.au/netiquette.html ]

On 21 Apr 2001, Webmaster <terranova at acenet.net.au> wrote:

> I'm having low memory problems and am using kpm to monitor memory use (see
> below for machine configuration). The indicator for swap space (presumably the
> HDD swap partition) always shows zero (0k used), and I'm wondering why.

It is possible to run out of memory and still have swap space free,
although it probably would be above 0 used.  For example, if the
machine is running out of memory to hold text pages (i.e. program
binaries), then swap won't help at all.
 
> During boot, a message is printed saying "swap space enabled".
> 
> Configuration: Pentium166, 32MB RAM, 32MB swap partition, Linux 2.2, KDE
> desktop.

Try using the command 

   $ free  

to find out how much swap is really being used.  The results look
something like this:

  $ free -m
(in megabytes)

              total       used       free     shared    buffers     cached
Mem:           505        342        163        174        135        119
-/+ buffers/cache:         87        418
Swap:          486          0        486

So, 87 MB is really *needed*, and most of the rest of RAM is being
used for buffering the disk.  486MB of swap is available, and none is
used.

Linux 2.2 doesn't do very well at freeing swap once it has been
written.  This is mostly harmless -- the pages will be discarded if
the space is needed, but the in-use number will be higher than it
really deserves to be.
               
Also, you could use

   # cat /proc/swaps

which should show something like:

Filename			Type		Size	Used	Priority
/dev/sda2                       partition	498004	0	-1

on a machine with 486MB of swap (va.samba.org).  

> Is this because:
>   1. Swap is always empty when kpm is in use?
>   2. It's not monitoring the swap partition, but something else?

kpm is the KDE process mangler?  It's possible, but unlikely.

>   3. The swap partition is inactive or unavailable?

/proc/swaps will tell you this.  If the swap partition is not active,
then there are two prime possiblities:

1. The swap space is not initialized.  As a protection against you
accidentally using your /home partition as swap, Linux will only mount
swap space that begins with a magic signature.  You can put this on
the partition with a command like:

  # mkswap /dev/hdc7

2. The swap space is not active.  Swap should be set up if there's a
line like this in /etc/fstab:

  /dev/sda2	none		swap	sw			0	0

This results in a command like this being executed by the startup
scripts:

  # swapon /dev/sda2

You can also type this by hand if you've just created more swap space.

>   4. There's a bug in kpm?
>   5. Something else ...

Hope that helps, and happy hacking!
--
Martin




--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.



More information about the General mailing list