this post was submitted on 18 Jun 2024
101 points (100.0% liked)

Linux

81 readers
10 users here now

A community for everything relating to the linux operating system

Also check out !linux_memes@programming.dev

Original icon base courtesy of lewing@isc.tamu.edu and The GIMP

founded 1 year ago
MODERATORS
 

One big difference that I've noticed between Windows and Linux is that Windows does a much better job ensuring that the system stays responsive even under heavy load.

For instance, I often need to compile Rust code. Anyone who writes Rust knows that the Rust compiler is very good at using all your cores and all the CPU time it can get its hands on (which is good, you want it to compile as fast as possible after all). But that means that for a time while my Rust code is compiling, I will be maxing out all my CPU cores at 100% usage.

When this happens on Windows, I've never really noticed. I can use my web browser or my code editor just fine while the code compiles, so I've never really thought about it.

However, on Linux when all my cores reach 100%, I start to notice it. It seems like every window I have open starts to lag and I get stuttering as the programs struggle to get a little bit of CPU that's left. My web browser starts lagging with whole seconds of no response and my editor behaves the same. Even my KDE Plasma desktop environment starts lagging.

I suppose Windows must be doing something clever to somehow prioritize user-facing GUI applications even in the face of extreme CPU starvation, while Linux doesn't seem to do a similar thing (or doesn't do it as well).

Is this an inherent problem of Linux at the moment or can I do something to improve this? I'm on Kubuntu 24.04 if it matters. Also, I don't believe it is a memory or I/O problem as my memory is sitting at around 60% usage when it happens with 0% swap usage, while my CPU sits at basically 100% on all cores. I've also tried disabling swap and it doesn't seem to make a difference.

EDIT: Tried nice -n +19, still lags my other programs.

EDIT 2: Tried installing the Liquorix kernel, which is supposedly better for this kinda thing. I dunno if it's placebo but stuff feels a bit snappier now? My mouse feels more responsive. Again, dunno if it's placebo. But anyways, I tried compiling again and it still lags my other stuff.

top 50 comments
sorted by: hot top controversial new old
[–] scsi@lemm.ee 41 points 5 months ago (4 children)

The Linux kernel uses the CPU default scheduler, CFS, a mode that tries to be fair to all processes at the same time - both foreground and background - for high throughput. Abstractly think "they never know what you intend to do" so it's sort of middle of the road as a default - every CPU cycle of every process gets a fair tick of work unless they've been intentionally nice'd or whatnot. People who need realtime work (classic use is for audio engineers who need near-zero latency in their hardware inputs like a MIDI sequencer, but also embedded hardware uses realtime a lot) reconfigure their system(s) to that to that need; for desktop-priority users there are ways to alter the CFS scheduler to help maintain desktop responsiveness.

Have a look to Github projects such as this one to learn how and what to tweak - not that you need to necessarily use this but it's a good point to start understanding how the mojo works and what you can do even on your own with a few sysctl tweaks to get a better desktop experience while your rust code is compiling in the background. https://github.com/igo95862/cfs-zen-tweaks (in this project you're looking at the set-cfs-zen-tweaks.sh file and what it's tweaking in /proc so you can get hints on where you research goals should lead - most of these can be set with a sysctl)

There's a lot to learn about this so I hope this gets you started down the right path on searches for more information to get the exact solution/recipe which works for you.

[–] 0x0@programming.dev 25 points 5 months ago (1 children)

I'd say nice alone is a good place to start, without delving into the scheduler rabbit hole...

[–] scsi@lemm.ee 14 points 5 months ago

I would agree, and would bring awareness of ionice into the conversation for the readers - it can help control I/O priority to your block devices in the case of write-heavy workloads, possibly compiler artifacts etc.

[–] SorteKanin@feddit.dk 21 points 5 months ago (5 children)

"they never know what you intend to do"

I feel like if Linux wants to be a serious desktop OS contender, this needs to "just work" without having to look into all these custom solutions. If there is a desktop environment with windows and such, that obviously is intended to always stay responsive. Assuming no intentions makes more sense for a server environment.

[–] BearOfaTime@lemm.ee 14 points 5 months ago (1 children)

