Debian Codegraph @

help/C/memory-map-what.page

raw
1 <page xmlns="http://projectmallard.org/1.0/"
2 type="topic" style="task"
3 id="memory-map-what">
4
5 <info>
6 <revision pkgversion="3.11" date="2014-01-28" status="candidate"/>
7 <link type="guide" xref="index#memory" group="memory" />
8
9 <include href="legal.xml" xmlns="http://www.w3.org/2001/XInclude"/>
10
11 <credit type="author copyright">
12 <name>Phil Bull</name>
13 <email>[email protected]</email>
14 <years>2011</years>
15 </credit>
16
17 <credit type="author copyright">
18 <name>Michael Hill</name>
19 <email>[email protected]</email>
20 <years>2011, 2014</years>
21 </credit>
22
23 <desc>The memory map of a process can help diagnose certain memory
24 issues.</desc>
25 </info>
26
27 <title>What is a memory map?</title>
28
29 <comment>
30 <cite date="2011-06-18" href="mailto:[email protected]">Phil Bull</cite>
31 <p>Difficult conceptual topic. Explain how to use memory maps to do
32 whatever the hell you're supposed to use them for.</p>
33 </comment>
34
35 <comment>
36 <cite date="2014-01-28" href="mailto:[email protected]">Kat</cite>
37 <p>TODO: check gui tags.</p>
38 </comment>
39
40 <p><gui>Virtual memory</gui> is a representation of the combined
41 <gui>physical memory</gui> and <link xref="mem-swap">swap space</link> in a
42 system. It enables running processes to access <em>more</em> than the
43 existing physical memory by <gui>mapping</gui> locations in physical memory
44 to files on disk.</p>
45
46 <p>When a program is launched, the system assigns it a unique process ID
47 (PID) and its <em>instructions</em> and <em>data</em> are loaded into memory
48 in <em>pages</em>. The page table of each process maps the correspondence
49 between its pages in virtual memory and their location in physical memory.
50 The <gui>memory map</gui> displays the total virtual memory use of the
51 process, and can be used to determine the memory cost of running a single or
52 multiple instances of the program, to ensure the use of the correct shared
53 libraries, to see the results of adjusting various performance tuning
54 parameters the program may have, or to diagnose issues such as memory
55 leaks.</p>
56
57 <p>If multiple copies of a program are running, the instructions (or
58 <em>text</em>) of the program only need to be loaded once into physical
59 memory. Each time a new instance of the program is launched (as a unique
60 process with its own virtual memory pages), its page table maps the location
61 of the text in virtual memory to those instructions in the original real
62 memory location. In addition, any dynamic shared libraries used by the
63 process appear as distinct in virtual memory, but are shared references to a
64 single copy of the library's text segment in real memory. When accounting for
65 the total memory use of a process, it is important to note that the cost of
66 shared libraries loaded into memory can be spread across all processes
67 currently using them.</p>
68
69 <p>When the system needs more pages of memory than are available, some of the
70 existing pages will be <em>paged out</em> or written to the <gui>swap
71 space</gui>. Text pages are flagged read-execute in memory and don't need to
72 be written to swap since they can be re-loaded from their original location
73 on disk. Data pages have read-write permissions, and if modified when in
74 memory, they are labeled <em>dirty</em>, and when designated for swapping,
75 must be paged out. When a page in swap space is required by a running
76 process, it needs to be swapped back in before use, perhaps causing another
77 page to be paged out.</p>
78
79 </page>