Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nowadays it is the inverse. Is there ever a good reason to enable it? Most devices run on TLC or other fast wearing flash, and swapping there is both expensive in terms of durability loss, as well as still much slower than just having enough RAM.

I think my only device with swap is my Mac laptop and it is relatively conservative when it swaps, unlike Linux with default settings.



> Is there ever a good reason to enable it?

Yes. It's a rare system that it shouldn't be enabled.

RAM is a precious resource. It's highly likely programs will allocate RAM that won't be used for days at a time. For example, if you are using docker once the containers are started the management daemon does nothing. If you have ssh enabled only for maintenance it unlikely to be used for days if not weeks on end. If your system starts gettys they are unlikely to be used, ever. The bulk of the init system probably isn't used once the system is started.

All those things belong in swap. The RAM they occupied can be used as disk cache. Extra disk cache will speed up things you are doing now. Notice this means most of the posts here are wrong - just having swap actually gives you a speed boost.

One argument here is that disabling swap provides you an early warning system you need more RAM. That's true, but there is a saner option. Swap is only a problem if the memory stored there is being used frequently. How do you monitor that? You look at reads from swap. If the steady state of the system is showing no reads from swap, you aren't using what's there, so it can't possibly have a negative speed impact. But if swap is being used and isn't being read from, it's freed some RAM so it is having a positive speed impact.

One final observation: the metric "swap should be twice the size of RAM" isn't so helpful nowadays. There aren't a lot of programs that sit around doing nothing. Maybe 1GB or so, and it's more or less fixed regardless of what the system is doing. Old systems didn't have 2GB of RAM, so the "twice RAM" rule made sense. But now a laptop might have 16GB. If you are using 32GB of swap and not reading from it would be a very, very unusual setup. If you are reading from that 32GB or swap, you're system is RAM starved and will be dog slow. You need to add RAM until those reads drop to 0.


The best modern reason to have as much swap as RAM is to make hibernation to disk more reliable, but a lot of people don't use that anymore. It's more reliable because the kernel doesn't have to work as hard to find space to write the system image to.


> One final observation: the metric "swap should be twice the size of RAM" isn't so helpful nowadays

Remembered when I thought "if double is recommended, four times should be even better!". It was not.

Nowadays I don't use swap because I rarely run out of RAM, it sits there eating a few precious GB of SSD, largely unused. The rare cases when I run out of RAM have been buggy Steam games on Proton. In 2024, it has been only "The Invincible", and that game has reports of running out of memory on Windows too.


But why do you have swap on with default settings?


They don't. They said their "only device with swap is my Mac laptop", so they have swap off in their Linux machines.

If your question was "why not keep swap on and change the default swap-iness settings", if keeping it totally off works fine for them, why bother?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: