NAME [Toc] [Back]
swapon - enable device or file system for paging
SYNOPSIS [Toc] [Back]
/usr/sbin/swapon -a [-u] [-t type]...
/usr/sbin/swapon [-e |-f] [-p priority] [-u] device ...
/usr/sbin/swapon [-m min] [-l limit] [-r reserve] [-p priority]
Obsolescent Form [Toc] [Back]
/usr/sbin/swapon directory [min limit reserve priority]
DESCRIPTION [Toc] [Back]
The swapon command enables devices or file systems on which paging is
to take place. (NOTE: the term `swap' refers to an obsolete
implementation of virtual memory; HP-UX actually implements virtual
memory by way of paging rather than swapping. This command and others
retain names derived from `swap' for historical reasons.)
By enabling a device for paging, the device can be accessed directly
(without going through the file system) during paging activity. When
a file system is enabled for paging, the device(s) on which the file
system resides are accessed indirectly through the file system. There
are advantages and disadvantages to both type of paging. Keep the
following tradeoffs in mind when enabling devices or file systems for
Paging directly to a device is significantly faster than doing so
through the file system. However, the space on the device that is
allocated to paging cannot be used for anything else, even if it is
not being actively used for paging.
Paging through a file system, while slower, provides a more efficient
use of the space on the device. Space that is not being used for
paging in this case can be used by the file system. Paging across a
network to a remote machine is always file system paging.
The system begins by paging on only a single device so that only one
disk is required at bootstrap time. Calls to swapon normally occur in
the system startup script /sbin/init.d/swap_start making all paging
space available so that the paging activity is interleaved across
Normally, the -a argument is given, causing all devices marked as swap
and all file systems marked as swapfs in the file /etc/fstab to be
made available to the paging system. By using the fields in
/etc/fstab (special_file_name or directory; see fstab(4)), the system
determines which block device or file system to use. The
Hewlett-Packard Company - 1 - HP-UX 11i Version 2: Sep 2004
special_file_name specified for each swap entry must specify a block
special file. The directory specified for each swapfs entry must
specify a directory within the file system to be enabled.
The second form of swapon enables individual block devices to be used
for paging. The device name must specify a block special file. If
more than one device is given, any options specified will be applied
to all devices. If a file system exists on the specified block device
and neither an -e nor -f option is specified, swapon fails and an
error message is given. This prevents a file system from being
inadvertently destroyed. To request paging in the space between the
end of the file system and the end of the device, use -e. To force
paging to a device containing a file system (destroying the file
system), the -f option can be used. Use this with extreme caution!
In either of the previous forms, an attempt to enable paging to a
device will fail and a warning message will be issued if swapon
determines that the device is being used by the savecrash command to
retrieve system dump information (see savecrash(1M)). The -u option
can be used to forcibly enable paging to devices being used by
savecrash; however, this may overwrite system dump information
contained on the device.
The last two forms of swapon provide two different methods for
enabling file systems for paging. The third form is the preferred
method, with the fourth being provided only for backward
compatibility. The directory name specifies a directory on the file
system that is to be enabled for paging. A directory named /paging is
created at the root of the specified file system (unless the file
system's name ends with /paging). All paging files are created within
this directory. The optional arguments to the fourth form have the
same meaning as the arguments to the options in the third form. Note
that, in the fourth form, if any of the optional arguments are
specified, all must be specified. In the third form, if more than one
directory is given, any options specified will be applied to all
After a file system has been enabled for paging, the optional
arguments can be modified by subsequent swapon commands.
Options [Toc] [Back]
swapon recognizes the following options and arguments:
-a Cause all devices marked as swap and all file
systems marked as swapfs in the file /etc/fstab to
be made available to the paging system. The
options field in /etc/fstab entries is read by
swapon, and must contain elements formatted as
Hewlett-Packard Company - 2 - HP-UX 11i Version 2: Sep 2004
min=min See the -m option for the value of
lim=limit See the -l option for the value of
limit. (File system paging areas
res=reserve See the -r option for the value of
reserve. (File system paging areas
pri=priority See the -p option for the value of
priority. (File system paging
end See the -e option for the meaning
of this option. (Device paging
See fstab(4) for an example entry.
-e Use space after the end of the file system on the
block device for paging. An error message is
returned if no file system is found on the device.
This option cannot be used with the -f option. Do
not confuse this with paging to a file system.
This option is for use with a disk that has both a
file system and dedicated paging space on it.
-f Force the device to be enabled, which will destroy
the file system on it. Use with extreme caution.
Normally, if a file system exists on the device to
be enabled, swapon fails and displays an error
message. This option cannot be used with the -e
-l limit limit specifies the maximum space the paging
system is allowed to take from the disk, provided
space is available that is not reserved for
exclusive use by the file system. The value of
limit is rounded up so that it is a multiple of
the paging allocation chunk size, which is set
with the kernel tunable parameter swchunk (see
swchunk(5), kctune(1M), and swapinfo(1M)). See
WARNINGS. The default value for limit is 0,
indicating there is no limit to the amount of file
system space the paging system can use.
limit can be specified in decimal (no prefix),
octal (0 prefix), or hexadecimal (0x prefix). It
may be specified in units of kilobytes (k suffix),
Hewlett-Packard Company - 3 - HP-UX 11i Version 2: Sep 2004
megabytes (M suffix), or file system blocks (no
suffix). (A kilobyte is 1024 bytes; a megabyte is
1024 kilobytes; the size of a file system block is
determined by the administrator when the file
system is created.)
-m min min indicates the space the paging system will
initially take from the file system. The value of
min is rounded up so that it is a multiple of the
paging allocation chunk size, which is set with
the kernel tunable parameter swchunk (see
swchunk(5), kctune(1M), and swapinfo(1M)). The
default value for min is 0, indicating no paging
space is to be allocated initially. min can be
specified in the same forms as limit, above.
-p priority priority indicates the order in which space is
taken from the file systems and devices used for
paging. Space is taken from the systems with
lower priority numbers first. Under most
circumstances, space is taken from device paging
areas before file system paging areas, regardless
of priority. See "Paging Allocation" in
swapinfo(1M) for more information. priority can
have a value from 0 to 10 and has a default value
-r reserve reserve specifies the space, in addition to the
space currently occupied by the file system, that
is reserved for file system use only, making it
unavailable to the paging system. This reserved
space is in addition to the minimum free space
specified by the administrator when the file
system was created. See WARNINGS. The default
value for reserve is 0 indicating that no file
system space is reserved for file system use only.
reserve can be specified in the same forms as
-t type Restrict the type of the paging area. If the -t
option is omitted, all of the paging areas defined
in /etc/fstab are made available. type can have
one of the following values:
dev Device paging areas.
fs File system paging areas.
local Paging areas defined on the local
Hewlett-Packard Company - 4 - HP-UX 11i Version 2: Sep 2004
remote Paging areas defined on remote systems.
-u Unlock block device files which are being used by
the savecrash command. Normally, swapon will not
enable paging on a device if it is being used by
savecrash to retrieve system dump information.
The list of devices in use is maintained in the
file /etc/savecrash.LCK. This option forces the
device to be enabled, which may overwrite any
system dump information contained on the device.
This option should be used with extreme caution.
RETURN VALUE [Toc] [Back]
swapon returns one of the following values:
0 Successful completion.
>0 An error condition occurred.
EXAMPLES [Toc] [Back]
The first two examples enable paging to the file system containing the
/paging directory. The maximum number of file system blocks available
to the paging system is set to 5000, the number of file system blocks
reserved for file system use only is set to 10000, and the priority is
set to 2. The number of file system blocks initially taken by the
paging system defaults to 0 in the first example, and is set to 0 in
the second example. On a file system with the default 8kB block size,
these examples allocate approximately 40MB of file system paging.
/usr/sbin/swapon -l 5000 -r 10000 -p 2 /paging
/usr/sbin/swapon /paging 0 5000 10000 2
This example enables paging to two block devices and sets the priority
of both devices to 0.
/usr/sbin/swapon -p 0 /dev/dsk/c10t0d0 /dev/dsk/c13t0d0
This example enables paging to a block device, using the space after
the end of the file system for paging and letting the priority default
/usr/sbin/swapon -e /dev/dsk/c4t0d0
This example enables paging to a block device, forcing paging even if
a file system exists on the device.
/usr/sbin/swapon -f /dev/dsk/c12t0d0
WARNINGS [Toc] [Back]
On systems running VxVM 3.5, the swap volumes to be configured for
system crash dumps should be created with the usage type as swap
during the creation of the swap volume. Not doing so will cause dump
Hewlett-Packard Company - 5 - HP-UX 11i Version 2: Sep 2004
corruption. You could use the -U option of vxassist(1M) to do the
Once file system blocks have been allocated for paging space, the file
system cannot be unmounted unless the system is rebooted.
If any paging area becomes unavailable while the system is running,
for example if a network failure occurs while paging to a remote
system, the system will immediately halt.
The file system block size used by the -l, -m, and -r options varies
between file systems, and is defined by the system administrator at
the time the file system is created. The dumpfs command can be used
to determine the block size for a particular file system (see
When using the -l and -r options, the reserve space specified by the
-r option takes precedence over the -l option. Thus, if:
D = Total disk space available to ordinary users
R = Reserve space specified by the -r option
limit = Paging space limit specified by the -l option
L = Space currently available to the paging system
F = Space currently occupied by the file system
the following relationships hold:
F + R + limit < D In normal operation
L = 0 If F + R >= D
0 <= L <= limit If F + R + limit >= D
FILES [Toc] [Back]
/dev/dsk/ccardttargetddevice Normal paging devices
/etc/fstab File system table
/etc/savecrash.LCK List of devices being used by
AUTHOR [Toc] [Back]
swapon was developed by HP and the University of California, Berkeley.
SEE ALSO [Toc] [Back]
kctune(1M), savecrash(1M), swapinfo(1M), vxassist(1M), swapon(2),
Hewlett-Packard Company - 6 - HP-UX 11i Version 2: Sep 2004 [ Back ]