นายพิสัณห์ ดวงจันทร์ รหัส 4422035

39
นนนนนนนนนน นนนนนนนนน นนนนนนนนนน นนนนนนนนน นนนน นนนน 4422035 4422035

Upload: melissa-rosales

Post on 30-Dec-2015

41 views

Category:

Documents


0 download

DESCRIPTION

Cache Memory Systems. Chapter 6: Physical Cache Chapter 7: Efficient Cache Management Technique. นายพิสัณห์ ดวงจันทร์ รหัส 4422035. Chapter 6: Physical Cache. Physical Cache Organization Physical Cache Management Multilevel Cache. Physical Cache Organization. Virtual Address. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

นายพิ�สั�ณห์ ดวงจั�นทร์ ร์ห์�สั นายพิ�สั�ณห์ ดวงจั�นทร์ ร์ห์�สั44442203522035

Page 2: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Physical Cache Or Physical Cache Organizationganization Physical Cache M Physical Cache Managementanagement Multilevel Cache Multilevel Cache

Page 3: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

CPUCPU

PhysicalPhysicalCacheCache Main Main

MemoryMemory

MMUMMU

VirtualVirtualAddressAddress

PhysicalPhysicalAddressAddress

PhysicalPhysicalAddressAddress

DataData DataData

Physical Cache Org Physical Cache Organizationanization

Hit!Miss

Page 4: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Physical Cache Organization

ข้�อดี�ข้อง Physical Cache– ไม่ม่�ปั�ญหาเรื่��อง Ambiguity และ Alias– ไม่ต้�องทำ�าการื่ flush

CPUCPU

PhysicalPhysicalCacheCache Main Main

MemoryMemory

MMUMMU

VirtualAddress

PhysicalAddress

PhysicalAddress

Data Data

Page 5: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Physical Cache Organization

Process ทำ��ไม่ไดี�ใช้�ข้�อม่�ลรื่วม่ก�น อยู่�ก�นคนละ Physical Page– Physical Tag ไม่ม่�ทำางทำ��จะ match ก�น

Process ทำ��ใช้�ข้�อม่�ลรื่วม่ก�น อยู่�ใน Physical Page เดี�ยู่วก�น– เพื่��อจะไดี� ทำ�า index รื่วม่ก�น และ match Tag ก�นไดี� ==> Hit!

ไม่เก%ดี Alias และ Ambiguity ข้&'น เพื่รื่าะไม่ใช้� Virtual address

โดียู่ทำ��ว ๆ ไปัแล�ว จะไม่ต้�อง flush สาม่ารื่ถทำ�า Bus WatchingBus Watching ไดี�

Page 6: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Physical Cache Organization ในรื่ะบบทำ��ไม่ม่� Physical cache: ข้�อม่�ลข้อง Process ทำ��

ไม่เก��ยู่วข้�องก�น อาจจะ อยู่�ใน Virtual address เดี�ยู่วก�น(Virtual Line เดี�ยู่วก�น)

ในรื่ะบบทำ��ใช้� Physical cache: ข้�อม่�ลข้อง Process ทำ��ไม่ เก��ยู่วข้�องก�น แม่�วาจะ อยู่�ใน Virtual address เดี�ยู่วก�น

แต้จะอยู่�ในคนละ Physical Line เพื่รื่าะจะน�าเอาPhysical address ม่าจ�ดี index

แก�ปั�ญหาส�าค�ญ ข้อง Virtual cache ลงไดี� (Alias & Ambiguity)

ม่�ความ่สาม่ารื่ถในการื่กรื่ะจายู่ข้�อม่�ลภายู่ใน Cache ไดี�อยู่างดี� เยู่��ยู่ม่

Page 7: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Managing a Physical Cache Physical cache ไม่ต้�องทำ�าการื่ Flushing เพื่รื่าะ Context Switch time:

– ใช้� Physical tag ==> ไม่เก%ดี Alias และAmbiguity ==> ไม่ต้�อง flush

– Hit ratio ส�ง เพื่รื่าะม่�การื่กรื่ะจายู่ข้�อม่�ลไดี�ดี� - - Fork time (Copy on Write Sharing):

– ทำ�'ง Parent และ Child process ใช้� P hysical addr ess อ�นเดี�ยู่วก�น ==> ไม่เก%ดี Alias และ Ambiguity

