swapon(2) System Calls Manual swapon(2) swapon, swapoff - / / LIBRARY Standard C library (libc, -lc) #include int swapon(const char *path, int swapflags); int swapoff(const char *path); swapon() , path, . swapoff() , path, . swapon() swapflags SWAP_FLAG_PREFER, , . swapflags : (prio << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK swapflags swapon() SWAP_FLAG_DISCARD, (discard) ( ). , , , . . ( CAP_SYS_ADMIN). , . . , , . , swapflags, . ( ). . . , . , , "" . Linux 1.3.6 , . On success, zero is returned. On error, -1 is returned, and errno is set to indicate the error. EBUSY ( swapon()) path . EINVAL path , ; EINVAL (swapon()) , , , tmpfs(5). EINVAL ( Linux 3.4) (swapon()) An invalid flag value was specified in swapflags. EINVAL (swapoff()) path . ENFILE . ENOENT path . ENOMEM . EPERM CAP_SYS_ADMIN. ; . . Linux. The swapflags argument was introduced in Linux 1.3.2. mkswap(8). There is an upper limit on the number of swap files that may be used, defined by the kernel constant MAX_SWAPFILES. Before Linux 2.4.10, MAX_SWAPFILES has the value 8; since Linux 2.4.10, it has the value 32. Since Linux 2.6.18, the limit is decreased by 2 (thus 30), since Linux 5.19, the limit is decreased by 3 (thus: 29) if the kernel is built with the CONFIG_MIGRATION option (which reserves two swap table entries for the page migration features of mbind(2) and migrate_pages(2)). Since Linux 2.6.32, the limit is further decreased by 1 if the kernel is built with the CONFIG_MEMORY_FAILURE option. Since Linux 5.14, the limit is further decreased by 4 if the kernel is built with the CONFIG_DEVICE_PRIVATE option. Since Linux 5.19, the limit is further decreased by 1 if the kernel is built with the CONFIG_PTE_MARKER option. Discard of swap pages was introduced in Linux 2.6.29, then made conditional on the SWAP_FLAG_DISCARD flag in Linux 2.6.36, which still discards the entire swap area when swapon() is called, even if that flag bit is not set. . mkswap(8), swapoff(8), swapon(8) Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 22 2023 . swapon(2)