8000 The seat's memory protection follows its applications' claims (ADR 0066, decisions 7 and 8) by NateIsern · Pull Request #556 · OxyHQ/OxyOS · GitHub
[go: up one dir, main page]

Skip to content

The seat's memory protection follows its applications' claims (ADR 0066, decisions 7 and 8) - #556

Draft
NateIsern wants to merge 16 commits into
mainfrom
feat/seat-memory-claims
Draft

NateIsern wants to merge 16 commits into
mainfrom
feat/seat-memory-claims

Conversation

@NateIsern
Copy link
Copy Markdown
Member

Stacked on #532 (step 7) and #545 (step 4): until they land this diff carries them. The follow-up's own changes are in crates/oxyos-account/src/session.rs, tools/oxyos-accountd/src/{main.rs,seat.rs,seat/tests.rs} and the session's listener in tools/oxyos-session/src/main.rs. Its floors test needs step 6's drop-ins (#553). Draft until those land; then main merged in, ADR 0066 decisions 7 and 8 updated.

ADR 0066, decisions 7 and 8: the seat's applications' memory protection follows their claims.

Step 4 (#545) protects the focused application's working set with MemoryLow on its scope and gives the user manager's app.slice the sum of the claims. With cgroup2's memory_recursiveprot (the ThinkPad's mount) a protection reaches a group only as far as each ancestor's covers it, and those ancestors (user@UID.service, user-UID.slice, user.slice) are system units only root sets; step 6's static floors are sized for the session's services alone, so the focused app got about 90 MiB of a 300 MiB working set. A static raise would leak: protection a parent's children do not claim is shared out by usage, i.e. to the hog.

  • The session tells its claim over its existing registrar connection to oxyos-accountd ({"memoryClaim": {"bytes": N}}, RegistrarThread::memory_claim): fire-and-forget, the latest re-told on every reconnection. Wired to Weights by state and App Nap (ADR 0066, step 4) #545's Naps::with_claim_listener (rate-limited there: on a focus change or every 10 s, only when the 16 MiB-rounded sum changes). Applications may not claim (only the registrar). Not the display protocol: no version.
  • oxyos-accountd carries it up for the seat's holder alone (the thread of The person at the seat outranks other users (ADR 0066, step 7) #532): user@UID.service and user-UID.slice MemoryLow = floor + claim, user.slice = its floor + claim, capped at 50 % of the machine's memory (seat::lows); another user's claim is kept and given while that user holds the seat; a claim ends with its session's connection; leaving the seat or ending sets the floors back, only where they were raised (seat::settle: a unit nobody raised keeps what it has). The floors (128M / 128M / 256M) are constants pinned by a test to step 6's drop-ins.
  • The benchmark mirrors the same rule: oxyos-accountd --apply-memory-claim USER_SLICES SEAT BYTES (no root), which perf.py saturation runs each time the fixture's app.slice/memory.low changes.

Measured (the benchmark, ThinkPad, perf-device rules, three alternating rounds a side, p95 input to present, median of rounds [each round]): A = step 6 + #516 + #546 (floors stay); B = A + #545 + this.

S6 (memory hog past the machine's 3 GiB) A B
typing 234.3 [50.0, 234.3, 352.5] ms 7.9 [7.7, 8.2, 7.9] ms
scroll 310.8 [343.7, 310.8, 306.0] 28.4 [34.7, 28.4, 24.0]
pointer 9.3 (504 of 720 answered) 6.7 (688 of 720)
drag 62.6 [62.6, 61.7, 78.7] 5.1 [5.0, 5.1, 5.1]
the application's JS p95 (typing) 27.1 2.6

S0 identical within 0.3 ms on both sides; no OOM kill or failed run; the session's memory stall under 1.4 % on both. The claims carried up every round: 0, 32, 48, 64 MiB (64 MiB → user@.service and the user's slice 192 MiB, user.slice 320 MiB; 0 → the floors). B is #545's claim and this carry-up together: the claim without its ancestors raised is capped at the static floors.

Tests: oxyos-account (the claim handed over and ended with its connection, the registrar thread telling it without waiting, a registered application refused, the wire format); oxyos-accountd (the policy: carried over each floor and capped; raised and lowered only where raised; a user's claim its sessions' largest; the floors equal step 6's drop-ins; the benchmark's tree; and logind + systemd played on a private bus: a claim carried up, another user's kept but not given, fast user switching handing it over, a session's end restoring the floors, the cap).

🤖 Generated with Claude Code

NateIsern and others added 16 commits November 10, 2026 08:13
oxyos-accountd, the root service that already follows the machine's sessions, follows logind on a
thread of its own (src/seat.rs): seat0's ActiveSession, UserNew and UserRemoved. At each, and at its
start, it reads each user slice's weights from systemd and sets them with SetUnitProperties
(runtime): the user of seat0's active session (the person, or the login screen while it shows)
raised to CPUWeight=400 and IOWeight=400, a slice weighing 400 off the seat set back to its default
(unset), nobody else written. Fast user switching moves the raise at once; a lock changes nothing; a
slice left raised (the service down when the seat changed, or a slice made again with an old runtime
drop-in) is lowered at start and when its user appears. It waits on the bus alone.

`oxyos-accountd --apply-seat-weights USER_SLICES SEAT` gives a cgroup tree that is not systemd's the
same weights, without root: the saturation benchmark's S7 weighs its two users so, measuring this
policy rather than a copy of it.

A root process under oxyos-accountd.service's own sandbox (no CAP_SYS_ADMIN, ProtectControlGroups)
may call SetUnitProperties on the system bus: checked on seldon on a throwaway slice (cpu.weight 400,
io.weight default 400, then unset). The unit changes only in its header.

Measured with perf.py saturation, S7 (another user's CPU load on every CPU of the run), main against
this, interleaved, p95 of each of two runs: on the ThinkPad typing 34.5, 16.5 -> 18.0, 18.5 ms (S0
7.6), the pointer 23.0, 9.9 -> 9.4, 6.9 (S0 6.0), the drag unchanged (6.0, 8.9 -> 8.2, 9.2; S0 5.0).

Tests: the policy, the benchmark's tree, and logind and systemd played on a private bus driving the
thread. ADR 0066 decision 8 and step 7; ADR 0020 decision 3 amended.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… service in background.slice

ADR 0066, decision 3. Every application, the compositor's shell and its search service ran in the
logind session's scope at one weight, so an application's thirty busy threads got thirty times the
compositor's share of a processor. Now each process the launcher starts (a Bloom host or a program,
the file chooser too) starts as oxyos-scope, which asks the person's user manager for
app-oxyos-<id>-<pid>.scope in app.slice with its own pid (StartTransientUnit: Slice, PIDs,
CPUWeight=100 so app.slice gets the CPU controller and each application is a group of its own,
CollectMode=inactive-or-failed), waits for its job, then executes the application's program in the
same process: the launcher's child, its pid and the pidfd it registers stay the application's,
nothing the program does happens outside its scope, and the compositor's turn never waits on the
bus. The compositor and the shell stay in the session's scope, a sibling of the user manager: together
they weigh as much as every application together. The search service is placed in background.slice
(ADR 0051 decision 13 amended: its premise, no user manager, is false on the device). A scope that
cannot be had (no user bus, a refusal, no answer in 5 s) is said once and the program runs where it
was started; the login screen launches nothing.

crates/oxyos-scopes: the scopes' names (systemd-escaped ids), the user manager's side (placing, and
SetUnitProperties for this boot), the saturation benchmark's fixture (OXYOS_CGROUP_FIXTURE: the same
layout made with the control group filesystem's files, each level enabling its parent's
controllers), and Scopes, the handle decisions 4 and 5 weigh running applications with (off the
caller's thread, the latest asked winning, waited for while a scope is being placed); a played
systemd manager for tests. oxyos_apps::Scoping wraps a launch (the program found as execvp would,
a missing one failing the launch as before). The development compositor places what it starts only
under OXYOS_CGROUP_FIXTURE (the benchmark), so the gate runs as before; a scenario's `scopes` runs it
with a tree of its own and checks what each slice holds (application-scopes, app-crash). The deploy
installs /usr/libexec/oxyos/oxyos-scope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0