Virtual Caches

42
Virtual Cach es กกกก กกกกกกก 4422005

description

Virtual Caches. กรกฎ คชฤทธิ์ 4422005. Virtual Address. Virtual Address. Physical Address. MMU. Main Memory. Virtual Cache. CPU. Data. Data. Virtual Caches. Virtual Caches. Problems with Virtual Caches Ambiguities Aliases. Physical Address. 0 x0000. 1234. * *. 0 x5000. - PowerPoint PPT Presentation

Transcript of Virtual Caches

Page 1: Virtual Caches

Virtual Caches

กรกฎ คชฤทธิ์�4422005

Page 2: Virtual Caches

Virtual Caches

CPUVirtualCache

MainMemory

MMU

Data Data

VirtualAddress

PhysicalAddress

VirtualAddress

Page 3: Virtual Caches

Virtual Caches

Problems with Virtual Caches•Ambiguities•Aliases

Page 4: Virtual Caches

Ambiguities

12

34

56

78

0 x0000

0 x5000

Physical

Address**

*

Page 5: Virtual Caches

Ambiguities Virtual Address

01000

Physical Address0 5000x

Maps to

Virtual Cache

010005678

*

*

Tag Data

Page 6: Virtual Caches

Ambiguities Virtual Address

01000

Physical Address0 0000x

Maps to

Virtual Cache

010005678

*

*

Tag Data

Page 7: Virtual Caches

Aliases

0x0000

0x1000

0x2000

0x3000

0x4000

0x5000

VirtualAddress Space 0x000

00x100

00x200

00x300

00x400

00x500

0

PhysicalAddress Space

Page 8: Virtual Caches

Managing a Virtual Cache

Context Switch• Process may use the same virtual add

ress to refer to different physical addr ess before and after context switch

• Kernel must flush everything the old p rocess had cached

• -Flushing a virtual cache can be a time consuming operation

Page 9: Virtual Caches

Managing a Virtual Cache

Fork• the child receive a complete copy of

the parent’s address space• Flushing during each context switch

eliminates most inconsistencies bet ween parent’s and child’s data

• But must consider about during the copy operations

Page 10: Virtual Caches

Managing a Virtual Cache - -Fork (without copy on write)

Parent’s Virtual Address Space

****

****

****

Kernel Virtual Space

Mapping to Parent’s Physical Pa

ges Temporary Mapping to

Child’s Phy sical Pages

for Copy Operation

Data Co pied to C hild’s Pa

ges

Page 11: Virtual Caches

Managing a Virtual Cache

Fork• - If write through caching is used, No

special flushing is needed during for k since at least one context switch m

ust occur before the child executes• - If write back caching is used, Main m

emory must be validated before tem porary mapping is removed

Page 12: Virtual Caches

Managing a Virtual Cache

Fork• if fork is implemented with co

- -py on write• - if write through, no flushing is n

eeded at fork time• - if write back, main memory mu

st be validated

Page 13: Virtual Caches

Managing a Virtual Cache

Exec• Discards the process’s current addr

ess space and replaces it with a ne w one for the new program the proc

ess will run• Possible to occur ambiguities• Kernel must invalidated all user data

from cache before execution begins

Page 14: Virtual Caches

Managing a Virtual Cache

Exit• Address space of process is discarded

• Last step of exit is to perform context switch that flushed th

e cache

Page 15: Virtual Caches

Managing a Virtual Cache

Brk and Sbrk• use to grow and shrink the pro

cess’s bss segment• growing bss causes no cache problems

• shrink bss, kernel must invalid ates data from cache

Page 16: Virtual Caches

Managing a Virtual Cache

Shared Memory and Mapped Files• no special cache management is n

eeded since the cache is flushed a t each context switch

• if single process attaches shared memory segment at different addr

ess ?

Page 17: Virtual Caches

Managing a Virtual Cache

I/O

CPUVirtualCache

MainMemory I/O

MMU

Data Data Data

Virtual Address Virtual Address Physical Address Physical Address

Page 18: Virtual Caches

Managing a Virtual Cache

I/O• Some problem occurs when usingDMA

• when write to device, kernel must validate main memory with cache

data before DMA starts• when read from device, cache mus

t be flushed

Page 19: Virtual Caches

Managing a Virtual Cache

- User Kernel Data Ambiguities• to prevent cached kernel data

