Is there a way to restrict system resources to users? I know that used to exist a way of forcing every newly spawned process of a user into the specified cgroup by using cgred service along with /etc/cgconfig.conf file, as explained here How can I configure cgroups to fairly share resources between users?.

However, this approach seems to be deprecated and the only way I've found is to modify cgroup attributes here /sys/fs/cgroup/user.slice/user-${UID}.slice by using systemctl set-property utility, the problem with this is that systemd creates this cgroup only when the user is logged, it gets removed as soon as user logs out. I am finding a way to restrict user resources even if he is logged out.

1 Answer 1


I've come across a solution.

  1. Create slice configuration file for each user:

    sudo mkdir /etc/systemd/system/user-<uid>.slice.d
    sudo touch /etc/systemd/system/user-<uid>.slice.d/override.conf

  2. Configure resource control, for example:

    echo "[Slice]
    CPUWeight=20" |  sudo tee /etc/systemd/system/user-<uid>.slice.d/override.conf
  1. Apply changes:
    systemctl daemon-reload

You can check if it worked by reading the appropriate user slice cgroup attributes and check if they match with the values you choose, for example:

cd /sys/fs/cgroup/user.slice/user-<uid>.slice
cat memory.low
cat cpu.weight
  • 1
    (1) I changed “Be careful to the spaces” to “Be careful with the spaces”, because “Be careful to the spaces” is not standard English.  But, either way, what do you mean by that?  (2) You need to do echo … | sudo tee … not echo … > sudo tee ….  (You had it right the first time.)  (3) You might want to choose either <uid> or ${UID} and use it consistently.  (4) In the verification step, what is  <cgroup_attribute>? … … … … … … … … … Please do not respond in comments; edit your answer to make it clearer and more complete. Jan 20 at 14:56
  • Iam searching for the exact same solution. Share CPU equally between all users. Did your solution achieve this? If one users gets a slightly higher Weight, it could consume more CPU as others, right? Mar 17 at 6:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .