Is "swap" still necessary/relevant?

No need. You can create a file with dd and swap on that. It won't do for crash dumps, but you can do that.
 
Just spinning up a new instance of FreeBSD 14 on a VM. The Guided UFS disk set-up using the entire disk has reserved 3.8GB out of a 120GB disk for swap.

Usually I go in and manually delete this. I realise it's a luxury but most of my kit has 16GB of RAM, and VMs are given 8GB of RAM (I run one at a time, as just a desktop user)

Is swap still necessary in this day and age? I can understand having a memory overflow is helpful but perhaps these days it's a bit redundant, unless there is some other use for swap that I'm not aware of, in which case I'd appreciate the learnings.

Thanks
What kind of workload to you want to run on the machine? That will tell you whether you should or should not have swap.

For example, databases should almost never swap to disk. Especially oracle SGA (shared memory) as it's used as a disk cache. Swapping a disk cache to disk is simply stupid.

Interactive workloads can tolerate paging. The rule of thumb there is to never spend more than 5% of your system resources satisfying paging requests. Memory paged out and never used (read back in) again can remain on swap. Whereas active paging will affect performance, and this can only be addressed by adding RAM.

If you're inclined to us a system without swap space, be aware that OOM will bite you. If OTOH you have a desktop system with 128 GB RAM you'll probably never need swap. But if you plan to build large ports such as chromium or llvm while, especially simultaneously, you might need swap. This is because your buffer cache (UFS cache or ZFS ARC) will likely push pages not ever used to auxiliary storage.

The other thing to think about is SSD. Paging to SSD will over time increase the rate of SSD wear compared to not paging. In that regard you may not want to configure swap space. In this scenario I'd recommend allocating the partition and only using it, i.e. swapon, when needed. I typically do that with my laptop when not at home, as when I am at home my laptop will automatically add swap on an external ZFS volume when it finds it -- the best of both worlds.

Long story short, it depends on your workload and what your expectations are.
 
This is 19 hours into building Chromium and dependencies from ports. Frustrating that I can't have that extra 4GB space back.
You should remove some RAM.

Code:
Mem: 350M Active, 6153M Inact, 1676M Laundry, 28G Wired, 601M Buf, 10G Free
ARC: 21G Total, 18G MFU, 1409M MRU, 784K Anon, 1068M Header, 1526M Other
     17G Compressed, 81G Uncompressed, 4.64:1 Ratio
Swap: 40G Total, 754M Used, 39G Free, 1% Inuse

When this one builds llvm for different targets in four distinct bhyve on 20 cores, paging is between 20 and 30G with occasionally 100M/sec moving in and out.

What You do is like running an empty truck and complaining that it has oversized brakes.
 
  • Like
Reactions: cy@
Is swap still necessary in this day and age? I can understand having a memory overflow is helpful but perhaps these days it's a bit redundant, unless there is some other use for swap that I'm not aware of, in which case I'd appreciate the learnings.
I have a bit of swap setup for my system to use and it's pretty much needed for the things I do. Without swap I have to reboot my system if I try to work on too big of files, especially when video editing.

20240103_14h14m16s_grim.png

Although this has been working well for a while, I am starting to work with more high quality footage, so I will be getting another 4 SSDs soon. I think that most desktop systems should have some swap as headroom even if no multimedia work is being done on them.
 
Long story short, it depends on your workload and what your expectations are.
Yeah, amen to that. I'm just a desktop user. Running on SSD. I didn't think of swapoff, I guess I can just comment the entry in /etc/fstab. I'm quite happy for it to crash for OOM, I don't think with my uses it'll ever get there. Chromium is my biggest resource hog. I'm not a tab hoarder ever, I've never seen the machine go over 4GB of RAM usage. I'm frankly surprised and impressed that the memory usage is so low after compiling Chromium for so long. Good job devs!

My impression was from previous comments in this thread that even when the memory isn't topped out, data is being "swapped" between swap and memory. If this is the case, I'd really like to prevent this (safely).

Imagine the scenario a few years down the line when these current Apple Silicon Macbooks with soldered RAM and onboard SSD storage finally get cracked and can run BSD/Linux systems, if that is the case, these NAND chips are gonna die fast! (probably will anyway!)

I have a bit of swap setup for my system to use and it's pretty much needed for the things I do.

Forgive my curiosity, what hardware are you running? Could you not add more RAM? Is that a Raspberry Pi or something?
 
what hardware are you running? Could you not add more RAM? Is that a Raspberry Pi or something?
I have a Dell PowerEdge R750XA with 2 Intel Xeon Silver 4309Y. I bought it directly from Dell. I only have 8GB instead of 16GB because one of the RAM sticks fell out during shipping and damaged the pins of the slot, although I can recommend, been pretty solid overall with FreeBSD on it.
 
Yeah, amen to that. I'm just a desktop user. Running on SSD. I didn't think of swapoff, I guess I can just comment the entry in /etc/fstab. I'm quite happy for it to crash for OOM, I don't think with my uses it'll ever get there. Chromium is my biggest resource hog. I'm not a tab hoarder ever, I've never seen the machine go over 4GB of RAM usage.
That is ok. Normal desktop operation does not use so much RAM. Mine is running fine with 8G - I have another 8G here, but there is no need to insert them.
My impression was from previous comments in this thread that even when the memory isn't topped out, data is being "swapped" between swap and memory. If this is the case, I'd really like to prevent this (safely).
That doesn't normally happen, and even if it would happen, it's harmless. The only bad thing I have seen is if the disk that does the swapping has cable problems. There is no mirroring on the swap device. Normally a cable problem is also harmless, because the mirror will catch it, but when it concerns swap, the system does crash.
 
Back
Top