Segmentation Mechanism
A segment is a virtual space that maps the size of memory space required by a program to a physical address space through the ing mechanism (the hardware completes the ing operation ). The field ing mechanism solves two problems existing in the operating system: (1) the address space is not isolated. (2) The program running address is unknown. In the paging method, the space required by the program is allocated in the memory. Therefore, the space is either swapped in or out; there is no problem of applying for more memory due to insufficient memory.
However, the segmentation method has a serious problem: the memory usage efficiency is low. The unit of memory ing in segments is the entire program. If the memory is insufficient, the space to be swapped out to the disk is the space required by the entire program, which causes a large number of disk access operations, and significantly reduced the running speed. In fact, in many cases, the data required for running the program is only a small part. The size of the data added to the memory may be small, and it is not necessary to write and write data as a whole.
For example, the field ing mechanism is described (Image Source: Click to open the link)
Paging Mechanism
The paging mechanism solves a memory usage efficiency problem in the preceding segmentation method. The core idea is that the system allocates page Y in the memory for page X in the program execution file, at the same time, page y is added to the ing table (page table) of the virtual space address of the process, so that the program can access the memory page y through ing.
The basic method of paging is to artificially divide the address space into a fixed page. The size of each page is determined by the hardware, or it is determined by the operating system (if the hardware supports multiple pages ). Currently, pages with a size of 4 kb are the choice of most PC operating systems.
Process paging. When we split the virtual address space of a process by PAGE, common data and code will be installed in the memory; data and code that are not used for the moment will be stored on the disk, when necessary, load the data from the disk to the memory. Here we need to understand three concepts: 1. virtual page (VP, virtual page), page in virtual space; 2. physical page (PP, physical page), pages in physical memory; 3. disk page (DP, disk page.
The implementation of virtual memory requires hardware support, from virtual address to physical address ing, through a component named MMU (memory mangement unit.
(For xiaomo's Reading Notes, refer to "programmer's self-cultivation". repost the original source. Thank you ).