Split from #12092 (review of #12236). Measured 2026-11-13: inside a 512 MiB limit, /api/v1/health reported the host's memory (os.totalmem()), and /system said "80 cores".
What should be true: vitals().memory reports memoryLimitBytes() (the cgroup's memory.max where set) as the total, and free as at most the limit less this process's resident memory.
Done when: a test shows vitals().memory.hostTotalBytes equals memoryLimitBytes(), and the cores shown read the cgroup's cpu.max where set.
A patch that did the memory half on the #12092 branch (commit c99b2dc66):
diff --git a/src/kernel/vitals.ts b/src/kernel/vitals.tsindex 2afe693a6..ca668371b 100644--- a/src/kernel/vitals.ts+++ b/src/kernel/vitals.ts@@ -13,7 +13,7 @@ import { statSync } from "node:fs";
import { readDisk, type DiskReading } from "./disk_reading.ts";
import { DISK_FLOOR, roomy } from "../spawn/disk_floor.ts";
import { dirname } from "node:path";
-import { freemem, totalmem } from "node:os";+import { freemem } from "node:os";
import { refusedInternal, type RefusedLedger } from "./internal_refused.ts";
import { recentErrors, redactSecrets, type ErrorLedger, type ErrorLine } from "./log.ts";
import {
@@ -39,7 +39,7 @@ import { running as runningVersion } from "./version.ts";
import { rollbackNeed } from "../release/launch.ts";
import { behindStanding } from "../release/behind.ts";
import { newestDrills } from "../core/domain_drills.ts";
-import { capacityValue } from "../core/capacity.ts";+import { capacityValue, memoryLimitBytes } from "../core/capacity.ts";
import { unwrittenFor, SILENT_AFTER_S } from "../http/access_log.ts";
import { DOMAINS } from "./domains.ts";
import { domainDrillNeeds } from "./domain_drill.ts";
@@ -319,6 +319,16 @@ export function laneSentence(
return `${head}; the longest running is ${name(longest)} at ${minutes(longest)} min (limit ${BUDGETS.gate / 60_000})${more}.`;
}
+/**+ * This process's memory beside the pod's own limit where one is set: a forge in 512 MiB+ * is not on a 64 GiB host (#12092).+ */+export function memoryReading(): Vitals["memory"] {+ const rssBytes = process.memoryUsage().rss;+ const limit = memoryLimitBytes();+ return { rssBytes, hostFreeBytes: Math.min(freemem(), Math.max(0, limit - rssBytes)), hostTotalBytes: limit };+}+
export function vitals(input: VitalsInput): Vitals {
const now = input.now ?? Date.now();
const at = new Date(now).toISOString();
@@ -603,11 +613,7 @@ export function vitals(input: VitalsInput): Vitals {
needs,
degraded,
disk,
- memory: {- rssBytes: process.memoryUsage().rss,- hostFreeBytes: freemem(),- hostTotalBytes: totalmem(),- },+ memory: memoryReading(),
queue,
lane,
stuck,
Split from #12092 (review of #12236). Measured 2026-11-13: inside a 512 MiB limit, /api/v1/health reported the host's memory (
os.totalmem()), and /system said "80 cores".What should be true:
vitals().memoryreportsmemoryLimitBytes()(the cgroup'smemory.maxwhere set) as the total, and free as at most the limit less this process's resident memory.Done when: a test shows
vitals().memory.hostTotalBytesequalsmemoryLimitBytes(), and the cores shown read the cgroup'scpu.maxwhere set.A patch that did the memory half on the #12092 branch (commit c99b2dc66):