Live data from Hacker News

Linux 7.3 improves performance when running out of vRAM

pixelcluster.dev

171–180 of 328 posts

Re: Linux 7.3 improves performance when running out of vRAM

#171
post #92

Earlier quoted context omitted.

From my experience, Windows does freeze and become completely unusable too, just not usually from RAM usage hitting 100%. I don't use Windows much, nor do I care much about that environment, but from what I've seen it seems to keep RAM usage below 100% most of the time. What I do see pretty often is the drive getting stuck at 100% usage instead, which makes the whole system ridiculously unusable anyway.

Windows does freeze and become unstable, but it's usually because of some ring 0 errors not getting trapped appropriately. But Windows has always handled both OOM and out of disk space very well. The system will be extremely sluggish, but it typically continues operating. The Linux design is to keep using memory, then push to swap, and then when you OOM you hard lock. The built in kernel OOM module can miss when RAM…

Linux can be configured to disable memory overcommit

sysctl -w vm.overcommit_memory=2 sysctl -w vm.overcommit_ratio=50

It is probably a bad idea to do that though as it will limit the amount of virtual address space an application can use

Re: Linux 7.3 improves performance when running out of vRAM

#172
post #92

Earlier quoted context omitted.

From my experience, Windows does freeze and become completely unusable too, just not usually from RAM usage hitting 100%. I don't use Windows much, nor do I care much about that environment, but from what I've seen it seems to keep RAM usage below 100% most of the time. What I do see pretty often is the drive getting stuck at 100% usage instead, which makes the whole system ridiculously unusable anyway.

Windows does freeze and become unstable, but it's usually because of some ring 0 errors not getting trapped appropriately. But Windows has always handled both OOM and out of disk space very well. The system will be extremely sluggish, but it typically continues operating. The Linux design is to keep using memory, then push to swap, and then when you OOM you hard lock. The built in kernel OOM module can miss when RAM…

Doesn't Windows, like macOS, automatically expand swap? You can't run out of memory nearly as quickly as you can on Linux. And at least on Windows I always figured this is why it felt so sluggish under load--it ends up paging alot. Not sure why macOS has always felt more consistent; perhaps the OS and major apps are less gratuitous memory hogs?

Re: Linux 7.3 improves performance when running out of vRAM

#173

I hope there will be an update where when my RAM gets full my PC doesn't freeze and becomes unusable... I remember that Linux and Windows do this in different ways and Windows doesn't have the problem.

I had this symptom due to having an SSD without a RAM cache, which caused the latency of disk access to rise to seconds under heavy paging, effectively freezing the computer. Enabling the kyber IO scheduler, tuned for responsiveness over throughput, solved it for me.

Re: Linux 7.3 improves performance when running out of vRAM

#174

I hope there will be an update where when my RAM gets full my PC doesn't freeze and becomes unusable... I remember that Linux and Windows do this in different ways and Windows doesn't have the problem.

A lot of cargo-culted sysctl tuning blogs will get you there... Linux doesn't have that problem, your chosen distro/config does. E.g., CachyOS is tuned for absolute minimum latency and assumes you won't be heavily multitasking. Using that as a workstation requires adjustments.

Re: Linux 7.3 improves performance when running out of vRAM

#175

I hope there will be an update where when my RAM gets full my PC doesn't freeze and becomes unusable... I remember that Linux and Windows do this in different ways and Windows doesn't have the problem.

This seems to always be explained in a confusing and sometimes wrong manner, so I may as well also try to explain it in a confusing and sometimes wrong manner too.

Both Windows and Linux allow applications to map memory in an uncommitted state. However, in Linux, uncommitted memory can magically become committed by simply trying to use it, whereas on Windows you have to first actually commit it with a separate API call.

You might wonder why you would even bother allocating uncommitted memory on Windows if you have to explicitly commit it later. Simple: just to reserve a contiguous slice of address space for later.

