Configuring Swap Space in Solaris

The swap command provides a method of adding, deleting, and monitoring the swap areas used by the kernel. Swap area changes made from the command line are not permanent and are lost after a reboot. To create permanent additions to the swap space, create an entry in the /etc/vfstab file. The entry in the /etc/vfstab file is added to the swap space at each reboot.

Displaying the Current Swap Configuration

The image shows the relationship between the used swap space, which consists of allocated and reserved swap spaces, and the available swap space.


To view the current swap space allocation, complete the following steps:

  1. List a summary of the system’s virtual swap space.

    # swap -s
    total: 41776k bytes allocated + 5312k reserved =
    	47088k used, 881536k available
    
  2. List the details of the system’s physical swap areas.

    # swap -l
    swapfile             dev  swaplo blocks   free
    /dev/dsk/c0t0d0s1   136,9      16 1048304 1048304

Adding Swap Space

When the swap space requirements of the system exceed the current swap space available, you can use the following procedures to add additional swap space to your system.

Adding Swap Slices

To add a swap slice, complete the following steps:

  1. Edit the /etc/vfstab file to add information describing the swap slice.

    # vi /etc/vfstab
    #device      device      mount     FS     fsck    mount     mount
    #to mount    to fsck     point     type   pass    at boot   options
    ...
    
  2. Add the following line to create the swap slice.

    /dev/dsk/c1t3d0s1       -       -       swap    -       no      -
    
  3. Use the swap -a command to add additional swap area.

    # swap -a /dev/dsk/c1t3d0s1

Adding Swap Files

To add a swap file, complete the following steps:

  1. Identify a file system that has adequate space to create an additional swap file, preferably on another drive.
  2. Make a directory to hold the swap file.

    # mkdir -p /usr/local/swap
    
  3. Create a 20-Mbyte swap file named swapfile in the /usr/local/swap directory.

    # mkfile 20m /usr/local/swap/swapfile
    
  4. Add the swap file to the system’s swap space.

    # swap -a /usr/local/swap/swapfile 
    
  5. List the details of the modified system swap space.

    # swap -l
    swapfile             dev  swaplo blocks   free
    /dev/dsk/c0t0d0s1   136,9      16 1048304 1048304
    /usr/local/swap/swapfile  -       16  40944  40944
    
  6. List a summary of the modified system swap space.

    # swap -s
    total: 41672k bytes allocated + 5416k reserved = 47088k used, 901200k available
    
  7. To use a swap file when the system is subsequently rebooted, add an entry for the swap file in the /etc/vfstab file.

    # vi /etc/vfstab
    #device     device     mount     FS      fsck    mount     mount
    #to mount   to fsck    point     type    pass    at boot   options
    ...
    /usr/local/swap/swapfile	 -	  -	   swap	   -	  no	  -

Removing Swap Space

If you no longer need the additional swap space, you can delete the swap space by removing the additional swap slices and swap files.

Removing Swap Slices

To remove a swap slice, complete the following steps:

  1. Delete a swap slice from the current swap configuration.

    # swap -d /dev/dsk/c1t3d0s1
    
  2. To prevent the swap slice from being configured as part of the swap configuration during a reboot or change of run level, edit the /etc/vfstab file, and remove the swap slice entry from the file.

Removing Swap Files

To remove a swap file, complete the following steps:

  1. Delete a swap file from the current swap configuration.

    # swap -d /usr/local/swap/swapfile
  2. Remove the file to free the disk space that it is occupying.

    # rm /usr/local/swap/swapfile
  3. To prevent the swap file from being configured as part of the swap configuration during a reboot or change of run level, edit the /etc/vfstab file, and remove the swap file entry.


Leave a Comment

Your email address will not be published. Required fields are marked *

CAPTCHA * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top