Even for a server, the UI should always get priority, because when you gotta remote in, most likely shit's already going wrong.

[–] SirDimples@programming.dev 10 points 5 months ago

Totally agree, I've been in the situation where a remote host is 100%-ing and when I want to ssh into it to figure out why and possibly fix it, I can't cause ssh is unresponsive! leaving only one way out of this, hard reboot and hope I didn't lose data.

This is a fundamental issue in Linux, it needs a scheduler from this century.

[–] 1984@lemmy.today 8 points 5 months ago

100% agree. Desktop should always be a strong priority for the cpu.

load more comments (3 replies)
[–] msage@programming.dev 5 points 5 months ago

Wasn't CFS replaced in 6.6 with EEDVF?

I have the 6.6 on my desktop, and I guess the compilations don't freeze my media anymore, though I have little experience with it as of now, need more testing.

load more comments (1 replies)
[–] lupec@lemm.ee 23 points 5 months ago* (last edited 5 months ago) (1 children)

Responsiveness for typical everyday usage is one of the main scenarios kernels like Zen/Liquorix and their out of the box scheduler configurations are meant to improve, and in my experience they help a lot. Maybe give them a go sometime!

Edit: For added context, I remember Zen significantly improving responsiveness under heavy loads such as the one OP is experiencing back when I was experimenting with some particularly computationally intensive tasks

[–] thingsiplay 11 points 5 months ago (1 children)

https://github.com/zen-kernel/zen-kernel/wiki/Detailed-Feature-List

That's the reason I installed Zen too and use it as the default. While Zen is meant to improve responsiveness of interactive usage on the system, it comes at a price. The overall performance might decrease and it should require more power. But if someone needs to solve the problem of the OP (need to work on the computer while under heavy load), then Zen is probably the right tool. Some distributions have the Zen Kernel in their repository and the install process is straightforward.

[–] lupec@lemm.ee 4 points 5 months ago

Very good points, it's all trade-offs at the end of the day. I've always found them more than worth it myself for non server workloads, but as always YMMV.

[–] crispy_kilt@feddit.de 19 points 5 months ago (2 children)

nice +5 cargo build

nice is a program that sets priorities for the CPU scheduler. Default is 0. Goes from -19, which is max prio, to +19 which is min prio.

This way other programs will get CPU time before cargo/rustc.

[–] SorteKanin@feddit.dk 7 points 5 months ago (1 children)

It's more of a workaround than a solution. I don't want to have to do this for every intensive program I run. The desktop should just be responsive without any configuration.

load more comments (1 replies)
[–] boredsquirrel@slrpnk.net 4 points 5 months ago (7 children)

So the better approach would be to spawn all desktop and base GUI things with nice -18 or something?

load more comments (7 replies)
[–] mcmodknower@programming.dev 18 points 5 months ago (1 children)

You could try using nice to give the rust compiler less priority (higher number) for scheduling.

[–] SorteKanin@feddit.dk 3 points 5 months ago (1 children)

This seems too complicated if I need to do that for other programs as well.

load more comments (1 replies)
[–] arendjr@programming.dev 13 points 5 months ago

The System76 scheduler helps to tune for better desktop responsiveness under high load: https://github.com/pop-os/system76-scheduler I think if you use Pop!OS this may be set up out-of-the-box.

[–] possiblylinux127@lemmy.zip 10 points 5 months ago* (last edited 5 months ago)

It really depends on your desktop. For instance gnome handles high CPU very well in my experience.

I would run your compiler in a podman container with a CPU cap.

Edit: it might be related to me using Fedora

[–] tatterdemalion@programming.dev 10 points 5 months ago* (last edited 5 months ago) (1 children)

Sounds like Kubuntu's fault to me. If they provide the desktop environment, shouldn't they be the ones making it play nice with the Linux scheduler? Linux is configurable enough to support real-time scheduling.

FWIW I run NixOS and I've never experienced lag while compiling Rust code.

[–] SorteKanin@feddit.dk 6 points 5 months ago (1 children)

I have a worrying feeling that if I opened a bug for the KDE desktop about this, they'd just say it's a problem of the scheduler and that's the kernel so it's out of their hands. But maybe I should try?

