Next | Prev | Up | Top | Contents | Index

Checking Swap Activity With The swap -s Command

The swap -s command is a very useful tool for determining if you need to add swap space of some sort. The output of the swap -s command looks something like:

total: 0 allocated + 64248 reserved = 64248 blocks used, 17400 blocks available
Where the fields displayed are as follows (see the swap(1M) reference page for more details):

allocated

The number of 512 bytes blocks allocated to private pages (for example, pages that contain data that is in use.)

reserved

The number of 512 byte blocks currently allocated but not yet marked as private pages (the space has been claimed, but is not yet being used.)

blocks used

The number of 512 byte blocks either allocated or reserved (the total number of allocated and reserved blocks)

blocks available


The number of 512 byte blocks available for future reservation and allocation (the total swap shown by the swap -l command less the number of blocks used)
Given the following sample swap -s output:

total: 0 allocated + 34200 reserved = 34200 blocks used, 47448 blocks available
It can be seen that 0 swap blocks are in use, 34200 have been reserved, but not used, which leaves 47448 blocks available for reservation. So, at this point in time, the system above is not swapping, but the programs running on the system have requested approximately 17 Megabytes of swap space, just in case they will need to grow.

Note: 10000 blocks is approximately equal to 5 Megabytes Many applications reserve what is known as virtual swap space. That is, they request more memory than they will ever need to grow into. The actual size of the application is the amount of physical system resources that the application is utilizing. The virtual size of the application is the amount of system resources it is utilizing plus the amount of extra resources requested but not in use. This is the case in the above example; space has been reserved, but is not in use.


Negative swap space

Let's look at another example of swap -s output:

total: 41920 allocated + 58736 reserved = 100656 blocks used, -19400 blocks available
It may seem worrisome that the swap space available is a negative number. What this means, though, is that some of the allocated/in use pages are located in main memory (RAM). The swap -s output does not take main memory into account. The data that is shown in the negative is actually data that is contained in system memory.

It appears that approximately 20 Megabytes of physical swap space is in use, as shown by the amount of allocated space. Therefore, the system is not out of physical swap space. If there was no more physical swap space, the number of allocated blocks would be very close/the same as to the number of blocks reported by the swap -l command. Approximately 30 additional Megabytes of swap space has been requested, shown by the requested field, giving a total of 50 Megabytes requested and/or in use. This appears to leave us with an overrun of 10 Megabytes.

Another way to think of that negative number is that the negative number is the amount of physical swap space minus the number of blocks used (allocated + requested). So, as long as this total is less negative than approximately the amount of physical memory (obtained from the hinv command) that you have, you have not overrun your system.

The following example shows swap -s output of a system that has most likely come to its swapping limit:

total: 76920 allocated + 23736 reserved = 100656 blocks used, -19400 blocks available
Notice that the total numbers are the same, but the number of allocated blocks is much higher. If the swap -l in this example were to report 81000 blocks of physical swap space on the system, it is easy to see that there are only 4000 physical blocks that are not in use.

If swap -s reports a negative number, increase virtual swap when your system is not near its physical limits. This will allow your system to allocate space to those applications that grab more space than they actually need. To do this you can turn on virtual swapping by executing the following commands:

su 
chkconfig vswap on 
/etc/init.d/swap start 
This will allocate more swap space, or space that can be reserved, but not allocated. Please see the /etc/init.d/swap file and the swap(1M) reference page for more information.

If virtual swapping is already chkconfig'd on or if the number of allocated blocks is approaching the number of blocks reported by the swap -l command, the only way to remedy the situation would be to add more physical memory or swap space. Please see the swap(1M) reference page for more information regarding adding swap space (whether through another disk partition or a swap file).


Next | Prev | Up | Top | Contents | Index