Operating System Review 3.2.1 - Virtual Memory

Problems with traditional storage

One shot: the job is loaded once to run
Persistence: not all parts need to be in memory for a long time

Definition and Characteristics

Load the part to be used into the internal memory, transfer the unused part to the external memory, and expand the memory logically. The
maximum capacity of the virtual memory is determined by the addressing range of the computer. The
actual capacity is the sum of the internal and external memory and the minimum value of the addressing range.

Multiplicity: It is not necessary to load the job at one time, but to load it into the memory multiple times.
Swapability: No resident memory is required when the job is running, and swapping in and swapping out is allowed.
Virtuality: Logically expand the memory capacity

When the required information is not in the internal memory, it will be loaded into the internal
memory. When the internal memory is not enough, the temporarily unused information will be called out of the internal memory.

accomplish

Request pagination management method

During the execution of the program, when the accessed information is not in the memory, the operating system is responsible for transferring the required information from the external storage to the memory, and then continues to execute the program. Features of paging and page replacement

page table mechanism

insert image description here
The page table for basic paging storage is the implicit page number and the page table entry is the memory block number. The
page table for requesting paging storage is the implicit page number and the page table entry is the memory block number, status number, access field, modification bit, and external memory address
because Basic paging only needs to record the memory block number of the corresponding page, which is used to obtain the corresponding memory address,
while requesting paging requires a status number to record whether the page has been loaded into memory, and the access field is used to record how many times it has been accessed recently or the last time it was accessed Time (limitation principle), modify bit to record whether it has been modified (check whether to rewrite back to external storage), external storage address is convenient for rewriting

page fault

When the page to be accessed is not in the memory, a page fault interrupt is generated, and the page fault interrupt handler
handles the interrupt. The page fault process is blocked, enters the blocking queue, wakes up after paging is completed, and puts it back into the ready queue

If there is a free block in the memory, allocate a free block for the process, load the missing page into the block, and modify the corresponding page table entry in the page table

If there is no free block in the memory, there is a page replacement algorithm to select a page to be eliminated. If the page has been modified during the memory period, it must be written back to the external memory, otherwise it is not necessary. The process is: when page 0 is missing, use page
replacement Algorithm to replace page 2, and page 2 has been replaced, write its data back to the corresponding external storage address, free up memory blocks, and update page table entries

Page faults are faults in internal interrupts. Faults are caused by error conditions and may be repaired.
Internal interrupts also have traps and terminations, which are intentional, such as system calls and errors that cause the program to terminate, respectively.

address translation agency

insert image description here
Process: Request paging, query the fast table, check the slow table to see if the required entry is in the memory if it is not hit, write to the fast table if it is, update the access bit and modification bit if it is not in the memory, a page fault interrupt will be triggered, and the external
memory Query the missing page in the middle, and put the missing page back into the memory
. If the memory is full at this time, you need to change the page. At this time, check whether the page has been modified. If it is modified, you need to rewrite it back to the external storage
page and load it into the memory. , modify the slow table, and the entries are also updated to the fast table

Page Replacement Algorithm

The cost of swapping pages in and out is high, and a good replacement algorithm pursues fewer page faults

Best Replacement OPT

The pages that are selected for elimination each time are pages that will never be used or will not be accessed for the longest time.
This ensures the lowest page fault rate, but it cannot be achieved

First in first out replacement FIFO

The page selected to be eliminated each time is the first page to enter the memory, but a Belady exception will occur, that is, the number of allocated memory blocks increases, but the number of page faults does not decrease but increases instead, which does not conform to the principle of locality, and the performance of the algorithm is poor

Most recently unused permutation LRU

For each elimination, select the page that has not been used for the longest time. There is an access field in the paging table of the previous request, which can be used to record the time t of the last access. When elimination is required, select the page with the smallest value of t. The performance is good, but it requires a
special Hardware support, difficult to implement, high overhead

Clock replacement CLOCK

insert image description here
Link the pages in the memory into a circular queue through the link pointer. When the page is accessed, the access bit is set to 1. When it needs to be swapped out, if the access bit of the page is 0, it is swapped out, and if it is 1, it is set to 0, do not swap out
When all 1s are in one round and no page can be swapped out, the second round will be performed

Improved clock replacement

As before, construct a circular queue
but increase the focus: priority is given to unvisited and unmodified frames, followed by unvisited but modified frames, then accessed but unmodified frames, and the last visited and modified frames are not modified in the first
insert image description here
round Flag bit, find unvisited and unmodified frames
The second round is to find unvisited but modified frames, and the access position of the scanned frames is 0,
the third and fourth rounds correspond to repeating the first The first and second rounds of operations do not need to modify any flag bits.
When the third and fourth rounds are required, it means that the frames in the memory have been accessed, depending on whether they have been modified.

page allocation strategy

resident set

In request paging storage management, the set of physical blocks allocated to a process
can be known from the virtual storage. The size of the resident set is generally smaller than the size of the process. Therefore, the occurrence rate of page faults is related to the size of the resident set. Too small a resident set will cause frequent page fault occurred

Page allocation, replacement strategy

fixed allocation

The operating system allocates a fixed number of physical blocks for each process, which does not change during operation, that is, the size of the resident set does not change

variable allocation

First allocate a certain number of physical blocks for it, increase or decrease appropriately during runtime, and the size of the resident set is variable

partial replacement

When a page fault occurs, only select its own physical block for replacement

global replacement

Page fault processes can use free physical blocks, or replace physical blocks held by other processes to external memory, and then get allocated.
The system will lock some pages, which cannot be swapped out of memory

Fixed Layout Partial Replacement

The number of physical blocks obtained is certain. When a page is missing, only its own page can be swapped out. The number of initial allocations can be determined according to the priority and size of the process.

mutable allocation global permutation

The system maintains a queue of free physical blocks. As long as a page fault occurs, a new physical block can be obtained. Only when the free physical block is used up, the unlocked page will be selected for swapping out

mutable allocation local permutation

When a page fault occurs, you can only swap out your own pages. When the page fault rate increases, allocate more physical blocks. When the page fault rate decreases, allocate fewer physical blocks.

paging timing

prepaging policy

According to the locality strategy, it is more efficient to transfer several adjacent pages at a time than to transfer one page at a time, which is mainly used for the first transfer of a process

demand paging policy

Pages are adjusted only when a page fault occurs when the process is running, one page at a time

paging source

insert image description here
Swap area: high-speed, before the process runs, copy data from the file area to the swap area,
when the swap area holding process-related data is insufficient: read files that do not need to be modified in the file area, and write files that may be modified Enter the swap area
UNIX: unused pages are placed in the file, and used pages are placed in the swap area

Jitter phenomenon

The page that has just been called out has to be called into the memory again, switching frequently because there are too few physical blocks

working set

Resident set: the collection of memory blocks allocated by the process in requesting paging storage management.
Working set: the collection of pages actually accessed by the process within a certain period of time.
insert image description here
By recording the changes in the working set, it is determined how many physical blocks are most suitable for the process, and also Selections available for swapping out pages

Guess you like

Origin blog.csdn.net/weixin_51109304/article/details/130934735