0
b7f27000     84K r-x--  /lib/libpthread-2.5.so
b7f3c000      4K -----  /lib/libpthread-2.5.so
b7f3d000      4K r----  /lib/libpthread-2.5.so
b7f3e000      4K rw---  /lib/libpthread-2.5.so
b7f3f000      8K rw---    [ anon ]
b7f41000     88K r-x--  /lib/libselinux.so.1
b7f57000      8K rw---  /lib/libselinux.so.1
b7f59000    256K r-x--  /usr/lib/libncurses.so.5.5
b7f99000     32K rw---  /usr/lib/libncurses.so.5.5
b7fa1000      8K rw---    [ anon ]
b7fa3000      4K r----  /usr/lib/locale/en_US.utf8/LC_MESSAGES/SYS_LC_MESSAGES
b7fa4000      4K r----  /usr/lib/locale/en_US.utf8/LC_PAPER
b7fa5000      4K r----  /usr/lib/locale/en_US.utf8/LC_NAME
b7fa6000      4K r----  /usr/lib/locale/en_US.utf8/LC_ADDRESS
b7fa7000      4K r----  /usr/lib/locale/en_US.utf8/LC_TELEPHONE
b7fa8000      4K r----  /usr/lib/locale/en_US.utf8/LC_MEASUREMENT
b7fa9000      4K r----  /usr/lib/locale/en_US.utf8/LC_IDENTIFICATION
b7faa000    108K r-x--  /lib/ld-2.5.so
b7fc5000      4K r----  /lib/ld-2.5.so
b7fc6000      4K rw---  /lib/ld-2.5.so
bf96f000    228K rw---    [ stack ]
 total    23740K

why these so lib are loaded more than more time? is that needed? why?

hugemeow
  • 7,777
  • 13
  • 50
  • 63

1 Answers1

3

Actually, each of those libraries is only loaded once; what you're seeing are the multiple memory regions used by each library.

A library contains code, rodata, and data (+bss). Code is readonly and executable (r-x), rodata is readonly (r--), and data (and bss) are read-write (rw-). These are the memory segments you're looking at (note that they all have different memory protection flags and sizes). Not all libraries have all of these segments, so you'll see that some libraries have only two (or even one) memory region mapped.

Note that pmap's "total" output measures only virtual memory utilization (which can be very high even for small processes). For physical memory use, use pmap -x and look under RSS (resident set size).

nneonneo
  • 171,345
  • 36
  • 312
  • 383
  • Can you add the code section is not loaded more than once so this is not a good way to show memory usage since the kernel only had one copy of the code segment – Adrian Cornish Sep 21 '12 at 05:15
  • 1
    Actually, the code section may be mapped `MAP_PRIVATE` (instead of `MAP_SHARED`), but with COW semantics. This allows the linker to perform relocations within the code section that affect only the executable it's loaded in (since the relocations depend on where the library is loaded). So, technically, the code section might not be shared. – nneonneo Sep 21 '12 at 05:18
  • Interesting - why would the CODE section need to be written too? – Adrian Cornish Sep 22 '12 at 01:21
  • Dynamic relocations. Shared libraries are loaded at runtime, and may contain references to other libraries or symbols. The process image contains placeholders for these symbols, and the dynamic linker (e.g. `ld.so` looks the symbols up during dynamic linking. – nneonneo Sep 22 '12 at 02:56
  • Thanks I understand - and I also understand I am out of my depth ;-) here EOT – Adrian Cornish Sep 22 '12 at 03:00
  • @nneonneo in fact the result is of the same with -x option or not – hugemeow Sep 22 '12 at 04:06
  • @nneonneo so lib is designed for sharing, why it may not be shared? – hugemeow Sep 22 '12 at 04:07