address transla on main points
play

Address Transla+on Main Points Address Transla+on Concept - PowerPoint PPT Presentation

Address Transla+on Main Points Address Transla+on Concept How do we convert a virtual address to a physical address? Flexible Address Transla+on


  1. Address ¡Transla+on ¡

  2. Main ¡Points ¡ • Address ¡Transla+on ¡Concept ¡ – How ¡do ¡we ¡convert ¡a ¡virtual ¡address ¡to ¡a ¡physical ¡ address? ¡ • Flexible ¡Address ¡Transla+on ¡ – Base ¡and ¡bound ¡ – Segmenta+on ¡ – Paging ¡ – Mul+level ¡transla+on ¡ • Efficient ¡Address ¡Transla+on ¡ – Transla+on ¡Lookaside ¡Buffers ¡ – Virtually ¡and ¡physically ¡addressed ¡caches ¡

  3. Address ¡Transla+on ¡Concept ¡ Virtual Address Raise Invalid Processor Translation Exception Valid Physical Memory Data Physical Address Data

  4. Address ¡Transla+on ¡Goals ¡ • Memory ¡protec+on ¡ • Memory ¡sharing ¡ – Shared ¡libraries, ¡interprocess ¡communica+on ¡ • Sparse ¡addresses ¡ – Mul+ple ¡regions ¡of ¡dynamic ¡alloca+on ¡(heaps/stacks) ¡ • Efficiency ¡ – Memory ¡placement ¡ – Run+me ¡lookup ¡ – Compact ¡transla+on ¡tables ¡ • Portability ¡

  5. Bonus ¡Feature ¡ • What ¡can ¡you ¡do ¡if ¡you ¡can ¡(selec+vely) ¡gain ¡ control ¡whenever ¡a ¡program ¡reads ¡or ¡writes ¡a ¡ par+cular ¡virtual ¡memory ¡loca+on? ¡ • Examples: ¡ – Copy ¡on ¡write ¡ – Zero ¡on ¡reference ¡ – Fill ¡on ¡demand ¡ – Demand ¡paging ¡ – Memory ¡mapped ¡files ¡ – … ¡

  6. A ¡Preview: ¡MIPS ¡Address ¡Transla+on ¡ • SoVware-­‑Loaded ¡Transla+on ¡lookaside ¡buffer ¡(TLB) ¡ – Cache ¡of ¡virtual ¡page ¡-­‑> ¡physical ¡page ¡transla+ons ¡ – If ¡TLB ¡hit, ¡physical ¡address ¡ – If ¡TLB ¡miss, ¡trap ¡to ¡kernel ¡ – Kernel ¡fills ¡TLB ¡with ¡transla+on ¡and ¡resumes ¡execu+on ¡ • Kernel ¡can ¡implement ¡ any ¡ page ¡transla+on ¡ – Page ¡tables ¡ – Mul+-­‑level ¡page ¡tables ¡ – Inverted ¡page ¡tables ¡ – … ¡

  7. Physical A ¡Preview: ¡MIPS ¡Lookup ¡ Memory Virtual Address Page# Offset Translation Lookaside Buffer (TLB) Virtual Page Page Frame Access Physical Address Matching Entry Frame Offset Page Table Lookup

  8. Virtually ¡Addressed ¡Base ¡and ¡Bounds ¡ Processor ’ s View Implementation Physical Memory Virtual Base Base Memory Virtual Virtual Physical Address Address Address Processor Processor Base+ Bound Bound Raise Exception

  9. Ques+on ¡ • With ¡virtually ¡addressed ¡base ¡and ¡bounds, ¡ what ¡is ¡saved/restored ¡on ¡a ¡process ¡context ¡ switch? ¡

  10. Virtually ¡Addressed ¡Base ¡and ¡Bounds ¡ • Pros? ¡ – Simple ¡ – Fast ¡(2 ¡registers, ¡adder, ¡comparator) ¡ – Safe ¡ – Can ¡relocate ¡in ¡physical ¡memory ¡without ¡changing ¡ process ¡ • Cons? ¡ – Can’t ¡keep ¡program ¡from ¡accidentally ¡overwri+ng ¡its ¡ own ¡code ¡ – Can’t ¡share ¡code/data ¡with ¡other ¡processes ¡ – Can’t ¡grow ¡stack/heap ¡as ¡needed ¡

  11. Segmenta+on ¡ • Segment ¡is ¡a ¡con+guous ¡region ¡of ¡ virtual ¡memory ¡ • Each ¡process ¡has ¡a ¡segment ¡table ¡(in ¡hardware) ¡ – Entry ¡in ¡table ¡= ¡segment ¡ • Segment ¡can ¡be ¡located ¡anywhere ¡in ¡physical ¡ memory ¡ – Each ¡segment ¡has: ¡start, ¡length, ¡access ¡permission ¡ • Processes ¡can ¡share ¡segments ¡ – Same ¡start, ¡length, ¡same/different ¡access ¡permissions ¡

  12. Segmenta+on ¡ Process ���� View Implementation Physical Memory Base 3 Virtual Stack Memory Base+ Processor Virtual Bound 3 Code Segment Table Virtual Address Processor Address Base Bound Access Base 0 Segment O ff set Read Code Data R/W Base+ R/W Bound 0 R/W Heap Base 1 Data Physical Address Base+ Stack Bound 1 Raise Exception Base 2 Heap Base+ Bound 2

  13. Segment ¡start ¡ length ¡ code ¡ 0x4000 ¡ 0x700 ¡ 2 ¡bit ¡segment ¡# ¡ 12 ¡bit ¡offset ¡ data ¡ 0 ¡ 0x500 ¡ heap ¡ -­‑ ¡ -­‑ ¡ stack ¡ 0x2000 ¡ 0x1000 ¡ Physical ¡Memory ¡ Virtual ¡Memory ¡ main: ¡240 ¡ store ¡#1108, ¡r2 ¡ x: ¡108 ¡ a ¡b ¡c ¡\0 ¡ 244 ¡ store ¡pc+8, ¡r31 ¡ … ¡ 248 ¡ jump ¡360 ¡ main: ¡4240 ¡ store ¡#1108, ¡r2 ¡ 24c ¡ 4244 ¡ store ¡pc+8, ¡r31 ¡ … ¡ 4248 ¡ jump ¡360 ¡ strlen: ¡360 ¡ loadbyte ¡(r2), ¡r3 ¡ 424c ¡ … ¡ … ¡ … ¡ … ¡ 420 ¡ jump ¡(r31) ¡ strlen: ¡4360 ¡ loadbyte ¡(r2),r3 ¡ … ¡ … ¡ x: ¡1108 ¡ a ¡b ¡c ¡\0 ¡ 4420 ¡ jump ¡(r31) ¡ … ¡ … ¡

  14. Ques+on ¡ • With ¡segmenta+on, ¡what ¡is ¡saved/restored ¡on ¡ a ¡process ¡context ¡switch? ¡

  15. UNIX ¡fork ¡and ¡Copy ¡on ¡Write ¡ • UNIX ¡fork ¡ – Makes ¡a ¡complete ¡copy ¡of ¡a ¡process ¡ • Segments ¡allow ¡a ¡more ¡efficient ¡implementa+on ¡ – Copy ¡segment ¡table ¡into ¡child ¡ – Mark ¡parent ¡and ¡child ¡segments ¡read-­‑only ¡ – Start ¡child ¡process; ¡return ¡to ¡parent ¡ – If ¡child ¡or ¡parent ¡writes ¡to ¡a ¡segment ¡(ex: ¡stack, ¡heap) ¡ • trap ¡into ¡kernel ¡ • make ¡a ¡copy ¡of ¡the ¡segment ¡and ¡resume ¡

  16. Processor ’ s View Implementation Physical Memory Process 1`s View Virtual Memory P2`s Data Code P1`s Processor Processor Heap Virtual Segment Table Address Data Seg. Offset Base Bound Access 0x0500 Read Code 0 500 P1`s R/W Stack Data Virtual Heap R/W Address Heap P1`s R/W Stack Data Stack Physical Address P2`s Heap Process 2`s View Code P1’s+ P2`s Processor Processor Code Virtual Segment Table P2`s Address Data Stack Seg. Offset Base Bound Access 0x0500 0 500 Code Read Data R/W Virtual Heap R/W Address Heap Stack R/W Stack

  17. Zero-­‑on-­‑Reference ¡ • How ¡much ¡physical ¡memory ¡is ¡needed ¡for ¡the ¡ stack ¡or ¡heap? ¡ – Only ¡what ¡is ¡currently ¡in ¡use ¡ • When ¡program ¡uses ¡memory ¡beyond ¡end ¡of ¡stack ¡ – Segmenta+on ¡fault ¡into ¡OS ¡kernel ¡ – Kernel ¡allocates ¡some ¡memory ¡ • How ¡much? ¡ – Zeros ¡the ¡memory ¡ • avoid ¡accidentally ¡leaking ¡informa+on! ¡ – Modify ¡segment ¡table ¡ – Resume ¡process ¡

  18. Segmenta+on ¡ • Pros? ¡ – Can ¡share ¡code/data ¡segments ¡between ¡processes ¡ – Can ¡protect ¡code ¡segment ¡from ¡being ¡overwripen ¡ – Can ¡transparently ¡grow ¡stack/heap ¡as ¡needed ¡ – Can ¡detect ¡if ¡need ¡to ¡copy-­‑on-­‑write ¡ • Cons? ¡ – Complex ¡memory ¡management ¡ • Need ¡to ¡find ¡chunk ¡of ¡a ¡par+cular ¡size ¡ – May ¡need ¡to ¡rearrange ¡memory ¡from ¡+me ¡to ¡+me ¡to ¡ make ¡room ¡for ¡new ¡segment ¡or ¡growing ¡segment ¡ • External ¡fragmenta+on: ¡wasted ¡space ¡between ¡chunks ¡

  19. Paged ¡Transla+on ¡ • Manage ¡memory ¡in ¡fixed ¡size ¡units, ¡or ¡pages ¡ • Finding ¡a ¡free ¡page ¡is ¡easy ¡ – Bitmap ¡alloca+on: ¡0011111100000001100 ¡ – Each ¡bit ¡represents ¡one ¡physical ¡page ¡frame ¡ • Each ¡process ¡has ¡its ¡own ¡page ¡table ¡ – Stored ¡in ¡physical ¡memory ¡ – Hardware ¡registers ¡ • pointer ¡to ¡page ¡table ¡start ¡ • page ¡table ¡length ¡

  20. Paged ¡Transla+on ¡(Abstract) ¡ Proces ����� View Physical Memory Frame 0 Code 0 Data 0 VPage 0 Heap 1 Code VPage 1 Code 1 Heap 0 Data Data 1 Heap Heap 2 Stack VPage N Stack 1 Stack 0 Frame M

  21. Paged ¡Transla+on ¡(Implementa+on) ¡ Physical Memory Frame 0 Physical Frame 1 Address Frame Offset Processor Page Table Virtual Address Frame Access Page # Offset Virtual Address Page # Offset Physical Address Frame Offset Frame M

  22. Process ¡View ¡ Physical ¡Memory ¡ A ¡ B ¡ I ¡ J ¡ C ¡ K ¡ D ¡ Page ¡Table ¡ L ¡ E ¡ 4 ¡ F ¡ 3 ¡ G ¡ H ¡ 1 ¡ E ¡ I ¡ F ¡ J ¡ G ¡ K ¡ H ¡ L ¡ A ¡ B ¡ C ¡ D ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend