Linux – Why /proc/meminfo Values Don’t Map Exactly to System RAM

debianlinuxmemory

The values in /proc/meminfo for MemTotal don't make sense. As a human, eyeballing it, it seems to roughly correspond to the installed RAM, but for using it to display the installed RAM from an automated utility it appears to be inexact, and inconsistent.

For a system with 1G of RAM, I would expect the MemTotal line to have a value of 1048576 – 1024*1024. But instead, I'm seeing 1029392. On another 4G box, I'm seeing 3870172, which is not a multiple of 1024, and it's not even close to 1029392*4. On an 8G box, I get 8128204, which again seems to have no correlation to the other values, nor is it a multiple of 1024.

I'm trying to use this information to report the RAM on a status web page. My work-around is to just "round" it to the nearest 1G multiple, but I'd like to understand why these values seem inconsistent and don't match my expectations.

Can somebody fill me in on what I'm missing here?

EDIT: To expand on the accepted answer below….

The reference can be found here.

Also of interest to me from that page, which explains the inconsistency, is this bit:

meminfo:

Provides information about distribution and utilization of memory. This
varies by architecture and compile options. …

Best Answer

From Documentation/filesystems/proc.txt:

MemTotal: Total usable ram (i.e. physical ram minus a few reserved
          bits and the kernel binary code)

So there you go.

Addendum:

dmesg|grep Memory: will give you a bit more:

$ dmesg|grep Memory:
Memory: 3934184k/5177344k available (4434k kernel code, 1091560k absent, 151600k reserved, 7433k data, 920k init)

Addendum II:

It's also worth adding that pretty much everything in /proc has at least cursory documentation in that file, so it's a good first stop any time you have a similar question.

Related Topic