Article directory
The theory in this chapter is based on the version kernel
32
of the bit platformLinux
kernel 2.6.32
1. Structure of Linux process address space
-
to ensure thatmemory safety, modern operating systemsnot allowedApplications (processes) directly access physical memory space
-
Generally speaking,Operating systems and compilerswill giveevery processset upA separate virtual memory spaceanda mapping page table, the virtual memory space is called the process address space,virtual memory addressThrough a specific mapping relationship withphysical memory addressbuild connection
-
Linux
The process address space is0x00000000 ~ 0xffffffff
numbered and has the following structure: -
Instructions in the process want to accessphysical memory, it is necessary to rely onvirtual memory addressmapping, processVirtual address and physical memorypasspage tableTo map:
-
From an application layer perspective,application codeneutralVariables and functions(data) memory address andinstruction itselfmemory addressAll are virtual memory addresses!!!All of thesevirtual memory addressas well asTheir mapping relationship to physical memory addressesThis is determined when the application is compiled, soProcess virtual memory mechanismEssentially, it is a memory management mechanism formed by the cooperation of the operating system and the compiler.
- When the CPU executes instructions internally, the memory address used is also a virtual memory address.
2. How Linux manages process address space
- every processEach has its own independentprocess address spaceandmapped page table
Linux
In the kernel, the process address spacestruct mm_struct
is maintained by one, andPCB
the structure (process control block) of each process points to astruct mm_struct
structure:struct mm_struct
Structure maintenanceprocess address spaceThe specific method is similar toUse pointers to maintain address ranges:- When multiple processes are loaded in the memory, there will be multiple
struct mm_struct
structures andmapped page table,thereforeLinux
process address spaceThe essence isstruct mm_struct
the structure andmapped page tableconstitutedKernel data structures
3. The model of Linux process using physical memory
Linux
The existence form of processPCB
(task_struct
) and process address space ( ):mm_struct
- How the process instruction set accesses physical memory:
4. The significance of the existence of process address space
- With the help ofmapped page tableThe operating system canDeny requests for illegal memory access by application processes, ensuring the memory security of the computer system
- In the sense of operating system design,virtual memory mechanismmake the operating systemMemory management moduleandProcess management moduleComplete understanding of coupling whenMemory management algorithmWhen adjustments are needed, it will not affectProcess management moduledesign (just modify the physical address in the mapped page table), similarly, whenProcess management moduleWhen redesign is required, it will not affectMemory management module
- virtual memory mechanismIn fact, it is a kind ofDelayed allocation strategy for physical memory, when the process
PBC
andInstruction SetAfter being loaded into memory, the operating system will not allocate physical memory to the objects in the process immediately (even if each object in the process has a virtual address), only when the process assignsPerform read and write operationsThe operating system will allocate physical memory to the object through page table mapping. This delayed memory allocation strategy improvesDuring the concurrent execution of each processComputer memory usage efficiency - becauseprocess virtual address spaceexistence, from the perspective of the application,The memory address of each objectThey are all arranged in an orderly and compact manner, allowing developers toMore convenient memory operations, at the same time the operating system can also more convenientlyMonitor and manage memory usage by processes, to achieve instant allocation and release of physical memory.