[–] haui_lemmy@lemmy.giftedmc.com 7 points 5 months ago

The kde peeps are insanely nice so I guess you should try.

[–] amanda@aggregatet.org 9 points 5 months ago* (last edited 5 months ago) (1 children)

Lots of bad answers here. Obviously the kernel should schedule the UI to be responsive even under high load. That’s doable; just prioritise running those over batch jobs. That’s a perfectly valid demand to have on your system.

This is one of the cases where Linux shows its history as a large shared unix system and its focus as a server OS; if the desktop is just a program like any other, who’s to say it should have more priority than Rust?

I’ve also run into this problem. I never found a solution for this, but I think one of those fancy new schedulers might work, or at least is worth a shot. I’d appreciate hearing about it if it does work for you!

Hopefully in a while there are separate desktop-oriented schedulers for the desktop distros (and ideally also better OOM handlers), but that seems to be a few years away maybe.

In the short term you may have some success in adjusting the priority of Rust with nice, an incomprehensibly named tool to adjust the priority of your processes. High numbers = low priority (the task is “nicer” to the system). You run it like this: nice -n5 cargo build.

[–] 0x0@programming.dev 5 points 5 months ago (2 children)

Obviously the kernel should schedule the UI to be responsive even under high load.

Obviously... to you.

This is one of the cases where Linux shows its history as a large shared unix system and its focus as a server OS; if the desktop is just a program like any other,

Exactly.

[–] SorteKanin@feddit.dk 8 points 5 months ago* (last edited 5 months ago) (1 children)

Obviously… to you.

No. I'm sorry but if you are logged in with a desktop environment, obviously the UI of that desktop needs to stay responsive at all times, also under heavy load. If you don't care about such a basic requirement, you could run the system without a desktop or you could tweak it yourself. But the default should be that a desktop is prioritized and input from users is responded to as quickly as possible.

This whole "Linux shouldn't assume anything"-attitude is not helpful. It harms Linux's potential as a replacement for Windows and macOS and also just harms its UX. Linux cannot ever truly replace Windows and macOS if it doesn't start thinking about these basic UX guarantees, like a responsive desktop.

This is one of the cases where Linux shows its history as a large shared unix system and its focus as a server OS; if the desktop is just a program like any other,

Exactly.

You say that like it's a good thing; it is not. The desktop is not a program like any other, it is much more important that the desktop keeps being responsive than most other programs in the general case. Of course, you should have the ability to customize that but for the default and the general case, desktop responsiveness needs to be prioritized.

[–] BearOfaTime@lemm.ee 4 points 5 months ago

Even for a server, the UI should always be priority. If you're not using the desktop/UI, what's the harm?

When you do need to remote into a box, it's often when shit's already sideways, and having an unresponsive UI (or even a sluggish shell) gets old.

A person interacting with a system needs priority.

[–] amanda@aggregatet.org 4 points 5 months ago

I meant, obviously in the sense that Windows and macOS both apparently already do this and that it’s a desirable property to have, not that it’s technically easy.

[–] SorteKanin@feddit.dk 7 points 5 months ago (3 children)

So I just tried using nice -n +19 and it still lags my browser and my UI. So that's not even a good workaround.

load more comments (3 replies)
[–] odium@programming.dev 7 points 5 months ago* (last edited 5 months ago) (2 children)
[–] 0x0@programming.dev 3 points 5 months ago

OP most likely wants the opposite for the compiler...

[–] SorteKanin@feddit.dk 3 points 5 months ago

I don't really want to limit the Rust compiler. If I leave my computer running while I take a break, I don't want it to artificially throttle the compiler. I just want user input and responsiveness of open windows to take priority over the compiler.

[–] cbazero@programming.dev 6 points 5 months ago (1 children)

If you compile on windows server the same problem happens. The server is basically gone. So there seems to be some special scheduler configuration in windows client os.

load more comments (1 replies)
[–] FizzyOrange@programming.dev 5 points 5 months ago (2 children)

No. And even worse is Linux's OOM behaviour - 99% of the time it just reboots the machine! Yes I have swap and zswap.

