Skip to content

fix(host-monitor): exclude reclaimable cache from macOS memory usage - #2

Open
xt1990xt1990 wants to merge 1 commit into
a31521424:mainfrom
xt1990xt1990:fix/host-monitor-macos-memory
Open

xt1990xt1990 wants to merge 1 commit into
a31521424:mainfrom
xt1990xt1990:fix/host-monitor-macos-memory

Conversation

@xt1990xt1990

Copy link
Copy Markdown

On macOS, host-monitor calculates used RAM as os.totalmem() - os.freemem(), which includes reclaimable file-backed cache and overstates memory usage compared with Activity Monitor. On a 64 GiB Apple Silicon Mac, a local sample reported about 62.2 GiB used with the old calculation versus 43.7 GiB (68.3%) with this change.

Read vm_stat on macOS and calculate anonymous pages minus purgeable pages, plus wired pages and the physical pages occupied by the compressor. Use the page size reported by the system to support both 4 KiB and 16 KiB pages. If collection fails, log the error and fall back to the existing OS counters.

Reuse the memory reading from each sampling tick for RPC responses, keeping the displayed value consistent with history and avoiding an extra subprocess per client request. Document the macOS accounting and add focused regression tests.

Validation on Node.js 24.13.1:

  • npm run typecheck in plugins/host-monitor passed against the latest main branch.
  • node --test server/sampler.test.mjs passed all 3 tests: both page sizes, cache exclusion and physical compressor accounting, and incomplete output.
  • Ran the sampler on macOS, verified the current percentage matches the reported bytes, and reloaded the installed plugin successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant