Live data from Hacker News

Linux Performance: Why You Should Almost Always Add Swap Space

haydenjames.io

41–50 of 120 posts

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#41
post #39

Nowadays linux has this thing called zram disk. It compresses data in memory on the fly. I think general swapping advice would serve most people better if they always add swap on zram first, before swap on ssd or hdd. The difference is that getting data in and out of zram is so fast that you can actually use it as a tier of a slower ram, transparently compressed.

is this activated per default today? Last information I've got from Ubuntu 16.04 times is that it is not activated by default. I know that macOS and Windows do similar to this by default.

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#42
post #33

> As a last resort, the Kernel will deploy OOM killer to nuke high-memory process(es) Yes! That is exactly what I want to happen! When the system runs out of RAM, things will generally stop functioning, swap enabled or not. The only question is how you want it to stop functioning when that happens. In almost every situation, I'll easily take the kernel killing whatever single process it thinks is most appropriate to…

Funny story though, we had a database server get nuked because a client process used too much memory. We hadn't done the tuning correctly and someone decided to run their queries locally. So it was entirely our fault. But mysqld - 220GB, mysql (client) - 30GB, let's nuke the server process.

Lesson learned, make sure you adjust the OOM killer on things like services that use lots of RAM.

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#43
post #33

> As a last resort, the Kernel will deploy OOM killer to nuke high-memory process(es) Yes! That is exactly what I want to happen! When the system runs out of RAM, things will generally stop functioning, swap enabled or not. The only question is how you want it to stop functioning when that happens. In almost every situation, I'll easily take the kernel killing whatever single process it thinks is most appropriate to…

I don't want this to happen.

On servers, in almost every situation, I'd rather have the server reboot than have some random process crash and leave the system in a potentially broken state.

On desktops, in every situation, I'd rather have X, my window manager and an emergency terminal pinned to RAM so I can always decide what to kill for myself. (https://github.com/stiletto/angrymlocker helps with setting this up.)

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#44
post #29
post #23

This is dangerous advice. At least on Ubuntu 16.04 with stock kernel running due to memory pressure into swap kills the systems. Basically everything times out and you can only hard-reboot. Without swap you have an OOM at least something you can recover from. If you need swap just add a little like 1-4gb - because if you have spinning disks 64gb swap won't help you at all because every request to swap is magnitudes m…

Not just ubuntu. We tell our engineers to remove their swap partitions because sometimes the test suite will consume all remaining memory and push into swap. If that happens, pretty much the only thing you can do is a hard poweroff. If you're fast, you can Ctrl+C and only lose a minute or two, but often you're just completely stuck. Much better to OOM and have the test suite killed early.

Wouldn’t it make much more sense to limit the maximum amount of memory available to something like (system memory-500MB) using CGroups? I know configuring CGroups can be difficult because there is no command line script but it might be worth it if it’s such a common problem with your test suits. An easy way to configure CGroups would be to use docker but that adds a lot of overhead in management (not in performance - but you need to have every dev install docker and test the suit using docker).

I use swap quite a lot, though, I’m not sure what my system moves to swap though. A large portion seems to be inactive google chrome tabs (whenever I open an inactive tab, chrome freezes for a second and I suddenly use ~70MB less swap.

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#45

Swap isn’t needed at all in this age. It’s just there for people who can’t afford more RAM and therefore have to resort to hacky solutions like this.

What an absurd statement. Do you use a laptop? I do and I'm using swap space right now. I would like to buy a laptop with 32 or 64 Gigs of RAM but I can't as most(all?) laptop makers don't ship with a memory controller that permits more than 16 Gigs of RAM. And I can afford to buy more RAM.

What is the rule for setting swap size, or can I use just swap file just like on win/mac? (I heard it will disable hibernation then)

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#46
post #15

I wondered this for a while, unfortunately a major question I have remains unanswered in the text: What about SSDs and SSD-only systems? (Like... any average laptop.) Should I be worried that putting a swap on an SSD will cause it to wear out fast due to many write cycles?

I used to work in flash manufacturing. We would joke, "I hope nobody ever uses this for swap!" The numbers I saw for endurance (basically write-erase cycles before failure) were not encouraging at all. As far as I can tell the only reason MLC flash works at all is that the controller does some magic to present a whole bunch of pretty flaky cells as a single reliable unit.

> As far as I can tell the only reason MLC flash works at all is that the controller does some magic to present a whole bunch of pretty flaky cells as a single reliable unit.

I would refuse to even use SLC flash without that magic.

But once you have all that ECC and balancing, durability almost stops being a problem outside of heavy database loads.

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#48
post #33

> As a last resort, the Kernel will deploy OOM killer to nuke high-memory process(es) Yes! That is exactly what I want to happen! When the system runs out of RAM, things will generally stop functioning, swap enabled or not. The only question is how you want it to stop functioning when that happens. In almost every situation, I'll easily take the kernel killing whatever single process it thinks is most appropriate to…

I don't want this to happen. On servers, in almost every situation, I'd rather have the server reboot than have some random process crash and leave the system in a potentially broken state. On desktops, in every situation, I'd rather have X, my window manager and an emergency terminal pinned to RAM so I can always decide what to kill for myself. ( https://github.com/stiletto/angrymlocker helps with setting this up.)

> I'd rather have the server reboot than have some random process crash and leave the system in a potentially broken state.

Set the OOM killer to trigger a reboot? Crawling to a swapping halt is the worst of both worlds, it's like a full system crash but the server never comes back.

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#49
post #25
post #23

This is dangerous advice. At least on Ubuntu 16.04 with stock kernel running due to memory pressure into swap kills the systems. Basically everything times out and you can only hard-reboot. Without swap you have an OOM at least something you can recover from. If you need swap just add a little like 1-4gb - because if you have spinning disks 64gb swap won't help you at all because every request to swap is magnitudes m…

indeed on ubuntu 16.04 64bit, when my chrome has 20+ tabs, some new tab could trigger a memory thrashing, that uses up all the memory and eats up a few GB disk, cpu load jumps up to 10x, the computer basically becomes unusable. i would rather a OOM kill the chrome process in this case, it wastes less time on me, a re-open of chrome will keep all the histories anyways. also on embedded system where the RAM is fairly l…

>when my chrome has 20+ tabs

That's not a swap problem, that's a Chrome problem.

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#50
post #15

I wondered this for a while, unfortunately a major question I have remains unanswered in the text: What about SSDs and SSD-only systems? (Like... any average laptop.) Should I be worried that putting a swap on an SSD will cause it to wear out fast due to many write cycles?

I used to work in flash manufacturing. We would joke, "I hope nobody ever uses this for swap!" The numbers I saw for endurance (basically write-erase cycles before failure) were not encouraging at all. As far as I can tell the only reason MLC flash works at all is that the controller does some magic to present a whole bunch of pretty flaky cells as a single reliable unit.

>I used to work in flash manufacturing

How long ago? r/w cycles haven't really been an issue on SSDs in a long time

Post reply on HN