@torrent-tv/proxy 2.95.11 → 2.95.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -58,17 +58,26 @@ import os from "node:os";
|
|
|
58
58
|
* Version 1 states the file lists of the cgroup alone as `active_file` and of
|
|
59
59
|
* it with its descendants as `total_active_file`; its usage includes the
|
|
60
60
|
* descendants, so the hierarchical figures are the ones that subtract from it.
|
|
61
|
+
*
|
|
62
|
+
* Version 2 has two limits. `memory.max` is where the kernel kills;
|
|
63
|
+
* `memory.high` is where it throttles the cgroup and pushes its memory out —
|
|
64
|
+
* on the Home Assistant kernel a 300 MB allocation took 2123 ms instead of
|
|
65
|
+
* 527 ms past a 128 MiB `memory.high`, with 186 MiB of it sent to swap
|
|
66
|
+
* (torrent-tv/meta#155). systemd's `MemoryHigh=` sets it without
|
|
67
|
+
* `MemoryMax=`, so it is a limit of its own, and a level's limit is the
|
|
68
|
+
* smaller of the two. Version 1's soft limit is not a counterpart: it only
|
|
69
|
+
* orders reclaim when the whole machine is short.
|
|
61
70
|
*/
|
|
62
71
|
const HIERARCHIES = {
|
|
63
72
|
1: {
|
|
64
73
|
mount: "/sys/fs/cgroup/memory",
|
|
65
|
-
|
|
74
|
+
limits: ["memory.limit_in_bytes"],
|
|
66
75
|
usage: "memory.usage_in_bytes",
|
|
67
76
|
reclaimable: ["total_active_file", "total_inactive_file"]
|
|
68
77
|
},
|
|
69
78
|
2: {
|
|
70
79
|
mount: "/sys/fs/cgroup",
|
|
71
|
-
|
|
80
|
+
limits: ["memory.max", "memory.high"],
|
|
72
81
|
usage: "memory.current",
|
|
73
82
|
reclaimable: ["active_file", "inactive_file", "slab_reclaimable"]
|
|
74
83
|
}
|
|
@@ -230,18 +239,24 @@ function levelsOf(mount, path) {
|
|
|
230
239
|
* @param {string} directory
|
|
231
240
|
* @param {number} hostTotal
|
|
232
241
|
* @returns {{ roomBytes: number, limitBytes: number } | null} Null where this
|
|
233
|
-
* level states no limit — `max
|
|
242
|
+
* level states no limit — `max` in every limit file, the version 1
|
|
243
|
+
* sentinel — or is not there.
|
|
234
244
|
*/
|
|
235
245
|
function roomAt(readFile, hierarchy, directory, hostTotal) {
|
|
236
|
-
let limitBytes;
|
|
237
246
|
let usageBytes;
|
|
238
247
|
try {
|
|
239
|
-
limitBytes = bytesOf(readFile(`${directory}/${hierarchy.limit}`));
|
|
240
248
|
usageBytes = bytesOf(readFile(`${directory}/${hierarchy.usage}`));
|
|
241
249
|
} catch {
|
|
242
250
|
return null; // silent-ok: no such level, or no memory controller on it.
|
|
243
251
|
}
|
|
244
|
-
|
|
252
|
+
const limitBytes = Math.min(...hierarchy.limits.map((name) => {
|
|
253
|
+
try {
|
|
254
|
+
return bytesOf(readFile(`${directory}/${name}`));
|
|
255
|
+
} catch {
|
|
256
|
+
return Number.NaN; // silent-ok: a limit file this kernel does not have states no limit.
|
|
257
|
+
}
|
|
258
|
+
}).filter(Number.isFinite));
|
|
259
|
+
if (limitBytes >= hostTotal || !Number.isFinite(usageBytes)) {
|
|
245
260
|
return null;
|
|
246
261
|
}
|
|
247
262
|
let reclaimableBytes = 0;
|