Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/spark-supervisor/blob/main/om/limits.om # spark-supervisor Process supervisor and health monitor for sovereign daemons Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `spark-supervisor / om / limits.om` 264 lines ยท 3644 bytes Raw Blame History 1 note Direct cgroup v2 user delegation. No systemd command is executed. 2 note The configured root must be a private child of a writable delegated domain. 3 4 fn cgrootpath to void 5 pset 6 for j ulong ulong get cgData 0 7 pb get cgRoot j 8 end 9 end 10 11 fn cgleafpath to void 12 pset 13 for j ulong ulong get cgData 1 14 pb get cgLeaf j 15 end 16 end 17 18 fn cgleafsave to void 19 put cgData 1 long plen 20 for j ulong plen 21 put cgLeaf j get pth j 22 end 23 end 24 25 note Write all bytes, then verify an exact numeric readback (kernel adds newline). 26 fn cgWriteValue value ulong to long 27 fd = popen 655361 0 28 if lt fd 0 29 ret fd 30 end 31 put gu GOB 0 32 onum long value 33 n = get gu GOB 34 position = ulong 0 35 while lt position n bound 4096 36 w = write int fd ob position sub n position 37 if le w 0 38 c = fclose int fd 39 ret -5 40 end 41 position = add position ulong w 42 end 43 c = fclose int fd 44 fd = popen ORDO 0 45 if lt fd 0 46 ret fd 47 end 48 r = read int fd ebuf 0 len ebuf 49 c = fclose int fd 50 if lt r long n 51 ret -5 52 end 53 for j ulong n 54 if ne get ob j get ebuf j 55 ret -5 56 end 57 end 58 if eq r long add n 1 59 if ne get ebuf n 10 60 ret -5 61 end 62 else 63 if ne r long n 64 ret -5 65 end 66 end 67 put gu GOB 0 68 ret 0 69 end 70 71 fn cgSet key view uchar * value ulong to long 72 cgleafpath 73 pstr key 74 ret cgWriteValue value 75 end 76 77 fn cgMove pid ulong to long 78 ret cgSet cgProcs pid 79 end 80 81 note cgroup.procs readback may contain other PIDs; enter is checked by /proc/self/cgroup too. 82 fn cgEnter to long 83 cgleafpath 84 pstr cgProcs 85 fd = popen 655361 0 86 if lt fd 0 87 ret fd 88 end 89 put gu GOB 0 90 onum getpid 91 w = write int fd ob 0 get gu GOB 92 n = get gu GOB 93 put gu GOB 0 94 c = fclose int fd 95 if ne w long n 96 ret -5 97 end 98 ret 0 99 end 100 101 fn cgInitialize to void 102 put cgData 2 -2 103 n = envget cgEnv 104 if le n 0 105 ret 106 end 107 if ge n 4000 108 put cgData 2 -36 109 ret 110 end 111 if ne get av 0 47 112 put cgData 2 -22 113 ret 114 end 115 for j ulong ulong n 116 put cgRoot j get av j 117 end 118 put cgData 0 n 119 cgrootpath 120 r = makedir pth 0 plen 448 121 if and lt r 0 ne r -17 122 put cgData 2 r 123 ret 124 end 125 cgrootpath 126 pstr cgManager 127 r = makedir pth 0 plen 448 128 if and lt r 0 ne r -17 129 put cgData 2 r 130 ret 131 end 132 cgleafsave 133 r = cgEnter 134 if lt r 0 135 put cgData 2 r 136 ret 137 end 138 cgrootpath 139 pstr cgControl 140 fd = popen 655361 0 141 if lt fd 0 142 put cgData 2 fd 143 ret 144 end 145 w = write int fd cgControllers 0 len cgControllers 146 c = fclose int fd 147 if ne w long len cgControllers 148 put cgData 2 -5 149 ret 150 end 151 put cgData 2 0 152 end 153 154 fn cgPrepare memory ulong tasks ulong weight ulong to long 155 if lt get cgData 2 0 156 ret get cgData 2 157 end 158 cgleafpath 159 r = makedir pth 0 plen 448 160 if lt r 0 161 ret r 162 end 163 if gt memory 0 164 r = cgSet cgMemory memory 165 if lt r 0 166 ret r 167 end 168 r = cgSet cgSwap 0 169 if lt r 0 170 ret r 171 end 172 r = cgSet cgOomGroup 1 173 if lt r 0 174 ret r 175 end 176 end 177 if gt tasks 0 178 r = cgSet cgPids tasks 179 if lt r 0 180 ret r 181 end 182 end 183 if gt weight 0 184 r = cgSet cgWeight weight 185 if lt r 0 186 ret r 187 end 188 end 189 ret 0 190 end 191 192 fn cgServicePath i ulong to void 193 cgrootpath 194 pstr cgSvc 195 pname i 196 cgleafsave 197 end 198 199 fn cgServicePrepare i ulong to long 200 if not cgLimited i 201 ret 0 202 end 203 cgServicePath i 204 cgRemove 205 cgServicePath i 206 ret cgPrepare get cgMem i get cgTasks i get cgCpu i 207 end 208 209 fn cgLimited i ulong to bool 210 ret or or gt get cgMem i 0 gt get cgTasks i 0 gt get cgCpu i 0 211 end 212 213 fn cgServiceEnter i ulong to long 214 if not cgLimited i 215 ret 0 216 end 217 cgServicePath i 218 ret cgEnter 219 end 220 221 fn cgKillLeaf to void 222 cgleafpath 223 pstr cgKill 224 fd = popen 655361 0 225 if ge fd 0 226 w = write int fd cgOne 0 len cgOne 227 c = fclose int fd 228 end 229 end 230 231 fn cgRemove to void 232 cgleafpath 233 r = rmdir pth 0 plen 234 end 235 236 fn cgOomCount to ulong 237 cgleafpath 238 pstr cgEvents 239 r = rdfile 240 if lt r 0 241 ret 0 242 end 243 p = ulong 0 244 while lt p get gu GSF bound 999999 245 p = lnext p 246 if wis 0 cgOomKey 247 v = wnum 1 248 if ge v 0 249 ret ulong v 250 end 251 end 252 end 253 ret 0 254 end 255 256 fn cgServiceExit i ulong to void 257 if not cgLimited i 258 ret 259 end 260 cgServicePath i 261 put cgOom i cgOomCount 262 cgKillLeaf 263 cgRemove 264 end