Virtual memory可讓programmer不必擔心memory-storage的limitations。除此之外它可讓processes之間輕易的share files以及實作shared memory。
它還提供了有效率的建立process的方法。
Instruction一定要在physical memory中才能執行,但是如果將所有code都放入physical memory,就限制了program大小一定要比physical memory小。
實際上,可以不用放入全部的program。例如說:
- 很少被呼叫的error handler
- 多分配但沒有被使用到的container部分
使用virtual memory來執行程式有幾個好處:
- 使用者可以編寫擁有很大的virtual address space的程式,超過physical memory。
- 同時間可以執行更多程式,response time和turnaround time也不會增加。
- Swap user program into memory時需要更少I/O(為何?)。
Virtual address space是logically程式儲存在memory裡的方法。看似是連續的,但實際上,對應到virtual memory中的page,physical memory中的frame可能是不連續的。其中的mapping由MMU管理。
Valid, invalid bit是記錄在page table中,每個frame是否valid。要進行address translation,也就是將page number轉換成 frame address時,如果valid bit為invalid,則會發生page fault。
page fault可能會是invalid reference,這時就會出現trap。但也有可能只是memory中沒有這個page而已。這時就將page從disk中swap到合適的frame。
pure demand paging一開始memory是沒有pages的,完全從一連串的page faults開始。因為locality of reference,這種overhead會逐步下降。
Demand paging需要硬體支援。需要儲存page table的空間(附有valid bit)。需要有secondary memory(用來swap),需要能夠restart instruction,因為當指令要求的page發生page fault時,當demand paging完成,需要回到這個page重新開始。
要從disk中讀取page至free frame,這個read request也要在queue中等待執行,還有等待disk的seek and latency time。在這段時間內,CPU可以被其他user使用。
當disk讀取完成之後,disk I/O subsystem會發出interrupt。這時就將其他user的register和process state儲存起來,準備切換。確認interrupt是來自disk之後,將page table修正(因為已經做出更動),等待CPU,並繼續該process的執行。
Effective Access Time由正常的memory access和page fault組成,page fault的部分則是由(page fault overhead + swap page out + swap page in + restart overhead)組成。
在page replacement policy中,有兩種方法可以實現LRU - counter implementation和stack implementation。
LRU-Approximation algorithm: 修改過的LRU演算法,例如說,加入reference bit。Page一旦被reference則reference bit設為1,而演算法會優先取代那些reference bit為0者。
Second-chance replacement則是會將reference bit設為0,並取代reference bit本來就為0的page。
Page-Buffering algorithm: 隨時都保持一個free frames pool,這樣當fault發生時就直接從裡面取用。當page fault發生時,將page讀入free frame並且選擇一個victim frame將其evict並加入pool中。當沒事的時候也可以evict victim frame。
每個process都需要minimum number of frames。每個process要分配多少frames,可以分成fixed allocation和priority allocation。
Fixed allocation又可以分成equal allocation和proportional allocation。
Priority則是根據process之間的優先度來分配。當某個process發生page fault時,它可以從優先權比它低的process取用frame。
Global replacement: process選擇replacement frame時可以從所有process的所有frame中選擇。但這樣會造成process execution time變動很高。這種方法的throughput較好,所以很常使用。
Local replacement則是process只能選擇要替換掉自己所分配到的frames。這樣每個process的performance相對較穩定,但可能會underutilized memory。
先前講義上都假設memory accesss的速度相同,但實際上許多系統為NUMA - Non-Uniform Memory Access。不同的CPU存取不同的memory,速度可能會不一樣。最好的方法就是,某個thread被scheduled在某個CPU上(應該是指在某個CPU上執行),就將接近這個CPU的memory分配給它。接近的意思應該是指CPU存取這個memory的速度最快。
Trashing: 猛移,崩潰
如果process擁有的frame數量不足,page-fault rate可能會相當高,可能會剛把某個frame換走又需要它換回來。
這會造成CPU utilization降低,作業系統認為需要增加degree of multiprogramming(我想應該是因為多一些process可以增加CPU utilization),又增加了新的process。
這種情況稱之為trashing。當degree of multiprogramming持續上升,trashing發生時,CPU utilization會急遽下降。這應該是種惡性循環。
Demand paging是依靠locality model運作,我想這意思應該是每個process使用到的memory都會集中在同一個區域,同時process之間使用到的區域可能會overlap。
當所有process使用到的所有區域相加,也就是sigma(size of locality) > total memory size時,tharshing就會發生。
Working set指的應該就是某個process需要的所有pages。
If a page fault occurs while we are fetching an operand, we must fetch and decode the instruction again and then fetch the operand.
Valid, invalid bit是記錄在page table中,每個frame是否valid。要進行address translation,也就是將page number轉換成 frame address時,如果valid bit為invalid,則會發生page fault。
page fault可能會是invalid reference,這時就會出現trap。但也有可能只是memory中沒有這個page而已。這時就將page從disk中swap到合適的frame。
pure demand paging一開始memory是沒有pages的,完全從一連串的page faults開始。因為locality of reference,這種overhead會逐步下降。
Demand paging需要硬體支援。需要儲存page table的空間(附有valid bit)。需要有secondary memory(用來swap),需要能夠restart instruction,因為當指令要求的page發生page fault時,當demand paging完成,需要回到這個page重新開始。
要從disk中讀取page至free frame,這個read request也要在queue中等待執行,還有等待disk的seek and latency time。在這段時間內,CPU可以被其他user使用。
當disk讀取完成之後,disk I/O subsystem會發出interrupt。這時就將其他user的register和process state儲存起來,準備切換。確認interrupt是來自disk之後,將page table修正(因為已經做出更動),等待CPU,並繼續該process的執行。
Effective Access Time由正常的memory access和page fault組成,page fault的部分則是由(page fault overhead + swap page out + swap page in + restart overhead)組成。
在page replacement policy中,有兩種方法可以實現LRU - counter implementation和stack implementation。
LRU-Approximation algorithm: 修改過的LRU演算法,例如說,加入reference bit。Page一旦被reference則reference bit設為1,而演算法會優先取代那些reference bit為0者。
Second-chance replacement則是會將reference bit設為0,並取代reference bit本來就為0的page。
Page-Buffering algorithm: 隨時都保持一個free frames pool,這樣當fault發生時就直接從裡面取用。當page fault發生時,將page讀入free frame並且選擇一個victim frame將其evict並加入pool中。當沒事的時候也可以evict victim frame。
每個process都需要minimum number of frames。每個process要分配多少frames,可以分成fixed allocation和priority allocation。
Fixed allocation又可以分成equal allocation和proportional allocation。
Priority則是根據process之間的優先度來分配。當某個process發生page fault時,它可以從優先權比它低的process取用frame。
Global replacement: process選擇replacement frame時可以從所有process的所有frame中選擇。但這樣會造成process execution time變動很高。這種方法的throughput較好,所以很常使用。
Local replacement則是process只能選擇要替換掉自己所分配到的frames。這樣每個process的performance相對較穩定,但可能會underutilized memory。
先前講義上都假設memory accesss的速度相同,但實際上許多系統為NUMA - Non-Uniform Memory Access。不同的CPU存取不同的memory,速度可能會不一樣。最好的方法就是,某個thread被scheduled在某個CPU上(應該是指在某個CPU上執行),就將接近這個CPU的memory分配給它。接近的意思應該是指CPU存取這個memory的速度最快。
Trashing: 猛移,崩潰
如果process擁有的frame數量不足,page-fault rate可能會相當高,可能會剛把某個frame換走又需要它換回來。
這會造成CPU utilization降低,作業系統認為需要增加degree of multiprogramming(我想應該是因為多一些process可以增加CPU utilization),又增加了新的process。
這種情況稱之為trashing。當degree of multiprogramming持續上升,trashing發生時,CPU utilization會急遽下降。這應該是種惡性循環。
Demand paging是依靠locality model運作,我想這意思應該是每個process使用到的memory都會集中在同一個區域,同時process之間使用到的區域可能會overlap。
當所有process使用到的所有區域相加,也就是sigma(size of locality) > total memory size時,tharshing就會發生。
Working set指的應該就是某個process需要的所有pages。
If a page fault occurs while we are fetching an operand, we must fetch and decode the instruction again and then fetch the operand.
為何?
留言
張貼留言