Blame man2/swapon.2

Packit 7cfc04
.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified by Michael Haardt <michael@moria.de>
Packit 7cfc04
.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
Packit 7cfc04
.\" Modified 1995-07-22 by Michael Chastain <mec@duracef.shout.net>
Packit 7cfc04
.\" Modified 1995-07-23 by aeb
Packit 7cfc04
.\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
Packit 7cfc04
.\" Modified 1998-09-08 by aeb
Packit 7cfc04
.\" Modified 2004-06-17 by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\" Modified 2004-10-10 by aeb
Packit 7cfc04
.\" 2004-12-14 mtk, Anand Kumria: added new errors
Packit 7cfc04
.\" 2007-06-22 Ivana Varekova <varekova@redhat.com>, mtk
Packit 7cfc04
.\"     Update text describing limit on number of swap files.
Packit 7cfc04
.\"
Packit 7cfc04
.\" FIXME Linux 3.11 added SWAP_FLAG_DISCARD_ONCE and SWAP_FLAG_DISCARD_PAGES
Packit 7cfc04
.\"	commit dcf6b7ddd7df8965727746f89c59229b23180e5a
Packit 7cfc04
.\"	Author: Rafael Aquini <aquini@redhat.com>
Packit 7cfc04
.\"	Date:   Wed Jul 3 15:02:46 2013 -0700
Packit 7cfc04
.\"
Packit 7cfc04
.TH SWAPON 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
swapon, swapoff \- start/stop swapping to file/device
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.B #include <unistd.h>
Packit 7cfc04
.br
Packit 7cfc04
.B #include <sys/swap.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int swapon(const char *" path ", int " swapflags );
Packit 7cfc04
.br
Packit 7cfc04
.BI "int swapoff(const char *" path );
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.BR swapon ()
Packit 7cfc04
sets the swap area to the file or block device specified by
Packit 7cfc04
.IR path .
Packit 7cfc04
.BR swapoff ()
Packit 7cfc04
stops swapping to the file or block device specified by
Packit 7cfc04
.IR path .
Packit 7cfc04
.PP
Packit 7cfc04
If the
Packit 7cfc04
.B SWAP_FLAG_PREFER
Packit 7cfc04
flag is specified in the
Packit 7cfc04
.BR swapon ()
Packit 7cfc04
.I swapflags
Packit 7cfc04
argument, the new swap area will have a higher priority than default.
Packit 7cfc04
The priority is encoded within
Packit 7cfc04
.I swapflags
Packit 7cfc04
as:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
.I "(prio << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK"
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
If the
Packit 7cfc04
.B SWAP_FLAG_DISCARD
Packit 7cfc04
flag is specified in the
Packit 7cfc04
.BR swapon ()
Packit 7cfc04
.I swapflags
Packit 7cfc04
argument, freed swap pages will be discarded before they are reused,
Packit 7cfc04
if the swap device supports the discard or trim operation.
Packit 7cfc04
(This may improve performance on some Solid State Devices,
Packit 7cfc04
but often it does not.)
Packit 7cfc04
See also NOTES.
Packit 7cfc04
.PP
Packit 7cfc04
These functions may be used only by a privileged process (one having the
Packit 7cfc04
.B CAP_SYS_ADMIN
Packit 7cfc04
capability).
Packit 7cfc04
.SS Priority
Packit 7cfc04
Each swap area has a priority, either high or low.
Packit 7cfc04
The default priority is low.
Packit 7cfc04
Within the low-priority areas,
Packit 7cfc04
newer areas are even lower priority than older areas.
Packit 7cfc04
.PP
Packit 7cfc04
All priorities set with
Packit 7cfc04
.I swapflags
Packit 7cfc04
are high-priority, higher than default.
Packit 7cfc04
They may have any nonnegative value chosen by the caller.
Packit 7cfc04
Higher numbers mean higher priority.
Packit 7cfc04
.PP
Packit 7cfc04
Swap pages are allocated from areas in priority order,
Packit 7cfc04
highest priority first.
Packit 7cfc04
For areas with different priorities,
Packit 7cfc04
a higher-priority area is exhausted before using a lower-priority area.
Packit 7cfc04
If two or more areas have the same priority,
Packit 7cfc04
and it is the highest priority available,
Packit 7cfc04
pages are allocated on a round-robin basis between them.
Packit 7cfc04
.PP
Packit 7cfc04
As of Linux 1.3.6, the kernel usually follows these rules,
Packit 7cfc04
but there are exceptions.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success, zero is returned.
Packit 7cfc04
On error, \-1 is returned, and
Packit 7cfc04
.I errno
Packit 7cfc04
is set appropriately.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EBUSY
Packit 7cfc04
(for
Packit 7cfc04
.BR swapon ())
Packit 7cfc04
The specified
Packit 7cfc04
.I path
Packit 7cfc04
is already being used as a swap area.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
The file
Packit 7cfc04
.I path
Packit 7cfc04
exists, but refers neither to a regular file nor to a block device;
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.RB ( swapon ())
Packit 7cfc04
The indicated path does not contain a valid swap signature or
Packit 7cfc04
resides on an in-memory filesystem such as
Packit 7cfc04
.BR tmpfs (5).
Packit 7cfc04
.TP
Packit 7cfc04
.BR EINVAL " (since Linux 3.4)"
Packit 7cfc04
.RB ( swapon ())
Packit 7cfc04
An invalid flag value was specified in
Packit 7cfc04
.IR flags .
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.RB ( swapoff ())
Packit 7cfc04
.I path
Packit 7cfc04
is not currently a swap area.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENFILE
Packit 7cfc04
The system-wide limit on the total number of open files has been reached.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOENT
Packit 7cfc04
The file
Packit 7cfc04
.I path
Packit 7cfc04
does not exist.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOMEM
Packit 7cfc04
The system has insufficient memory to start swapping.
Packit 7cfc04
.TP
Packit 7cfc04
.B EPERM
Packit 7cfc04
The caller does not have the
Packit 7cfc04
.B CAP_SYS_ADMIN
Packit 7cfc04
capability.
Packit 7cfc04
Alternatively, the maximum number of swap files are already in use;
Packit 7cfc04
see NOTES below.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
These functions are Linux-specific and should not be used in programs
Packit 7cfc04
intended to be portable.
Packit 7cfc04
The second
Packit 7cfc04
.I swapflags
Packit 7cfc04
argument was introduced in Linux 1.3.2.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
The partition or path must be prepared with
Packit 7cfc04
.BR mkswap (8).
Packit 7cfc04
.PP
Packit 7cfc04
There is an upper limit on the number of swap files that may be used,
Packit 7cfc04
defined by the kernel constant
Packit 7cfc04
.BR MAX_SWAPFILES .
Packit 7cfc04
Before kernel 2.4.10,
Packit 7cfc04
.B MAX_SWAPFILES
Packit 7cfc04
has the value 8;
Packit 7cfc04
since kernel 2.4.10, it has the value 32.
Packit 7cfc04
Since kernel 2.6.18, the limit is decreased by 2 (thus: 30)
Packit 7cfc04
if the kernel is built with the
Packit 7cfc04
.B CONFIG_MIGRATION
Packit 7cfc04
option
Packit 7cfc04
(which reserves two swap table entries for the page migration features of
Packit 7cfc04
.BR mbind (2)
Packit 7cfc04
and
Packit 7cfc04
.BR migrate_pages (2)).
Packit 7cfc04
Since kernel 2.6.32, the limit is further decreased by 1
Packit 7cfc04
if the kernel is built with the
Packit 7cfc04
.B CONFIG_MEMORY_FAILURE
Packit 7cfc04
option.
Packit 7cfc04
.PP
Packit 7cfc04
Discard of swap pages was introduced in kernel 2.6.29,
Packit 7cfc04
then made conditional
Packit 7cfc04
on the
Packit 7cfc04
.B SWAP_FLAG_DISCARD
Packit 7cfc04
flag in kernel 2.6.36,
Packit 7cfc04
.\" To be precise: 2.6.35.5
Packit 7cfc04
which still discards the
Packit 7cfc04
entire swap area when
Packit 7cfc04
.BR swapon ()
Packit 7cfc04
is called, even if that flag bit is not set.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR mkswap (8),
Packit 7cfc04
.BR swapoff (8),
Packit 7cfc04
.BR swapon (8)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.