[Linux] 10. Process address space

1. Derivation of virtual address

insert image description here

2. Perceptual understanding

insert image description here

3. Regional division

Before understanding the virtual address space, first understand what area division is.
insert image description here
During the 38th line in elementary school, the table was divided into two areas. The analogy is that the address space is also divided in this way.
The operating system needs to manage the process. Different areas of the process map different virtual addresses.
insert image description here
The size of this virtual address space is 2 to 32 bytes. The so-called area adjustment of heap (heap)/stack (stack) is essentially to modify each The end or start of the area
defines local variables (push the stack) or the space on the malloc/new heap ------> expand the stack area or the heap area
function call (pop the stack) or free release resources ----- -> Reduce stack or heap space

4. Rational understanding

insert image description here
(The page table is not only a simple mapping but also can intercept illegal access to the physical address space)

5. The reason for the existence of virtual address space

5.1 Security and Independence

insert image description here

5.2 Compiler and CPU

insert image description here
Let the process view the code and data corresponding to the process from a unified perspective, which is convenient for CPU use, and the compiler also compiles the code from a unified perspective. The rules of the two are the same, and it can be used after
compilation

It is the above three reasons that lead to the existence of virtual addresses, mainly to protect code and data, so that processes do not disturb each other when they are running.
When we use vs2019 to debug under the windows operating system and run it for debugging, the registers inside the CPU use virtual addresses (the monitoring window displays virtual addresses &xxx)

6. Solve the problem of parent-child process independence

At the beginning, our problem was derived from the concept of virtual address space with different values ​​when accessing the same address space through the parent and child processes. Now we need to explain this phenomenon. The virtual address space of the parent and child processes is the same, but the child process modifies the
insert image description here
global Data leads to copy-on-write, and the virtual addresses of the two do not point to a physical address space.
Therefore, the same address seen on the monitor has different values ​​(the same address refers to the virtual address space). Only
here can we really understand the process. independence.
It is precisely because of the independence of the process that a process modifies the shared data, and if it affects other processes, it cannot be called independence

expand

The logical address of the current computer uses 232 address spaces to separate the code area and data area (ELF format). The
old version of the computer code area and data area uses the form of offset.
Every time it is converted into a physical address It is obtained based on the area plus the offset
insert image description here

Guess you like

Origin blog.csdn.net/weixin_60915103/article/details/130616185