Understand storage management

Memory is one of the most important resources in a computer system. Because any program and data as well as various control data structures must occupy a certain amount of storage space, storage management directly affects system performance.
Storage consists of internal memory and external memory. Memory is a continuous address space composed of storage units (often referred to as bytes) actually provided by the system, which can be directly accessed by the processor. External storage (auxiliary storage) refers to some external storage components such as floppy disks, hard disks, optical disks and tapes, which are often used to store programs and data that are not yet executed. The processor cannot directly access external memory. It needs to activate the I/O (Input/Output, input/output) device to exchange memory and external memory. Its access speed is slow, but it is cheap and is often used as a backup device for memory.
The memory size is determined by the system hardware, and the storage capacity is limited by the actual storage unit. Virtual memory (referred to as virtual memory) does not consider the size of the actual memory and the actual address of data access. It only considers the relative position between related data. Its capacity is determined by the number of bits in the computer address.
The use of memory in the system is generally divided into two parts. One part is the system space, which stores the operating system itself and related system programs; the other part is the user space, which stores the user's programs and data.
Storage management mainly refers to the management of internal memory, and is responsible for the allocation and recycling of memory, memory protection and memory expansion. The purpose of storage management is to maximize memory usage efficiency. The storage management mechanism has undergone many changes, from the previous single continuous area management to partition storage management and then to segmented page management. At present, the first two technologies have been gradually phased out. Below we will explain segmented page storage management in detail.
1. Page storage management
The basic idea of ​​paging is to divide the logical space of the program and the physical space of the memory into several pages of the same size, and allocate them in units of pages. In page storage management, the virtual address in the system is an ordered pair (page number, displacement). The system establishes a page table for each process, whose content includes the correspondence between the logical page number and the physical page number of the process, status, etc.
The dynamic address translation of the page system is carried out as follows: when the process is running, the first address of its page table is already in the basic address register in the system's dynamic address translation mechanism. When the executed instruction accesses the virtual memory address (p, d), it first checks the page table according to the page number p. From the status, it can be known whether this page has been transferred into the memory. If it has been transferred into the memory, the memory location p’ of the page is obtained, and then combined with the relative displacement d within the page, the physical address r is obtained. If the page has not yet been loaded into memory, a page fault interrupt is generated to load the required page, as shown in Figure 2-5.
Logical address, or virtual address (page number || address within page)
Physical address (page frame number (physical block number) || address within page)
Logical address<-Conversion->Physical address: The address in the page is the same, the corresponding relationship between page number and block number can be queried in the page table
Insert image description here
Page virtual Storage management implements virtual memory based on page storage management. First, the job information is stored as a copy on the disk. When the job is executed, some pages of the job information are loaded into the internal memory. If the accessed page is already in the memory when the job is executed, address translation is performed according to the page storage management method. Obtain the absolute address of the memory to be accessed. If the page to be accessed is not in the memory, a "page fault interrupt" is generated, and the operating system loads the currently required page into the internal memory.
For this reason, when loading a job, it should be indicated in the page table of the job which pages are already in the internal memory and which pages have not yet been loaded into the memory. A flag bit can be used to indicate whether the corresponding page is in memory. It can be assumed that a flag bit of 1 means that the page is in memory, and a flag bit of 0 means that the page has not been loaded into memory. In order to easily find the copy of the job information from the disk, the page table can also indicate the location of each page copy on the disk.
When loading a currently required page, if there is no free block in the internal memory, you can select a page that is already in the internal memory and temporarily call it out of the memory. If the page has been modified during execution, the page information is rewritten back to the disk, otherwise there is no need to rewrite it back to the disk. When a page is temporarily transferred out of memory, the memory space released is used to store the page currently needed.
When the page that is called out is used again in the future, another page can be called out in the same way and loaded into the memory again. After the page is called out or loaded, the corresponding entries in the page table must be modified.
When there is no free block in the memory, in order to load a page, a page must be selected from the pages already in the memory according to a certain algorithm, and it can be temporarily transferred out of the memory to make room for the memory. To store the pages that need to be loaded, this work is called "paging". How to select the page to be called out is very important. If an inappropriate algorithm is used, the following phenomenon will occur: the page that has just been called out will be used immediately, so it must be loaded again, and it will be loaded shortly. It is selected and called out again, and is loaded again soon after it is called out. This repeats, making scheduling very frequent. This phenomenon is called "jitter". A good scheduling algorithm should reduce or avoid jitter. Commonly used page scheduling algorithms are:
(1) Optimal (OPT) algorithm. Selecting pages that are no longer used or will be used in the farthest future is an ideal algorithm, but it is difficult to implement and is often used in comparisons of elimination algorithms.
(2) Random (RAND) algorithm. Randomly selecting eliminated pages costs little, but may select pages that will be accessed immediately.
(3) First-in-first-out algorithm. Selecting the page that has been in memory the longest may seem reasonable, but may eliminate frequently used pages. In addition, when using the FIFO algorithm, when the process is not allocated enough pages, sometimes the number of pages allocated to the process increases, and the number of page faults increases instead. The FIFO algorithm is simple and easy to implement. The page numbers of the pages loaded into the internal memory can be queued in the order in which they are entered. The page at the head of the queue is always called out every time. When a new page is loaded, the page number of the new page is queued at the end of the queue. .
Figure: Calculation example. Title 123 is the three pages in the memory, title 4321... is the page (page number) that needs to be accessed, and the text of the table is the content currently saved in the three spaces of the memory.< /span> Virtual (logical) address: (segment number, displacement) The segment table includes: segment number/segment length/base address Segment storage management is similar to page storage management. The basic idea of ​​segmentation is to divide user tasks into logically complete segments, and use segments as units as the spatial scale for internal and external memory exchange. 2. Segment storage management
Insert image description here
(4) Least Recently Used (LRU) algorithm. Selects the least used page in the period closest to the current time. The main starting point of this algorithm is that if a page has been accessed, it may be accessed soon; conversely, if a page has not been accessed for a long time, it will not be accessed in the recent period. A job is composed of several logically meaningful segments (such as main program, subroutine, data segment, etc.). In a segmented system, programs (jobs) are allowed to occupy many separate partitions of memory. Each partition stores a program segment. In this way, each job requires several pairs of bounded address registers, making it more difficult to determine whether the accessed address is out of bounds. In segmented storage systems, storage protection keys are often used to implement storage protection. The virtual address in a segmented system is an ordered pair (segment number, displacement). The system creates a segment table for each job, whose contents include segment number, segment length, memory starting address and status, etc. The status indicates whether this segment has been transferred into the memory, that is, the starting address of the memory indicates this segment, and the status indicates the access rights of this segment.





