Modern operating system notes-storage management 2

Source: Internet
Author: User

Reprint Please specify: theviper http://www.cnblogs.com/TheViper

Speeding up the paging process

In any paging system, there are two issues to consider:

1. Virtual address-to-physical address mapping must be very fast

2. If the virtual address space is large, the page table will be very large

The need for large and fast page mappings has become an important constraint on building computers, and the simplest design is to use a single page table consisting of a set of "fast hardware registers", each of which corresponds to a virtual page and a virtual page number as an index. The advantage of this approach is that it is simple and does not require access to memory during the mapping process. The disadvantage is that when the page table is large, the cost is high, and each context switch must load the entire page table.

Conversion Check Buffer

Phenomenon: Most programs always have multiple accesses to a small number of pages.

Solution: Set up a small hardware device for the computer that maps the virtual address directly to the physical address without having to access the page table, called the Fast table.

Page table for large memory

1. Multi-level page table

For example, consider a 32-bit virtual address 0x00403004 (decimal 4206596) located at the data portion of 12292 bytes. Its virtual address corresponds to pt1=1,pt2=2,offset=4.

First, using PT1 as the index to access the top-level page table gets the table entry 1, its corresponding address range is 4m-8m, and then it uses PT2 as an index to access the Level two page table just found and get the table entry 3, Its corresponding virtual address range is 12288-16383 (that is, absolute address 4206592-4210687) within its 4M block. This table entry contains the page box number of the page on which the virtual address 0x00403004 is located.

If the page is not in memory, the "in \ not" bit in the page table entry will be 0, which raises a fault for pages. If the page is in memory, the page box number obtained from the two-level page table will be combined with the offset (4) to form the physical address. The address is placed on the bus and sent to memory.

Inverted page Table

For a 32-bit virtual address space, a multilevel page table can work well, but as 64-bit computers become more prevalent, the situation has changed radically. If the current address space is 2 of the 64 square bytes, the page size is 4KB, you need a page table with 2 of the 52 table entries. If each table entry is 8 bytes, the entire page table will exceed 30 million GB (30PB).

One solution is to use the inverted page table. In this design, each page box in real memory has a table entry, instead of a table entry for each virtual page. The table entry records which (process, virtual page) is located in the page box.

Although the inverted page table saves a lot of space, it also has serious weaknesses: the transition from virtual to physical addresses is difficult. When process n accesses the virtual page p, the hardware can no longer find the physical page box by referring p as an index to the page table, but must search the entire Inverted page table to find a table item (N,P). In addition, the search must be performed once for each memory access operation, not just when the fault is broken.

You can use a fast table, and if the fast table can record all frequently used pages, the address translation may become as fast as the usual fast table. However, when the fast table fails, you need to search the entire Inverted page table, a feasible way to implement this search is to create a hash list, with a virtual address to hash. That is, all virtual pages that currently have the same hash value in memory are linked together.

Page replacement algorithm

When a page fault is interrupted, the operating system must select one of the pages in memory to swap it out of memory to make room for the page to be paged in. If the page to be swapped out has been modified during memory residency, it must be written back to disk to update the copy of the page on disk. If you have not been modified, you can overwrite the eliminated page directly with the page that is being paged in.

1. Optimal page replacement

If a page is not used within 8 million instructions, and the other page is not used within 6 million instructions, then the previous page is replaced, and the page break that occurs as a result of the need to dial in to it is postponed to the future.

However, it cannot be implemented because when a page break occurs, the operating system is unable to know when the individual pages will be accessed next.

2. Page substitution has not been used recently

The system will set two status bits per page. Sets the R bit when the page is accessed (read or write) and sets the M bit when the page is written. These bits are included in the page table entry and are updated each time the memory is accessed.

The algorithm can be constructed with M-bit and R-bit: When a process is started, two bits of all its pages are set by the operating system to 0. R bits are cleared at regular intervals (such as when each clock is interrupted) to differentiate between pages that have not been visited recently and pages that are visited.

When a page break occurs, the operating system checks all the pages and the results are divided into 4 categories:

First class: Not accessed, nor modified

Type II: not accessed, modified

Category III: Has been accessed and has not been modified

Class Fourth: Has been accessed and has been modified

A third type of page becomes the first class after its R bit is interrupted by the clock 0. The clock interrupt does not clear the M bit because this information is used when deciding whether a page needs to be written back to disk.

The implication of this algorithm is that in the most recent clock tick (typical time is about 20ms), it is better to retire a modified page that has not been accessed than to eliminate a frequently used clean page.

3. First-in/out page replacement (FIFO)

A linked list of all currently in-memory pages is maintained by the operating system, and the most recent entry is placed at the end of the table, and the longest page entered is placed on the table header. When a page break occurs, the table header is eliminated and the newly paged page is added to the footer.

4. Second Chance page replacement