==> ไม่ต้�อง flush– Copy Page ไดี�งายู่ เพื่รื่าะไม่ไดี�น�า Virtual address

ทำ��ทำ�า Temporary mapping ม่าเก��ยู่วข้�อง

Page 8: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Managing a Physical Cache Exec, Exit, Brk, Sbrk time:

– Process ทำ��ไม่เก��ยู่วข้�องก�น อยู่�คนละ Physical page– เม่��อ Process A จบการื่ทำ�างาน ==> memory

deallocation ==> Process อ��น ๆ ไม่สาม่ารื่ถเข้�าถ&งPhysical page ข้อง process A ไดี� ==> ข้�อม่�ลเกาทำ��

ค�างอยู่� ไม่ม่�ทำางถ�กเข้�าถ&ง (access)– เม่��อเน�'อทำ��สวนน�'ถ�ก reallocate ==> UNIX จะม่�การื่ทำ�า

Zero-filling เอง– ดี�งน�'น ไม่ต้�อง flush

Shared Memory and Mapped Files: – ใช้� Physical address ในการื่อ�างถ&งข้�อม่�ลทำ��ใช้�รื่วม่ก�น

==> ไม่เก%ดี Alias ( เหม่�อนก�บการื่ใช้� Virtual address) ==> ไม่ต้�อง flush

Page 9: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Managing a Physical Cache

- User Kernel Data Ambiguity: – เม่��อม่�การื่ access Kernel’s Page ==> เช้/ค

Permission ==> User process ไม่สาม่ารื่ถ เข้�าถ&ง Kernel data ไดี�

– เน��องจากใช้� Physical address ==> ไม่เก%ดีAlias และ Ambiguity ==> ไม่ต้�อง flush

I/O and Bus Watching: – Virtual Cache: เม่��อเก%ดี I/O Operation ==>

Data Inconsistency ==> Flushing– P hysical Cache “ใช้� Bus Watching” ==>

ข้�อม่�ลใน Cache ม่�การื่แก�ไข้อ�ต้โนม่�ต้% ==> ไม่ต้�องflush

Page 10: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Bus Watc Bus Watchinghing

Cache, Memory and I/O interconnection on a System Bus

CPU/MMU

Physical Cache

I/OMemory

System Bus

Snooping

Page 11: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Bus Watching ข้�อม่�ลสงไปัใน bus ในรื่�ปัข้อง Bus Transaction ข้นาดีข้อง Bus Transaction = 12 words,

24 words ฯลฯ Cache จะคอยู่จ�บต้าดี� (monitor) ก%จกรื่รื่ม่ต้าง ๆ

ใน Bus เรื่�ยู่กวา “Snooping” Cache Look-up Operation

– น�า Address ม่าผ่าน Hash function ==> Line/Set ==> Indexing ==> ต้รื่วจสอบ Tag

… วา•Miss ==> ไม่ต้�องทำ�าอะไรื่•Hit ==> ดี�าเน%นการื่ก�บข้�อม่�ลทำ��อยู่�ใน Cache (Cache-Resident)

Page 12: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Intel i860 XP Cache Architecture VPN Offset PPN Offset

Line0

1

2

3

0

1

2

3

Line0

1

2

3

0

1

2

3

VirtualTag

PhysicalTagData

.

.

.

Set

0

1

Set

0

1

11< ..5>

11< ..5>

Virtual address from CPU Physical address from bus

Page 13: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Multilevel Cache

CPURegisters

CPURegisters

1st LevelCache

1st LevelCache

2nd LevelCache

2nd LevelCache

MainMemory

MainMemory

1Primary ( st Level) Cache ==> FFFFFF & FFFFFFF Virtual Cache

Secondary (2nd Level) Cache ==> Lower & Larger Physical Cache

ทำ�า MMU Translation พื่รื่�อม่ ๆ ก�บ 1st Level Cache Look-up ไดี�

ถ�า miss ทำ�� 1st Level Cache ==> จะไปัดี�ทำ�� 2 nd Level Cache ต้อไปั โดียู่ใช้� Physical address ทำ��ไดี�จาก MMU Translation

