6 ms·
The discussions about swap in the LWN comments are interesting. I wasn't aware that at the "swap should be 2x RAM" tip was actually a hard requirement at one po
by aftbit 2y ago
The discussions about swap in the LWN comments are interesting. I wasn't aware that at the "swap should be 2x RAM" tip was actually a hard requirement at one point (allegedly around Linux 2.4). I also wasn't aware that common recommendation was to run with swap again.
I have some systems (usually VMs) where RAM is much bigger than the root disk. For example, 500+ GiB of RAM and only 100 GiB of disk. I have other VMs where the disk is orders of magnitude slower than the RAM (e.g. EBS on AWS EC2).
I wonder what I should be doing for swap and vm.swappiness. Usually I just run with either no swap or a tiny 4 GiB swap file on /.
- lionkor 2y agoOn real machines I run with a super low swappiness of 1-5 or so, which effectively means it will always use RAM, basically until its too late. That way its difficult to accidentally get OOM killed, instead everything just slows way down when swap gets involved when RAM is full.
- IshKebab 2y agoYeah the trouble is in my experience it slows down to the point that the system is unresponsive and you have to reboot anyway. I don't think Linux has a good answer to RAM management other than "buy lots and lots of RAM" (I already have 32GB and it's nowhere near enough). I wish it worked like Windows - I've never had to reboot due to lack of RAM there, and even when the system is unresponsive ctrl-alt-del is very reliable.
- dspillett 2y agoI've had Windows hang due (apparently) to OOM before now, most recently last week: already low on free memory due to other things, a runaway chrome tab chef through a huge pile of memory overnight. Come morning everything was at a crawl (task manager responded quickly but everything else took an age to register any event like a click or keypress. Bringing up chrome's task manager, sorting by RAM use, and navigating to the top of the list, to find the problem, took several minutes. Switching to that tab hung everything, even task manager. This was running in a VM so I could see from the host that the OS has hung: practically no CPU or IO use, what little there was was likely just "background noise" from hyper-v, also not even the simplest service accepted TCP connections nor would it respond to ping. Left it like that for tens of minutes to see no change, so resorted to a hard stop & start. It happens, albeit quite rarely.
- MrDrMcCoy 2y agoEarlyOOM, swap, and zswap is the answer combo you're looking for. With those in place and properly tuned, you'd have to have something go extraordinarily sideways for an actual issue to appear.
- IshKebab 2y agoI have swap and zswap. It just delays the problem. And anyway, I don't recall having to tune Windows to work properly.
- Spivak 2y ago> instead everything just slows way down when swap gets involved when RAM is full I have literally never wanted this and so I'm curious why you do. This is why earlyoom is a thing precisely because grinding your system to a halt is often worse than killing and restarting some processes. High swappiness so you run slower but never lock up or low swappiness with an aggressive oom killer so you don't lock up are to me the only sane options. Why do you want your servers to be up but thrashing?
- lionkor 2y agoFor me, if I run out of RAM, its because im running a task that should not fail - so the reasoning is that id rather have it take longer than fail.
- pantalaimon 2y agoBugs happen and memory leaks happen. Also make -j is prone to run out of memory if you have many cores, I’d rather adjust the number of threads than have my system grind to a halt.
- pdw 2y agoI think they must be referring something in an unstable-series kernel. I don't remember anything like that, but I only ever used the stable kernels. (Back then, there were separate stable (2.2.x, 2.4.x) and unstable (2.3.x, 2.5.x) branches. "Linus forced a swap rewrite" sounds like an unstable branch thing.) I always heard that the "2x RAM" thing came from some primordial BSD release.
- NekkoDroid 2y agoI guess the best I can give you is this: https://chrisdown.name/2018/01/02/in-defence-of-swap.html https://chrisdown.name/2018/01/02/in-defence-of-swap.html
- toast0 2y agoI think it makes sense to have swap be the smaller of 2x ram and 512 MB, unless you have specific needs. On small memory systems, it really is useful to have 2x ram, because it can be pretty useful sometimes. On large memory systems, it's highly likely that your system is too far gone once it's used a significant amount of swap, so 512 MB seems like as good a place as any to stop. Swap used %, and swap in / out rates are a very good measure of system health, and if you have no swap, you lose out on those metrics. Ideally, for a small leak, you'll have enough time to get an alert about high swap use, and come in and inspect the situation before you start getting OOMs, but for a large leak, you want the system to fault quickly --- it doesn't do anybody any good to be up but deathly slow due to thrashing for a long time.
- tmtvl 2y agoI use a swap partition 1/2 the size of my RAM, a zram swap partition 1/4 the size of my RAM, and 160 swappiness. Well, I say 1/2 and 1/4 size, it's actually 8GB and 4GB to a RAM size of 15.3, but it's close enough.
- MrDrMcCoy 2y agoWhy not a single swap space with zswap? I find it much easier to configure, and the performance difference can largely be eliminated with a little tuning.
- tmtvl 2y agoI had zram set up by itself in the past, but on my most recent install I got paranoid and I decided to set up a swap partition just in case (though I dunno what happens when zram runs out of space). I suppose I may as well try zswap. On an unrelated note: if you're the DrMcCoy from Twenty Sided and GOL it's nice to see you.
- MrDrMcCoy 2y agoI am not that person, but from those community names, I expect we'd get along famously :)
- MrDrMcCoy 2y agoA small swap space with zswap is where it's at. You get all the benefits of swap, plus reduced I/O and high-enough speed fetches that it just feels like extra memory. Well worth configuring, IMO.
- DaSHacka 2y agoI typically enable zram instead, on modern systems disk-based swap is going to be extraordinarily sluggish, and unlikely to be the make-or-break of recovering a system if you 64GB+ of RAM was already chewed through.
- MrDrMcCoy 2y agozram != zswap, which is unfortunately confusing. Unlike zram, which is a fixed-size in-memory block device that can be used for swap, zswap makes its own pool for compressed pages that you can resize at will, and sends compressed pages to your real on-disk swap. This significantly reduces I/O and gives you the best of both worlds between in-memory and on-disk swap. I'll be happy to share my config if you like.
- SoftTalker 2y agoI remember the swap = 2x RAM guideline back in the day. When RAM got into the gigabytes it stopped making sense. If you're out of memory on a 64GB machine, a swap file is only going to (slowly) prolong the inevitable. These days I set up servers without swap, and I have not run into any issues doing that.
- aidenn0 2y agoIIRC 2x RAM was so that there would be room for kernel core dumps when the kernel ate all your ram.
- Izkata 2y agoIn the 2000s a common recommendation was for it to be at least 1x your RAM (so 2x was a common/easy selection) so that laptops would have enough space to hibernate (rather than just suspend).