summaryrefslogtreecommitdiff
path: root/dot/local
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-12-09 03:58:40 -0500
committerAndrew Cady <d@jerkface.net>2018-12-09 03:58:40 -0500
commit7aa3cd0a0e2961388df2cc11665dabef2250d6d7 (patch)
treec896a5794ccac2cee8de95ace42929d8cd84512b /dot/local
parentd10f93fbbd4116f083a682dcf431b3b84d8ec6e4 (diff)
sliceweasel: WIP on cpu slicing
Diffstat (limited to 'dot/local')
-rwxr-xr-x[-rw-r--r--]dot/local/bin/sliceweasel22
1 files changed, 19 insertions, 3 deletions
diff --git a/dot/local/bin/sliceweasel b/dot/local/bin/sliceweasel
index 1ec45db..c6f07d0 100644..100755
--- a/dot/local/bin/sliceweasel
+++ b/dot/local/bin/sliceweasel
@@ -18,12 +18,17 @@ memory_limit_in_bytes=$(bc -q <<< "$total_memory * $memory_ratio / 1" ) || die "
18 18
19init_control_group() 19init_control_group()
20{ 20{
21 control_group_dir=/sys/fs/cgroup/memory/"$control_group" 21 control_group_dir=/sys/fs/cgroup/"$1"/"$control_group"
22 [ -d "$control_group_dir" ] && return 22 [ -d "$control_group_dir" ] && return
23 $as_root mkdir "$control_group_dir" || die "mkdir failed" 23 $as_root mkdir "$control_group_dir" || die "mkdir failed"
24 set_memory_limit $memory_limit_in_bytes || die "set_memory_limit failed" 24 set_memory_limit $memory_limit_in_bytes || die "set_memory_limit failed"
25} 25}
26 26
27get_cpu_limit()
28{
29 false
30}
31
27get_memory_limit() 32get_memory_limit()
28{ 33{
29 cat "$control_group_dir"/memory.limit_in_bytes 34 cat "$control_group_dir"/memory.limit_in_bytes
@@ -60,7 +65,7 @@ get_cgroup()
60 65
61launch_command() 66launch_command()
62{ 67{
63 init_control_group || die "init_control_group failed" 68 init_control_group memory || die "init_control_group failed"
64 cg=$(get_cgroup memory) || die "failed to ascertain current control group" 69 cg=$(get_cgroup memory) || die "failed to ascertain current control group"
65 [ "$cg" = / ] || die "current control group should be '/', but is instead '$cg'" 70 [ "$cg" = / ] || die "current control group should be '/', but is instead '$cg'"
66 join_control_group || die "join_control_group failed" 71 join_control_group || die "join_control_group failed"
@@ -75,9 +80,19 @@ pretty_show_memory_limit()
75 "$((memory_limit * 100 / total_memory))" 80 "$((memory_limit * 100 / total_memory))"
76} 81}
77 82
83recpu_control_group()
84{
85 init_control_group cpu
86 case "$1" in
87 [0-9]*%) set_cpu_limit $((total_cpu * "${1%\%}" / 100)) ;;
88 [0-9]*) set_cpu_limit "$1" ;;
89 [-+*/][0-9]*) set_cpu_limit $(( $(get_cpu_limit) "$1" )) ;;
90 esac
91}
92
78resize_control_group() 93resize_control_group()
79{ 94{
80 init_control_group 95 init_control_group memory
81 case "$1" in 96 case "$1" in
82 '') pretty_show_memory_limit >&2 ;; 97 '') pretty_show_memory_limit >&2 ;;
83 [0-9]*%) set_memory_limit $((total_memory * "${1%\%}" / 100)) ;; 98 [0-9]*%) set_memory_limit $((total_memory * "${1%\%}" / 100)) ;;
@@ -98,6 +113,7 @@ case "$1" in
98 --) shift; launch_command "$@" ;; 113 --) shift; launch_command "$@" ;;
99 --resize) resize_control_group "$2" ;; 114 --resize) resize_control_group "$2" ;;
100 --resize=*) resize_control_group "${1#--resize=}" ;; 115 --resize=*) resize_control_group "${1#--resize=}" ;;
116 --cpu=*) recpu_control_group "${1#--cpu=}"
101 --*) usage; [ "$1" = '--help' -o "$1" = '--usage' ] ;; 117 --*) usage; [ "$1" = '--help' -o "$1" = '--usage' ] ;;
102 *) launch_command "$@" ;; 118 *) launch_command "$@" ;;
103esac 119esac