GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dynamic slots: capacity readings: swap, pressure, live total, per-piece demand (DS2) by scuttletoby · Pull Request #284 · scuttletoby/t3code

dynamic slots: capacity readings: swap, pressure, live total, per-piece demand (DS2) #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
scuttletoby merged 2 commits into main from fork/capacity-readings
Nov 17, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

dynamic slots: capacity readings: swap, pressure, live total, per-piece demand (DS2) #284

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
8bad3cd
dynamic slots: capacity readings: swap, pressure, live total, per-pie…
scuttletoby Nov 17, 2026
fe6f5fb
dynamic slots: capacity readings: review fixes (container cap, PSI of…
scuttletoby Nov 17, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
dynamic slots: capacity readings: review fixes (container cap, PSI of…
…f, file errors)

- A failed read of cgroup.controllers or the v1 root memory.stat no longer
  reads as "no container": cgroup is "unreadable", so available memory and
  cores are null (never the host's numbers).
- The cgroup v2 root's memory.max and cpu.max are read whenever they exist,
  so a container with systemd inside is capped too; /proc/self/cgroup is no
  longer read. A real host's root has no such files.
- PSI built in but turned off (EOPNOTSUPP) reads as "no PSI" for the machine;
  everywhere else it stays a failed read.
- capacityFileError sorts the real host's file errors, tested code by code
  (every error read as missing no longer passes).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@scuttletoby @claude
scuttletoby and claude committed Nov 17, 2026
commit fe6f5fbec2a8a75bce69a9dbfd1eb8e7ca2c95b5

There are no files selected for viewing

32 changes: 21 additions & 11 deletions 32 packages/shared/src/capacity/README.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,27 @@ the list and the read: drop it). `capacityFactsOf` joins them with what the call
A missing, unreadable, empty, cut-short, impossible (available above total, swap free above swap total,
PSI above 100) or wrongly-unitted value is `null` (total, available, cores, demand) or `"unreadable"`
(swap, PSI, OS level): the rule then admits nothing or brakes, never more. Only a file that does not
exist where the OS simply has no such signal means "none": `/proc/pressure/memory` (kernel without PSI)
and a v1 box's PSI. Fixture cases marked `failed` must never give more room than their healthy host.

| Reading | Linux, cgroup v2 | Linux, cgroup v1 | macOS | Windows (and the rest) |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
| total, available | `/proc/meminfo` MemTotal, MemAvailable (kB); in a container (namespace root `0::/`) capped by `memory.max` and `memory.max - (memory.current - inactive_file)` | same; capped by the root `memory.limit_in_bytes` when below the total | Node's total; `vm_stat` free + inactive + speculative pages. If that fails: Node's free pages (an under-read) | Node's `totalmem`, `freemem` (with standby) |
| cores | Node's, capped by the namespace root's `cpu.max` | Node's (`cpu.cfs_quota_us` not read) | Node's | Node's |
| swap | SwapTotal, SwapFree; total 0 = none | same | none: swap files grow on demand (wider margin; the OS level covers it) | none: Node does not give the page file (wider margin) |
| PSI | `/proc/pressure/memory`; missing = none (margin only) | same | none: the OS level `kern.memorystatus_vm_pressure_level` (1 ok, 2 elevated, 4 severe; else unreadable) | none, no OS level: available against the margin only |
| box PSI | `<box>/memory.pressure`; missing = unreadable | none | none | none |
| demand of a piece | `memory.stat` anon + shmem + `memory.swap.current` (missing swap part = 0: owes more); `current`, `peak` kept for cost learning | `total_rss + total_shmem + total_swap`; `usage_in_bytes`, `max_usage_in_bytes` | `null`: owes its full cost | `null`: owes its full cost |
exist where the OS simply has no such signal means "none": `/proc/pressure/memory` (kernel without PSI;
also when it exists but PSI is turned off, EOPNOTSUPP) and a v1 box's PSI. A failed read is never
"missing": the real host sorts only ENOENT/ENOTDIR as missing and EOPNOTSUPP as turned off; EACCES,
EIO and the rest are unreadable. When `cgroup.controllers` or the v1 root `memory.stat` (how the
cgroup version is found) cannot be read, `cgroup` is `"unreadable"`: a container cap is unknown, so
available and cores are `null`. Fixture cases marked `failed` must never give more room than their
healthy host.

| Reading | Linux, cgroup v2 | Linux, cgroup v1 | macOS | Windows (and the rest) |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
| total, available | `/proc/meminfo` MemTotal, MemAvailable (kB); in a container capped by the root's `memory.max` and `memory.max - (memory.current - inactive_file)` | same; capped by the root `memory.limit_in_bytes` when below the total | Node's total; `vm_stat` free + inactive + speculative pages. If that fails: Node's free pages (an under-read) | Node's `totalmem`, `freemem` (with standby) |
| cores | Node's, capped by the root's `cpu.max` | Node's (`cpu.cfs_quota_us` not read) | Node's | Node's |
| swap | SwapTotal, SwapFree; total 0 = none | same | none: swap files grow on demand (wider margin; the OS level covers it) | none: Node does not give the page file (wider margin) |
| PSI | `/proc/pressure/memory`; missing = none (margin only) | same | none: the OS level `kern.memorystatus_vm_pressure_level` (1 ok, 2 elevated, 4 severe; else unreadable) | none, no OS level: available against the margin only |
| box PSI | `<box>/memory.pressure`; missing = unreadable | none | none | none |
| demand of a piece | `memory.stat` anon + shmem + `memory.swap.current` (missing swap part = 0: owes more); `current`, `peak` kept for cost learning | `total_rss + total_shmem + total_swap`; `usage_in_bytes`, `max_usage_in_bytes` | `null`: owes its full cost | `null`: owes its full cost |

The cgroup v2 root's `memory.max` and `cpu.max` are read whenever they exist: a real host's root has
none (the kernel gives the root no limit files), so a host service's own unit limit is never taken,
and a container's namespace root has them wherever this process sits inside it (systemd inside the
container puts it in `/init.scope`, not at `0::/`); `/proc/self/cgroup` is not read.

