|
21 | 21 | \end{slide} |
22 | 22 |
|
23 | 23 | \begin{itemize} |
24 | | -\item each process has 3 basic segments (memory segments, not |
| 24 | +\item Each process has 3 basic segments (memory segments, not |
25 | 25 | hardware segments): |
26 | 26 | \begin{itemize} |
27 | 27 | \item text \dots{} program code |
28 | 28 | \item data \dots{} initialized variables |
29 | 29 | \item stack |
30 | 30 | \end{itemize} |
31 | 31 | \item \texttt{text} and \texttt{data} sections are saved in executable file |
32 | | -\item the sections for inicialized and non-initialized variables and heap are |
| 32 | +\item The sections for inicialized and non-initialized variables and heap are |
33 | 33 | considered as data |
34 | | -\item it is also possible to connect segments of shared memory |
| 34 | +\item It is also possible to connect segments of shared memory |
35 | 35 | (\texttt{shmat}) or files (\texttt{mmap}) into the address space. |
36 | | -\item the text is shared between all processes which execute the same code. |
| 36 | +\item The text is shared between all processes which execute the same code. |
37 | 37 | The data segment and stack are private for each process. |
38 | | -\item each system can use different layout of process address space |
39 | | -(and typically it is indeed so). See next slide which also shows |
| 38 | +\item Each system can use a different layout of a process address space |
| 39 | +(and typically it is indeed so). See the next slide which also shows |
40 | 40 | sections for \texttt{mmap} and \emph{heap}. |
41 | 41 | \item \emph{bss} \dots{} non-initialized variables (\texttt{bss} |
42 | 42 | comes from the IBM 7090 assembler and stands for \uv{block started by |
43 | 43 | symbol}). While the program is running, the \texttt{data}, \texttt{bss} and heap |
44 | 44 | sections (not shown in the picture) make up data segments of the process. |
45 | 45 | Heap size can be changed using the \texttt{brk} and \texttt{sbrk} system calls. |
46 | | -\item note -- non-initialized variables like static variables -- |
| 46 | +\item Note -- by non-initialized variables are meant static variables -- |
47 | 47 | i.e. global variables or variables declared as \texttt{static} both in the |
48 | | -functions and outside. All these variables are automatically initialized |
49 | | -with zeroes before the program is started. Therefore it is not necessary |
50 | | -to store their value in the binary. Once one of these variables is initialized, |
51 | | -it will become part of the data segment on disk. |
52 | | -\item \emph{(user) stack} \dots{} local non-static variables, |
53 | | -function parameters (on certain architectures in certain modes - e.g. 32-bit x86), |
54 | | -return addresses. Each process has 2 stacks -- one for user mode and another |
55 | | -for kernel mode. User stack automatically grows according to its use |
56 | | -(except for threads where each thread has its own limited stack). |
57 | | -\item \emph{user area (u-area)} \dots{} contains process information used by |
| 48 | +functions and outside that are not set to a value. All these variables are |
| 49 | +automatically initialized with zeroes before the program is started. Therefore |
| 50 | +it is not necessary to store their value in the binary. Once one of these |
| 51 | +variables is initialized, it will become part of the data segment on disk. |
| 52 | +\item \emph{(User) stack} \dots{} local non-static variables, function |
| 53 | +parameters (on certain architectures in certain modes - e.g. 32-bit x86), return |
| 54 | +addresses. Each process has 2 stacks -- one for a user mode and another for |
| 55 | +kernel mode. The user stack automatically grows according to its use (except |
| 56 | +for threads where each thread has its own limited stack). |
| 57 | +\item \emph{User area (u-area)} \dots{} contains process information used by |
58 | 58 | the kernel which are not needed when the process is swapped out to disk |
59 | 59 | (number of open files, signal handling settings, number of shared memory segments, |
60 | 60 | program arguments, environment variables, current working directory, etc.). |
61 | 61 | This area is accessible only to the kernel which will see just the area |
62 | | -of currently running process. The rest of data which is needed even if the |
63 | | -process is not currently running or is swapped out to disk, is stored in |
64 | | -\texttt{proc} structure. The \texttt{proc} structures for all processes |
65 | | -are always resident in mempory and accessible in kernel modes. |
| 62 | +of a currently running process. The rest of the data needed even if the process |
| 63 | +is not currently running or while swapped out to disk is stored in the |
| 64 | +\texttt{proc} structure. \texttt{proc} structures for all processes are always |
| 65 | +resident in memory and accessible in a kernel mode. |
66 | 66 | \end{itemize} |
67 | 67 |
|
68 | | - |
69 | 68 | \begin{slide} |
70 | 69 | \sltitle{Example: Solaris 11 x86 32-bit} |
71 | 70 | \begin{center} |
|
76 | 75 | \label{SOLARIS_PROC_ADDR_SPACE} |
77 | 76 |
|
78 | 77 | \begin{itemize} |
79 | | -\item the following is deductible from the image: |
| 78 | +\item The following is deductible from the image: |
80 | 79 |
|
81 | 80 | \begin{itemize} |
82 | 81 | \item maximum size of kernel for Solaris 11 x86 32-bit is 256 megabytes |
83 | 82 | \item there is free space between kernel and memory reserved for \texttt{mmap} |
84 | 83 | \item stack grows towards lower addresses and its size is limited to 128 megabytes |
85 | 84 | \end{itemize} |
86 | 85 |
|
87 | | -\item \emph{heap} is part of the memory that can be extended by the processes |
88 | | -using the \texttt{brk} and \texttt{sbrk} syscalls and is used by |
89 | | -the \texttt{malloc} function. |
90 | | -The \texttt{malloc} allocator gradually extends the heap based on demand, |
91 | | -and manages acquired memory and distributes to the process in chunks. |
92 | | -When \texttt{free} is called, it does not mean that the memory is returned |
93 | | -to the kernel; it is only returned to the allocator. |
| 86 | +\item A \emph{heap} is a part of the memory that can be extended by processes |
| 87 | +using the \texttt{brk} and \texttt{sbrk} syscalls and is used by the |
| 88 | +\texttt{malloc} function. The \texttt{malloc} allocator gradually extends the |
| 89 | +heap on demand, and manages acquired memory and distributes it to the process in |
| 90 | +chunks. When \texttt{free} is called, it does not mean that the memory is |
| 91 | +returned to the kernel; it is only returned to the allocator. |
94 | 92 | \item The \texttt{mmap} area is used for mapping files into memory, i.e. also |
95 | 93 | for shared libraries. Some allocators use also this memory internally, |
96 | | -e.g. in case process requests larger chunks of memory at once. |
97 | | -It is possible to exclusively use just \texttt{mmap}, it is transparent |
98 | | -to the application. When using \texttt{mmap} it is possible to return the |
99 | | -memory to the kernel (using \texttt{munmap}), compared to the |
100 | | -\texttt{brk}/\texttt{sbrk} based implementation. |
101 | | -\item The picture was taken from [McDougall-Mauro], and does not contain space |
102 | | -for non-initialized variables. If you try to print the address of such variable |
103 | | -on this system, you will find out that both initialized and non-initialized |
104 | | -variables share common data segment, on the image visible as |
105 | | -,,executable -- DATA''. |
106 | | -Example: \example{pmap/proc-addr-space.c} |
| 94 | +e.g. in case a process requests larger chunks of memory at once. It is possible |
| 95 | +to exclusively use just \texttt{mmap}, and that is transparent to the |
| 96 | +application. When using \texttt{mmap} it is possible to return the memory to the |
| 97 | +kernel (using \texttt{munmap}), in contrast to the \texttt{brk}/\texttt{sbrk} |
| 98 | +based implementation. |
| 99 | +\item The picture was taken from [McDougall-Mauro] and does not contain space |
| 100 | +for non-initialized variables. If you try to print the address of such a |
| 101 | +variable on this system, you will find out that both initialized and |
| 102 | +non-initialized variables share a common data segment, labeled in the image as |
| 103 | +,,executable -- DATA''. Example: \example{pmap/proc-addr-space.c}. |
107 | 104 | \item The kernel mapping is not necessary, for example on Solaris running on |
108 | 105 | \emph{amd64} architecture (i.e. 64-bit) the kernel is no longer mapped into |
109 | 106 | user space. |
110 | 107 | \item \texttt{brk} nor \texttt{sbrk} are part of the standard, hence portable |
111 | | -applications should not use them; if similar functionality is needed, they |
| 108 | +applications should not use them; if a similar functionality is needed, they |
112 | 109 | should use \texttt{mmap}, see page \pageref{MMAP}. |
113 | 110 | \end{itemize} |
114 | 111 |
|
115 | | - |
116 | 112 | %%%%% |
117 | 113 |
|
118 | 114 | \begin{slide} |
|
0 commit comments