Cgroups - howto: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 16: | Line 16: | ||
# Add cgroup_enable=memory to GRUB_CMDLINE_KERNEL: |
# Add cgroup_enable=memory to GRUB_CMDLINE_KERNEL: |
||
GRUB_CMDLINE_LINUX="cgroup_enable=memory" |
GRUB_CMDLINE_LINUX="cgroup_enable=memory" |
||
update-grub2 |
|||
</pre> |
|||
== Mount cgroups == |
|||
Add to /etc/fstab |
|||
<pre> |
|||
cgroup /sys/fs/cgroup cgroup defaults 0 0 |
|||
</pre> |
|||
= Create cgroup owner(s) = |
|||
<pre> |
|||
sudo cgcreate -a limiter -g cpu:limiter |
|||
</pre> |
|||
* Adding ressources to that user. A CPU is divided into 1024 slices, so assigning 100 for a user would equal ~10%. |
|||
<pre> |
|||
# About 10 % cpu |
|||
echo 100 > /cgroup/cpu/$USER/cpu.shares |
|||
# 10 Mb |
|||
echo 10000000 > /cgroup/memory/$USER/memory.limit_in_bytes |
|||
# -g specifies the control group to run the process in |
|||
# Limit cpu |
|||
cgexec -g cpu:$USER command <options> & |
|||
# Limit cpu and memory |
|||
cgexec -g memory,cpu:$USER command <options> & |
|||
</pre> |
|||
If the above works fine, cgroups is setup successfully. |
|||
= Setting up configurations = |
|||
Edit /etc/cgconfig.conf, add your cgroups users |
|||
<pre> |
|||
group $USER { |
|||
# Specify which users can admin (set limits) the group |
|||
perm { |
|||
admin { |
|||
uid = $USER; |
|||
} |
|||
# Specify which users can add tasks to this group |
|||
task { |
|||
uid = $USER; |
|||
} |
|||
} |
|||
# Set the cpu and memory limits for this group |
|||
cpu { |
|||
cpu.shares = 100; |
|||
} |
|||
memory { |
|||
memory.limit_in_bytes = 10000000; |
|||
} |
|||
} |
|||
</pre> |
</pre> |
Latest revision as of 11:39, 20 September 2014
Howto - cgroups
This is only for debian wheezy
Prereq
apt-get install cgroup-bin
Enable cgroups memory configuration
This is disabled by default in wheezy (installed though), so activate via:
vim /etc/default/grub # Add cgroup_enable=memory to GRUB_CMDLINE_KERNEL: GRUB_CMDLINE_LINUX="cgroup_enable=memory" update-grub2
Mount cgroups
Add to /etc/fstab
cgroup /sys/fs/cgroup cgroup defaults 0 0
Create cgroup owner(s)
sudo cgcreate -a limiter -g cpu:limiter
- Adding ressources to that user. A CPU is divided into 1024 slices, so assigning 100 for a user would equal ~10%.
# About 10 % cpu echo 100 > /cgroup/cpu/$USER/cpu.shares # 10 Mb echo 10000000 > /cgroup/memory/$USER/memory.limit_in_bytes # -g specifies the control group to run the process in # Limit cpu cgexec -g cpu:$USER command <options> & # Limit cpu and memory cgexec -g memory,cpu:$USER command <options> &
If the above works fine, cgroups is setup successfully.
Setting up configurations
Edit /etc/cgconfig.conf, add your cgroups users
group $USER { # Specify which users can admin (set limits) the group perm { admin { uid = $USER; } # Specify which users can add tasks to this group task { uid = $USER; } } # Set the cpu and memory limits for this group cpu { cpu.shares = 100; } memory { memory.limit_in_bytes = 10000000; } }