Portage cgroups

System configuration
First of all, you have to build cgroup support into the kernel.

Then you have to make sure that a the cgroup filesystem is mounted at each boot. With systemd you should have it out of the box. With OpenRC you probably (untested) should add something like this to /etc/fstab:

Helper script
When the system is properly configured, you can create the helper program that puts portage in its own cgroup when invoked.

This creates a new group in the cpu hierarchy containing only the portage process (its children will be added automatically).

You may want to change the amount of cpu time assigned to this cgroup; you can do that by adding, i.e. echo 512 > "${cgroup}/cpu.shares"

It should work like this: suppose you only have the root cgroup with cpu.shares=1024 (the default) and the portage cgroup with cpu.shares=512. If both cgroups run a cpu-hogging program the root one will get 1024 / (1024 + 512) = 66.7% of cpu time; the portage one will get 512 / (1024 + 512) = 33.3%.

Portage configuration
Finally you will need to hook this script into portage adding this line to make.conf: