Live data from Hacker News

In defence of swap: common misconceptions

chrisdown.name

51–60 of 151 posts

Re: In defence of swap: common misconceptions

#51
post #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.

They won't be able to achieve anything like 2GB/s when handling reads from swap, because they are likely to be lots of small chunks of reads - the pages being swapped in are often 4k and will be very difficult to predict, so bulk I/O will be unlikely. Same goes for writes, with the added proviso that your SSDs will have far worse small file write performance than reads, which is probably the 2GB/s headline figure.

A better statistic to use is how many IOPS the disk can handle.

Re: In defence of swap: common misconceptions

#52
post #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.

If I may ask, which disks are you using?

Re: In defence of swap: common misconceptions

#53
post #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?

I just wish Linux distro installers would make opting out the default option; no, I don't want to swap on my SSD. The last time I installed a distro, I still had to select the manual option for partitioning.

With an 8 Gig stick in my NUC, for normal desktop usage it never goes above 3.

Re: In defence of swap: common misconceptions

#54
My use case for swap: 10 dev environments on a cheap-ass AWS server. Where each environment is about 5 docker images.

They are slower, but to give every branch a fully usable test system is pretty awesome. No reason to pay through the butt for RAM for tier-1 dev environments. You can also have a premium dev environment for the develop branch on a different server.

Re: In defence of swap: common misconceptions

#55

Earlier quoted context omitted.

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 i…

> Applications can mmap() a file and use that region for "rarely used data" if such is known in advance.

They could, but that's a lot like just making swap be manual.

> Extraneous functions should be backed by the executable in the common case.

I don't mean the code itself, I mean all the data it builds up for something that isn't needed.

Re: In defence of swap: common misconceptions

#56

Earlier quoted context omitted.

Firefox has a couple options which may help you get by. I can't guarantee these will fix everything but they are worth experimenting with. about:memory has various options, including a 'minimize memory usage' button and profiling tools. about:preferences has Privacy & Security > Cached Web Content > Override automatic cache management (select and set at 500MB, 1GB, or whatever works best).

Yep, you can adjust the max amount of cache it will store in ram and disk(separately).

I don't see any option to separate that in the settings page, is it hidden behind a flag somewhere?

Re: In defence of swap: common misconceptions

#57
post #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.

[deleted]

Re: In defence of swap: common misconceptions

#58
post #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.

I have 4GiB swapfiles on the cluster nodes I manage, which have 512GiB RAM.

It's hardly used, around 300MiB at present, probably things like the mail daemon. It's been useful to have a very slow node, which I can SSH into (after 10 minutes) and kill a chosen process, rather than a dead/OOMed node. But I think the difference is marginal, and perhaps 512MiB would have been a more appropriate size for the partition.

(Swappiness is set to 1.)

Re: In defence of swap: common misconceptions

#59

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…

You can use Alt+SysRq+f to manually call oom_kill.

Re: In defence of swap: common misconceptions

#60
post #37

Does hibernating via a swap file work reasonably well yet? I haven't had a chance to try this out yet, but that's the main reason I still have a swap partition on my laptop.

Well done mate - you are the first person to mention this here. It was also only briefly mentioned in the article.

Yes, hibernation does work well and it requires swap. Personally, I set a swap partition equal to RAM + 512MB on systems that I want to hibernate on.

Linux also supports swap files and this might be handy: https://wiki.debian.org/Hibernation/Hibernate_Without_Swap_P...

Post reply on HN