




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Chap. 7.4: Virtual MemoryCS61C L35 VM I (2)Garcia UCBReview: CachesCache design choices:size of cache: speed v. capacitydirect-mapped v. associativefor N-way set assoc: choice of Nblock replacement policy2nd level cache?Write through v. write back?Use performance model to pick between choices, depen
2、ding on programs, technology, budget, .CS61C L35 VM I (3)Garcia UCBAnother View of the Memory HierarchyRegsL2 CacheMemoryDiskTapeInstr. , OperandsBlocksPagesFilesUpper LevelLower LevelFasterLargerCacheBlocksThus farNext:VirtualMemoryRecall: illusion of memorynProgrammers view about memorynUnlimited
3、amount of fast memorynHow to create the above illusion?無(wú)限大的快速記憶體Scene: libraryBook shelfdeskbooksVirtual memory 虛擬記憶體nCreate an illusion of unlimited memorynMotivation nA collection of programs running at once on a machinenTotal memory required by all programs the amount of main memory availablenAll
4、ow a single user program to exceed the size of primary memorynSoftware solution: programmers divided programs into pieces, called overlays多個(gè)程式同時(shí)執(zhí)行,大於主記憶體單一程式大於主記憶體Process nThe state of a program is called a processnState of a program:nProgram counter (PC), registers, page table,nTo allow another pro
5、gram to use the CPU, we must save this statenContext switchingnOS (operating system) changes from running process P1 to running process P2行程CS61C L35 VM I (7)Garcia UCBSimple Example: Base and Bound Reg0 OSUser AUser BUser C$base $base+$bound Want discontinuous mappingProcess size memAddition not en
6、ough!= What to do?Enough space for User D,but discontinuous (“fragmentation problem”) Virtual memory systemnMain memory as a cache for the secondary storage (disk)MemoryCPUMemorySizeCost ($/bit)SpeedSmallestBiggestHighestLowestFastestSlowestMemorycacheDiskCache for diskHow to mapto disk?More about V
7、irtual MemorynCalled “Virtual Memory”nAlso allows OS to share memory, protect programs from each othernToday, more important for protection vs. just another level of memory hierarchynEach process thinks it has all the memory to itselfnHistorically, it predates cachesCS61C L35 VM I (10)Garcia UCBMapp
8、ing Virtual Memory to Physical Memory 0Physical Memory Virtual MemoryCodeStaticHeapStack64 MBDivide into equal sizedchunks (about 4 KB - 8 KB)0Any chunk of Virtual Memory assigned to any chuck of Physical Memory (“page”)CS61C L35 VM I (11)Garcia UCBPaging Organization (assume 1 KB pages)AddrTransMAP
9、Page is unit of mappingpage 01K1K1K0102431744Virtual MemoryVirtualAddresspage 1page 311K2048page 2.page 0010247168PhysicalAddressPhysicalMemory1K1K1Kpage 1page 7.VM address translation (1)3 2 1 011 10 9 815 14 13 1231 30 29 28 27Page offsetVirtual page numberVirtual address3 2 1 011 10 9 815 14 13 1
10、229 28 27Page offsetPhysical page numberPhysical addressTranslationPage size=212VirtualaddressPhysicaladdressAddress space=232=4GBAddress space=230=1GBHow to translate virtual addresses ? Ans: Direct mapped, set-associative, full-associative?VM address translation (2)Page offsetVirtual page numberVi
11、rtual addressPage offsetPhysical page numberPhysical addressPhysical page numberValidIf 0 then page is notpresent in memoryPage table registerPage table20121831 30 29 28 27 15 14 13 12 11 10 9 8 3 2 1 029 28 2715 14 13 12 11 10 9 8 3 2 1 0Each programhas its ownpage table220Address translation: Full
12、-associativeCS61C L35 VM I (14)Garcia UCBPaging/Virtual Memory Multiple ProcessesUser B: Virtual Memory CodeStaticHeapStack0CodeStaticHeapStackA PageTableB PageTableUser A: Virtual Memory 00Physical Memory64 MBPage fault (cache miss)Physical memoryDisk storageValid111101101101Page tableVirtual pagen
13、umberPhysical page ordisk addressVirtualPage numberKey issues in VMnPage fault penalty takes millions of cyclesnPages should be large enough to amortize the high access timen32-64KBnReduce the page fault rate: full-associative placementnUse clever algorithm to replace pages while page faults occurnL
14、RU (least recently used) ?nUse write-back instead of write-throughMake the address translation fasternMotivation: page tables are stored in main memoryLoad/storevirtual addressPage tablePhysical addressIn memoryMain memorydata2 memoryaccesses !Use a cacheto store page tableTranslation-lookaside buff
15、er (TLB) V alid111101101101Page tableP hysical pageaddressValidTLB111101TagVirtual pagenum berPhysical pageor disk addressPhysical m em oryDisk storageTLBTLBmissCS61C L35 VM I (19)Garcia UCBVM, TLB, and cacheTLBs usually small, typically 128 - 256 entries Like any other cache, the TLB can be direct
16、mapped, set associative, or fully associative ProcessorVACachemisshitdataTLBLookupPAhitmissMainMemoryTrans-lationOn TLB miss, get page table entry from main memoryVM, TLB, and cachesValidTagDataPage offsetPage offsetVirtual page numberVirtual addressPhysical page num berValid1220201614Cache index32C
17、acheDataCache hit2ByteoffsetDirtyTagTLB hitPhysical page num berPhysical address tagTLBPhysical address31 30 29 15 14 13 12 11 10 9 8 3 2 1 0 31 30 12 11 1 0 Virtual addressTLBcacheProtection with Virtual memorynVM allows the sharing of a single main memory by multiple processesnOS place the page ta
18、bles in the address space of OSnIndependent virtual pages map to disjoint physical pagenUser process can not change the page table mappingCS61C L35 VM I (22)Garcia UCBComparing the 2 levels of hierarchy Cache VersionVirtual Memory vers. Block or LinePage MissPage Fault Block Size: 32-64BPage Size: 4
19、K-8KB Placement:Fully AssociativeDirect Mapped, N-way Set Associative Replacement: Least Recently UsedLRU or Random(LRU) Write Thru or BackWrite BackCS61C L36 VM II (23)Garcia UCBReview: 4 Qs for any Memory Hierarchy Q1: Where can a block be placed? One place (direct mapped) A few places (set associ
20、ative) Any place (fully associative) Q2: How is a block found? Indexing (as in a direct-mapped cache) Limited search (as in a set-associative cache) Full search (as in a fully associative cache) Separate lookup table (as in a page table) Q3: Which block is replaced on a miss? Least recently used (LR
21、U) Random Q4: How are writes handled? Write through (Level never inconsistent w/lower) Write back (Could be “dirty”, must have dirty bit) CS61C L36 VM II (24)Garcia UCB Block 12 placed in 8 block cache:Fully associativeDirect mapped2-way set associative- Set Associative Mapping = Block # Mod # of Se
22、ts0 1 2 3 4 5 6 7Blockno.Fully associative:block 12 can go anywhere0 1 2 3 4 5 6 7Blockno.Direct mapped:block 12 can go only into block 4 (12 mod 8)0 1 2 3 4 5 6 7Blockno.Set associative:block 12 can go anywhere in set 0 (12 mod 4)Set0Set1Set2Set3Q1: Where block placed in upper level?CS61C L36 VM II
23、 (25)Garcia UCB Direct indexing (using index and block offset), tag compares, or combination Increasing associativity shrinks index, expands tagBlockoffsetBlock AddressTagIndexQ2: How is a block found in upper level?Set SelectData SelectCS61C L36 VM II (26)Garcia UCBEasy for Direct MappedSet Associative or Fully Associative: Random LRU (Least Recently Used)Miss RatesAssociativity:2-way 4-way 8-waySizeLRU Ran LRU Ran LRU Ran16 KB5.2% 5.7% 4.7% 5.3% 4.4%5.0%64 KB1.9% 2.0% 1.5% 1
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年語(yǔ)文考試實(shí)踐性試題及答案解析
- 2025年藥師考試未來(lái)發(fā)展趨勢(shì)探討試題及答案
- 主管護(hù)師考試案例分析技巧試題及答案
- 探討中國(guó)文化的試題及答案匯編
- 執(zhí)業(yè)藥師考試中的理論與實(shí)操問(wèn)題試題及答案
- 中國(guó)文化概論考試準(zhǔn)備指南
- 執(zhí)業(yè)護(hù)士考試案例分享與專業(yè)思維的培養(yǎng)試題及答案
- 2025年主管護(hù)師考試豐富資源試題及答案
- 中國(guó)老年圍術(shù)期麻醉管理指導(dǎo)意見(jiàn)課件
- 制藥公用系統(tǒng)工程 空氣凈化課件
- 地圖學(xué)第1章-緒論
- 浙江省腫瘤醫(yī)院醫(yī)療廢物暫存間環(huán)保設(shè)施提升改造項(xiàng)目報(bào)告表
- 《加拉帕戈斯群島》課件
- 2024人教版新教材初中物理八年級(jí)下冊(cè)內(nèi)容解讀課件(深度)
- 工程經(jīng)濟(jì)學(xué)(青島理工大學(xué))知到智慧樹(shù)章節(jié)測(cè)試課后答案2024年秋青島理工大學(xué)
- (高清版)DB2201∕T 43-2023 肉犢牛飼養(yǎng)技術(shù)規(guī)范
- 2025年醫(yī)院消化內(nèi)科年度工作計(jì)劃
- 2025年華能長(zhǎng)興分公司招聘筆試參考題庫(kù)含答案解析
- 醫(yī)院感染管理制度培訓(xùn)
- 2024年高考政治學(xué)科高考萬(wàn)能答題模板(高分版)
- 水資源應(yīng)急調(diào)度模型-洞察分析
評(píng)論
0/150
提交評(píng)論