เปั3นการื่ผ่สม่ผ่สานข้�อดี�ข้อง Cache ทำ�'ง 2 แบบไว�ดี�วยู่ก�น

Page 14: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Intel i860 XR Cache Architecture

CPUCPU PhysicalCache

PhysicalCache

I/OI/O

MainMemory

MainMemory

MMUMMU

DataCacheData

Cache

InstCacheInst

Cache

ExternalCache

VirtualAddress

PhysAddr

PhysAddr

DataDataData

Instructions

Bus

i860 XR

Page 15: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

MIPS R4000 Cache Architecture

CPUCPU PhysicalCache

PhysicalCache

I/OI/O

MainMemory

MainMemory

MMUMMU

DataCacheData

Cache

InstCacheInst

Cache

ExternalCache

VirtualAddress

PhysAddr

PhysAddr

DataDataData

Instructions

Bus

MIPS R4000

Page 16: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Address Space La Address Space Layoutyout Cache Size Bound Cache Size Bound

ed Flushing ed Flushing Delayed Cache In Delayed Cache In

validation validation - Cache Aligning D- Cache Aligning D

ata Structure ata Structure

Page 17: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Efficient Cache Management Techniques การื่ต้�ดีส%นปัรื่ะส%ทำธิ%ภาพื่ข้อง Cache ข้&'นอยู่�ก�บ 3

ปั�จจ�ยู่– Locality of Reference– Physical design – Cache Management Techniques

Locality of Reference และ Physical design of the cache น�'นแก�ไข้ไม่ไดี�

เปั5าหม่ายู่ ==> Cache ManagementTechniques

Page 18: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Efficient Cache Management Techniques ม่� 4 เทำคน%ค– Address Space Layout– Cache Size Bounded Flushin

g– Delayed Cache Invalidation– - Cache Aligning Data Structure

Page 19: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Address Space Layout Virtually Indexed Cache

– ปักต้%แล�ว จะ ใช้� Hash algorithm ในการื่กรื่ะ จายู่ข้�อม่�ลข้อง text, data และ stack

region ข้อง Process ( ทำ�าเปั3น index)– ทำ�าการื่ก�าหนดี Virtual address ทำ��เหม่าะสม่ให�

แก text, data และ stack region เพื่��อไม่ให�เก%ดี เปั3น index ทำ��ซ้ำ�'าซ้ำ�อนก�น

TextData/bssStack

0 0x0 8x00

00

00

0

0xffff00

00

Page 20: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Address Space Layout Virtually Indexed Cache

0

x00

x10

0

x20

0

x30

…0

xff0

0

1

2

3

…2

5

5

0 8x00

00

00

0

0 8x00

00

01

0

0 8x00

00

02

0

0 8x00

00

03

0

…0 8x00

00

0

0

1

2

3

…2

5

5

0xffff00

00

0xffff00

10

0xffff00

20

0xffff00

30

…0xffff00ff

0

1

2

3

…2

5

5

Text index Data index Stack index

Page 21: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

0xffff00ff

AddressSpace

60

KUnused

Text

Stack

Data

Cache 0

255

0

0

0

xxx

08

00

00

0fff.

0 8x00

00

00

0

0xfff00

00

Address Space Layout Virtually Indexed Cache

Page 22: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Address Space Layout Virtually Indexed Cache

0

x00

x10

0

x20

0

x30

…0

xff0

0

1

2

3

…2

5

5

0 8x00

06

00

0

0 8x00

06

01

0

0 8x00

06

02

0

0 8x00

06

03

0

…0 8x00

06ff0

1

5

3

6

1

5

3

7

1

5

3

8

1

5

3

9

…1

7

9

1

0xffffx00

0

0xffffx01

0

0xffffx02

0

0xffffx03

0

…0xffffxxx0

3

8

4

0

3

8

4

1

3

8

4

2

3

8

4

3

…4

0

9

5

Text index Data index Stack index

Page 23: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

0xffff0fff

AddressSpaceText

Stack

Data

Cache

24K

0

0

0

xxx

0 8x00

06

0fff.

0 8x00

06

00

0

0xfff00

00

Address Space Layout Virtually Indexed Cache

40K

Page 24: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Address Space Layout ข้�อจ�าก�ดีข้อง Virtually Indexed C