Linux is just really bad at desktop.

[–] possiblylinux127@lemmy.zip 3 points 5 months ago* (last edited 5 months ago)

I haven't had that experience. (Systemd oom)

[–] sxan@midwest.social 4 points 5 months ago* (last edited 5 months ago) (1 children)

While I ultimately think your solution is to use a different scheduler, and that the most useful responses you've gotten have been about that; and that I agree with your response that Linux distros should really be tuning the scheduler for the UI by default and let developers and server runners take the burden of tuning differently for their workloads... all that said, I can't let this comment on your post go by:

which is good, you want it to compile as fast as possible after all

If fast compile times are your priority, you're using the wrong programming language. One of Go's fundamental principles is fast compile times; even with add-on caching tooling in other languages, Go remains one of the fastest-compiling statically compiled, strongly typed programming languages available. I will not install Haskell programs unless they're precompiled bin packages, that's a hard rule. I will only reluctantly install Rust packages, and will always choose bins if available. But I'll pick a -git Go package without hesitation, because they build crazy fast.

Anyway, I hope you find the scheduler of your dreams and live happily ever after.

[–] SorteKanin@feddit.dk 8 points 5 months ago (1 children)

I only said as fast as possible - I generally think the compile times are fine and not a huge problem. Certainly worth it for all the benefits.

[–] balder1993@programming.dev 5 points 5 months ago (3 children)

There’s no free lunch after all. Go’s quick compilation also means the language is very simple, which means all the complexity shifts to the program’s code.

load more comments (3 replies)
[–] sunzu@kbin.run 4 points 5 months ago

I face similar issue when updating steam games although I think that's related to disk read write

But either way, issues like these gonna need to be address before we finally hit the year of Linux desktop lol

[–] Rentlar@lemmy.ca 3 points 5 months ago (2 children)

Yeah I think the philosophy of Linux is to not assume what you are going to be use it for. Why should Linux know where your priorities are better than you?

Some people want to run their rustc, ffmpeg or whatever intensive program and don't mind getting a coffee while that happens, or it's running on a non-user facing server anyway, to ensure that the process happens as soon as technically possible. Mind you that your case is not an "average usecase" either, not everyone is a developer that does compilation tasks.

So you've got a point that the defaults could be improved for the desktop software developer user or somehow made more easily configurable. As suggested downthread, try the nice command, an optimized scheduler or kernel, or pick a distribution equipped with that kind of kernel by default. The beauty of Linux is that there are many ways to solve a problem, and with varying levels of effort you can get things to pretty much exactly where you want them, rather than some crowdpleasing default.

[–] BearOfaTime@lemm.ee 4 points 5 months ago (1 children)

There's a setting in windows to change the priority management, most people never see it.

By default it's configured for user responsiveness, but you can set it for service responsiveness.

Though this is nothing like the process priority management in Linux, it's one setting, that frankly I've never seen it make any difference. At least with Linux you can configure all sorts of priority management, on the fly no less.

Even with a server, you'd still want the UI to have priority. God knows when you do have to remote in, it's because you gotta fix something, and odds are the server is gonna be misbehavin' already.

load more comments (1 replies)
[–] SorteKanin@feddit.dk 3 points 5 months ago (2 children)

Why should Linux know where your priorities are better than you?

Because a responsive desktop is basic good UX that should never ever be questioned. That should at least be the default and if you don't want your desktop to have special priority, then you can configure it yourself.

pick a distribution equipped with that kind of kernel by default.

I'm running Kubuntu, an official variant of Ubuntu which is very much a "just works" kind of distribution - yet this doesn't just work.

load more comments (2 replies)
[–] BB_C@programming.dev 3 points 5 months ago (1 children)

This hasn't been my experience when no swapping is involved (not a concern for me anymore with 32GiB physical RAM with 28GiB zram).

And I've been Rusting since v1.0, and Linuxing for even longer.

And my setup is boring (and stable), using Arch's LTS kernel which is built with CONFIG_HZ=300. Long gone are the days of running linux-ck.

Although I do use craneleft backend now day to day, so compiles don't take too long anyway.

load more comments (1 replies)
load more comments
view more: next ›