Skip to content

Instantly share code, notes, and snippets.

@moschlar
Last active February 5, 2024 10:00
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moschlar/70d9a8375b86cd4d83dd to your computer and use it in GitHub Desktop.
Save moschlar/70d9a8375b86cd4d83dd to your computer and use it in GitHub Desktop.
Run Gentoo Portage in a cpu cgroup
PORTAGE_IONICE_COMMAND="/usr/local/sbin/portage-cgroup \${PID}"
#!/bin/sh
CGROUP_CPU_ROOT="/sys/fs/cgroup/cpu"
PORTAGE_CPU_SHARES=512
# $1 must be the portage PID
[ -n "$1" ] || exit 1
echo "/usr/local/sbin/remove-empty-cpu-cgroup" > "${CGROUP_CPU_ROOT}/release_agent"
cgroup=$(mktemp -d --tmpdir="${CGROUP_CPU_ROOT}" portage-XXXX) &&
echo $1 > "${cgroup}/tasks" &&
echo 1 > "${cgroup}/notify_on_release" &&
echo ${PORTAGE_CPU_SHARES} > "${cgroup}/cpu.shares"
#!/bin/sh
CGROUP_CPU_ROOT="/sys/fs/cgroup/cpu"
[ -n "${1}" ] || exit 1
cgroup="${CGROUP_CPU_ROOT}/${1}"
rmdir "${cgroup}"
@hrk
Copy link

hrk commented Feb 5, 2024

Unfortunately, this has become obsolete starting with 6.6 where EEVDF replaces CFS.
notify_on_release and release_agent have been removed as well (but I can't pinpoint exactly when).

@moschlar
Copy link
Author

moschlar commented Feb 5, 2024

@hrk And more sadly, I don't even use Gentoo anymore. But when I hopefully come back to it someday, I will probably re-evaluate 😉

@hrk
Copy link

hrk commented Feb 5, 2024

Hoping to see you back someday ;-) The script was very useful and gentoo is always in my heart (and computers alike)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment