1

I know that pmap of a process shows how the memory mapping is done. For example, the first lines of pmap output shows the memory mapping to the text segment of the process' executable. Assume I have a really big executable and my code size is large. For a small text segment(small executable) the pmamp shows 400000 - 401000 - 4096 B - 4 KiB of text segment mapped.

(1) If the text segment is really large how does it map? (2) Is it map dynamically based on the pages required as part of the code execution progress?

Franc
  • 229
  • 3
  • 15

1 Answers1

0

Sections in the executable that are needed at runtime are mapped as-is, with mappings covering the full extent of each section; the corresponding pages are only loaded as required, but the mappings have to exist ahead of time for that to happen.

For example, with Emacs, I see

0000000000400000     88K r---- emacs-26.3
0000000000416000   2044K r-x-- emacs-26.3
0000000000615000    372K r---- emacs-26.3
0000000000672000     32K r---- emacs-26.3
000000000067a000  36560K rw--- emacs-26.3

The text segment is the 2044KiB r-x segment, which corresponds to the .text section in the executable (as shown by e.g. size -A):

section                     size       addr
...
.text                    2049234    4324272
...
Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164