Operating System: Chapter 8 答案

Memory-Management Unit 將virtual address mapping到physical address。

26. 程式不需要整個在main memory中,這樣有更好的memory utilization。沒用到的routines也不必在memory中。

27. Context switch time為 part of program / transfer rate + average latency。

28. 隨著process在memory中讀進和讀出,free memory space被拆成許多小空間。External fragmentation的意思是雖然總free memory space足夠,但他們不是連續的。Best-fit和first-fit strategies都會有這個問題。

29. Internal fragmentation發生在分配給process的memory比其所request的要稍微大一點的時候。如果將physical memory切成固定長度的小塊並以此為單位來分配則會發生這種問題。

Compaction用來處理external fragmentation,但它只有在allocation是dynamic且在execution time發生時才能使用。Compaction只要改變base register就能改變program和data的base address。

30. Paging的意思是physical memory被分成稱為frame的固定block,logical memory則是被分成page。Logical address中的page number和offset被用來mapping到physical memory。

31. Page table的數量通常很大,被儲存在page-table base register(PTBR),當要讀取資料時,會先去PTBR中的page number位置獲得frame number,再結合page offset來獲得實際的address。這會大大降低memory access的速度,因此需要使用TLB來改善。
Translation look-aside buffer(TLB)是special, small, fast-loopup的硬體cache。TLB中會直接儲存page number和frame number的對應。當request發生時會先去TLB中尋找。

32. 在page table中每個entry都會有一個valid bit,當這個bit為valid時,the associated page是在process的logical address space中的,反之則否。OS利用這個bit來管理是否allow to access the page。

33. Hashed page table以計算virtual page number的hash value產生。每個entry都是一個linked list,而其中的element則是由三個filed組成: virtual page number,the value of the mapped page frame,還有往下一個element的pointer。

34. Segmentation memory management scheme: 將logical address視為一系列的segment,每個segment都有name和length。User是使用segment name和offset來表達一個address。
Paging memory management scheme: User表達一個地址,hardware則將其拆成page number和offset。

35. 在IA-32(英特爾32位元架構)中,logical address space的partition為分成兩個部分。前一個部分由local descriptor table(LDT)儲存,包含了最多8K個segments,只對這個process開放。後一個部分由global descriptor table(GDT)儲存,包含了最多8K個segment,對所有process開放。

36. 在CPU執行process時,它會產生一個logical address space。如果任何logical address大於或等於limit register的話則是危險的address,應該要有trap至operating system monitor發生(addressing error)。

37. CPU首先產生一個logical address,它包含了page number和offset。首先檢查TLB中有沒有對應的page number,如果沒有的話則搜尋page table並找出相對應的page frame。

38. Mobile operating system的file system通常是使用flash memory而非magnetic hard disk。Flash memory有兩大缺點: 容量限制,且poor throughput between flash and main memory。而且flash memory的讀取次數有限。我想main memory和flash之間的throughput低應該是不支援paging的主要原因。

39. ARM architecture支援四種不同的page size: 1-MB和16-MB(sections)是使用one-level paging,而4-KB和16-KB則是使用two-level paging。在outer level中擁有兩個micro TLB,一個給data,另一個給instructions使用。Inner level則是有一個main TLB,如果micro TLB的address translation失敗了,則檢查main TLB,如果又失敗則檢查整個page table。

所以address可能是指到data或者是instruction的...

Exercises

8.1
Internal fragmentation: 當某個job佔據某個region或page,但又沒有完全使用其中的memory space發生。多餘的space無法使用,直到job完成,region或page被release。
External fragmentation: 當總memory空間可以satisfy a memory request,但實際上不能時發生。

8.2
Linkage editor是將multiple object module結合成program binary。
在final program binary中,linkage editor需要將unresolved symbolic address改成實際上變數所在的address。為了要達成這個目的,module必須keep tracking所有refer to unresolved symbolic address的instruction。在linking時,每個module都會被assign一個sequence of addresses,記錄著整個program binary中的unresolved symbolic address的位置。

8.3 跳過

8.4 Dynamic memory allocation:
contiguous memory allocation: 需要relocate整個program。
pure segmentation: 也可能需要relocate整個segment,因為每個segment都連載一起,沒有足夠的空間讓他長大。
pure paging: 有可能不需要relocate就能incremental allocation。


8.5 三種main memory organization scheme
contiguous memory allocation: 會發生external fragmentation,沒辦法share code。
pure segmentation: 會發生external fragmentation,可以share code。
pure paging: 會發生internal fragmentation,可以share code。

8.7
Paging為了維持translation structure需要更多overhead。Translation structure應該是指把logical address轉換成physical address。每個page都需要一個entry,記錄其在memory中的physical address。Segement則只需要register管理segement base和segment extents。

8.8
Contiguous memory allocation需要OS allocate整個virtual address space的extent。
Pure segmentation可讓OS給每個segmentation小的extent。


8.10
每個address都指向一個word

8.11
Conventional single-level page table = Logical address space / page size
Inverted page table = Physical memory space / page size

8.13
當page table變得很大時,如有一長串unused page table可以collapse成一個single-segment table entry。將segment paging則可以減少external fragmentation。

8.18
Hashed page table的體積較小,但它有可能會發生conflict,將多個page放在同一個hash table entry中。



留言