Address Translation 1, Lecture Slide - Computer Science, Slides of Computer Numerical Control

Address translation, Virtual memory, Approach, Segmentation with paging, Paged page table, Memory hierarchy, Hash functions, Caching

Typology: Slides

2010/2011

Uploaded on 10/07/2011

christina
christina 🇺🇸

4.6

(23)

393 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Address Translation (contd.)
Arvind Krishnamurthy
Spring 2004
Recap: Virtual Memory
nRequirements of implementing the translation table:
nNeeds to be fast
nSimplify memory allocation
nUse fixed-sized objects instead of variable-sized objects
nAvoid fragmentation (both internal and external)
nSupport sharing of code (or other pieces of program state)
nSupport incremental increase of stack, heap, etc.
nMake translation table data structures inaccessible to user
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Address Translation 1, Lecture Slide - Computer Science and more Slides Computer Numerical Control in PDF only on Docsity!

Address Translation (contd.)

Arvind Krishnamurthy

Spring 2004

Recap: Virtual Memory

n Requirements of implementing the translation table:

n Needs to be fast n Simplify memory allocation n Use fixed-sized objects instead of variable-sized objects n Avoid fragmentation (both internal and external) n Support sharing of code (or other pieces of program state) n Support incremental increase of stack, heap, etc. n Make translation table data structures inaccessible to user

Approaches

n Base & bounds approach:

n Simple, fast n But does not support sharing, incremental increase n Complex memory allocation

n Segment table:

n Top few bits encode segment number. Each segment has a base and bounds. n Supports sharing and allows holes in virtual address space n Complex memory allocation

n Page tables:

n Memory allocation done in small page sizes (4K – 16K) n Supports sharing n But need to allocate page table for entire virtual address space

VPage # offset

Virtual address

PPage# ...

PPage# ...

PPage # offset

Physical address

Page table seg size

Vseg #

Each segment has its own page table

Supports sharing of segments, incremental growth of stack etc.

Almost simple memory allocation

Segmentation with paging

Paged Page Tables

n Since it is a virtual address, it must be translated again

n Need to lookup the segment table to do translation n To break “recursion,” make one of the segment table entries contain a physical pointer to a page table n In other words, all the page table of all segments live in a special segment VPage # offset

seg size

Vseg #

Virtual address

Physical address to segment’s page table

Address Translation Example

n Translate virtual address:

n Segment: 0x n Page number: 0x n Offset: 0xDEF

0x3 0x00000 0x 0x3 0x00100 0x 0x3 0x00200 0x 0x0 0x04010 0x

Segment table

Paged Page Tables

VP1 off

Virtual address

seg size

VS

VP2 off

Virtual address

VS

PPage# ...

PPage# ...

PPage# ...

PPage# ...

PPage # off

VP2:

off2:

Paged Page Tables

TranslateAddr(vaddr) { <seg1, page1, offset1> = vaddr; PTPtr = LookupSegmentTable(seg1); PTEPtr = PTPtr + page1 * sizeof(PTE); if (PTEPtr is virtual) PTEPtr = TranslateAddr(PTEPtr); PPageNumber = PTEPtr; // ignore permission bits paddr = PPageNumberpage_size + offset1; return paddr; }

Generic Issues in Caching

n Cache hit: item is in cache

n Cache miss: item is not in cache, have to do full operation

n Effective access time = P(hit) * cost of hit + P(miss) * cost

of miss

n Issues:

n How do you find whether the item is in the cache or not? n If not in the cache, how do you choose what to replace from cache to make room? n Consistency – how do you keep cache copy consistent with real version?

Control Secondary Storage (Disk)

Processor

Registers Main Memory (DRAM)

Second Level Cache (SRAM)

CacheOn-Chip

1s 10,000,000s (10s ms)

Speed (ns): 10s 100s 100s Gs

Size (bytes): (^) Ks Ms

Tertiary Storage (Disk)

10,000,000,000s (10s sec) Ts

Memory Hierarchy

n Two principles: n Smaller the amount of memory, faster it can be accessed n Larger the amount of memory, cheaper per byte

Why caching works?

n Present the user with as much memory as is available in

the cheapest technology

n Provide access at the speed offered by the fastest

technology

n By taking advantage of the principle of locality

n Temporal locality: will reference same locations as accessed in the recent past n Spatial locality: will reference locations near those accessed in the recent past

Caching applied to address translation

n Often reference same page repeatedly, why go through

entire translation each time?

n Use Translation Look-aside Buffer (TLB)

CPU

TLB remember? Yes No remember!

Translation Box

(MMU) physical memory

virtual address

physical address

Data read or write (untranslated)

How to tell if needed translation is in TLB?

Option 1: Search table in sequential order

Option 2: “direct mapped”

n Restrict each virtual page to use specific slot in TLB

Vpage # Vpage #^ Ppage #

No: check full translation; replace entry

Yes Use translation

hash

Hash functions

n What is a good hash function?

n Table entry = (Vpage# / NUM_TLB_ENTRIES)

n Table entry = (Vpage# % NUM_TLB_ENTRIES)

Other strategies

Option 3: Set associative

Option 4: Check all entries of TLB in parallel

n Requires more hardware n Translation can be store anywhere in TLB n Referred to as “fully associative”

Vpage # Vpage # Ppage #

hash

Vpage #Ppage #

How do we choose which item to replace?

n For direct mapped, never any choice as to which item to

replace.

n But for set associative or fully associative cache have a choice

n What policy?

n Least recently used? n Random? n Most recently used?

n In hardware: often choose item to replace randomly

n Simple and fast

n In software: do something more sophisticated

n Tradeoff: spend CPU cycles to try to improve cache hit rate