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       swapon()   takes   a   swapflags   argument.    If  swapflags  has  the
22       SWAP_FLAG_PREFER bit turned on, the new swap area will  have  a  higher
23       priority than default.  The priority is encoded within swapflags as:
24
25           (prio << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK
26
27       These  functions  may  only be used by a privileged process (one having
28       the CAP_SYS_ADMIN capability).
29

PRIORITY

31       Each swap area has a priority, either high or low.  The default  prior‐
32       ity  is low.  Within the low-priority areas, newer areas are even lower
33       priority than older areas.
34
35       All priorities  set  with  swapflags  are  high-priority,  higher  than
36       default.   They  may  have any non-negative value chosen by the caller.
37       Higher numbers mean higher priority.
38
39       Swap pages are allocated from areas in priority order, highest priority
40       first.   For areas with different priorities, a higher-priority area is
41       exhausted before using a lower-priority area.  If  two  or  more  areas
42       have the same priority, and it is the highest priority available, pages
43       are allocated on a round-robin basis between them.
44
45       As of Linux 1.3.6, the kernel usually follows these  rules,  but  there
46       are exceptions.
47

RETURN VALUE

49       On  success,  zero is returned.  On error, -1 is returned, and errno is
50       set appropriately.
51

ERRORS

53       EBUSY  (for swapon()) The specified path is already  being  used  as  a
54              swap area.
55
56       EINVAL The  file  path exists, but refers neither to a regular file nor
57              to a block device; or, for swapon(), the indicated path does not
58              contain  a  valid swap signature; or, for swapoff(), path is not
59              currently a swap area.
60
61       ENFILE The system limit on the total number  of  open  files  has  been
62              reached.
63
64       ENOENT The file path does not exist.
65
66       ENOMEM The system has insufficient memory to start swapping.
67
68       EPERM  The  caller  does not have the CAP_SYS_ADMIN capability.  If all
69              swapfiles are in use.  (If CONFIG_MIGRATION is enabled then  the
70              maximal  number of swap files is MAX_SWAPFILES-2 (30 since linux
71              2.4.10), otherwise MAX_SWAPFILES (32 since Linux 2.4.10, 8  ear‐
72              lier) swap files could be used)
73

CONFORMING TO

75       These  functions  are Linux specific and should not be used in programs
76       intended to be portable.  The second swapflags argument was  introduced
77       in Linux 1.3.2.
78

NOTES

80       The partition or path must be prepared with mkswap(8).
81

SEE ALSO

83       mkswap(8), swapoff(8), swapon(8)
84
85
86
87Linux 2.6.7                       2004-10-10                         SWAPON(2)
Impressum