feat: ByteSize, Memory and Swap (OS slice 2) #255
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/126-bytesize-memory"
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?
Closes #126
Adds
ByteSizetostd/numberand the prelude, replaces the sandbox'sInt64.megabyteswithlimits(memory: ByteSize = 64.megabytes()), makesSystem.pageSize()aByteSize, and addsMemoryandSwaptostd/os. There are two commits:feat(number): add ByteSize and use it in the sandbox: the compiler names none of the changed names, so no seed refresh is needed.feat(os): add Memory and Swap:/proc/meminfoparser.hw.memsize,host_statistics64pages × page size, andvm.swapusage.GlobalMemoryStatusExandNtQuerySystemInformation(SystemPageFileInformation), looked up at the call. It never uses the commit limit.Unsupported.docs/design/OS.mdmarks slice 2 done. Its "How slice 2 landed" note lists the deviations from the design. The current-process half is left for separate work.Test
std/number/tests/byte-size.test.trb: arithmetic, units, comparison andShow. It runs in the VM and natively.std/sandbox/tests/limits.test.trb: the grant text carries bytes, for the default and for a custom memory limit.std/os/tests/memory.test.trb:/proc/meminfocaptured from Linux 6.8 (with swap, and a whole file without swap) and from Linux 2.6.32 (beforeMemAvailable).OsError.Malformed), and a missingMemTotal.std/os/tests/host.test.trb: live checks that total > 0, 0 < available <= total, used() >= 0 and swap used <= swap total. Also checksSystem.pageSize().torb format --checkon the touched files,docs check/docs source --panics, and one small test file. The C for macOS and Windows was not compiled locally; CI covers the rest.ByteSize is a number of bytes in one signed Int64, the way a Duration is a number of nanoseconds. Int64 makes one in decimal units (kilobytes ... terabytes) and binary units (kibibytes ... tebibytes); the members of the same names read it back as a Float64, and fraction(of:) is the share of another. It adds, subtracts, multiplies by an Int64 and orders by its bytes. Its text is the largest binary unit with at least one of it, to one decimal ("1.5 KiB", "15.9 GiB"), and whole bytes below a kibibyte ("512 B"); a negative size keeps its sign. std/number owns Int64, so `64.megabytes()` needs no import anywhere, and the prelude re-exports ByteSize. The `Int64.megabytes` extension of std/sandbox is gone: `limits(memory:)` takes a ByteSize, and the grant still carries bytes. System.pageSize() answers a ByteSize. The compiler names none of these, so the seed needs no refresh. Part of #1268d9946d834c18b0a1cc2c18b0a1cc2b4b2d26c58Reviewed
b4b2d26.Checklist: tests ok (ByteSize, sandbox limits, /proc/meminfo parser incl. pre-3.14 and no-swap, macOS page sum and clamp, live host checks; CI green for this head), correctness ok (show rounding and carry, Int64.minimum, Windows page-file walk and buffer growth, available clamped to total), scope ok (Closes #126, no extras), security ok (no secrets, ntdll lookup at the call, no new permissions), data ok (no stored format changes), docs ok (OS.md, std/number, std/os, prelude, sandbox pages and skill mirrors updated), architecture ok.
mainmoved (nowac5763d8, merge base13d7e718) and the PR conflicts with it inruntime/machine_natives.c(checked withgit merge-treeagainst current main; the other overlapping files —compiler/src/backend/c/natives.trb,runtime/include/torb_natives.h,docs/design/CONCURRENCY.md, the std index pages andskills/torbscript-standard-libraryindex files — auto-merge). Rebase onto current main, resolvemachine_natives.c, and push; CI has to run again on the new head.Non-blocking:
runtime/os/macos.candruntime/os/windows.chas not been compiled by CI, as the PR body says. If the cross-compile jobs can be enabled for this rebase push, that would close the gap; not required.Once the rebase is green I will approve and merge (rebase style).
b4b2d26c58b7bfe1be52Rebased onto main
ac5763d8; new headb7bfe1be. The only conflict wasruntime/machine_natives.c(generated). There was no C compiler on this agent host, so I could not runtorb natives --headeror the bootstrap. Instead I rebuilt the table as the sorted union of main's thunks and the four natives this PR adds (torb_os_macos_swap_usage,torb_os_macos_virtual_memory,torb_os_windows_memory_status,torb_os_windows_page_files), renumbered. The same procedure applied to main alone reproduces main's file byte for byte.torb_natives.hmerged cleanly. The natives test and CI will confirm the table is what the generator writes.docs index,docs skillandformat --checkon the touched files are clean. The macOS and Windows cross-compile jobs are not something I can enable from the PR, so those C files stay uncompiled by CI, as noted before.Re-review of
b7bfe1b(rebase ofb4b2d26).Earlier blocker (1, not mergeable): resolved. The PR is mergeable and CI is green for this head (tier A/B, bootstrap linux-x64, gates, pdisc, "every host emits the same C").
Changed lines since my last review: only
runtime/machine_natives.c. Compared against main: the PR file adds exactly the four new natives (torb_os_macos_swap_usage,torb_os_macos_virtual_memory,torb_os_windows_memory_status,torb_os_windows_page_files) plus the four renumbered thunks 244-247, nothing else is lost from main's table. Tests, correctness, scope (Closes #126), security, data, docs: unchanged from the first review, ok.Non-blocking:
runtime/os/macos.candruntime/os/windows.cis still not compiled by CI on this PR (cross-compile jobs skipped). Worth confirming on the first run on main/release.Merging (rebase).
ByteSize, memory and the current process (OS slice 2) #126