Docsity

Lecture Notes on Memory - High Performance Computer Architecture | CS 6290, Study notes of Computer Science

Partial preview of the text

Download Lecture Notes on Memory - High Performance Computer Architecture | CS 6290 and more Study notes Computer Science in PDF only on Docsity!

CS6290 Memory

Views of Memory • Real machines have limited amounts of

memory

– 640KB? A few GB? – (This laptop = 2GB)

• Programmer doesn’t want to be bothered

– Do you think, “oh, this computer only has 128MB

so I’ll write my code this way…”

– What happens if you run on a different machine?

Programmer’s View • Really “Program’s View”• Each program/process gets its own 4GB

space

Kernel

Text

Data Heap Stack

Kernel

Text Data

Heap Stack

Kernel

Text

Data Heap Stack

CPU’s View • At some point, the CPU is going to have to

load-from/store-to memory… all it knows isthe real, A.K.A.

physical

memory

• … which unfortunately

is often < 4GB

• … and is never

4GB

per process

Page Table • Map from virtual addresses to physical

locations

0K 4K 8K 12K

Virtual

Addresses

0K 4K 8K 12K 16K20K24K28K

Physical

Addresses

“Physical Location” may

include hard-disk

Page Table implements

this V

Æ

P mapping

Page Tables

0K 4K 8K 12K

0K 4K 8K 12K 16K 20K 24K 28K

0K 4K 8K 12K

Physical Memory

Simple Page Table

• Flat organization

– One entry per page – Entry contains physical page

number (PPN) or indicates pageis on disk or invalid

– Also meta-data (e.g.,

permissions, dirtiness, etc.)

One entry per page

Multi-Level Page Tables

Level 1

Level 2

Page Offset

Physical Page Number

Virtual Page Number

CPU Memory Access •

Program deals with virtual addresses

“Load R1 = 0[R2]”

On memory instruction

Compute virtual address (0[R2])

Compute virtual page number

Compute physical address of VPN’s page tableentry

Load* mapping

Compute physical address

Do the actual Load* from memory

Could be more depending

On page table organization

Impact on Performance? • Every time you load/store, the CPU must

perform two (or more) accesses!

• Even worse, every

fetch

requires translation

of the PC!

• Observation:

– Once a virtual page is mapped into a physical

page, it’ll likely stay put for quite some time

Translation Cache: TLB • TLB = Translation Look-aside Buffer

TLB

Virtual

Address

Cache

Data

Physical Address

Cache

Tags

Hit?

If TLB hit, no need to do page table lookup

from memory

Note: data cache

accessed by physical

addresses now

PAPT Cache • Previous slide showed Physically-Addressed

Physically-Tagged cache

– Sometimes called PIPT (I=Indexed)

• Con: TLB lookup and cache access serialized

– Caches already take > 1 cycle

• Pro: cache contents valid so long as page

table not modified

Virtually Indexed Physically Tagged

Virtual

Address

Cache

Data

Cache

Tags

Hit?

  • Pro: latency – TLB parallelized• Pro: don’t need to flush $ on process swap• Con: Limit on cache indexing (can only use

bits

not

from the VPN/PPN)

TLB

Physical Address

=

Physical Tag

Big page size can help here

TLB Design • Often fully-associative

– For latency, this means few entries – However, each entry is for a whole page – Ex. 32-entry TLB, 4KB page… how big of working

set while avoiding TLB misses?

• If many misses:

– Increase TLB size (latency problems) – Increase page size (fragmenation problems)