Check RAM Size: Installed vs What the OS Reports

Updated

Checking installed RAM on a Linux system

On Linux, installed RAM is sudo dmidecode --type memory and RAM the kernel can use is grep MemTotal /proc/meminfo. On macOS the pair is sysctl -n hw.memsize and sysctl -n hw.memsize_usable. Those are two different numbers on every machine.

Measured here, on a Mac advertised as having 36 GB:

$ sysctl hw.memsize hw.memsize_usable
hw.memsize: 38654705664
hw.memsize_usable: 37720604672

$ system_profiler SPHardwareDataType | grep Memory
      Memory: 36 GB

38654705664 bytes is exactly 36 GiB. 37720604672 is what is left after firmware and hardware take their cut — a difference of 934100992 bytes, 890.83 MiB, on this machine. Nothing is wrong. That memory is carved out before the OS boots, for the GPU, the secure enclave, ACPI tables and reserved regions, and no amount of quitting apps returns it.

Linux draws the same line, and the kernel’s own documentation of /proc/meminfo spells it out in the definition of MemTotal: “Total usable RAM (i.e. physical RAM minus a few reserved bits and the kernel binary code)”. So when free -h shows less than the sticker on the box, that is the documented behaviour, not a fault and not a hardware failure.

Which command answers which question

Cited from the vendor documentation, not run here:

  • What the kernel can use — free, vmstat -s, top, htop, cat /proc/meminfo. All five read the same kernel counters. free is a formatter over /proc/meminfo; it is not an independent second opinion, and if two of them disagree you have a units problem, not a hardware one.
  • What is physically installed — sudo dmidecode --type memory and sudo lshw -class memory, both of which read the firmware’s SMBIOS tables rather than asking the kernel. That is why they need root and why they can report modules the kernel has excluded.
  • Neither, reliably — inxi -m is a wrapper over the two above and inherits whichever one it happened to reach.

Two cautions. dmidecode reports what the firmware claims, and vendors ship SMBIOS tables containing placeholder strings; it is evidence about the firmware, not a measurement of the DIMMs. And on ARM machines — including Apple silicon and most cloud ARM instances — there is no SMBIOS memory table to read at all, so the “planning to upgrade your RAM” framing does not transfer. On this machine the module detail comes from system_profiler SPMemoryDataType, which reports Type: LPDDR5 and Manufacturer: Micron for memory that is soldered onto the package and cannot be upgraded.

The macOS sysctl that returns a wrong number

Guides that translate Linux advice to macOS often reach for hw.physmem, because it looks like the obvious name. On this 36 GB machine:

$ sysctl hw.physmem
hw.physmem: 3360866304

3.13 GiB. It is not a memory size at all — it is a 32-bit variable, and 3360866304 is exactly hw.memsize_usable modulo 232. Any machine with more than 4 GiB gets a meaningless answer, and it is meaningless in a way that looks plausible. Use hw.memsize.

The same trap catches page arithmetic. vm_stat reports counts in pages, and every worked example on the internet multiplies by 4096:

$ vm_stat | head -1
Mach Virtual Memory Statistics: (page size of 16384 bytes)

16384, not 4096, on Apple silicon. Read the page size from the first line of vm_stat or from sysctl -n hw.pagesize; never hard-code it. A script that assumes 4096 under-reports by a factor of four. check-physical-ram-size.sh asserts the hw.physmem truncation and the match between vm_stat‘s page size and hw.pagesize rather than taking my word for either; on Linux it also checks that free reports exactly MemTotal * 1024, a branch that reports SKIP on macOS.

The short version

# Linux  (cited from the vendor docs, not run on this page)
grep MemTotal /proc/meminfo          # usable, in kB
free -h                              # the same number, formatted
sudo dmidecode --type memory         # installed modules, per the firmware

# macOS  (executed for this page)
sysctl -n hw.memsize                 # installed, in bytes
sysctl -n hw.memsize_usable          # what the OS gets
system_profiler SPHardwareDataType   # marketing figure, e.g. "36 GB"
system_profiler SPMemoryDataType     # type and manufacturer

If installed and usable differ by tens of megabytes, that is normal reservation. If they differ by the size of a whole module, you have a seating or a fault problem, and that is the one case where dmidecode‘s per-slot listing earns its keep — it will show you the slot the kernel is not counting. That same per-slot view is the only way to see how the modules are paired, which is the question behind dual-channel configuration — and why an Apple silicon Mac has nothing to pair.

Identify the machine, or find where the memory went

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.