darwin: exclude inactive and speculative pages from used memory - #1976
Conversation
|
@natoscott |
e906263 to
9dc8009
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummarySurgically fixes macOS memory accounting that inflated "used" memory on high‑RAM Apple Silicon systems by reclassifying page types and switching to the correct page-count source for anonymous/app pages. Changes
Assessment
NoteReviewer feedback indicates a report where large inactive counts still appear and displayed wired/used values remained unexpected on a high‑memory Mac; follow-up testing on affected hardware is recommended. WalkthroughThis PR updates macOS memory reporting: configure.ac now detects vm_statistics64.internal_page_count; Platform.c marks speculative and inactive pages as cache-only (countsAsUsed=false) and selects internal_page_count (or active_count fallback). Memory-class calculations for ACTIVE now use page_K * saturatingSub(internal_page_count, vm->purgeable_count); INACTIVE and SPECULATIVE are tied to showCachedMemory and PURGEABLE uses vm->purgeable_count when shown. Assessment against linked issues
Poem
Comment |
Two issues caused htop to massively overreport memory usage on
high-RAM Apple Silicon systems (e.g. 49G vs 9G on a 192GB M2 Ultra):
1. Inactive and speculative pages were counted as used memory.
These are reclaimable caches and should only appear when Show
cached memory is enabled.
2. The active (app memory) value was computed by subtracting
external_page_count from active_count. external_page_count
counts all file-backed pages across active, inactive and
speculative lists, so on machines with large inactive lists
it exceeds active_count and the saturatingSub clamp produces
zero, leaving only wired memory in the total.
Use internal_page_count (anonymous pages) directly instead,
matching Activity Monitors App Memory definition:
app_memory = internal_page_count - purgeable_count
Closes: htop-dev#1975
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9dc8009 to
af53de4
Compare
|
Thank you, tested and confirming that new fix af53de4 reports as 15.1 G / 192 G. htop dropped from the buggy 48 G down to 15.1 G. |
Inactive and speculative pages are reclaimable caches, not actively used memory. Counting them as "used" inflates the displayed value far beyond what Activity Monitor reports, especially on high-RAM Apple Silicon systems (e.g. 49G vs 9G on a 192GB M2 Ultra).
Both classes already had countsAsCache=true; this change sets countsAsUsed=false so they no longer contribute to the "used" total. They remain visible when "Show cached memory" is enabled.
Resolves: #1975