The
swapctl function is used to add and delete swap devices, and modify their configuration.
The
cmd parameter specifies the operation to be performed. The
arg and
misc parameters have different meanings, depending on the
cmd parameter.
1.
If cmd is SWAP_NSWAP, the current number of swap devices in the system is returned. The arg and misc parameters are ignored.
2.
If
cmd is
SWAP_STATS, the current statistics for swap devices are returned in the
arg parameter. No more than
misc swap devices are returned. The
arg parameter should point to an array of at least
misc struct swapent structures:
struct swapent {
dev_t se_dev; /* device id */
int se_flags; /* entry flags */
int se_nblks; /* total blocks */
int se_inuse; /* blocks in use */
int se_priority; /* priority */
char se_path[PATH_MAX+1]; /* path to entry */
};
The flags are defined as
SWF_INUSE in use: we have swapped here
SWF_ENABLE enabled: we can swap here
SWF_BUSY busy: I/O happening here
SWF_FAKE fake: still being built
3.
If cmd is SWAP_ON, the arg parameter is used as a pathname of a file to enable swapping to. The misc parameter is used to set the priority of this swap device.
4.
If cmd is SWAP_OFF, the arg parameter is used as the pathname of a file to disable swapping from. The misc parameter is ignored.
5.
If cmd is SWAP_CTL, the arg and misc parameters have the same function as for the SWAP_ON case, except that they change the priority of a currently enabled swap device.
6.
If cmd is SWAP_DUMPDEV, the arg parameter is used as the pathname of a device to use as the dump device, should the system panic.
7.
If cmd is SWAP_GETDUMPDEV, the arg parameter points to a dev_t, which is filled in by the current dump device.
When swapping is enabled on a block device, the first portion of the disk is left unused to prevent any disklabel present from being overwritten. This space is allocated from the swap device when the
SWAP_ON command is used.
The priority of a swap device can be used to fill faster swap devices before slower ones. A priority of 0 is the highest, with larger numbers having lower priority. For a fuller discussion on swap priority, see the
SWAP PRIORITY section in
swapctl(8).