Live data from Hacker News

In defence of swap: common misconceptions

chrisdown.name

11–20 of 151 posts

Re: In defence of swap: common misconceptions

#11

So, in other words, if you have enough memory for your workload that you won't run out, there's no benefit to having swap space (i.e. you've wasted money on memory you don't need). But if you DO have swap space, there won't be a performance hit (at least not under Linux) because it will only swap out some rarely used pages and then sit there doing nothing. So, in the general case, it's better to have it and not need…

> So, in other words, if you have enough memory for your workload that you won't run out, there's no benefit to having swap space (i.e. you've wasted money on memory you don't need).

No, that's the opposite. If you have enough memory for your workload that you won't run out, swapping lets you use more memory for disk cache (instead of keeping unaccessed anonymous pages in real ram).

Unless by "won't run out" you mean "never have to throw away a disk cache page", which seems very unrealistic.

Re: In defence of swap: common misconceptions

#12

So, in other words, if you have enough memory for your workload that you won't run out, there's no benefit to having swap space (i.e. you've wasted money on memory you don't need). But if you DO have swap space, there won't be a performance hit (at least not under Linux) because it will only swap out some rarely used pages and then sit there doing nothing. So, in the general case, it's better to have it and not need…

If you, however, want to get back to work as quickly as possible if one of your calculations erroneously uses too much memory, having swap will prolong the system-is-frozen period before the OOM killer solves the problem.

Re: In defence of swap: common misconceptions

#13
post #8

This is an informative and well written article, but seems incomplete in this day and age. In public cloud environments, network attached storage is far more prevalent, so the swap story may be different there (I honestly don't know though). Since the author works at Facebook, he probably lacks experience in this regard.

Every cloud provider I've worked with (okay, so AWS :P) gives you ephemeral local storage. Obvioulsy you don't swap onto a network drive.

Re: In defence of swap: common misconceptions

#14

So, in other words, if you have enough memory for your workload that you won't run out, there's no benefit to having swap space (i.e. you've wasted money on memory you don't need). But if you DO have swap space, there won't be a performance hit (at least not under Linux) because it will only swap out some rarely used pages and then sit there doing nothing. So, in the general case, it's better to have it and not need…

If you, however, want to get back to work as quickly as possible if one of your calculations erroneously uses too much memory, having swap will prolong the system-is-frozen period before the OOM killer solves the problem.

> the OOM killer "solves" the problem.

I fixed this for you. At least there are still some OSes that don't consider this a "solution."

Re: In defence of swap: common misconceptions

#15
post #8

This is an informative and well written article, but seems incomplete in this day and age. In public cloud environments, network attached storage is far more prevalent, so the swap story may be different there (I honestly don't know though). Since the author works at Facebook, he probably lacks experience in this regard.

Every cloud provider I've worked with (okay, so AWS :P) gives you ephemeral local storage. Obvioulsy you don't swap onto a network drive.

Even on AWS they're phasing out local storage on new instance types: https://ec2instances.info/ (search for ec2 only, but it's the majority of new instance families)

Re: In defence of swap: common misconceptions

#16
post #8

This is an informative and well written article, but seems incomplete in this day and age. In public cloud environments, network attached storage is far more prevalent, so the swap story may be different there (I honestly don't know though). Since the author works at Facebook, he probably lacks experience in this regard.

Every cloud provider I've worked with (okay, so AWS :P) gives you ephemeral local storage. Obvioulsy you don't swap onto a network drive.

Modern AWS instance types are EBS-only.

Re: In defence of swap: common misconceptions

#17
post #6

I have an older Chromebook (c720), which is really quite memory starved (2GB RAM), and have experienced ChromeOS completely frying the SSD simply through prolonged tab-heavy swapping. Now, I've replaced the SSD and installed a non-Google Linux distro, and would like to limit the amount of swapping Firefox can do. I had been planning to simply use cgroups' memory features to limit the amount of memory consumed by Fire…

Setting the `swappiness` value might be of use to you.

Setting a lower value (min is 0, default is 60 iirc, max is 100, so above half) reduces the likelihood of the kernel swapping. The lower the number the fuller ram needs to be before the kernel will start swapping. Hence a low number will mean that less swapping will happen, hence meaning less SSD wear.

Re: In defence of swap: common misconceptions

#18
post #6

I have an older Chromebook (c720), which is really quite memory starved (2GB RAM), and have experienced ChromeOS completely frying the SSD simply through prolonged tab-heavy swapping. Now, I've replaced the SSD and installed a non-Google Linux distro, and would like to limit the amount of swapping Firefox can do. I had been planning to simply use cgroups' memory features to limit the amount of memory consumed by Fire…

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).

Re: In defence of swap: common misconceptions

#19
post #16

Earlier quoted context omitted.

Every cloud provider I've worked with (okay, so AWS :P) gives you ephemeral local storage. Obvioulsy you don't swap onto a network drive.

Modern AWS instance types are EBS-only.

With the exception of the High IO types (I2/I3). They still get it and the newer instances get NVMe SSDs. In other words they are making it a feature of certain types that would benefit from it.

Re: In defence of swap: common misconceptions

#20
I'm a big fan of determinism and service uniformity. Having that rarely used and response time critical function/data/whatever swapped out increases service time variation at best and complicates all worst case response time calculations at least.

I understand from the land of JIT compilers, garbage collectors, and oversubscribed everything that this is not much of a substantial concern as these features are already traded away.

The swap may be the best case in a bad situation. I would argue along the lines of don't be in a bad situation...

I'm looking at you 8 of 16 GB used on cold boot Mac laptops... Looking at you with indignation and rancor Chrome.

Post reply on HN