frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

In defence of swap: common misconceptions (2018)

https://chrisdown.name/2018/01/02/in-defence-of-swap.html
34•jitl•5h ago

Comments

01HNNWZ0MV43FF•2h ago
`sudo apt-get install earlyoom`

Configure it to fire at like 5% and forget it.

I've never seen the OOM do its dang job with or without swap.

cmckn•1h ago
If you've tried `systemd-oomd`, I'm curious what your thoughts are: https://www.freedesktop.org/software/systemd/man/latest/syst...
ggm•1h ago
Recognition that older linux swap strategies were unhelpful sometimes, which this piece of writing does, validates out past sense it wasn't working well. Regaining trust takes time.

Sometimes I think if backing store and swap were more clearly delineated we might have got to decent algorithms sooner. Having a huge amount of swap pre-emptively claimed was making it look like starvation, when it was just a runtime planning strategy. It's also confusing how top and vmstat report things.

Also, as a BSD mainly person, I think the differences stand out. I haven't noticed an OOM killer approach on BSD.

Ancient model: twice as much swap as memory

Old model: same amount of swap as memory

New model: amount of swap your experience tells you this job mix demands to manage memory pressure fairly, which is a bit of a tall ask sometimes, but basically pick a number up to memory size.

kijin•1h ago
> 6. Disabling swap doesn't prevent pathological behaviour at near-OOM, although it's true that having swap may prolong it. Whether the global OOM killer is invoked with or without swap, or was invoked sooner or later, the result is the same: you are left with a system in an unpredictable state. Having no swap doesn't avoid this.

This is the most important reason I try to avoid having a large swap. The duration of pathological behavior at near-OOM is proportional to the amount of swap you have. The sooner your program is killed, the sooner your monitoring system can detect it ("Connection refused" is much more clear cut than random latency spikes) and reboot/reprovision the faulty server. We no longer live in a world where we need to keep a particular server online at all cost. When you have an army of servers, a dead server is preferable to a misbehaving server.

OP tries to argue that a long period of thrashing will give you an opportunity for more visibility and controlled intervention. This does not match my experience. It takes ages even to log in to a machine that is thrashing hard, let alone run any serious commands on it. The sooner you just let it crash, the sooner you can restore the system to a working state and inspect the logs in a more comfortable environment.

heavyset_go•17m ago
Maybe I'm just insane, but if I'm on a machine with ample memory, and a process for some reason can't allocate resources, I want that process to fail ASAP. Same thing with high memory pressure situations, just kill greedy/hungry processes, please.

Like something is going very wrong if the system is in that state, so I want everything to die immediately.

tanelpoder•1h ago
This wasn't on Linux, but on one of the old-school commercial Unixes - a customer had memory leaks in some of their daemon processes. They couldn't fix them for some reason.

So they invested in additional swap space, let the processes slowly grow, swap out leaked stuff and restart them all over the weekend...

userbinator•59m ago
Under no/low memory contention

on some workloads this may represent a non-trivial drop in performance due to stale, anonymous pages taking space away from more important use

WTF?

creshal•10m ago
Welcome to the wonderful world of Java programs. When your tomcat abomination pulls in 500 dependencies for one method call each, and 80% of the methods aren't even called in regular use except to perform dependency injection mumbo jumbo during the 90 seconds your tomcat needs to start up, you easily end up with 70% of your application's anon pages being completely useless, but if you can't banish them to swap, they'll prevent the code on the hot path from having any memory left over for file caching.

So even if you never run into OOM situations, adding a couple gigabytes of swap lets you free up that many gigabytes of RAM for file caching, and suddenly your application is on average 5x faster - but takes 3 seconds longer to service that one obscure API call that needs to dig all those pages back up. YMMV if you prefer consistently poor performance over inconsistent but usually much better performance.

goopypoop•44m ago
swap.avi is its own damning defence
LegionMammal978•37m ago
On my desktop system, most of my problems with swap come from dealing with the aftermath of an out-of-control process eating all my RAM. In this case, the offending program demands memory so quickly that everything from legitimate programs gets swapped out. These programs proceed to run poorly for the next several minutes to an hour depending on usage, since the OS only swaps pages back in once they are referenced, even if there is plenty of free space not even being used in the disk cache.

Eventually I wrote a small script that does the equivalent of "sudo swapoff -a && sudo swapon -a" to eagerly flush everything to RAM, but I was surprised by how many people seemed to think there's no legitimate reason to ever want to do so.

vbezhenar•29m ago
I've always created swap of 1.5x - 4x RAM size on every Linux computer I've had to manage and never had any issues with it. That's my rule that I learned many years ago, follow to this day and will follow.

Worst thing: I left 5% of my SSD unused which will actually be used for garbage collection and other staff. That's OK.

What I don't understand is why modern Linux is so shy of touching swap. With old kernels, Linux happily pushed unused pages to a swap, so even if you don't eat memory, your swap will be filled with tens or hundreds MB of memory and that's a great thing. Modern kernel just keeps swap usage at 0, until memory is exhausted.

kevin_thibedeau•22m ago
I haven't used swap for 15 years. You have to be judicious about heavy app usage with only 16GiB. With 32GiB, I've never triggered OOM.
creshal•18m ago
> I've always created swap of 1.5x - 4x RAM size on every Linux computer I've had to manage and never had any issues with it.