from user process, cache must be flushed

• - Apollo DN 4000, add bit indica te user or kernel mode

Page 20: Virtual Caches

Virtual Caches with Keys

กรกฎ คชฤทธิ์�4422005

Page 21: Virtual Caches

Virtual Caches with KeysCurren

tProces

s Key

CPUVirtualCache

MainMemory

MMU

Data Data

VirtualAddress

PhysicalAddress

VirtualAddress

Page 22: Virtual Caches

Managing a Virtual Cache with Keys

Context Switch• Normally no need to flush the cach

e as long as enough keys that uniqu e can be assigned to each processe

s• when reassigning key, all entries ta

gged with affected key must be flushed

Page 23: Virtual Caches

Managing a Virtual Cache with Keys

Fork• No need to Flush• Some problem

Key1

Tag0 1x00

00

0

Data10

11

97

0

Key2

Tag0 1x00

00

0

Data10

11

97

0

Page 24: Virtual Caches

Managing a Virtual Cache with Keys Fork

• Some problemKey1

Tag0 1x00

00

0

Data10

11

97

0

- - -

Key1

Tag0 1x00

00

0

Data10

11

97

0

2 0 1x00

00

0

10

11

97

0

Page 25: Virtual Caches

Managing a Virtual Cache with Keys

Exec• A unique key must be chosen fo

r new address space• if reassigning key, all entries ta

gged with affected key must beflushed

Page 26: Virtual Caches

Managing a Virtual Cache with Keys

Exit• not necessary to invalidate cac

he at exit time• cache is flushed during contextswitch

Page 27: Virtual Caches

Managing a Virtual Cache with Keys

Brk and Sbrk• Same as pure virtual cache

Page 28: Virtual Caches

Managing a Virtual Cache with Keys

Shared Memory and MappedFiles• Can not share data within cache

ModM

Tag0 1x00

00

0

Data10

11

97

0

Key1

Mod-

Tag0 1x00

00

0

Data10

11

97

0

Key2

Page 29: Virtual Caches

Managing a Virtual Cache with Keys

I/O• Same as pure virtual cache

Page 30: Virtual Caches

Managing a Virtual Cache with Keys

- User Kernel Data Ambiguities• Kernel process have special key• User process can not access ker

nel data• Kernel process can not share us

er data

Page 31: Virtual Caches

Virtual Cache Usage in MMUs

- Special purpose cache, Translation L ookside Buffer (TLB) or Address trans

lation Cache (ATC)• caching most recently used page mapping

• - - speed up virtual to physical address tra nslation process

• must be flush on each context switch

Page 32: Virtual Caches

Virtual Caches

with Physical A ddress Tags

กรกฎ คชฤทธิ์�4422005

Page 33: Virtual Caches

Virtual Caches with Physical Tags

CPU Virtual Cache

withPhysic

al Tags

MainMemory

MMU

Data Data

VirtualAddress

PhysicalAddress

Page 34: Virtual Caches

Managing a Virtual Cache with Physical Tags

Context Switch• Normally no need to flush the cache

• No keys to mange as virtual cac he with keys

Page 35: Virtual Caches

Managing a Virtual Cache with Physical Tags

Fork• No cache flushing is required fo

r fork• Data can be shared in cache• No aliases can occur

Page 36: Virtual Caches

Managing a Virtual Cache with Physical Tags

Exec• Address space not be use by an

y process•exec deallocates pages, must b

e ensure that stale data is remo ved prior to allocating page to n

ew process

Page 37: Virtual Caches

Managing a Virtual Cache with Physical Tags

Exit• Can be either flushed at system

call or postponed until physical page are reuse

Page 38: Virtual Caches

Managing a Virtual Cache with Physical Tags

Brk and Sbrk• Like exec and exit• Can be either flushed at system

call or postponed until physical page are reuse

Page 39: Virtual Caches

Managing a Virtual Cache with Physical Tags

Shared Memory and MappedFiles• Can share data in cache• Better hit ratio for shared memory

Page 40: Virtual Caches

Managing a Virtual Cache with Physical Tags

I/O• Same as pure virtual cache

Page 41: Virtual Caches

Managing a Virtual Cache with Physical Tags

- User Kernel Data Ambiguities• No ambiguities between user a

nd kernel data• Kernel can reference cached us

er data directly

Page 42: Virtual Caches

The End