You are not logged in.

#1 2025-10-21 05:50:17

sawntoee
Member
Registered: 2025-10-21
Posts: 6

[SOLVED] Configuring OOM killer to target makepkg build processes

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

#2 2025-10-21 08:18:47

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,086

Re: [SOLVED] Configuring OOM killer to target makepkg build processes

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

#3 2025-10-21 09:23:53

gromit
Administrator
From: Germany
Registered: 2024-02-10
Posts: 1,523
Website

Re: [SOLVED] Configuring OOM killer to target makepkg build processes

Within the Arch infra we have have special settings for the slices the processes run in: https://gitlab.archlinux.org/archlinux/ … type=heads

Offline

#4 2025-10-21 11:01:13

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 14,951

Re: [SOLVED] Configuring OOM killer to target makepkg build processes

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

#5 2025-10-21 12:07:42

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,086

Re: [SOLVED] Configuring OOM killer to target makepkg build processes

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 wink

Offline

#6 2025-10-23 06:39:25

sawntoee
Member
Registered: 2025-10-21
Posts: 6

Re: [SOLVED] Configuring OOM killer to target makepkg build processes

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

#7 2025-10-23 07:17:45

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,086

Re: [SOLVED] Configuring OOM killer to target makepkg build processes

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

Lone_Wolf wrote:

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

#8 2025-10-23 09:02:28

sawntoee
Member
Registered: 2025-10-21
Posts: 6

Re: [SOLVED] Configuring OOM killer to target makepkg build processes

> 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

#9 2025-10-23 11:04:17

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,086

Re: [SOLVED] Configuring OOM killer to target makepkg build processes

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

#10 2025-10-23 13:03:21

sawntoee
Member
Registered: 2025-10-21
Posts: 6

Re: [SOLVED] Configuring OOM killer to target makepkg build processes

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

Board footer

Powered by FluxBB