From 88e95dad71447b03ac95514da0fd281389dc9d7b Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sun, 27 Mar 2022 19:56:50 -0400 Subject: working --- fireslay | 18 +++++++++++------- ioslay-firefox | 8 ++++---- ioslay-mgr.sh | 25 ++++++++++++++++++------- sliceweasel | 2 +- sliceweasel.lib.sh | 4 +++- 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() then echo $pid fi - done < $FIREFOX_GROUP/cgroup.procs + done < $FIREFOX_GROUP_PROCS } -CURRENT_GROUP=$(get_current_group) -FIREFOX_GROUP=${CURRENT_GROUP%/*}/firefox -FIREFOX_GROUP_PROCS=$FIREFOX_GROUP/cgroup.procs +uid=$(getent passwd $SUDO_USER | (IFS=: read _ _ id _; echo $id)) +group=user.slice/user-$uid.slice/firefox +group_procs=/sys/fs/cgroup/$group/cgroup.procs -[ -e "$FIREFOX_GROUP_PROCS" ] - -main "$@" +FIREFOX_GROUP_PROCS=$group_procs +if [ -e "$FIREFOX_GROUP_PROCS" ] +then + main "$@" +else + echo "Error: Firefox group not found ($FIREFOX_GROUP_PROCS)" >&2 +fi diff --git a/ioslay-firefox b/ioslay-firefox index 0fae790..fb382e0 100755 --- a/ioslay-firefox +++ b/ioslay-firefox @@ -52,11 +52,11 @@ iotop_reader() fi case "$log" in *1* ) - ( - set -x - : $log - ) + echo IO '!!' $log >&2 ;; + # * ) + # echo IO OK $log >&2 + # ;; esac ;; "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() set -x ps u "$@" sudo kill "$@" - ) + ) +} + +slay_slayer() +{ + if [ "$ioslay" ] + then + children=$(for pid in $ioslay; do pgrep -P $ioslay; done) + grandchildren=$(for pid in $children; do pgrep -P $pid; done) + vkill $ioslay $children $grandchildren + fi } uid=1000 group=user.slice/user-$uid.slice/firefox +group_procs=/sys/fs/cgroup/$group/cgroup.procs wantcomm='Web Content' ioslay= lastprocs= -trap 'RECEIVED_SIGINT=y' SIGINT -while [ -z "$RECEIVED_SIGINT" ] +SIGNALLED= +trap 'SIGNALLED=y' SIGINT SIGTERM SIGHUP +while [ ! "$SIGNALLED" ] do - read -N 1000100 procs < /sys/fs/cgroup/$group/cgroup.procs + read -N 1000100 procs < "$group_procs" if [ "$procs" ] then set -- @@ -91,7 +103,7 @@ do # echo "pids: ($*|$(echo $procs))" >&2 if [ "$lastargs" != "$*" ] then - [ -z "$ioslay" ] || vkill $ioslay $(pgrep -P $ioslay) + slay_slayer wait $ioslay sudo ioslay-firefox "$@" & ioslay=$! @@ -100,5 +112,4 @@ do fi sleep 1 done - - +slay_slayer 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/ group=/sys/fs/cgroup/user.slice/user-$(id -u).slice/firefox join_group "$group" set_max_ratio "$group" memory 1/2 -set_max_ratio "$group" io 9/10 +set_max_ratio "$group" io 7/10 exec firefox "$@" 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() case "$controller" in io) fsroot=$(get_filesystem "$IO_ROOT_DIR") || return + # TODO: Do not use lsblk, because it fails to report the correct + # MOUNTPOINT when a bind mount is present. majmin=$(lsblk -o 'MOUNTPOINT,MAJ:MIN' | sed -ne "s?^$fsroot *??p") || return case "$majmin" in *:*) ;; - *) return 1 ;; + *) echo "Error: majmin=$majmin" >&2; return 1 ;; esac set_max "$group" "$controller" "$majmin wbps=$limit rbps=$limit" ;; -- cgit v1.2.3