SWAPON(2)
π SWAPON(2) π β from the System Calls Manual, bestie
okay so literally put your phone down for two secs because we're doing a whole system call today and it's giving main character energy. this is SWAPON(2), it lives in the System Calls Manual, and it's about swapon and swapoff β the two lil' functions that control devices for interleaved paging/swapping. yes bestie, paging AND swapping. both. iconic. π«Ά
π¦ NAME π¦
swapon, swapoff β control devices for interleaved paging/swapping
π LIBRARY π
Standard C Library (libc, -lc). yeah she's linked against -lc, no cap π
β¨ SYNOPSIS β¨
#include <unistd.h>
int
swapon(const char *special);
int
swapoff(const char *special);
like, that's it. two functions. two ints. so clean β¨
πΈ DESCRIPTION πΈ
The swapon() system call makes the block device special available to the system for allocation for paging and swapping. the way that it just hands the whole device overβ¦ π The names of potentially available devices are known to the system and defined at system configuration time. The size of the swap area on special is calculated at the time the device is first made available for swapping. like, first time only. that's when the math happens πβ¨
The swapoff() system call disables paging and swapping on the given device. All associated swap metadata are deallocated, and the device is made available for other purposes. she's freed. she's unbothered. she's available for other purposes π
π RETURN VALUES π
If an error has occurred, a value of -1 is returned and errno is set to indicate the error. so if you see -1, that's not a vibe, that's an error code bestie π go read errno.
π₯ ERRORS π₯
Both swapon() and swapoff() can fail if:
[ENOTDIR]β A component of the path prefix is not a directory. rude of it honestly π[ENAMETOOLONG]β A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. that's a LOT of characters, like calm down β[ENOENT]β The named device does not exist. it's giving nothing. it's giving nowhere π«₯[EACCES]β Search permission is denied for a component of the path prefix. locked out π[ELOOP]β Too many symbolic links were encountered in translating the pathname. symlink chain that never ends, no ma'am π[EPERM]β The caller is not the super-user. bestie you are NOT root. sit down π[EFAULT]β Thespecialargument points outside the process's allocated address space. that pointer is in the void, babes π»
Additionally, swapon() can fail for the following reasons:
[ENOTBLK]β Thespecialargument is not a block device. wrong kind of device, she said no π[EBUSY]β The device specified byspecialhas already been made available for swapping. she's already booked and busy β¨[ENXIO]β The major device number ofspecialis out of range (this indicates no device driver exists for the associated hardware). no driver, no service π«[EIO]β An I/O error occurred while opening the swap device. the hardware said "i'm tired" π[EINTEGRITY]β Corrupted data was detected while reading from the file system to open the swap device. corrupted data detected, that's a whole crime scene π¨
Lastly, swapoff() can fail if:
[EINVAL]β The system is not currently swapping tospecial. you can't turn off something that was never on, bestie π«[ENOMEM]β Not enough virtual memory is available to safely disable paging and swapping to the given device. not enough virtual memory to safely do the thing β and yes, "safely" is doing a LOT of work in that sentence, so take it seriously π₯
π SEE ALSO π
config(8), swapon(8), sysctl(8) β go read these next, iykyk πβ¨
π HISTORY π
The swapon() system call appeared in 4.0BSD. The swapoff() system call appeared in FreeBSD 5.0. legacy behavior honestly, we love a glow-up π
okay that's the whole page bestie, you ATE it π this one's from the Debian crew, dated March 30, 2020 β go forth and swap responsibly, mwah π
β¨π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1980, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms