fix accounting + report real macOS memory pressure (-P)#11
Merged
Conversation
…ting - shared: stop reporting the memory compressor as "shared" (semantically wrong); macOS exposes no system-wide shared-memory counter, so report 0 - buff/cache & available: include speculative (read-ahead) pages that were previously omitted, tightening the total = used + free + buff/cache identity - add -P/--pressure: prints the real kernel signal (kern.memorystatus_vm_pressure_level, the same one Activity Monitor uses), since macOS compresses in-RAM before swapping and the Linux-style columns cannot reveal pressure - update README to match the new behavior Signed-off-by: Andre Nogueira <aanogueira@protonmail.com>
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.
Summary
Fixes two memory-accounting bugs and adds an opt-in flag that surfaces the real macOS memory-pressure signal.
Bug fixes
sharedno longer misreports the compressor. It was printingcompressor_page_countin thesharedcolumn — semantically wrong (Linuxshared=Shmem, not compressed anonymous memory). macOS exposes no cheap system-wide shared-memory counter, so we now report0(honest placeholder) rather than a misleading value.speculativepages are now counted.speculative_count(read-ahead file cache) was never read, so it was missing frombuff/cacheandavailable. Including it tightens thetotal = used + free + buff/cacheidentity (was off ~0.5 GB, now ~0.4%).New feature:
-P/--pressuremacOS relieves memory pressure with an in-RAM compressor before it touches swap, so the Linux-style
free/swapcolumns can look healthy while the machine is actually thrashing.-Pprints the real kernel signalkern.memorystatus_vm_pressure_level(the same one Activity Monitor uses):normal/warning/critical, plus available %.Default output stays Linux-parseable (flag is opt-in).
Validation
makeclean under-Wall -Wextra -Werror -pedanticclang-format --Werrorcleanmake testsmoke passes-Poutput cross-checked againstsysctl kern.memorystatus_vm_pressure_level; column values cross-checked againstvm_statFollow-up (not in this PR)
A genuine
sharedvalue would require summing shared footprint across all tasks (astop/libtopdo) — filed as a possible enhancement.🤖 Generated with Claude Code