1SWAPON(2)                  Linux Programmer's Manual                 SWAPON(2)
2
3
4

NAME

6       swapon, swapoff - start/stop swapping to file/device
7

SYNOPSIS

9       #include <unistd.h>
10       #include <asm/page.h> /* to find PAGE_SIZE */
11       #include <sys/swap.h>
12
13       int swapon(const char *path, int swapflags);
14       int swapoff(const char *path);
15

DESCRIPTION

17       swapon()  sets  the  swap area to the file or block device specified by
18       path.  swapoff() stops swapping to the file or block  device  specified
19       by path.
20
21       If  the  SWAP_FLAG_PREFER  flag  is specified in the swapon() swapflags
22       argument, the new swap area will have a higher priority  than  default.
23       The priority is encoded within swapflags as:
24
25           (prio << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK
26
27       If  the  SWAP_FLAG_DISCARD  flag is specified in the swapon() swapflags
28       argument, freed swap pages will be discarded before they are reused, if
29       the  swap  device  supports  the  discard or trim operation.  (This may
30       improve performance on some Solid State  Devices,  but  often  it  does
31       not.)  See also NOTES.
32
33       These  functions  may  be used only by a privileged process (one having
34       the CAP_SYS_ADMIN capability).
35
36   Priority
37       Each swap area has a priority, either high or low.  The default  prior‐
38       ity  is low.  Within the low-priority areas, newer areas are even lower
39       priority than older areas.
40
41       All priorities  set  with  swapflags  are  high-priority,  higher  than
42       default.   They  may  have  any nonnegative value chosen by the caller.
43       Higher numbers mean higher priority.
44
45       Swap pages are allocated from areas in priority order, highest priority
46       first.   For areas with different priorities, a higher-priority area is
47       exhausted before using a lower-priority area.  If  two  or  more  areas
48       have the same priority, and it is the highest priority available, pages
49       are allocated on a round-robin basis between them.
50
51       As of Linux 1.3.6, the kernel usually follows these  rules,  but  there
52       are exceptions.
53

RETURN VALUE

55       On  success,  zero is returned.  On error, -1 is returned, and errno is
56       set appropriately.
57

ERRORS

59       EBUSY  (for swapon()) The specified path is already  being  used  as  a
60              swap area.
61
62       EINVAL The  file  path exists, but refers neither to a regular file nor
63              to a block device; or, for swapon(), the indicated path does not
64              contain  a  valid swap signature or resides on an in-memory file
65              system like tmpfs; or, for swapoff(), path is  not  currently  a
66              swap area.
67
68       ENFILE The  system  limit  on  the  total number of open files has been
69              reached.
70
71       ENOENT The file path does not exist.
72
73       ENOMEM The system has insufficient memory to start swapping.
74
75       EPERM  The caller does not have the CAP_SYS_ADMIN capability.  Alterna‐
76              tively, the maximum number of swap files are already in use; see
77              NOTES below.
78

CONFORMING TO

80       These functions are Linux-specific and should not be used  in  programs
81       intended  to be portable.  The second swapflags argument was introduced
82       in Linux 1.3.2.
83

NOTES

85       The partition or path must be prepared with mkswap(8).
86
87       There is an upper limit on the number of swap files that may  be  used,
88       defined  by  the  kernel constant MAX_SWAPFILES.  Before kernel 2.4.10,
89       MAX_SWAPFILES has the value 8; since kernel 2.4.10, it  has  the  value
90       32.  Since kernel 2.6.18, the limit is decreased by 2 (thus: 30) if the
91       kernel is built with the CONFIG_MIGRATION option  (which  reserves  two
92       swap  table  entries  for  the  page migration features of mbind(2) and
93       migrate_pages(2)).  Since kernel 2.6.32, the limit is further decreased
94       by 1 if the kernel is built with the CONFIG_MEMORY_FAILURE option.
95
96       Discard of swap pages was introduced in kernel 2.6.29, then made condi‐
97       tional on the SWAP_FLAG_DISCARD flag in kernel 2.6.36, which still dis‐
98       cards  the  entire swap area when swapon() is called, even if that flag
99       bit is not set.
100

SEE ALSO

102       mkswap(8), swapoff(8), swapon(8)
103

COLOPHON

105       This page is part of release 3.53 of the Linux  man-pages  project.   A
106       description  of  the project, and information about reporting bugs, can
107       be found at http://www.kernel.org/doc/man-pages/.
108
109
110
111Linux                             2010-11-15                         SWAPON(2)
Impressum