The Unclear Impact

linux desktop performance/experiments

so @koz_ross recently mentioned his system locks up without linux-ck and i remembered that yeah, mine freezes up and gets stuttery when building stuff

is there a way to fix this with stock linux? introducing my two-part EXPERIMENT: launch everything with systemd-run, and set up systemd-oomd

there's going to be a lot of systemd stuff here so if you're not running systemd, this probably isn't for you

linux desktop performance/experiments

the core issue here is resource starvation and the system not knowing which resources to prioritize

so how does linux scheduling work? muqss does this based on latency, but mainline uses the completely fair scheduler- each process gets a block of time proprtional to other processes

this will definitely let fork bombs and other massively parallel things kill your system

linux desktop performance/experiments

so one way to fix this is by setting the nice levels of stuff. the main downside of this is that it's not automatic and it's still proportional

another way is using autogroups which groups processses- so you no longer schedule based on unix processes but on terminal session groups. seems saner and actually solves issues

but cgroups disables autogroups, yikes!
so what do we do?

linux desktop performance/experiments

well if you run systemd-cgls you can see that most of your user programs are running in a single session cgroup (unless you're on a DE or something), meaning your firefox running youtube and your make tree are back at square one with all equal weight

so one solution to fix this is to run programs indirectly, such as 'systemd-run --user --scope PROGRAM'. this puts the PROGRAM and anything else it runs in its own cgroup!

linux desktop performance/experiments

so i prefixed my keybindings in i3 for dmenu and startups with this, and now firefox and each terminal i open are in different cgroups. i had to use '--disable-server' for xfce4-terminal since some terminal emulators like to daemonize

nothing has changed in my workflow and i have a MUCH better system for latency as now i can run 'ninja -j32' in one terminal and not have any system stutters

linux desktop performance/experiments

another issue linux hits is running out of memory. this can be a headache to solve for the kernel and things like earlyoom, but with cgroups it's simple- systemd will look for the cgroup using all the memory and kill it. so if i run 'ninja -j0' it will kill my terminal cgroup once it hits OOM and not touch anything else i'm doing

linux desktop performance/experiments

another bonus is forkbombs: while writing this i ran a forkbomb and then killed the cgroup containing all the forkbomb shit

linux desktop performance/experiments

it would be nice for linux to have a program for launching applications in linux like this, like 'launch' that would automatically set up cgroups and things, maybe even nice levels and processes- automatically according to some config

Re: linux desktop performance/experiments
@jookia that sounds like systemd

_ducks in corner_
replies
0
announces
0
likes
0

Re: linux desktop performance/experiments

@kristof explain yourself

Re: linux desktop performance/experiments

@jookia I’m sleepy, fail to scroll back in threads, and make bad jokes!

peeks out of corner

that said, setting up cgroups + niceness according to a config file legitimately sounds like systemd (user) units…

(I’m a bit surprised that firejail doesn’t have similar functionality, since it’s also nearly a kitchen sink in terms of linux process management gizmos, and stuffing all child processes into a cgroup wouldn’t be much of a stretch before stuffing them into a process namespace, anyways)

Re: linux desktop performance/experiments

@kristof well yes it could be systemd units, but this is a lot easier using on the fly cgroups

linux desktop performance/experiments

@jookia I've tested this setup, but in Firefox, I get _really_ bad video stutter at high loads. I get audio stutter also, but that's much less if the video is not being displayed and I'm not loading a chonky website.