1. Discrete distribution Method
----Continuous allocation (partitioned storage management) requires that jobs be placed in a contiguous storage area, resulting in many "fragments ", where fixed partitions produce internal fragmentation, and dynamic partitioning creates external fragmentation. Although a "compact" method can be used to stitch many fragments into usable chunks of space, there is a lot of overhead involved. If you allow a process to be loaded directly into many non-contiguous partitions, you do not need to be "compact". Based on this idea, a discrete distribution method is produced. If the base unit of a discrete allocation is a page , it is called paging storage management, and if the base unit of a discrete allocation is a segment , it is called a segmented storage Management method.
---- in the management of paging storage, if you do not have a page swap function, it is called basic paging storage management, or pure paging storage management. It does not have the capability to support virtual storage , which requires that each job be loaded into memory before it can be run.
2. Page and Page table
----pages and physical blocks
Paging storage management is to divide the logical address space of a process into several equal-sized slices, called pages or pages, numbered for each page, starting with 0, such as page No. 0, page 1th, and so on. Correspondingly, the memory space is divided into a number of storage blocks of the same size as the page, called (physical) block or page frame (frame), also numbered, such as 0# block, # block, and so on. When allocating memory for a process, several pages in a process are loaded in blocks into multiple physical blocks that can not be contiguous. Because the last page of the process often does not have a piece of it, it forms an unusable fragment called " in-page fragmentation ."
----Page Size
The page size in the paging system should be moderate. if the page is too small , on the one hand, although it can reduce memory fragmentation , it is helpful to improve memory utilization . But on the other hand, it also makes each process occupy more pages, which causes the process's page table to be too long (page number, block number), consumes a lot of memory, and reduces the efficiency of page swapping . If the page is large , although it can reduce the length of the page table, improve the speed of the page swap, but will increase the amount of fragmentation in the page . Therefore, the page size selection should be moderate, and the page size should be a power of 2, usually 512b~8kb.
----Address Structure
The address structure in the paging address has two parts: the first part is the page number P, and the latter part is the amount of displacementin the page W (or called in-page address ). As shown in the following illustration: If the logical address space is 2 m, the page size is 2 N (bytes), then the high m-n bit of the logical address is the page number, and the low n bit is the offset within the page.
In the above address structure, the address length of the two parts is 32 bits, where the 0~11 bit (12 bits) is the in-page offset , that is, the =2^12=4kb;12~31 bit per page size (20 bits) is the page number, that is, the maximum number of pages (page table items) =2^20=1mb. In-page offsets are also known as intra-page displacements, page offsets, or in-page addresses. For a particular machine , its address structure is certain . If the address in the given logical address space is a, the size of the page is L, then the page number P and the page address W can be evaluated as follows: P=int (a/l) w= (A) MOD (L) where INT is the divisible function and MOD is the take -over function.
For example, the system's page size is 1KB (1024B), a=2170b is set, then p=2,w=2170-2048=122 is obtained.
----Page Table
In a paging system, each page of a process is allowed to be stored discretely in a different physical block of memory , but the system should be able to ensure that the process runs correctly, that is, the physical block corresponding to each page can be found in memory, The system also establishes a page image table for each process, referred to as the page table .
All pages in the process address space (0~n), in turn, have a page table entry in the page table that records the corresponding physical block number of the page in memory. After the page table is configured, when the process executes, it finds the block number of each page in memory by looking up the page table , which is the role of the page table to implement the address mapping from the page number to the physical block number . Even in a simple paging system, an access control field is often set up in table entries in the page table to protect the contents of the block.
- When only one of the access control fields is available, it can be used to specify whether the contents of the block are allowed to read/write or read-only.
-- when the Access control field is two bits, it can be specified as read/write, read-only, and only execute access mode.
If a process attempts to write a block that is read-only, it will cause an interruption in the operating system. If you want to use the paging system to implement virtual memory, but also in the page table to add the status bit/modify bits and other data items for the page swap out the reference, in particular, see the request Paging Storage management mode . http://blog.csdn.net/dongyanxia1000/article/details/51727339
In order to achieve the above convenience, a page table register (ptr,page Table Register) is set up in the system, which holds the page table at the start address of the memory F and the length of the page table m . when the process is not executed , the starting address and length of the page table are stored in the Process Control block (PCB) . The page table start address and length are saved in the page table register when the process executes.
Assuming that the page size is L, the page table length (Number of page table items) is M, the process of logical address A to get physical address e through address transformation is as follows:
--1) calculates the page number p= (int) (A/L), and the in-page offset w=a%l.
--2) Compare page number P (theoretical value 0~m-1) and page table length m, if p>= m, generates an out-of-bounds interrupt, otherwise go to the next step.
--3) page table in page number p corresponds to the address of the page Table Entry = Page Table start address F + page number p x page table item size, take out the contents of the physical block number B in the page table item.
--4) calculates e=bxl+w (the size of the page is the size of the physical block, and the address inside the page is the address within the physical block)
--5) uses the resulting physical address E to access memory.
The entire address transformation process is done automatically by the hardware. The address transformation process is shown in the following figure: