feat: fleet sizes 4g to 192g in the size table and root's gate (#892 S2)
Task 1 of the S2 plan. cgroup.Sizes gains ten literal fleet rows after xlarge (4g, 6g, 8g, 12g, 16g, 24g, 32g, 48g, 96g, 192g; 200% CPU per GiB, CPU and IO weight 200), and apppolicy's list follows. FleetSize, SharedSizeOf, ValidSharedParentLimit and FleetMemoryBudget (total - max(1 GiB, total/8)) are new, as is cgroup.FleetGate, root's view of whether a box runs fleet sizes: GenAllowed for one generation's limit, ParentAllowed for an overlap parent (ruling P4). Root's instance control reads CARLOS_FLEET from host.env into Server.Fleet with /proc/meminfo's MemTotal (ruling P2). Start, seed and command tiers, setTier (so gVisor slices), /parent and /size pass the gate; the zero gate takes small..xlarge and today's parents exactly as before. The agent's strict cgroup paths take the same gate from its CARLOS_FLEET. Claims take shared sizes only (ruling P6). Census: census-ruling-stateless-scale-2-fleet-sizes, five units (body) and one new (ReadMemTotal, reads a file); reviewer to be arranged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 files changed,
+728
−28
docs/superpowers/notes/census-proposal-stateless-scale-2-fleet-sizes.md+31 −0internal/activator/gomemlimit_test.go+3 −1internal/apppolicy/apppolicy.go+1 −1internal/apppolicy/sizenames_test.go+6 −1internal/cgroup/cgroup.go+11 −0internal/cgroup/cgroup_test.go+12 −2internal/cgroup/fleetgate.go+110 −0internal/cgroup/fleetgate_test.go+94 −0internal/cgroup/gen.go+11 −4internal/cgroup/gen_test.go+20 −2internal/cgroup/sizes.go+40 −0internal/cgroup/sizes_test.go+98 −1internal/cgroup/strict_gen_linux.go+2 −2internal/cgroup/strict_gen_linux_test.go+34 −3internal/cgroup/strict_linux.go+8 −4internal/cgroup/strict_linux_test.go+12 −0internal/host/claimlaunch_root.go+3 −1internal/host/claimroleassembly.go+3 −2internal/instancectl/claimunit.go+3 −1internal/instancectl/cmd.go+1 −1internal/instancectl/fleetsize.go+47 −0internal/instancectl/fleetsize_linux.go+9 −0internal/instancectl/fleetsize_other.go+9 −0internal/instancectl/fleetsize_test.go+117 −0internal/instancectl/gen.go+6 −0internal/instancectl/server.go+13 −2internal/instancectl/size.go+5 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-stateless-scale-2-fleet-sizes.tsv+18 −0
Intent
Attributed to this commit: 20.3 g CO₂e (2,466,419 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on stateless-scale-2-fleet-sizes, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/notes/census-proposal-stateless-scale-2-fleet-sizes.md b/docs/superpowers/notes/census-proposal-stateless-scale-2-fleet-sizes.md| new file mode 100644 |
| index 000000000..7808ad03e |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-stateless-scale-2-fleet-sizes.md |
| @@ -0,0 +1,31 @@ |
| +# Census approval: stateless-scale-2-fleet-sizes |
| + |
| +Ruling `census-ruling-stateless-scale-2-fleet-sizes`. The independent reviewer approves or rejects every change below, 1 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `internal/cgroup/cgroup.go` `setup` | body | unchanged (1) | the agent (carlos-edge.service, user carlos), not root: setup now also records a fleet-size gate on the agent's own Manager when CARLOS_FLEET is set in its environment (os.Getenv, beside the existing CARLOS_IMDS_FLAT_FENCE read). The gate's MemTotal closure reads /proc/meminfo through ReadMemTotal when a strict prepare is asked for a fleet size (#892 S2). It only lets the strict validators (PrepareStrict, PrepareGen, SetParentLimit) accept the new fleet rows within FleetMemoryBudget; without CARLOS_FLEET they take small..xlarge and today's parents exactly as before. Reads added: env CARLOS_FLEET; /proc/meminfo (kernel, fixed path) via the closure | |
| +| `internal/instancectl/gen.go` `Server.handleParent` | body | unchanged (1) | root: after the unchanged ValidParentLimit check, a parent outside today's shared set (one or two of small..xlarge) must also pass Server.Fleet.ParentAllowed: CARLOS_FLEET in root's host.env, not a gVisor box, readable MemTotal, and the whole overlap within max(0, MemTotal - max(1 GiB, MemTotal/8)), else 400 before any write. Today's parent set is accepted unchanged on every box. Same one site (r.URL.Query of the agent's request); no read added in this body (MemTotal is read by hostMemTotal through the gate) | |
| +| `internal/instancectl/server.go` `runWithClaim` | body | unchanged (6) | root: the production Server literal gains Fleet: productionFleetGate(os.Getenv), which is Fleet = CARLOS_FLEET set in carlos-instance-control.service's environment (EnvironmentFile /etc/carlos/host.env, root-owned, the same way EdgeFenceOff reads CARLOS_EDGE_FENCE) and MemTotal = hostMemTotal (/proc/meminfo through cgroup.ReadMemTotal, read only when a fleet size is asked for). Reads added: env CARLOS_FLEET; /proc/meminfo (kernel, fixed path, via the gate) | |
| +| `internal/instancectl/server.go` `type Server` | body | unchanged (1) | root: new field Fleet cgroup.FleetGate (#892 S2), root's fleet-size gate; field declaration only; no read added | |
| +| `internal/instancectl/size.go` `Server.handleSize` | body | unchanged (1) | root: after the unchanged SizeByName check, the named row must pass Server.Fleet.GenAllowed (a shared size always; a fleet size only on a CARLOS_FLEET box, not gVisor, within the MemTotal budget), else 400 before any systemctl call. Same one site; no read added in this body | |
| + |
| +Envelopes re-pinned: `internal/apppolicy`, `internal/cgroup`, `internal/host`, `internal/instancectl`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Recorded dispositions, which each change must still satisfy: |
| + |
| +- `internal/cgroup/cgroup.go` `setup`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-hunt-account-root-hardening;basis=setup records whether the flat IMDS fence is armed (CARLOS_IMDS_FLAT_FENCE); when armed, a flat start whose shim or placement is unavailable is refused instead of falling back to start-and-move; no read is added |
| +- `internal/instancectl/gen.go` `Server.handleParent`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J2,J4;basis=root-input;rev3=census-ruling-instance-egress-sizes-328-329;basis=#329 plan 3 Task 5: holds the host's slice lock (lockSliceWrites) around its one set-property, so /parent and /size never interleave on one slice. Its one site is still r.URL.Query() of the agent's request (counted as file:Query). The checks in this body are unchanged, though cgroup.ValidParentLimit, which it calls, now accepts one size or the sum of any two from the four-row table (up to 4 GiB, was 2 GiB); no read added.;rev3=census-ruling-agent-start-demo-1;basis=Reads fixed DemoBox and clamps the existing parent memory writer to small.;rev3=census-ruling-gvisor-demos;basis=Validate logical parent input as before, require the demo route in gVisor mode and apply Physical once to the small demo parent. Existing request query read unchanged; shares stay logical. |
| +- `internal/instancectl/server.go` `runWithClaim`: authority, task C,D,G. Basis: Claim instance controller adds held-release RPC dispatch within existing launch/participation execution boundary.;rev3=census-ruling-rootfs-apps-2;basis=takes a RegistryView (HostApp and HostRuntime) for the bare hostApp, and the production Server literal gains HostRuntime, ProbeImage: BuildProbeImage, ProbeImageFile: ProbeImagePath, RootfsProbeOut under /run/carlos-control and DenyEvery: 10s; this body reads nothing new itself; the readers it wires (instanceRegistryHostRuntime, BuildProbeImage, the rootfs probe's output) are decision rows;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Task 4 and #329 plan 3 Task 5: takes the egress asserter as a parameter, sets it on the production Server literal (Egress) and starts its 30 s Loop beside probeLoop and diskLoop; the literal also names the fixture check ProbeFixturesOK (renamed in plan 2 Task 14). It sets no control drop-in directory: plan 3's ControlDropInDir default (/run/systemd/system.control) was deleted with removeGenControlDropIn in ef38e13b (the P1 EROFS fix), so instance control names systemd's control directory only to read it (TrustedDropinReader). The same four sites (the two exec.CommandContext closures, statfsBytes, the data literal), offsets moved; no read added.;rev3=census-ruling-agent-start-demo-1;basis=Wires root-owned demo config and existing fixed paths into the service.;rev3=census-ruling-region-ha-p3b;basis=Resume root-owned hairpin state before probes/control service work; verify current systemd agent identity and kernel fence/addresses, restore pidfd watch or revoke stale state. Same direct exec/statfs/data sites; indirect inputs are protected root snapshot/state and kernel evidence, never receipt data.;rev3=census-ruling-agent-start-demo-3;basis=Construct the demo snapshot supervisor for configured demo boxes; startup cleanup gates builder readiness. Census read-site delta: unchanged (4).;rev3=census-ruling-gvisor-demos;basis=Retain sandbox modes and error; bind host-provided baseline and runtime callbacks without importing host templates. Existing reads unchanged. Task 6: Capture HostClaims once from ControlConfig/hostwrite.Enabled and set the fixed root-owned bundle discovery directory. Existing command and configuration reads unchanged. Task 7: enable gVisor worker construction through fixed unitFamily(roleBuild); readiness proof rechecks sandbox admission and current Ready without reaching the constructor fatal path for transient refusals. Existing command/config reads unchanged. Final R1 P2: wire the fixed /var/lib/carlos/oci-rootfs parent for native readiness evidence; no request-supplied path. Carry the root-only host.env validation callback into Ready; no agent read or caller-selected path.;rev3=census-ruling-same-box-edge-fence;basis=Root. Sets NFT: edgefence.Exec (runs /usr/sbin/nft from PATH with fixed arguments and root-derived stdin, see the envelope) and EdgeFenceOff from os.Getenv; wraps s.Systemctl with guardStarts and calls bindEgressFence; calls denyLocalAddrs once before Serve so a leftover runtime exemption is checked or replaced by the whole deny before any request is served. No new file read; the exec is nft's.;rev3=census-ruling-bounded-systemctl;basis=the production Systemctl closure runs through internal/systemd.Command (same args, combined output, caller ctx; mutations no deadline of their own, queries also QueryTimeout); the new Journal closure runs journalctl through internal/systemd.Command(Journalctl) for the gVisor probe diagnostic only, with the arguments that closure used to pass to Run; no new read, path or input |
| +- `internal/instancectl/server.go` `type Server`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=Re-digested at the pre-land merge: the body includes main's own change under census ruling 292, with no further change from this branch. Census ruling 292 reclassified this declaration accepted-legacy (J2,J4) for root's per-host ordering of legacy run starts against stops; this ruling kept the row as main classed it. Its own addition is the cmd start's poll and wait bounds and its per-host lock map: field declarations only;rev3=census-ruling-rootfs-apps-2;basis=new fields: HostRuntime, ProbeImage, ProbeImageFile, RootfsProbeOut, DenyEvery, the deny's lastDeny and denyMu, the rootfs probe's report and lock, the jit reload counters and imageDigests; genStarting counts binary generation starts per unit; rootfsLocksMu and rootfsLocks, one lock entry per rootfs unit name being started or removed right now, held by a start from its layout through systemctl start and its own cleanup and by a removal from its proof through the raw removal, a removal refusing while it is taken, a waiting start giving up when its request ends, an entry dropped with its last holder or waiter (fixes E6, L2, L3); rootfsProvenHook, a test hook run between the proof and the raw removal; field declarations only; no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 and #329 plan 3 Task 5: the declaration gains sliceLocks (one mutex per host slice, taken by /size and /parent) and Egress (the asserter every start path calls), and its comment names the egress allow (plan 3's ControlDropInDir field was deleted in ef38e13b, the P1 EROFS fix); the same one site, the Statfs field, offset moved; no read added.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 6: comments only: the one-shot pacing fields cover /cmd and /tty, and cmdLocks is now keyed by (role, host) (oneShotKey, PF-7) so a session's start never waits behind a command's; field declarations unchanged; the same one site, no read added;rev3=census-ruling-agent-start-demo-1;basis=Adds fixed demo configuration, registry views, derived runtime root, synchronization and purge guard.;rev3=census-ruling-region-ha-p3b;basis=Add hairpinActive boolean alongside lastDeny under existing deny synchronization. Field declaration only; existing Statfs selector unchanged, no new read or externally supplied authority.;rev3=census-ruling-region-ha-p3b2-rolls;basis=adds one field holding the current hairpin exit watcher, guarded by the root hairpin flock; no new read;rev3=census-ruling-agent-start-demo-3;basis=Retain the snapshot supervisor in instance-control state; no new request-selected path. Census read-site delta: unchanged (1).;rev3=census-ruling-gvisor-demos;basis=Retain Task 1 mode/error/readiness fields, baseline/runtime callbacks, Task 4 per-host validated staged descriptors and root-selected probe nonce. Fix round 1 adds a private writer-operation seam assigned only in package tests, after the unchanged GVisorID admission check; production defaults still call the same checked constructor, WriteRootfs, WriteBundle and verifier. No new direct read or request-controlled callback. Task 5: private injected removal seam for unprivileged tests; production default removes only root-derived bundle and skeleton after both-family proof inside existing start fence. No new request field or agent-selected unit. Task 6: Retain serialized probe nonce, runtime-set identity verifier/token, fixed claims flag, bundle discovery root, and private unprivileged identity seam. No request-controlled callback or path; existing declaration read-site classification unchanged. Task 6 fix round 1: private gvisorProbeTestOps is set only in package tests; production defaults retain all fixed paths and the checked root output opener. No externally supplied callback or new direct read. Final R1 P2: retain fixed skeleton parent and concurrent per-instance cleanup refusals; no direct read or external configuration field. Carry the root-only host.env validation callback into Ready; no agent read or caller-selected path.;rev3=census-ruling-same-box-edge-fence;basis=Field declarations only: NFT (the nft runner; nil never loads the fence), EdgeFenceOff (host.env CARLOS_EDGE_FENCE=off), and under the existing denyMu/mu: fenceAddrs, fenceReason, fenceRetry, denyApplied. No read added.;rev3=census-ruling-bounded-systemctl;basis=new field Journal, the journalctl seam for the gVisor probe's diagnostic; field declaration only; no read added |
| +- `internal/instancectl/size.go` `Server.handleSize`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-instance-egress-sizes-328-329;identity=instance control (/opt/carlos/carlos instance-control, carlos-instance-control.service, root);basis=root-input (J2,J4, as Server.handleParent): new (#329 plan 3 Task 5): POST /size from the agent (the peer check admits only the edge unit's main process; claimAwareLegacy answers 503 with host claims on). Its one site is r.URL.Query() of that request (counted as file:Query): host must pass ValidHostShape, memory_max and gen are refused, size must name a row of cgroup.Sizes. Under the slice lock it runs systemctl set-property --runtime on SliceName(host) with that row's CPUWeight, CPUQuota and IOWeight, then writeSizeReadBack runs systemctl show of the slice and answers it. Root sets the slice's CPU and IO shares from the agent's choice among four platform rows; nothing from the request reaches systemctl as a string.;rev3=census-ruling-agent-start-demo-1;basis=Reads fixed DemoBox and clamps the existing live CPU/IO writer to small. |
| + |
| +New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff: |
| + |
| +- new `internal/cgroup/fleetgate.go:ReadMemTotal`: reads +file:ReadFile; written legacy, accepted-legacy, frozen |
| + |
| +Seal: `47ebd73418bcbe1bdf9cf34a2b94e3393a1279aea58f9ee0aca3f0cfe42b9132` → `dcd00ad63015e1ca6be4cd6f653c92a92891fea266e88e831e237adb64a1c54c`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-stateless-scale-2-fleet-sizes.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/activator/gomemlimit_test.go b/internal/activator/gomemlimit_test.go| index a42f10bbc..fbfcc839a 100644 |
| --- a/internal/activator/gomemlimit_test.go |
| +++ b/internal/activator/gomemlimit_test.go |
| @@ -24,7 +24,9 @@ import ( |
| // the agent does not know to be capped, and never writes into the maps it |
| // is handed. |
| func TestWithGoMemLimit(t *testing.T) { |
| - want := map[string]string{"small": "214748360", "standard": "429496728", "large": "858993456", "xlarge": "1717986912"} |
| + want := map[string]string{"small": "214748360", "standard": "429496728", "large": "858993456", "xlarge": "1717986912", |
| + // #892 S2's fleet sizes. |
| + "4g": "3435973832", "6g": "5153960752", "8g": "6871947672", "12g": "10307921504", "16g": "13743895344", "24g": "20615843016", "32g": "27487790688", "48g": "41231686040", "96g": "82463372080", "192g": "164926744160"} |
| for _, s := range cgroup.Sizes { |
| child := map[string]string{"CARLOS_HOST": "h.example.com"} |
| got := withGoMemLimit(child, map[string]string{"APP": "1"}, s.Limit) |
diff --git a/internal/apppolicy/apppolicy.go b/internal/apppolicy/apppolicy.go| index 97df1976a..76b793564 100644 |
| --- a/internal/apppolicy/apppolicy.go |
| +++ b/internal/apppolicy/apppolicy.go |
| @@ -33,7 +33,7 @@ const Prefix = release.AppPolicyPrefix |
| // import internal/cgroup, whose tests reach apppolicy through hostbox and |
| // provision (an import cycle in test). TestSizeNamesAreCgroupSizes holds the |
| // two equal. |
| -var sizeNames = []string{"small", "standard", "large", "xlarge"} |
| +var sizeNames = []string{"small", "standard", "large", "xlarge", "4g", "6g", "8g", "12g", "16g", "24g", "32g", "48g", "96g", "192g"} |
| // validSize is whether name is one of sizeNames, matched exactly. |
| func validSize(name string) bool { |
diff --git a/internal/apppolicy/sizenames_test.go b/internal/apppolicy/sizenames_test.go| index 71dae2f23..61663dff0 100644 |
| --- a/internal/apppolicy/sizenames_test.go |
| +++ b/internal/apppolicy/sizenames_test.go |
| @@ -16,12 +16,17 @@ func TestSizeNamesAreCgroupSizes(t *testing.T) { |
| if got, want := sizeNames, cgroup.SizeNames(); !slices.Equal(got, want) { |
| t.Fatalf("apppolicy's size names %q, cgroup.Sizes' %q", got, want) |
| } |
| + // #892 S2: the ten fleet sizes follow xlarge. A policy may name them; |
| + // whether a box runs one is root's and the console's to judge. |
| + if want := []string{"small", "standard", "large", "xlarge", "4g", "6g", "8g", "12g", "16g", "24g", "32g", "48g", "96g", "192g"}; !slices.Equal(sizeNames, want) { |
| + t.Errorf("apppolicy's size names %q, want %q", sizeNames, want) |
| + } |
| for _, n := range cgroup.SizeNames() { |
| if !validSize(n) { |
| t.Errorf("validSize(%q) = false", n) |
| } |
| } |
| - for _, n := range []string{"", "Small", "medium", "standard "} { |
| + for _, n := range []string{"", "Small", "medium", "standard ", "4G", "5g", "256g"} { |
| if validSize(n) { |
| t.Errorf("validSize(%q) = true", n) |
| } |
diff --git a/internal/cgroup/cgroup.go b/internal/cgroup/cgroup.go| index 9832a4ccf..3ed0985dc 100644 |
| --- a/internal/cgroup/cgroup.go |
| +++ b/internal/cgroup/cgroup.go |
| @@ -229,6 +229,11 @@ type Manager struct { |
| // and in tests, where the window exposes no exempt leaf and the fallback |
| // keeps its Ruling 2 behaviour. |
| fencedSpawn bool |
| + // fleet is the strict validators' fleet-size gate (#892 S2): set in the |
| + // production setup() when CARLOS_FLEET names this box's fleet, with the |
| + // box's MemTotal. The zero gate (every other box, a test, SetupAt) |
| + // takes the shared sizes alone. |
| + fleet FleetGate |
| // leftover is the hosts whose per-host dir sweepStale could not remove |
| // at setup: something a previous agent started may still be alive in |
| // it. unswept says setup did not sweep at all (a retaining setup) or |
| @@ -313,6 +318,12 @@ func setup(logf func(string, ...any), retain bool) *Manager { |
| m.fencedSpawn = true |
| logf("agent: flat-tier IMDS fence active — a flat start the shim cannot place fails closed (H1-M4)") |
| } |
| + // A fleet box's agent may run fleet sizes in its strict groups, within |
| + // the box's budget (#892 S2): the same signal and the same MemTotal |
| + // root's instance control judges by. |
| + if os.Getenv("CARLOS_FLEET") != "" { |
| + m.fleet = FleetGate{Fleet: true, MemTotal: func() (int64, error) { return ReadMemTotal("/proc/meminfo") }} |
| + } |
| logf("agent: exec-child accounting armed (delegated subtree %s)", m.Root()) |
| return m |
| } |
diff --git a/internal/cgroup/cgroup_test.go b/internal/cgroup/cgroup_test.go| index a18e14da5..716f5539d 100644 |
| --- a/internal/cgroup/cgroup_test.go |
| +++ b/internal/cgroup/cgroup_test.go |
| @@ -474,8 +474,18 @@ func TestSizeTableIsTheSpecsBytes(t *testing.T) { |
| "standard": {536870912, 483183819, 429496728, Shares{CPUWeight: 100, CPUQuotaPercent: 100, IOWeight: 100}}, |
| "large": {1073741824, 966367638, 858993456, Shares{CPUWeight: 100, CPUQuotaPercent: 200, IOWeight: 100}}, |
| "xlarge": {2147483648, 1932735276, 1717986912, Shares{CPUWeight: 200, CPUQuotaPercent: 400, IOWeight: 200}}, |
| - } |
| - order := []string{"small", "standard", "large", "xlarge"} |
| + "4g": {4294967296, 3865470561, 3435973832, Shares{CPUWeight: 200, CPUQuotaPercent: 800, IOWeight: 200}}, |
| + "6g": {6442450944, 5798205846, 5153960752, Shares{CPUWeight: 200, CPUQuotaPercent: 1200, IOWeight: 200}}, |
| + "8g": {8589934592, 7730941131, 6871947672, Shares{CPUWeight: 200, CPUQuotaPercent: 1600, IOWeight: 200}}, |
| + "12g": {12884901888, 11596411692, 10307921504, Shares{CPUWeight: 200, CPUQuotaPercent: 2400, IOWeight: 200}}, |
| + "16g": {17179869184, 15461882262, 13743895344, Shares{CPUWeight: 200, CPUQuotaPercent: 3200, IOWeight: 200}}, |
| + "24g": {25769803776, 23192823393, 20615843016, Shares{CPUWeight: 200, CPUQuotaPercent: 4800, IOWeight: 200}}, |
| + "32g": {34359738368, 30923764524, 27487790688, Shares{CPUWeight: 200, CPUQuotaPercent: 6400, IOWeight: 200}}, |
| + "48g": {51539607552, 46385646795, 41231686040, Shares{CPUWeight: 200, CPUQuotaPercent: 9600, IOWeight: 200}}, |
| + "96g": {103079215104, 92771293590, 82463372080, Shares{CPUWeight: 200, CPUQuotaPercent: 19200, IOWeight: 200}}, |
| + "192g": {206158430208, 185542587180, 164926744160, Shares{CPUWeight: 200, CPUQuotaPercent: 38400, IOWeight: 200}}, |
| + } |
| + order := []string{"small", "standard", "large", "xlarge", "4g", "6g", "8g", "12g", "16g", "24g", "32g", "48g", "96g", "192g"} |
| if len(Sizes) != len(order) { |
| t.Fatalf("Sizes has %d rows, want %d", len(Sizes), len(order)) |
| } |
diff --git a/internal/cgroup/fleetgate.go b/internal/cgroup/fleetgate.go| new file mode 100644 |
| index 000000000..373d036c7 |
| --- /dev/null |
| +++ b/internal/cgroup/fleetgate.go |
| @@ -0,0 +1,110 @@ |
| +package cgroup |
| + |
| +import ( |
| + "bufio" |
| + "bytes" |
| + "errors" |
| + "fmt" |
| + "os" |
| + "strconv" |
| +) |
| + |
| +// ErrFleetSize is FleetGate's refusal: a limit this box does not run. |
| +var ErrFleetSize = errors.New("cgroup: not a size this box runs") |
| + |
| +// FleetMemoryBudget is how much of a box's memory its fleet-size copies |
| +// may take (#892 S2): total less max(1 GiB, total/8), never below zero. |
| +func FleetMemoryBudget(totalBytes int64) int64 { |
| + reserve := totalBytes / 8 |
| + if reserve < 1<<30 { |
| + reserve = 1 << 30 |
| + } |
| + if b := totalBytes - reserve; b > 0 { |
| + return b |
| + } |
| + return 0 |
| +} |
| + |
| +// FleetGate is root's view of whether this box may run fleet sizes. |
| +type FleetGate struct { |
| + Fleet bool // CARLOS_FLEET set in root's host.env |
| + MemTotal func() (int64, error) // /proc/meminfo MemTotal in bytes |
| +} |
| + |
| +// GenAllowed is whether one generation (or a unit's slice) may carry l: a |
| +// shared size on every box; a fleet size only on a fleet box, in a systemd |
| +// (not gVisor) unit, within the box's FleetMemoryBudget. Anything else, |
| +// and every fleet size under the zero gate, is ErrFleetSize. |
| +func (g FleetGate) GenAllowed(l Limit, gvisor bool) error { |
| + if _, ok := SharedSizeOf(l); ok { |
| + return nil |
| + } |
| + if _, ok := SizeOf(l); !ok { |
| + return fmt.Errorf("%w: memory %d is not a platform size", ErrFleetSize, l.MemoryMax) |
| + } |
| + return g.fits(l, gvisor) |
| +} |
| + |
| +// ParentAllowed is whether a generation parent may carry l: today's set |
| +// (one or two of small..xlarge) on every box; a limit only a fleet size |
| +// makes valid under GenAllowed's fleet, sandbox and budget conditions, the |
| +// overlap's whole sum within the budget (ruling P4). |
| +func (g FleetGate) ParentAllowed(l Limit, gvisor bool) error { |
| + if ValidSharedParentLimit(l) { |
| + return nil |
| + } |
| + if !ValidParentLimit(l) { |
| + return fmt.Errorf("%w: memory %d is not one size or two", ErrFleetSize, l.MemoryMax) |
| + } |
| + return g.fits(l, gvisor) |
| +} |
| + |
| +func (g FleetGate) fits(l Limit, gvisor bool) error { |
| + if !g.Fleet { |
| + return fmt.Errorf("%w: memory %d is a fleet size and this box is in no fleet", ErrFleetSize, l.MemoryMax) |
| + } |
| + if gvisor { |
| + return fmt.Errorf("%w: memory %d is a fleet size and a gVisor unit takes none", ErrFleetSize, l.MemoryMax) |
| + } |
| + if g.MemTotal == nil { |
| + return fmt.Errorf("%w: memory %d is a fleet size and the box's memory is unknown", ErrFleetSize, l.MemoryMax) |
| + } |
| + total, err := g.MemTotal() |
| + if err != nil { |
| + return fmt.Errorf("%w: memory %d is a fleet size and the box's memory is unknown: %v", ErrFleetSize, l.MemoryMax, err) |
| + } |
| + if budget := FleetMemoryBudget(total); l.MemoryMax > budget { |
| + return fmt.Errorf("%w: memory %d is over this box's fleet budget %d", ErrFleetSize, l.MemoryMax, budget) |
| + } |
| + return nil |
| +} |
| + |
| +// ParseMemTotal is /proc/meminfo's MemTotal in bytes. A missing, malformed |
| +// or non-positive line, or a unit other than kB, is an error. |
| +func ParseMemTotal(meminfo []byte) (int64, error) { |
| + sc := bufio.NewScanner(bytes.NewReader(meminfo)) |
| + for sc.Scan() { |
| + f := bytes.Fields(sc.Bytes()) |
| + if len(f) == 0 || string(f[0]) != "MemTotal:" { |
| + continue |
| + } |
| + if len(f) != 3 || string(f[2]) != "kB" { |
| + return 0, fmt.Errorf("meminfo: MemTotal line %q", sc.Text()) |
| + } |
| + kb, err := strconv.ParseInt(string(f[1]), 10, 64) |
| + if err != nil || kb <= 0 || kb > (1<<53)/1024 { |
| + return 0, fmt.Errorf("meminfo: MemTotal %q", f[1]) |
| + } |
| + return kb * 1024, nil |
| + } |
| + return 0, errors.New("meminfo: no MemTotal") |
| +} |
| + |
| +// ReadMemTotal is ParseMemTotal of the file at path (/proc/meminfo). |
| +func ReadMemTotal(path string) (int64, error) { |
| + b, err := os.ReadFile(path) |
| + if err != nil { |
| + return 0, err |
| + } |
| + return ParseMemTotal(b) |
| +} |
diff --git a/internal/cgroup/fleetgate_test.go b/internal/cgroup/fleetgate_test.go| new file mode 100644 |
| index 000000000..8f9ef25e6 |
| --- /dev/null |
| +++ b/internal/cgroup/fleetgate_test.go |
| @@ -0,0 +1,94 @@ |
| +package cgroup |
| + |
| +import ( |
| + "errors" |
| + "testing" |
| +) |
| + |
| +func memTotal(n int64) func() (int64, error) { |
| + return func() (int64, error) { return n, nil } |
| +} |
| + |
| +// TestFleetGate pins root's view of fleet sizes (#892 S2, ruling P2/P4): |
| +// small..xlarge and today's parent set pass on every box; a fleet row, or |
| +// a parent only a fleet row makes valid, needs a fleet box, a systemd |
| +// unit, a readable MemTotal and the box's budget. |
| +func TestFleetGate(t *testing.T) { |
| + const gib = int64(1) << 30 |
| + size := func(name string) Limit { |
| + s, ok := SizeByName(name) |
| + if !ok { |
| + t.Fatalf("no size %q", name) |
| + } |
| + return s.Limit |
| + } |
| + xlarge := size("xlarge") |
| + fleet := func(total int64) FleetGate { return FleetGate{Fleet: true, MemTotal: memTotal(total)} } |
| + broken := FleetGate{Fleet: true, MemTotal: func() (int64, error) { return 0, errors.New("no meminfo") }} |
| + type check struct { |
| + name string |
| + gate FleetGate |
| + parent bool |
| + l Limit |
| + gvisor bool |
| + ok bool |
| + } |
| + for _, c := range []check{ |
| + // The zero gate: every shared box today. |
| + {"zero gen 4g", FleetGate{}, false, size("4g"), false, false}, |
| + {"zero gen xlarge", FleetGate{}, false, xlarge, false, true}, |
| + {"zero gen small gvisor", FleetGate{}, false, size("small"), true, true}, |
| + {"zero parent xlarge+xlarge", FleetGate{}, true, Limit{MemoryMax: 4 * gib}, false, true}, |
| + {"zero parent 4g+xlarge", FleetGate{}, true, Limit{MemoryMax: 6 * gib}, false, false}, |
| + {"zero parent 4g alone", FleetGate{}, true, Limit{MemoryMax: 4 * gib}, true, true}, // = xlarge+xlarge |
| + {"zero gen 3 GiB", FleetGate{}, false, Limit{MemoryMax: 3 * gib}, false, false}, |
| + // A fleet box with exactly enough. |
| + {"5 GiB gen 4g", fleet(5 * gib), false, size("4g"), false, true}, |
| + {"5 GiB-1 gen 4g", fleet(5*gib - 1), false, size("4g"), false, false}, |
| + // An 8 GiB fleet box: budget 7 GiB. |
| + {"8 GiB gen 6g", fleet(8 * gib), false, size("6g"), false, true}, |
| + {"8 GiB gen 8g", fleet(8 * gib), false, size("8g"), false, false}, |
| + {"8 GiB parent 4g+4g", fleet(8 * gib), true, Limit{MemoryMax: 8 * gib}, false, false}, |
| + {"8 GiB parent 4g+xlarge", fleet(8 * gib), true, Limit{MemoryMax: 6 * gib}, false, true}, |
| + {"8 GiB parent 4g+xlarge gvisor", fleet(8 * gib), true, Limit{MemoryMax: 6 * gib}, true, false}, |
| + {"8 GiB gen 4g gvisor", fleet(8 * gib), false, size("4g"), true, false}, |
| + {"8 GiB gen xlarge gvisor", fleet(8 * gib), false, xlarge, true, true}, |
| + {"8 GiB gen arbitrary", fleet(8 * gib), false, Limit{MemoryMax: 3*gib + 12345}, false, false}, |
| + {"8 GiB parent arbitrary", fleet(8 * gib), true, Limit{MemoryMax: 5*gib + 1}, false, false}, |
| + {"8 GiB gen 0", fleet(8 * gib), false, Limit{}, false, false}, |
| + // A fleet box whose MemTotal cannot be read. |
| + {"broken gen 4g", broken, false, size("4g"), false, false}, |
| + {"broken parent 6 GiB", broken, true, Limit{MemoryMax: 6 * gib}, false, false}, |
| + {"broken gen xlarge", broken, false, xlarge, false, true}, |
| + {"broken parent 4 GiB", broken, true, Limit{MemoryMax: 4 * gib}, false, true}, |
| + {"nil MemTotal gen 4g", FleetGate{Fleet: true}, false, size("4g"), false, false}, |
| + // MemTotal set but no fleet: refused whatever the memory. |
| + {"not fleet 256 GiB gen 4g", FleetGate{MemTotal: memTotal(256 * gib)}, false, size("4g"), false, false}, |
| + {"256 GiB gen 192g", fleet(256 * gib), false, size("192g"), false, true}, |
| + } { |
| + var err error |
| + if c.parent { |
| + err = c.gate.ParentAllowed(c.l, c.gvisor) |
| + } else { |
| + err = c.gate.GenAllowed(c.l, c.gvisor) |
| + } |
| + if (err == nil) != c.ok { |
| + t.Errorf("%s: err = %v, want ok=%v", c.name, err, c.ok) |
| + } |
| + if err != nil && !errors.Is(err, ErrFleetSize) { |
| + t.Errorf("%s: err %v is not ErrFleetSize", c.name, err) |
| + } |
| + } |
| +} |
| + |
| +func TestParseMemTotal(t *testing.T) { |
| + got, err := ParseMemTotal([]byte("MemTotal: 32600364 kB\nMemFree: 1000 kB\n")) |
| + if err != nil || got != 32600364*1024 { |
| + t.Errorf("ParseMemTotal = %d, %v; want %d", got, err, int64(32600364)*1024) |
| + } |
| + for _, bad := range []string{"", "MemFree: 1 kB\n", "MemTotal: x kB\n", "MemTotal: 12 MB\n", "MemTotal: -1 kB\n", "MemTotal: 0 kB\n"} { |
| + if n, err := ParseMemTotal([]byte(bad)); err == nil { |
| + t.Errorf("ParseMemTotal(%q) = %d, nil; want an error", bad, n) |
| + } |
| + } |
| +} |
diff --git a/internal/cgroup/gen.go b/internal/cgroup/gen.go| index 1f2a764ba..9616c3c4f 100644 |
| --- a/internal/cgroup/gen.go |
| +++ b/internal/cgroup/gen.go |
| @@ -61,13 +61,20 @@ func OverlapLimit(incumbent, successor Limit) Limit { |
| // ValidParentLimit reports whether l is a limit a generation parent may |
| // carry: one size, or the sum of any two (an overlap across a size |
| // change). Strict containment and the root control service accept nothing |
| -// else. |
| -func ValidParentLimit(l Limit) bool { |
| - for _, a := range Sizes { |
| +// else, and a limit only a fleet size makes valid only through FleetGate. |
| +func ValidParentLimit(l Limit) bool { return validParentIn(Sizes, l) } |
| + |
| +// ValidSharedParentLimit is ValidParentLimit over the shared sizes alone |
| +// (small..xlarge): one of them, or the sum of any two. It is the parent |
| +// set every box takes, unchanged by the fleet sizes. |
| +func ValidSharedParentLimit(l Limit) bool { return validParentIn(Sizes[:sharedSizes], l) } |
| + |
| +func validParentIn(sizes []Size, l Limit) bool { |
| + for _, a := range sizes { |
| if l == a.Limit { |
| return true |
| } |
| - for _, b := range Sizes { |
| + for _, b := range sizes { |
| if l.MemoryMax == a.Limit.MemoryMax+b.Limit.MemoryMax { |
| return true |
| } |
diff --git a/internal/cgroup/gen_test.go b/internal/cgroup/gen_test.go| index c9ac918bc..76acd7061 100644 |
| --- a/internal/cgroup/gen_test.go |
| +++ b/internal/cgroup/gen_test.go |
| @@ -92,12 +92,18 @@ func TestOverlapAndValidParentLimits(t *testing.T) { |
| } |
| for max, want := range map[int64]bool{ |
| 512 << 20: true, 1 << 30: true, 1536 << 20: true, 2 << 30: true, |
| - 0: false, 64 << 20: false, 6 << 30: false, |
| + 0: false, 64 << 20: false, 4864 << 20: false, |
| } { |
| if got := ValidParentLimit(Limit{MemoryMax: max}); got != want { |
| t.Errorf("ValidParentLimit(%d) = %v, want %v", max, got, want) |
| } |
| } |
| + // 6 GiB is 4g+xlarge: a parent only a fleet size makes valid (#892 |
| + // S2), so not one of the shared set. |
| + if !ValidParentLimit(Limit{MemoryMax: 6 << 30}) || ValidSharedParentLimit(Limit{MemoryMax: 6 << 30}) { |
| + t.Errorf("6 GiB: ValidParentLimit %v, ValidSharedParentLimit %v; want true, false", |
| + ValidParentLimit(Limit{MemoryMax: 6 << 30}), ValidSharedParentLimit(Limit{MemoryMax: 6 << 30})) |
| + } |
| } |
| // TestValidParentLimitIsOneSizeOrTwo: a generation parent carries one size |
| @@ -108,11 +114,23 @@ func TestValidParentLimitIsOneSizeOrTwo(t *testing.T) { |
| t.Errorf("ValidParentLimit(%d MiB) = false, want true", mib) |
| } |
| } |
| - for _, max := range []int64{0, 7, 384 << 20, 3584 << 20, 6144 << 20} { |
| + for _, max := range []int64{0, 7, 384 << 20, 3584 << 20, 4864 << 20} { |
| if ValidParentLimit(Limit{MemoryMax: max}) { |
| t.Errorf("ValidParentLimit(%d) = true, want false", max) |
| } |
| } |
| + // The shared set is exactly the list above (#892 S2): 6 GiB and up |
| + // need a fleet size. |
| + for _, mib := range []int64{256, 512, 768, 1024, 1280, 1536, 2048, 2304, 2560, 3072, 4096} { |
| + if !ValidSharedParentLimit(Limit{MemoryMax: mib << 20}) { |
| + t.Errorf("ValidSharedParentLimit(%d MiB) = false, want true", mib) |
| + } |
| + } |
| + for _, max := range []int64{0, 7, 384 << 20, 3584 << 20, 5120 << 20, 6144 << 20, 8192 << 20} { |
| + if ValidSharedParentLimit(Limit{MemoryMax: max}) { |
| + t.Errorf("ValidSharedParentLimit(%d) = true, want false", max) |
| + } |
| + } |
| } |
| func TestStartChildPutsTheTierOnTheGenerationAndTheParent(t *testing.T) { |
diff --git a/internal/cgroup/sizes.go b/internal/cgroup/sizes.go| index 42473a826..f91d091f4 100644 |
| --- a/internal/cgroup/sizes.go |
| +++ b/internal/cgroup/sizes.go |
| @@ -14,13 +14,31 @@ type Size struct { |
| // derived from it, and ValidParentLimit and the strict validators accept |
| // its rows, which is why every row is a literal: a row built from any of |
| // them would be an initialization cycle. |
| +// |
| +// The first sharedSizes rows (small to xlarge) run on every box. Every row |
| +// after them is a fleet size (#892 S2): 200% CPU per GiB, and only for a |
| +// box of an owned fleet with the memory for it (FleetGate). |
| var Sizes = []Size{ |
| {Name: "small", Limit: Limit{MemoryMax: 256 << 20}, Shares: Shares{CPUWeight: 50, CPUQuotaPercent: 50, IOWeight: 50}}, |
| {Name: "standard", Limit: Limit{MemoryMax: 512 << 20}, Shares: Shares{CPUWeight: 100, CPUQuotaPercent: 100, IOWeight: 100}}, |
| {Name: "large", Limit: Limit{MemoryMax: 1 << 30}, Shares: Shares{CPUWeight: 100, CPUQuotaPercent: 200, IOWeight: 100}}, |
| {Name: "xlarge", Limit: Limit{MemoryMax: 2 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 400, IOWeight: 200}}, |
| + {Name: "4g", Limit: Limit{MemoryMax: 4 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 800, IOWeight: 200}}, |
| + {Name: "6g", Limit: Limit{MemoryMax: 6 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 1200, IOWeight: 200}}, |
| + {Name: "8g", Limit: Limit{MemoryMax: 8 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 1600, IOWeight: 200}}, |
| + {Name: "12g", Limit: Limit{MemoryMax: 12 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 2400, IOWeight: 200}}, |
| + {Name: "16g", Limit: Limit{MemoryMax: 16 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 3200, IOWeight: 200}}, |
| + {Name: "24g", Limit: Limit{MemoryMax: 24 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 4800, IOWeight: 200}}, |
| + {Name: "32g", Limit: Limit{MemoryMax: 32 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 6400, IOWeight: 200}}, |
| + {Name: "48g", Limit: Limit{MemoryMax: 48 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 9600, IOWeight: 200}}, |
| + {Name: "96g", Limit: Limit{MemoryMax: 96 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 19200, IOWeight: 200}}, |
| + {Name: "192g", Limit: Limit{MemoryMax: 192 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 38400, IOWeight: 200}}, |
| } |
| +// sharedSizes is how many of Sizes' first rows are shared sizes: small, |
| +// standard, large and xlarge, the sizes every box runs. |
| +const sharedSizes = 4 |
| + |
| // SizeByName is the size called name, matched exactly (no case folding). |
| func SizeByName(name string) (Size, bool) { |
| for _, s := range Sizes { |
| @@ -50,3 +68,25 @@ func SizeNames() []string { |
| } |
| return names |
| } |
| + |
| +// FleetSize is whether name is a fleet size: a row after xlarge (#892 S2). |
| +// small..xlarge and names that are no size are not. |
| +func FleetSize(name string) bool { |
| + for i, s := range Sizes { |
| + if s.Name == name { |
| + return i >= sharedSizes |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// SharedSizeOf is SizeOf restricted to the shared sizes, small..xlarge: |
| +// the rows every box runs, whatever its fleet. |
| +func SharedSizeOf(l Limit) (Size, bool) { |
| + for _, s := range Sizes[:sharedSizes] { |
| + if s.Limit == l { |
| + return s, true |
| + } |
| + } |
| + return Size{}, false |
| +} |
diff --git a/internal/cgroup/sizes_test.go b/internal/cgroup/sizes_test.go| index 595156b38..6eaae76ad 100644 |
| --- a/internal/cgroup/sizes_test.go |
| +++ b/internal/cgroup/sizes_test.go |
| @@ -14,6 +14,16 @@ func TestSizesTable(t *testing.T) { |
| {Name: "standard", Limit: Limit{MemoryMax: 512 << 20}, Shares: Shares{CPUWeight: 100, CPUQuotaPercent: 100, IOWeight: 100}}, |
| {Name: "large", Limit: Limit{MemoryMax: 1 << 30}, Shares: Shares{CPUWeight: 100, CPUQuotaPercent: 200, IOWeight: 100}}, |
| {Name: "xlarge", Limit: Limit{MemoryMax: 2 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 400, IOWeight: 200}}, |
| + {Name: "4g", Limit: Limit{MemoryMax: 4 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 800, IOWeight: 200}}, |
| + {Name: "6g", Limit: Limit{MemoryMax: 6 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 1200, IOWeight: 200}}, |
| + {Name: "8g", Limit: Limit{MemoryMax: 8 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 1600, IOWeight: 200}}, |
| + {Name: "12g", Limit: Limit{MemoryMax: 12 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 2400, IOWeight: 200}}, |
| + {Name: "16g", Limit: Limit{MemoryMax: 16 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 3200, IOWeight: 200}}, |
| + {Name: "24g", Limit: Limit{MemoryMax: 24 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 4800, IOWeight: 200}}, |
| + {Name: "32g", Limit: Limit{MemoryMax: 32 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 6400, IOWeight: 200}}, |
| + {Name: "48g", Limit: Limit{MemoryMax: 48 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 9600, IOWeight: 200}}, |
| + {Name: "96g", Limit: Limit{MemoryMax: 96 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 19200, IOWeight: 200}}, |
| + {Name: "192g", Limit: Limit{MemoryMax: 192 << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: 38400, IOWeight: 200}}, |
| } |
| if !reflect.DeepEqual(Sizes, want) { |
| t.Fatalf("Sizes = %+v\nwant %+v", Sizes, want) |
| @@ -49,9 +59,12 @@ func TestSizesTable(t *testing.T) { |
| if got, ok := SizeOf(Limit{MemoryMax: 3 << 30}); ok { |
| t.Errorf("SizeOf(3G) = %+v, true; want not ok", got) |
| } |
| + if got, ok := SizeOf(Limit{MemoryMax: 5 << 30}); ok { |
| + t.Errorf("SizeOf(5G) = %+v, true; want not ok", got) |
| + } |
| names := SizeNames() |
| - if wantNames := []string{"small", "standard", "large", "xlarge"}; !reflect.DeepEqual(names, wantNames) { |
| + if wantNames := []string{"small", "standard", "large", "xlarge", "4g", "6g", "8g", "12g", "16g", "24g", "32g", "48g", "96g", "192g"}; !reflect.DeepEqual(names, wantNames) { |
| t.Errorf("SizeNames() = %q, want %q", names, wantNames) |
| } |
| // A caller that edits the returned slice does not edit the table. |
| @@ -99,3 +112,87 @@ func TestSizesTableIsLiteral(t *testing.T) { |
| t.Fatalf("no `var Sizes = ...` in sizes.go") |
| } |
| } |
| + |
| +// TestFleetSizeBounds pins #892 S2's ten fleet rows: exact numbers, in |
| +// order after xlarge, FleetSize true for them alone, SharedSizeOf and |
| +// ValidSharedParentLimit holding today's small..xlarge set, and the fleet |
| +// budget max(0, total - max(1 GiB, total/8)). |
| +func TestFleetSizeBounds(t *testing.T) { |
| + fleet := []struct { |
| + name string |
| + gib int64 |
| + quota int |
| + }{ |
| + {"4g", 4, 800}, {"6g", 6, 1200}, {"8g", 8, 1600}, {"12g", 12, 2400}, {"16g", 16, 3200}, |
| + {"24g", 24, 4800}, {"32g", 32, 6400}, {"48g", 48, 9600}, {"96g", 96, 19200}, {"192g", 192, 38400}, |
| + } |
| + if len(Sizes) != 4+len(fleet) { |
| + t.Fatalf("Sizes has %d rows, want %d", len(Sizes), 4+len(fleet)) |
| + } |
| + if Sizes[3].Name != "xlarge" { |
| + t.Fatalf("Sizes[3] = %q, want xlarge", Sizes[3].Name) |
| + } |
| + for i, f := range fleet { |
| + row := Sizes[4+i] |
| + want := Size{Name: f.name, Limit: Limit{MemoryMax: f.gib << 30}, Shares: Shares{CPUWeight: 200, CPUQuotaPercent: f.quota, IOWeight: 200}} |
| + if row != want { |
| + t.Errorf("Sizes[%d] = %+v, want %+v", 4+i, row, want) |
| + } |
| + if f.quota != int(200*f.gib) { |
| + t.Errorf("%s: quota %d is not 200 per GiB", f.name, f.quota) |
| + } |
| + if !FleetSize(f.name) { |
| + t.Errorf("FleetSize(%q) = false", f.name) |
| + } |
| + if got, ok := SharedSizeOf(row.Limit); ok { |
| + t.Errorf("SharedSizeOf(%s) = %+v, true; want not ok", f.name, got) |
| + } |
| + // 4g alone is xlarge+xlarge, a parent every box takes today. |
| + if got := ValidSharedParentLimit(row.Limit); got != (f.name == "4g") { |
| + t.Errorf("ValidSharedParentLimit(%s) = %v", f.name, got) |
| + } |
| + if !ValidParentLimit(row.Limit) { |
| + t.Errorf("ValidParentLimit(%s) = false", f.name) |
| + } |
| + } |
| + for _, name := range []string{"small", "standard", "large", "xlarge", "", "3g", "4G", "medium"} { |
| + if FleetSize(name) { |
| + t.Errorf("FleetSize(%q) = true", name) |
| + } |
| + } |
| + for _, s := range Sizes[:4] { |
| + if got, ok := SharedSizeOf(s.Limit); !ok || got != s { |
| + t.Errorf("SharedSizeOf(%s) = %+v, %v; want the row", s.Name, got, ok) |
| + } |
| + } |
| + // Today's parent set, exactly: one or two of small..xlarge. |
| + shared := map[int64]bool{} |
| + for _, a := range Sizes[:4] { |
| + shared[a.Limit.MemoryMax] = true |
| + for _, b := range Sizes[:4] { |
| + shared[a.Limit.MemoryMax+b.Limit.MemoryMax] = true |
| + } |
| + } |
| + for n := range shared { |
| + if !ValidSharedParentLimit(Limit{MemoryMax: n}) { |
| + t.Errorf("ValidSharedParentLimit(%d) = false", n) |
| + } |
| + } |
| + for _, n := range []int64{0, 1, 5 << 30, 6 << 30, (4 << 30) + (4 << 30), 192 << 30} { |
| + if ValidSharedParentLimit(Limit{MemoryMax: n}) { |
| + t.Errorf("ValidSharedParentLimit(%d) = true", n) |
| + } |
| + } |
| + for _, tc := range []struct{ total, want int64 }{ |
| + {8 << 30, 7 << 30}, |
| + {32 << 30, 28 << 30}, |
| + {5 << 30, 4 << 30}, |
| + {0, 0}, |
| + {1 << 29, 0}, |
| + {-1, 0}, |
| + } { |
| + if got := FleetMemoryBudget(tc.total); got != tc.want { |
| + t.Errorf("FleetMemoryBudget(%d) = %d, want %d", tc.total, got, tc.want) |
| + } |
| + } |
| +} |
diff --git a/internal/cgroup/strict_gen_linux.go b/internal/cgroup/strict_gen_linux.go| index 69923813c..9ef930e93 100644 |
| --- a/internal/cgroup/strict_gen_linux.go |
| +++ b/internal/cgroup/strict_gen_linux.go |
| @@ -159,7 +159,7 @@ func (m *Manager) PrepareStrictParent(host string, tier Limit) (*Prepared, error |
| // and memory.oom.group=1 (spec §7.3). tier is this generation's own and may |
| // differ from the incumbent's when a release changes tier. |
| func (p *Prepared) PrepareGen(n uint64, tier Limit) (out *Prepared, err error) { |
| - if _, ok := SizeOf(tier); p == nil || p.strictPreparedState == nil || n == 0 || !ok { |
| + if p == nil || p.strictPreparedState == nil || n == 0 || p.fleet.GenAllowed(tier, false) != nil { |
| return nil, ErrStrictRefused |
| } |
| p.mu.Lock() |
| @@ -213,7 +213,7 @@ func (p *Prepared) PrepareGen(n uint64, tier Limit) (out *Prepared, err error) { |
| // failure leaves the record matching the kernel. A limit someone else set |
| // is refused, not overwritten. |
| func (p *Prepared) SetParentLimit(l Limit) error { |
| - if p == nil || p.strictPreparedState == nil || !ValidParentLimit(l) { |
| + if p == nil || p.strictPreparedState == nil || p.fleet.ParentAllowed(l, false) != nil { |
| return ErrStrictRefused |
| } |
| p.mu.Lock() |
diff --git a/internal/cgroup/strict_gen_linux_test.go b/internal/cgroup/strict_gen_linux_test.go| index 4aec80d5f..7aaeb1bc8 100644 |
| --- a/internal/cgroup/strict_gen_linux_test.go |
| +++ b/internal/cgroup/strict_gen_linux_test.go |
| @@ -62,12 +62,21 @@ func TestPrepareGenWritesTheFullTier(t *testing.T) { |
| } |
| } |
| -// TestPrepareGenWritesEverySize: each of the four sizes is a generation's |
| -// own limit, written in full; a sum of two (768 MiB) is a parent's limit |
| -// only, never a generation's. |
| +// TestPrepareGenWritesEverySize: each size is a generation's own limit, |
| +// written in full (a fleet size only through a fleet gate with the budget, |
| +// #892 S2); a sum of two (768 MiB) is a parent's limit only, never a |
| +// generation's. |
| func TestPrepareGenWritesEverySize(t *testing.T) { |
| for _, size := range Sizes { |
| p := genParentFixture(t) |
| + if FleetSize(size.Name) { |
| + makeGenFixture(t, p, 1, "populated 0\n") |
| + if child, err := p.PrepareGen(1, size.Limit); child != nil || !errors.Is(err, ErrStrictRefused) { |
| + t.Fatalf("%s under the zero gate: %v, %v; want ErrStrictRefused", size.Name, child, err) |
| + } |
| + p = genParentFixture(t) |
| + p.fleet = FleetGate{Fleet: true, MemTotal: func() (int64, error) { return 256 << 30, nil }} |
| + } |
| d := makeGenFixture(t, p, 1, "populated 0\n") |
| child, err := p.PrepareGen(1, size.Limit) |
| if err != nil { |
| @@ -183,6 +192,28 @@ func TestSetParentLimitAcceptsATierChange(t *testing.T) { |
| } |
| } |
| +// TestSetParentLimitFleetOverlapNeedsTheGate: a parent only a fleet size |
| +// makes valid (4g + xlarge) is refused under the zero gate and set under a |
| +// fleet gate whose budget holds it (#892 S2, ruling P4). |
| +func TestSetParentLimitFleetOverlapNeedsTheGate(t *testing.T) { |
| + six := Limit{MemoryMax: 6 << 30} |
| + p := genParentFixture(t) |
| + if err := p.SetParentLimit(six); !errors.Is(err, ErrStrictRefused) { |
| + t.Fatalf("6 GiB under the zero gate: %v", err) |
| + } |
| + p.fleet = FleetGate{Fleet: true, MemTotal: func() (int64, error) { return (7 << 30) - 1, nil }} |
| + if err := p.SetParentLimit(six); !errors.Is(err, ErrStrictRefused) { |
| + t.Fatalf("6 GiB over a box of 7 GiB less a byte: %v", err) |
| + } |
| + p.fleet.MemTotal = func() (int64, error) { return 8 << 30, nil } |
| + if err := p.SetParentLimit(six); err != nil { |
| + t.Fatalf("6 GiB within an 8 GiB box's budget: %v", err) |
| + } |
| + if got := readFixture(t, filepath.Join(p.dir.Name(), "memory.max")); got != strconv.FormatInt(6<<30, 10) { |
| + t.Fatalf("parent memory.max = %q", got) |
| + } |
| +} |
| + |
| func TestGenerationKillAndEmptyTouchesOnlyItsChild(t *testing.T) { |
| p := genParentFixture(t) |
| d1 := makeGenFixture(t, p, 1, "populated 1\n") |
diff --git a/internal/cgroup/strict_linux.go b/internal/cgroup/strict_linux.go| index f1921d8b6..19fd26f05 100644 |
| --- a/internal/cgroup/strict_linux.go |
| +++ b/internal/cgroup/strict_linux.go |
| @@ -50,6 +50,9 @@ type strictPreparedState struct { |
| // generation child's own. |
| genParent bool |
| tier Limit |
| + // fleet is the Manager's fleet gate, which PrepareGen and |
| + // SetParentLimit judge a generation parent's limits by. |
| + fleet FleetGate |
| } |
| func strictOpen(dir *os.File, name string, flags int) (*os.File, error) { |
| @@ -201,8 +204,9 @@ func (m *Manager) StrictPreflight() error { |
| } |
| // PrepareStrict never uses accounting's fallback. Only a size's own limit is |
| -// accepted (one row of the size table, never a sum); a zero or missing limit |
| -// cannot create an uncapped command. |
| +// accepted (one row of the size table, never a sum; a fleet size only |
| +// through the Manager's FleetGate); a zero or missing limit cannot create |
| +// an uncapped command. |
| func (m *Manager) PrepareStrict(host string, limit Limit) (*Prepared, error) { |
| return m.prepareStrict(host, limit, false) |
| } |
| @@ -214,14 +218,14 @@ func (m *Manager) prepareStrict(host string, limit Limit, genParent bool) (out * |
| if m == nil || m.root == "" { |
| return nil, ErrStrictUnsupported |
| } |
| - if _, ok := SizeOf(limit); !controlname.ValidHostShape(host) || !ok { |
| + if !controlname.ValidHostShape(host) || m.fleet.GenAllowed(limit, false) != nil { |
| return nil, ErrStrictRefused |
| } |
| root, e := m.strictRoot() |
| if e != nil { |
| return nil, e |
| } |
| - p := &Prepared{strictPreparedState: &strictPreparedState{root: root, host: host, limits: map[string]*os.File{}, start: func(cmd *exec.Cmd) error { return cmd.Start() }}} |
| + p := &Prepared{strictPreparedState: &strictPreparedState{root: root, host: host, limits: map[string]*os.File{}, start: func(cmd *exec.Cmd) error { return cmd.Start() }, fleet: m.fleet}} |
| reserved := false |
| defer func() { |
| if err != nil { |
diff --git a/internal/cgroup/strict_linux_test.go b/internal/cgroup/strict_linux_test.go| index a0fa429bc..fdfb75d17 100644 |
| --- a/internal/cgroup/strict_linux_test.go |
| +++ b/internal/cgroup/strict_linux_test.go |
| @@ -121,9 +121,21 @@ func TestPrepareStrictTakesEverySize(t *testing.T) { |
| "PrepareStrict": func(l Limit) (*Prepared, error) { return m.PrepareStrict("x.example", l) }, |
| "PrepareStrictParent": func(l Limit) (*Prepared, error) { return m.PrepareStrictParent("x.example", l) }, |
| } |
| + big := &Manager{root: "/sys/fs/cgroup", fleet: FleetGate{Fleet: true, MemTotal: func() (int64, error) { return 256 << 30, nil }}} |
| for name, prepare := range prepares { |
| for _, size := range Sizes { |
| p, e := prepare(size.Limit) |
| + if FleetSize(size.Name) { |
| + // The zero gate takes no fleet size (#892 S2). |
| + if p != nil || !errors.Is(e, ErrStrictRefused) { |
| + t.Errorf("%s(%s) under the zero gate = %v, %v; want ErrStrictRefused", name, size.Name, p, e) |
| + } |
| + if name == "PrepareStrict" { |
| + p, e = big.PrepareStrict("x.example", size.Limit) |
| + } else { |
| + p, e = big.PrepareStrictParent("x.example", size.Limit) |
| + } |
| + } |
| if p != nil || errors.Is(e, ErrStrictRefused) || !errors.Is(e, ErrStrictUnsupported) { |
| t.Errorf("%s(%s) = %v, %v; want the runtime check's ErrStrictUnsupported", name, size.Name, p, e) |
| } |
diff --git a/internal/host/claimlaunch_root.go b/internal/host/claimlaunch_root.go| index 7284f4a9d..f0cd7cf73 100644 |
| --- a/internal/host/claimlaunch_root.go |
| +++ b/internal/host/claimlaunch_root.go |
| @@ -160,8 +160,10 @@ func claimLaunchAuthority(c *hostclaim.Claim, t hostguard.FenceTarget, box strin |
| return nil |
| } |
| +// claimLaunchTier takes a shared size only: claims take no fleet size |
| +// (#892 S2, ruling P6). |
| func claimLaunchTier(n int64) bool { |
| - _, ok := cgroup.SizeOf(cgroup.Limit{MemoryMax: n}) |
| + _, ok := cgroup.SharedSizeOf(cgroup.Limit{MemoryMax: n}) |
| return ok |
| } |
diff --git a/internal/host/claimroleassembly.go b/internal/host/claimroleassembly.go| index 3b716c31f..118ef8a5b 100644 |
| --- a/internal/host/claimroleassembly.go |
| +++ b/internal/host/claimroleassembly.go |
| @@ -116,10 +116,11 @@ type claimIsolatedLaunch struct { |
| } |
| // claimIsolatedPaths admits only the nested layout's database, directly in |
| -// the host's instance directory, and a platform tier. |
| +// the host's instance directory, and a shared platform tier (claims take no |
| +// fleet size: #892 S2, ruling P6). |
| func claimIsolatedPaths(roots map[string]string, host string, in ClaimLaunchInputs) (claimIsolatedLaunch, error) { |
| data := roots["data"] |
| - _, sized := cgroup.SizeOf(cgroup.Limit{MemoryMax: in.Limit.MemoryMax}) |
| + _, sized := cgroup.SharedSizeOf(cgroup.Limit{MemoryMax: in.Limit.MemoryMax}) |
| if !filepath.IsAbs(data) || !provision.ValidHostShape(host) || !filepath.IsAbs(in.DBPath) || filepath.Clean(in.DBPath) != in.DBPath || !sized { |
| return claimIsolatedLaunch{}, hostbox.ErrRoleLaunchShape |
| } |
diff --git a/internal/instancectl/claimunit.go b/internal/instancectl/claimunit.go| index 96cf6b1ef..9f6c61dcb 100644 |
| --- a/internal/instancectl/claimunit.go |
| +++ b/internal/instancectl/claimunit.go |
| @@ -67,8 +67,10 @@ var ( |
| // code calls it by. |
| func ClaimUnitControlGroup(host string) string { return RunUnitControlGroup(host) } |
| +// claimTier takes a shared size only: claims are shelved and take no |
| +// fleet size (#892 S2, ruling P6). |
| func claimTier(n int64) (cgroup.Limit, bool) { |
| - if _, ok := cgroup.SizeOf(cgroup.Limit{MemoryMax: n}); !ok { |
| + if _, ok := cgroup.SharedSizeOf(cgroup.Limit{MemoryMax: n}); !ok { |
| return cgroup.Limit{}, false |
| } |
| return cgroup.Limit{MemoryMax: n}, true |
diff --git a/internal/instancectl/cmd.go b/internal/instancectl/cmd.go| index 4d68d6cd9..116bf4db1 100644 |
| --- a/internal/instancectl/cmd.go |
| +++ b/internal/instancectl/cmd.go |
| @@ -56,7 +56,7 @@ func (s *Server) startOneShot(w http.ResponseWriter, r *http.Request, role Role) |
| http.Error(w, "role "+string(role)+" is not a one-shot role", http.StatusInternalServerError) |
| return |
| } |
| - req, err := parseRequest(r, verbShape{tier: true, exe: true, cmd: true, rootfs: true}) |
| + req, err := s.parseTierRequest(r, verbShape{tier: true, exe: true, cmd: true, rootfs: true}) |
| if err != nil { |
| http.Error(w, err.Error(), http.StatusBadRequest) |
| return |
diff --git a/internal/instancectl/fleetsize.go b/internal/instancectl/fleetsize.go| new file mode 100644 |
| index 000000000..8a9d471db |
| --- /dev/null |
| +++ b/internal/instancectl/fleetsize.go |
| @@ -0,0 +1,47 @@ |
| +package instancectl |
| + |
| +import ( |
| + "net/http" |
| + |
| + "github.com/carlosframework/platform/internal/cgroup" |
| + "github.com/carlosframework/platform/internal/execsandbox" |
| +) |
| + |
| +// FleetEnv names the fleet a box belongs to in /etc/carlos/host.env, which |
| +// carlos-instance-control.service loads (#892 S2, ruling P2). Root-owned |
| +// and written at provisioning: neither a tenant nor the agent sets it. Set, |
| +// root takes fleet sizes within the box's budget (Server.Fleet). |
| +const FleetEnv = "CARLOS_FLEET" |
| + |
| +// productionFleetGate is root's fleet gate from its own environment. |
| +func productionFleetGate(getenv func(string) string) cgroup.FleetGate { |
| + return cgroup.FleetGate{Fleet: getenv(FleetEnv) != "", MemTotal: hostMemTotal} |
| +} |
| + |
| +// gvisorUnits is whether this box's units run in the gVisor family, as |
| +// setTier and writeGenDropIn decide it: such a unit takes no fleet size. |
| +func (s *Server) gvisorUnits() bool { |
| + return s.effectiveSandbox() == execsandbox.EffectiveGVisor |
| +} |
| + |
| +// tierAllowed is Server.Fleet's answer for one unit's (or generation's) |
| +// tier on this box. |
| +func (s *Server) tierAllowed(tier cgroup.Limit) error { |
| + return s.Fleet.GenAllowed(tier, s.gvisorUnits()) |
| +} |
| + |
| +// parseTierRequest is parseRequest with the tier judged by this box's |
| +// fleet gate: a fleet size the box cannot run is a 400 before any write, |
| +// as a tier that is no size is. |
| +func (s *Server) parseTierRequest(r *http.Request, v verbShape) (request, error) { |
| + req, err := parseRequest(r, v) |
| + if err != nil { |
| + return request{}, err |
| + } |
| + if v.tier { |
| + if err := s.tierAllowed(req.tier); err != nil { |
| + return request{}, err |
| + } |
| + } |
| + return req, nil |
| +} |
diff --git a/internal/instancectl/fleetsize_linux.go b/internal/instancectl/fleetsize_linux.go| new file mode 100644 |
| index 000000000..4007ae501 |
| --- /dev/null |
| +++ b/internal/instancectl/fleetsize_linux.go |
| @@ -0,0 +1,9 @@ |
| +//go:build linux |
| + |
| +package instancectl |
| + |
| +import "github.com/carlosframework/platform/internal/cgroup" |
| + |
| +// hostMemTotal is /proc/meminfo's MemTotal in bytes: the box's memory, |
| +// which the fleet budget is taken from. |
| +func hostMemTotal() (int64, error) { return cgroup.ReadMemTotal("/proc/meminfo") } |
diff --git a/internal/instancectl/fleetsize_other.go b/internal/instancectl/fleetsize_other.go| new file mode 100644 |
| index 000000000..78a4e5769 |
| --- /dev/null |
| +++ b/internal/instancectl/fleetsize_other.go |
| @@ -0,0 +1,9 @@ |
| +//go:build !linux |
| + |
| +package instancectl |
| + |
| +import "errors" |
| + |
| +// hostMemTotal has no /proc/meminfo to read off Linux: fleet sizes are |
| +// refused. |
| +func hostMemTotal() (int64, error) { return 0, errors.New("instance control: no MemTotal off linux") } |
diff --git a/internal/instancectl/fleetsize_test.go b/internal/instancectl/fleetsize_test.go| new file mode 100644 |
| index 000000000..7050ab3c1 |
| --- /dev/null |
| +++ b/internal/instancectl/fleetsize_test.go |
| @@ -0,0 +1,117 @@ |
| +package instancectl |
| + |
| +import ( |
| + "context" |
| + "io" |
| + "net/http" |
| + "strconv" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/cgroup" |
| + "github.com/carlosframework/platform/internal/execsandbox" |
| +) |
| + |
| +const fleetGiB = int64(1) << 30 |
| + |
| +func fleetGate(total int64) func(*Server) { |
| + return func(s *Server) { |
| + s.Fleet = cgroup.FleetGate{Fleet: true, MemTotal: func() (int64, error) { return total, nil }} |
| + } |
| +} |
| + |
| +// TestFleetSizeRootValidator: root takes a fleet size only from its own |
| +// fleet gate (#892 S2, P2/P4/P6), through the real handlers. A shared box |
| +// (the zero gate) refuses a fleet start and a parent only a fleet row |
| +// makes valid, and still takes today's 4 GiB parent; a fleet box with the |
| +// budget takes a fleet start; a gVisor slice and a claim never take one. |
| +func TestFleetSizeRootValidator(t *testing.T) { |
| + const host = "bill-2.example.com" |
| + t.Run("zero gate", func(t *testing.T) { |
| + ctl := &fakeCtl{answers: map[string]string{"show -p InvocationID --value": "abc123\n"}} |
| + _, c := newServer(t, ctl) |
| + for _, path := range []string{ |
| + "/parent?host=" + host + "&memory_max=" + strconv.FormatInt(6*fleetGiB, 10), |
| + "/start?host=" + host + "&role=run&memory_max=" + strconv.FormatInt(4*fleetGiB, 10), |
| + } { |
| + resp := post(t, c, path) |
| + body, _ := io.ReadAll(resp.Body) |
| + resp.Body.Close() |
| + if resp.StatusCode != http.StatusBadRequest { |
| + t.Errorf("%s: status %d (%s), want 400", path, resp.StatusCode, body) |
| + } |
| + } |
| + if got := ctl.joined(); got != "" { |
| + t.Fatalf("a refused fleet size reached systemctl:\n%s", got) |
| + } |
| + resp := post(t, c, "/parent?host="+host+"&memory_max="+strconv.FormatInt(4*fleetGiB, 10)) |
| + resp.Body.Close() |
| + if resp.StatusCode != http.StatusNoContent { |
| + t.Errorf("/parent 4 GiB (xlarge+xlarge): status %d, want 204", resp.StatusCode) |
| + } |
| + }) |
| + t.Run("fleet gate 8 GiB", func(t *testing.T) { |
| + ctl := &fakeCtl{answers: map[string]string{"show -p InvocationID --value": "abc123\n"}} |
| + _, c := newServer(t, ctl, fleetGate(8*fleetGiB)) |
| + six := strconv.FormatInt(6*fleetGiB, 10) |
| + resp := post(t, c, "/start?host="+host+"&role=run&memory_max="+six) |
| + resp.Body.Close() |
| + if resp.StatusCode != http.StatusOK { |
| + t.Fatalf("start 6g: status %d, want 200", resp.StatusCode) |
| + } |
| + want := "set-property --runtime carlos-instances-bill\\x2d2.example.com.slice MemoryMax=" + six + " MemoryHigh=" + strconv.FormatInt(cgroup.HighOf(6*fleetGiB), 10) + " MemorySwapMax=" + six + " CPUWeight=200 CPUQuota=1200% IOWeight=200" |
| + if first, _, _ := strings.Cut(ctl.joined(), "\n"); first != want { |
| + t.Errorf("first systemctl line\n%s\nwant\n%s", first, want) |
| + } |
| + // 8g is over the budget (7 GiB): refused before systemctl. |
| + ctl2 := &fakeCtl{} |
| + _, c2 := newServer(t, ctl2, fleetGate(8*fleetGiB)) |
| + resp = post(t, c2, "/start?host="+host+"&role=run&memory_max="+strconv.FormatInt(8*fleetGiB, 10)) |
| + resp.Body.Close() |
| + if resp.StatusCode != http.StatusBadRequest || ctl2.joined() != "" { |
| + t.Errorf("start 8g on an 8 GiB box: status %d, calls %q; want 400 and none", resp.StatusCode, ctl2.joined()) |
| + } |
| + }) |
| + t.Run("gvisor slice tier", func(t *testing.T) { |
| + ctl := &fakeCtl{} |
| + s, _ := newServer(t, ctl, fleetGate(64*fleetGiB), func(s *Server) { s.SandboxEffective = execsandbox.EffectiveGVisor }) |
| + four, _ := cgroup.SizeByName("4g") |
| + if err := s.setTier(context.Background(), host, four.Limit); err == nil { |
| + t.Error("setTier 4g on a gVisor box: nil, want a refusal") |
| + } |
| + if got := ctl.joined(); got != "" { |
| + t.Errorf("a refused gVisor tier reached systemctl: %s", got) |
| + } |
| + xl, _ := cgroup.SizeByName("xlarge") |
| + if err := s.setTier(context.Background(), host, xl.Limit); err != nil { |
| + t.Errorf("setTier xlarge on a gVisor box: %v", err) |
| + } |
| + }) |
| + t.Run("claim tier", func(t *testing.T) { |
| + if _, ok := claimTier(4 * fleetGiB); ok { |
| + t.Error("claimTier(4g) took a fleet size") |
| + } |
| + }) |
| +} |
| + |
| +// TestFleetSizeLiveSizeRefused: /size naming a fleet size on a box whose |
| +// gate refuses it is refused before any write; a shared size still |
| +// applies. |
| +func TestFleetSizeLiveSizeRefused(t *testing.T) { |
| + ctl := sizeCtl("MemoryMax=536870912\nCPUQuotaPerSecUSec=4s\nCPUWeight=200\nIOWeight=200\n") |
| + _, c := newServer(t, ctl) |
| + status, body := postSize(t, c, "host="+sizeHost+"&size=192g") |
| + if status != http.StatusBadRequest { |
| + t.Errorf("/size 192g: status %d (%s), want 400", status, body) |
| + } |
| + if got := ctl.joined(); got != "" { |
| + t.Fatalf("/size 192g called systemctl:\n%s", got) |
| + } |
| + status, body = postSize(t, c, "host="+sizeHost+"&size=xlarge") |
| + if status != http.StatusOK { |
| + t.Errorf("/size xlarge: status %d (%s), want 200", status, body) |
| + } |
| + if !strings.Contains(ctl.joined(), "CPUQuota=400%") { |
| + t.Errorf("/size xlarge did not apply: %s", ctl.joined()) |
| + } |
| +} |
diff --git a/internal/instancectl/gen.go b/internal/instancectl/gen.go| index f77fb0ccd..031c36951 100644 |
| --- a/internal/instancectl/gen.go |
| +++ b/internal/instancectl/gen.go |
| @@ -773,6 +773,12 @@ func (s *Server) handleParent(w http.ResponseWriter, r *http.Request) { |
| http.Error(w, "memory_max "+strconv.Quote(q.Get("memory_max"))+" is not one tier or two", http.StatusBadRequest) |
| return |
| } |
| + // A parent only a fleet size makes valid needs this box's fleet gate, |
| + // the whole overlap within its budget (#892 S2, ruling P4). |
| + if err := s.Fleet.ParentAllowed(cgroup.Limit{MemoryMax: n}, s.gvisorUnits()); err != nil { |
| + http.Error(w, "memory_max "+strconv.Quote(q.Get("memory_max"))+": "+err.Error(), http.StatusBadRequest) |
| + return |
| + } |
| if s.DemoBox { |
| small, _ := cgroup.SizeByName("small") |
| n = small.Limit.MemoryMax |
diff --git a/internal/instancectl/server.go b/internal/instancectl/server.go| index 5b44d06b5..7cc063cee 100644 |
| --- a/internal/instancectl/server.go |
| +++ b/internal/instancectl/server.go |
| @@ -148,6 +148,11 @@ type Server struct { |
| // EdgeFenceOff is host.env's CARLOS_EDGE_FENCE=off: the full deny, |
| // whatever the box's addresses. |
| EdgeFenceOff bool |
| + // Fleet is root's fleet-size gate (#892 S2): host.env's CARLOS_FLEET |
| + // (FleetEnv) and the box's MemTotal. Every tier, parent and live size |
| + // that only a fleet size makes valid passes it; the zero gate (a |
| + // shared box) takes small..xlarge and today's parents alone. |
| + Fleet cgroup.FleetGate |
| // DenyEvery is denyLoop's cadence: how often the box's addresses are |
| // re-read for a change, so a new one is denied to every nested unit |
| // (#367; 10 s in production). Zero runs no loop. |
| @@ -372,6 +377,7 @@ func runWithClaim(args []string, claim, heldRelease http.Handler, view RegistryV |
| LocalAddrs: func() ([]netip.Prefix, error) { return localPrefixes(fibTriePath, ifInet6Path) }, |
| NFT: edgefence.Exec, |
| EdgeFenceOff: os.Getenv(EdgeFenceEnv) == "off", |
| + Fleet: productionFleetGate(os.Getenv), |
| DenyEvery: 10 * time.Second, |
| DataRoot: "/data/instances", |
| Statfs: statfsBytes, |
| @@ -798,6 +804,8 @@ func parseQuery(host string, q url.Values, v verbShape) (request, error) { |
| if err != nil { |
| return request{}, fmt.Errorf("memory_max %q is not a number", q.Get("memory_max")) |
| } |
| + // Any row here; a fleet row is the fleet gate's to judge |
| + // (parseTierRequest, setTier). |
| if _, ok := cgroup.SizeOf(cgroup.Limit{MemoryMax: n}); !ok { |
| return request{}, fmt.Errorf("memory_max %d is not a platform tier", n) |
| } |
| @@ -859,6 +867,9 @@ func (s *Server) setTier(ctx context.Context, host string, tier cgroup.Limit) er |
| small, _ := cgroup.SizeByName("small") |
| tier = small.Limit |
| } |
| + if err := s.tierAllowed(tier); err != nil { |
| + return err |
| + } |
| family := execsandbox.FamilySystemd |
| if s.effectiveSandbox() == execsandbox.EffectiveGVisor { |
| family = execsandbox.FamilyGVisor |
| @@ -904,7 +915,7 @@ func writeJSON(w http.ResponseWriter, status int, v any) { |
| } |
| func (s *Server) handleStart(w http.ResponseWriter, r *http.Request) { |
| - req, err := parseRequest(r, verbShape{roles: []Role{RoleRun, RoleSidecar, RoleWorker}, tier: true, gen: true, exe: true, rootfs: true, worker: true}) |
| + req, err := s.parseTierRequest(r, verbShape{roles: []Role{RoleRun, RoleSidecar, RoleWorker}, tier: true, gen: true, exe: true, rootfs: true, worker: true}) |
| if err != nil { |
| http.Error(w, err.Error(), http.StatusBadRequest) |
| return |
| @@ -1101,7 +1112,7 @@ func (s *Server) handleSeed(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| - req, err := parseRequest(r, verbShape{tier: true, exe: true, seed: true}) |
| + req, err := s.parseTierRequest(r, verbShape{tier: true, exe: true, seed: true}) |
| if err != nil { |
| http.Error(w, err.Error(), http.StatusBadRequest) |
| return |
diff --git a/internal/instancectl/size.go b/internal/instancectl/size.go| index b5e2e881a..321154fbf 100644 |
| --- a/internal/instancectl/size.go |
| +++ b/internal/instancectl/size.go |
| @@ -71,6 +71,11 @@ func (s *Server) handleSize(w http.ResponseWriter, r *http.Request) { |
| http.Error(w, "size "+strconv.Quote(q.Get("size"))+" is not a platform size", http.StatusBadRequest) |
| return |
| } |
| + // A fleet size's shares only where this box runs that size (#892 S2). |
| + if err := s.tierAllowed(size.Limit); err != nil { |
| + http.Error(w, "size "+strconv.Quote(q.Get("size"))+": "+err.Error(), http.StatusBadRequest) |
| + return |
| + } |
| if s.DemoBox { |
| size, _ = cgroup.SizeByName("small") |
| } |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 3abe8443a..8142012a1 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -275,3 +275,4 @@ plan14-root-reads-media-spike-values.tsv 194e88ad9cd7413c93b1181c0ac1e962107039a |
| plan14-root-reads-path-routes-across-boxes.tsv f959a3626e83650aaad1880eecc3feddebdbd78474937f4c619df658eb46a1d6 |
| plan14-root-reads-headers-security-allowlist.tsv f959a3626e83650aaad1880eecc3feddebdbd78474937f4c619df658eb46a1d6 |
| plan14-root-reads-stateless-scale-1-memory-env.tsv 47ebd73418bcbe1bdf9cf34a2b94e3393a1279aea58f9ee0aca3f0cfe42b9132 |
| +plan14-root-reads-stateless-scale-2-fleet-sizes.tsv dcd00ad63015e1ca6be4cd6f653c92a92891fea266e88e831e237adb64a1c54c |
diff --git a/internal/provision/testdata/plan14-root-reads-stateless-scale-2-fleet-sizes.tsv b/internal/provision/testdata/plan14-root-reads-stateless-scale-2-fleet-sizes.tsv| new file mode 100644 |
| index 000000000..bc5deb724 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-stateless-scale-2-fleet-sizes.tsv |
| @@ -0,0 +1,18 @@ |
| +# Census overlay stateless-scale-2-fleet-sizes, written by census-propose (#369). census-ruling-stateless-scale-2-fleet-sizes, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-stateless-scale-2-fleet-sizes.md. |
| +# 5 body, 0 sites, 4 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +# 1 new dispositions: 0 reads re-frozen at their disposition with the claim, 1 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other. |
| +@legacy 0fa85d969c48493b2c14c3600ab8508c25d2eb2267ee86b70c592c3c602adbb1 internal/cgroup/cgroup.go setup legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-hunt-account-root-hardening;basis=setup records whether the flat IMDS fence is armed (CARLOS_IMDS_FLAT_FENCE); when armed, a flat start whose shim or placement is unavailable is refused instead of falling back to start-and-move; no read is added;rev3=census-ruling-stateless-scale-2-fleet-sizes;basis=the agent (carlos-edge.service, user carlos), not root: setup now also records a fleet-size gate on the agent's own Manager when CARLOS_FLEET is set in its environment (os.Getenv, beside the existing CARLOS_IMDS_FLAT_FENCE read). The gate's MemTotal closure reads /proc/meminfo through ReadMemTotal when a strict prepare is asked for a fleet size (#892 S2). It only lets the strict validators (PrepareStrict, PrepareGen, SetParentLimit) accept the new fleet rows within FleetMemoryBudget; without CARLOS_FLEET they take small..xlarge and today's parents exactly as before. Reads added: env CARLOS_FLEET; /proc/meminfo (kernel, fixed path) via the closure file:ReadFile@73 1c2d963c219576573ba11b9b1ba07c3823902b850615a93406f6cfc3c78065cb |
| +@legacy bce72a2f498322b60434183b6db1c4703d8b691246083a08052e29757c6ea259 internal/instancectl/gen.go Server.handleParent legacy accepted-legacy accepted-legacy;rev3=J2,J4;basis=root-input;rev3=census-ruling-instance-egress-sizes-328-329;basis=#329 plan 3 Task 5: holds the host's slice lock (lockSliceWrites) around its one set-property, so /parent and /size never interleave on one slice. Its one site is still r.URL.Query() of the agent's request (counted as file:Query). The checks in this body are unchanged, though cgroup.ValidParentLimit, which it calls, now accepts one size or the sum of any two from the four-row table (up to 4 GiB, was 2 GiB); no read added.;rev3=census-ruling-agent-start-demo-1;basis=Reads fixed DemoBox and clamps the existing parent memory writer to small.;rev3=census-ruling-gvisor-demos;basis=Validate logical parent input as before, require the demo route in gVisor mode and apply Physical once to the small demo parent. Existing request query read unchanged; shares stay logical.;rev3=census-ruling-stateless-scale-2-fleet-sizes;basis=root: after the unchanged ValidParentLimit check, a parent outside today's shared set (one or two of small..xlarge) must also pass Server.Fleet.ParentAllowed: CARLOS_FLEET in root's host.env, not a gVisor box, readable MemTotal, and the whole overlap within max(0, MemTotal - max(1 GiB, MemTotal/8)), else 400 before any write. Today's parent set is accepted unchanged on every box. Same one site (r.URL.Query of the agent's request); no read added in this body (MemTotal is read by hostMemTotal through the gate) file:Query@78 2825f7708356c107eb3960e76865ce24eac36e23529374f1a4e78fb4e46b45df |
| +@legacy 47730ce40f37422d345356b7f605b7f430a0a1413abb018c519b3b098a17412b internal/instancectl/server.go type Server legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=Re-digested at the pre-land merge: the body includes main's own change under census ruling 292, with no further change from this branch. Census ruling 292 reclassified this declaration accepted-legacy (J2,J4) for root's per-host ordering of legacy run starts against stops; this ruling kept the row as main classed it. Its own addition is the cmd start's poll and wait bounds and its per-host lock map: field declarations only;rev3=census-ruling-rootfs-apps-2;basis=new fields: HostRuntime, ProbeImage, ProbeImageFile, RootfsProbeOut, DenyEvery, the deny's lastDeny and denyMu, the rootfs probe's report and lock, the jit reload counters and imageDigests; genStarting counts binary generation starts per unit; rootfsLocksMu and rootfsLocks, one lock entry per rootfs unit name being started or removed right now, held by a start from its layout through systemctl start and its own cleanup and by a removal from its proof through the raw removal, a removal refusing while it is taken, a waiting start giving up when its request ends, an entry dropped with its last holder or waiter (fixes E6, L2, L3); rootfsProvenHook, a test hook run between the proof and the raw removal; field declarations only; no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 and #329 plan 3 Task 5: the declaration gains sliceLocks (one mutex per host slice, taken by /size and /parent) and Egress (the asserter every start path calls), and its comment names the egress allow (plan 3's ControlDropInDir field was deleted in ef38e13b, the P1 EROFS fix); the same one site, the Statfs field, offset moved; no read added.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 6: comments only: the one-shot pacing fields cover /cmd and /tty, and cmdLocks is now keyed by (role, host) (oneShotKey, PF-7) so a session's start never waits behind a command's; field declarations unchanged; the same one site, no read added;rev3=census-ruling-agent-start-demo-1;basis=Adds fixed demo configuration, registry views, derived runtime root, synchronization and purge guard.;rev3=census-ruling-region-ha-p3b;basis=Add hairpinActive boolean alongside lastDeny under existing deny synchronization. Field declaration only; existing Statfs selector unchanged, no new read or externally supplied authority.;rev3=census-ruling-region-ha-p3b2-rolls;basis=adds one field holding the current hairpin exit watcher, guarded by the root hairpin flock; no new read;rev3=census-ruling-agent-start-demo-3;basis=Retain the snapshot supervisor in instance-control state; no new request-selected path. Census read-site delta: unchanged (1).;rev3=census-ruling-gvisor-demos;basis=Retain Task 1 mode/error/readiness fields, baseline/runtime callbacks, Task 4 per-host validated staged descriptors and root-selected probe nonce. Fix round 1 adds a private writer-operation seam assigned only in package tests, after the unchanged GVisorID admission check; production defaults still call the same checked constructor, WriteRootfs, WriteBundle and verifier. No new direct read or request-controlled callback. Task 5: private injected removal seam for unprivileged tests; production default removes only root-derived bundle and skeleton after both-family proof inside existing start fence. No new request field or agent-selected unit. Task 6: Retain serialized probe nonce, runtime-set identity verifier/token, fixed claims flag, bundle discovery root, and private unprivileged identity seam. No request-controlled callback or path; existing declaration read-site classification unchanged. Task 6 fix round 1: private gvisorProbeTestOps is set only in package tests; production defaults retain all fixed paths and the checked root output opener. No externally supplied callback or new direct read. Final R1 P2: retain fixed skeleton parent and concurrent per-instance cleanup refusals; no direct read or external configuration field. Carry the root-only host.env validation callback into Ready; no agent read or caller-selected path.;rev3=census-ruling-same-box-edge-fence;basis=Field declarations only: NFT (the nft runner; nil never loads the fence), EdgeFenceOff (host.env CARLOS_EDGE_FENCE=off), and under the existing denyMu/mu: fenceAddrs, fenceReason, fenceRetry, denyApplied. No read added.;rev3=census-ruling-bounded-systemctl;basis=new field Journal, the journalctl seam for the gVisor probe's diagnostic; field declaration only; no read added;rev3=census-ruling-stateless-scale-2-fleet-sizes;basis=root: new field Fleet cgroup.FleetGate (#892 S2), root's fleet-size gate; field declaration only; no read added file:Statfs@5536 6187fe6aaa37d3e4740b72153fa648038ef9e2a3a998654234811be8c159bc8d |
| +@legacy 1e939943a684cdb32282f7b1c7da889ad11acff9f59da960d35a0299b3a49110 internal/instancectl/size.go Server.handleSize legacy accepted-legacy accepted-legacy;rev3=census-ruling-instance-egress-sizes-328-329;identity=instance control (/opt/carlos/carlos instance-control, carlos-instance-control.service, root);basis=root-input (J2,J4, as Server.handleParent): new (#329 plan 3 Task 5): POST /size from the agent (the peer check admits only the edge unit's main process; claimAwareLegacy answers 503 with host claims on). Its one site is r.URL.Query() of that request (counted as file:Query): host must pass ValidHostShape, memory_max and gen are refused, size must name a row of cgroup.Sizes. Under the slice lock it runs systemctl set-property --runtime on SliceName(host) with that row's CPUWeight, CPUQuota and IOWeight, then writeSizeReadBack runs systemctl show of the slice and answers it. Root sets the slice's CPU and IO shares from the agent's choice among four platform rows; nothing from the request reaches systemctl as a string.;rev3=census-ruling-agent-start-demo-1;basis=Reads fixed DemoBox and clamps the existing live CPU/IO writer to small.;rev3=census-ruling-stateless-scale-2-fleet-sizes;basis=root: after the unchanged SizeByName check, the named row must pass Server.Fleet.GenAllowed (a shared size always; a fleet size only on a CARLOS_FLEET box, not gVisor, within the MemTotal budget), else 400 before any systemctl call. Same one site; no read added in this body file:Query@96 ef6d9da8f61aacd18fcfb6c19fe2113dde5414c97fab67de8d2e1ce5782273bb |
| +@legacy cfc2cad27651e696bdb8b59a3f7caf137df9eae22cce0b3efd73b2509da19b82 internal/cgroup/fleetgate.go ReadMemTotal legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-scale-2-fleet-sizes;basis=new: os.ReadFile of the path its caller names, then ParseMemTotal (the MemTotal line in kB, positive, bounded). Its callers pass the fixed /proc/meminfo only (instancectl hostMemTotal for root, the agent's cgroup setup closure); kernel-written, not writable by a tenant, app or agent. Used only to bound fleet sizes; an error refuses every fleet size file:ReadFile@59 00e5b8e25b9e3dbc9ee3e449ceaa22d283d69969dfc6582b2cfcdc74c07ef69e |
| +internal/cgroup/cgroup.go setup legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-hunt-account-root-hardening;basis=setup records whether the flat IMDS fence is armed (CARLOS_IMDS_FLAT_FENCE); when armed, a flat start whose shim or placement is unavailable is refused instead of falling back to start-and-move; no read is added;rev3=census-ruling-stateless-scale-2-fleet-sizes;basis=the agent (carlos-edge.service, user carlos), not root: setup now also records a fleet-size gate on the agent's own Manager when CARLOS_FLEET is set in its environment (os.Getenv, beside the existing CARLOS_IMDS_FLAT_FENCE read). The gate's MemTotal closure reads /proc/meminfo through ReadMemTotal when a strict prepare is asked for a fleet size (#892 S2). It only lets the strict validators (PrepareStrict, PrepareGen, SetParentLimit) accept the new fleet rows within FleetMemoryBudget; without CARLOS_FLEET they take small..xlarge and today's parents exactly as before. Reads added: env CARLOS_FLEET; /proc/meminfo (kernel, fixed path) via the closure file:ReadFile@73 1c2d963c219576573ba11b9b1ba07c3823902b850615a93406f6cfc3c78065cb |
| +internal/instancectl/gen.go Server.handleParent legacy accepted-legacy accepted-legacy;rev3=J2,J4;basis=root-input;rev3=census-ruling-instance-egress-sizes-328-329;basis=#329 plan 3 Task 5: holds the host's slice lock (lockSliceWrites) around its one set-property, so /parent and /size never interleave on one slice. Its one site is still r.URL.Query() of the agent's request (counted as file:Query). The checks in this body are unchanged, though cgroup.ValidParentLimit, which it calls, now accepts one size or the sum of any two from the four-row table (up to 4 GiB, was 2 GiB); no read added.;rev3=census-ruling-agent-start-demo-1;basis=Reads fixed DemoBox and clamps the existing parent memory writer to small.;rev3=census-ruling-gvisor-demos;basis=Validate logical parent input as before, require the demo route in gVisor mode and apply Physical once to the small demo parent. Existing request query read unchanged; shares stay logical.;rev3=census-ruling-stateless-scale-2-fleet-sizes;basis=root: after the unchanged ValidParentLimit check, a parent outside today's shared set (one or two of small..xlarge) must also pass Server.Fleet.ParentAllowed: CARLOS_FLEET in root's host.env, not a gVisor box, readable MemTotal, and the whole overlap within max(0, MemTotal - max(1 GiB, MemTotal/8)), else 400 before any write. Today's parent set is accepted unchanged on every box. Same one site (r.URL.Query of the agent's request); no read added in this body (MemTotal is read by hostMemTotal through the gate) file:Query@78 2825f7708356c107eb3960e76865ce24eac36e23529374f1a4e78fb4e46b45df |
| +internal/instancectl/server.go runWithClaim authority C,D,G Claim instance controller adds held-release RPC dispatch within existing launch/participation execution boundary.;rev3=census-ruling-rootfs-apps-2;basis=takes a RegistryView (HostApp and HostRuntime) for the bare hostApp, and the production Server literal gains HostRuntime, ProbeImage: BuildProbeImage, ProbeImageFile: ProbeImagePath, RootfsProbeOut under /run/carlos-control and DenyEvery: 10s; this body reads nothing new itself; the readers it wires (instanceRegistryHostRuntime, BuildProbeImage, the rootfs probe's output) are decision rows;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Task 4 and #329 plan 3 Task 5: takes the egress asserter as a parameter, sets it on the production Server literal (Egress) and starts its 30 s Loop beside probeLoop and diskLoop; the literal also names the fixture check ProbeFixturesOK (renamed in plan 2 Task 14). It sets no control drop-in directory: plan 3's ControlDropInDir default (/run/systemd/system.control) was deleted with removeGenControlDropIn in ef38e13b (the P1 EROFS fix), so instance control names systemd's control directory only to read it (TrustedDropinReader). The same four sites (the two exec.CommandContext closures, statfsBytes, the data literal), offsets moved; no read added.;rev3=census-ruling-agent-start-demo-1;basis=Wires root-owned demo config and existing fixed paths into the service.;rev3=census-ruling-region-ha-p3b;basis=Resume root-owned hairpin state before probes/control service work; verify current systemd agent identity and kernel fence/addresses, restore pidfd watch or revoke stale state. Same direct exec/statfs/data sites; indirect inputs are protected root snapshot/state and kernel evidence, never receipt data.;rev3=census-ruling-agent-start-demo-3;basis=Construct the demo snapshot supervisor for configured demo boxes; startup cleanup gates builder readiness. Census read-site delta: unchanged (4).;rev3=census-ruling-gvisor-demos;basis=Retain sandbox modes and error; bind host-provided baseline and runtime callbacks without importing host templates. Existing reads unchanged. Task 6: Capture HostClaims once from ControlConfig/hostwrite.Enabled and set the fixed root-owned bundle discovery directory. Existing command and configuration reads unchanged. Task 7: enable gVisor worker construction through fixed unitFamily(roleBuild); readiness proof rechecks sandbox admission and current Ready without reaching the constructor fatal path for transient refusals. Existing command/config reads unchanged. Final R1 P2: wire the fixed /var/lib/carlos/oci-rootfs parent for native readiness evidence; no request-supplied path. Carry the root-only host.env validation callback into Ready; no agent read or caller-selected path.;rev3=census-ruling-same-box-edge-fence;basis=Root. Sets NFT: edgefence.Exec (runs /usr/sbin/nft from PATH with fixed arguments and root-derived stdin, see the envelope) and EdgeFenceOff from os.Getenv; wraps s.Systemctl with guardStarts and calls bindEgressFence; calls denyLocalAddrs once before Serve so a leftover runtime exemption is checked or replaced by the whole deny before any request is served. No new file read; the exec is nft's.;rev3=census-ruling-bounded-systemctl;basis=the production Systemctl closure runs through internal/systemd.Command (same args, combined output, caller ctx; mutations no deadline of their own, queries also QueryTimeout); the new Journal closure runs journalctl through internal/systemd.Command(Journalctl) for the gVisor probe diagnostic only, with the arguments that closure used to pass to Run; no new read, path or input;rev3=census-ruling-stateless-scale-2-fleet-sizes;basis=root: the production Server literal gains Fleet: productionFleetGate(os.Getenv), which is Fleet = CARLOS_FLEET set in carlos-instance-control.service's environment (EnvironmentFile /etc/carlos/host.env, root-owned, the same way EdgeFenceOff reads CARLOS_EDGE_FENCE) and MemTotal = hostMemTotal (/proc/meminfo through cgroup.ReadMemTotal, read only when a fleet size is asked for). Reads added: env CARLOS_FLEET; /proc/meminfo (kernel, fixed path, via the gate) data-literal@2897,file:Command@1151,file:Command@1333,file:CommandContext@1512,file:Exec@2713,file:Statfs@2918 61686631222d6594e5d77e1864201ca08bf664d9f4827c852b620849e1556ff7 |
| +internal/instancectl/server.go type Server legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=Re-digested at the pre-land merge: the body includes main's own change under census ruling 292, with no further change from this branch. Census ruling 292 reclassified this declaration accepted-legacy (J2,J4) for root's per-host ordering of legacy run starts against stops; this ruling kept the row as main classed it. Its own addition is the cmd start's poll and wait bounds and its per-host lock map: field declarations only;rev3=census-ruling-rootfs-apps-2;basis=new fields: HostRuntime, ProbeImage, ProbeImageFile, RootfsProbeOut, DenyEvery, the deny's lastDeny and denyMu, the rootfs probe's report and lock, the jit reload counters and imageDigests; genStarting counts binary generation starts per unit; rootfsLocksMu and rootfsLocks, one lock entry per rootfs unit name being started or removed right now, held by a start from its layout through systemctl start and its own cleanup and by a removal from its proof through the raw removal, a removal refusing while it is taken, a waiting start giving up when its request ends, an entry dropped with its last holder or waiter (fixes E6, L2, L3); rootfsProvenHook, a test hook run between the proof and the raw removal; field declarations only; no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 and #329 plan 3 Task 5: the declaration gains sliceLocks (one mutex per host slice, taken by /size and /parent) and Egress (the asserter every start path calls), and its comment names the egress allow (plan 3's ControlDropInDir field was deleted in ef38e13b, the P1 EROFS fix); the same one site, the Statfs field, offset moved; no read added.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 6: comments only: the one-shot pacing fields cover /cmd and /tty, and cmdLocks is now keyed by (role, host) (oneShotKey, PF-7) so a session's start never waits behind a command's; field declarations unchanged; the same one site, no read added;rev3=census-ruling-agent-start-demo-1;basis=Adds fixed demo configuration, registry views, derived runtime root, synchronization and purge guard.;rev3=census-ruling-region-ha-p3b;basis=Add hairpinActive boolean alongside lastDeny under existing deny synchronization. Field declaration only; existing Statfs selector unchanged, no new read or externally supplied authority.;rev3=census-ruling-region-ha-p3b2-rolls;basis=adds one field holding the current hairpin exit watcher, guarded by the root hairpin flock; no new read;rev3=census-ruling-agent-start-demo-3;basis=Retain the snapshot supervisor in instance-control state; no new request-selected path. Census read-site delta: unchanged (1).;rev3=census-ruling-gvisor-demos;basis=Retain Task 1 mode/error/readiness fields, baseline/runtime callbacks, Task 4 per-host validated staged descriptors and root-selected probe nonce. Fix round 1 adds a private writer-operation seam assigned only in package tests, after the unchanged GVisorID admission check; production defaults still call the same checked constructor, WriteRootfs, WriteBundle and verifier. No new direct read or request-controlled callback. Task 5: private injected removal seam for unprivileged tests; production default removes only root-derived bundle and skeleton after both-family proof inside existing start fence. No new request field or agent-selected unit. Task 6: Retain serialized probe nonce, runtime-set identity verifier/token, fixed claims flag, bundle discovery root, and private unprivileged identity seam. No request-controlled callback or path; existing declaration read-site classification unchanged. Task 6 fix round 1: private gvisorProbeTestOps is set only in package tests; production defaults retain all fixed paths and the checked root output opener. No externally supplied callback or new direct read. Final R1 P2: retain fixed skeleton parent and concurrent per-instance cleanup refusals; no direct read or external configuration field. Carry the root-only host.env validation callback into Ready; no agent read or caller-selected path.;rev3=census-ruling-same-box-edge-fence;basis=Field declarations only: NFT (the nft runner; nil never loads the fence), EdgeFenceOff (host.env CARLOS_EDGE_FENCE=off), and under the existing denyMu/mu: fenceAddrs, fenceReason, fenceRetry, denyApplied. No read added.;rev3=census-ruling-bounded-systemctl;basis=new field Journal, the journalctl seam for the gVisor probe's diagnostic; field declaration only; no read added;rev3=census-ruling-stateless-scale-2-fleet-sizes;basis=root: new field Fleet cgroup.FleetGate (#892 S2), root's fleet-size gate; field declaration only; no read added file:Statfs@5536 6187fe6aaa37d3e4740b72153fa648038ef9e2a3a998654234811be8c159bc8d |
| +internal/instancectl/size.go Server.handleSize legacy accepted-legacy accepted-legacy;rev3=census-ruling-instance-egress-sizes-328-329;identity=instance control (/opt/carlos/carlos instance-control, carlos-instance-control.service, root);basis=root-input (J2,J4, as Server.handleParent): new (#329 plan 3 Task 5): POST /size from the agent (the peer check admits only the edge unit's main process; claimAwareLegacy answers 503 with host claims on). Its one site is r.URL.Query() of that request (counted as file:Query): host must pass ValidHostShape, memory_max and gen are refused, size must name a row of cgroup.Sizes. Under the slice lock it runs systemctl set-property --runtime on SliceName(host) with that row's CPUWeight, CPUQuota and IOWeight, then writeSizeReadBack runs systemctl show of the slice and answers it. Root sets the slice's CPU and IO shares from the agent's choice among four platform rows; nothing from the request reaches systemctl as a string.;rev3=census-ruling-agent-start-demo-1;basis=Reads fixed DemoBox and clamps the existing live CPU/IO writer to small.;rev3=census-ruling-stateless-scale-2-fleet-sizes;basis=root: after the unchanged SizeByName check, the named row must pass Server.Fleet.GenAllowed (a shared size always; a fleet size only on a CARLOS_FLEET box, not gVisor, within the MemTotal budget), else 400 before any systemctl call. Same one site; no read added in this body file:Query@96 ef6d9da8f61aacd18fcfb6c19fe2113dde5414c97fab67de8d2e1ce5782273bb |
| +internal/cgroup/fleetgate.go ReadMemTotal legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-scale-2-fleet-sizes;basis=new: os.ReadFile of the path its caller names, then ParseMemTotal (the MemTotal line in kB, positive, bounded). Its callers pass the fixed /proc/meminfo only (instancectl hostMemTotal for root, the agent's cgroup setup closure); kernel-written, not writable by a tenant, app or agent. Used only to bound fleet sizes; an error refuses every fleet size file:ReadFile@59 00e5b8e25b9e3dbc9ee3e449ceaa22d283d69969dfc6582b2cfcdc74c07ef69e |
| +@coverage internal/apppolicy 0a758be8a30d847d27ff610736b668a526b8e5f47e6dcc042a8c143c25864295 |
| +@coverage internal/cgroup 18eb14bb51403da80ca35f8046278f79557a890d21527ec868a16b80d508e54f |
| +@coverage internal/host 3a3bc8cc219234ee5669caa1b041ef7596655cbd4ae6a2397ca9a55ecc15c353 |
| +@coverage internal/instancectl 495f63275f21b9652438d6f2105f0d5619c1f51459024b5407fc03cff0ff805d |