Report one memory total from sysinfo and meminfo - #300
Merged
Conversation
xalestar
force-pushed
the
meminfo-sysinfo-agree
branch
from
August 16, 2026 12:50
1005633 to
7bef252
Compare
sysinfo(2) caps totalram at a hardcoded 4094595072 bytes while
/proc/meminfo reports sysctl(HW_MEMSIZE), so the two surfaces describe
different machines: 3998628 kB against 25165824 kB on a 24 GiB host. A
guest that reads both subtracts one from the other. busybox free takes
total and free from sysinfo and buff/cache from /proc/meminfo and
computes used = total - free - cached; a Cached larger than the whole of
totalram wraps that subtraction, and free prints the total and a used of
18014398500886155 run together into a single 24-digit field:
Mem: 399862818014398500886155 257465 0 ...
Nothing outside sys.c reads the ceiling and no test pins it, so deleting
it is the shortest route to agreement: both surfaces take the total from
sys_guest_ram_bytes(), which is HW_MEMSIZE. That also retires the
proportional scaling the ceiling required, and a 64-bit overflow inside
it where scaling in bytes multiplied the host figure by the capped total
and left 64 bits once host free memory reached about 4.2 GiB. A guest
sizing a heap or a job count from MemTotal reads the machine it runs on
rather than a sixth of it.
Free has to be reported once as well: busybox subtracts sysinfo's
freeram rather than MemFree, and the two are separate host_statistics64
samples that drift against each other. sys_guest_ram_free() serves both
from the snapshot sysinfo reports.
The Mach counters do not partition. A purgeable page is also counted in
inactive, so free plus inactive plus purgeable can exceed physical
memory whatever the total is, and scaling or not scaling makes no
difference to that. proc_open_meminfo() clamps Cached against what
MemFree leaves, which is the invariant the guest's subtraction needs.
Cached gives up the precision rather than MemFree, since MemFree has to
keep matching freeram.
The test asserts the agreement rather than either number, since the
totals are host-dependent, and it runs in test-matrix against a real
kernel where both come from one si_meminfo() and agree by construction.
xalestar
force-pushed
the
meminfo-sysinfo-agree
branch
from
August 17, 2026 07:23
7bef252 to
e567706
Compare
Contributor
Author
|
The cap is cosmetic, so it is deleted rather than justified. Nothing outside The clamp stays, because it does not depend on the cap: the Mach counters double-count purgeable pages inside inactive, so free plus inactive plus purgeable can exceed physical memory whatever the total is derived from. Rebased onto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sysinfo(2) caps totalram at a hardcoded 4094595072 bytes while /proc/meminfo reports sysctl(HW_MEMSIZE), so the two surfaces describe different machines: 3998628 kB against 25165824 kB on a 24 GiB host.
A guest that reads both then subtracts one from the other. busybox
freetakes total and free from sysinfo and buff/cache from /proc/meminfo and computesused = total - free - cached; a Cached larger than the whole of totalram wraps that subtraction, andfreeprints the total and a used of 18014398505005547 run together into a single 24-digit field:To the question in the review: the ceiling is cosmetic. Nothing outside
sys.creads it, no test pins it, and no guest is known to choke on a large MemTotal, so this deletes it rather than keeping the machinery that services it. Both surfaces take the total fromsys_guest_ram_bytes(), which is HW_MEMSIZE. That retires the proportional scaling the ceiling required and the 64-bit overflow inside it, and a guest sizing a heap or a job count from MemTotal reads the machine it runs on rather than a sixth of it.Free is reported once as well, since busybox subtracts sysinfo's freeram rather than MemFree and the two were separate host_statistics64 samples that drift against each other.
sys_guest_ram_free()serves both from the snapshot sysinfo reports.Deleting the cap does not retire the clamp. The Mach counters do not partition: a purgeable page is also counted in inactive, so free plus inactive plus purgeable can exceed physical memory whatever the total is derived from.
proc_open_meminfo()clamps Cached against what MemFree leaves, which is the invariant the guest's subtraction actually needs. Cached gives up the precision rather than MemFree, since MemFree has to keep matching freeram.The test asserts the agreement rather than either number, since the totals are host-dependent, and it runs in test-matrix against a real kernel where the two surfaces come from one si_meminfo() and agree by construction.
With the change in place the reproducer above reports
and 25165824 - 282896 - 8355696 = 16527232, which is the used column.
The new assertion fails without the fix rather than passing vacuously. The same test binary run against a build of
maingivesVerified on an Apple Silicon host (Darwin 25.6, 24 GiB), on a branch rebased onto
mainat 3541d18. make check, make lint and the .ci/ format, newline and security checks all pass. The three test-matrix modes stay within their baselines with zero failures: elfuse-aarch64 252 passed, qemu-aarch64 231 passed, elfuse-x86_64 78 passed. test-sysinfo passes in both the elfuse-aarch64 and qemu-aarch64 columns, so the assertion holds against a real kernel as well.