The consequence of this is that on Windows an allocation failure usually occurs at an API call where it can return a failure, and indeed does. On Linux though, an allocation can fail during a page fault that is entirely transparent to the application. So instead, the default behavior is to allow overcommit, where applications are allowed to commit more memory than the system actually has, under the assumption that in many cases it won't all be in use at once. Instead of an application hitting an error or crashing on a failed allocation, if there is no memory left, a process simply hangs.

Here's my take on why this is the way it is:

- Because programs are written without any knowledge of what memory pages are committed, applications will allocate physical memory pages transparently even if they didn't malloc or mmap anything. Because of that, when an allocation fails under memory pressure, it's pretty likely the first page to stall on overcommit isn't really related to the actual memory pressure.

- To try to mitigate this, during high memory pressure situations, mechanisms like the OOM killer have to score tasks based on several factors to try to guess which ones are causing the problem.

- When you have something like make -j running, it is pretty easy for it to choose Firefox instead of the 200 instances of Clang, since individually none of those Clang instances are really using much memory. This, of course, doesn't fix the bleeding, it just kills your browser. There are ways to mitigate this problem, but they are not often implemented and nothing will ever be perfect.

One may wonder if it is worth the trouble... Probably not, but it does have its advantages, particularly when it comes to databases and caches, which can aggressively reserve memory and mmap files and heavily lean on demand paging for memory management. It's just that in this case, managing memory pressure becomes somewhat heuristics-based, and tools like cgroups are often desired to isolate failure domains and control memory allocations in production systems.

This is a tough problem to solve. Many improvements to the Linux OOM situation have been made, from simply fixing problems that made the wedging even worse, to tweaking the OOM scoring, to usermode daemons like systemd-oomd that try to catch memory pressure earlier. However, so far this is a solidly unsolved problem - the same exact wedging is still possible today.

As hopeless as it seems, I am still open-minded here. The Linux desktop moves slow, but nonetheless it seems pretty good at overcoming challenging obstacles.

Re: Linux 7.3 improves performance when running out of vRAM

#176

I hope there will be an update where when my RAM gets full my PC doesn't freeze and becomes unusable... I remember that Linux and Windows do this in different ways and Windows doesn't have the problem.

Just last night I was debugging some batch job on a Linux box making the machine go unresponsive even though there's no swap. User process taking all the RAM and the OOM killer doesn't stop it, instead the killer itself gets live-locked along with the ssh session or whatever else, so I can't just get in to look at it.

Re: Linux 7.3 improves performance when running out of vRAM

#177

Earlier quoted context omitted.

For me Windows becomes unusable as soon as any of my drives is being hammered, including when it is swapping, but not limited to it.

Explorer freezes too when an external hard drive spins up, very annoying.

I remember my older Macs and Windows 98 laptops liked spinning the CD randomly, sometimes waiting to read it. I'd eject it when I hear it spinning. No CD for you.

Re: Linux 7.3 improves performance when running out of vRAM

#179

I see all the comments about how Windows and Linux handle OOM, but I suppose I'll also mention macOS. On my M4 Max Mac Studio if I try to load too big of an AI model with protections off, the desktop starts glitching back and forth between the past few hundred frames. It looks bad when it happens but CtrlC still works to kill llama.cpp and if you were using LM Studio, SSH also works. Once you kill the offending proce…

Heh, is it cause the integrated graphics is out of memory? Cause it's unified.

Re: Linux 7.3 improves performance when running out of vRAM

#180

I see all the comments about how Windows and Linux handle OOM, but I suppose I'll also mention macOS. On my M4 Max Mac Studio if I try to load too big of an AI model with protections off, the desktop starts glitching back and forth between the past few hundred frames. It looks bad when it happens but CtrlC still works to kill llama.cpp and if you were using LM Studio, SSH also works. Once you kill the offending proce…

On my M4 Max MacBook Pro, if I run or even load an LLM more than a couple times, even a small one, general desktop performance starts to get really, really bad until a reboot and I don't know why. Genuinely, everything starts feeling super sluggish, even long after the process has terminated -- cmd+tab gets slow, apps constantly hang for a few seconds at a time, the cursor position starts lagging and videos are slow…

But you're on a beta release?
Post reply on HN