Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-nice is not very effective with autogrouping/cgroup_sched enabled #437

Open
rpigott opened this issue Aug 13, 2023 · 2 comments
Open

Comments

@rpigott
Copy link

rpigott commented Aug 13, 2023

gamemode makes use of setpriority to renice game processes when possible, but when autogrouping or cgroups are used it does not have the intended effect, and both are commonly enabled in distro kernels.

sched(7) has some details, but basically CFS divides cpu resources by task groups, which means the cgroup cpu controller if enabled and otherwise by autogrouping, and only finally by process priority. Renicing it only changes its priority relative to other tasks in the group.

I think when systemd/cgroups are used, gamemode should probably change the cpu controller weight by moving the game process to a unique cgroup and writing to the cpu.weight property.

The cpu weight is accessible to an unprivileged user, which makes it much more desirable for gamemode's use-case. We can use existing user configs by leveraging the cpu.weight.nice property as well, which gives an equivalent "nice" like interface to the cpu controller.

[1] https://docs.kernel.org/scheduler/sched-bwc.html
[2] https://docs.kernel.org/admin-guide/cgroup-v2.html#cpu-interface-files
[3] https://man.archlinux.org/man/sched.7#The_autogroup_feature

EDIT: clarity

@rpigott rpigott changed the title re-nice is pointless or harmful with autogrouping enabled re-nice is not very effective with autogrouping/cgroup_sched enabled Aug 20, 2023
@gschintgen
Copy link

This is spot on! re-nice is only a placebo, at least on Ubuntu-derived systems and also apparently on Arch and Fedora. See this excellent thread:
https://www.reddit.com/r/linux/comments/d7hx2c/why_nice_levels_are_a_placebo_and_have_been_for_a/

@rpigott
Copy link
Author

rpigott commented May 7, 2024

If the cpu controller is enabled, autogroups are not used for processes outside of the root cgroup, even if enabled. So autogrouping is only possibly relevant for non-systemd systems (not sure what they do with cgroups), since systemd will put everything into the system or user slice.

What actually matters is the process niceness, the cpu.weight property of the local cgroup, and the cpu.weight of all the cgroups above it in the hierarchy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants