In the end the core idea is: sometimes you have anonymous memory that is accessed so rarely that you'd rather have an extra disk cache page. If you assume that the kernel is not paging out memory that you actually use when not under pressure, swap doesn't hurt you.
If you don't need it, you don't need it. The other question is: how much swap exactly should I have? And why wouldn't I just add that much RAM instead?
> In the end the core idea is: sometimes you have anonymous memory that is accessed so rarely that you'd rather have an extra disk cache page.
That's the theory. In practice I always have more than enough RAM for all the cached pages the system wants to cache. On my laptop right now (booted today), I have 500MB of cached pages and 5.8 gigabytes of free memory. On my server (booted 499 days ago) I have 700MB of cached pages and 6 gigabytes of free memory.
If I were running out of memory [be it for cache or applications], I'd prefer to have more RAM than add swap. Yes, I keep calling it emergency memory.
> If you assume that the kernel is not paging out memory that you actually use when not under pressure, swap doesn't hurt you.
1) Bad assumption 2) it doesn't help you either, so why bother? Actually I might have a use for that disk space. In that case the swap just hurts.
Because adding RAM costs money, adding swap space is a config setting.
It looks to me that your boxes are idle. Sure, if you're not doing any work, it doesn't matter...
>1) Bad assumption 2) it doesn't help you either, so why bother? Actually I might have a use for that disk space. In that case the swap just hurts.
1) Is it? Can you source that claim somehow? 2) It does help you, that's the point. It makes your disk reads faster 3) Your answer to needing memory is 'buy more ram', but you 'may have a use for that disk space'? Buy more disk.
Only my anecode. I've had systems become annoyingly sluggish because the OS decided I no longer need something and paged it out, even tough I had plenty of RAM. Turns out I needed that something.
> 2) It does help you, that's the point. It makes your disk reads faster
I just gave my numbers. The systems are not caching nearly as much as I have ram. These numbers come from systems I use every day; they are not idle.
> 3) Your answer to needing memory is 'buy more ram', but you 'may have a use for that disk space'? Buy more disk.
Why are people so hell bent on telling me I should use swap that doesn't actually help me at all? Yes I buy as much as disk as I need, and I'm not putting unnecessary swapfiles or partitions on them. Yes I also buy as much RAM as I need.
The only real justification I see for swap here is that it's cheaper -- poor man's RAM. I call that emergency memory for when you can't have enough RAM. If I have enough memory, swap is completely pointless.
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 :(
One counter example:
If your processes in sum tend to A) access many disk locations, at large total disk space B) hold a lot of underused data in ram
This isn't totally impossible. Maybe an Ethereum node with a script doing a bunch of data reads, running side by side with hundreds of Chrome tabs, few of which are regularly accessed. (Totally hypothetical, of course...)
Swapping some rarely used ram out so the OS can buffer disk into ram seems like a reasonable approach (although maybe even more reasonable is: close some tabs).
Your point still stands that more ram is strictly as good or better performance in this scenario, but you might be able to get an equivalent performance boost much more cheaply with some swap space for the underused ram. Also, upgrading past 32 GB ram starts to veer from expensive to impossible on a laptop.
I wonder if instead of using 4GB RAM, I'd setup 3GB RAM + 1GB swap space in RAM disk would result in much wiser OOM killer decisions (or stability).
Showing superiority of such configuration would probably convince all swap sceptics
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.