Solved Swap - Is it still really necessary?

Alain De Vos that's one of the things about system resources; it all depends on the workload.
Building ports/systems from source takes up a lot of resources, mostly memory. So it's not unexpected for ports to dip into swap when needed.

Virtual Machines: I think that's a case by case basis. If one is using the VM to say test out new kernels or new drivers that may cause a crash, then swap is useful for the core files. If you are building ports in a VM, it may be useful. General use, it may not be. But it all depends how much RAM is allocated to the VM itself.

My opinions.
your approach is interesting, or even debugging a FreeBSD kernel by hacking the kernel, putting it to run in a VM.
 
  • Like
Reactions: mer
Even swap isn't always enough... I have a 512MB VM with 20GB of SSD and 1.5GB swap (the maximum before FreeBSD 12 complains about too much). Compiling the latest Python version from ports exhausts both memory and swap at the linking stage even after killing almost every process on the system.

Sometimes, depending on the port, simply shutting down to single user mode provides sufficient memory to compile and link successfully.

So, to address the OP, yes swap is still necessary. It is like insurance, you don't need it... until you do!
 
your approach is interesting, or even debugging a FreeBSD kernel by hacking the kernel, putting it to run in a VM.
It's been a while since I've done that and I probably read about it somewhere, but it does work. Of course there are limitations like you may not be able to talk directly to real hardware but it does work for a lot of cases.
 
Just recently, I actually ran into a situation where I needed swap, and still wasn't enough. This is on my machine with 16G of ram, and 10G of swap; and the program(Texstudio) triggered OOM once, and I had to kill it 2 more times when I was monitoring memory usage. Admittedly, I knew before hand the program is terrible on managing memory when viewing large pdf files (the pdf in hand is 31MB of straight text and over 8-9k pages long depending on font used). Normal usage of the program, it is common for memory to exceed 10G when I work on that document. I just happen to run into a case, of toggling a flag causes the program eat more than 20+G of ram.

I do admit, during my normal usage I rarely encounter a situation that my swap ever gets used.
 
I think that on modern systems swap is not needed at all.
But some applications require swap. For example, VirtualBox uses it when copies its HDDs.
Some time ago I tried to use swap on Debian.
I checked how swap is used. Here is my crontab:
Code:
lanin@debian2:~$ sudo crontab -u root -l | tail -n 5
[sudo] password for lanin:
# m h  dom mon dow   command
0-59 * * * * /usr/lib/sysstat/sa1 1 1 -S DISK
0 0 * * * /usr/lib/sysstat/sa1 --rotate
5 19 * * * /usr/lib/sysstat/sa2 -A

and then:
Code:
lanin@debian2:~$ sar -S
Linux 5.10.0-9-amd64 (debian2)     20.10.2021     _x86_64_    (56 CPU)

