Macchina-CLI / libmacchina

A library providing access to all sorts of system information.
https://crates.io/crates/libmacchina
MIT License
68 stars 20 forks source link

macos memory usage incorrect #166

Open k2662 opened 7 months ago

k2662 commented 7 months ago

the reported memory usage is lower than shown in activity monitor.

Gobidev commented 7 months ago

How much do they differ? Can you provide examples?

k2662 commented 7 months ago

How much do they differ? Can you provide examples?

by up to 3GB. like: if actual was 12GB then it would show 9.3GB

k2662 commented 6 months ago

Any update?

Gobidev commented 6 months ago

@k2662 Can you provide a screenshot of the memory usage reported by the activity monitor along with running vm_stat in a terminal? There are multiple options of what to count as used memory so it would be interesting to see what the activity monitor uses.

I don't own any device running macOS so testing is somewhat difficult. What I tried is running the libmacchina readouts and vm_stat on a macOS GitHub runner here, where the free memory reported by libmacchina approximately matches the free and inactive pages of vm_stat combined:

libmacchina:
reported free: 3330848 [kB] = 3410788352 Bytes

vm_stat:
reported free: 26076 [Pages] = 427229184 Bytes (1 Page = 16384 Bytes)
reported inactive: 183623 [Pages] = 3008479232 Bytes
free + inactive = 3435708416 Bytes
k2662 commented 6 months ago

@k2662 Can you provide a screenshot of the memory usage reported by the activity monitor along with running vm_stat in a terminal? There are multiple options of what to count as used memory so it would be interesting to see what the activity monitor uses.

I don't own any device running macOS so testing is somewhat difficult. What I tried is running the libmacchina readouts and vm_stat on a macOS GitHub runner here, where the free memory reported by libmacchina approximately matches the free and inactive pages of vm_stat combined:

libmacchina:
reported free: 3330848 [kB] = 3410788352 Bytes

vm_stat:
reported free: 26076 [Pages] = 427229184 Bytes (1 Page = 16384 Bytes)
reported inactive: 183623 [Pages] = 3008479232 Bytes
free + inactive = 3435708416 Bytes

image

image

k2662 commented 2 months ago

Is this not being fixed?

grtcdr commented 2 months ago

Perhaps @123marvin123 can help us with this issue :)

123marvin123 commented 2 months ago

I believe this happens because Activity Monitor includes compressed memory as used memory. There are some discrepancies in how different apps report this metric. "iStat Menus" includes also the compressed memory, but many command line tools (e.g. https://github.com/giampaolo/psutil) do not.

So I'm not sure what is the best approach.