summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-03-27 19:56:50 -0400
committerAndrew Cady <d@cryptonomic.net>2022-03-27 19:56:50 -0400
commit88e95dad71447b03ac95514da0fd281389dc9d7b (patch)
tree141c1ec445a13f989bcac57bcca4ca1e98b9cc1b
parentbe326e580cb7a34634242e7408a99607231d9aa7 (diff)
working
-rwxr-xr-xfireslay18
-rwxr-xr-xioslay-firefox8
-rwxr-xr-xioslay-mgr.sh25
-rwxr-xr-xsliceweasel2
-rwxr-xr-xsliceweasel.lib.sh4
5 files changed, 37 insertions, 20 deletions
diff --git a/fireslay b/fireslay
index 3e52a84..9485cd4 100755
--- a/fireslay
+++ b/fireslay
@@ -80,14 +80,18 @@ web_content_pids()
80 then 80 then
81 echo $pid 81 echo $pid
82 fi 82 fi
83 done < $FIREFOX_GROUP/cgroup.procs 83 done < $FIREFOX_GROUP_PROCS
84} 84}
85 85
86CURRENT_GROUP=$(get_current_group) 86uid=$(getent passwd $SUDO_USER | (IFS=: read _ _ id _; echo $id))
87FIREFOX_GROUP=${CURRENT_GROUP%/*}/firefox 87group=user.slice/user-$uid.slice/firefox
88FIREFOX_GROUP_PROCS=$FIREFOX_GROUP/cgroup.procs 88group_procs=/sys/fs/cgroup/$group/cgroup.procs
89 89
90[ -e "$FIREFOX_GROUP_PROCS" ] 90FIREFOX_GROUP_PROCS=$group_procs
91 91if [ -e "$FIREFOX_GROUP_PROCS" ]
92main "$@" 92then
93 main "$@"
94else
95 echo "Error: Firefox group not found ($FIREFOX_GROUP_PROCS)" >&2
96fi
93 97
diff --git a/ioslay-firefox b/ioslay-firefox
index 0fae790..fb382e0 100755
--- a/ioslay-firefox
+++ b/ioslay-firefox
@@ -52,11 +52,11 @@ iotop_reader()
52 fi 52 fi
53 case "$log" in 53 case "$log" in
54 *1* ) 54 *1* )
55 ( 55 echo IO '!!' $log >&2
56 set -x
57 : $log
58 )
59 ;; 56 ;;
57 # * )
58 # echo IO OK $log >&2
59 # ;;
60 esac 60 esac
61 ;; 61 ;;
62 "Current DISK"*) continue ;; 62 "Current DISK"*) continue ;;
diff --git a/ioslay-mgr.sh b/ioslay-mgr.sh
index 1b8cf73..85ff4d7 100755
--- a/ioslay-mgr.sh
+++ b/ioslay-mgr.sh
@@ -64,18 +64,30 @@ vkill()
64 set -x 64 set -x
65 ps u "$@" 65 ps u "$@"
66 sudo kill "$@" 66 sudo kill "$@"
67 ) 67 )
68}
69
70slay_slayer()
71{
72 if [ "$ioslay" ]
73 then
74 children=$(for pid in $ioslay; do pgrep -P $ioslay; done)
75 grandchildren=$(for pid in $children; do pgrep -P $pid; done)
76 vkill $ioslay $children $grandchildren
77 fi
68} 78}
69 79
70uid=1000 80uid=1000
71group=user.slice/user-$uid.slice/firefox 81group=user.slice/user-$uid.slice/firefox
82group_procs=/sys/fs/cgroup/$group/cgroup.procs
72wantcomm='Web Content' 83wantcomm='Web Content'
73ioslay= 84ioslay=
74lastprocs= 85lastprocs=
75trap 'RECEIVED_SIGINT=y' SIGINT 86SIGNALLED=
76while [ -z "$RECEIVED_SIGINT" ] 87trap 'SIGNALLED=y' SIGINT SIGTERM SIGHUP
88while [ ! "$SIGNALLED" ]
77do 89do
78 read -N 1000100 procs < /sys/fs/cgroup/$group/cgroup.procs 90 read -N 1000100 procs < "$group_procs"
79 if [ "$procs" ] 91 if [ "$procs" ]
80 then 92 then
81 set -- 93 set --
@@ -91,7 +103,7 @@ do
91 # echo "pids: ($*|$(echo $procs))" >&2 103 # echo "pids: ($*|$(echo $procs))" >&2
92 if [ "$lastargs" != "$*" ] 104 if [ "$lastargs" != "$*" ]
93 then 105 then
94 [ -z "$ioslay" ] || vkill $ioslay $(pgrep -P $ioslay) 106 slay_slayer
95 wait $ioslay 107 wait $ioslay
96 sudo ioslay-firefox "$@" & 108 sudo ioslay-firefox "$@" &
97 ioslay=$! 109 ioslay=$!
@@ -100,5 +112,4 @@ do
100 fi 112 fi
101 sleep 1 113 sleep 1
102done 114done
103 115slay_slayer
104
diff --git a/sliceweasel b/sliceweasel
index 7a0cae2..f9df2c8 100755
--- a/sliceweasel
+++ b/sliceweasel
@@ -9,7 +9,7 @@ IO_ROOT_DIR=$HOME/.cache/mozilla/firefox/
9group=/sys/fs/cgroup/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 7/10
13exec firefox "$@" 13exec firefox "$@"
14 14
15 15
diff --git a/sliceweasel.lib.sh b/sliceweasel.lib.sh
index 3c54841..890fb79 100755
--- a/sliceweasel.lib.sh
+++ b/sliceweasel.lib.sh
@@ -107,10 +107,12 @@ set_max_ratio()
107 case "$controller" in 107 case "$controller" in
108 io) 108 io)
109 fsroot=$(get_filesystem "$IO_ROOT_DIR") || return 109 fsroot=$(get_filesystem "$IO_ROOT_DIR") || return
110 # TODO: Do not use lsblk, because it fails to report the correct
111 # MOUNTPOINT when a bind mount is present.
110 majmin=$(lsblk -o 'MOUNTPOINT,MAJ:MIN' | sed -ne "s?^$fsroot *??p") || return 112 majmin=$(lsblk -o 'MOUNTPOINT,MAJ:MIN' | sed -ne "s?^$fsroot *??p") || return
111 case "$majmin" in 113 case "$majmin" in
112 *:*) ;; 114 *:*) ;;
113 *) return 1 ;; 115 *) echo "Error: majmin=$majmin" >&2; return 1 ;;
114 esac 116 esac
115 set_max "$group" "$controller" "$majmin wbps=$limit rbps=$limit" 117 set_max "$group" "$controller" "$majmin wbps=$limit rbps=$limit"
116 ;; 118 ;;