Score:0

Linux process scheduling by user?

in flag

It seems Linux schedules process execution independently of the user of the process. So, if one user is running 100 processes and another user is running 1 process, in average, the first one will get 100x more CPU time than the second one.

Is there any possibility to balance CPU time by user, meaning that, in this example, both users get 50% CPU time?

Score:2
cn flag

This being Linux, of course the defaults are relatively basic, but there are many competing choices of tools to change those. But not all of them are available on every distro, so it is not obvious which one to use.

On cgroups systems, CPU resource supports a weighted distribution model, where each group is assigned a fraction of available resource in a ratio according to weight.

On systemd systems, the slice concept directly corresponds to using cgroups. Read man systemd.resource-control and consider enabling DefaultCPUAccounting=. Apply the same CPU ratio to each unit in question. For example, to do this to each interactive user, put this in something like /etc/systemd/system/user-.slice.d/resource.conf

[Unit]
Description:Default CPU ratio
Documentation:man:systemd.resource-control

[Slice]
CPUWeight=100

The number's precise value is not important, as long as each unit in question gets something of the correct proportion. Further, its not that they are dividing up total system CPU, but the CPU assigned to the parent user.slice. If tweaking a service unit instead, those are out of system.slice.

On systems using pam_limit, POSIX resource limits can be set on logged in users. See man limits.conf, and the config file might be a drop-in like /etc/security/limits.d/resource.conf. A practical thing to might be to set nproc to the maximum number of tasks a user gets. Exceeding that, things fail to fork. Or, cpu is a tempting limit, however exceeding the hard limit might start killing processes, which is not a great user experience.

And for the task version of the children's game red light green light, there is cpulimit. This sends SIGSTOP and SIGCONT signals to manage CPU use, simple. Notably it is a bit ad-hoc in that there is no config file, it needs to be invoked to start a process, or be given a PID.

Score:1
in flag

You can use cgroup and assign application accordingly based on your requirement, one reference is cgroups-v2

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.