
It's a mystery to me why modern computers don't come with disk activity lights, as this problem we didn't need dock widgets to solve 20 years ago when literally every computer came equipped with one. If you have a dock widget that tells when you are going above 50% swap usage, you can close some tabs before it gets to be an unrecoverable situation. So, find a way to stay ahead of the kernel and know better. The kernel does really not want to kill off your processes, and it has more opportunities than ever to ensure it keeps too many balls in the air when you have asked it to do so. I don't fully understand this part, but I suspect the answer is "try to use Swap less, and be aware of when you are using it." You may find your cache recycle rates going through the roof because things can be paged out to disk and re-loaded faster than should be possible. If the solid disk is 50x faster than the spinning disk that the swap was originally designed to use, then swapping will cost less overall and the heuristic will lean on it as a strategy to keep the OOM killer away even more often. The kernel is making decisions based on a heuristic which is complicated and well-documented, but inscrutable. The second worst thing that you can do is put your swap on fast SSD or NVMe, and it's not why you think. This will improve your "nearly out of memory" performance. Having some swap gives the kernel something else to evict, so have a healthy amount of swap and Linux will find the occasion to use it for the least frequently used pages that are not already on disk. (Wait, pages back to disk? I told you I didn't have swap) Yes – the linux kernel can page things back to disk even if you don't have swap, remember all of the binaries you're running have originally come from that disk, and the kernel knows it doesn't strictly need to have them in memory until they are volatile, or you tried to read those pages again. "The Linux kernel has overcommit baked into the fiber of its being." I've begun to understand that this idea is so deeply engrained in the kernel that in a multi-tenant or desktop workstation, you simply can't extract it back out and "just provide enough RAM," unless you know the performance characteristics and you really mean it when you say "that should be enough RAM." If you don't have any swap and the kernel starts to run out of memory, it's going to start evicting whatever pages it can back to disk. I've been in a couple of interesting discussions about Linux memory management lately that enlightened me somewhat, and I won't claim to be an expert now, but I've been around the low-memory block enough to understand now that, there's no simple right answer to the question of "Do you have swap?"

Every individual page fault is handled quickly, there's just waaaaaay too many of them. The kernel is sitting there trying every trick in the book, and the OOM killer doesn't see what's happening. On newer SSDs, the disks are too fast to trip the OOM killer into action! This is why, when this problem manifests, your disk activity light goes on solid, even if you don't have swap enabled. These heuristics, however, are expecting these page-in and page-out operations to be slow (as they were on HDDs). The out-of-memory (OOM) killer heuristically watches the system and kills off processes that cause memory pressure problems. Performance sucks terribly, but it keeps trucking on. Or, in the VirtualBox case, the mmap'd disk image can be removed mostly from RAM and have those pages loaded from disk as needed.

Things like shared libraries can get paged out! If one of those pages is requested, it can be reloaded from disk. when the usual candidates run out, things have to get more clever. If swap is enabled and not saturated, paging out some data to disk is a likely option.
Optimize my mac for productivity free#
To elaborate a bit based on my understanding of the issue: VirtualBox seems like a great program to tickle the issue.ĭuring a memory pressure scenario, the kernel starts looking around for things that it can get out of RAM to free up space.
