Memory Management-virtual memory (note)

Source: Internet
Author: User
Tags field table

I. Terms of virtual memory

 

Virtual Memory

In the storage allocation mechanism, although the standby address is a part of the primary memory, it can also be addressable. The address used by the program to reference the memory is different from the physical address used by the memory system for identification. The address generated by the program is automatically converted to the machine address. The size of virtual storage is limited by the addressing mechanism of the computer system and the amount of available backup memory, and is not limited by the actual quantity of internal storage locations.

Virtual Address

The address allocated to a specific location in the virtual memory so that the location can be accessed, as if it was a part of the primary memory.

Virtual Address Space

Virtual storage allocated to processes

Address Space

Memory Address range that can be used for a process

Real address

Address of the storage location in the memory

Ii. Features of segmentation and paging (virtual and non-virtual)

Simple Paging

Virtual Paging

Simple Segmentation

Virtual Segmentation

The memory is divided into small blocks of fixed size and becomes a page frame.

The memory is divided into small blocks of fixed size and becomes a page frame.

Memory not divided

Memory not divided

Programs are divided into pages

Programs are divided into pages

The programmer specifies the program segment for the compiler.

The programmer specifies the program segment for the compiler.

The page contains internal fragments.

The page contains internal fragments.

No internal fragments

No internal fragments

No external fragments

No external fragments

External fragments exist.

External fragments exist.

The operating system must maintain a page table for each process.

The operating system must maintain a page table for each process.

The operating system must maintain a field table for each process to describe the loading address and length of each segment.

The operating system must maintain a field table for each process to describe the loading address and length of each segment.

The operating system must maintain a free page box page table

The operating system must maintain a free page box page table

The operating system must maintain a void list in the memory.

The operating system must maintain a void list in the memory.

The processor uses the page number and offset address to calculate the absolute address.

The processor uses the page number and offset address to calculate the absolute address.

The processor uses the field number and offset to calculate the absolute address.

The processor uses the field number and offset to calculate the absolute address.

When the process is running, all pages must be in the memory, unless overwrite technology is used.

When a process is running, not all pages must be in the Memory Page box, but only read pages as needed.

All segments must be in the memory when the process is running, unless overwrite technology is used

When a process is running, not all segments must be in the memory.

 

To read one page into the memory, you may need to write another page to the disk.

 

To read a segment into the memory, you may need to write another segment or segment to the disk.

III,System Jitter

When using the virtual memory, instead of calling all the process pages to the memory, you only need to call enough pages in the memory. When you need to access the program pages in the external memory, you can call it again. This reduces the memory space of a process. More processes can be loaded into the main memory to improve the utilization of other devices in the computer system. However, when the page switching algorithm is unreasonable, if a page has just been transferred out of memory, it will be accessed again below, so that if this happens frequently, the processor spends most of its time switching pages between memory and memory instead of executing commands. This is called "system jitter ".

Iv. Address Translation

1. address translation in the paging system

 

The basic principle of paging storage management is to divide the primary storage space and secondary storage space into several equal pages. The page size is a byte, such as (1 kb), (2 kb ), (4 kb), and specify a page number for each page in order, that is, 0 pages, 1 pages, 2 pages ,.... For ease of description, the primary page (physical page or absolute page) is called a page. For example, if the primary storage space is 8 KB, the secondary storage space is 16 KB, and the page size is 1 kb, the primary storage space can be divided into 8 pages, and the page number is 0 ~ 7. The secondary storage space can be divided into 16 pages with a page number ranging from 0 ~ 15. When the program is running, address ing is performed on "pages". That is, the operating system transfers the logical page from the secondary storage to the primary storage, which is stored on the physical page for CPU execution. In the paging storage management mechanism, the logical address corresponding to the logical page is called a linear address.

