Most active commenters
  • eru(6)
  • fluoridation(5)
  • adastra22(3)
  • vlovich123(3)

←back to thread

804 points jryio | 19 comments | | HN request time: 0.001s | source | bottom
Show context
speedgoose ◴[] No.45661785[source]
Looking at the htop screenshot, I notice the lack of swap. You may want to enable earlyoom, so your whole server doesn't go down when a service goes bananas. The Linux Kernel OOM killer is often a bit too late to trigger.

You can also enable zram to compress ram, so you can over-provision like the pros'. A lot of long-running software leaks memory that compresses pretty well.

Here is how I do it on my Hetzner bare-metal servers using Ansible: https://gist.github.com/fungiboletus/794a265cc186e79cd5eb2fe... It also works on VMs.

replies(15): >>45661833 #>>45662183 #>>45662569 #>>45662628 #>>45662841 #>>45662895 #>>45663091 #>>45664508 #>>45665044 #>>45665086 #>>45665226 #>>45666389 #>>45666833 #>>45673327 #>>45677907 #
levkk ◴[] No.45662183[source]
Yeah, no way. As soon as you hit swap, _most_ apps are going to have a bad, bad time. This is well known, so much so that all EC2 instances in AWS disable it by default. Sure, they want to sell you more RAM, but it's also just true that swap doesn't work for today's expectations.

Maybe back in the 90s, it was okay to wait 2-3 seconds for a button click, but today we just assume the thing is dead and reboot.

replies(16): >>45662314 #>>45662349 #>>45662398 #>>45662411 #>>45662419 #>>45662472 #>>45662588 #>>45663055 #>>45663460 #>>45664054 #>>45664170 #>>45664389 #>>45664461 #>>45666199 #>>45667250 #>>45668533 #
KaiserPro ◴[] No.45662472[source]
Yeahna, thats just memory exhaustion.

Swap helps you use ram more efficiently, as you put the hot stuff in swap and let the rest fester on disk.

Sure if you overwhelm it, then you're gonna have a bad day, but thats the same without swap.

Seriously, swap is good, don't believe the noise.

replies(2): >>45662602 #>>45662672 #
adastra22 ◴[] No.45662672[source]
I don’t understand. If you provision the system with enough RAM, then you can for every page in RAM, hot or not.
replies(1): >>45663000 #
1. akvadrako ◴[] No.45663000[source]
Only if you have more RAM than disk space, which is wasteful for many applications.
replies(1): >>45663147 #
2. adastra22 ◴[] No.45663147[source]
Running out of memory kills performance. It is better to kill the VM and restart it so that any active VM remains low latency.

That is my interpretation of what people are saying upthread, at least. To which posters such as yourself are saying “you still need swap.” Why?

replies(2): >>45663366 #>>45666448 #
3. eru ◴[] No.45663366[source]
RAM costs money, disk space costs less money.

It's a bit wasteful to provision your computers so that all the cold data lives in expensive RAM.

replies(2): >>45663396 #>>45663411 #
4. adastra22 ◴[] No.45663396{3}[source]
When building distributed systems, service degradation means you’ll have to provision more systems. Cheaper to provision fewer systems with more RAM.
replies(1): >>45663573 #
5. fluoridation ◴[] No.45663411{3}[source]
>It's a bit wasteful to provision your computers so that all the cold data lives in expensive RAM.

But that's a job applications are already doing. They put data that's being actively worked on in RAM they leave all the rest in storage. Why would you need swap once you can already fit the entire working set in RAM?

replies(3): >>45663566 #>>45663646 #>>45665729 #
6. eru ◴[] No.45663566{4}[source]
Sure, some applications are written to manually do a job that your kernel can already do for you.

In that case, and if you are only running these applications, the need for swap is much less.

replies(1): >>45663689 #
7. eru ◴[] No.45663573{4}[source]
It depends on what you are doing, and how your system behaves.

If you size your RAM and swap right, you get no service degradation, but still get away with using less RAM.

But when I was at Google (about a decade ago), they followed exactly the philosophy you were outlining and disabled swap.

