Adding Swap to Linux⚓︎
Overview⚓︎
In Chris Down’s In defence of swap blog post he explains the importance of swap and that it is still best practice to add swap to systems and not depend on memory alone.
When a system runs out of memory and does not have swap, or does have swap but it is in full use, you can add a temp swap to get yourself out of a tight spot if you have a local volume with free space.
Process of Adding Temp Swap⚓︎
Bash | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
Common Issues⚓︎
When using fallocate
on some file systems the file will be created with ‘holes’. See the man swapon
for more information.
If you receive the following error you likely have holes in the swap file.
swapon: /tmp/tmp_swap: swapon failed: Invalid argument
Check journalctl
for ‘swapon’ to confirm this finding.
kernel: swapon: swapfile has holes
To work around this use dd
as shown above.