Swap is a space on a drive used by the operating system when RAM (random access memory) is full. When RAM no longer has enough space to store data from running applications, the system will move some data that is not used frequently from RAM to swap. This helps the operating system avoid "lack of memory" and maintain the operation of applications.
Swap can be set up as:
| Criteria | Swap partition | Swap file |
|---|---|---|
| Performance | Slightly better on older (small) systems. | Performance is comparable on modern systems. |
| Easy to manage size | Hard to change (must resize partition). | Easy to resize by editing files. |
| Configuration | Requires pre-created partition. | Can be created at any time on an existing partition. |
| Resource usage | Occupies a fixed partition, cannot be used for other purposes. | Only occupies space when created and activated. |
| Flexibility | Not flexible. | Flexible, easy to create/delete swap file. |
| Supports snapshots or backups | Cannot be easily backed up (unless backing up the entire disk). | Can be backed up to the same partition containing the swap file. |
Separate from main data:
Increased stability on old systems:
Stable performance:
Better security:
Swap files are easy to create, delete and resize without editing disk partitions.
No need to reboot the system or use partitioning tools.
Use swap partition:
When installing the system from scratch and want to separate swap from data partition.
If you use an old operating system, or need high and stable swap performance on old hardware.
Use swap file:
When you don't want to edit the partition or need to change the swap size frequently.
When the system is already installed and there is no swap partition before.
If you need the flexibility to create or delete swap in a short time.