Why doesn't the value in /proc/meminfo seem to map exactly to the system RAM?

7,571

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.

Share:
7,571

Related videos on Youtube

Eric Asberry
Author by

Eric Asberry

My programming career began when I was 10 years old and my father brought home a Timex/Sinclair 1000 with a whopping 2K of RAM. Turbo Pascal 3.0 was the first software package I bought for my first PC, a Tandy 1000. I did most of my early professional software development in C/C++ in various flavors of Unix. These days I play mostly with Java on Linux or OSX but occasionally dabble in scripting and web stuff.

Updated on September 17, 2022

Comments

  • Eric Asberry
    Eric Asberry almost 2 years

    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. ...

  • Eric Asberry
    Eric Asberry over 13 years
    Thank you! So basically, RTFM. :) Didn't know where to find this info and my Google-Fu let me down. In case anyone else is interested, the above mentioned reference can be found here: kernel.org/doc/Documentation/filesystems/proc.txt
  • user2751502
    user2751502 over 13 years
    For the record (and the improvement of your Google-Fu): a Google search for "/proc/meminfo" yields exactly this information as the first search result.
  • Eric Asberry
    Eric Asberry over 13 years
    I confess, I never tried searching for just "/proc/meminfo". Thank you for taking the time to point out my weak Google-Fu. The good news is my search for "meminfo inconsistent" brings up this page now. :)
  • kristianlm
    kristianlm over 9 years
    interesetingly, when I google for /proc/meminfo now, google takes me here!