It would be very beneficial if portage supported setting various cgroups option s such as cpu.weight and memory.high/max.
Currently portage supports cgroups v1 to group all emerge activities under one cgroup subtree. It would be great if it also supported cgroups v2.
make.conf could be updated with something like this:
CGROUP2="cpu.weight=100 memory.high=1g memory.oom.group=1"
The great advantage is to be able to limit recourses for all emerge processes as a whole, rather than per ebuild instance.
This is implemented in openrc already.
I made a quick wrapper script to work with cgroups v2 with portage. It requires that PORTAGE_NICENESS and FEATUERS=cgroup are off, and that cgroups v2 (unified) is enabled and mounted correctly.
https://github.com/Gatak/cgexec (execute commands in a cgroup)
To use it simply do: # cgexec -c50 emerge xxx/yyy
Most people do not use purely cgroups v2 so cgexec wont work there then. It would be better with a generic solution that works with other features, including both systemd and OpenRC (I use and prefer OpenRC).