Live data from Hacker News

In defence of swap: common misconceptions

chrisdown.name

41–50 of 151 posts

Re: In defence of swap: common misconceptions

#41

In defence against swap on my personal computer: -PCs have a lot of RAM now -When you allocate that much memory it's usually a bug in your own code like a size_t that overflowed. I never saw programs I would actually want to use try to allocate that much -When using swap instead of ram, everything becomes so slow that you're screwed anyway. The UI doesn't even respond fast enough to kill whatever tries to use all tha…

Regarding the complexity of making an extra partition: I completely agree, having a separate partition for swap is annoying. Luckily, Linux supports swap files; all my systems (where I had to manually set up swap), I just create a file called /swapfile.

I imagine this would solve the full disk encryption complexity too.

Re: In defence of swap: common misconceptions

#42
For many years now I use ram compression instead of swap for desktops/laptops. I particularly like zram but zswap is also great if you you are hitting hardware limits.

The difference with swap is that the computer doesn't get unresponsive, it just slows down a bit. And Ram compression still buys some time before OOM killer hits.

Re: In defence of swap: common misconceptions

#43

In defence against swap on my personal computer: -PCs have a lot of RAM now -When you allocate that much memory it's usually a bug in your own code like a size_t that overflowed. I never saw programs I would actually want to use try to allocate that much -When using swap instead of ram, everything becomes so slow that you're screwed anyway. The UI doesn't even respond fast enough to kill whatever tries to use all tha…

Exactly! Also, the person who goes from 32G of RAM to 256G of RAM is going to run without swap.

Re: In defence of swap: common misconceptions

#44

Swap was a great idea, but its time is gone. Swap doesn't make sense anymore, hard drives have not scaled and kept up with the improvements in RAM. In the Pentium 1 era EDO RAM maxed out at 256MB/s and hard disk xfer was 10MB/s. Common RAM size was 16MB. In today's era DDR4 maxes out at 32GB/s and hard disk xfer is 500 MB/s. Common RAM size is 16GB. RAM xfer rate has grown is 320x. RAM capacity has grown 100x. Disk x…

32GB/s is 128× 256MB/s, not 320×, and 16GB is 1024× 16MB. The latter, I think, is the reason swap has gotten less useful. It seems even modern programmers don’t know what to do with all that RAM (possibly because, at top speed, it takes 8 times as long to fill it all up (about 20 times as long if the data has to come from a hard disk)

Re: In defence of swap: common misconceptions

#45

> Under temporary spikes in memory usage > With swap: We’re more resilient to temporary spikes, but in cases of severe memory starvation, the period from memory thrashing beginning to the OOM killer may be prolonged. We have more visibility into the instigators of memory pressure and can act on them more reasonably, and can perform a controlled intervention. Somehow that doesn't resonate with my experience. I tend to…

Swap iotime quotas maybe? I suspect the solution is a lot more complicated though - what I really want is a way to wall off my UI so it stays responsive during swap thrashing and let's me react to the situation.

Re: In defence of swap: common misconceptions

#46
post #5

All of this boils down to "because buying more disk is cheaper than buying more RAM" and "avoid memory contention." The author discusses the situation as if the quantity of RAM is fixed and swap can be added (or not). But that isn't the only possibility — you can also add more RAM (it's just expensive). For the same number of GB of RAM+swap vs just RAM, there is no reason to prefer the option with swap.

> you can also add more RAM (it's just expensive)

Or just impossible

Many laptops still have remarkably low maximum-RAM limits. The ones I have here ( Dell SME & corporate types ) are 4GB and 8GB. I live in constant fear of the solid-blue disk-access lamp.

And when I boot-up after a swap-thrash I am scolded for an unclean shutdown :(

Re: In defence of swap: common misconceptions

#47

Swap was a great idea, but its time is gone. Swap doesn't make sense anymore, hard drives have not scaled and kept up with the improvements in RAM. In the Pentium 1 era EDO RAM maxed out at 256MB/s and hard disk xfer was 10MB/s. Common RAM size was 16MB. In today's era DDR4 maxes out at 32GB/s and hard disk xfer is 500 MB/s. Common RAM size is 16GB. RAM xfer rate has grown is 320x. RAM capacity has grown 100x. Disk x…

The purpose of swap is not running things out of it. The purpose is shoveling unused data out of memory. And for that it doesn't need to be particularly fast. Swap has a lot less purpose in a world without memory leaks and extraneous functions. But in practice it's quite good at getting several gigabytes of unnecessary data out of the way, so ram can be used properly. Swap, well-used, should only take up a few percen…

> The purpose of swap is not running things out of it. The purpose is shoveling unused data out of memory. And for that it doesn't need to be particularly fast.

You can't detect a priori whether data is "unused." If you guess wrong a few times in a row, you get the familiar pattern where your Linux box is unresponsive to everything and needs to be bounced.

If you could detect whether data is rarely used, swap still isn't necessary. Applications can mmap() a file and use that region for "rarely used data" if such is known in advance.

Extraneous functions should be backed by the executable in the common case. In the JIT case, they probably won't be JITted anyway.

I still think the OOM killer is less intrusive than swapping to disk. It kills some, but not all, of the processes on the machine get killed. The system pretty reliably comes back to life in less time than it takes a human to diagnose the problem and bounce the system. As a bonus, no human needs to get involved.

Re: In defence of swap: common misconceptions

#48

Swap was a great idea, but its time is gone. Swap doesn't make sense anymore, hard drives have not scaled and kept up with the improvements in RAM. In the Pentium 1 era EDO RAM maxed out at 256MB/s and hard disk xfer was 10MB/s. Common RAM size was 16MB. In today's era DDR4 maxes out at 32GB/s and hard disk xfer is 500 MB/s. Common RAM size is 16GB. RAM xfer rate has grown is 320x. RAM capacity has grown 100x. Disk x…

    hard disk xfer is 500 MB/s
You need better disks. The one in the laptop I'm typing this on can do 2GB/s, which greatly weakens your comparison.

Re: In defence of swap: common misconceptions

#49

> Under temporary spikes in memory usage > With swap: We’re more resilient to temporary spikes, but in cases of severe memory starvation, the period from memory thrashing beginning to the OOM killer may be prolonged. We have more visibility into the instigators of memory pressure and can act on them more reasonably, and can perform a controlled intervention. Somehow that doesn't resonate with my experience. I tend to…

There's a userspace daemon that does that: https://github.com/rfjakob/earlyoom (I am the author)

Re: In defence of swap: common misconceptions

#50

In my experience, a misbehaving linux system that's out of RAM and has swap to spare will be unusably slow. The process of switching to a tty, logging in, and killing whatever the offending process is can easily take a good 15 minutes. Xorg will just freeze. Oh, and hopefully you know what process it is, else good luck running `top`. Until this is fixed, I'll just keep running my systems with very small amounts of sw…

What function does the 0.5GB swap have?
Post reply on HN