Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

phl92

macrumors 6502
Original poster
Oct 28, 2020
301
47
So I just noticed that on MacOS happens the same as on Linux. The ram usage and also swap usage is totally different depending with which program I analyze it. My default Activity Monitor shows on my Mac Air M1 is pretty much always quite loaded even after just rebooting. Around 5-6 GB Ram usage and as soon as I have a bit of heavy Browser usage and some IDE's (IntelliJ) open my Swap gets also around 1-3 GB Ram.
However, I just installed htop on my command line, and here the values are totally different. At the moment htop shows 3,9 GB Ram and 450 MB Swap. My activity monitor shows at the same time 6,7 GB Ram but Swap usage is identical. Howver, on activity monitor is also Cached Files shown (at the moment 1,3 GB usage) and in htop I don't see Cached files at all.

But I noticed in Linux even weirder things. I use there htop , stacer and the default System monitor. All 3 Apps show TOTAL different numbers of my RAM Usage.

Someone can explain a bit?
 
At the moment htop shows 3,9 GB Ram and 450 MB Swap. My activity monitor shows at the same time 6,7 GB Ram but Swap usage is identical.
Everyone is agreed on how to measure swap. It is the size of pages which have been written to disk and removed from RAM.

But what is "used" memory? Or perhaps I should say used by what? The trouble with RAM usage is that there is more than one way of describing how a page in memory is being used. It is complicated.

The traditional Unix way (as used by htop) is to allocate each page to one of Wired, Active, Inactive, Speculative and Free. For the last ~10 years there is also Compressed. The total Wired + Active + Inactive + Speculative +Compressed + Free is your physical RAM size. These values can be taken from the Terminal command vm_stat.

htop (and some other Linux utilities) show Used, Buffers, Shared and Cache - these add up to Physical RAM less Free. I don't know a macOS Terminal command to present these values, nor which system calls might be used. htop does not explicitly present Compressed - I can only assume it is counted its Cache.

I believe htop's "Used" is showing Wired + Active. This is the value show as "Mem".

An alternative way of presenting RAM usage (as used by Activity Monitor) is to allocate each page to one of Wired, Application, Compressed, Cached and Free. Activity Monitor describes Wired + Application + Compressed as "Used". And "Used" + Cached + Free (not shown) equals Physical Memory.

Arguably the Activity Monitor way is the more useful way of presenting RAM usage.

Only the values for Wired RAM (that which can't be compressed or swapped) and Compressed are the same in both schemes.

It does not work to expect AM's measure of "used" to be the same a htop's "Mem" - they are measured in different ways.

Only one app that I know of presents both measures of RAM usage - iStat Menus.
 
Last edited:
  • Like
Reactions: phl92
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.