-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset-cgroups-limits.sh
More file actions
executable file
·76 lines (70 loc) · 1.8 KB
/
set-cgroups-limits.sh
File metadata and controls
executable file
·76 lines (70 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Set cgroups limits.
# Set bash strict mode.
set -euo pipefail
device="$(hostname)"
case "$device" in
"alicecerno2")
versionCGroups=2
ramMax=770690780160
cpuMax=9500000
ioWriteMax=660602880
ioReadMax=1887436800
partition="8:0"
;;
"alipap1")
versionCGroups=2
ramMax=384880619315
cpuMax=9500000
ioWriteMax=471859200
ioReadMax=1038090240
partition="8:0"
;;
"aliceml")
versionCGroups=2
ramMax=385122671411
cpuMax=5500000
ioWriteMax=471859200
ioReadMax=1226833920
partition="8:96"
;;
*)
echo "Not a known device!"
exit 1
;;
esac
setLimit() {
limit="$1"
file="$2"
[[ -f "$file" ]] || { echo "File $file does not exist."; return; }
# set -o xtrace
echo "$limit" > "$file"
# set +o xtrace
echo "$file"
cat "$file"
}
echo "Setting cgroups (v$versionCGroups) limits for $device"
if [[ $versionCGroups -eq 1 ]]; then
# cgroups v1
# RAM
setLimit "$ramMax" /sys/fs/cgroup/memory/user.slice/memory.limit_in_bytes
# CPU
setLimit "$cpuMax" /sys/fs/cgroup/cpu/user.slice/cpu.cfs_quota_us
# IO
setLimit "$partition $ioWriteMax" /sys/fs/cgroup/blkio/user.slice/blkio.throttle.write_bps_device
setLimit "$partition $ioReadMax" /sys/fs/cgroup/blkio/user.slice/blkio.throttle.read_bps_device
elif [[ $versionCGroups -eq 2 ]]; then
# cgroups v2
# enable controllers
setLimit "+memory +cpu +io" /sys/fs/cgroup/cgroup.subtree_control
setLimit "+memory +cpu +io" /sys/fs/cgroup/user.slice/cgroup.subtree_control
# RAM
setLimit "$ramMax" /sys/fs/cgroup/user.slice/memory.max
# CPU
setLimit "$cpuMax" /sys/fs/cgroup/user.slice/cpu.max
# IO
setLimit "$partition wbps=$ioWriteMax rbps=$ioReadMax" /sys/fs/cgroup/user.slice/io.max
else
echo "Unsupported version of cgroups $versionCGroups"
exit 1
fi