Thursday, December 17, 2009

Swap Space Management

Types of Swap Space :

1. Device Swap Space :

An entire disk or a partition in a disk or a logical volume in a volume group can be used as swap space. This type is called as device swap.

2. File System Swap Space:

You can allocate a specific amount of space in an existing file system. This will create a directory called paging on that file system. This type of swap space can coexist with the files in the file system. This type is called as file system swap space.

Daemon used to manage memory and swap :
  a. swapper
  b. vhand

Swap Space Priority:

a. There are priority levels from number 0 to 10.
b. Number 0 is the highest and 10 is the lowest level of priority.
c. When the highest priority swap space is full, then the next level swap will be used.
d. If 2 or more swap spaces have the same priority, then the round robin mechanism will be used.
e. If the disk and file system swaps have the same priority, then the disk swap will get the preference.


Let us now look the way to create the swap space,

To create swap space in an entire disk :
# swapon /dev/dsk/c1t2d4

To create swap space in a logical volume :
# swapon /dev/vg01/lvol1

To create swap space in an entire disk with a priority of 2 :
# swapon -p 2 /dev/dsk/c1t2d4

To create a file system swap of size 300MB :
# swapon -l 300M /swapdir

This will create a directory called paging on that file system and puts a maximum limit of 300MB on that swap area.


How to activte all the swap spaces on every reboot ?

For automatic activation of swap spaces, you have to put the entry for each and every swap space in /etc/fstab file. When you reboot the system, /sbin/init.d/swap_start script gets executed in run level 1. This script will execute the below command to activate all the swap spaces.

# swapon -a

Sample /etc/fstab entry for disk based swap space,

/dev/dsk/c0t1d0   .   swap   defaults  0  0

Sample /etc/fstab entry for file system based swap space,

.   /swapdir   swapfs   lim=300M   0   0

How to monitor the swap space ?

"swapinfo" command will show the statistics on device, LV and file system swaps.

To show only the device swap areas,
# swapinfo -d

To show only the file system swap areas,
# swapinfo -f

To show all the device and file system swaps in megabytes instead of kilebytes :
# swapinfo -m

To show all the device and file system swaps with a total details at the last line :
# swapinfo -t

No comments:

Post a Comment