logoalt Hacker News

A 40ms Go garbage collector pause caused by swap

94 points • by shellpipe • today at 1:11 AM • 91 comments • view on HN

Comments

nasretdinov • today at 6:34 AM

Unfortunately that's somewhat expected - regardless of implementation, the sole fact that the GC needs to somehow walk the entire tree to trace still referenced sections makes swap highly impractical -- even if you had not had 40ms stop-the-world pauses the LRU cache used by swap would get thrown away at every GC.

I believe that's actually the same reason why Apple stopped using GC in their frameworks in favour of automatic reference counting.

➕ show 5 replies
jacobgold • today at 5:24 AM

"It hurts when I do this"

"Stop doing that"

If you care about latency, disable swap. System wide or for the specific the cgroup.

➕ show 1 reply
xavdid • today at 6:27 AM

Discord learned this back in 2020 and published a great blog post on it: https://discord.com/blog/why-discord-is-switching-from-go-to...

➕ show 2 replies
pizlonator • today at 4:31 AM

Is there a reason why Go isn’t using on the fly GC, where there’s no STW at all?

➕ show 1 reply
soltanov • today at 4:50 AM

A GC latency SLO should include operating-system memory pressure. Otherwise, a page-fault problem will look like a collector problem and lead to the wrong fix.

➕ show 2 replies
Gabrys1 • today at 6:45 AM

I started wondering if there could be swap-aware GC, like first make the required page swapped in (not that there's any obvious API for that...) and only then pause the world?

➕ show 3 replies
imclaren • today at 6:53 AM

This. Memory bloat bugs are relatively easy to fix in Go, but sometimes it’s an adventure to remove swap bloat. And I think it’s worth removing all swap bloat!

faangguyindia • today at 6:24 AM

I use Go where i'd use Node, Ruby or Python.

I use Rust where i need low latency.

ahmedmostafa16 • today at 5:50 AM

The nasty bit is that swap doesn't just make the allocation slower; if GC metadata gets paged out, you have turned memory pressure into a stop-the-world latency spike.

charcircuit • today at 8:30 AM

If memory is paged out we could defer cleaning out garbage from it.

➕ show 1 reply
amelius • today at 8:00 AM

When my system starts using swap space, I've already given up all hopes of a decently running system, so IMHO this particular "bug" doesn't matter much.

I'm being downvoted, but honestly, is anyone always testing their software while swap is active?

raverbashing • today at 5:54 AM

I don't get why people do not prefer reference counting, it has more predictable runtime performance

(though of course a swap is a swap - but you can "trigger" it depending on your memory or file access pattern)

➕ show 5 replies
loeg • today at 7:06 AM

So, uh, mlock those pages?

octoberfranklin • today at 4:30 AM

Yet another reason why "no runtime" is such a huge advantage.

➕ show 1 reply
palaceme • today at 8:30 AM

[flagged]

lin7c • today at 6:22 AM

[flagged]

truth_seeker • today at 4:35 AM

What is stopping the author to use latest version of Go and Linux Kernel ?