Swap

In the Linux/Unix world, the term swap is generally used as a synonym for memory paging. Swap Article description::refers to both the act of moving memory pages between RAM and disk and the allocated space on the disk itself.

Linux can use any combination of swap partition and/or swap files together; however swap space may not be necessary depending on the necessary requirements for the system in question. For example, a laptop that will be suspending to disk (hibernation) requires all pages in memory to be stored to disk, so swap is necessary in this case. Server systems equipped with large amount of memory and running at a constant load might not require swap at all. For further details, see the dedicated Knowledge Base article.

Swap partition
As best practice, the Gentoo Handbook recommends, as part of the installation process, creating a swap partition with a size of twice the available system memory.

Swap partitions can be created and activated at any time as long as partitions are available and formatted correctly.

Creation
Presuming is the partition available to be used for swap:

Review the activated swaps with the command:

To avoid manually activating the swap file across reboots, append a line (adjusting the path as necessary) to :

Swap files
In order to work around the more ridged constraints of disk partitions, an alternative is to use swap as an on-disk file. Files have the ability to be located inside disk partitions. This allows the system administrator the flexibility to resize or move the swap space as necessary to meet the demands of the system without having to open a partitioning tool.

Creation
The first step in creating a swap file is to allocate a file of the target swap size. Several standard utilities can be used for this purpose. (part of will suffice for this example

Review the system swaps with the command:

To avoid manually activating the swap file across reboots, append a line (adjusting the path as necessary) to :

OpenRC configuration
When using swap files, the service ordering in OpenRC should be changed via :

External resources

 * Upstream kernel.org documentation on swap suspend - https://www.kernel.org/doc/html/latest/power/swsusp.html#swap-suspend