summaryrefslogtreecommitdiff
path: root/sliceweasel
diff options
context:
space:
mode:
Diffstat (limited to 'sliceweasel')
-rwxr-xr-xsliceweasel134
1 files changed, 3 insertions, 131 deletions
diff --git a/sliceweasel b/sliceweasel
index 1b34d67..ebca97f 100755
--- a/sliceweasel
+++ b/sliceweasel
@@ -1,137 +1,9 @@
1#!/bin/sh 1#!/bin/sh
2 2. sliceweasel.lib.sh
3# HAHAHAH Bro it finally works. It fucking works. It finally fucking works.
4
5# It just needs to monitor IO with iotop and start killing firefox processes
6# from the bottom (least memory usage) up. This allows any one tab access to the
7# full memory available to Firefox! And integrate it into the your-fired.sh
8# script. And it's truly fixed. And integrate the firefox updater.
9
10IO_ROOT_DIR=$HOME/.cache/mozilla/firefox/
11
12[ -d "$IO_ROOT_DIR" ] || exit
13
14get_age()
15{
16 local mtime now
17 mtime=$(stat --format=%Y "$1") || return
18 now=$(date +%s) || return
19 echo $(( now - mtime ))
20}
21
22get_filesystem()
23{
24 echo /
25}
26
27get_total_memory()
28{
29 free -b | {
30 read _
31 read _ total _
32 echo $total
33 }
34}
35
36math()
37{
38 printf '%s\n' "$*" | bc -lq
39}
40
41get_total_io()
42{
43 results=$IO_ROOT_DIR/io.test.result
44 zeroes=$IO_ROOT_DIR/io.test
45 if [ -e "$results" ]
46 then
47 age=$(get_age "$results") || return
48 if [ "$age" -gt $((60 * 60 * 24 * 7)) ]
49 then
50 rm "$results"
51 fi
52 fi
53
54 if ! [ -e "$results" ]
55 then
56 MEGS=128
57 then=$(date +%s.%N) || return
58 dd if=/dev/zero of="$zeroes" bs=${MEGS}M count=1 || return
59 now=$(date +%s.%N) || return
60 rm "$zeroes"
61 speed=$(math $now - $then / $((MEGS * 1024 * 1024))) || return
62 echo $speed > "$results"
63 fi
64 read total < "$results" || return
65 echo ${total%.*}
66}
67
68root_write()
69{
70 $AS_ROOT sh -c 'cat > "$1"' sh "$1"
71}
72
73join_group()
74{
75 GROUP_DIR=/sys/fs/cgroup/"$1"
76 [ -d "$GROUP_DIR" ] || $AS_ROOT mkdir "$GROUP_DIR"
77 echo $$ | root_write "$GROUP_DIR"/cgroup.procs
78}
79
80add_subtree_controller()
81{
82 local group="$1" controller="$2" control_file
83 control_file=$(realpath -e "/sys/fs/cgroup/$group/cgroup.subtree_control") || return
84 case "$control_file" in
85 /sys/fs/cgroup/cgroup.subtree_control) ;;
86 *) add_subtree_controller "$group"/.. "$2" ;;
87 esac
88
89 [ "$1" ] && [ "$2" ] && [ -e "$control_file" ] || return
90 if ! grep -q "\\b${controller}\\b" "$control_file"
91 then
92 echo +"$controller" | root_write "$control_file"
93 fi
94}
95
96set_max()
97{
98 add_subtree_controller "$1"/.. "$2"
99 [ -e "$GROUP_DIR"/"$2".max ] || return
100 printf '%s\n' "$3" | root_write "$GROUP_DIR"/"$2".max
101}
102
103set_max_ratio()
104{
105 local group="$1" controller="$2" ratio="$3" limit
106 total=$(get_total_$controller)
107 n=${ratio%%/*}
108 d=${ratio#$n/}
109 [ "$d" = "${d%/*}" ] || return
110 limit=$(( total * n / d ))
111 [ "$limit" ] || return
112 [ "$limit" -gt 0 ] || return
113 case "$controller" in
114 io)
115 fsroot=$(get_filesystem "$IO_ROOT_DIR") || return
116 majmin=$(lsblk -o 'MOUNTPOINT,MAJ:MIN' | sed -ne "s?^$fsroot *??p") || return
117 case "$majmin" in
118 *:*) ;;
119 *) return 1 ;;
120 esac
121 set_max "$group" "$controller" "$majmin wbps=$limit rbps=$limit"
122 ;;
123 *) set_max "$group" "$controller" "$limit"
124 esac
125}
126
127get_current_group()
128{
129 read g < /proc/$$/cgroup
130 echo ${g#0::/}
131}
132 3
133set -e 4set -e
134 5IO_ROOT_DIR=$HOME/.cache/mozilla/firefox/
6[ -d "$IO_ROOT_DIR" ]
135[ "$(id -un)" = 0 ] && AS_ROOT= || AS_ROOT='sudo --' 7[ "$(id -un)" = 0 ] && AS_ROOT= || AS_ROOT='sudo --'
136 8
137group=user.slice/user-$(id -u).slice/firefox 9group=user.slice/user-$(id -u).slice/firefox