How are /proc/meminfo values calculated?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite












/! Current state: Update 3 /!



Some /proc/meminfo values are a sum or a difference of some other values.
However, not much is said about how they are calculated in these two links (just do ctrl-f meminfo to get there):



  • https://www.kernel.org/doc/Documentation/filesystems/proc.txt

  • man 5 proc

Besides, I've also dug here and there, and here's what I found so far:



MemFree: LowFree + HighFree
Active: Active(anon) + Active(file)
Inactive: Inactive(anon) + Inactive(file)


I have not found much about the other fields, and where I have, the results don't match, like in these Stack Overflow posts:




  • How to Calculate MemTotal in /proc/meminfo
    (2035272 kB vs expected 2034284 kB)

  • Entry in /proc/meminfo - on Stack Overflow

Are these two values correctly calculated? Or is there some variability due to some external means?



Also, some values can't -obviously- be calculated without external values, but I'm still interested in that.



How are /proc/meminfo values calculated?




If that helps, here's an example of /proc/meminfo:



MemTotal: 501400 kB
MemFree: 38072 kB
MemAvailable: 217652 kB
Buffers: 0 kB
Cached: 223508 kB
SwapCached: 11200 kB
Active: 179280 kB
Inactive: 181680 kB
Active(anon): 69032 kB
Inactive(anon): 70908 kB
Active(file): 110248 kB
Inactive(file): 110772 kB
Unevictable: 0 kB
Mlocked: 0 kB
HighTotal:
HighFree:
LowTotal:
LowFree:
MmapCopy:
SwapTotal: 839676 kB
SwapFree: 785552 kB
Dirty: 4 kB
Writeback: 0 kB
AnonPages: 128964 kB
Mapped: 21840 kB
Shmem: 2488 kB
Slab: 71940 kB
SReclaimable: 41372 kB
SUnreclaim: 30568 kB
KernelStack: 2736 kB
PageTables: 5196 kB
Quicklists:
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 1090376 kB
Committed_AS: 486916 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 4904 kB
VmallocChunk: 34359721736 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
ShmemHugePages:
ShmemPmdMapped:
CmaTotal:
CmaFree:
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 36800 kB
DirectMap2M: 487424 kB
DirectMap4M:
DirectMap1G:



Update 1:



Here's the code used by /proc/meminfo to fill its data:



http://elixir.free-electrons.com/linux/v4.15/source/fs/proc/meminfo.c#L46



