Credit to @ryanc@infosec.exchange

I just did the graphic

top 98 comments

sorted by: hot top controversial new old
[–] 58 points 2 months ago (3 children)

There are good use cases for swap. I work with very performance sensitive memory hogging applications that tend to process in bursts as incoming batched data arrives. We also have a lot of required background "security" applications.

Having the idle applications move out to swap so that a significant amount of free RAM to allow for the active, real-time applications to expand into is a major boon. RAM is expensive now, so it's become even more critical to not waste it.

But even in self-hosting at home I take advantage of it since I have a limited number of servers with limited RAM and a bunch of applications and/or docker containers running, many of which don't need to be active at all times, but if they were all active, would have trouble with the limited RAM. Swap allows for inactive applications to free up RAM for the active ones and leave enough available at all times to allow an application to quickly spin up new jobs.

Anyway, sure, for a simple desktop computer without a bunch of junk background applications running for "security" or whatever, and an overabundance of RAM installed, it's probably not useful. But for high performance, memory hungry applications with lots of background stuff running, it can be a big help.

That said, there are use cases where the opposite is useful and using a RAM drive is better than writing to disk for cache and temporary logs when you have enough RAM. My opnsense router for instance uses a RAM drive to store cache and logs (logs are mirrored to the NAS for long term storage, so just the local copy is lost on reboot). That system has enough RAM and I'd rather reduce disk wear, and I don't plan to add too many other applications to that server that it would run low.

  • source
  • hideshow 3 child comments
  • [–] 6 points 2 months ago

    I also found it useful to do some one-off batch processing of a big file without thinking of chunking and doing too complicated things. Imagine something like a 60GB file in a custom format that need to be deduplicated. It's easier to just load it all up in memory and do run the algorithm 2-3x slower using a 50GB swapfile than spend hours to complicate the algorithm.

  • source
  • parent
  • [–] 43 points 2 months ago (3 children)

    I used to be this guy. We have huge amount of memory in our storage server. Why would we need swap? Well, once the system started killing programs I read up on swap and how the system handles its caches, especially ZFS ARC.

    Short version is that while the system can evict its caches syncronously, it can only async notify ZFS that it should also shrink its caches, but the out-of-memory killer will start killing before ZFS and its kernel counterpart can start to free up memory.

    A tiny bit of swap completely solved this, since swapping is sync for the kernel and the OOM killer will wait for it.

  • source
  • hideshow 3 child comments
  • [–] 42 points 2 months ago (5 children)

    No

    15.5/15.5 GB RAM used, plus 16.8/465GB swap

    It turns out the computer mostly freezes once you go past 200% RAM used.

  • source
  • hideshow 5 child comments
  • [–] 2 points 2 months ago (3 children)
  • 16GB are my usual breakfast, I'll fill that quickly after booting... I'm happy that I got 64GB, though even that is often used up, thus I sometimes wish for 128Gb though (and for running somewhat capable local LLMs 512GB would be even better...).

    Bottomline: ypu can basically never have enough RAM...

  • source
  • parent
  • [–] 3 points 2 months ago* (1 child)

    Trying to ray-trace a 512,000x256,000 image using Chunky. I had to split it into 16 parts to reduce the RAM to a sane amount (in 2018, it may have been optimised since).

    I was trying to find the limit for a single png, and I think I found it.

  • source
  • parent
  • hideshow 1 child comment
  • [+] 61 points 2 months ago (7 children)
  • [–] [S] 26 points 2 months ago (5 children)

    Shit did I botch it? I made this on my phone and the toot I copied the script from was just text. Wanted to make it look more interesting so I found this site that let you make the windows. I just went with what I thought looked best.

  • source
  • parent
  • hideshow 5 child comments
  • [–] 6 points 2 months ago (2 children)

    Is this tongue in cheek i swear I cannot tell any longer.

    Some swap is beneficial

  • source
  • parent
  • hideshow 2 child comments
  • load more comments (-1 replies)
  • [–] 19 points 2 months ago (9 children)

    All I know is that I had 16GB RAM and 4GB swap and I used to get crashes sometimes.

    Set that fucker to 32GB out of spite, now no crashes. No idea why that helped. But I guess I do have like 15 tabs open on the regular (web dev)

  • source
  • hideshow 9 child comments
  • [–] 15 points 2 months ago (4 children)

    15 tabs? Those are rookie numbers. Unless you mean "before 8:07 Monday morning".

  • source
  • parent
  • hideshow 4 child comments
  • [–] 8 points 2 months ago* (2 children)

    browsers offload inactive tabs from memory anyway, unless you're actively switching among 15+ tabs, they won't be using as much ram

  • source
  • parent
  • hideshow 2 child comments
  • [–] 9 points 2 months ago (3 children)

    Historically swap needed to be a minimum of installed ram.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 8 points 2 months ago* (last edited 2 months ago) (2 children)

    I don't recall that, but IIRC it does need to be a minimum of installed RAM if you want to be able to hibernate, since then you write out the contents of your memory to swap. That makes having at least as much swap as RAM a good rule of thumb for many systems.

    IIRC kernel crash dumps also make use of swap in a similar way, though I assume that in most sane scenarios, it's not going to actually require as much swap as physical memory, because you won't have all of your physical memory allocated to the kernel.

    On non-exotic Linux systems, I always make sure to have more swap than physical RAM.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 16 points 2 months ago (1 child)

    "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

  • source
  • hideshow 1 child comment
  • [–] 14 points 2 months ago

    "I'm not a friggin bear, I don't hibernate!"

  • source
  • [–] 28 points 2 months ago (12 children)

    People still use swap partitions instead of swap files?

  • source
  • hideshow 12 child comments
  • [–] 6 points 2 months ago (8 children)

    Don't you need swap partitions to be able to use hibernation?

  • source
  • parent
  • hideshow 8 child comments
  • [–] 7 points 2 months ago (1 child)

    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.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 1 point 2 months ago

    I do the same and use ugrd. I think dracut would also work.
    You just set the resume kernel parameter to the decrypted memory device with the swapfile offset.
    As long as the initrd attempts a resume after it decrypted all volumes it'll work, and the initrd doesn't even need to understand why and what was resumed from

  • source
  • parent
  • [–] 4 points 2 months ago (1 child)
  • [–] 2 points 2 months ago (2 children)

    I don't use hibernation so I'm not sure.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 2 months ago (1 child)

    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.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 3 points 2 months ago

    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.

  • source
  • parent
  • [–] 13 points 2 months ago

    swapfile gang

    .rw------- root root 4.0 GB Mon Jun  1 04:10:37 2026 ο€– /var/swap
    
  • source
  • [–] 12 points 2 months ago* (last edited 2 months ago)

    Once tortured myself with having to go through...

    The Android build system. Booo, scary.

    I only wanted a LineageOS boot image built. The recommended specs list 64GiB RAM. Figured wouldn't apply to me until I tried to build a target literally called "nothing". It just used up all of the RAM and OOMed about 2 minutes in, building the "build cache" or whatever the fuck it needs to do to "warm up".

    After a few fucktons of swapspace, turning off some of my daemons, some sysctl fuckery (there were options for limiting process virtual memory size IIRC? I put it all the way up) and taskset -p 0-15:1 (use logical CPUs 0, 2, 4...), I had my laptop allocating 50 something GiB. I have 16GB (decimal) physical RAM installed and I consider that already way too much for my usual needs.

    After about half an hour of the build system build systeming, it just stopped doing that then built the kernel in 4 minutes with everything else in some time too.

    Yes, I have tried just running make directly. That just resulted in an image that did nothing but toggle on and off an empty (no percentage) charging circle via power button.

  • source
  • [–] 12 points 2 months ago (2 children)

    SWAP RAM is useful for hibernation mode and fall back ram incase you have low memory.

  • source
  • hideshow 2 child comments
  • [–] 11 points 2 months ago

    Swap and zram saved my R and Python Dana analysis script a couple of times.

  • source
  • [–] 11 points 2 months ago

    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"

  • source
  • [–] 10 points 2 months ago (2 children)

    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.

  • source
  • hideshow 2 child comments
  • [–] 10 points 2 months ago* (last edited 2 months ago)

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

  • source
  • [–] 9 points 2 months ago (1 child)

    I init a ramdisk and put a swap file there and call it L4 cache

  • source
  • hideshow 1 child comment
  • [–] 7 points 2 months ago*

    I actually did this for a laugh a very, very long time ago. I had upgraded my 75MHz Pentium machine from 8MB to a whopping 40MB, so since I knew it would run fine with just 8, I installed a TSR RAMdisk and told Windows 3.1 to put its swap on that drive.

    It worked great, but I decided I'd rather use the memory for other things.

    But in more modern times, I've literally forced browser caches into memory-based tmpfs to take the load off system disks, which is basically the same thing. And it reduces wear on my hardware.

  • source
  • parent
  • [–] 9 points 2 months ago

    Definitely configure swap, but I don't think there is much benefit of a swap partition over a swap file these days and swap files are trivial to configure.

  • source
  • [–] 8 points 2 months ago (9 children)

    Can anyone tell me why I see swap usage with 10+GB of free RAM available?

  • source
  • hideshow 9 child comments
  • [–] 12 points 2 months ago (5 children)

    Saving ram to swap can be done with minimal impact. Helpful when you run out of memory and that 2gb app idling can be dumped right away instead of waiting for it to be copied to swap.

  • source
  • parent
  • hideshow 5 child comments
  • [–] 1 point 2 months ago (4 children)

    but that's not what's happening. processes do actually get removed from RAM, and when they are needed they are very slow until they are loaded back. the system thinks it's more valuable to have that memory be filesystem cache

  • source
  • parent
  • hideshow 4 child comments
  • [–] -1 points 2 months ago (3 children)

    If true then Linux is a decade behind windows and macOS.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 1 point 1 month ago (2 children)

    tbh windows was doing this very aggressively on my system, it was swapping like a mad man right when memory usage reached 50%

  • source
  • parent
  • hideshow 2 child comments
  • [–] 3 points 1 month ago* (last edited 1 month ago)

    If you(or your distro) use zram then the zram usage may also count as swap in resource monitors. For me this was the case when i saw swap usage where it is clearly not needed to swap. You can check it with swapon commands.

    Other reason is that more frequently accesed files may be cached to ram and less important stuff gets swapped. But if you notice swap being used while total ram usage including cached is much lower than total, then its probably zram(and it does (Edit:)not write to disk so dont worry about that)

  • source
  • parent
  • [–] 12 points 2 months ago (3 children)

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

  • source
  • hideshow 3 child comments
  • [–] 8 points 2 months ago (1 child)

    Were you using a HDD for swap? It's nearly unnoticeable on an NVMe drive.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 3 points 2 months ago

    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.

  • source
  • parent
  • [–] 6 points 2 months ago* (4 children)

    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.

  • source
  • hideshow 4 child comments
  • [–] 6 points 2 months ago (2 children)

    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.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 1 month ago

    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

  • source
  • parent
  • [–] 6 points 2 months ago

    I don't really need swap until I need to compile blender... Need somewhere around 64Gb (with compression) to deal with the peaks

  • source
  • [–] 6 points 1 month ago

    ACPI S4 Hibernation would like to have a word with you

  • source
  • [–] 5 points 2 months ago*

    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 πŸ‘

  • source
  • I've had my computer crash trying to open or save a pdf once because it used up all the RAM space (16gb) and then used up the small swap (probably like 10gb?) and I guess some critical processes I guess just got told "no." Seems wild to me that Windows would just crash before it told a pdf it couldn't use over 20gb of memory.

  • source
  • [–] 4 points 2 months ago

    I have a small home server that I occasionally push through huge batch processing jobs. During the pushes, I might collide with other projects that use a pretty big chunk of the RAM. So, to make sure it's never a killer (just a major slow down), I made a 32GB swap file. If I need it, it's there and disk is hella cheap.

    This machine has never had a GUI installed. No browsers to complain about, just plain old data processing, stats models, and old skool computing.

    Now, my worst case scenario was building a C++ program on a raspberry pi gen 1. That has 256MB of RAM. g++ ran out building, so I NFS mounted a huge disk from my desktop machine and made the swap file there. The build took a while... but the program ran fine after the week long build, no swap needed.

  • source
  • [–] 7 points 2 months ago (7 children)

    My built-in Devil's Advocate has to ask if that's really true? Have you got a citation newer than 2 decades old? Frankly, i find it difficult to believe that anyone wouldn't like to use electron software, for the simple reason that making your SSD suffer is fun.

    Edit: in 30 years of administering Linux and (previously) Solaris sytems i've never once had to change HDDs or SSDs, so claims of torture are, i opine, exaggerated. i'll also claim that keeping electron software out of the filesystem is not good for your hygiene.

  • source
  • hideshow 7 child comments
  • [–] 6 points 2 months ago (4 children)

    That’s some really great luck you have, over the 15 years or so I have been running my Linux server I have had to replace the SSD twice(likely due to gentoo and compiling everything all the time) and had 2 hdds in my raid cluster need replacement. Here’s hoping my NAS has your luck

  • source
  • parent
  • hideshow 4 child comments
  • [–] 7 points 2 months ago* (3 children)

    To be clear: what i wrote is not actually something real, it was a joke i made by modifying a comment from a thread on github gist, i am actually surprised it wad credible enough that someone would reply seriously xD

    https://gist.github.com/joshenders/c4960cec9c63a7b7d68ffa9543356c43

  • source
  • parent
  • hideshow 3 child comments
  • [–] 2 points 2 months ago (2 children)

    Definitely bit the onion on this one, it did seem remarkable lol though I just pulled a 16 year old drive out of my Son’s PC(that was technically still working however slowly) hence the semi plausibility on my end lol

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 2 months ago* (last edited 2 months ago) (1 child)

    lmao, 16 years is a lot! That drive can drive

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 2 months ago

    Yeah it was to the point that Samsung doesn’t even admit to have made this drive on their website anywhere, I pulled the drive and was like wtf Samsung rust? I almost exclusively bought western digital in recent memory so was a surprise, had to do some digging to decode the manufacturing codes to identify the manufacturing date

  • source
  • parent
  • [–] 2 points 2 months ago

    I manage a cluster that makes heavy use of SSDs in RAID10 configuration. Those things are constantly degrading and having to be swapped out. I've started a drawer of faulted drives that I don't have the heart you throw out.

  • source
  • parent
  • [–] 6 points 1 month ago

    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.

  • source
  • [–] 3 points 1 month ago

    ZFS chuckles darkly in the corner

  • source
  • [–] 3 points 2 months ago

    unfortunately with S0ix being forced on all modern laptops, zram is the only logical choice. With s3 sleep at least i can say i need swap because i need hibernation...With S0ix? Dont bother.

  • source
  • load more comments
    view more: next β€Ί
    37 comments in c/programmer_humor@programming.dev view that post