Want to make /proc/*/smaps output anonymous region

2019-09-04 15:06发布

I want to see the precise amount of memory each processes use as anonymous page, because anonymous memory cannot be paged out, thus tracking this usage precisely is important.

One way to get the whole sum of anonymous page is to read /proc/meminfo AnonPages.

The other way is to add up all the entries in smaps file which matches follows:

  • no name
  • [stack]
  • [heap]
  • /dev/zero
  • /dev/shm/...
  • Relocated section private_dirty

    Section used for relocation would be updated for each process, which makes some private_dirty region in a named mapping region. Elf loader seems to change read/write attribute using mprotect when doing relocation, so it is difficult to differentiate such region from a data section, and making it difficult to track these usage from each process point of view

So I would like to know how to differentiate the above relocated section, and to precisely track the anonymous memory usage for each processes.

Maybe we should add new entry in /proc/*/smaps to show the amount of Anonymous memory for each section.