News for hackers. Stuff that matters.
Re:A 40ms Go garbage collector pause caused by swap by jacobgold on Monday October 05, 2026 @01:24AM (#49960986)
"It hurts when I do this"

"Stop doing that"

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

Re:A 40ms Go garbage collector pause caused by swap by delamon on Monday October 05, 2026 @01:55AM (#49961142)
This is not entirely correct. If you care about latency, then it doesn't matter on which major fault your application gets paused. Disabling swap protects you from data pages being evicted, but code pages can still be paged out.

If you care about latency, mlock() your memory, do not disable swap. Swap is good and gives the kernel an equal opportunity to evict data and code pages.

Re:A 40ms Go garbage collector pause caused by swap by xxs on Monday October 05, 2026 @02:29AM (#49961335)
For GC enabled languages swap is universally bad. Some gc-pauses are indistinguishable from a system crash. It's a side effect on not having tightly specified memory limits.

I'd rather have applications be oom_killed than having them swap out, the former is rather obvious and demands action.

Re:A 40ms Go garbage collector pause caused by swap by delamon on Monday October 05, 2026 @02:35AM (#49961376)
If you want you application to stay in memory, then make it explicitly with mlock()/mlockall().

Disabling swap will just moves pressere elsewhere: to code pages. And evicted code page is no better: full stall while kernel loads that page from disk.

Re:A 40ms Go garbage collector pause caused by swap by xaduha on Monday October 05, 2026 @03:32AM (#49961763)
I think discussing it in a vacuum is pointless, it should depend on how much memory you have. You can have a swap on, but with a low `vm.swappiness` number.
Re:A 40ms Go garbage collector pause caused by swap by blueflow on Monday October 05, 2026 @04:46AM (#49962259)
The point is that disabling swap does not prevent page eviction. Instead of swap, this discussion should be about the page cache.
Re:A 40ms Go garbage collector pause caused by swap by xaduha on Monday October 05, 2026 @05:19AM (#49962462)
Surely as long as it is all in memory these pauses are not going to be that significant, details like that should be left for the language devs to optimize.

You can tell an average Golang user to use mutexes, you shouldn't be telling them to lock memory manually.

Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Monday October 05, 2026 @11:20AM (#49966016)
vm.swappiness doesn’t work the way most people assume it does. and it is ignored under heavy memory pressure.
Re:A 40ms Go garbage collector pause caused by swap by xaduha on Tuesday October 06, 2026 @04:52AM (#49975948)
Maybe, but it still there and probably has a different value between distros as well. Default value is 60, what is that good for exactly?

If you're in a position where you still want swap to be there, but only used in extreme situations, then you should set it yourself. Otherwise disable swap or switch a language.

Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Tuesday October 06, 2026 @05:06AM (#49976037)
What do you think this value of 60 means? Also, as I said, in extreme situations, when the system is right before invoking the OOM killer, swap is used regardless of `vm.swappiness` setting.
Re:A 40ms Go garbage collector pause caused by swap by xaduha on Tuesday October 06, 2026 @08:38AM (#49977518)
> What do you think this value of 60 means?

Some arbitrary number.

https://docs.kernel.org/admin-guide/sysctl/vm.html#swappines...

> At 0, the kernel will not initiate swap until the amount of free and file-backed pages is less than the high watermark in a zone.

I don't see a reason why the default shouldn't be 0 then on modern systems.

Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Wednesday October 07, 2026 @12:44PM (#49995305)
Value 60 is not an arbitrary number. It makes the kernel reclaim 140 file pages for each 60 swapped-out anon pages. This proportion is supposed to reflect the relative performance cost between sequential file access and random swap I/O on HDD. For SSDs, the value 100 is more appropriate.

> I don't see a reason why the default shouldn't be 0 then on modern systems.

The zero value makes reclaim very unbalanced and is not appropriate for generic systems. This will cause the kernel to discard all the page cache, slowing down the system with uncached I/O, while keeping all unused anonymous pages in memory.

Re:A 40ms Go garbage collector pause caused by swap by xaduha on Wednesday October 07, 2026 @01:18PM (#49995830)
I don't get the point that you're even arguing. Are you saying that 60 is fine as a default? Or are you saying that people should even think about vm.swappiness because it doesn't matter? The alternative here is to disable swap completely, that's what started this whole thread.

> If you care about latency, disable swap.

Re:A 40ms Go garbage collector pause caused by swap by yvdriess on Monday October 05, 2026 @03:22AM (#49961693)
Disabling swap disables loading a process' binary to memory? Or do you mean that evicted code pages will need to get loaded from disk every time.
Re:A 40ms Go garbage collector pause caused by swap by dwattttt on Monday October 05, 2026 @04:00AM (#49961954)
There are good sibling replies answering your question, but to give a specific example: if your application writes something but then doesn't need it anymore. Since we're talking about go, perhaps a data structure you need also holds a reference to data you don't need.

When the kernel needs memory, it goes hunting for a page it can discard. But since that's transparent, the kernel can only discard a page if it knows it can get it back (after all, it's still got valid data on it, and maybe you'll try access it again later).

If there's swap, a page full of stale/unneeded data can be written out to swap. But if there's no swap, your page of "dangling data that you'll never use, but is still valid & referenced" can't be discarded; the kernel doesn't know you won't want it later, and it can't recreate the page if it throws it away.

So like sibling said, at that point it has to find other pages it can evict from memory, ones that _do_ have somewhere persistent they can be written out to. Pages loaded from binaries on disk satisfy that, so those will get dropped instead.

Re:A 40ms Go garbage collector pause caused by swap by xxs on Monday October 05, 2026 @04:24AM (#49962113)
For JIT languages most of the code is dynamically generated, not available to be loaded back from the disk. Morealso, the allocations do happen at large chucks where the oom_killer also happens, so it's significantly less of an issue.
Re:A 40ms Go garbage collector pause caused by swap by dwattttt on Monday October 05, 2026 @05:16AM (#49962444)
That doesn't necessarily improve matters. Now any code that gets JIT'd is also going to be permanently pinned in memory too, no matter whether it'll get used again, if you don't have swap.
Re:A 40ms Go garbage collector pause caused by swap by xxs on Monday October 05, 2026 @11:06AM (#49965831)
Under normal conditions the code gets jitted after some use... and the VM is free to deoptimize it when it reaches its max allowed generated cache.

The only code in danger is the one from libraries (e.g. zlib)

Re:A 40ms Go garbage collector pause caused by swap by delamon on Monday October 05, 2026 @03:40AM (#49961809)
There are two types of pages: anonymous and mapped from files. The code pages are mapped from a binary; they are not very special.

Under memory pressure, the kernel evicts less popular pages from memory. If a page has been mapped from a file, it is dropped (if dirty, then it is written out first). If it is needed later, the kernel can read it back from the file. If a page is anonymous (read: heap page), then there is no backing file and the kernel copies it to swap before dropping it. This is swapping.

So, what happens if you disable swap and the kernel is low on memory? What can it evict? Anonymous pages cannot be evicted: there is no swap to put a copy in. The only choice the kernel has is to evict pages that are mapped from files. Those include pages mapped from the executable. You don't eliminate stalls by disabling swap, you just move them elsewhere: the kernel will page out code and your app gets paused whenever the execution flow hits such a page.

Re:A 40ms Go garbage collector pause caused by swap by mrob on Monday October 05, 2026 @04:08AM (#49962008)
>So, what happens if you disable swap and the kernel is low on memory? What can it evict?

Your userspace early OOM killer triggers and lets you know you're trying to run more than will fit in memory so you don't do it again. (In my experience, the kernel OOM killer can't be trusted to kill processes soon enough.)

Re:A 40ms Go garbage collector pause caused by swap by yvdriess on Monday October 05, 2026 @05:01AM (#49962341)
Thanks for the clarification, learning everyday.

I haven't had to analyze the performance of no-swap processes before. My assumption is that code is hot enough to avoid eviction and that evicted code pages are rather the exception. To strong-man the argument, I can imagine long running complex (bloated) services could have parts that are not touched unless a specific request comes in.

Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Monday October 05, 2026 @11:16AM (#49965964)
You are missing that the file LRU is not only the code pages or memory mapped files but all file data. The active code pages are specifically excluded from being discarded during the reclaim process.
Re:A 40ms Go garbage collector pause caused by swap by FooBarWidget on Monday October 05, 2026 @03:02PM (#49969015)
I wish this is true but evidence is against you. Just try testing memory pressure on a no swap system. You will see that the system grinds to a half for a few minutes before you even get to an OOM event.
Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Monday October 05, 2026 @03:38PM (#49969526)
Could you clarify what exactly is "not true"? Also, could you explain what exactly your evidence proves? What do you think happens when the system becomes unresponsive under memory pressure, and why?
Re:A 40ms Go garbage collector pause caused by swap by FooBarWidget on Tuesday October 06, 2026 @02:44AM (#49975060)
> The active code pages are specifically excluded from being discarded during the reclaim process.

This is not true, or the system wouldn't grind to a halt due to having to reload code pages (even those that are recently in use) from disk over and over.

For example, key presses and output streaming in SSH become unresponsive. The code pages for handling key presses and output streaming are obviously in use — I just used them!

Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Tuesday October 06, 2026 @04:37AM (#49975832)
I'll try again. Why do you think that unresponsiveness is caused by code pages being discarded? Do you have evidence for this? Have you considered that there are other mechanisms that cause programs to become unresponsive under memory pressure?
Re:A 40ms Go garbage collector pause caused by swap by FooBarWidget on Tuesday October 06, 2026 @11:37AM (#49980105)
It's the explanation that I've read when scouring forums for reasons why it happens. I'd love to hear alternative explanations and how to measure/verify them. But the measurement tools also become unresponsive so I can't check anything.

But frankly, as a user I don't really care what the real technical reason is. I just don't think the system should become unresponsive for minutes on end during memory pressure. Just OOM-kill earlier, when it's supposed to.

Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Wednesday October 07, 2026 @01:45PM (#49996232)
The assumption that a system gets unresponsive due to code pages being reclaimed doesn't make any sense. It is a common myth, cargo-cult knowledge. The kernel doesn't discard any active referenced pages at all, and the active code pages are the last that are getting reclaimed.

The proper explanation is relatively straightforward. Normally, any memory request for a process is served by getting a page from the free memory pool. But when the system free memory goes below the low watermark (calculated from vm.min_free_kbytes and vm.watermark_scale_factor), the kernel stops giving the pages from the free memory pool and instead goes into direct reclaim, trying to find unused pages. While the kernel does reclaim, the allocating process remains stalled. The kernel can't return control to the process - there is no page mapped that the process tried to access. This applies to any types of pages - anon, file-backed, code pages. So, under the condition of free memory below the low watermark, any process trying to allocate memory gets stalled. This is measured as memory pressure stalls (PSI) in /proc/pressure/memory.

The problem with the system being stuck in an unresponsive state is that the design choice for the kernel OOM handling is to be optimistic and keep the workload running as long as the kernel is making any progress reclaiming pages. The direct reclaim process needs to fail to make any progress 16 times before the OOM killer is invoked.

The solution is to use cgroup memory limits to avoid getting into the situation of memory exhaustion and use user-space oomd to recover from this situation earlier.

Re:A 40ms Go garbage collector pause caused by swap by FooBarWidget on Friday October 09, 2026 @03:12AM (#50017117)
So you're saying processes are stuck for minutes on end at trying to get memory from the kernel? I find this implausible because relatively simple processes such as ssh and bash shouldn't be getting memory from the kernel at a continuous basis. Unless they're suddenly processing a lot of new data (like me trying to cat /dev/urandom), they should be spending most of the time working with the memory they already have. Especially when all I'm doing is pressing keystrokes in ssh+bash, not even hitting enter. Note that malloc doesn't ask memory from the kernel at every call. Glibc malloc is (in)famously stubborn with caching memory it has gotten from the kernel, hesitant to release it back to the kernel.

Any repeatable way to prove your thesis or disprove the trashing-code-pages thesis?

Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Friday October 09, 2026 @03:42AM (#50017345)
You seem to confuse user-space memory allocations (malloc) with the kernel memory page allocation and mapping. The processes don't need to allocate any new memory with malloc. They get stuck when accessing memory that is not mapped to a physical memory page or when they enter a syscall that needs in-kernel memory allocation.
Re:A 40ms Go garbage collector pause caused by swap by FooBarWidget on Friday October 09, 2026 @09:13AM (#50020024)
Ok fine. But again: any repeatable way to prove your thesis or disprove the trashing-code-pages thesis? And how to do this when the system is freezing up?
Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Friday October 09, 2026 @11:54AM (#50022342)
I have already pointed you to /proc/pressure/memory. Prometheus node_exporter tracks it as node_pressure_memory_waiting_seconds_total and node_pressure_memory_stalled_seconds_total. You'll see them spiking when you experience stalling.

You can also track variables from /proc/vmstat exported as node_vmstat_allocstall_(normal|dma32|movable), node_vmstat_pgscan_direct, node_vmstat_pgsteal_direct - you'll see them spike when the system enters direct reclaim.

Install and configure systemd-oomd and track its log - it will activate on memory pressure.

To track code page eviction/re-faults specifically, you'll need to write some eBPF code, there are no direct measurements for this available.

Re:A 40ms Go garbage collector pause caused by swap by delamon on Monday October 05, 2026 @05:00PM (#49970669)
Perhaps I wasn't clear, but I did say that all file pages are treated equally. I would assume that page with PC is excluded from reclamation process, but other code pages are valid targets.
Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Monday October 05, 2026 @05:05PM (#49970724)
All code pages in the active file LRU are excluded from the reclaim.
Re:A 40ms Go garbage collector pause caused by swap by delamon on Tuesday October 06, 2026 @01:49AM (#49974690)
All recently referenced code pages in the active LRU are excluded from reclaim.

Code pages are paged in on demand: for any sufficiently large binary just some code pages will be mapped right after start. Given enough memory pressure, the active LRU will be shrunk often enough to push code pages out of the active LRU and then they are eventually evicted.

I'm not aware how it works in modern MGLRU, but I would assume similar ovservable behevior holds.

Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Tuesday October 06, 2026 @04:58AM (#49975984)
Active code pages with the "Accessed" bit set are specifically excluded from being moved to inactive LRU when active LRU is being shrunk. Instead, they are moved to the head of the active LRU. All other pages are moved from active LRU to the inactive LRU unconditionally, even if they have the "Accessed" bit set. So, no, the active code pages are not going to be eventually evicted.
Re:A 40ms Go garbage collector pause caused by swap by delamon on Tuesday October 06, 2026 @06:56AM (#49976718)
I think we are saying the same thing. Active code pages are not evicted; non-active code pages (that is, pages that had not been accessed since last time of active LRU shrinking) may be evicted.
Re:A 40ms Go garbage collector pause caused by swap by MobiusHorizons on Monday October 05, 2026 @03:40AM (#49961808)
Under memory pressure the system will free the ram used for code pages because it can always load them back from the executable on disk. It’s the same virtual memory mechanism as swap but without needing dedicated swap space. The op is saying disabling swap doesn’t prevent long pauses during memory pressure, because the system just swaps code out instead of dynamically allocated memory.
Re:A 40ms Go garbage collector pause caused by swap by FooBarWidget on Monday October 05, 2026 @02:55PM (#49968922)
While I've seen systems grinding to a halt due to evicting code pages, the idea that disabling swap distributes load between code pages and data pages makes no sense to me. Data pages are also disk backed, so they could also be evicted at any time. Why would data pages be written to swap if they came fron the disk in the first place?

So that only leaves anonymous data pages, i.e., regular data in memory, that could be swapped. Ok but you're not easing the load on code pages, those still get evicted during memory pressure whether you have swap or not.

Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Monday October 05, 2026 @04:32PM (#49970273)
The assumption that data pages can always be easily discarded is incorrect. Dirty data pages can't be discarded until they are written back. Recently accessed data pages are also not discarded until all inactive data and code pages are discarded.
Re:A 40ms Go garbage collector pause caused by swap by jacobgold on Monday October 05, 2026 @06:05PM (#49971514)
FYI: This `delamon` account seems to be meat proxying us. Just relaying garbage AI answers without understanding his own words. Doubt he's ever used mlock himself for anything.

His reply below was presumably killed by mods for doing this: https://news.ycombinator.com/item?id=49970841

Re:A 40ms Go garbage collector pause caused by swap by delamon on Tuesday October 06, 2026 @01:02AM (#49974393)
I'm not. If you think that I said something not correct, do correct me. We're all learning.
Re:A 40ms Go garbage collector pause caused by swap by jacobgold on Tuesday October 06, 2026 @11:08AM (#49979649)
I see that you've rewritten your AI generated reply there. So when have you used mlock in production for Go services, the way you're advising others to do? What were the circumstances?
Re:A 40ms Go garbage collector pause caused by swap by delamon on Tuesday October 06, 2026 @02:16PM (#49982075)
I did not rewrite anything.

Yes, I was and still running go and zig binaries with mlockall. Apps have large in-application caches and also perform large streaming reads of datasets bigger than available RAM. If it happens that several streaming reads running at same time, they push memory pressure hard enough, so kernel swaps out cold parts of in-app caches. That later leads to elevated latencies => mlockall to avoid that.

Re:A 40ms Go garbage collector pause caused by swap by torginus on Monday October 05, 2026 @04:20AM (#49962094)
Please read the article. The issue was caused by swapped out metadata being read in a critical section, not typical heap traversal shenanigans.

This is not exclusive to GC, any program that reads a rarely accessed piece of memory is vulnerable to this.

Re:A 40ms Go garbage collector pause caused by swap by MrDrMcCoy on Monday October 05, 2026 @11:26PM (#49973803)
Run your process in a cgroup that's set to disallow swap, then. The rest of your system benefits from having swap. This was an easy and safe thing that required minimal convincing to roll out to production at my company.
Re:A 40ms Go garbage collector pause caused by swap by silon42 on Monday October 05, 2026 @03:39AM (#49961800)
It would probably make sense to disable swapping "code" also for non-GC languages (or at least do it as a last resort).
Re:A 40ms Go garbage collector pause caused by swap by quotemstr on Monday October 05, 2026 @02:54AM (#49961490)
Plus, it wouldn't necessarily be that hard to selectively mlock the pages accessed in STW critical regions.
Re:A 40ms Go garbage collector pause caused by swap by jacobgold on Monday October 05, 2026 @10:43AM (#49965536)
No, do not try to use mlock to avoid swapping, except in very specific scenarios. That way lies madness.

To be more explicit about my advice: disable swap and ensure you have sufficient memory for your workload.

Your 14 MB Go binary is not the source of your memory pressure. Your memory pressure is coming from the allocated anonymous pages supporting your programs data structures on the heap.

Have sufficient memory for your workload, monitor it, and let the Go GC and kernel manage memory normally. This will work exactly as you'd hope.

Re:A 40ms Go garbage collector pause caused by swap by delamon on Monday October 05, 2026 @12:17PM (#49966847)
Can you elaborate, why mlock is bad? And how disabling swap is better?

You are correct, that 90MB Go binary is not major memory consumer. But it doesn't matter what is the source of memory pressure. What matters is what kernel do under pressure. If you disable swap, then under memory pressure kernel can only pageout memory mapped files, no matter how small they are. And your code will be paged out.

Re:A 40ms Go garbage collector pause caused by swap by jacobgold on Monday October 05, 2026 @01:43PM (#49967965)
We're trying to solve a problem: we don't want huge latency spikes caused by swapping memory to disk. The only good solution to that is to have sufficient RAM. It's that simple.

Introducing mlock is operationally annoying and trying to solve the wrong problem. It requires elevated container permissions, it's not something your SRE team is going to expect, few programs do it, and it has all kinds of technical implications and interactions with kernel OOM system, forking, the Go GC, etc.

And nothing about mlock solves the problem of having insufficient RAM for your workload.

There are very specific scenarios where mlock is exactly the right solution but the typical Go HTTP service is not one of them. The KISS principle applies.

Re:A 40ms Go garbage collector pause caused by swap by delamon on Monday October 05, 2026 @05:12PM (#49970841)
You are correct, of course: if your application needs 2x RAM and you only have 1x, then there is no way mlock can magically save you from swapping. What it gives is protection from a noisy neighbour.

The good thing is that mlock/mlockall does not require elevated permissions. But it is bounded by the memlock rlimit, which you need to configure for the container. If you don't want paging/swapping, set it equal to the total memory you give to the container and call it a day.

I'm curious about the technical implications. Which ones do you have in mind?

To be honest, I don't quite see how mlock makes it complex. It's quite the opposite: it has very clear semantics and makes reasoning about system behavior simple. Disabling swap is the opposite: you're making a bet and hoping it works.

Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Tuesday October 06, 2026 @04:58AM (#49975985)
In simple cases, instead of using `mlock` just set cgroup memory.min
Re:A 40ms Go garbage collector pause caused by swap by delamon on Tuesday October 06, 2026 @07:14AM (#49976846)
That would work reasonably well. With one important caveat: memory controller tracks all memory, including page cache. Setting memory.min will prevent reclaim of page cache charged to that cgroup, as long as total memory usage stays below the limit.
Re:A 40ms Go garbage collector pause caused by swap by man8alexd on Wednesday October 07, 2026 @02:19PM (#49996729)
Another important caveat: people keep assuming that page cache can be easily discarded and it doesn't count towards the working memory set. Then they get surprised by unexpected OOMs. There is a decade-old issue on Kubernetes https://github.com/kubernetes/kubernetes/issues/43916
Re:A 40ms Go garbage collector pause caused by swap by lokar on Tuesday October 06, 2026 @10:52AM (#49979394)
Using mlock on all the code and static pages in a binary at startup is not hard or risky.
Re:A 40ms Go garbage collector pause caused by swap by jacobgold on Tuesday October 06, 2026 @11:10AM (#49979681)
I didn't claim it was hard or risky.

Have you actually done this yourself for Go programs that you've deployed into production? If so, what were the circumstances? Was it your solution to latency spikes?

Re:A 40ms Go garbage collector pause caused by swap by lokar on Tuesday October 06, 2026 @12:00PM (#49980432)
It was the default for every production binary. I read the c++ implementation, not really that crazy. It was for latency, and in some cases (with other measures) to keep the binary running if the disk failed.

The alternative (which I’ve also done), is to put the binary in tmpfs, after making sure it’s not bloated.

Re:A 40ms Go garbage collector pause caused by swap by jacobgold on Tuesday October 06, 2026 @02:16PM (#49982079)
Your Go binary was being swapped out due to memory pressure, causing latency, and using mlock was your fix for this problem?

Or did someone else do this work and you assumed it was effective? Or did you personally implement this change and then validate that the before/after metrics improved as a result?

Re:A 40ms Go garbage collector pause caused by swap by lokar on Tuesday October 06, 2026 @03:28PM (#49982890)
As I mentioned, it had long been the standard, the core library gave you a simple flag to use. I would occasionally find cases where it was not set correctly and you could see it causing short spikes (the simplest way to measure is something like a pacemaker task on an event loop, or task scheduling delay since it strips out other variables).

The impact is pretty obvious.

Re:A 40ms Go garbage collector pause caused by swap by jacobgold on Tuesday October 06, 2026 @04:39PM (#49983773)
Alright, so you didn't implement it. And you're describing a "pacemaker task on an event loop"? That doesn't sound like a Go program at all, where we don't have a single event loop to measure and we have built-in runtime metrics.

Just seems kinda weird to give advice on forums when you're not speaking from actual relevant experience. I'm getting meat proxy answers and confident replies from people who've never done what they're suggesting others do.

Re:A 40ms Go garbage collector pause caused by swap by lokar on Tuesday October 06, 2026 @04:48PM (#49983886)
As I said, I was more familiar with the C++ implementation, but we had it for every language in use.

I ultimately change the runtime environment to no longer allow any local durable storage for job (with a handful of exceptions), including swap and binary staging. The fact that almost everything was already using mlock made the transition simpler.

Re:A 40ms Go garbage collector pause caused by swap by inkyoto on Tuesday October 06, 2026 @08:37PM (#49986306)
I am struggling to understand which specific problems that pertain to the use of mlock(2) you are alluding to.

Java is an example of the most widely deployed garbage-collected language in production around the world, deployment number and scale-wise. Most of the world's missing critical systems today run on Java. Java can run as a process or in a container. Containerised Java deployments do not require unique operational SRE arrangements, nor do they require any unique/dedicated permissions to run in a container.

Upon start-up, the JVM checks whether the system has sufficient memory to satisfy the max heap size constraint, and it will duly fail to start up if not. Afterwards, the JVM will allocate the required amount of memory, and it will mlock it. Multi-terabyte[0] RAM JVM deployments[1] do exist and exhibit exactly the same behaviour. Java has had such behaviour since its inception.

The prevailing number of Java deployments run on systems with swap enabled, and, from the operational standpoint, it is pure insanity to run mission critical (banking, payments, government etc) apps without a swap. Swapless JVM deployments are virtually unknown or are operational negligence.

The principal exceptions for running a JVM on a system without a swap are hard real-time scenarios and embedded systems. That is it.

What makes Go different or unique that it can't use mlock and that it would require special permissions or unique/distinct SRE/operational arrangements? It is eluding me.

[0] The Azul JVM supports up to 20 Tb of RAM which it will mlock.

[1] See the published Azul/Forrester evidence for reference. It is an interesting read regardless of the mlock debate.

Re:A 40ms Go garbage collector pause caused by swap by lokar on Wednesday October 07, 2026 @12:27PM (#49995049)
I'm pretty sure almost all of our (very large) java systems were running without swap (it took effort to enable swap for your jobs, and eventually was almost impossible).

Java is generally simpler to run without swap since you know in advance how large the heap can be, so it's just a small amount of variability in the jvm internals to consider.

You don't want swap of heap/stack, or paged out code pages. The latency hit is pretty bad even for non-"real"-time systems. And really, you should know how much memory you are going to use (to within some fair bounds).

Adding only a small amount of swap for very cold pages does not save very much ram. And using it for anything else is very bad for interactive systems. In the same vein paging out code pages you won't ever run just does not save very much.

It requires some discipline in monitoring, load testing, etc, but you should be doing that anyway.

Re:A 40ms Go garbage collector pause caused by swap by tliltocatl on Monday October 05, 2026 @02:30PM (#49968608)
Fun fact: being able to run garbage-collected languages (i. e. Lisp) was one of original motivations for adopting demand paging.