Linux Ate My RAM
linuxatemyram.com
linuxatemyram.com
> available memory (or "free + buffers/cache") is close to zero
> swap used increases or fluctuates
> dmesg | grep oom-killer shows the OutOfMemory-killer at work
How about this one: the entire system becomes so unresponsive that even a VT switch takes multiple minutes to process, never mind actually logging in and running diagnostics. I don't know exactly why, but I used to get this pretty regularly on a 2 GB laptop if I did the wrong thing in Firefox. The workaround was installing earlyoom [1] (after which the tab would crash instead), although I assume there's some kind of sysfs parameter that I might have tweaked instead.
Thankfully that system wasn't mine so I just got a laugh of this situation.
Still, 20 years later I still can't wrap my head around why Linux still needs oom-killer when Windows can run just fine without such functionality.
malloc failing seems like a much simpler indication of memory pressure than the alternatives like PSI.
this would work if there was a cgroup virtual address space controller, but I think those have been proposed but never merged.
As for Windows, the big difference is no fork()
Missing the whole picture. fork() isn't the real reason, it's that Windows guarantees memory or no memory while Linux by default overcommits (both of which isn't necessarily a bad thing - it's just different ways of managing a limited resource). NT could implement (and does, it's just not exposed in Win32 API) a non-overcommiting fork() and its memory algorithms will be the same afterwards.
Consider the scenario of a process with 51% of memory usage, what happens when it forks? The system pretty much _has_ to allow overcommit at this point, otherwise fork() will fail.
Now, you can change the accounting to say that when the process modify a memory page (thus creating a copy), we'll check that there is enough memory _then_.
That would move the "danger" of memory being yanked from underneath you. But that means that a process that calls fork() may then run into a problem some indeterministic time later.
That is kind of a killer.
ERRORS
The fork() function will fail if:
[EAGAIN]
The system lacked the necessary resources to create another process, or the system-imposed limit on the total number of processes under execution system-wide or by a single user {CHILD_MAX} would be exceeded.
The fork() function may fail if:
[ENOMEM]
Insufficient storage space is available.
The POSIX specification is clear on this: you can hard fail. Also, as an aside malloc() can also fail and the program must be able to handle that. Unfortunately for some programmers (mainly coming from GC-aware languages), they just assume that it won't fail. (Also, most rely on fork-exec but there's posix_spawn() for de novo execution).Again, NT does indeed have a fork function, however the Windows API doesn't expose that (and this is the hack Cygwin used when forking), but it's designed to fail instead of overcommit when all memory is exhausted.
In most GC languages I've used, if malloc fails for some reason (we rarely call it ourselves directly) an error happens and, unless handled, the whole app crashes. Which is fine, BTW, because I much prefer an app that crashes and dies to one that does things with the assumption something that didn't work did.
My Windows 10 installation just BSODs when Firefox fills up the RAM if the page file is disabled.
I'd much prefer the OOM killer.
I never had that happen. What actually happens is firefox just crashes, or the screen goes blank for a few seconds while the graphics driver resets.
But even the graphics driver crashing is already bad enough. If there's not enough memory, offending programs should be crashing, not drivers.
(and yes, ram sticks are good and verifed with memtest86 and testmem5)
Ouch. Never run Windows without the swap. It can be as small as the system allows (AFAIR 16Mb for Win7), but it should be enabled.
While this is the obvious footgun the problem is nobody ever tests with the swap disabled.
I've seen very weird behaviour without the swap, the most funny one was when some 3D game (sadly don't remember the name) internal timer went completely nuts without the swap and game was working just fine with the swap enabled.
Funny thing is I clearly remember Windows 7/8.1 showing a warning about memory running low and then killing Firefox. On Windows 10 they managed to bork that, too.
seriously asking. if you're fiddling with that in the 21st century you are Doing It Wrong.
Processes may crash, but kernel shouldn't, period.
If it crashes today with no swap while running 5 programs, it'll crash tomorrow with swap enabled while running 10 programs.
a requirement of the kernel is that there is virtual memory space. the page file is part of what enables that on Windows.
on Win 8.0 (I think) and before, the page file was nowhere nearly as vital, and you could turn it off in certain situations. an educated user could use their knowledge to know when it was ok to turn it off.
new versions of Windows change many things; they are not simple reskins of previous windows versions. the kernel and low level stuff changes a lot, version to version. knowledge that was valid in Windows XP is very likely no longer valid on Windows 10 or 11, and certainly is no longer valid in all situations.
keep your knowledge up to date. even things that appear to change relatively slowly, such as Windows, experience a lot of churn at lower levels. the APIs may not change, but their implementations often do.
earlyoom kills stuff sooner instead of trying this for a long time. I’ve also heard that some people have had some success by locking base system libraries and executables in memory.
(Please let me know if this explanation is not correct or there are other solutions worth trying)
I’ve never been able to track down the exact cause.
It looks like 12309 https://web.archive.org/web/20140816132654/https://bugzilla....
Free memory is useless memory. You paid for it, let it work for you.
> wait you can actually download more ram if you set up google drive as swap space
* https://www.techradar.com/news/software/operating-systems/ho...
The most recent instance was just a month ago.
Though I like when I ask people to explain why their app/service should /not/ use free and abundant memory to serve their users. That short-circuits their brain.
here's a reason: because if chrome decides to eat 1GB of memory per tab, and I only have 8GB of ram, then I can't run anything else if I have more than a few tabs open. If chrome could have gotten by with 0.2GB per tab, then it using "abundant memory to serve their users" doesn't actually serve their users, it makes their experience worse. I suppose the system could work if there was some mechanism for the OS to demand that a program free up memory, but I haven't seen that in practice.
> I suppose the system could work if there was some mechanism for the OS to demand that a program free up memory, but I haven't seen that in practice.
Memory mapped files works exactly like that, IIRC.
Windows does it right. On the task manager graph, disk cache is not counted as used memory. And for experts, there's a separate "memory composition" diagram, with the following parts: in use, modified, standby, and free.
Not it's a human bug (not knowing enough about your system).
>disk cache is not counted as used memory.
But it is, and people would be shocked to see that windows uses 17GB of memory after startup ;)
I know enough about my systems, yet I think Windows is doing it right. The numbers reported by Linux, or visible on the “memory composition” diagram in Windows task manager, are borderline useless for everyone except OS kernel developers.
Despite I know these hairy implementation details about the ways OS kernel manages physical memory, I don’t really care. When I check these system tools, in 100% of cases I want answer to the question “how much ram my applications could use without swapping”.
>Despite I know these hairy implementation details about the ways OS kernel manages physical memory, I don’t really care.
I do, and obviously everyone that implements top and htop etc.
Linux folks say that unused memory is not good, of course it is. Windows folks say that free memory is a good thing, and of course it is.
See? It actually is the same thing that being seen from different perspective.
Absolutely, but these perspectives aren’t equally useful, it depends on the user and their use case.
The real low-level thing reported by Linux is a useful perspective for kernel developers, and maybe for students learning about virtual memory management in operating systems.
However, the fake data reported by Windows task manager is the useful perspective for everyone else. I think 99% of people using these tools are in this category.
So a new user clicking System Monitor will get a RAM graph they understand.
30 or so years ago, while watching over a friend of mine's shoulder who was sitting at the gorgeous 3278-2 system console with the legendary beam-spring keyboard, looking into usage stats on an IBM 4381 mainframe, I noticed the CPU (I think it was only one on that machine, that occupied most of a floor) was pegged at 100% usage. When I asked if that was bad, he simply responded:
"Of course it's 100% used! We paid for it, we'd better use it!"
Later I understood that he'd probably be more concerned if the IO processors started to get saturated, but, by then, I was no longer using mainframes.
>You can't disable disk caching.
I guess I'm lucky I've never been confused by this. All the RAM monitors I've been using (KSysGuard and conky) must be reporting RAM usage accurately.