ache – ใช้�ไดี�ก�บรื่ะบบทำ��สาม่ารื่ถคาดีหม่ายู่เน�'อทำ��ทำ��

application ต้�องการื่ไดี�– ใช้�ไม่ไดี�เลยู่ก�บรื่ะบบทำ��ม่� Cache ข้นาดีเล/ก

โดียู่เฉพื่าะทำ��ม่�ข้นาดีน�อยู่กวา หรื่�อเทำาก�บข้นาดีข้อง Page ข้อง Process

Page 25: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Text

Stack

Data

Cache

Address Space A

0x0

0xfff

0x80006000

0x800006fff

0xfffff000

0xffffffff

Text

Stack

Data

Address Space B

0x0

0xfff

0x80006000

0x800006fff

0xfffff000

0xffffffff

Address Space Layout Dynamic Address Binding

Page 26: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Address Space Layout Dynamic Address Binding

– ส8ม่ Starting address ต้อน link time หรื่�อ สวนข้อง stack สาม่ารื่ถทำ�าไดี�ต้อน exec

time• แต้ปักต้%แล�ว Address binding จะเก%ดีข้&'นแบบStatic ณ Link time

– ใช้� Position-independent code ( โปัรื่แกรื่ม่ทำ��ไม่ม่�การื่ binding ไปัยู่�ง Virtual address ใดี ๆ ในต้อน compile, link time)• ยู่�งไม่ม่�สถาปั�ต้ยู่กรื่รื่ม่ใดีทำ��รื่องรื่�บ Position-independent code

Page 27: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Address Space Layout ข้�อจ�าก�ดีข้อง Dynamic Address

Binding– ข้�อต้กลงต้าง ๆ รื่วม่ถ&ง Starting

address ม่าต้รื่ฐาน หายู่ไปั ทำ�าให�เส�ยู่เวลาต้รื่วจสอบโปัรื่แกรื่ม่ม่ากข้&'น

– ใช้�ไดี�ก�บรื่ะบบทำ��ม่� Cache ข้นาดีใหญ พื่อทำ�� จะทำ�าให�เก%ดี Locality of Reference

เทำาน�'น– เก%ดี Overhead ในการื่ค�านวณ Load

address

Page 28: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Address Space Layout Physically Indexed Cache

– ทำ�าการื่ allocate Physical page แบบกรื่ะจายู่

– ใช้� Modulo cache indexing แบงPhysical page ออกเปั3น n กล8ม่• โดียู่ทำ�� n = Cache size / Page size•Page แรื่ก จะอยู่�ทำ��ต้�าแหนง0•Page ทำ��สอง จะอยู่�ทำ��ต้�าแหนง1• ต้อไปัเรื่��อยู่ ๆ จนถ&งต้�าแหนงทำ�� n-1• เม่��อครื่บ ก/วนกล�บไปัทำ��ต้�าแหนง 0 ใหม่

Page 29: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Cache

0

1

2

3

4

5

6

7

Page Number

Physical Memory

Address Space Layout Physically Indexed Cache

Page 30: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Address Space Layout ข้�อจ�าก�ดีข้อง Physically Indexed

Cache– ใช้�ไดี�ก�บรื่ะบบทำ��ม่� Cache ข้นาดีใหญ

ม่ากกวาข้นาดีข้อง Page หลายู่ ๆ เทำา

Page 31: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Cache Size Bounded Flushing

ข้นาดีข้�อม่�ลทำ��ใหญทำ��ส8ดีทำ��จะถ�ก flush = ข้นาดีข้องCache– ถ�าต้�องทำ�าการื่ flush cache เม่��อ I/O buffer

ม่� ข้นาดี4K• ถ�า Cache ข้นาดี 2K 2==> Flush ครื่�'ง• ถ�า Cache ข้นาดี 4K FFFFF ==> ครื่�'งเดี�ยู่ว

– Cache ทำ��ม่�ข้นาดีใหญ จะลดี flushing overhead

Page 32: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Delayed Cache Invalidation การื่ทำ�า Invalidation บอยู่ ๆ ทำ�าให�ปัรื่ะส%ทำธิ%ภาพื่ข้องรื่ะบบลดีลงเพื่รื่าะ– เปั3น time consuming ==> ทำ�าทำ�ละ Line– โดียู่ปักต้%แล�ว Cache จะ flush ไดี� ทำ�ละ 1 line– เก%ดีการื่ invalidate line ทำ��ไม่ไดี�บรื่รื่จ8ข้�อม่�ลทำ��ต้�องการื่ลบ

