--- layout: post title: Say goodbye to desktop lag while compiling your @world category: GNU/Linux tags: - gentoo - systemd --- 1. Start by creating a new systemd slice `/etc/systemd/system/portage.slice`: ```systemd [Install] WantedBy=slices.target [Slice] CPUShares=256 ``` 1. Enable and start the unit you just created: ```sh systemctl enable --now portage.slice ``` `CPUShares` option defaults to 1024, `systemd` will create a user slice for each user with an active session, and all processes that user run will be assigned to that slice, anything that a user may run will receive 4 times the CPU time of processes assigned to the portage slice. ```sh ➜ ~ cat /sys/fs/cgroup/cpu,cpuacct/user.slice/cpu.shares 1024 ``` 1. Repurpose `PORTAGE_IONICE_COMMAND` variable. This is one of those awesome variables you can set in your `make.conf` to alter how you build stuff. It should be a command string for portage to call to modify its own priority with a `\${PID}` placeholder that will be substituted with a `PID`. Maybe it was created with `ionice` in mind, but we can abuse that placeholder to write pids to the `cgroup.procs` file in the portage slice. Add the following line to your `/etc/portage/make.conf`: ```sh PORTAGE_IONICE_COMMAND="sh -c \"echo \${PID} > /sys/fs/cgroup/systemd/portage.slice/cgroup.procs\"" ``` The `cgroup.procs` file is present in every cgroup and contains a list of processes that are members of that particular cgroup. Writing a PID to this file will move all threads in that process at once to the cgroup, and that, is awesome.