HN Hall of Fame Weekly email

Almost Always Add Swap Space

haydenjames.io Essays & writing Essays & articles Software engineering Candidate
Screenshot of haydenjames.io captured 2026-07-20
Page preview · captured 2026-07-20

Resurfaced independently across 5 calendar years, with breakout response in 2 of them.

submissions
10
submitters
3
observed span
2017–2023
peak thread · 109 comments
52 pts
latest 20+ return · 2019-07-19
52 pts

Submission timeline

2007–2026

One slot for every year since HN launched. Height is that year's peak points; orange marks a 100+ point or 50+ comment breakout. Select a bar to open its strongest thread.

First comments on top threads

HN comment order

This is bad advice when the swap is backed by spinning disk rather than SSD, in large part because paging in once the problem is solved is not aggressive enough. Let me make it concrete: say 1 GiB of your application's RAM gets swapped out then is later paged in only as needed (4 KiB pages) with no readahead. Now the application's VM space is a minefield: there are up to 262,144 times it can stall for a ~10 ms…

Swap engineering is definitely way more complicated than the article lets on. What people often don't realise is that Linux distinguishes between dirty and clean memory, with dirty memory not reflected in swap, and clean memory already stored somewhere on disc, and program code is counted as clean memory that just happens to live somewhere other than swap. Therefore, under memory pressure (especially if you set swappiness to zero), you will be preferentially swapping out your program code (because it…

Don't forget Part 2: https://haydenjames.io/linux-performance-almost-always-add-s... zram is cool, and I've noticed Fedora uses it out of the box. Much better than regular swap space on a disk. https://wiki.archlinux.org/title/Improving_performance#zram_... Interestingly, my 64GB desktop has 50GB available between free and caches, yet has 95MB of swap space used (out of 8GB zram). How can I tell which process is swapped out? Probably something which I haven't ever needed since I've booted the PC.

Counter-point, why swap is almost never required. [1] We don't have swap on over 30k servers. If you must use it, ensure it is encrypted. [1] - https://github.com/ohdns/sysctl_and_thp_test

The first top-level comment from each of the four biggest threads, in HN’s own order. Excerpts are shortened; open a comment for full context.

Breakout years
2

100+ points or 50+ comments

Total points
137

reference only — not used in Hall rules or ranking

Total comments
192

reference only — not used in Hall rules or ranking

Every submission

DateTitle as submittedByPointsComments
2017-07-30No SWAP is hurting your Linux performanceashitlerferad60
2017-07-31Linux Performance: Why You Should Almost Always Add Swap Spacedtx120
2017-08-08Linux Performance: Why You Should Almost Always Add Swap Spaceashitlerferad30
2017-12-18Linux Performance: Why You Should Almost Always Add Swap SpaceFirst breakoutashitlerferad46109
2019-04-17Linux: *Almost* Always Add Swap Spaceashitlerferad83
2019-04-18Linux Performance: Why You Should Almost Always Add Swap SpaceSupermighty32
2019-07-19Almost Always Add Swap SpaceBest thread · Latest 20+ point returnashitlerferad5275
2020-10-12Almost always add swap spaceashitlerferad40
2021-12-02Almost Always Add Swap Spaceashitlerferad113
2023-09-25Almost Always Add Swap (Linux)ashitlerferad20