CS251 - Computer Organization and Design - Spring 2008

Lecture 34 - Virtual Memory

Practical Details

  1. Assignment 8
  2. Assignment 9

Examples of Cache Memories

Set Associative

Effectively a set of direct mapping caches


Cache address Valid Tag Data Valid Tag Data Valid Tag Data Valid Tag Data
000...000 31 - n3 bits 31 - n3 bits 31 - n3 bits 31 - n3 bits


Line number in memory Line number in set Word number in line Access Size
31 to n3+1 n3 to n2+1 n2 to n1+1 n1 to 0
Tag Cache address Ignored

Circuit (Figure 7.17, page 503)

  1. Use line number in set to choose a horizontal set of lines
  2. In parallel match Line number in memory to each tag in the set
  3. In parallel use Word number in line to activate one word in each set
  4. All SetHits ORed to get Hit
  5. If (Hit) then
  6. Else

New Issues

Replacement Algorithm

Usually least recently used (LRU). i.e. most dusty

Others are possible

Virtual Memory

Like cache, but between main memory and disk

Disk Hardware

Spinning disk & read/write head

Disk speed

Seek time can be minimized by smart algorithms, rotational delay cannot. But predictive caching helps a lot in some disks.


Surely, virtual memory is an obsolete concept.


Virtual memory is indeed obsolete, but



Address translation (64 bit address, 4Kbyte pages, 1 terabyte physical memory)

Virtual address

63 to 12 11 to 0
Virtual page number Offset within page

maps to

Physical address

39 to 12 11 to 0
Physical page number Offset within page

Address translation uses a page table

Physical pages can be

Page table

Virtual page number Valid Physical page number
63 to 12 0/1 39 to 12


This is pretty gross, which means `not pretty at all'.

Integration of virtual memory with the cache

Table Lookaside Buffer (TLB)

Valid Dirty Ref Read Write Tag (Virtual Page Number) Physical Page Number
0/1 0/1 0/1 0/1 63 to 12 40 to 12


  1. Divide virtual address
    63 -- Virtual page number -- 12 11 -- page offset -- 0
  2. If virtual page number matches tag AND Valid AND Read OR Write then
    1. Increment Ref
    2. If (access is Write) then
      1. Set Dirty
    3. Form physical address
      39 -- Physical page number -- 12 11 -- page offset -- 0
    4. Divide phyical address
      39 -- Line number in memory -- 14 13 -- line number in cache --6 5 -- offset in line -- 2 1 -- acess size -- 0

      and access cache.

  3. Else if NOT (Read OR Write) then
    1. Raise memory protection exception
  4. Else if NOT(virtual page number matches tag AND Valid) then
    1. Raise page fault exception
    2. OS chooses page to replace.
    3. If (Dirty on that page) OS writes that page back to disk
    4. OS reads in new page from disk

Comment. OS usually swaps out any process that incurs a page fault so as to use the processor for something else.

Return to: