mirror of
https://github.com/p8952/bocker.git
synced 2025-11-08 21:43:59 +01:00
Allow the setting of cgroup limits using env variables; Allocate CPU resources via shares not cores
This commit is contained in:
parent
df8c4065c7
commit
74c2b197c7
28
README.md
28
README.md
@ -79,6 +79,34 @@ Created: img_42150
|
|||||||
|
|
||||||
$ bocker run img_42150 which wget
|
$ bocker run img_42150 which wget
|
||||||
/usr/bin/wget
|
/usr/bin/wget
|
||||||
|
|
||||||
|
$ bocker run img_42150 cat /proc/1/cgroup
|
||||||
|
...
|
||||||
|
4:memory:/ps_42152
|
||||||
|
3:cpuacct,cpu:/ps_42152
|
||||||
|
...
|
||||||
|
|
||||||
|
$ cat /sys/fs/cgroup/cpu/ps_42152/cpu.shares
|
||||||
|
512
|
||||||
|
|
||||||
|
$ cat cat /sys/fs/cgroup/memory/ps_42152/memory.limit_in_bytes
|
||||||
|
512000000
|
||||||
|
|
||||||
|
|
||||||
|
$ BOCKER_CPU_SHARE=1024 \
|
||||||
|
BOCKER_MEM_LIMIT=1024 \
|
||||||
|
bocker run img_42150 cat /proc/1/cgroup
|
||||||
|
...
|
||||||
|
4:memory:/ps_42188
|
||||||
|
3:cpuacct,cpu:/ps_42188
|
||||||
|
|
||||||
|
$ cat /sys/fs/cgroup/cpu/ps_42188/cpu.shares
|
||||||
|
1024
|
||||||
|
|
||||||
|
$ cat cat /sys/fs/cgroup/memory/ps_42188/memory.limit_in_bytes
|
||||||
|
1024000000
|
||||||
|
...
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Functionality: Currently Implemented
|
## Functionality: Currently Implemented
|
||||||
|
|||||||
6
bocker
6
bocker
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -o errexit -o nounset -o pipefail; shopt -s nullglob
|
set -o errexit -o nounset -o pipefail; shopt -s nullglob
|
||||||
btrfs_path='/var/bocker'; cgroups='cpu,cpuacct,cpuset,memory';
|
btrfs_path='/var/bocker' && cgroups='cpu,cpuacct,memory';
|
||||||
|
|
||||||
function bocker_check() {
|
function bocker_check() {
|
||||||
btrfs subvolume list "$btrfs_path" | grep -qw "$1" && echo 0 || echo 1
|
btrfs subvolume list "$btrfs_path" | grep -qw "$1" && echo 0 || echo 1
|
||||||
@ -76,8 +76,8 @@ function bocker_run() { #HELP Create a container:\nBOCKER run <image_id> <comman
|
|||||||
echo 'nameserver 8.8.8.8' > "$btrfs_path/$uuid"/etc/resolv.conf
|
echo 'nameserver 8.8.8.8' > "$btrfs_path/$uuid"/etc/resolv.conf
|
||||||
echo "$cmd" > "$btrfs_path/$uuid/$uuid.cmd"
|
echo "$cmd" > "$btrfs_path/$uuid/$uuid.cmd"
|
||||||
cgcreate -g "$cgroups:/$uuid"
|
cgcreate -g "$cgroups:/$uuid"
|
||||||
cgset -r cpuset.cpus=0-1 "$uuid" && cgset -r cpuset.mems=0 "$uuid"
|
: ${BOCKER_CPU_SHARE:=512} && cgset -r cpu.shares="$BOCKER_CPU_SHARE" "$uuid"
|
||||||
cgset -r memory.limit_in_bytes=512000000 "$uuid"
|
: ${BOCKER_MEM_LIMIT:=512} && cgset -r memory.limit_in_bytes="$((BOCKER_MEM_LIMIT * 1000000))" "$uuid"
|
||||||
cgexec -g "$cgroups:$uuid" \
|
cgexec -g "$cgroups:$uuid" \
|
||||||
ip netns exec netns_"$uuid" \
|
ip netns exec netns_"$uuid" \
|
||||||
unshare -fmuip --mount-proc \
|
unshare -fmuip --mount-proc \
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user