8. vlovich123 ◴[] No.45663646{4}[source]
Because then you have more active working memory as infrequently used pages are moved to compressed swap and can be used for more page cache or just normal resident memory.

Swap ram by itself would be stupid but no one doing this isn’t also turning on compression.

replies(2): >>45666343 #>>45671937 #
9. fluoridation ◴[] No.45663689{5}[source]
You mean to tell me most applications you've ever used read the entire file system, loading every file into memory, and rely on the OS to move the unused stuff to swap?
replies(1): >>45664970 #
10. eru ◴[] No.45664970{6}[source]
No? What makes you think so?
replies(1): >>45665034 #
11. fluoridation ◴[] No.45665034{7}[source]
Then what do you mean, some applications organize hot and cold data in RAM and storage respectively? Just about every application does it.
replies(1): >>45666351 #
12. akvadrako ◴[] No.45665729{4}[source]
This subthread is about a poster's claim above that every page would be in RAM if you have enough, "hot or not", not just the working set.
13. eru ◴[] No.45666343{5}[source]
> Swap ram by itself would be stupid but no one doing this isn’t also turning on compression.

I'm not sure what you mean here? Swapping out infrequently accesses pages to disk to make space for more disk cache makes sense with our without compression.

replies(1): >>45670340 #
14. eru ◴[] No.45666351{8}[source]
A silly but realistic example: lots of applications leak a bit of memory here and there.

Almost by definition, that leaked memory is never accessed again, so it's very cold. But the applications don't put this on disk by themselves. (If the app's developers knew about which specific bit is leaking, they'd rather fix the leak then write it to disk.)

replies(1): >>45667356 #
15. KaiserPro ◴[] No.45666448[source]
> Running out of memory kills performance. It is better to kill the VM and restart it so that any active VM remains low latency.

Right, you seem to be not understanding what I'm getting at.

Memory exhaustion is bad, regardless of swap or not.

Swap gets you a better performing machine because you can swap out shit to disk and use that ram for vfs cache.

the whole "low latency" and "I want my VM to die quicker" is tacitly saying that you haven't right sized your instances, your programme is shit, and you don't have decent monitoring.

Like if you're hovering on 90% ram used, then your machine is too small, unless you have decent bounds/cgroups to enforce memory limits.

16. fluoridation ◴[] No.45667356{9}[source]
That's just recognizing that there's a spectrum of hotness to data. But the question remains: if all the data that the application wants to keep in memory does fit in memory, why do you need swap?
17. vlovich123 ◴[] No.45670340{6}[source]
Swapping out to RAM without compression is stupid - then you’re just shuffling pages around in memory. Compression is key so that you free up space. Swap to disk is separate.
18. fluoridation ◴[] No.45671937{5}[source]
>Because then you have more active working memory as infrequently used pages are moved to compressed swap and can be used for more page cache or just normal resident memory.

Uhh... A VMM that swaps out to disk an allocated page to make room for more disk cache would be braindead. The process has allocated that memory to use it. The kernel doesn't have enough information to deem disk cache a higher priority. The only thing that should cause it to be swapped out is either another process or the kernel requesting memory.

replies(1): >>45677588 #
19. vlovich123 ◴[] No.45677588{6}[source]
> A VMM that swaps out to disk an allocated page to make room for more disk cache would be braindead

Claiming any decision is “brain dead” in something as heuristic heavy and impossible to compute optimally as resident memory pages is quite the statement to make; this is a form of the knapsack problem (NP-complete at least) with the added benefit of time where the items are needed in some specific indeterminate order in the future and there’s a whole bunch of different workloads and workload permutations that alter this.

To drive this point home in case you disagree, what’s dumber? Swapping out to disk an allocated page (from the kernel’s perspective) that’s just sitting in the free list of the userspace allocator for that process or a page of some frequently accessed page of data?

Now, I agree that VMMs may not do this because it’s difficult to come up with these kinds of scenarios that don’t penalize the general case, more importantly than performance this has to be a mechanism that is explainable to others and understandable for them. But claiming it’s a braindead option to even consider is IMHO a bridge too far.