4 ms·
Another useless feature into Linux kernel. Who uses swap space nowadays?! Last time I used swap on Linux device was around Pentium 2 era but in reality closer t
by iberator 8mo ago
Another useless feature into Linux kernel. Who uses swap space nowadays?! Last time I used swap on Linux device was around Pentium 2 era but in reality closer to 486DX era
- Titan2189 8mo agoWe use it in production. Workloads with unpredictable memory usage (32Mb to 4Gb per process), but we also want to start enough processes to saturate the CPU. Before we configured & enabled swap we were either sitting at low CPU utilisation or OOM
- sl-1 8mo agoIt is still useful for many workloads, I use it in work and on my own machines
- ch_123 8mo agoI ran Linux without swap for some years on a laptop with a large-for-the-time amount of RAM (about 8GB). It _mostly_ worked, but sudden spikes of memory usage would render the system unresponsive. Usually it would recover, but it in some cases it required a power cycle. Similarly, on a server where you might expect most of the physical memory to get used, it ends up being very important for stability. Think of VM or container hosts in particular.
- solstice 8mo agoI had a similar experience with Kubuntu on a xps13 from 2016 with only 8GB of RAM and the system suddenly freezing so hard that a hard reboot was required. While looking for the cause, I noticed that the system had only 250 MB of swap space. After increasing that to 10 GB there have been no further instances of freezing so far.
- GCUMstlyHarmls 8mo agoI dont get why anti-swap is so prevalent in Linux discussions. Like, what does it hurt to stick 8-16-32gb extra "oh fuck" space on your drive. Either you're going to never exhaust your system ram, so it doesn't matter, minimally exhaust it and swap in some peak load but at least nothing goes down, or exhaust it all and start having things get OOM'd which feels bad to me. Am I out of touch? Surely it's the children who are wrong.
- man8alexd 8mo ago8-16-32gb of swap space without cgroup limits would get the system into swap thrashing and make it unresponsive.
- ch_123 8mo agoI think it's some kind of misplaced desire to be "lightweight" and avoid allocating disk space that cannot be used for regular storage. My motivation way back when for wanting to avoid swap was due to concerns about SSD wear issues, but those have been solved for a long time ago.
- manuel_w 8mo agoThe pro-swap stance has never made sense to me because it feels like a logical loop. There’s a common rule of thumb that says you should have swap space equal to some multiple of your RAM. For instance, if I have 8 GB of RAM, people recommend adding 8 GB of swap. But since I like having plenty of memory, I install 16 GB of RAM instead—and yet, people still tell me to use swap. Why? At that point, I already have the same total memory as those with 8 GB of RAM and 8 GB of swap combined. Then, if I upgrade to 24 GB of RAM, the advice doesn’t change—they still insist on enabling swap. I could install an absurd amount of RAM, and people would still tell me to set up swap space. It seems that for some, using swap has become dogma. I just don’t see the reasoning. Memory is limited either way; whether it’s RAM or RAM + swap, the total available space is what really matters. So why insist on swap for its own sake?
- man8alexd 8mo agoThis rule of thumb is outdated by two decades. The proper rule of thumb is to make the swap large enough to keep all inactive anonymous pages after the workload has stabilized, but not too large to cause swap thrashing and a delayed OOM kill if a fast memory leak happens.
- tremon 8mo agoThat's not useful as a rule of thumb, since you can't know the size of "all inactive anonymous pages" without doing extensive runtime analysis of the system under consideration. That's pretty much the opposite of what a rule of thumb is for.
- SCdF 8mo agoYou should still use swap. It's not "2x RAM" as advice anymore, and hasn't been for years: https://chrisdown.name/2018/01/02/in-defence-of-swap.html https://chrisdown.name/2018/01/02/in-defence-of-swap.html tl;dr; give it 4-8GB and forget about it.
- ch_123 8mo agoI've heard "square root of physical memory" as a heuristic, although in practice I use less than this with some of my larger systems.
- man8alexd 8mo agoThe proper rule of thumb is to make the swap large enough to keep all inactive anonymous pages after the workload has stabilized, but not too large to cause swap thrashing and a delayed OOM kill if a fast memory leak happens.
- boomlinde 8mo agoThat's not so much a rule of thumb as an assessment you can only make after thorough experimentation or careful analysis.
- man8alexd 8mo agoYou don't need "horough experimentation or careful analysis". Just keep free swap space below few hundred megabytes but above zero.
- boomlinde 8mo ago"Keep swap space below few hundred megabytes but above zero" is a good example of a rule of thumb. "Make the swap large enough to keep all inactive anonymous pages after the workload has stabilized, but not too large to cause swap thrashing and a delayed OOM kill if a fast memory leak happens" is not.
- 8mo ago
- wongarsu 8mo agoIt's unloved on Linux because using Linux under memory pressure sucks. But that's not a good reason to abandon improvements. Even more so with the direction RAM prices are headed
- man8alexd 8mo agoIt sucks without proper cgroup limits because swap makes OOM slower to trigger. Either set the cgroup limits or make the swap small.
- ChocolateGod 8mo agoThis requires additional setup from the user, the default setup should just "work".
- man8alexd 8mo agoThere are different definitions of "just work".
- gf000 8mo agoIt sucks for interactive use only. It could be solved in user space (see the other comment with cgroups), it just isn't.
- krautsauer 8mo agoI rely on it heavily. Have you tried zram swap?
- iberator 8mo agowasting ram speed, disk speed AND cpu compression cycles? No, thank you. ZRAM is dumbest Linux idea in the past 20 years.
- krautsauer 8mo agoDisk speed? You can use zram on a diskless system. Are you sure you know what it does? (There's also the thing where it may be faster to read data from ram compressed and decompress it in cpu cache than reading it uncompressed, but that obviously depends on the workload.)
- iberator 8mo agoahh sorry. you are right: no disk usage. :)
- NoGravitas 8mo agoEven if you have plenty of memory for your work load, there are useful performance reasons for having some swap. The TLDR section of this link covers the important bits. https://chrisdown.name/2018/01/02/in-defence-of-swap.html https://chrisdown.name/2018/01/02/in-defence-of-swap.html Relatively speaking, you do need a lot less swap than you did back in the day, but performance will suffer if you don't have some, and having too much doesn't cost you anything except storage.
- lousken 8mo agoYea I am also surprised, tho I stopped using pagefile in 2011. I always told people to buy as much RAM as possible, so nowadays everybody I know has 64GBs and I have 96. Windows and Linux can use it as cache and it works amazing.