Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

understanding pmap output

I was trying to see memory map of a process on Linux x86-64 using pmap -x command. I got confused looking at the output of the pmap. Particularly for the entries for mapping dynamic libraries. There are multiple entries for them (actually 4 for all most all of them, with some having 3 entries). Following is an example

  Address           Kbytes   RSS   Dirty Mode   Mapping

00000036ca200000      88      64       0 r-x--  libpthread-2.5.so
00000036ca216000    2044       0       0 -----  libpthread-2.5.so
00000036ca415000       4       4       4 r----  libpthread-2.5.so
00000036ca416000       4       4       4 rw---  libpthread-2.5.so

The second row for each of the library always has size of 2MB while it has no page permission. Across all libraries it seems its RSS is ALWAYS zero. Last two rows also have same size (which is base page size) and same permissions (a handful libraries does not have rw mapping).

Does anybody has some explanation for this? I am kind of having a sense that possibly the mapping with the read-only protection is done by the loader to read the metadata of the library while the portion with the executable permission actually the code for the library. I may be wrong though.

But I have no clue about that middle row. No permission and no usages? Anyone has some words of wisdom here?

I also saw a few pages reported to be on the anonymous memory and not have any mode bit set. What do these represent?

like image 677
Arka Avatar asked Mar 22 '12 19:03

Arka


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.

How use PMAP command?

-p : This option is used to display the full path to the files. -d : This option is used to display the device format. -q : This option is used to ignore the column names while displaying the report of the memory map. -A : This option is used to display results to the given range.

What is PMAP used for?

The command pmap report virtual memory map of a process. This command can be used to find out causes of memory bottlenecks.

What is a PMAP file?

Description. The pmap command reports the memory map of a process or processes.


2 Answers

These protected "----" pages are guard pages to prevent pointers from indexing between the code and data segments of the library. They only exist in the virtual space of the process and exist to cause a fault if a pointer walks past the end of the segment.

If these weren't addressed into a shared library file I would say they were serving as a buffer for expanding allocations into e.g. malloc or stack growth. For example glibc requests large chunks of address space from the kernel for thread-local allocation arenas then consumes them slowly for malloc'd allocations. In a much larger pmap from a JVM I'm looking at there are a few dozen of these, each following a RW page or filling in the space between two large RW allocations and the boundaries between them shift as the RW pages expand. On X86_64 guard pages like this can use the CPU's memory protection system to catch bad pointer dereferences.

like image 66
user5479960 Avatar answered Sep 23 '22 18:09

user5479960


First of all , there can be this case that one same process can use more than one memory usage instance. I don't know if this is what you want to know. I have seen that , while using a browser in Linux, with just one tab open, and using the top command, it shows like more than 4 usage in the memory usage list, covering more than 10mb of memory. I think its ok because of the more number of threads running by the same process.

This link may be useful, since, in the usage example itself, if you observe, the mapping of the -x command show more number of usage.

http://www.cyberciti.biz/tips/howto-find-memory-used-by-program.html

like image 30
Xander Avatar answered Sep 21 '22 18:09

Xander