Module 10: Virtual Memory Background(背景) Demand Paging(请求页式) ° Performance of Demand Paging(请求页式的性能) Page Replacement(页置换) Page-Replacement Algorithms(页置换算法) ● Alocation of frames(页框的分配) ° Thrashing(簸) Other Considerations(其他考虑) Demand Segmenation(请求段式) Applied Operating System Concepts Silberschatz, Galvin, and Gagne @1999
10.1 Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts Module 10: Virtual Memory • Background(背景) • Demand Paging(请求页式) • Performance of Demand Paging(请求页式的性能) • Page Replacement(页置换) • Page-Replacement Algorithms(页置换算法) • Allocation of Frames (页框的分配) • Thrashing(颠簸) • Other Considerations(其他考虑) • Demand Segmenation(请求段式)
Background Virtual memory -separation of user logical memory from physical memory.(虚拟内存一物理内存和用户逻辑内存的区分) Only part of the program needs to be in memory for execution(只有部分运行的程序需要在内存中) Logical address space can therefore be much larger than physical address space(因此,逻辑地址空间能够比物理地 址空间大) Need to allow pages to be swapped in and out(必须允许页 面能够被换入和换出) rtual| memory can be implemented via(虚拟内存能够通过以下 手段来执行) Demand paging(请求页式 Demand segmentation(请求段式 Applied Operating System Concepts Silberschatz, Galvin, and Gagne @1999
10.2 Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts Background • Virtual memory – separation of user logical memory from physical memory.(虚拟内存—物理内存和用户逻辑内存的区分) – Only part of the program needs to be in memory for execution(只有部分运行的程序需要在内存中). – Logical address space can therefore be much larger than physical address space(因此,逻辑地址空间能够比物理地 址空间大). – Need to allow pages to be swapped in and out(必须允许页 面能够被换入和换出). • Virtual memory can be implemented via(虚拟内存能够通过以下 手段来执行): – Demand paging (请求页式) – Demand segmentation(请求段式)
Demand Paging Bring a page into memory only when it is needed(只有在一个页 需要的时候才把它换入内存) Less vo needed(需要很少的lo) Less memory needed(需要很少的内存) Faster response(快速响应) More users(多用户) ° Page is needed(需要页)→ reference to it(查阅此页) invalid reference(无效的访问)→abot(中止) not-in-memo(不在内存)= bring to memo(换入内存 Applied Operating System Concepts Silberschatz, Galvin, and Gagne @1999
10.3 Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts Demand Paging • Bring a page into memory only when it is needed(只有在一个页 需要的时候才把它换入内存). – Less I/O needed(需要很少的I/O) – Less memory needed (需要很少的内存) – Faster response(快速响应) – More users(多用户) • Page is needed (需要页) reference to it(查阅此页) – invalid reference(无效的访问) abort(中止) – not-in-memory(不在内存) bring to memory(换入内存 )
Valid-Invalid Bit With each page table entry a valid-invalid bit is associated 1→in- memory,0→ not-in-memory)(在每一个页表的表项有一个有 效-无效位相关联,1表示在内存,0表示不内存) nitially valid- invalid but is set to0 on all entries(在所有的表项,这 个位被初始化为0) Example of a page table snapshot(一个页表映象的例子) Frame #t valid-invalid bit 0 page table During address translation, if valid-invalid bit in page table entry is 0(在地址转换中,如果页表表项位的值是0)→ page fault(缺页) Applied Operating System Concepts 10.4 Silberschatz, Galvin, and Gagne @1999
10.4 Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts Valid-Invalid Bit • With each page table entry a valid–invalid bit is associated (1 in-memory, 0 not-in-memory)(在每一个页表的表项有一个有 效- 无效位相关联,1表示在内存,0表示不内存) • Initially valid–invalid but is set to 0 on all entries(在所有的表项,这 个位被初始化为0). • Example of a page table snapshot(一个页表映象的例子). • During address translation, if valid–invalid bit in page table entry is 0(在地址转换中,如果页表表项位的值是0) page fault(缺页). 1 1 1 1 0 0 0 Frame # valid-invalid bit page table
Page Fault If there is ever a reference to a page, first reference will trap to os(n 果有对一个页的访问,第一个访问要陷入0s)→ page fault(缺页) os looks at another table to decide(OS查看另一个表来决定): - Invalid reference(无效引用)→ abort(终止) Just not in memory(仅仅不在内存) Get empty frame(得到空的页框). Swap page into frame(把页换入页框) Reset tables, validation bit=1(重新设置页表,把位设为1) ° Restart instruction(重启指令): Least Recently Used(最近未使用) block move(块移动) auto increment/decrement location (区域自动增长/缩减) Applied Operating System Concepts 10.5 Silberschatz, Galvin, and Gagne @1999
10.5 Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts Page Fault • If there is ever a reference to a page, first reference will trap to OS(如 果有对一个页的访问,第一个访问要陷入OS) page fault(缺页) • OS looks at another table to decide(OS查看另一个表来决定): – Invalid reference(无效引用) abort(终止). – Just not in memory(仅仅不在内存). • Get empty frame(得到空的页框). • Swap page into frame(把页换入页框). • Reset tables, validation bit = 1(重新设置页表,把位设为1). • Restart instruction(重启指令): Least Recently Used (最近未使用) – block move(块移动) – auto increment/decrement location (区域自动增长/缩减)