Docsity

Virtual Memory - Computer Architecture - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Virtual Memory - Computer Architecture - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Virtual Memory

View of Memory Hierarchies

Regs

L2 Cache

Memory

Disk

Tape

Instr. Operands

Blocks

Pages

Files

Upper Level

Lower Level

Faster

Larger

Cache Blocks

Thus far

Next: Virtual Memory

Virtual Memory: Motivation

  • If Principle of Locality allows caches to

offer (usually) speed of cache memory with

size of DRAM memory,

then recursively why not use at next level to

give speed of DRAM memory, size of Disk

memory?

  • Treat Memory as โ€œcacheโ€ for Disk !!!
  • Share memory between multiple processes

but still provide protection โ€“ donโ€™t let one

program read/write memory of another

  • Address space โ€“ give each program the

illusion that it has its own private memory

  • Suppose code starts at addr 0x40000000. But different processes have different code, both at the same address! So each program has a different view of memory

Virtual to Physical Address Translation

  • Each program operates in its own virtual address space;

~only program running

  • Each is protected from the other
  • OS can decide where each goes in memory
  • Hardware (HW) provides virtual -> physical mapping

virtual address (inst. fetch load, store)

Program operates in its virtual address space

HW mapping physical address (inst. fetch load, store)

Physical memory (incl. caches)

Mapping Virtual Memory to Physical Memory

Physical Memory

โˆž

Code

Static

Heap

Stack

64 MB

  • Divide into equal sized chunks (about 4KB)
  • Any chunk of Virtual Memory assigned to any chuck of Physical Memory (โ€œpageโ€)

Virtual Memory Mapping

Virtual Address: page no. offset

Page Table Base Reg

Page Table located in physical memory

(actually, concatenation)

index into page table

Physical Memory Address

Page Table

Val -id

Access Rights

Physical Page Address

V A.R. P. P. A.

Docsity.com

Issues in VM Design

What is the size of information blocks that are transferred from secondary to main storage (M)? โ‡’ page size (Contrast with physical block size on disk, I.e. sector size)

Which region of M is to hold the new block โ‡’ placement policy

How do we find a page when we look for it? โ‡’ block identification

Block of information brought into M, and M is full, then some region of M must be released to make room for the new block โ‡’ replacement policy

What do we do on a write? โ‡’ write policy

Missing item fetched from secondary memory only on the occurrence of a fault โ‡’ demand load policy

pages

reg

cache mem^

disk

frame

Memory Organization with TLB

  • TLBs usually small, typically 128 - 256 entries
  • Like any other cache, the TLB can be fully associative, set associative, or direct mapped

Processor

TLB

Lookup

Cache

Main Memory

VA PA^ miss

hit

data

Trans- lation

hit

miss

Typical TLB Format

Virtual Physical Dirty Ref Valid Access Address Address Rights

  • TLB just a cache on the page table mappings
  • TLB access time comparable to cache (much less than main memory access time)
  • Ref: Used to help calculate LRU on replacement
  • Dirty: since use write back, need to know whether or not to write page to disk when replaced

TLB Miss

  • If the address is not in the TLB, MIPS traps

to the operating system

  • The operating system knows which program

caused the TLB fault, page fault, and knows

what the virtual address desired was

requested

1 2 9

valid virtual physical

TLB Miss: If data is in Memory

  • We simply add the entry to the TLB, evicting

an old entry from the TLB

1 7 32 1 2 9

valid virtual physical

What if the memory is full?

  • We load the page off the disk into a least

recently used block of memory, using a

DMA transfer

  • Meantime we switch to some other process waiting to be run
  • When the DMA is complete, we get an

interrupt and update the process's page table

  • So when we switch back to the task, the desired data will be in memory

Virtual Memory Problem # 2

  • Page Table too big!
    • 4GB Virtual Memory รท 4 KB page โ‡’ ~ 1 million Page Table Entries โ‡’ 4 MB just for Page Table for 1 process, 25 processes โ‡’ 100 MB for Page Tables!
  • Variety of solutions to tradeoff memory size of

mapping function for slower when miss TLB

  • Make TLB large enough, highly associative so rarely miss on address translation