[Linux] Program address space, virtual address, memory management method

Program address space

Virtual address space

Address: Generally speaking, the address is the address of the memory, that is, the number of the memory unit.
In the process, these addresses (variable addresses, etc.) accessed by the program are actually fake addresses, which are called virtual addresses ;
what we call the program address is actually called the virtual address space of the process (the program does not occupy memory, but the process occupies RAM)

The virtual address space is actually a fake address space described by the system to the process , which is a mm_struct structure

The system will describe a virtual address for each process. All the
processes access are virtual addresses. The virtual address is converted to a physical address and then accessed.

Page table mapping

Insert picture description here

Observe the above picture: Now there is a 16M memory and three programs with a memory size of 4M, 8M, and 5M respectively. Because the process needs to use continuous memory space to run, the above process cannot run, but through the page table After mapping, it can run normally.

Page table mapping: Give each process a virtual address space, allowing the process to access complete and continuous addresses, but when these virtual addresses are used, a physical memory address is mapped through the page table. Page table mapping realizes the discrete storage of data in physical memory , making the process think that it is running in continuous and complete memory, which improves the utilization of memory.

Memory management method

Segmented memory management : divide the address space into multiple segments (heap, stack, data segment, code segment...) to facilitate the address management of the compiler.
Segmented virtual address composition : segment number + segment address offset; in the system There is a segment table (segment number, physical memory segment starting address)

Paged memory management : divide the address space into multiple small blocks (pages) to improve memory utilization.
Paged virtual address composition : page number + page offset (under a 32-bit address, the upper 20 bits are the page number, the lower 12 The bit is the offset within the page); there is a page table in the system (page number, physical memory fast starting address, access control authority, page fault interrupt bit...)

Segmental paging memory management : segment the virtual address space and perform paging management in each segment, which combines the advantages of segmentation and paging

Guess you like

Origin blog.csdn.net/weixin_43962381/article/details/114895815
Recommended