Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

heap VS anon memory in the result of pmap

The following is the result after run on solaris, it shows there are two heaps, but in my understanding, for a process, there is only one heap which is a large continuous memory which can be managed by brk to expand or shrink the size. And for anon memory, a process can have many anon memory which can be managed by mmap/munmap. Is my understanding correct? or I read the result of the pmap wrongly?

sol9# pmap -sx pgrep testprog

... 00022000 3960 3960 3960 - 8K rwx-- [ heap ]

00400000 131072 131072 131072 - 4M rwx-- [ heap ]

... FF390000 8 8 - - 8K r-x-- libc_psr.so.1

FF3B0000 8 8 8 - 8K rwx-- [ anon ]

...


total Kb 135968 135944 135112 -

like image 472
Daniel Avatar asked Jan 28 '10 00:01

Daniel


People also ask

What is anon in PMAP output?

Anonymous memory: Memory not relating to any named object or file within the file system is reported as [ anon ]. The pmap command displays common names for certain known anonymous memory mappings, such as: [ heap ] The process heap.

What does pmap show?

The pmap command in Linux is used to display the memory map of a process. A memory map indicates how memory is spread out.

What is RSS in PMAP?

In computing, resident set size (RSS) is the portion of memory occupied by a process that is held in main memory (RAM). The rest of the occupied memory exists in the swap space or file system, either because some parts of the occupied memory were paged out, or because some parts of the executable were never loaded.


1 Answers

You are both correct and misreading the pmap output. If you had done pmap -x the results would probably be less confusing, showing the heap just once, but since you added the -s flag, it breaks down the heap into segments with different page mappings.

The addresses starting at 0x0022000 are not aligned properly to be mapped to a 4Mb page, so they use 3960kb of 8k pages. 0x0022000+(3960*1024) = 0x00400000

At 0x00400000 the address is properly aligned for 4Mb pages, so the heap switches to using the larger pages with fewer page table entries.

If you wanted to ensure that your heap started at the proper alignment to use 4Mb pages for the whole thing instead of starting with 8k until it reached an alignment boundary, then you would link your program with -M /usr/lib/ld/map.bssalign to do that.

A slightly more in-depth explanation can be found in the Page Size and Memory Layout blog post from Solaris Application Programming author Darryl Gove.

like image 116
alanc Avatar answered Sep 20 '22 16:09

alanc