os: ByteSize, memory and the current process (OS slice 2) #126
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
Add
ByteSize(a count of bytes with a unit) tostd/numberand the prelude, make the sandbox use it, and addMemoryandSwaptostd/os. The current-process half of OS slice 2 is split into #251 and #252.Source
ByteSizemegabytesmegabytes()moves" (same move, wanted by the resources budget)Current state on main (
9889e8f998db8d4289b23fe9ce9441607e986c2e)ByteSize,Memory,Swapdo not exist anywhere in code.std/number/src/lib.trbhas no byte unit; the prelude re-exportsDurationfromstd/timebut nothing for bytes.std/sandbox/src/lib.trbhasextend Int64 { fn megabytes(): Self }(10^6) andlimits(steps: Int, memory: Int = 64.megabytes(), ...); the fieldmemoryLimit: Intis written into the grant text. Docs and one explanation page tell users touse Int64.megabytes from "std/sandbox".System.pageSize(): Intinstd/os/src/system.trb(comment in OS.md: it becomes aByteSizein this slice); test instd/os/tests/host.test.trb.std/os/src/<system>/halves exist for windows, linux, macos, posix, bsd, freebsd, browser;runtime/os/{windows,linux,posix,macos,bsd,freebsd}.chold the natives; no memory native yet.Decisions taken by the loop
ByteSizeis a record over one privateInt64exactly as OS.md specifies (traitsShow, Compare, Add, Subtract, Multiply<Int64, ByteSize>,EqualsthroughCompareasDurationdoes),show()in binary units to one decimal (owner-answered in OS.md section 12).Int64.megabyteswould be ambiguous, which is the argument of OS.md section 6.limits(memory:)takes aByteSizeand the internalmemoryLimitstays anIntof bytes (the grant text is unchanged)..FreeBsdand.BrowseranswerFail OsError.Unsupporteduntil the FreeBSD slice (the other slices' pattern); no new case needs a design decision.Acceptance criteria
ByteSize(std/number, prelude, no import needed):64.megabytes().bytes() == 64_000_000,1.mebibytes().bytes() == 1_048_576, every unit of both families onInt64and every reader (kilobytes() ... tebibytes(),fraction(of:)); sums, differences andByteSize * Int64work; a difference may be negative; comparison orders by bytes.show():512 B,1.5 KiB(1536),15.9 GiB,0 B, and a negative size keeps its sign; the boundary 1023 B / 1024 B is tested.--native, platform independent (pure arithmetic).Int64.megabytes() : Int64is gone fromstd/sandbox;SandboxCapabilities.limits(memory: ByteSize = 64.megabytes()); the grant text still carries the byte count (a test reads the default and a custom value); every64.megabytes()in docs, tests, CONCEPT and examples follows;use Int64.megabytes from "std/sandbox"is removed from the-sandbox.md and mistakes-models-make.md.System.pageSize(): ByteSizeand its test follow.Memory,Swap(std/os/src/memory.trb, exported fromstd/os),Memory.current(): Result<Memory, OsError>,used() = total - available,Swap.free():/proc/meminfoparser (pure, tested with captured files incl. a pre-3.14 file withoutMemAvailable, a file without swap, a malformed line ->OsError.Malformed); a live test:total > 0,0 < available <= total,used() >= 0, swap used <= swap total.hw.memsize,host_statistics64pages (free, inactive, speculative, purgeable) times the page size,vm.swapusage; the same live assertions.GlobalMemoryStatusExand the page files fromNtQuerySystemInformation(SystemPageFileInformation)(looked up at the call, as slice 1 does for its Windows natives, so no build names a new library), never the commit limit; the same live assertions.Unsupported;torb check --every-target std/oslowers every program and test on all targets (it is a gate oftools/gates.sh a).availableis each system's own estimate and whyused()is derived (OS.md pitfall).docs/standard-library/number.md,os.md,sandbox.mdand the prelude page updated,skills/regenerated (docs skill --checkis a tier A gate); OS.md slice 2 marked done with a short "How slice 2 landed" note, and the status line at its top names slices 0 to 2 (the current-process part marked as moved to #251 and #252 and not done until they close).TORB_RUNNERS) and otherwise through the portable workflow on the mirror after landing; the live Memory tests only run on a machine of their system, and the pure parser tests on all of them. The FreeBSD and browser arms are covered bycheck --every-targetonly.Seed
None. The compiler does not use
ByteSize,Memoryor a std name looked up by string (checked: nothing for it insemantics/checker/wellknown.trb; nomegabytescaller incompiler/src), so the seed compiles the new std as it is. New natives are not used by the compiler itself, so they do not take the two-commit rule. If implementation finds the compiler importinglimits(memory:), split into two commits: addByteSizeand teach the sandbox both forms, then remove theInt64form.Size
One PR, two Conventional Commits:
feat(number): add ByteSize and use it in the sandbox(criteria 1 to 3), thenfeat(os): add Memory and Swap(criterion 4 and docs). The current-process half is split out: #251 (identity, executable, working directory, uptime; takes the seed two-commit rule) and #252 (resources, processors, memory limit).Dependencies
OS slice 1 (done). #252 depends on this issue (
ByteSize) and on #251.std/networkaddresses and network interfaces (OS slice 5) #129[loop:torbscript] intake: in scope (author orion, label loop), source OS.md slice 2, not a duplicate. No dependencies; needs every supported system. next: waiting (refine queued, ready buffer full) until 2026-10-10T04:00:00Z
std/networkaddresses and network interfaces (OS slice 5) #129[loop:torbscript] claim refine by session:loop-torbscript-20261009 until 2026-10-09T08:14Z
CurrentProcessidentity, executable and working directory (OS slice 2, part 2) #251CurrentProcessresources, processors and memory limit (OS slice 2, part 3) #252[loop:torbscript] refine: rewrote the body to goal, pinned sources, state on main, per-platform acceptance criteria (CI coverage per target), seed impact, size and dependencies. The current-process half of slice 2 was too large for this PR and is split into #251 (identity, executable move with the seed two-commit rule, working directory, uptime) and #252 (resources, processors, memory limit); this issue keeps
ByteSize, the sandbox change,System.pageSizeandMemory/Swap.[loop:torbscript] decided by the loop: (1) the sandbox's
Int64.megabytesis removed without a shim, because two members of one name onInt64would be ambiguous (OS.md section 6 already specifies it; the sandbox natives are planned, so no behaviour changes). (2)Memoryon FreeBSD and the browser answersUnsupporteduntil the FreeBSD slice, as the other slices do. (3) No seed refresh: the compiler uses none of the new names; the executable move, which it does use, is in #251. (4) Parsers are pure and tested with captured text on every machine; live tests only on their own system.next: implement
[loop:torbscript] claim implement by session:loop-torbscript-20261009 until 2026-10-09T12:17Z
[loop:torbscript] close: PR #255 (ByteSize and Memory) merged by argus (merge commit
319caaf8), issue closed. Claim released. Follow-ups #251 and #252 are unblocked.CurrentProcessidentity, executable and working directory (OS slice 2, part 2) #251CurrentProcessresources, processors and memory limit (OS slice 2, part 3) #252CurrentProcessresources, processors and memory limit (OS slice 2, part 3) #252SubnetandMacAddress(step 1 of #129, OS slice 5) #528std/networkaddresses and network interfaces (OS slice 5) #129