ข้&'นไดี� บางกรื่ณ� สาม่ารื่ถ delay การื่ทำ�า Invalidation ออก

ไปัไดี�– 12K Virtual cache with physical tag; 4K

Page; 10 Processes– 1Invalidate ครื่�'ง: 1 Process = ดี�าเน%นการื่ก�บข้�อม่�ล

120K– 1Invalidate ครื่�'ง: 10 Processes = ดี�าเน%นการื่ก�บ

ข้�อม่�ล 12K

Page 33: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Delayed Cache Invalidation

Virtual Cache with Key– รื่อจนรื่ะบบใช้� Key ทำ��วางอยู่�หม่ดี และต้�องการื่ใช้� Key

ข้อง Defunct Process ==> Invalidate– Unused Key List: ดี&ง Key ออกไปัให� Process

ทำ��เก%ดีข้&'นใหม่– Used Key List: เก/บ Key ข้องบรื่รื่ดีา Defunct

Process ไว�– เม่��อ Unused Key List หม่ดี

•OS ทำ�าการื่ Invalidate Cache

• น�า Key ทำ�'งหม่ดีใน Used Key List ไปัให�แก Unused Key List

Page 34: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Delayed Cache Invalidation

Physically Tagged without BusWatching– คล�ายู่ ๆ ก�บทำ��ผ่านม่า ค�อม่�การื่ใช้� Free List ข้อง Phy

sical Page– Cl eanList: Physical Page เปัลา ๆ ส�าหรื่�บ

Process ใหม่– DirtyLi st: Physical Page ข้องบรื่รื่ดีา Defunct

Process – เม่��อ Clean List หม่ดี

•OS ทำ�าการื่ Invalidate Cache • ยู่�ายู่ทำ8ก Page ใน Dirty Li st ไปัให�แก Clean List

Page 35: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

- Cache Aligning Data Structure

ทำ�าให�ข้�อม่�ลทำ��โปัรื่แกรื่ม่ต้�องใช้�งาน บรื่รื่จ8ลง ใน Cache line ไดี�อยู่างเหม่าะสม่ เพื่��อ

– ลดีการื่ Miss – เพื่%�ม่ Locality of Reference

ข้�อม่�ลดี�งกลาว อาจจะเปั3น data structure ข้องโปัรื่แกรื่ม่ หรื่�อต้�วโปัรื่แกรื่ม่เองก/ไดี�

ใน UNIX โครื่งสรื่�างข้�อม่�ลทำ��เข้�าถ&งบอยู่ ทำ��ส8ดี ค�อ “ Process table”

Page 36: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

- Cache Aligning DataStructure

Line Cache

0

1

2

3

4

Entry 0

Entry 2

Entry 3 Entry 4

Entry 1

Entry 5

Entry 6 Entry 7

Page 37: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Cache

Entry 0

Entry 1

Entry 2

Entry 3

Entry 4

Padding

Padding

Padding

Padding

Padding

0

1

2

3

4

- Cache Aligning DataStructure

Line Cache

Page 38: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

- Cache Aligning DataStructure

ข้�อจ�าก�ดีข้อง Cache-Aligning Data Structure – Padding ข้นาดีใหญ ==> ลดีปัรื่ะส%ทำธิ%ภาพื่ข้อง

รื่ะบบ• เส�ยู่เน�'อทำ��วางไปัเปัลา ๆ• ลดี Locality of Reference

– ไม่ Portable เพื่รื่าะต้�องทำ�าการื่ built-in ข้นาดีข้องCache line ไว�ในโปัรื่แกรื่ม่

– เหม่าะก�บสถานการื่ณ;ทำ��ให�ความ่ส�าค�ญก�บ “ปัรื่ะส%ทำธิ%ภาพื่ ” “ข้อง โปัรื่แกรื่ม่ ม่ากกวา Portability”

• ต้�วอยู่าง เช้น OS

Page 39: นายพิสัณห์ ดวงจันทร์  รหัส 4422035

Thanks Yo - u : )