I’ve heard a lot of people say your swap should be 2x RAM… but do I really need 32GB of swap?

  • ARNiM@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    As most have pointed, the “always 2x” rule doesn’t have that much of relevance in 2023 as most computers now has more than 4GB of RAM. I would only use that much of a swap when using a low hardware.

    For desktop, I would never go swapless, though. In the event of memory pressure, swap would still help in that situation so that OOM Killer do not kick off and unintentionally kill my working process. Plus it helps that Linux can move the least used data to the swap and use the RAM for filesystem cache.

    So my rule of thumb, for desktop: If RAM < 8GB: Swap == 2x RAM If RAM => 8GB: Swap == 1x RAM

    For servers, I think it depends on the workload. I keep a small amount, like probably 50% of RAM or less. But for stuff like Redis, it doesn’t make sense to have swap. You want to ensure that everything is in the memory.

  • toikpi@feddit.uk
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    I suggest that you read “In defence of swap” that various people have linked to. It includes information about swap size.

    Here are swap size recommendations for from Red Hat and Canonical. You may not run oof these distributions but the information will probably still apply.

    https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/storage_administration_guide/ch-swapspace

    https://help.ubuntu.com/community/SwapFaq

    Assuming you have 16GB of RAM 32GB is the maximum swap size you need if want to use hibernation. You can you less if don’t plan to use hibernation.

  • z3bra@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    Don’t even bother with a SWAP partition. Create an empty file on your / partition so you can grow/shrink it as needed.

    did if=/dev/zero of=/SWAP bs=1024m count=4
    mkswap /SWAP
    swapon /SWAP