That's a couple terabyte of swap on servers these days, and even on laptops I wouldn't want to deal with 300-ish GB swap.

creshal•16m ago
I wish people would actually read TFA instead of reflexively repeating nonsensical folk remedies.

iFixit iPhone Air teardown

https://www.ifixit.com/News/113171/iphone-air-teardown
41•zdw•2h ago•16 comments

$2 WeAct Display FS adds a 0.96-inch USB information display to your computer

https://www.cnx-software.com/2025/09/18/2-weact-display-fs-adds-a-0-96-inch-usb-information-displ...
228•smartmic•8h ago•107 comments

Ultrasonic Chef's Knife

https://seattleultrasonics.com/
498•hemloc_io•13h ago•402 comments

The bloat of edge-case first libraries

https://43081j.com/2025/09/bloat-of-edge-case-libraries
28•PaulHoule•3h ago•27 comments

Hyperion: Minecraft game engine for custom events

https://hyperion.rs/
55•cjcuddy•4d ago•12 comments

Slavery After Abolition: Revolt on the Amelia

https://www.historytoday.com/archive/feature/slavery-after-abolition-revolt-amelia
10•samclemens•3d ago•0 comments

Teen suspect surrenders in 2023 Las Vegas casino cyberattack case

https://www.casino.org/news/teen-suspect-surrenders-in-2023-las-vegas-strip-cyberattack-case/
48•campuscodi•6h ago•21 comments

Designing NotebookLM

https://jasonspielman.com/notebooklm
197•vinhnx•12h ago•67 comments

In defence of swap: common misconceptions (2018)

https://chrisdown.name/2018/01/02/in-defence-of-swap.html
34•jitl•5h ago•14 comments

I’m Not a Robot

https://neal.fun/not-a-robot/
381•meetpateltech•4d ago•198 comments

Were RNNs all we needed? A GPU programming perspective

https://dhruvmsheth.github.io/projects/gpu_pogramming_curnn/
47•omegablues•2d ago•11 comments

Knitted Anatomy

https://www.knitted-anatomy.at/cardiovascular-system/
77•blikstiender•3d ago•5 comments

A brief history of threads and threading

https://eclecticlight.co/2025/09/20/a-brief-history-of-threads-and-threading/
61•emschwartz•8h ago•12 comments

Teardown of Apple 40W dynamic power adapter with 60W max

https://www.chargerlab.com/teardown-of-apple-40w-dynamic-power-adapter-with-60w-max-a3365/
122•givinguflac•2d ago•89 comments

AI Was Supposed to Help Juniors Shine. Why Does It Mostly Make Seniors Stronger?

https://elma.dev/notes/ai-makes-seniors-stronger/
15•elmsec•4h ago•15 comments

Amazon to end commingling after years of complaints from brands and sellers

https://www.modernretail.co/operations/amazon-to-end-commingling-program-after-years-of-complaint...
179•blindriver•3h ago•62 comments

Spectral Labs releases SGS-1: the first generative model for structured CAD

https://www.spectrallabs.ai/research/SGS-1
3•JumpCrisscross•1h ago•0 comments

Scream cipher

https://sethmlarson.dev/scream-cipher
257•alexmolas•2d ago•94 comments

A revolution in English bell ringing

https://harpers.org/archive/2025/10/a-change-of-tune-veronique-greenwood-bell-ringing/
60•ascertain•9h ago•26 comments

FLX1s phone is launched

https://furilabs.com/flx1s-is-launched/
208•slau•18h ago•146 comments

Lidar, optical distance and time of flight sensors

https://ams-osram.com/innovation/technology/depth-and-3d-sensing/lidar-optical-distance-and-time-...
3•mahirsaid•2d ago•0 comments

Ask HN: Radar and radio failures at Dallas area airports

20•pdonner•3h ago•9 comments

Learning Languages with the Help of Algorithms

https://www.johndcook.com/blog/2025/09/17/learning-languages-with-the-help-of-algorithms/
9•ibobev•3d ago•1 comments

Escapee pregnancy test frogs colonised Wales for 50 years (2019)

https://www.bbc.com/news/uk-wales-44886585
111•Luc•4d ago•47 comments

Solving a wooden puzzle using Haskell

https://glocq.github.io/en/blog/20250428/
57•Bogdanp•4d ago•18 comments

After Babel Fish: The promise of cheap translations at the speed of the Web

https://hedgehogreview.com/issues/lessons-of-babel/articles/after-babel-fish
50•miqkt•2d ago•10 comments

Vapor chamber tech keeps iPhone 17 Pro cool

https://spectrum.ieee.org/iphone-17-pro-vapor-chamber
106•rbanffy•15h ago•229 comments

MapSCII – World map in terminal

https://github.com/rastapasta/mapscii
155•_august•2d ago•19 comments

Images over DNS

https://dgl.cx/2025/09/images-over-dns
168•dgl•17h ago•45 comments

PYREX vs. pyrex: What's the difference?

https://www.corning.com/worldwide/en/products/life-sciences/resources/stories/in-the-field/pyrex-...
130•lisper•23h ago•101 comments