summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-01-23 10:52:19 -0500
committerAndrew Cady <d@cryptonomic.net>2022-01-23 10:52:19 -0500
commite0783c80d3d6f6f6efdbe2fddde4ff1ec00a5558 (patch)
treecac70a80c69dc914f32055812d90f571d3c727e5
parent7cd5e3d95512ef83bdc19dca9268b499785ea777 (diff)
this all works i think
-rwxr-xr-xfireslay20
-rwxr-xr-xsliceuser1
-rwxr-xr-xsliceweasel2
-rwxr-xr-xsliceweasel.lib.sh23
4 files changed, 27 insertions, 19 deletions
diff --git a/fireslay b/fireslay
index 1926e19..a63a709 100755
--- a/fireslay
+++ b/fireslay
@@ -1,4 +1,6 @@
1#!/bin/sh 1#!/bin/sh
2set -e
3. sliceweasel.lib.sh
2 4
3die() 5die()
4{ 6{
@@ -54,7 +56,7 @@ main()
54 ;; 56 ;;
55 esac 57 esac
56 set -x 58 set -x
57 ps $* >&2 59 ps $* >&2 &
58 kill $* 60 kill $*
59 ) 61 )
60 62
@@ -65,14 +67,14 @@ main()
65 67
66web_content_pids() 68web_content_pids()
67{ 69{
68 top -w512 -bn1 -o '%MEM' | sed -e '1,/^$/d' | { 70 while read pids
69 while read line 71 do
70 do set -- $line 72 for pid in $pids
71 [ "${12} ${13}" = "Web Content" ] || continue 73 do
72 [ "${8}" != Z ] || continue 74 read comm < /proc/$pid/comm && [ "$comm" = 'Web Content' ] || continue
73 echo $1 75 read _ _ state _ < /proc/$pid/stat && [ "$state" != Z ] && echo $pid
74 done 76 done
75 } 77 done < "$(get_current_group)"/cgroup.procs
76} 78}
77 79
78main "$@" 80main "$@"
diff --git a/sliceuser b/sliceuser
index 9d80789..16d441f 100755
--- a/sliceuser
+++ b/sliceuser
@@ -7,6 +7,7 @@ IO_ROOT_DIR=$HOME/.cache/mozilla/firefox/
7[ "$(id -un)" = 0 ] && AS_ROOT= || AS_ROOT='sudo --' 7[ "$(id -un)" = 0 ] && AS_ROOT= || AS_ROOT='sudo --'
8 8
9group=$(get_current_group) 9group=$(get_current_group)
10set -x
10set_max_ratio "$group" memory 3/4 11set_max_ratio "$group" memory 3/4
11set_max_ratio "$group" io 8/10 12set_max_ratio "$group" io 8/10
12 13
diff --git a/sliceweasel b/sliceweasel
index ebca97f..7a0cae2 100755
--- a/sliceweasel
+++ b/sliceweasel
@@ -6,7 +6,7 @@ IO_ROOT_DIR=$HOME/.cache/mozilla/firefox/
6[ -d "$IO_ROOT_DIR" ] 6[ -d "$IO_ROOT_DIR" ]
7[ "$(id -un)" = 0 ] && AS_ROOT= || AS_ROOT='sudo --' 7[ "$(id -un)" = 0 ] && AS_ROOT= || AS_ROOT='sudo --'
8 8
9group=user.slice/user-$(id -u).slice/firefox 9group=/sys/fs/cgroup/user.slice/user-$(id -u).slice/firefox
10join_group "$group" 10join_group "$group"
11set_max_ratio "$group" memory 1/2 11set_max_ratio "$group" memory 1/2
12set_max_ratio "$group" io 9/10 12set_max_ratio "$group" io 9/10
diff --git a/sliceweasel.lib.sh b/sliceweasel.lib.sh
index bbaed78..3c54841 100755
--- a/sliceweasel.lib.sh
+++ b/sliceweasel.lib.sh
@@ -55,12 +55,12 @@ get_total_io()
55 55
56root_write() 56root_write()
57{ 57{
58 $AS_ROOT sh -c 'cat > "$1"' sh "$1" 58 $AS_ROOT sh -c 'cat > "$1"' sh "$1" || true
59} 59}
60 60
61join_group() 61join_group()
62{ 62{
63 GROUP_DIR=/sys/fs/cgroup/"$1" 63 GROUP_DIR="$1"
64 [ -d "$GROUP_DIR" ] || $AS_ROOT mkdir "$GROUP_DIR" 64 [ -d "$GROUP_DIR" ] || $AS_ROOT mkdir "$GROUP_DIR"
65 echo $$ | root_write "$GROUP_DIR"/cgroup.procs 65 echo $$ | root_write "$GROUP_DIR"/cgroup.procs
66} 66}
@@ -68,13 +68,15 @@ join_group()
68add_subtree_controller() 68add_subtree_controller()
69{ 69{
70 local group="$1" controller="$2" control_file 70 local group="$1" controller="$2" control_file
71 control_file=$(realpath -e "/sys/fs/cgroup/$group/cgroup.subtree_control") || return 71 control_file="$group/cgroup.subtree_control"
72 case "$control_file" in 72
73 /sys/fs/cgroup/cgroup.subtree_control) ;; 73 [ "$group" ] && [ "$controller" ] && [ -d "$group" ] && [ -e "$control_file" ] || return
74 *) add_subtree_controller "$group"/.. "$2" ;; 74
75 case "$group" in
76 /sys/fs/cgroup) ;;
77 *) add_subtree_controller "$(realpath "$group/..")" "$2" ;;
75 esac 78 esac
76 79
77 [ "$1" ] && [ "$2" ] && [ -e "$control_file" ] || return
78 if ! grep -qe "\\b${controller}\\b" "$control_file" 80 if ! grep -qe "\\b${controller}\\b" "$control_file"
79 then 81 then
80 echo +"$controller" | root_write "$control_file" 82 echo +"$controller" | root_write "$control_file"
@@ -83,9 +85,12 @@ add_subtree_controller()
83 85
84set_max() 86set_max()
85{ 87{
86 add_subtree_controller "$1"/.. "$2"
87 max_file=$group/$2.max 88 max_file=$group/$2.max
88 [ -e "$max_file" ] || return 89 if [ ! -e "$max_file" ]
90 then
91 add_subtree_controller "$1"/.. "$2"
92 [ -e "$max_file" ] || return
93 fi
89 printf '%s\n' "$3" | root_write "$max_file" 94 printf '%s\n' "$3" | root_write "$max_file"
90} 95}
91 96