четверг, 26 октября 2017 г.

How to calculate system memory usage from /proc/meminfo (like htop)

https://stackoverflow.com/questions/41224738/how-to-calculate-system-memory-usage-from-proc-meminfo-like-htop

These are the calculations I make to get the numbers for the green, blue and yellow bars in the memory meter:
  • Total used memory = MemTotal - MemFree
  • Non cache/buffer memory (green) = Total used memory - (Buffers + Cached memory)
  • Buffers (blue) = Buffers
  • Cached memory (yellow) = Cached + SReclaimable - Shmem
  • Swap = SwapTotal - SwapFree
In the htop source code: linux/LinuxProcessList.c and linux/Platform.c.