Operating System Concepts Chapter 9 VirtualMemory Management 1

  • Slides: 39
Download presentation
Operating System Concepts 作業系統原理 Chapter 9 虛擬記憶體管理 (Virtual-Memory Management) 1

Operating System Concepts 作業系統原理 Chapter 9 虛擬記憶體管理 (Virtual-Memory Management) 1

7

7

2. 2 需求分頁的性能(Performance of Demand Paging) 每 400, 000次存取才允許有一次Page Fault 8

2. 2 需求分頁的性能(Performance of Demand Paging) 每 400, 000次存取才允許有一次Page Fault 8

3. 寫入時複製(Copy-on-Write) n n n Copy-on-Write (COW) allows both parent and child processes to

3. 寫入時複製(Copy-on-Write) n n n Copy-on-Write (COW) allows both parent and child processes to initially share the same pages in memory If either process modifies a shared page, only then is the page copied COW allows more efficient process creation as only modified pages are copied Free pages are allocated from a pool of zeroed-out pages 9

4. 1 基本技巧(Basic Page Replacement) n 1. 2. 3. 4. 分頁替換的方法如下。如果沒有空白欄可用,就去找一個目前並未使用 的欄並且把它空出來。要把某個欄空出來,可以把該欄的內涵寫入置換 空間中,並且更改分頁表(以及所有相關的表格)以標示該頁已不在記憶 體中了。空出來的欄現在就可以用來存放引起分頁錯誤的那一頁。

4. 1 基本技巧(Basic Page Replacement) n 1. 2. 3. 4. 分頁替換的方法如下。如果沒有空白欄可用,就去找一個目前並未使用 的欄並且把它空出來。要把某個欄空出來,可以把該欄的內涵寫入置換 空間中,並且更改分頁表(以及所有相關的表格)以標示該頁已不在記憶 體中了。空出來的欄現在就可以用來存放引起分頁錯誤的那一頁。 Find the location of the desired page on disk Find a free frame: - If there is a free frame, use it - If there is no free frame, use a page replacement algorithm to select a victim frame Bring the desired page into the (newly) free frame; update the page and frame tables Restart the process 11

4. 2 FIFO法則(FIFO Page Replacement) n 最簡單的頁替換演算法就是先進先出 (first-in, first-out, FIFO)演算法。 畢雷地異常(Belady's anomaly) Frames越多 Page

4. 2 FIFO法則(FIFO Page Replacement) n 最簡單的頁替換演算法就是先進先出 (first-in, first-out, FIFO)演算法。 畢雷地異常(Belady's anomaly) Frames越多 Page Fault反而越多 13

First-In-First-Out (FIFO) Algorithm n n Reference string: 1, 2, 3, 4, 1, 2, 5,

First-In-First-Out (FIFO) Algorithm n n Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 3 frames (3 pages can be in memory at a time per process) 1 1 4 5 2 2 1 3 3 3 2 4 1 1 5 4 2 2 1 5 3 3 2 4 4 3 9 page faults 4 frames 10 page faults Belady’s Anomaly: more frames more page faults

4. 3 最佳頁替換(Optimal Page Replacement) n 最佳頁替換演算法(optimal page-replacement algorithm)是所有演算法中 分頁錯誤比率最低的一種。它永遠不會遭遇到畢雷地異常的問題。目 前存在的最佳頁替換演算法稱為OPT或MIN。 Replace page that

4. 3 最佳頁替換(Optimal Page Replacement) n 最佳頁替換演算法(optimal page-replacement algorithm)是所有演算法中 分頁錯誤比率最低的一種。它永遠不會遭遇到畢雷地異常的問題。目 前存在的最佳頁替換演算法稱為OPT或MIN。 Replace page that will not be used for longest period of time 必須預知之後Reference String 15

4. 4 LRU (Least Recently Used) 如何去執行LRU: n Counter implementation q q Every page

4. 4 LRU (Least Recently Used) 如何去執行LRU: n Counter implementation q q Every page entry has a counter; every time page is referenced through this entry, copy the clock into the counter When a page needs to be changed, look at the counters to determine which are to change 16

n Stack implementation – keep a stack of page numbers in a double link

n Stack implementation – keep a stack of page numbers in a double link form: q Page referenced: n q move it to the top No search for replacement 17

Fixed Allocation n n Equal allocation – For example, if there are 100 frames

Fixed Allocation n n Equal allocation – For example, if there are 100 frames and 5 processes, give each process 20 frames. Proportional allocation – Allocate according to the size of process

q 處理輾轉現象的策略: - 作組模式(Working-Set Model)及 - 分頁錯誤頻率(Page-Fault Frequency Scheme)。 27

q 處理輾轉現象的策略: - 作組模式(Working-Set Model)及 - 分頁錯誤頻率(Page-Fault Frequency Scheme)。 27

Working-Set Model n n working-set window a fixed number of page references Example: 10,

Working-Set Model n n working-set window a fixed number of page references Example: 10, 000 instruction WSSi (working set of Process Pi) = total number of pages referenced in the most recent (varies in time) q q q n n n if too small will not encompass entire locality if too large will encompass several localities if = will encompass entire program D = WSSi total demand frames if D > m Thrashing Policy if D > m, then suspend one of the processes

7. 1 基本功能(Basic Mechanism) 32

7. 1 基本功能(Basic Mechanism) 32

7. 2 記憶體對映 I/O (Memory-Mapped I/O) 33

7. 2 記憶體對映 I/O (Memory-Mapped I/O) 33