System Administration Guide: Basic Administration

Adding More Swap Space

As system configurations change and new software packages are installed, you might need to add more swap space. The easiest way to add more swap space is to use the mkfile and swap commands to designate a part of an existing UFS or NFS file system as a supplementary swap area. These commands, described in the following sections, enable you to add more swap space without repartitioning a disk.

Alternative ways to add more swap space are to repartition an existing disk or add another disk. For information on how to repartition a disk, see Chapter 31, Managing Disks (Overview).

Creating a Swap File

The following general steps are involved in creating a swap file:

The mkfile Command

The mkfile command creates a file that is suitable for use as either an NFS-mounted or a local swap area. The sticky bit is set, and the file is filled with zeros. You can specify the size of the swap file in bytes (the default) or in Kbytes, blocks, or Mbytes by using the k, b, or m suffixes, respectively.

The following table shows the mkfile command options.

Table 41–2 Options to the mkfile Command

Option 

Description 

-n

Creates an empty file. The size is noted, but the disk blocks are not allocated until data is written to them. 

-v

Reports the names and sizes of created files. 


Caution – Caution –

Use the -n option only when you create an NFS swap file.


How to Create a Swap File and Make It Available

  1. Become superuser.

    You can create a swap file without root permissions. However, to avoid accidental overwriting, root should be the owner of the swap file.

  2. Create a directory for the swap file, if needed.

  3. Create the swap file.


    # mkfile nnn[k|b|m] filename
    

    The swap file of the size nnn (in Kbytes, bytes, or Mbytes) and filename you specify is created.

  4. Activate the swap file.


    # /usr/sbin/swap -a /path/filename
    

    You must use the absolute path name to specify the swap file. The swap file is added and available until the file system is unmounted, the system is rebooted, or the swap file is removed. Keep in mind that you can't unmount a file system while some process or program is swapping to the swap file.

  5. Add an entry for the swap file to the /etc/vfstab file that specifies the full path name of the file, and designates swap as the file system type, as follows:


    /path/filename   -      -       swap     -     no     -
  6. Verify that the swap file is added.


    $ /usr/sbin/swap -l
    

Example—Creating a Swap File and Making It Available

The following examples shows how to create a 100–Mbyte swap file called /files/swapfile.


# mkdir /files
# mkfile 100m /files/swapfile
# swap -a /files/swapfile
# vi /etc/vfstab
(An entry is added for the swap file):
/files/swapfile   -      -       swap     -     no     -
# swap -l
swapfile             dev  swaplo blocks   free
/dev/dsk/c0t0d0s1   136,1      16 1638608 1600528
/files/swapfile        -       16 204784  204784