296 lines
6.3 KiB
HTML
296 lines
6.3 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of SWAPON</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>SWAPON</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
swapon, swapoff - start/stop swapping to file/device
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>></B>
|
|
|
|
<BR>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/sys/swap.h">sys/swap.h</A>></B>
|
|
|
|
<P>
|
|
|
|
<B>int swapon(const char *</B><I>path</I><B>, int </B><I>swapflags</I><B>);</B>
|
|
|
|
<BR>
|
|
|
|
<B>int swapoff(const char *</B><I>path</I><B>);</B>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>swapon</B>()
|
|
|
|
sets the swap area to the file or block device specified by
|
|
<I>path</I>.
|
|
|
|
<B>swapoff</B>()
|
|
|
|
stops swapping to the file or block device specified by
|
|
<I>path</I>.
|
|
|
|
<P>
|
|
|
|
If the
|
|
<B>SWAP_FLAG_PREFER</B>
|
|
|
|
flag is specified in the
|
|
<B>swapon</B>()
|
|
|
|
<I>swapflags</I>
|
|
|
|
argument, the new swap area will have a higher priority than default.
|
|
The priority is encoded within
|
|
<I>swapflags</I>
|
|
|
|
as:
|
|
<P>
|
|
|
|
|
|
|
|
<I>(prio << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK</I>
|
|
|
|
|
|
|
|
<P>
|
|
|
|
If the
|
|
<B>SWAP_FLAG_DISCARD</B>
|
|
|
|
flag is specified in the
|
|
<B>swapon</B>()
|
|
|
|
<I>swapflags</I>
|
|
|
|
argument, freed swap pages will be discarded before they are reused,
|
|
if the swap device supports the discard or trim operation.
|
|
(This may improve performance on some Solid State Devices,
|
|
but often it does not.)
|
|
See also NOTES.
|
|
<P>
|
|
|
|
These functions may be used only by a privileged process (one having the
|
|
<B>CAP_SYS_ADMIN</B>
|
|
|
|
capability).
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Priority</H3>
|
|
|
|
Each swap area has a priority, either high or low.
|
|
The default priority is low.
|
|
Within the low-priority areas,
|
|
newer areas are even lower priority than older areas.
|
|
<P>
|
|
|
|
All priorities set with
|
|
<I>swapflags</I>
|
|
|
|
are high-priority, higher than default.
|
|
They may have any nonnegative value chosen by the caller.
|
|
Higher numbers mean higher priority.
|
|
<P>
|
|
|
|
Swap pages are allocated from areas in priority order,
|
|
highest priority first.
|
|
For areas with different priorities,
|
|
a higher-priority area is exhausted before using a lower-priority area.
|
|
If two or more areas have the same priority,
|
|
and it is the highest priority available,
|
|
pages are allocated on a round-robin basis between them.
|
|
<P>
|
|
|
|
As of Linux 1.3.6, the kernel usually follows these rules,
|
|
but there are exceptions.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success, zero is returned.
|
|
On error, -1 is returned, and
|
|
<I>errno</I>
|
|
|
|
is set appropriately.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="1"><B>EBUSY</B>
|
|
|
|
<DD>
|
|
(for
|
|
<B>swapon</B>())
|
|
|
|
The specified
|
|
<I>path</I>
|
|
|
|
is already being used as a swap area.
|
|
<DT id="2"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
The file
|
|
<I>path</I>
|
|
|
|
exists, but refers neither to a regular file nor to a block device;
|
|
<DT id="3"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
(<B>swapon</B>())
|
|
|
|
The indicated path does not contain a valid swap signature or
|
|
resides on an in-memory filesystem such as
|
|
<B><A HREF="/cgi-bin/man/man2html?5+tmpfs">tmpfs</A></B>(5).
|
|
|
|
<DT id="4"><B>EINVAL</B> (since Linux 3.4)
|
|
|
|
<DD>
|
|
(<B>swapon</B>())
|
|
|
|
An invalid flag value was specified in
|
|
<I>flags</I>.
|
|
|
|
<DT id="5"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
(<B>swapoff</B>())
|
|
|
|
<I>path</I>
|
|
|
|
is not currently a swap area.
|
|
<DT id="6"><B>ENFILE</B>
|
|
|
|
<DD>
|
|
The system-wide limit on the total number of open files has been reached.
|
|
<DT id="7"><B>ENOENT</B>
|
|
|
|
<DD>
|
|
The file
|
|
<I>path</I>
|
|
|
|
does not exist.
|
|
<DT id="8"><B>ENOMEM</B>
|
|
|
|
<DD>
|
|
The system has insufficient memory to start swapping.
|
|
<DT id="9"><B>EPERM</B>
|
|
|
|
<DD>
|
|
The caller does not have the
|
|
<B>CAP_SYS_ADMIN</B>
|
|
|
|
capability.
|
|
Alternatively, the maximum number of swap files are already in use;
|
|
see NOTES below.
|
|
</DL>
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
These functions are Linux-specific and should not be used in programs
|
|
intended to be portable.
|
|
The second
|
|
<I>swapflags</I>
|
|
|
|
argument was introduced in Linux 1.3.2.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The partition or path must be prepared with
|
|
<B><A HREF="/cgi-bin/man/man2html?8+mkswap">mkswap</A></B>(8).
|
|
|
|
<P>
|
|
|
|
There is an upper limit on the number of swap files that may be used,
|
|
defined by the kernel constant
|
|
<B>MAX_SWAPFILES</B>.
|
|
|
|
Before kernel 2.4.10,
|
|
<B>MAX_SWAPFILES</B>
|
|
|
|
has the value 8;
|
|
since kernel 2.4.10, it has the value 32.
|
|
Since kernel 2.6.18, the limit is decreased by 2 (thus: 30)
|
|
if the kernel is built with the
|
|
<B>CONFIG_MIGRATION</B>
|
|
|
|
option
|
|
(which reserves two swap table entries for the page migration features of
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mbind">mbind</A></B>(2)
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?2+migrate_pages">migrate_pages</A></B>(2)).
|
|
|
|
Since kernel 2.6.32, the limit is further decreased by 1
|
|
if the kernel is built with the
|
|
<B>CONFIG_MEMORY_FAILURE</B>
|
|
|
|
option.
|
|
<P>
|
|
|
|
Discard of swap pages was introduced in kernel 2.6.29,
|
|
then made conditional
|
|
on the
|
|
<B>SWAP_FLAG_DISCARD</B>
|
|
|
|
flag in kernel 2.6.36,
|
|
|
|
which still discards the
|
|
entire swap area when
|
|
<B>swapon</B>()
|
|
|
|
is called, even if that flag bit is not set.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?8+mkswap">mkswap</A></B>(8),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?8+swapoff">swapoff</A></B>(8),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?8+swapon">swapon</A></B>(8)
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="10"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="11"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="12"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="13"><A HREF="#lbAE">Priority</A><DD>
|
|
</DL>
|
|
<DT id="14"><A HREF="#lbAF">RETURN VALUE</A><DD>
|
|
<DT id="15"><A HREF="#lbAG">ERRORS</A><DD>
|
|
<DT id="16"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="17"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DT id="18"><A HREF="#lbAJ">SEE ALSO</A><DD>
|
|
<DT id="19"><A HREF="#lbAK">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:34 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|