Not read yet (stated limits): a cgroup v1 container's CPU quota and a container's `memory.swap.max`; a
cgroup v2 box with PSI turned off by `cgroup.pressure` reads as unreadable (elevated). Process-tree
Expand Down
116 changes: 115 additions & 1 deletion 116 packages/shared/src/capacity/capacity-readings.json
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"format": "capacity-readings/1",
"//": "Fixtures for the capacity readings (capacityReadings.ts; the kit's Python reader later runs the same cases). A host: platform, Node's numbers, files (text, or {error: unreadable}; a path not listed is missing) and commands ('file arg ...' -> stdout; not listed = failed). A case: a host, `failed` when it is a failed or half reading (it must never give more room than the healthy host), an optional patch (files/commands merged key by key, null removes; other keys replace), what to read, and the expected keys (only those given are compared; gaps are compared by reading name). Expected values are worked by hand: 1 MB = 1048576 bytes = 1024 kB, rounded down.",
"//": "Fixtures for the capacity readings (capacityReadings.ts; the kit's Python reader later runs the same cases). A host: platform, Node's numbers, files (text, {error: unreadable} or {error: unsupported} (EOPNOTSUPP: the kernel has the file but the feature is off); a path not listed is missing) and commands ('file arg ...' -> stdout; not listed = failed). A case: a host, `failed` when it is a failed or half reading (it must never give more room than the healthy host), an optional patch (files/commands merged key by key, null removes; other keys replace), what to read, and the expected keys (only those given are compared; gaps are compared by reading name). Expected values are worked by hand: 1 MB = 1048576 bytes = 1024 kB, rounded down.",
"hosts": {
"linux-v2": {
"platform": "linux",
Expand Down Expand Up @@ -252,6 +252,14 @@
"read": "machine",
"expect": { "psi": "unreadable", "gaps": [] }
},
{
"name": "PSI built in but turned off",
"why": "psi=0 at boot or CONFIG_PSI_DEFAULT_DISABLED (the RHEL 8 family): the file exists but reading it fails with EOPNOTSUPP. The kernel says it has no such signal: none, and the gap says so (not unreadable, which would hold the level at elevated for ever)",
"host": "linux-v2",
"patch": { "files": { "/proc/pressure/memory": { "error": "unsupported" } } },
"read": "machine",
"expect": { "psi": null, "gaps": ["psi"] }
},
{
"name": "PSI empty",
"failed": true,
Expand Down Expand Up @@ -396,6 +404,71 @@
"read": "machine",
"expect": { "cpuCores": null }
},
{
"name": "container with systemd inside",
"why": "systemd-nspawn, LXC/Incus or podman --systemd: this process sits in a unit (0::/init.scope), not at the namespace root. The root's memory.max and cpu.max still exist, so the cap is the container's: 4096 / 3328 / 2 as in 'container with a memory and CPU limit'",
"host": "linux-container",
"patch": { "files": { "/proc/self/cgroup": "0::/init.scope\n" } },
"read": "machine",
"expect": { "totalMb": 4096, "availableMb": 3328, "cpuCores": 2 }
},
{
"name": "container with systemd inside, deeper unit",
"why": "0::/system.slice/t3.service inside a container: still the root's cap",
"host": "linux-container",
"patch": { "files": { "/proc/self/cgroup": "0::/system.slice/t3.service\n" } },
"read": "machine",
"expect": { "totalMb": 4096, "availableMb": 3328, "cpuCores": 2 }
},
{
"name": "container, own cgroup unreadable",
"failed": true,
"why": "/proc/self/cgroup is not needed to find the cap: the root's memory.max and cpu.max decide. A failed read of it never removes the cap: 4096 / 3328 / 2",
"host": "linux-container",
"patch": { "files": { "/proc/self/cgroup": { "error": "unreadable" } } },
"read": "machine",
"expect": { "totalMb": 4096, "availableMb": 3328, "cpuCores": 2 }
},
{
"name": "container, cgroup.controllers unreadable",
"failed": true,
"why": "cannot tell which cgroup version, so not whether there is a cap: available and cores unreadable (never the host's 6886 / 12)",
"host": "linux-container",
"patch": { "files": { "/sys/fs/cgroup/cgroup.controllers": { "error": "unreadable" } } },
"read": "machine",
"expect": { "cgroup": "unreadable", "availableMb": null, "cpuCores": null }
},
{
"name": "container limit unsupported",
"failed": true,
"why": "EOPNOTSUPP means 'none' only for the machine PSI; on memory.max it is a failed read: available unreadable",
"host": "linux-container",
"patch": { "files": { "/sys/fs/cgroup/memory.max": { "error": "unsupported" } } },
"read": "machine",
"expect": { "availableMb": null }
},
{
"name": "host process with its own unit limit",
"why": "a real host's cgroup v2 root has no memory.max or cpu.max; this process's unit has its own limits (1 GB, 1 core). Those are the unit's, not the machine's: 12122 / 6886 / 12",
"host": "linux-v2",
"patch": {
"files": {
"/sys/fs/cgroup/work.slice/t3-server.scope/memory.max": "1073741824\n",
"/sys/fs/cgroup/work.slice/t3-server.scope/cpu.max": "100000 100000\n",
"/sys/fs/cgroup/work.slice/memory.max": "2147483648\n"
}
},
"read": "machine",
"expect": { "totalMb": 12122, "availableMb": 6886, "cpuCores": 12, "cgroup": "v2" }
},
{
"name": "host process at the cgroup root",
"why": "0::/ on a real host (no cgroup namespace): the root has no memory.max or cpu.max, so no cap: 12122 / 6886 / 12",
"host": "linux-v2",
"patch": { "files": { "/proc/self/cgroup": "0::/\n" } },
"read": "machine",
"expect": { "totalMb": 12122, "availableMb": 6886, "cpuCores": 12 }
},
{
"name": "cgroup v1 machine",
"why": "MemTotal 8388608 kB = 8192, MemAvailable 4096, swap 2048/2048; root limit is the v1 'no limit' number; no PSI file: none",
Expand Down Expand Up @@ -424,6 +497,29 @@
"read": "machine",
"expect": { "totalMb": 2048, "availableMb": 1074 }
},
{
"name": "cgroup v1 container, root memory.stat unreadable",
"failed": true,
"why": "the 2 GB container of 'cgroup v1 container with a limit', but memory.stat (how v1 is found) cannot be read: cgroup unreadable, available and cores unreadable (never the host's 4096 / 4)",
"host": "linux-v1",
"patch": {
"files": {
"/sys/fs/cgroup/memory/memory.limit_in_bytes": "2147483648\n",
"/sys/fs/cgroup/memory/memory.usage_in_bytes": "1073741824\n",
"/sys/fs/cgroup/memory/memory.stat": { "error": "unreadable" }
}
},
"read": "machine",
"expect": { "cgroup": "unreadable", "availableMb": null, "cpuCores": null }
},
{
"name": "piece when the cgroup version is unreadable",
"why": "no cgroup to read the piece from: demand unknown, the piece owes its full cost (never gone)",
"host": "linux-v2",
"patch": { "files": { "/sys/fs/cgroup/cgroup.controllers": { "error": "unreadable" } } },
"read": { "piece": "/work.slice/agent-a.scope" },
"expect": { "gone": false, "demandMb": null }
},
{
"name": "cgroup v2 piece",
"why": "anon 222130176 + shmem 4194304 + swap 104857600 = 331182080 B = 315.8 -> 315 (file pages are not demand); current 389136384 -> 371; peak 915546112 -> 873",
Expand Down Expand Up @@ -560,6 +656,24 @@
"read": { "box": "/other.slice" },
"expect": { "psi": "unreadable" }
},
{
"name": "box PSI turned off for that box",
"why": "cgroup.pressure 0 on the box (EOPNOTSUPP): unreadable, the safe side; only the machine PSI reads 'unsupported' as none",
"host": "linux-v2",
"patch": {
"files": { "/sys/fs/cgroup/work.slice/memory.pressure": { "error": "unsupported" } }
},
"read": { "box": "/work.slice" },
"expect": { "psi": "unreadable" }
},
{
"name": "box PSI when the cgroup version is unreadable",
"why": "cannot tell v1 (no box PSI) from v2: unreadable, never none",
"host": "linux-v2",
"patch": { "files": { "/sys/fs/cgroup/cgroup.controllers": { "error": "unreadable" } } },
"read": { "box": "/work.slice" },
"expect": { "psi": "unreadable" }
},
{
"name": "box path that climbs out",
"why": "a box path with '..' is never read: unreadable, never none",
Expand Down
18 changes: 17 additions & 1 deletion 18 packages/shared/src/capacityReadings.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import readingsJson from "./capacity/capacity-readings.json" with { type: "json"
import vectorsJson from "./capacity/capacity-vectors.json" with { type: "json" };
import {
type CapacityFileRead,
capacityFileError,
type CapacityHost,
capacityFactsOf,
type MachineReadings,
Expand All @@ -20,7 +21,7 @@ import {
} from "./capacityRule.ts";
import type { CapacityVectorsFile } from "./capacityVectors.ts";

type FixtureFile = string | { readonly error: "unreadable" };
type FixtureFile = string | { readonly error: "unreadable" | "unsupported" };
interface FixtureHost {
readonly platform: string;
readonly totalMemBytes: number;
Expand Down Expand Up @@ -254,6 +255,21 @@ describe("capacity readings: the real host", () => {
expect(await host.run("/nonexistent-capacity-readings-test/command", [])).toBeNull();
});

it("reads a file that exists but cannot be read as unreadable, never as missing", async () => {
// A directory gives EISDIR: like EACCES or EIO, a failed read, so never "no such limit".
expect(await nodeCapacityHost("linux").readFile("/")).toEqual({ error: "unreadable" });
});

it("sorts file errors: missing only when absent, unsupported only for EOPNOTSUPP", () => {
expect(capacityFileError("ENOENT")).toBe("missing");
expect(capacityFileError("ENOTDIR")).toBe("missing");
expect(capacityFileError("ENOTSUP")).toBe("unsupported");
expect(capacityFileError("EOPNOTSUPP")).toBe("unsupported");
for (const code of ["EACCES", "EPERM", "EIO", "EISDIR", "EMFILE", "ENODEV", undefined, 42]) {
expect(capacityFileError(code), String(code)).toBe("unreadable");
}
});

it("reads this machine when it is Linux", async () => {
const host = nodeCapacityHost("linux");
if (!("text" in (await host.readFile("/proc/meminfo")))) return;
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.