Monitoring Swap Space

Team-Fly    

Solaris™ Operating Environment Boot Camp
By David Rhodes, Dominic Butler
Table of Contents
Chapter 7.  Swap Space


Somehow we need to check how our swap space is being used. We can't check it in the same way we would check a filesystem. The reason for this is that when a swap area is created, whether it's a raw partition or a file, we simply create the "full thing" and pass it onto the system to use as it sees fit. For example, earlier we defined a disk partition that was around 80 MB in size. At this time, we have no idea how full it is. Similarly, we created a 100 MB swap file. Utilities such as df and du will report its size correctly, but again will be unable to tell us how much of it is actually used at present.

So, now let's look at some ways of determining what's happening with swap. First, we can see the current swap allocation on a system as follows:

 hydrogen# swap l swapfile             dev  swaplo blocks   free /dev/dsk/c0t2d0s3  226,7      16 16774704 16774640 hydrogen# 

The columns shown are described in Table 7.3.

Table 7.3. Column Details

Column Heading

Description

swapfile

This is the path name of the disk partition or file on which the swap space is located.

Dev

This is the major and minor number of the partition. It will contain a dash (-) if the swap space is located on a file.

swaplo

This is the starting location of the swap space shown as an offset from the beginning of the partition or file.

blocks

This is the size of the swap file in 512-byte blocks.

Free

This is the number of 512-byte blocks of swap that are not currently allocated.

We can get some additional information on swap usage by running swap s:

 hydrogen# swap s total: 311704k bytes allocated + 55592k reserved = 367296k used,    14658824k available hydrogen# 

The "bytes allocated" refers to the amount of swap that has been allocated and is in use, while the term "reserved" refers to the amount of swap that has been claimed for possible future use but is not actually being used at the moment. These values are added up to give the total in use, the remainder being the swap still available. Note that the size of swap displayed by the "-s" option is shown in kilobytes and includes the system RAM, whereas the "-l" displays sizes in 512-byte blocks and does not include the size of RAM in its calculations.

If your system is suffering from problems caused by a lack of swap space, you may see any of the following error messages:

  • program out of memory

  • malloc error 0

  • WARNING: Sorry, no swap space to grow stack for pid

  • /tmp: File system full, swap space limit exceeded

  • /tmp: File system full, memory allocation failed

The latter two examples may at first seem to point to the fact that /tmp has filled, possibly because somebody has been creating something very large in it. This could cause the problem, but because /tmp has a filesystem type of TMPFS it will be affected by lack of memory or swap space. These problems all indicate that you probably need to increase the amount of swap space you have.

If you are worried that abusers of /tmp will cause you to run out of swap space, you can actually set a limit on the maximum size it can become by setting a mount option in the /etc/vfstab file. Altering the entry to be the same as the following example will set an effective limit of 100 MB on it:

 swap  -     /tmp          tmpfs   -      yes     size=100m 

Using Sar

If you suspect that you may not have sufficient swap space, you can run the sar command with the "-r" option at regular intervals:

 hydrogen# sar -r 5 5 14:23:29 freemem freeswap 14:23:34  846214 29678904 14:23:39  847907 29738202 14:23:44  849603 29797696 14:23:49  846218 29678980 14:23:54  849603 29797696 hydrogen# 

The above example takes five samples with a five-second interval between each sample and shows the amount of free memory (in pages) and free swap space (in disk blocks) at each sample. If you wish to monitor this over a period of time, an entry would usually be added to the sys crontab file:

 0,10,20,30,40,50 * * * * /usr/lib/sa/sa1 

If the above crontab entry was used, then sar statistics would be collected every 10 minutes and stored in a file for each day of the month in the directory /var/adm/sa. We could look at the memory and swap statistics using the sar command as follows:

 hydrogen# sar r f sa30 <lines removed for clarity> 17:00:00  775787 27679278 17:10:00  774895 27664929 17:20:00  769536 27653001 17:30:00  681201 27630680 17:40:01  681820 27664144 17:50:01  682670 27602540 18:00:00  704518 27673268 18:10:00  697904 27616876 18:20:00  683044 27655721 18:30:01  695920 27704512 18:40:00  700563 27649453 18:50:00  700633 27649167 19:00:00  700626 27648279 <lines removed for clarity> hydrogen# 

This shows us all the sar r statistics that were gathered at 10-minute intervals for the 30th day of the month. The files get overwritten each month, so if you wish to keep more than a month's worth of statistics you need to save each file before it is overwritten.

Using Vmstat

The sar command is fine for what it does, but the information it gives us is fairly limited. If we want to monitor our memory and swap usage in much more detail, then we can use the vmstat command. This command, like sar, will take samples at regular intervals over a period of time. For example, the following will check memory usage every 10 seconds and report the results to the screen:

 hydrogen# vmstat 10 procs     memory            page            disk          faults      cpu  r b w   swap  free  re  mf pi po fr de  sr s0 s1 s6 s1   in  sy  cs us sy id  0 0 0 12582944 4575224 40 95  160 31 31 0 0 2  0  0  2 2657 792 390  1  3 97  0 0 0 12222880 3971448 0 1  0  0   0  0  0  0  0  0  0 2609 518 217  0  0 100  0 0 0 12222880 3971448 14 157 0 0  0  0  0  2  0  0  2 2621 800 363  0  1 99  0 0 0 12222880 3971448 0 19 0  0   0  0  0  0  0  0  0 2615 965 249  0  0 100 hydrogen# 

This is a lot of output to digest. Table 7.4 shows details of the data each column refers to.

Table 7.4. Vmstat Output

Column Heading

Description

procs

r

Number of processes in the run queue.

 

b

Number of processes blocked for resource I/O or paging and so forth.

 

w

Number of processes currently swapped.

memory

swap

Current free swap (KB).

 

free

Current free memory (KB).

page

re

Page reclaims per second.

 

mf

Minor faults per second.

 

pi

KB paged in per second.

 

po

KB paged out per second.

 

fr

KB freed per second.

 

de

Anticipated short-term memory shortfall (KB) per second.

 

sr

Pages scanned by clock algorithm per second.

disk

s0

Number of disk operations per second on SCSI disk target 0 (there can be up to four columns of information under the disk heading, depending on how many disks you have installed).

faults

in

Device interrupts per second.

 

sy

System calls per second.

 

cs

CPU context switches per second.

cpu

us

Percentage CPU time in user mode.

 

sy

Percentage CPU time in system mode.

 

id

Percentage CPU time idle.

If we see very low values in the pages scanned column (page/sr), this is a sure sign that we are not experiencing any memory shortage problems. If, on the other hand, we see very high values (around 200 or higher) we may have a problem, but not definitely. We would need to monitor the situation for a while before making a judgment. If the value falls again, it may have been that a process was reading a large quantity of uncached data, so we can ignore it. However, if it remains high, then it is likely that we are short of memory.


    Team-Fly    
    Top
     



    Solaris Operating Environment Boot Camp
    Solaris Operating Environment Boot Camp
    ISBN: 0130342874
    EAN: 2147483647
    Year: 2002
    Pages: 301

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net