14:00:01    kbswpfree kbswpused  %swpused  kbswpcad   %swpcad
14:10:01     48827388         0      0,00         0      0,00
14:20:01     48827388         0      0,00         0      0,00
14:30:01     48827388         0      0,00         0      0,00
14:40:01     48827388         0      0,00         0      0,00
14:50:01     48826620       768      0,00        60      7,81
14:59:01     48826620       768      0,00        60      7,81
15:00:01     48826620       768      0,00        60      7,81
15:01:01     48826620       768      0,00         0      0,00
15:02:01     48826620       768      0,00         0      0,00
15:03:01     48826620       768      0,00         0      0,00
15:04:01     48826620       768      0,00         0      0,00
15:05:01     48826620       768      0,00         0      0,00
15:06:01     48826620       768      0,00         0      0,00
15:07:01     48826620       768      0,00         0      0,00
15:08:01     48826620       768      0,00         0      0,00
15:09:01     48826620       768      0,00         0      0,00
15:10:01     48826620       768      0,00         0      0,00
15:11:01     48826620       768      0,00         0      0,00
15:12:01     48826620       768      0,00         0      0,00
15:13:01     48826620       768      0,00         0      0,00
15:14:01     48826620       768      0,00         0      0,00
15:15:01     48826620       768      0,00         0      0,00
15:16:01     48826620       768      0,00         0      0,00
15:17:01     48826620       768      0,00         0      0,00
15:18:01     48826620       768      0,00         0      0,00
15:19:01     48826364      1024      0,00        12      1,17
15:20:01     48826364      1024      0,00        12      1,17
15:21:01     48826364      1024      0,00        12      1,17
15:22:01     48826364      1024      0,00        12      1,17
15:23:01     48826364      1024      0,00        12      1,17
15:24:01     48826364      1024      0,00        12      1,17
15:25:01     48826364      1024      0,00        12      1,17
15:26:01     48826364      1024      0,00        12      1,17
15:27:01     48826108      1280      0,00        16      1,25
15:28:01     48825852      1536      0,00        60      3,91
15:29:01     48825852      1536      0,00        60      3,91
15:30:01     48825852      1536      0,00        60      3,91
15:31:01     48825852      1536      0,00        60      3,91
15:32:01     48825852      1536      0,00        60      3,91
15:33:01     48825852      1536      0,00        60      3,91
15:34:01     48825852      1536      0,00        60      3,91
15:35:01     48825852      1536      0,00        60      3,91
15:36:01     48825852      1536      0,00        60      3,91
15:37:01     48825852      1536      0,00        64      4,17
15:38:01     48825852      1536      0,00        64      4,17
15:39:01     48825852      1536      0,00        64      4,17
15:40:02     48825852      1536      0,00        64      4,17
15:41:01     48825852      1536      0,00        64      4,17
15:42:01     48825852      1536      0,00        64      4,17
15:43:01     48825852      1536      0,00        64      4,17
15:44:01     48825852      1536      0,00        64      4,17
15:45:01     48825852      1536      0,00        64      4,17
15:46:01     48825852      1536      0,00        64      4,17
15:47:01     48825852      1536      0,00        64      4,17
15:48:01     48825852      1536      0,00        64      4,17
15:49:01     48825852      1536      0,00        64      4,17
15:50:01     48825852      1536      0,00        64      4,17
15:51:01     48825852      1536      0,00        64      4,17
15:52:01     48825852      1536      0,00        64      4,17
15:53:01     48825852      1536      0,00        64      4,17
15:54:01     48825852      1536      0,00        64      4,17
15:55:01     48825852      1536      0,00        64      4,17
15:56:01     48825852      1536      0,00        64      4,17
15:57:01     48825852      1536      0,00        64      4,17
15:58:01     48825852      1536      0,00        64      4,17
15:59:01     48825852      1536      0,00        64      4,17
16:00:01     48825852      1536      0,00        64      4,17
16:01:01     48825852      1536      0,00        64      4,17
16:02:01     48825852      1536      0,00        64      4,17
16:03:01     48825852      1536      0,00        64      4,17
16:04:01     48825852      1536      0,00        64      4,17
16:05:01     48825852      1536      0,00        64      4,17
16:06:01     48825852      1536      0,00        60      3,91
16:07:01     48825852      1536      0,00        60      3,91
16:08:01     48825852      1536      0,00        60      3,91
16:09:01     48825852      1536      0,00        60      3,91
16:10:01     48825852      1536      0,00        60      3,91
16:11:01     48825852      1536      0,00        60      3,91
16:12:01     48825852      1536      0,00        60      3,91
16:13:01     48825852      1536      0,00        60      3,91
16:14:01     48825852      1536      0,00        60      3,91
16:15:01     48825852      1536      0,00        60      3,91
16:16:01     48825852      1536      0,00        60      3,91
16:17:01     48825852      1536      0,00        60      3,91
16:18:01     48825852      1536      0,00        60      3,91
16:19:01     48825852      1536      0,00        60      3,91
16:20:01     48825852      1536      0,00        60      3,91
16:21:01     48825852      1536      0,00        60      3,91
16:22:01     48825852      1536      0,00        60      3,91
16:23:01     48825852      1536      0,00        60      3,91
16:24:01     48825852      1536      0,00        60      3,91
16:25:01     48825852      1536      0,00        60      3,91
16:26:01     48825852      1536      0,00        60      3,91
16:27:01     48825852      1536      0,00        60      3,91
16:28:01     48825852      1536      0,00        60      3,91
16:29:01     48825852      1536      0,00        60      3,91
16:30:01     48825852      1536      0,00        60      3,91
16:31:01     48825852      1536      0,00        60      3,91
16:32:01     48825852      1536      0,00        60      3,91
16:33:01     48825852      1536      0,00        60      3,91
16:34:01     48825852      1536      0,00        60      3,91
16:35:01     48825852      1536      0,00        60      3,91
16:36:01     48825852      1536      0,00        60      3,91
16:37:01     48825852      1536      0,00        60      3,91
16:38:01     48825852      1536      0,00        60      3,91
16:39:01     48825852      1536      0,00        60      3,91
16:40:01     48825852      1536      0,00        60      3,91
16:41:01     48825852      1536      0,00        60      3,91
16:42:01     48825852      1536      0,00        60      3,91
16:43:01     48825852      1536      0,00        60      3,91
16:44:01     48825852      1536      0,00        60      3,91
16:45:01     48825852      1536      0,00        60      3,91
16:46:01     48825852      1536      0,00        60      3,91
16:47:01     48825852      1536      0,00        60      3,91
16:48:01     48825852      1536      0,00        60      3,91
16:49:01     48825852      1536      0,00        60      3,91
16:50:02     48825852      1536      0,00        60      3,91
16:51:01     48825852      1536      0,00        60      3,91
16:52:01     48825852      1536      0,00        60      3,91
16:53:01     48825852      1536      0,00        60      3,91
16:54:01     48825852      1536      0,00        60      3,91
16:55:01     48825852      1536      0,00        60      3,91
16:56:01     48825852      1536      0,00        60      3,91
16:57:01     48825852      1536      0,00        60      3,91
16:58:01     48825852      1536      0,00        60      3,91
16:59:01     48825852      1536      0,00        60      3,91
17:00:01     48825852      1536      0,00        60      3,91
17:01:01     48825852      1536      0,00        60      3,91
17:02:01     48825852      1536      0,00        60      3,91
17:03:01     48825852      1536      0,00        60      3,91
17:04:01     48825852      1536      0,00        60      3,91
17:05:01     48825852      1536      0,00        60      3,91
17:06:01     48825852      1536      0,00        60      3,91
17:07:01     48825852      1536      0,00        60      3,91
17:08:01     48825852      1536      0,00        60      3,91
17:09:01     48825852      1536      0,00        60      3,91
17:10:01     48825852      1536      0,00        60      3,91
17:11:01     48825852      1536      0,00        60      3,91
17:12:01     48825852      1536      0,00        60      3,91
17:13:01     48825852      1536      0,00        60      3,91
17:14:01     48825852      1536      0,00        60      3,91
17:15:01     48825852      1536      0,00        60      3,91
17:16:01     48825852      1536      0,00        60      3,91
17:17:01     48825852      1536      0,00        60      3,91
17:18:01     48825852      1536      0,00        60      3,91
17:19:01     48825852      1536      0,00        60      3,91
17:20:01     48825852      1536      0,00        60      3,91
17:21:01     48825852      1536      0,00        60      3,91
17:22:01     48825852      1536      0,00        60      3,91
17:23:01     48825852      1536      0,00        60      3,91
17:24:01     48825852      1536      0,00        60      3,91
17:25:01     48825852      1536      0,00        60      3,91
17:26:01     48825852      1536      0,00        60      3,91
17:27:01     48825852      1536      0,00        60      3,91
17:28:01     48825852      1536      0,00        60      3,91
17:29:01     48825852      1536      0,00        60      3,91
17:30:01     48825852      1536      0,00        60      3,91
17:31:01     48825852      1536      0,00        60      3,91
17:32:01     48825852      1536      0,00        60      3,91
17:33:01     48825852      1536      0,00        60      3,91
17:34:01     48825852      1536      0,00        60      3,91
17:35:01     48825852      1536      0,00        60      3,91
17:36:01     48825852      1536      0,00        60      3,91
17:37:01     48825852      1536      0,00        60      3,91
17:38:01     48825852      1536      0,00        60      3,91
17:39:01     48825852      1536      0,00        60      3,91
17:40:01     48825852      1536      0,00        60      3,91
17:41:01     48825852      1536      0,00        60      3,91
17:42:01     48825852      1536      0,00        60      3,91
17:43:01     48825852      1536      0,00        60      3,91
17:44:01     48825852      1536      0,00        60      3,91
17:45:01     48825852      1536      0,00        60      3,91
17:46:01     48825852      1536      0,00        60      3,91
17:47:01     48825852      1536      0,00        60      3,91
17:48:01     48825852      1536      0,00        60      3,91
17:49:01     48825852      1536      0,00        60      3,91
17:50:01     48825852      1536      0,00        60      3,91
17:51:01     48825852      1536      0,00        60      3,91
17:52:01     48825852      1536      0,00        60      3,91
17:53:01     48825852      1536      0,00        60      3,91
17:54:01     48825852      1536      0,00        60      3,91
17:55:01     48825852      1536      0,00        60      3,91
17:56:01     48825852      1536      0,00        60      3,91
17:57:01     48825852      1536      0,00        60      3,91
17:58:01     48825852      1536      0,00        60      3,91
17:59:01     48825852      1536      0,00        60      3,91
18:00:01     48825852      1536      0,00        60      3,91
18:01:01     48825852      1536      0,00        60      3,91
18:02:02     48825852      1536      0,00        60      3,91
18:03:01     48825852      1536      0,00        60      3,91
18:04:01     48825852      1536      0,00        60      3,91
18:05:01     48825852      1536      0,00        60      3,91
18:06:01     48825852      1536      0,00        60      3,91
18:07:01     48825852      1536      0,00        60      3,91
18:08:01     48825852      1536      0,00        60      3,91
18:09:01     48825852      1536      0,00        60      3,91
18:10:01     48825852      1536      0,00        60      3,91
18:11:01     48825852      1536      0,00        60      3,91
18:12:01     48825852      1536      0,00        60      3,91
18:13:01     48825852      1536      0,00        60      3,91
18:14:01     48825852      1536      0,00        60      3,91
18:15:01     48825852      1536      0,00        60      3,91
18:16:01     48825852      1536      0,00        60      3,91
18:17:01     48825852      1536      0,00        60      3,91
18:18:01     48825852      1536      0,00        60      3,91
18:19:01     48825852      1536      0,00        60      3,91
18:20:01     48825852      1536      0,00        60      3,91
18:21:01     48825852      1536      0,00        60      3,91
18:22:01     48825852      1536      0,00        60      3,91
18:23:01     48825852      1536      0,00        60      3,91
18:24:01     48825852      1536      0,00        60      3,91
18:25:01     48825852      1536      0,00        60      3,91
18:26:01     48825852      1536      0,00        60      3,91
Average:     48825977      1411      0,00        52      3,71

I.e. almost never used.
 
I was using the double physical ram rule of thumb back in the Sun SPARCstation days (1989). Disk space and physical memory are cheap, crash recovery without swap isn't. I agree with swap being a just in case backstop. A well designed server probably will hardly touch swap space, but it gives me a smart fire alarm or panic button if something goes south. Throw in VMs and testing and I can see swap being used. If you report a bug, the person working on your bug may want the crash data in the swap file. Swap is a like condom, better to have it and not need it then wish you had it then have to rebuild your system again with swap space so you can help catch that bug or gremlin and to get rid of it once and for all.

I've been burning in my excellent barn eBay find of a Lenovo Thinkserver RD230. I've done a make buildworld on FreeBSD 13.1 to test staged upgrades. The server will be maxed up with the fastest Lenovo recommended Xeon CPUs (X5675) and 64 GB of RAM. Even with only 16 GB of RAM and the Xeon X5603 it originally came with, it wasn't breathing hard. It was pretty much yawning doing a make buildworld very efficiently with CPU and memory resources.
 
Back
Top