In paging storage management, the key problem to be solved is: which physical page should be selected to store the transferred logical page? How do I convert a linear address to a physical address? To solve these problems, the system creates a page table for each page and stores several page information in the primary storage, such as page number, capacity, whether to load the primary storage, and which page is stored in the primary storage.
When the CPU accesses a page, it first needs to look up the page table to determine whether the page to be accessed is in the primary storage. If the primary storage is hit, otherwise it is not hit. Then, the missed pages are transferred from the secondary storage to the primary storage according to a scheduling algorithm, and the linear address is converted to the physical address based on the correspondence between the logical page number and the stored physical page number.
The location of the page table in the memory is located by the page table address register. The status information recorded in the page table is 1st page numbers indicating the logic page. The 2nd feature bit records whether the logic page is loaded into the primary storage. The "0" indicates that the page is not loaded, "1" indicates that the logical page has been loaded; 3rd Items Record the page number of the physical page where the logical page is loaded into the primary storage, that is, after the logical page 1 is transferred to the primary storage from the secondary storage, stored on the 7th physical page.
The physical address of a storage unit consists of a page number and an address in the page. The address in the 8 KB primary storage page is from the address line A9 ~ Provided by A0, it can address 1 kb of page storage space. The address range is 0 ~ 1 023; the page number is from A12 ~ Provided by A10, the number of pages on the 8 pages is 0 ~ 7. It can be seen that the physical address of the page storage unit is
Physical address = page size x page number + page address
The method for determining a linear address is exactly the same as that for determining a physical address. It is also composed of a page number and a page address, as shown in 5.37 (B. The 16 KB sub-storage space can be divided into 16 pages. The address in the page is from the address line A9 ~ Provided by A0, its page number is 0 ~ 15 from the top 4 address lines A13 ~ Provided by A10.


During address translation, because the logical pages and physical pages are of the same size, the addresses in the pages are the same and the page numbers are different, you only need to convert the page number of a linear address to the page number of a physical address. In Figure 5.36, the logical address of a command on the logic page 1 to access data is 1024 × 1 + 452 = 1 476, it is saved to the primary storage 7 page and the corresponding physical address is 1 024 × 7 + 452 = 7 620.

 

2. address translation in the segmentation system

The basic principle of segmented storage management is that the segments are divided by the logical structure of the program. The length of each segment varies with the program. To describe the attributes of a logical segment, the system creates a field table (resident in memory) for each segment to record some information about the segment, such as the field number, start point, length, and loading of segments. The CPU checks whether the segment has been transferred to the primary storage by accessing the segment table, and completes the conversion between the logical and physical addresses.

The logical address consists of the segment number S and the segment address W. The segment number S is equivalent to the segment name of the logical segment, which indicates the start address of the logical segment. During address translation, the operating system uses s to retrieve the segment table. Information 1 recorded in the segment table indicates that the segment has been transferred to the primary storage, and B indicates the starting address for loading the segment into the primary storage, therefore, the physical address corresponding to the logical address is B + W.
In the management of segmented storage, because the division of segments corresponds to the natural division of programs, it is logically independent and easy to compile, manage, modify, and protect programs, it also facilitates multi-program sharing. However, the segment length is uneven, and the start and end points are not fixed, which makes it difficult to allocate the primary storage space. It is easy to leave unused "headers" between segments, resulting in waste.

 

3. Address Translation in a segment-page System

 

The main feature of paging storage management is that the primary storage has a high utilization rate and is easy to manage secondary storage, but the modular performance is poor. The main feature of segmented storage management is that the modular performance is good, however, the primary storage utilization is not high and it is difficult to manage the secondary storage.

Segment-page storage management is a compromise between Segment Storage Management and paging storage management. It first divides the program into several logical segments of varying sizes according to its logical structure, and then divides each logical segment into several logical pages of the same size. The primary storage space is divided into several physical pages of the same size. Information scheduling between the secondary storage and primary storage takes pages as the basic transmission unit. Each program segment corresponds to a field table, and each page corresponds to a page table. During CPU access, the segment table indicates the address of the page table corresponding to each segment. The page table of each segment determines the location of the primary storage space where the page is located, and finally concatenates it with the address in the page table, determine the physical address of the CPU to access the Unit

The management of segment-page storage combines the advantages of segment management and page management, but it takes a lot of time to complete address conversion only after two levels of table queries.

V. Replacement Strategy

Replacement algorithms include: the best replacement algorithm opt, FIFO replacement algorithm, least page replacement algorithm, recently unused page replacement algorithm, and clock page replacement algorithm.

The OPT algorithm is a theoretical algorithm.It switches out pages that are no longer used, but cannot predict which page is no longer used. However, this algorithm is the optimal algorithm and can be used to evaluate the performance of other algorithms.

FIFO Algorithm: Replace the page according to the time when the page is loaded into the memory. The older the page, the first to be swapped out, no matter whether the page is frequently used or not, this may lead to an increase in the page missing rate, resulting in an increase in the number of page replacements.

Least use of the page replacement algorithm: Sort by the time used last time. swap out the page with the longest time used last time. You can use the stack data structure. Each time the page is accessed, place the page number on the top of the stack.

Recently, the page replacement algorithm is not used: Set the reference bit R. R = 1 for each call, and r = 0 for each period of time, if the replacement check page is zero, it means it will not be used in the near future. You can swap it out.

Clock page replacement algorithm: The application is R. When r = 1 indicates that it has been referenced. This method is a FIFO improvement. Based on the memory loading time and whether it has been referenced, first, check the longest time item. If r = 0, replace it. If it is 1, check the next item and set R = 0. If all r = 1, replace according to the FIFO method.

After selecting the replacement page, how do I replace it?

First, check whether the replaced page has been modified. If not, you can directly erase the page. If you have modified the page, you must first save it to the external store and then read it into the new page.

Page buffering technology: Do not save it first, Because I/O operations are added each time a page is saved, which consumes too much. The buffer technology can store modified and unmodified pages in a buffer, and save modified pages in batches to reduce Io operations. Unmodified pages are buffered to prevent recent calls and do not need to be transferred from external memory to memory. If not called for a period of time, the cache is cleared in batches.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.