FIFO may be frequently used to replace the page, in order to avoid this problem, the algorithm to make a simple change: Check the oldest page of R bit, if R bit is 0, indicating that the page is old and not used, can be replaced immediately, if it is 1, the R bit zeroed, and put the page to the end of the list, Modify its load time so that it looks like it was just transferred, and then proceed with the search.

The algorithm is essentially looking for a page that has not been visited since the nearest clock interval. If all the pages have been accessed, the algorithm becomes FIFO.

5. Clock page replacement

Although the second Chance page substitution is a reasonable algorithm, it often moves the page in the linked list. A better way is to keep all the pages in a ring-shaped list like the clock, with a needle pointing to the oldest page.

6. Least Recently used page replacement (LRU)

Replaces pages that have not been used for the longest time when a page break occurs. Although LRU is theoretically feasible, it is expensive. In order to fully implement LRU, you need to maintain a linked list of all pages in memory, the most recently used page in the table header, and the furthest minimum used page at the end of the table. The hard part is that every time you access memory, you have to update the entire list. It is a very time-consuming operation to find a page in the list to delete it and then move it to the table header.

7. Using software to simulate LRU

Although the previous two LRU algorithms can be implemented theoretically, only a very small number of computers have this kind of hardware.

One possible scenario is NFU (the least common algorithm), which associates each page with a software counter. The counter initial value is 0. Each time the clock is interrupted, all pages in memory are scanned by the operating system, and the R bit of each page is added to its counter. This counter basically tracks how frequently each page is accessed. The page with the smallest displacement counter value when a fault is interrupted.

The main problem with NFC is that it never forgets anything. For example, multiple scans, frequently used pages in the first scan, may still have high counter values for the second scan.

Fortunately, only a small change to NFC can make it a good simulation of the LRU. Its modification is divided into two parts: first, move the counter right one bit before the R bit is added, and then add the R bit to the left-most bit of the counter. The modified algorithm is called the aging algorithm.

When a page break occurs, the pages with the smallest counter value are displaced, and if a page has not been accessed in the previous 4 tick ticks, then its counter should be preceded by 4 consecutive 0. If even one page in the previous 4 ticks is accessed, its counter value is larger than the counter value of the page that was not accessed in the previous 4 clock ticks, and the farther away the current time is, the greater the value of the left-most effect on the counter value, because the last comparison is the size of the value.

8. Working Set page substitution

All the collection of pages currently in use by a process is called the working set, and if the entire working set is loaded into memory, the process does not incur many page faults until it runs to the next run stage. If the memory is too small to accommodate the entire working set, there will be a large number of page faults, since it is usually only a few nanoseconds to complete the instruction, it now takes 10 milliseconds to read from disk. This occurs when a fault is interrupted every time a few instruction programs are called bumps.

To solve this problem, many paging systems try to track the working set of a process to ensure that its working set is already in memory before the program is run.

Algorithm: A page that is not in the working set is retired when there is an outage of pages.

Specifically, the K value is selected, and the collection of pages used by the most recent K memory accesses is uniquely determined after each memory access. Suppose there is a K-bit shift register that moves the register one bit to the left of each memory access, and then inserts the page number that you just visited on the right-hand side. The set of K-pages behind a shift register is the working set.

Theoretically, when a page break occurs, just read the contents of the shift register and sort it, and then delete the duplicate pages, and the result is the working set. However, when the shift register is maintained and the missing pages are interrupted, the overhead required to process it is too high, and the technology has never been used.

As an alternative, there are several approximate methods. One approach is not to look backwards at the memory accesses of the last k times, but to consider their execution time. The working set of a process can be thought of as a collection of pages that it has visited in the past T-second actual run time.

Because only those pages that are in memory can be eliminated as candidates, the algorithm ignores pages that are not in memory.

Specifically, assuming that the hardware is used to set R and M bits, in each tick, there is a periodic clock interrupt that clears the R bit in software mode. The time period t contains multiple clock ticks.

When processing each table entry, check the R bit, and if it is 1, set the last use time to the current actual time, which indicates that the page is being used when a fault is interrupted. If it is 0, you need to calculate its lifetime (that is, the current actual time minus the last time it was used), and then compare it to T. If it is greater than T, then the page is not in the working set and replaced with the new page. If <=t, leave the page temporarily, but keep a record of the page with the longest lifetime (minimum value for last used time).

If the entire page table has not been scanned for elimination, all pages are in the working set. In this case, if one or more r=0 pages are found, the longest surviving page is eliminated.

Worst case, in the current time tick, all the pages have been visited (r=1), randomly choose a elimination, of course, it is best to choose a clean page elimination.

9. Working Set Clock page replacement

When a page break occurs, it is time-consuming to scan the entire table of pages to determine which pages are eliminated.

An improved algorithm, which is based on the clock algorithm, and uses the working set information called the Working Set clock algorithm.

Each table entry contains the last-used time from the working set algorithm, as well as the R-bit, M-bit.

Summarize

Modern operating system notes-storage management 2

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.