Insert image description here

The dynamic address translation of the segmented system is performed as follows: when the process is executed, the first address of its segment table is already in the base address register, and the executed instruction accesses virtual memory (s, d) (fetch instruction or fetch operand), first check the segment table according to the segment number s. If the segment has been transferred into the memory, the memory starting address of the segment is obtained, and then added to the relative address within the segment (the offset within the segment d) to obtain the actual address. If the segment has not been loaded into memory, a missing segment interrupt is generated to load the required segment. The address translation methods of segment storage and page storage are similar, see Figure 1-6.
Segmented virtual storage management is still based on segmented storage management, providing users with a virtual space larger than the actual memory capacity. Segmented virtual storage management retains each segment information in the job on the disk. When the job can be put into execution, do the following operations:
(1) First, save the currently required segment or segments. The segment is loaded into memory.
(2) When the job is executed, if the segment to be accessed is already in the memory, the address translation is performed according to the method in "Segment Storage Management"; if the segment to be accessed is not in the memory, then A "missing segment interrupt" is generated, and the operating system loads the currently required segment into memory.
Therefore, a flag should be added to the segment table to indicate whether the segment is in memory and the location of each segment on the disk. For segments that are already in memory, the starting address of the segment in memory must still be pointed out. and occupied memory area length.
When the job executes the segment to be accessed, the address translation mechanism of the hardware looks up the segment table. If the segment is in the memory, the logical address is immediately converted into an absolute address; if the segment is not in the memory, a "missing segment interrupt" is formed, and the operating system handles this interrupt.
The solution is to check the memory allocation table to find a contiguous area large enough to accommodate the segment. If a contiguous area large enough is not found, check the total number of free areas. If If the total number of free areas can meet the requirements of the segment, then perform appropriate moves to concentrate the scattered free areas; if the total number of free areas cannot meet the requirements of the segment, you can call out one or more segments in the memory, and then load the segment currently to be accessed. into memory. After a segment is moved, called out, and loaded, the corresponding entries in the segment table must be modified. After the new segment is loaded, the job should be allowed to re-execute the interrupted instruction. At this time, the segment to be accessed can be found and execution can continue.
3. Segment page storage management
Segment page management is the product of the combination of segment and page management methods. It combines the characteristics of segment organization and page organization. According to the program module segmentation, Paging is performed within the segment, and the memory is divided into fixed-length pages. The form of the virtual address in the segment-page system is (segment number, page number, intra-page offset), as shown in Figure 2-6. The system creates a segment table for each process and a page table for each segment. Segment page management adopts segment allocation and page usage methods to facilitate dynamic connection and dynamic allocation of storage. This storage management can improve memory space utilization.
Insert image description here
Segmented virtual management still allocates memory space in units of segments. The entire segment is called out, loaded, and sometimes moved, which increases the system overhead. If each segment is divided into several pages according to the segment-page storage management method, then each segment does not need to occupy continuous storage space; even when the memory block is not enough, only some pages in a segment can be loaded into the memory. The management method is called "segment page virtual storage management".
Segment page virtual storage management creates a segment table for each job loaded into memory, and also creates a page table for each segment. The segment table indicates the storage location and length of the segment's page table. The page table should indicate the location of each page of the segment on the disk and whether the page is in memory. If it is in memory, fill in the occupied memory block number. When the job is executed, the segment table is looked up according to the segment number, the corresponding page table is found, and then the page table is looked up according to the page number. The flag bit is used to determine whether the page is already in the memory. If so, address translation is performed; otherwise, page scheduling is performed. The address translation process is shown in Figure 2-7.
Insert image description here
Segment page virtual storage management combines the advantages of segment and page, but increases the overhead of setting tables (segment table, page table) and table lookup. Segment page virtual memory generally only Used in large computer systems.

Guess you like

Origin blog.csdn.net/miachen520/article/details/134903856