Hacker News new | ask | show | jobs
by csdtx 1984 days ago
Just getting into FreeBSD and reading through the Absolute FreeBSD book right now. Remembered that Michael states "The main use for swap on modern systems is to have a place to store a memory dump should the system panic and crash."

I think this is reason enough to enable swap even if you do not plan on using swap for system memory. It's always nice to have a memory dump if the system crashes so you can check what the issue was and correct it. If you wouldn't want to fix those kinds of issues why would you be running FreeBSD anyway?

4 comments

You might be right if you are running some sort of experimental FreeBSD system, where for some reason you expect crashes.

On the other hand, I have run continuously, 24/7, for almost 20 years a FreeBSD server without any swap and without ever seeing any crash or panic. In my opinion the swap is useless and it is better to just install enough physical memory.

I reboot that system just once a year or so, for a kernel update or a hardware upgrade.

I run on it a large number of services, mostly Internet related, e.g. firewall, router, NTP server, DNS server for outside, DNS resolver for the internal network, e-mail server, Web server, Web proxy, file server.

Swap is not meant to enable you to escape the memory demands of your workload. If your workload requires more physical memory than you have, then swap will probably not help you.

However just because your software allocates data in memory doesn't mean it needs to be there. Rarely used memory could be swapped out to cache more frequently used files on disk instead, increasing the overall throughput of the system. This could be true whether or not you have an excess of physical memory for your workload.

I've been running freebsd my primary home and work platforms for almost 20 years and the only time I've had crashes that would have dumped to swap were when I was doing some driver development for early flash storage cards and a few times with the early ZFS merges.

None of my FreeBSD systems have swapped anything out in years. Most of the VMs get half gig of "I guess it might by used by something" swap space.

Somewhat ironically NVME would be insanely good for historical swap use cases but anything that cares about performance hasn't swapped in the better part of a decade.

> If you wouldn't want to fix those kinds of issues why would you be running FreeBSD anyway?

Because it's a stable, robust, feature rich system, and I'm happy to benefit from that without being an OS developer.

I think that another good reason to enable swap is if you use a memory filesystem for /tmp (e.g. tmpfs). /tmp tends to accumulate garbage, so it is nice to have the system page out files that are still present but effectively no more needed
Doesn't swap adversely impact the longevity of one's solid state drive?
Only if it's used.

Not being facetious -- if you operate entirely within RAM (as if you had disabled swap), then it won't really be used much.

For linux this is not (always) true. How about FreeBSD? Any sources?
The article says "It is thus common to see moderate swap space usage even when plenty of free memory is available", with an explanation above. So it sounds like it's not always true for FreeBSD either.
The notion there is that at some point in the past free memory was scarce, so the kernel swapped out some pages, and that swap space may still be in use long after the shortage is alleviated. FreeBSD won't swap anything out unless there's a shortage of free pages.
You can set the swapiness of both systems if you want for it to be true. Modern SSDs won’t last a second longer without a swap and now a days of swap files there’s really no excuse to not have one.
I don't think this is realistically an issue unless you have heavy server workloads which constantly blow the memory ceiling of your node and then hammer it hard. Hammering it as in actually actively writing and reading from the pages of memory in swap, which is also difficult as MRU pages are should be kept in RAM. At that point you really should be monitoring it and stick some more memory in it anyway. For end users desktops and laptops it'd be pretty hard to kill a (quality) drive dead in under 10 years at the moment based on longevity estimates even with some swap usage.

This is one reason I went with an 8Gb RAM Mac recently. If I go into swap territory occasionally it's not really a big issue. As yet as a terminal node, which is what it really is, I barely ever touch swap even with a ton of things open.

If swap can reduce the overall amount of disk I/O through more effective use of memory for disk caching, then it might actually increase longevity of SSD drives.