Next: User Accounts, Previous: Mapped Devices, Up: System Configuration [Contents][Index]
Swap space, as it is commonly called, is a disk area specifically designated for paging: the process in charge of memory management (the Linux kernel or Hurd’s default pager) can decide that some memory pages stored in RAM which belong to a running program but are unused should be stored on disk instead. It unloads those from the RAM, freeing up precious fast memory, and writes them to the swap space. If the program tries to access that very page, the memory management process loads it back into memory for the program to use.
A common misconception about swap is that it is only useful when small amounts of RAM are available to the system. However, it should be noted that kernels often use all available RAM for disk access caching to make I/O faster, and thus paging out unused portions of program memory will expand the RAM available for such caching.
For a more detailed description of how memory is managed from the viewpoint of a monolithic kernel, See Memory Concepts in The GNU C Library Reference Manual.
The Linux kernel has support for swap partitions and swap files: the former uses a whole disk partition for paging, whereas the second uses a file on a file system for that (the file system driver needs to support it). On a comparable setup, both have the same performance, so one should consider ease of use when deciding between them. Partitions are “simpler” and do not need file system support, but need to be allocated at disk formatting time (logical volumes notwithstanding), whereas files can be allocated and deallocated at any time.
Note that swap space is not zeroed on shutdown, so sensitive data (such as passwords) may linger on it if it was paged out. As such, you should consider having your swap reside on an encrypted device (see Mapped Devices).
Objects of this type represent swap spaces. They contain the following members:
target
The device or file to use, either a UUID, a file-system-label
or
a string, as in the definition of a file-system
(see File Systems).
dependencies
(default: '()
)A list of file-system
or mapped-device
objects, upon which
the availability of the space depends. Note that just like for
file-system
objects, dependencies which are needed for boot and
mounted in early userspace are not managed by the Shepherd, and so
automatically filtered out for you.
priority
(default: #f
)Only supported by the Linux kernel. Either #f
to disable swap
priority, or an integer between 0 and 32767. The kernel will first use
swap spaces of higher priority when paging, and use same priority spaces
on a round-robin basis. The kernel will use swap spaces without a set
priority after prioritized spaces, and in the order that they appeared in
(not round-robin).
discard?
(default: #f
)Only supported by the Linux kernel. When true, the kernel will notify the disk controller of discarded pages, for example with the TRIM operation on Solid State Drives.
Here are some examples:
(swap-space (target (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
Use the swap partition with the given UUID. You can learn the UUID of a
Linux swap partition by running swaplabel device
, where
device is the /dev file name of that partition.
(swap-space (target (file-system-label "swap")) (dependencies mapped-devices))
Use the partition with label swap
, which can be found after all
the mapped-devices mapped devices have been opened. Again, the
swaplabel
command allows you to view and change the label of a
Linux swap partition.
Here’s a more involved example with the corresponding file-systems
part
of an operating-system
declaration.
(file-systems (list (file-system (device (file-system-label "root")) (mount-point "/") (type "ext4")) (file-system (device (file-system-label "btrfs")) (mount-point "/btrfs") (type "btrfs")))) (swap-devices (list (swap-space (target "/btrfs/swapfile") (dependencies (filter (file-system-mount-point-predicate "/btrfs") file-systems)))))
Use the file /btrfs/swapfile as swap space, which depends on the file system mounted at /btrfs. Note how we use Guile’s filter to select the file system in an elegant fashion!
Next: User Accounts, Previous: Mapped Devices, Up: System Configuration [Contents][Index]