From 15e3dedcee1d0830871ffc692143318a87646101 Mon Sep 17 00:00:00 2001 From: Christian Segundo Date: Thu, 25 Jul 2024 02:12:22 +0200 Subject: wip --- content/posts/2021-02-03-gentoo-no-desktop-lag.md | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 content/posts/2021-02-03-gentoo-no-desktop-lag.md (limited to 'content/posts/2021-02-03-gentoo-no-desktop-lag.md') diff --git a/content/posts/2021-02-03-gentoo-no-desktop-lag.md b/content/posts/2021-02-03-gentoo-no-desktop-lag.md new file mode 100644 index 0000000..966419b --- /dev/null +++ b/content/posts/2021-02-03-gentoo-no-desktop-lag.md @@ -0,0 +1,52 @@ +--- +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`: + + ``` + [Install] + WantedBy=slices.target + + [Slice] + CPUShares=256 + ``` + +1. Enable and start the unit you just created: + + ``` + 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. + + ``` + ➜ ~ 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`: + + ``` + 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 :D -- cgit v1.2.3