- cross-posted to:
- programmer_humor@programming.dev
- cross-posted to:
- programmer_humor@programming.dev
Credit to @ryanc@infosec.exchange
I just did the graphic
The trick is to first create a RAM disk. Then put the swap file on there and it’s about as fast as RAM. Then, with the new memory you have created, make another RAM disk. Yep, then make more swap space on there.
I have solved both the memory and SSD availability issues with this infinite RAM and disk space trick.
ACPI S4 Hibernation would like to have a word with you
Swap is there an emergency relief for when a runaway process starts to eat all the resources. The system gets slow the user says hey what’s that? They look and see oh wow this one process is really eating a lot of resources that’s bad, can I kill it or do I need to gracefully try to shut it down. Swap buys you time when it could matter. When you don’t have swap OOM killer takes out whatever it wants and for a desktop user that may not be that big of a deal but for a server the database is likely the first target that is taken out.
you misunderstand the meme (of course it doesn’t help either); because the alternative isn’t “no swap”, but rather “use a swap file instead of swap partition”
My 64GiB are enough for my tasks, i don’t use swap.
I may consider it for laptops but only for hibernation purposes.I basically never used swap until I used some script that was supposed to de-duplicate text messages from SMS backups.
Turns out feeding it a 100,000 message archive spanning back 15 years will somehow eat up ~80GB of RAM. I doubt it should, I guess it probably just wasn’t optimized for such a large amount.
So I made a 64GB swap file and it completed fine.
Not everything should work from ram. This is why we stream files for processing.
The backup itself was only ~8gb.
OMG I miss this meme format
“Hello I would like to torture my SSD’s FTL because I left three Electron apps open”
If you don’t actually need the swap, Linux isn’t going to make use of swap. If you need the swap, then you’d probably rather use it than have the OOM killer take out a process.
My desktop has plenty of swap available, but is using none of it, because the system isn’t under memory pressure.
If you don’t actually need the swap, Linux isn’t going to make use of swap.
Eh, yes and no.
It will offload things from RAM into swap in order free up RAM space for disk cache. Which is kind of a weird reversal when you think about it, loading your RAM contents onto disk so that you can load your disk contents onto RAM. But by doing this to idle processes in order to disk cache files you’re likely to use soon, the system does become significantly faster and more responsive.
“Unresizeable block device at end of disk”
Classically the swap partition was located at the physical middle of the drive so that on average, no matter where the heads where, the swap partition wasn’t far away
Also “unresizeable” as if you can’t just swapoff and just delete and recreated it anywhere (update the path in fstab) and then swapon again.
swapfile gang
.rw------- root root 4.0 GB Mon Jun 1 04:10:37 2026 /var/swapDo you hibernate? 🐻
No, I have a 13-second boot time
Bah, 56 seconds ought to be enough for anyone
Everyone defending swap like crazy in the comments… so let me give a counter argument specifically for desktop:
Many years ago I stopped using swap on all my computers (I exclusively use linux) and the reason is: every time anything regarding interactivity went to swap, my system would freeze and literally become unusable for a really long time until I killed something. Since I got tired if that behaviour I decided I prefer for random shit to die but my computer still be usable.
It wasn’t very often, but I don’t get OOM killer often either (as in I don’t remember the last time it happened and I use linux every day for both work and fun), and the freezing situation was way more annoying, to the point I sometimes ended up cold switching off the computer. I’m surprised on how many people run out of memory constantly. I guess you all are just using linux for servers and have crazy processing of infinite data…
Or shotcut. I once ran it on 8GB, minimal arch with no swap. Well.
And I’m not even trying to build android on my new relatively modern laptop. It won’t work.
Were you using a HDD for swap? It’s nearly unnoticeable on an NVMe drive.
yep it was HDD, but with the low amount of times I have any OOM issue, I’m way more worried about NVMe flash burning than a random process being killed once every blue moon.
In fact I didn’t mention, but since the advent of flash drives what I’ve done is trying to locate heavy disk writing apps and find alternatives for them, amid disabling many logs.
For swap, it hunts me to think some automatic process I don’t have control over will burn those sweet erase cycles without me noticing just because someone programmed it poorly. I’m way more happy knowing I have some control over it.
Maybe stop giving a shit what I do with my partions? 🤷 Mine is definitely to try and make hibernate work on a shitty old laptop that’ll drain the battery if I let it sleep and unplug it.
I was thinking about hibernation as well but wasn’t sure if hibernation might also work with a swap file
Honestly the kernel is smart enough to only use it if you need it most of the time from what I can remember from my admin days, no idea why op cares.
Have a PC with 16gb ram that lives up to the overwatch game system reqs. When I installed it and launched it, it began building some sort of cache. A one time job. During that chache my os would force close steam to prevent an oom crash. I then added 16gb swap and during the owerwatch cache job the used phys ram would max out at 12gb I think and the swap sent up to 10gb. So a 22gb ram job. Yikes. Thanks swap ram 👍
People still use swap partitions instead of swap files?
Don’t you need swap partitions to be able to use hibernation?
Nope, I hibernate with a swap file and it’s in a LUKS partition. Although IIRC that whole setup requires me to use systemd boot.
It’s doable with a swap file instead. But some filesystems are more supportive than others.
For example BTRFS doesn’t support swapfiles over multiple devices (so my raid1c3 spanning 3 differently sized disks for example) and also swapfiles must be completely pre-allocated. (On the plus side BTRFS automatically blocks any accidently attempt to backup a subvolume containing a swap file.)
And no matter the filesystem you need to manually tell the kernel device and physical offset for the file via kernel parameters. Which can again be easier on some than on others (also causing the no-multiple-device filesystem problem mentioned above.
Nah, you can use
resume_offsetinstead.Here’s an example: https://forum.endeavouros.com/t/how-to-hibernate-with-btrfs-swapfile-luks2-systemd-boot-dracut/55620/2
I don’t use hibernation so I’m not sure.
So you shut your pc down like a caveman when you do hardware upgrades or repairs or move apartments?
Yeah I shut down every day. It boots up fast enough that it’s really not an issue.
This. Swap files on LUKS encrypted partition. Also, the swapspace daemon!
I’ve seen so many setups where people encrypt their data but forget to encrypt their swap.
what’s the problem? it’s not like you dump the entire contents of your system’s ram to disk any time use hibernate /s
Even without hibernation, data in apps you have open will end up in the swap if your system is ever RAM-constrained.
Generally it only happens to programs you keep running in the background and might not use for a long time that also don’t have much background activity. For example password managers.
It depends on what you set your swappiness to, too. I think Linux distros still have pretty aggressive defaults that swap more than they probably need to.
that’s what trixie’s netinst defaults to when i set up new desktops using encrypted lvm… root and swap volumes inside that, unlocking together at boot. my use doesn’t hit swap much, so it’s nbd. i just leave it like it is. only where an installer doesn’t support encrypted swap partitions do i use a file or ram-based swap instead.
It’s not as bad with LVM since LVM is more flexible. A swap file does still make it easier to change the size as needed though. If you need more swap, you can spin up a new swap file pretty much instantly while the system is running, without having to repartition. You can have both a swap partition and a swap file active at the same time though.
On systems where the data is encrypted, also encrypting the swap makes sense so I’m glad Debian does that.
Building a PC in 2026 be like “I cant afford RAM, but I can use a whole TB hard disk I shucked from an old WD external as swap and maybe my PC will feel modern”
Then what is the setup if my computer only has 4GB of memory for daily driving? Just curious because swap partitions are what I normally do on limited resource machines.
Eh, it’s fine. That’s what I do with 4 GB RAM as well. However even though I set 8 GB swap on that machine I noticed it’s hardly using the half of it at most. (Using Void Linux)
Dunno how well zswap handles at that size, but the point is that is compresses swap into RAM, so it would use a max of 819.2M for a total of 2457.6M of swap space. If you need more, then by all means, use a swap file or partition lol.
Actually linux easily supports multiple and tiered swap mounts, so you could even go zswap + ssd swap + hdd swap, or a cheapo “burn at your own risk” usb flash swap lol.
so it would use a max of 819.2M for a total of 2457.6M of swap space.
calling it total is a bit of a stretch. that’s the best case scenario, when the contents compress well.
also, zswap might not be a good idea on that system. if it only has 4 GB RAM, it likely has a CPU tht is slower and has only a couple cores, and the modern web is cpu heavy enough as it is
That is pretty cool. Did not know that. Will still be keeping my partition because it works fine for me.