However, since I'm not that of a coder, I'm having a hard time to figure out where these enums (e.g. NR_LRU_LISTS, etc) and global variables (e.g totalram_pages from si_meminfo in page_alloc.c#L4673 ) are filled.



Update 2:



The enums part is now solved, and NR_LRU_LISTS equals 5.



But the totalram_pages part seems to be harder to find out...



Update 3:



It looks like I won't be able to read the code since it looks very complex.
If someone manages to do it and shows how /proc/meminfo valures are calculated, he/she can have the bounty.



The more the answer is detailed is, the higher the higher the bounty will be.







share|improve this question


























    up vote
    4
    down vote

    favorite












    /! Current state: Update 3 /!



    Some /proc/meminfo values are a sum or a difference of some other values.
    However, not much is said about how they are calculated in these two links (just do ctrl-f meminfo to get there):



    • https://www.kernel.org/doc/Documentation/filesystems/proc.txt

    • man 5 proc

    Besides, I've also dug here and there, and here's what I found so far:



    MemFree: LowFree + HighFree
    Active: Active(anon) + Active(file)
    Inactive: Inactive(anon) + Inactive(file)


    I have not found much about the other fields, and where I have, the results don't match, like in these Stack Overflow posts:




    • How to Calculate MemTotal in /proc/meminfo
      (2035272 kB vs expected 2034284 kB)

    • Entry in /proc/meminfo - on Stack Overflow

    Are these two values correctly calculated? Or is there some variability due to some external means?



    Also, some values can't -obviously- be calculated without external values, but I'm still interested in that.



    How are /proc/meminfo values calculated?




    If that helps, here's an example of /proc/meminfo:



    MemTotal: 501400 kB
    MemFree: 38072 kB
    MemAvailable: 217652 kB
    Buffers: 0 kB
    Cached: 223508 kB
    SwapCached: 11200 kB
    Active: 179280 kB
    Inactive: 181680 kB
    Active(anon): 69032 kB
    Inactive(anon): 70908 kB
    Active(file): 110248 kB
    Inactive(file): 110772 kB
    Unevictable: 0 kB
    Mlocked: 0 kB
    HighTotal:
    HighFree:
    LowTotal:
    LowFree:
    MmapCopy:
    SwapTotal: 839676 kB
    SwapFree: 785552 kB
    Dirty: 4 kB
    Writeback: 0 kB
    AnonPages: 128964 kB
    Mapped: 21840 kB
    Shmem: 2488 kB
    Slab: 71940 kB
    SReclaimable: 41372 kB
    SUnreclaim: 30568 kB
    KernelStack: 2736 kB
    PageTables: 5196 kB
    Quicklists:
    NFS_Unstable: 0 kB
    Bounce: 0 kB
    WritebackTmp: 0 kB
    CommitLimit: 1090376 kB
    Committed_AS: 486916 kB
    VmallocTotal: 34359738367 kB
    VmallocUsed: 4904 kB
    VmallocChunk: 34359721736 kB
    HardwareCorrupted: 0 kB
    AnonHugePages: 0 kB
    ShmemHugePages:
    ShmemPmdMapped:
    CmaTotal:
    CmaFree:
    HugePages_Total: 0
    HugePages_Free: 0
    HugePages_Rsvd: 0
    HugePages_Surp: 0
    Hugepagesize: 2048 kB
    DirectMap4k: 36800 kB
    DirectMap2M: 487424 kB
    DirectMap4M:
    DirectMap1G:



    Update 1:



    Here's the code used by /proc/meminfo to fill its data:



    http://elixir.free-electrons.com/linux/v4.15/source/fs/proc/meminfo.c#L46



    However, since I'm not that of a coder, I'm having a hard time to figure out where these enums (e.g. NR_LRU_LISTS, etc) and global variables (e.g totalram_pages from si_meminfo in page_alloc.c#L4673 ) are filled.



    Update 2:



    The enums part is now solved, and NR_LRU_LISTS equals 5.



    But the totalram_pages part seems to be harder to find out...



    Update 3:



    It looks like I won't be able to read the code since it looks very complex.
    If someone manages to do it and shows how /proc/meminfo valures are calculated, he/she can have the bounty.



    The more the answer is detailed is, the higher the higher the bounty will be.







    share|improve this question
























      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      /! Current state: Update 3 /!



      Some /proc/meminfo values are a sum or a difference of some other values.
      However, not much is said about how they are calculated in these two links (just do ctrl-f meminfo to get there):



      • https://www.kernel.org/doc/Documentation/filesystems/proc.txt

      • man 5 proc

      Besides, I've also dug here and there, and here's what I found so far:



      MemFree: LowFree + HighFree
      Active: Active(anon) + Active(file)
      Inactive: Inactive(anon) + Inactive(file)


      I have not found much about the other fields, and where I have, the results don't match, like in these Stack Overflow posts:




      • How to Calculate MemTotal in /proc/meminfo
        (2035272 kB vs expected 2034284 kB)

      • Entry in /proc/meminfo - on Stack Overflow

      Are these two values correctly calculated? Or is there some variability due to some external means?



      Also, some values can't -obviously- be calculated without external values, but I'm still interested in that.



      How are /proc/meminfo values calculated?




      If that helps, here's an example of /proc/meminfo:



      MemTotal: 501400 kB
      MemFree: 38072 kB
      MemAvailable: 217652 kB
      Buffers: 0 kB
      Cached: 223508 kB
      SwapCached: 11200 kB
      Active: 179280 kB
      Inactive: 181680 kB
      Active(anon): 69032 kB
      Inactive(anon): 70908 kB
      Active(file): 110248 kB
      Inactive(file): 110772 kB
      Unevictable: 0 kB
      Mlocked: 0 kB
      HighTotal:
      HighFree:
      LowTotal:
      LowFree:
      MmapCopy:
      SwapTotal: 839676 kB
      SwapFree: 785552 kB
      Dirty: 4 kB
      Writeback: 0 kB
      AnonPages: 128964 kB
      Mapped: 21840 kB
      Shmem: 2488 kB
      Slab: 71940 kB
      SReclaimable: 41372 kB
      SUnreclaim: 30568 kB
      KernelStack: 2736 kB
      PageTables: 5196 kB
      Quicklists:
      NFS_Unstable: 0 kB
      Bounce: 0 kB
      WritebackTmp: 0 kB
      CommitLimit: 1090376 kB
      Committed_AS: 486916 kB
      VmallocTotal: 34359738367 kB
      VmallocUsed: 4904 kB
      VmallocChunk: 34359721736 kB
      HardwareCorrupted: 0 kB
      AnonHugePages: 0 kB
      ShmemHugePages:
      ShmemPmdMapped:
      CmaTotal:
      CmaFree:
      HugePages_Total: 0
      HugePages_Free: 0
      HugePages_Rsvd: 0
      HugePages_Surp: 0
      Hugepagesize: 2048 kB
      DirectMap4k: 36800 kB
      DirectMap2M: 487424 kB
      DirectMap4M:
      DirectMap1G:



      Update 1:



      Here's the code used by /proc/meminfo to fill its data:



      http://elixir.free-electrons.com/linux/v4.15/source/fs/proc/meminfo.c#L46



      However, since I'm not that of a coder, I'm having a hard time to figure out where these enums (e.g. NR_LRU_LISTS, etc) and global variables (e.g totalram_pages from si_meminfo in page_alloc.c#L4673 ) are filled.



      Update 2:



      The enums part is now solved, and NR_LRU_LISTS equals 5.



      But the totalram_pages part seems to be harder to find out...



      Update 3:



      It looks like I won't be able to read the code since it looks very complex.
      If someone manages to do it and shows how /proc/meminfo valures are calculated, he/she can have the bounty.



      The more the answer is detailed is, the higher the higher the bounty will be.







      share|improve this question














      /! Current state: Update 3 /!



      Some /proc/meminfo values are a sum or a difference of some other values.
      However, not much is said about how they are calculated in these two links (just do ctrl-f meminfo to get there):



      • https://www.kernel.org/doc/Documentation/filesystems/proc.txt

      • man 5 proc

      Besides, I've also dug here and there, and here's what I found so far:



      MemFree: LowFree + HighFree
      Active: Active(anon) + Active(file)
      Inactive: Inactive(anon) + Inactive(file)


      I have not found much about the other fields, and where I have, the results don't match, like in these Stack Overflow posts:




      • How to Calculate MemTotal in /proc/meminfo
        (2035272 kB vs expected 2034284 kB)

      • Entry in /proc/meminfo - on Stack Overflow

      Are these two values correctly calculated? Or is there some variability due to some external means?



      Also, some values can't -obviously- be calculated without external values, but I'm still interested in that.



      How are /proc/meminfo values calculated?




      If that helps, here's an example of /proc/meminfo:



      MemTotal: 501400 kB
      MemFree: 38072 kB
      MemAvailable: 217652 kB
      Buffers: 0 kB
      Cached: 223508 kB
      SwapCached: 11200 kB
      Active: 179280 kB
      Inactive: 181680 kB
      Active(anon): 69032 kB
      Inactive(anon): 70908 kB
      Active(file): 110248 kB
      Inactive(file): 110772 kB
      Unevictable: 0 kB
      Mlocked: 0 kB
      HighTotal:
      HighFree:
      LowTotal:
      LowFree:
      MmapCopy:
      SwapTotal: 839676 kB
      SwapFree: 785552 kB
      Dirty: 4 kB
      Writeback: 0 kB
      AnonPages: 128964 kB
      Mapped: 21840 kB
      Shmem: 2488 kB
      Slab: 71940 kB
      SReclaimable: 41372 kB
      SUnreclaim: 30568 kB
      KernelStack: 2736 kB
      PageTables: 5196 kB
      Quicklists:
      NFS_Unstable: 0 kB
      Bounce: 0 kB
      WritebackTmp: 0 kB
      CommitLimit: 1090376 kB
      Committed_AS: 486916 kB
      VmallocTotal: 34359738367 kB
      VmallocUsed: 4904 kB
      VmallocChunk: 34359721736 kB
      HardwareCorrupted: 0 kB
      AnonHugePages: 0 kB
      ShmemHugePages:
      ShmemPmdMapped:
      CmaTotal:
      CmaFree:
      HugePages_Total: 0
      HugePages_Free: 0
      HugePages_Rsvd: 0
      HugePages_Surp: 0
      Hugepagesize: 2048 kB
      DirectMap4k: 36800 kB
      DirectMap2M: 487424 kB
      DirectMap4M:
      DirectMap1G:



      Update 1:



      Here's the code used by /proc/meminfo to fill its data:



      http://elixir.free-electrons.com/linux/v4.15/source/fs/proc/meminfo.c#L46



      However, since I'm not that of a coder, I'm having a hard time to figure out where these enums (e.g. NR_LRU_LISTS, etc) and global variables (e.g totalram_pages from si_meminfo in page_alloc.c#L4673 ) are filled.



      Update 2:



      The enums part is now solved, and NR_LRU_LISTS equals 5.



      But the totalram_pages part seems to be harder to find out...



      Update 3:



      It looks like I won't be able to read the code since it looks very complex.
      If someone manages to do it and shows how /proc/meminfo valures are calculated, he/she can have the bounty.



      The more the answer is detailed is, the higher the higher the bounty will be.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 21 at 17:33









      GAD3R

      22.4k154894




      22.4k154894










      asked Jan 31 at 1:14









      X.LINK

      23018




      23018




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          5
          down vote













          The contents of /proc/meminfo are determined by meminfo_proc_show in fs/proc/meminfo.c in the kernel.



          The calculations are all relatively straightforward, but the sources of information used aren’t necessarily so obvious. For example, MemTotal is the totalram value from the sysinfo structure; that’s filled in by si_meminfo in mm/page_alloc.c.






          share|improve this answer




















          • That's pretty straightforward indeed. However, I'm having a hard time -I'm not that much of a programmer- to find where those enums members are defined (e.g NR_LRU_LISTS, NR_LRU_BASE, LRU_ACTIVE_ANON, etc). I do have found this website: elixir.free-electrons.com/linux/v4.15/source/fs/proc/meminfo.c ; But clicking on these values seems to point on a lot of possibilities, still without knowing what was called right before meminfo_proc_show().
            – X.LINK
            Jan 31 at 15:02







          • 1




            I’ll expand my answer to detail where the values come from, but it will take me a little while to write it all up.
            – Stephen Kitt
            Feb 1 at 8:17










          • Any news about how /proc/meminfo values are calculated ?
            – X.LINK
            Feb 24 at 3:30







          • 1




            I haven’t forgotten you, it’s taking me longer than I hoped to write everything up...
            – Stephen Kitt
            Feb 24 at 10:04










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f420839%2fhow-are-proc-meminfo-values-calculated%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          5
          down vote













          The contents of /proc/meminfo are determined by meminfo_proc_show in fs/proc/meminfo.c in the kernel.



          The calculations are all relatively straightforward, but the sources of information used aren’t necessarily so obvious. For example, MemTotal is the totalram value from the sysinfo structure; that’s filled in by si_meminfo in mm/page_alloc.c.






          share|improve this answer




















          • That's pretty straightforward indeed. However, I'm having a hard time -I'm not that much of a programmer- to find where those enums members are defined (e.g NR_LRU_LISTS, NR_LRU_BASE, LRU_ACTIVE_ANON, etc). I do have found this website: elixir.free-electrons.com/linux/v4.15/source/fs/proc/meminfo.c ; But clicking on these values seems to point on a lot of possibilities, still without knowing what was called right before meminfo_proc_show().
            – X.LINK
            Jan 31 at 15:02







          • 1




            I’ll expand my answer to detail where the values come from, but it will take me a little while to write it all up.
            – Stephen Kitt
            Feb 1 at 8:17










          • Any news about how /proc/meminfo values are calculated ?
            – X.LINK
            Feb 24 at 3:30







          • 1




            I haven’t forgotten you, it’s taking me longer than I hoped to write everything up...
            – Stephen Kitt
            Feb 24 at 10:04














          up vote
          5
          down vote













          The contents of /proc/meminfo are determined by meminfo_proc_show in fs/proc/meminfo.c in the kernel.



          The calculations are all relatively straightforward, but the sources of information used aren’t necessarily so obvious. For example, MemTotal is the totalram value from the sysinfo structure; that’s filled in by si_meminfo in mm/page_alloc.c.






          share|improve this answer




















          • That's pretty straightforward indeed. However, I'm having a hard time -I'm not that much of a programmer- to find where those enums members are defined (e.g NR_LRU_LISTS, NR_LRU_BASE, LRU_ACTIVE_ANON, etc). I do have found this website: elixir.free-electrons.com/linux/v4.15/source/fs/proc/meminfo.c ; But clicking on these values seems to point on a lot of possibilities, still without knowing what was called right before meminfo_proc_show().
            – X.LINK
            Jan 31 at 15:02







          • 1




            I’ll expand my answer to detail where the values come from, but it will take me a little while to write it all up.
            – Stephen Kitt
            Feb 1 at 8:17










          • Any news about how /proc/meminfo values are calculated ?
            – X.LINK
            Feb 24 at 3:30







          • 1




            I haven’t forgotten you, it’s taking me longer than I hoped to write everything up...
            – Stephen Kitt
            Feb 24 at 10:04












          up vote
          5
          down vote










          up vote
          5
          down vote









          The contents of /proc/meminfo are determined by meminfo_proc_show in fs/proc/meminfo.c in the kernel.



          The calculations are all relatively straightforward, but the sources of information used aren’t necessarily so obvious. For example, MemTotal is the totalram value from the sysinfo structure; that’s filled in by si_meminfo in mm/page_alloc.c.






          share|improve this answer












          The contents of /proc/meminfo are determined by meminfo_proc_show in fs/proc/meminfo.c in the kernel.



          The calculations are all relatively straightforward, but the sources of information used aren’t necessarily so obvious. For example, MemTotal is the totalram value from the sysinfo structure; that’s filled in by si_meminfo in mm/page_alloc.c.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 31 at 5:41









          Stephen Kitt

          142k22308370




          142k22308370











          • That's pretty straightforward indeed. However, I'm having a hard time -I'm not that much of a programmer- to find where those enums members are defined (e.g NR_LRU_LISTS, NR_LRU_BASE, LRU_ACTIVE_ANON, etc). I do have found this website: elixir.free-electrons.com/linux/v4.15/source/fs/proc/meminfo.c ; But clicking on these values seems to point on a lot of possibilities, still without knowing what was called right before meminfo_proc_show().
            – X.LINK
            Jan 31 at 15:02







          • 1




            I’ll expand my answer to detail where the values come from, but it will take me a little while to write it all up.
            – Stephen Kitt
            Feb 1 at 8:17










          • Any news about how /proc/meminfo values are calculated ?
            – X.LINK
            Feb 24 at 3:30







          • 1




            I haven’t forgotten you, it’s taking me longer than I hoped to write everything up...
            – Stephen Kitt
            Feb 24 at 10:04
















          • That's pretty straightforward indeed. However, I'm having a hard time -I'm not that much of a programmer- to find where those enums members are defined (e.g NR_LRU_LISTS, NR_LRU_BASE, LRU_ACTIVE_ANON, etc). I do have found this website: elixir.free-electrons.com/linux/v4.15/source/fs/proc/meminfo.c ; But clicking on these values seems to point on a lot of possibilities, still without knowing what was called right before meminfo_proc_show().
            – X.LINK
            Jan 31 at 15:02







          • 1




            I’ll expand my answer to detail where the values come from, but it will take me a little while to write it all up.
            – Stephen Kitt
            Feb 1 at 8:17










          • Any news about how /proc/meminfo values are calculated ?
            – X.LINK
            Feb 24 at 3:30







          • 1




            I haven’t forgotten you, it’s taking me longer than I hoped to write everything up...
            – Stephen Kitt
            Feb 24 at 10:04















          That's pretty straightforward indeed. However, I'm having a hard time -I'm not that much of a programmer- to find where those enums members are defined (e.g NR_LRU_LISTS, NR_LRU_BASE, LRU_ACTIVE_ANON, etc). I do have found this website: elixir.free-electrons.com/linux/v4.15/source/fs/proc/meminfo.c ; But clicking on these values seems to point on a lot of possibilities, still without knowing what was called right before meminfo_proc_show().
          – X.LINK
          Jan 31 at 15:02





          That's pretty straightforward indeed. However, I'm having a hard time -I'm not that much of a programmer- to find where those enums members are defined (e.g NR_LRU_LISTS, NR_LRU_BASE, LRU_ACTIVE_ANON, etc). I do have found this website: elixir.free-electrons.com/linux/v4.15/source/fs/proc/meminfo.c ; But clicking on these values seems to point on a lot of possibilities, still without knowing what was called right before meminfo_proc_show().
          – X.LINK
          Jan 31 at 15:02





          1




          1




          I’ll expand my answer to detail where the values come from, but it will take me a little while to write it all up.
          – Stephen Kitt
          Feb 1 at 8:17




          I’ll expand my answer to detail where the values come from, but it will take me a little while to write it all up.
          – Stephen Kitt
          Feb 1 at 8:17












          Any news about how /proc/meminfo values are calculated ?
          – X.LINK
          Feb 24 at 3:30





          Any news about how /proc/meminfo values are calculated ?
          – X.LINK
          Feb 24 at 3:30





          1




          1




          I haven’t forgotten you, it’s taking me longer than I hoped to write everything up...
          – Stephen Kitt
          Feb 24 at 10:04




          I haven’t forgotten you, it’s taking me longer than I hoped to write everything up...
          – Stephen Kitt
          Feb 24 at 10:04












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f420839%2fhow-are-proc-meminfo-values-calculated%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay