From 64b8d81975c8868ad0a3b6bb414e9820dfb602df Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 11:27:27 +0200 Subject: [PATCH 1/4] =?UTF-8?q?test:=20reproduce=20#779=20=E2=80=94=20shut?= =?UTF-8?q?down=20devices=20retain=20RAM=20budget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/capacity/shutdown-ram.test.ts | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/core/capacity/shutdown-ram.test.ts diff --git a/src/core/capacity/shutdown-ram.test.ts b/src/core/capacity/shutdown-ram.test.ts new file mode 100644 index 000000000..9bdee0b2b --- /dev/null +++ b/src/core/capacity/shutdown-ram.test.ts @@ -0,0 +1,57 @@ +import { describe, expect, it } from "vitest"; + +import { FakeSystemStats } from "../../ports/index.js"; +import { CapacityCoordinator } from "./index.js"; +import { resourceStrategy } from "./testing.js"; + +const gibibyte = 1024 ** 3; + +function capacity(): CapacityCoordinator { + return new CapacityCoordinator( + resourceStrategy.create( + { + limits: { + android: { maxDevices: 8, maxRunning: 8 }, + ios: { maxDevices: 8, maxRunning: 8 }, + maxRunning: 16, + }, + ramBudget: { + androidBytesPerDevice: 4 * gibibyte, + iosBytesPerDevice: 3 * gibibyte, + iosSlimBytesPerDevice: gibibyte, + }, + }, + new FakeSystemStats({ cpuCount: 8, totalRamBytes: 12 * gibibyte }), + ), + ); +} + +describe("shutdown RAM accounting (#779 proposal)", () => { + it("releases shutdown devices' RAM for status, provisioning and slim boots", () => { + const devices = [ + { id: "ios-full", mode: "full" as const, platform: "ios" as const, state: "shutdown" }, + { id: "ios-slim", mode: "slim" as const, platform: "ios" as const, state: "shutdown" }, + { + id: "android-full", + mode: "full" as const, + platform: "android" as const, + state: "shutdown", + }, + ] as const; + const planned = { mode: "full" as const, platform: "ios" as const }; + expect(capacity().tryReserveProvisioning(planned, [])).toMatchObject({ ok: true }); + expect(capacity().tryReserveBoot(devices[1], [devices[1]])).toMatchObject({ ok: true }); + + expect.soft(capacity().runningCapacity(devices).global.running).toBe(0); + expect.soft(capacity().ramBudget(devices)).toEqual({ + limitBytes: 8 * gibibyte, + overLimit: false, + usedBytes: 0, + }); + for (const platform of ["ios", "android"] as const) { + expect.soft(capacity().atRamBudget(platform, devices), platform).toBe(false); + } + expect.soft(capacity().tryReserveProvisioning(planned, devices)).toMatchObject({ ok: true }); + expect.soft(capacity().tryReserveBoot(devices[1], devices)).toMatchObject({ ok: true }); + }); +}); From 64527f2b96772fb6edc7d95ff1557a27d12c4de3 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sat, 24 Oct 2026 21:57:15 +0200 Subject: [PATCH 2/4] fix(capacity): a shut-down device holds no RAM budget (#779) --- docs/CONFIGURATION.md | 14 ++++++++------ src/core/capacity/AGENTS.md | 8 ++++---- src/core/capacity/coordinator.test.ts | 2 +- src/core/capacity/coordinator.ts | 6 +++++- .../capacity/strategies/resource/index.test.ts | 15 ++++++++------- src/core/capacity/strategies/resource/index.ts | 12 +++++++----- src/core/capacity/strategy.ts | 6 +++--- src/leasing/create-leasing.test.ts | 12 ++++-------- 8 files changed, 40 insertions(+), 35 deletions(-) diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 056ef01ef..3ab5814ca 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -757,9 +757,11 @@ strategy's own options, so its shape depends on the strategy you selected. Device and running ceilings derived from the machine, with a RAM budget on top: a device is only created if its budgeted RAM still fits under the -machine's total, minus 4 GiB left for the OS. Each device that has booted +machine's total, minus 4 GiB left for the OS. Each device that holds RAM counts by its own mode, at the slim or the full size for its platform. A -device that has not booted yet counts at the full size. +device that has not booted yet counts at the full size. A shut-down device +counts nothing against the RAM budget (it still counts against +`maxDevices`), and booting it needs room for its full size. | Property | Description | Default | | ----------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------------------- | @@ -821,8 +823,8 @@ budget counts each one at the size of the mode it has: - **Every new device needs room for the full size.** A slim device boots full and is slimmed after, so it uses the full size until then. A device counts at the full size until it has booted, whatever mode it asked for. - Booting a shut-down slim device needs the same room; if there is none, it - stays shut down and a request for it waits. A slim size pays off once + Booting a shut-down device, slim or full, needs the same room, since a + shut-down device holds none; if there is none, it stays shut down and a request for it waits. A slim size pays off once devices have booted: in a budget that fits two full devices, with slim ones at half that size, three slim devices fit. - **A device counts by the mode it has, not the one it asked for.** A @@ -834,8 +836,8 @@ budget counts each one at the size of the mode it has: - **Over the limit.** Restarting with larger sizes than the devices were admitted under can put the use above the limit. `simlock status` then shows the RAM budget `(over limit)`. Until a device is deleted, no new - device is created, in either mode, and no shut-down slim device boots if - its slim size is smaller than the full size. + device is created, in either mode, and no shut-down device boots if its + full size does not fit. Releasing a lease does not lower the use, because the device still exists; idle devices are still handed out. - **Raise the limits with the slim size.** The device and running limits diff --git a/src/core/capacity/AGENTS.md b/src/core/capacity/AGENTS.md index e5a4c08bb..ef9124199 100644 --- a/src/core/capacity/AGENTS.md +++ b/src/core/capacity/AGENTS.md @@ -34,7 +34,7 @@ Callers: leasing's `AcquisitionPlanner`, the warm pool, `status.get`. Parent: [c - `tryReserveProvisioning(planned, devices)` — `canProvision`, then a running slot. Counts as a device and a running slot until released. - `tryReserveBoot(device, devices)` — `canBoot` (RAM first), then a running slot. The device - counts `full` in every decision until released. + counts `full` and no longer `shutdown` (so it holds RAM) in every decision until released. - Release is idempotent. Every take and release calls the observer. 6. **Read** — `runningCapacity` (running, reserved, max, `overLimit` per platform and global), `deviceLimit`, `ramBudget` (devices only, reservations left out), `atRamBudget(platform)`: would @@ -49,10 +49,10 @@ Callers: leasing's `AcquisitionPlanner`, the warm pool, `status.get`. Parent: [c **`resource`** (default). Limits from the machine, plus a RAM budget. -- Limit = `totalRamBytes` − 4 GiB. Used = sum over every device not `deleted` (shut down - included), each by platform and mode; a slim size left unset is the full size. +- Limit = `totalRamBytes` − 4 GiB. Used = sum over every device neither `deleted` nor + `shutdown`, each by platform and mode; a slim size left unset is the full size. - `canProvision`: device limit, then used + new device's size > limit → `ram-budget`. -- `canBoot`: extra = full size − own size; refused `ram-budget` when used + extra > limit. +- `canBoot`: extra = full size for a shut-down device (it holds none), else full size − own size; refused `ram-budget` when used + extra > limit. - Over the limit (sizes raised by a restart): every create and every boot that adds RAM is refused. Nothing is stopped or reclaimed for it. diff --git a/src/core/capacity/coordinator.test.ts b/src/core/capacity/coordinator.test.ts index f59f2212a..8bc27a57c 100644 --- a/src/core/capacity/coordinator.test.ts +++ b/src/core/capacity/coordinator.test.ts @@ -301,7 +301,7 @@ describe("CapacityCoordinator", () => { expect(capacity.ramBudget([slim, iosDevice("ready-1", "full", "ready")])).toEqual({ limitBytes: 8 * gibibyte, overLimit: false, - usedBytes: 4 * gibibyte, + usedBytes: 3 * gibibyte, }); }); diff --git a/src/core/capacity/coordinator.ts b/src/core/capacity/coordinator.ts index 190631342..ef19e5293 100644 --- a/src/core/capacity/coordinator.ts +++ b/src/core/capacity/coordinator.ts @@ -175,7 +175,11 @@ export class CapacityCoordinator { return [ ...devices.map((device) => device.id !== undefined && booting.has(device.id) - ? { ...device, mode: "full" as const } + ? { + ...device, + mode: "full" as const, + state: device.state === "shutdown" ? "booting" : device.state, + } : device, ), ...this.#provisioningReservations.map(asProvisioningDevice), diff --git a/src/core/capacity/strategies/resource/index.test.ts b/src/core/capacity/strategies/resource/index.test.ts index 451b99fde..5db8249a1 100644 --- a/src/core/capacity/strategies/resource/index.test.ts +++ b/src/core/capacity/strategies/resource/index.test.ts @@ -214,17 +214,18 @@ describe("resource strategy RAM budget by mode", () => { }); }); - it("never refuses booting a shut-down full device for RAM, even over the limit", () => { + it("charges booting a shut-down full device its whole size, refusing it only when that no longer fits", () => { const strategy = sized({ androidBytesPerDevice: 4 * gibibyte, iosBytesPerDevice: 3 * gibibyte, iosSlimBytesPerDevice: gibibyte, }); const shutdown = device("ios", "full", "shutdown"); - const over = [shutdown, device("ios", "full"), device("ios", "full")]; - expect(strategy.ramBudget(over)?.overLimit).toBe(true); - expect(strategy.canBoot(shutdown, over)).toEqual({ ok: true }); + expect(strategy.canBoot(shutdown, [shutdown, device("ios", "full")])).toEqual({ ok: true }); + expect( + strategy.canBoot(shutdown, [shutdown, device("ios", "full"), device("ios", "full")]), + ).toEqual({ ok: false, reason: "ram-budget" }); }); it("counts slim and full devices on both platforms at the sum of each device's own size", () => { @@ -262,7 +263,7 @@ describe("resource strategy RAM budget by mode", () => { }); }); - it("reports the limit as total RAM minus the reserve, use over non-deleted devices, and over only past the limit", () => { + it("reports the limit as total RAM minus the reserve, use over devices neither deleted nor shut down, and over only past the limit", () => { const strategy = sized({ androidBytesPerDevice: 4 * gibibyte, iosBytesPerDevice: 2 * gibibyte, @@ -277,9 +278,9 @@ describe("resource strategy RAM budget by mode", () => { expect(strategy.ramBudget(atLimit)).toEqual({ limitBytes: 8 * gibibyte, overLimit: false, - usedBytes: 8 * gibibyte, + usedBytes: 6 * gibibyte, }); - expect(strategy.ramBudget([...atLimit, device("ios", "slim")])).toEqual({ + expect(strategy.ramBudget([...atLimit, device("android", "full")])).toEqual({ limitBytes: 8 * gibibyte, overLimit: true, usedBytes: 10 * gibibyte, diff --git a/src/core/capacity/strategies/resource/index.ts b/src/core/capacity/strategies/resource/index.ts index d5cf1ff0f..5ede9d334 100644 --- a/src/core/capacity/strategies/resource/index.ts +++ b/src/core/capacity/strategies/resource/index.ts @@ -20,6 +20,8 @@ import { const GIBIBYTE = 1024 ** 3; const OS_RAM_RESERVE_BYTES = 4 * GIBIBYTE; +// why: a shut-down device holds no RAM, so it is the one state the budget leaves out. +const SHUTDOWN = "shutdown"; /** * Device and running ceilings derived from the machine, with a RAM budget gate @@ -60,8 +62,9 @@ class ResourceCapacityStrategy implements CapacityStrategy { } canBoot(device: CapacityDevice, devices: readonly CapacityDevice[]): CapacityDecision { + const fullBytes = this.#bytesPerDevice({ ...device, mode: "full" }); const extraBytes = - this.#bytesPerDevice({ ...device, mode: "full" }) - this.#bytesPerDevice(device); + device.state === SHUTDOWN ? fullBytes : fullBytes - this.#bytesPerDevice(device); if (extraBytes <= 0) return { ok: true }; return this.#usedBytes(devices) + extraBytes > this.#limitBytes() ? { ok: false, reason: "ram-budget" } @@ -98,10 +101,9 @@ class ResourceCapacityStrategy implements CapacityStrategy { } #usedBytes(devices: readonly CapacityDevice[]): number { - return activeDevices(devices).reduce( - (total, device) => total + this.#bytesPerDevice(device), - 0, - ); + return activeDevices(devices) + .filter((device) => device.state !== SHUTDOWN) + .reduce((total, device) => total + this.#bytesPerDevice(device), 0); } #bytesPerDevice({ platform, mode }: PlannedCapacityDevice): number { diff --git a/src/core/capacity/strategy.ts b/src/core/capacity/strategy.ts index df00539fb..c4503466a 100644 --- a/src/core/capacity/strategy.ts +++ b/src/core/capacity/strategy.ts @@ -71,9 +71,9 @@ export interface CapacityStrategy { canProvision(device: PlannedCapacityDevice, devices: readonly CapacityDevice[]): CapacityDecision; /** - * Whether the shut-down `device`, already among `devices`, may boot. A device - * boots at its platform's full size before any slim pass, so a boot needs room - * for the difference between that and the size the device counts at. + * why: Whether the shut-down `device`, already among `devices`, may boot. A device + * boots at its platform's full size before any slim pass. A shut-down device holds + * no RAM, so a boot needs room for that whole size; a running one needs the difference. */ canBoot(device: CapacityDevice, devices: readonly CapacityDevice[]): CapacityDecision; diff --git a/src/leasing/create-leasing.test.ts b/src/leasing/create-leasing.test.ts index 26639c96c..b010bb74a 100644 --- a/src/leasing/create-leasing.test.ts +++ b/src/leasing/create-leasing.test.ts @@ -1531,15 +1531,14 @@ describe("createLeasing RAM budget by mode", () => { rule: "test", target: toShutDown.device.id, }); - expect(before.engine.ramBudget?.usedBytes).toBe(1.5 * gibibyte); + expect(before.engine.ramBudget?.usedBytes).toBe(1 * gibibyte); - // Restarted at 2 GiB slim: the three slim devices use 6 GiB of 5. const after = await createHarness({ driver, state: before.state, idleShutdownAfterMs: 0, limits: roomy, - ramBudget: { ...ramBudget, iosSlimBytesPerDevice: 2 * gibibyte }, + ramBudget: { ...ramBudget, iosSlimBytesPerDevice: 3 * gibibyte }, totalRamBytes: 9 * gibibyte, }); await after.engine.convergeRunningCapacity(); @@ -1574,8 +1573,6 @@ describe("createLeasing RAM budget by mode", () => { expect(reused.device.id).toBe(idle.device.id); expect(after.registry.snapshot.leases.map((lease) => lease.deviceId)).toContain(held.device.id); - // A release lowers nothing; deleting both idle devices brings use to 2 GiB of 5, and a new - // device's 3 GiB fits again. await after.engine.release(reused.lease.id, "explicit"); await after.engine.settle(); expect(after.engine.ramBudget?.overLimit).toBe(true); @@ -1587,12 +1584,11 @@ describe("createLeasing RAM budget by mode", () => { await after.engine.cleanup.execute({ action, reason: "test", rule: "test", target }); } await after.engine.settle(); - // why: the pool keeps the kind the reused lease taught it: the one slim device it made takes the 2 GiB the deletes freed. - expect(operations(driver, "makeReady")).toBe(boots + 1); + expect(operations(driver, "makeReady")).toBe(boots); expect(after.engine.ramBudget).toEqual({ limitBytes: 5 * gibibyte, overLimit: false, - usedBytes: 4 * gibibyte, + usedBytes: 3 * gibibyte, }); }); }); From 83ac019ffa49d2745aad9dc16c414d93ffa604a8 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sat, 24 Oct 2026 22:00:43 +0200 Subject: [PATCH 3/4] docs: RAM budget excludes shut-down devices in CLI, HTTP API and schema comment (#779) --- docs/CLI.md | 6 +++--- docs/HTTP-API.md | 10 +++++----- src/contract/schemas.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/CLI.md b/docs/CLI.md index b8f18c63b..99453ba44 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -1662,11 +1662,11 @@ The RAM budget line appears only under the `resource` capacity strategy (see [CONFIGURATION.md](CONFIGURATION.md#capacity-strategies)); under `fixed` there is none. In `--json` it is `capacity.ramBudget`: `limitBytes` (the machine's RAM minus 4 GiB left for the OS), `usedBytes` -(the sizes of every listed device that is not deleted, each by its mode) and +(the sizes of every listed device that is neither deleted nor shut down, each by its mode) and `overLimit`. The line reads `(over limit)` when the use is past the limit, for example after a restart with larger per-device sizes; until a device -is deleted, none is created, and no shut-down slim device boots if its slim -size is smaller than the full size. +is deleted, none is created, and no shut-down device boots if its full size +does not fit. Against a **gateway** (`simlock --gateway status`) the same command answers for the whole fleet, in the same shape: the daemon line reads diff --git a/docs/HTTP-API.md b/docs/HTTP-API.md index 04d6f2d93..2a340fbe3 100644 --- a/docs/HTTP-API.md +++ b/docs/HTTP-API.md @@ -292,11 +292,11 @@ RAM budget; under `fixed` the field is absent: ``` `limitBytes` is the machine's RAM minus 4 GiB left for the OS. `usedBytes` is -the sum over every listed device that is not deleted, each at the size of the -mode it reports, so it always matches the device list. `overLimit` is true -when the use exceeds the limit, for example after a restart with larger -per-device sizes; until a device is deleted, none is created, and no -shut-down slim device boots if its slim size is smaller than the full size. +the sum over every listed device that is neither deleted nor shut down, each +at the size of the mode it reports. `overLimit` is true when the use exceeds +the limit, for example after a restart with larger per-device sizes; until a +device is deleted, none is created, and no shut-down device boots if its full +size does not fit. Each platform's capacity entry (`capacity.ios`, `capacity.android`) also carries **`atRamBudget`**, always present: `true` when creating one more full diff --git a/src/contract/schemas.ts b/src/contract/schemas.ts index 148a03e1b..a8048a814 100644 --- a/src/contract/schemas.ts +++ b/src/contract/schemas.ts @@ -505,8 +505,8 @@ export const statusCapacitySchema = z.object({ ios: platformCapacityEntrySchema, android: platformCapacityEntrySchema, global: runningCapacityEntrySchema.extend({ warm: z.number() }), - /** Present only under a strategy that keeps a RAM budget. `usedBytes` counts every - * non-deleted device by the mode it reports, without in-flight provisioning. */ + /** why: present only under a strategy that keeps a RAM budget. `usedBytes` counts every + * device neither deleted nor shut down, by the mode it reports, without in-flight provisioning. */ ramBudget: z .object({ limitBytes: z.number().finite(), From 4c1ffee118e2557c114e709a64281a552e478730 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sat, 24 Oct 2026 22:11:57 +0200 Subject: [PATCH 4/4] docs: RAM wording and test comments match shut-down devices holding no budget (#779) --- src/core/capacity/coordinator.test.ts | 6 +++--- src/core/capacity/strategies/resource/index.test.ts | 4 ++-- src/leasing/acquisition-planner.test.ts | 6 +++--- src/leasing/acquisition-planner.ts | 2 +- src/leasing/create-leasing.test.ts | 2 +- website/src/content/docs/docs/worker/capacity.mdx | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/core/capacity/coordinator.test.ts b/src/core/capacity/coordinator.test.ts index 8bc27a57c..267487f9d 100644 --- a/src/core/capacity/coordinator.test.ts +++ b/src/core/capacity/coordinator.test.ts @@ -211,7 +211,7 @@ describe("CapacityCoordinator", () => { ), ); const slim = iosDevice("slim-1", "slim", "shutdown"); - // 8 GiB used of 8, and the one iOS running slot taken: both would refuse; RAM is named. + // why: 7 GiB used of 8, the boot would add 3 GiB, and the one iOS running slot taken: both would refuse; RAM is named. const devices: CapacityDevice[] = [ slim, iosDevice("ready-1", "full", "ready"), @@ -224,7 +224,7 @@ describe("CapacityCoordinator", () => { it("holds a boot's extra size until the boot reservation is released", () => { const capacity = sizedCoordinator(); const slim = iosDevice("slim-1", "slim", "shutdown"); - // 5 GiB used of 8: booting the slim device adds 2 GiB, leaving 1. + // why: 4 GiB used of 8: booting the shut-down slim device adds its full 3 GiB, leaving 1. const devices = [ slim, iosDevice("ready-1", "full", "ready"), @@ -233,7 +233,7 @@ describe("CapacityCoordinator", () => { const boot = capacity.tryReserveBoot(slim, devices); if (!boot.ok) throw new Error("expected a boot reservation"); - // 7 GiB counted: no room for a new device's 3 GiB, nor for a second slim boot's 2 GiB. + // why: 7 GiB counted: no room for a new device's 3 GiB, nor for a second slim boot's 3 GiB. expect(capacity.tryReserveProvisioning({ mode: "full", platform: "ios" }, devices)).toEqual({ ok: false, reason: "ram-budget", diff --git a/src/core/capacity/strategies/resource/index.test.ts b/src/core/capacity/strategies/resource/index.test.ts index 5db8249a1..033920a2f 100644 --- a/src/core/capacity/strategies/resource/index.test.ts +++ b/src/core/capacity/strategies/resource/index.test.ts @@ -204,10 +204,10 @@ describe("resource strategy RAM budget by mode", () => { iosSlimBytesPerDevice: gibibyte, }); const shutdown = device("ios", "slim", "shutdown"); - // 7 GiB used of 8: booting adds the 1 GiB between the slim and the full size. + // why: 6 GiB used of 8 (the shut-down device holds none): booting adds its full 2 GiB. const fits = [shutdown, device("ios", "full"), device("ios", "full"), device("ios", "full")]; expect(strategy.canBoot(shutdown, fits)).toEqual({ ok: true }); - // 8 GiB used: the same boot would reach 9. + // why: 7 GiB used: the same boot would reach 9. expect(strategy.canBoot(shutdown, [...fits, device("ios", "slim")])).toEqual({ ok: false, reason: "ram-budget", diff --git a/src/leasing/acquisition-planner.test.ts b/src/leasing/acquisition-planner.test.ts index dfae71702..be18e53c3 100644 --- a/src/leasing/acquisition-planner.test.ts +++ b/src/leasing/acquisition-planner.test.ts @@ -369,7 +369,7 @@ describe("AcquisitionPlanner", () => { }; const leases = [leaseOn(android)]; - // 6 GiB used of 8: the boot adds the 2.5 GiB between the slim and the full size. + // why: 5 GiB used of 8: the boot adds the shut-down device's full 3.5 GiB. const devices = [android, idleOther, shutdownSlim]; expect(plan(acquisitionPlanner, devices, { leases, spec: slimSpec })).toEqual({ kind: "wait", @@ -382,12 +382,12 @@ describe("AcquisitionPlanner", () => { expect(claims.isClaimed(idleOther.id)).toBe(false); expect(claims.isClaimed(shutdownSlim.id)).toBe(false); - // Without the idle device, 5 GiB is used and the boot fits. + // why: Without the idle device, 4 GiB is used and the boot fits. const boot = plan(acquisitionPlanner, [android, shutdownSlim], { leases, spec: slimSpec }); expect(boot).toMatchObject({ device: shutdownSlim, kind: "boot-shutdown" }); }); - it("evicts an idle slim device for a full request at the device limit, then waits when the freed RAM is not enough", () => { + it("evicts an idle shut-down slim device for a full request at the device limit, then waits when the RAM is still not enough", () => { const { planner: acquisitionPlanner } = sizedPlanner(2); const android = device("android", "leased", { physical: false, diff --git a/src/leasing/acquisition-planner.ts b/src/leasing/acquisition-planner.ts index 48bc0f93a..1be60b5b4 100644 --- a/src/leasing/acquisition-planner.ts +++ b/src/leasing/acquisition-planner.ts @@ -172,7 +172,7 @@ export class AcquisitionPlanner { } #planShutdownBoot(input: AcquisitionPlannerInput, device: VirtualDevice): AcquisitionPlan { - // A boot refused for RAM evicts nothing: freeing a running slot frees no RAM. + // why: only a running-limit refusal picks a victim (#runningVictim); a RAM-budget refusal waits. const running = this.capacity.tryReserveBoot( capacityDevice(device), capacityDevices(input.snapshot.virtualDevices), diff --git a/src/leasing/create-leasing.test.ts b/src/leasing/create-leasing.test.ts index f63f40cdf..33f39208e 100644 --- a/src/leasing/create-leasing.test.ts +++ b/src/leasing/create-leasing.test.ts @@ -1497,7 +1497,7 @@ describe("createLeasing RAM budget by mode", () => { }); }); - it("over its limit after a restart with larger sizes, creates no device in either mode and boots no shut-down slim device, but grants an idle one; a delete brings it back under", async () => { + it("over its limit after a restart with larger sizes, creates no device in either mode and boots no shut-down slim device, but grants an idle one; shutting the idle one down brings it back under", async () => { const clock = new FakeClock(1_000); const driver = new FakeDriver({ knownModels: ["iPhone 16", "iPhone 16 Pro"], diff --git a/website/src/content/docs/docs/worker/capacity.mdx b/website/src/content/docs/docs/worker/capacity.mdx index dbe11259d..46712a42e 100644 --- a/website/src/content/docs/docs/worker/capacity.mdx +++ b/website/src/content/docs/docs/worker/capacity.mdx @@ -50,7 +50,7 @@ A lease request that needs a new device or a boot does this, in order: 5. At a running limit, it shuts down an idle booted device to make room. 6. Otherwise it waits in the queue until a device frees up. With `--no-wait` it fails with `NO_CAPACITY` instead. -A leased device is never shut down or deleted to make room. When the RAM budget is what blocks a request, Simlock does not shut anything down, because a shut-down device holds no RAM and does not count against the budget, but booting it needs room for its full size. The request waits until a device is deleted. +A leased device is never shut down or deleted to make room. When the RAM budget is what blocks a request, Simlock shuts nothing down for it: only a running limit makes it shut down an idle device. The request waits until enough RAM is free, for example when an idle device shuts down on its own or a device is deleted. ## Size by the machine: the `resource` strategy @@ -150,7 +150,7 @@ To fit more slim simulators in the RAM budget, give them a smaller size: - A device counts at the full size until it has booted, because a slim device boots full first. Creating any device needs room for the full size. - After it boots, a device counts by the mode it has. A slim request that got a full device counts as full. - Booting a shut-down device, slim or full, needs room for its full size, since a shut-down device holds none. If there is none, it stays shut down and the request waits. -- If you restart with larger sizes than the devices were created under, the budget can show `(over limit)`. Until a device is deleted, no new device is created and no shut-down device boots if its full size does not fit. +- If you restart with larger sizes than the devices were created under, the budget can show `(over limit)`. Until enough RAM is free, no new device is created and no shut-down device boots if its full size does not fit. ## Keep devices booted: the warm pool