brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: vm_stat prints Mac memory in pages, so check the page size first

Memory
~/tips/tip-macos-vm-stat-memory-pages

vm_stat

Prints macOS memory statistics in pages, with the page size in the header.

vm_stat is the plain old way to see what the memory manager is doing. The first thing to know is that it counts pages, not megabytes.

Run it without arguments and the man page says you get all accumulated statistics along with the page size:

vm_stat

To turn a page count into megabytes, multiply by the page size. This reads the size from sysctl and prints the free pages in MB:

vm_stat | awk -v s=$(sysctl -n hw.pagesize) '/Pages free/ {gsub(/\./,"",$3); printf "%.0f MB free\n", $3*s/1048576}'

With an interval it keeps printing, and -c stops it after a number of rounds:

vm_stat -c 5 2

That prints five reports, two seconds apart. The first line after each banner shows the system-wide totals, and every line after it shows the change since the previous one. An interval of 1 therefore gives you values per second.

A few of the lines the man page explains:

  • Pages wired down counts pages that cannot be paged out
  • Pages stored in compressor counts pages whose contents sit in the in-memory compressor pool
  • Swapins and Swapouts count compressed data moved to and from swap files, in units of pages

The caveat is the Pages free line. The man page says file-backed pages can be evicted and read back under pressure, so free pages alone say little about whether the Mac is short on memory. The page I read also says meminfo(1) is the modern, preferred tool for physical memory and should be used instead of vm_stat where possible, so check whether your macOS has it.

Further reading: vm_stat man page

More Memory tips lsmem --summary for f in /proc/[0-9]*/status; do sudo apt install smem sudo pmap -x 1234 sudo systemctl edit indexer.service All Memory tips (12) All topics

Link