You are not logged in.
Hi guys, how can I configure the OOM killer to target build processes spawned by makepkg instead of my Desktop Environment?
I usually build with 12 out of 16 threads on my laptop, and it works fine most of the time. However, sometimes, there's too much load on my laptop and my CPU/RAM becomes fully utilised, resulting in my laptop freezing and the OOM killer activating. However, the OOM killer prioritises killing random processes like my desktop environment instead of build processes. After some investigation, it seems that this is because the OOM killer treats each make process as it's own individual process. How do I force the OOM killer to treat every child process of make, etc together as one process and kill it instead of my DE?
Last edited by sawntoee (2025-10-23 13:04:48)
Offline
increase the oom_adj or ghe process, https://www.oracle.com/technical-resour … iller.html
How do I force the OOM killer to treat every child process of make, etc together as one process and kill it instead of my DE?
https://wiki.archlinux.org/title/Cgroup … _a_command
https://www.kernel.org/doc/html/latest/ … face-files
See "memory.oom.group"
Offline
Within the Arch infra we have have special settings for the slices the processes run in: https://gitlab.archlinux.org/archlinux/ … type=heads
Offline
The method suggested by seth will be tricky to get right as it's not makepkg that claims the memory but make, ninja, meson, qmake , scons and every build method you use.
The method mentioned by gromit could be useful if you always build with devtools, but I doubt it will affect makepkg .
Simplest solution : double or triple the amount of memory in your system by adding extra memory modules
2nd choice : increase swap space to above your amount of physical memory
If those are not possible or don't help enough :
I looked at this when systemd added its oomkiller and found it should be named X11/wayland killer instead.
The systemd oomkiller gets started on demand without any user action through /usr/share/dbus-1/system-services/org.freedesktop.oom1.service
It can't be masked, disabled, blocked EXCEPT by deleting that file .
If that solves/reduces the problem, you're better off by blocking it permanently through pacman.conf as I have done and rely on kernel oom handling instead .
It's one of the steps in my 'taming systemd' doc. (it's been a WIP for years now, I should really clean it up and publish it)
Last edited by Lone_Wolf (2025-10-21 11:03:48)
Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.
clean chroot building not flexible enough ?
Try clean chroot manager by graysky
Offline
You don't need to use devtools, just systemd-run makpkg w/ that slice? But afaict it'll require https://man.archlinux.org/man/systemd-oomd.8
The kernel oom killer would probably have benefited from memory.oom_policy, https://lwn.net/Articles/761118/
Simplest solution : double or triple the amount of memory in your system by adding extra memory modules
Or run less parallel jobs ![]()
Offline
Hi guys, thanks for all the help and sorry for the late reply, I somehow injured both of my hands and am unable to use my laptop without great difficulty.
I'm hoping for a "one size fits all" solution that I can configure and never touch again and not worry about it breaking, hence adjusting oom-adj will not work as the build process used is unknown per pkgbuild. I am aware of systemd-run with cgroup, however i am slightly skeptical as I do want to wrap makepkg such that pacman uses it by default. Has anyone done this before? From what I understand, that also requires systemd-oomd which is... suboptimal from prior experience.
Offline
I somehow injured both of my hands
Ambidextrous masturbation?
I'm hoping for a "one size fits all" solution that I can configure and never touch again and not worry about it breaking
Simplest solution : double or triple the amount of memory in your system by adding extra memory modules
and/or have sufficient swap.
Computers don't work by magic, if you're touching their limits you'll have to exert control over the process.
I do want to wrap makepkg such that pacman uses it by default
Errr… what?
That's not a thing.
Offline
> Ambidextrous masturbation?
Man, you would not believe the amount of times i've heard that joke today XD
> Errr… what?
Man, I've gotta be a huge flaming dumbass. Due to how much I conflate pacman with my AUR helper i thought pacman called makepkg internally and not the other way around. I also didn't know that makepkg was a shell script. I do suppose that moving makepkg to a location lower down PATH and replacing it with a shim script that calls systemd-run ... makepkg $@ should work without much major consequence?
Offline
Don't replace /usr/bin/makpkg but you can use a shim in /usr/local/bin/makepkg (don't forget to call /usr/bin/makepkg by absolute path there) - or edit your AUR helper.
Offline
Yup, it works, thanks!
/usr/local/bin/makepkg
#!/bin/bash
# THIS IS A WRAPPER
MEM_LIMIT_PERCENT=80
avail_kb=$(grep MemAvailable /proc/meminfo | awk '{print $2}')
# Compute 50% of it in MB
mem_limit_mb=$(( avail_kb / 1024 * MEM_LIMIT_PERCENT / 100 ))
systemd-run --user --scope -p "MemoryMax=${mem_limit_mb}M" /usr/bin/makepkg "$@"Offline