p The .Fa cmd parameter specifies the operation to be performed. The .Fa arg and .Fa misc parameters have different meanings, depending on the .Fa cmd parameter. l -enum -offset indent t If .Fa cmd is .Dv SWAP_NSWAP , the current number of swap devices in the system is returned. The .Fa arg and .Fa misc parameters are ignored. t If .Fa cmd is .Dv SWAP_STATS , the current statistics for swap devices are returned in the .Fa arg parameter. No more than .Fa misc swap devices are returned. The .Fa arg parameter should point to an array of at least .Fa misc struct swapent structures: d -literal 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 */ }; .Ed
p The flags are defined as d -literal 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 .Ed t If .Fa cmd is .Dv SWAP_ON , the .Fa arg parameter is used as a pathname of a file to enable swapping to. The .Fa misc parameter is used to set the priority of this swap device. t If .Fa cmd is .Dv SWAP_OFF , the .Fa arg parameter is used as the pathname of a file to disable swapping from. The .Fa misc parameter is ignored. t If .Fa cmd is .Dv SWAP_CTL , the .Fa arg and .Fa misc parameters have the same function as for the .Dv SWAP_ON case, except that they change the priority of a currently enabled swap device. t If .Fa cmd is .Dv SWAP_DUMPDEV , the .Fa arg parameter is used as the pathname of a device to use as the dump device, should the system panic. t If .Fa cmd is .Dv SWAP_GETDUMPDEV , the .Fa arg parameter points to a dev_t, which is filled in by the current dump device. .El
p 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 .Dv SWAP_ON command is used.
p 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 .Sx SWAP PRIORITY section in .Xr swapctl 8 . .Sh RETURN VALUES If the .Fa cmd parameter is .Dv SWAP_NSWAP or .Dv SWAP_STATS , .Fn swapctl returns the number of swap devices, if successful. The .Dv SWAP_NSWAP command is always successful. Otherwise it returns 0 on success and -1 on failure, setting the global variable .Va errno to indicate the error. .Sh ERRORS .Fn swapctl succeeds unless: l -tag -width Er t Bq Er EACCES Search permission is denied for a component of the path prefix. t Bq Er EBUSY The device specified by .Fa arg has already been made available for swapping. t Bq Er EFAULT .Fa arg points outside the process' allocated address space. t Bq Er EINVAL The device configured by .Fa arg has no associated size, or the .Fa cmd was unknown. t Bq Er EIO An I/O error occurred while opening the swap device. t Bq Er ELOOP Too many symbolic links were encountered in translating the pathname. t Bq Er ENAMETOOLONG A component of a pathname exceeded rq Dv NAME_MAX characters, or an entire path name exceeded rq Dv PATH_MAX characters. t Bq Er ENOENT The named device does not exist. For the .Dv SWAP_CTL command, the named device is not currently enabled for swapping. t Bq Er ENOTDIR A component of the path prefix is not a directory. t Bq Er ENXIO The major device number of .Fa arg is out of range (this indicates no device driver exists for the associated hardware); or the block device specified by .Fa arg is not marked as a swap partition in the disklabel. t Bq Er EPERM The caller is not the super-user. .El .Sh SEE ALSO .Xr swapctl 8 .Sh HISTORY The .Fn swapctl function call appeared in .Nx 1.3 . The .Fa se_path member was added to .Va struct swapent in .Nx 1.4 , when the header file was also moved from n vm/vm_swap.h to its current location in n sys/swap.h . .Sh AUTHORS .An -nosplit The current swap system was designed and implemented by .An Matthew Green Aq Mt mrg (at] eterna23.net , with help from .An Paul Kranenburg Aq Mt pk (at] NetBSD.org and .An Leo Weppelman Aq Mt leo (at] NetBSD.org , and insights from .An Jason R. Thorpe Aq Mt thorpej (at] NetBSD.org .