24
KVM Forum 2008 Nested paging hardware and software Benjamin Serebrin Jörg Rödel Advanced Micro Devices June 13, 2008

Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

KVM Forum 2008Nested paging hardware and software

Benjamin SerebrinJörg Rödel

Advanced Micro Devices

June 13, 2008

Page 2: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

2

Outline

1. Background

– AMD64 Page Walks and Caching

– Virtualization Terminology

– Memory Management in Virtualized Systems

2. Two-Dimensional Page Walks

– Nested Paging + Current Paging = 2D Page Walk

– 2D Page Walk Caching

– Hardware and Software 2D Page Walk Acceleration

3. KVM Implementation and Results

– KVM Software Implementation

– Results

Page 3: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

3

Four-Level AMD64 Page Walk

B

C

D

A

Cache Translation

in TLB

Page Tables

L1

L2

L3

L4

Data

L4 PT BaseVirtual Address

PA

PA

PA

PA

PA

L4 data PA = Data VA + PT Base

L3 data PA = Data VA + L4 value

L2 data PA = Data VA + L3 value

L1 data PA = Data VA + L2 value

Data PA = L1 value

Page 4: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

4

AMD64 Processor Page Walk Caching

Page Walk Cache (PWC)

• In all generations of AMD64 processors

• Stores intermediate page table values

• Low-latency access Page Walk Cache

Page Table Walk Logic

Memory HierarchyL2 cacheL3 cacheDRAM

L4 L3 L2 L1

PWC miss

miss in TLBs

Page 5: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

5

GUEST1

Address Terminology

Addresses

� GVA: guest virtual address

� GPA: guest physical address

� SPA: system physical address

Hypervisor

GUEST2

OS

and

Apps

System Hardware

GVA GPA

SPA

OS

and

Apps

GVA GPA

Page 6: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

6

Virtualization Memory Management:No hardware support: Shadow Paging

Guest OS

GuestPageTable

Hypervisor

ShadowPageTable

SPA

GVA

Guest OS can only convert GVA ���� GPA

Hypervisor createsshadow page table

to convert GVA ���� SPA

Trap Guest Page TableAccesses

GVA ���� SPA with Shadow Page Table

Page 7: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

7

Virtualization Memory Management:Hardware support: Nested Paging

Guest OS

GuestPageTable

NestedPageTable

GPAGVA

Hypervisor

• Benefits: No more traps on Guest Page Table accesses• Drawback: Extra page table steps add latency to TLB miss

gPA ���� sPAwith nestedpage table

gVA ���� gPAwith unmodified guest page table

SPA

Page 8: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

8

Outline

1. Background

– AMD64 Page Walks and Caching

– Virtualization Terminology

– Address Translations in Virtualized Systems

2. Two-Dimensional Page Walks

– Nested Paging + Native Paging = 2D Page Walk

– 2D Page Walk Caching

– Hardware and Software 2D Page Walk Acceleration

3. KVM Implementation and Results

– KVM Software Implementation

– Results

Page 9: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

9

11

16

6

Two-Dimensional (2D) Page Walk

1 32

87 9

1312 14

1817 19

2322

Nested page table

10

15

20

5

24

Guest p

age ta

ble

gL1

gL2

gL3

gL4

nL4 nL3 nL2 nL1 G

GuestData

gPA

GPAL44

GVAD

SPAL4

SPAL3

SPAL2

SPAL1

SPAD21

A

B

C

D

GPAL3

GPAL2

GPAL1

GPAD

Cache Translation

in TLB

Page 10: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

10

Two-Dimensional Page Walk Caching

Average 2D Walk

• 14 PWC hits

– 5% of PWC misses

• 6 mixed PWC hit/miss

– 25% of PWC misses

• 4 PWC misses

– 70% of PWC misses

gL1

gL2

gL3

gL4

nL4 nL3 nL2 nL1 G

gPA

High Reuse4 reds in a row = translation reuse

Difficult to cacheMap small memory regions

BLUE = PWC MISS

PURPLE = PWC MIXED

RED = PWC HIT

Page 11: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

11

HIT MIXED MISS2 6 4

HIT MIXED MISS14 6 4

HIT MIXED MISS10 6 4

Two-Dimensional Page Walk Caching:with the Nested TLB (NTLB)

gL1

gL2

gL3

gL4

nL4 nL3 nL2 nL1 GN

T

L

B

gPA

gL4 NTLB Hit: Skip Nested Page Walk

gL3 NTLB Hit: Skip Nested Page Walk

gL2 NTLB Hit: Skip Nested Page Walk

gL1 NTLB Miss: Perform Nested Page Walk

gPA NTLB Miss: Perform Nested Page Walk

2D Walk: PWC Access

GPA SPAGVA

SPA

Simulated Results of not-exactly-real hardware – see ASPLOS08 paper

Page 12: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

12

Sources of 2D Walk Overhead:L2 Cache Misses

• Many PWC misses become L2 cache misses

• 1 of 4 PWC misses also miss in L2 cache

gL1

gL2

gL3

gL4

nL4 nL3 nL2 nL1 GN

T

L

B

gPA

2D Walk: PWC Access

HIT MIXED MISS2 6 4

Simulated Results of not-exactly-real hardware – see ASPLOS08 paper

Page 13: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

13

HIT MIXED MISS1 3 2

HIT MIXED MISS2 6 4

HIT MIXED MISS2 5 3

Large Nested Pages

gL1

gL2

gL3

gL4

nL4 nL3 nL2 nL1 GN

T

L

B

& Large Guest Pages

gPA

2D Walk: PWC Access

Large Nested Pages• Created by hypervisor• Map 2MB instead of 4KB• Eliminate nL1 column• Fewer PWC misses

Large Guest Pages• Created by guest OS• Map 2MB instead of 4KB• Eliminate gL1 row• Fewer PWC misses

Large pages are good!

Page 14: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

14

Outline

1. Background

– AMD64 Page Walks and Caching

– Virtualization Terminology

– Address Translations in Virtualized Systems

2. Two-Dimensional Page Walks

– Nested Paging + Native Paging = 2D Page Walk

– 2D Page Walk Caching

– Hardware and Software 2D Page Walk Acceleration

3. KVM Implementation and Results

– KVM Software Implementation

– Results

Page 15: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

15

Nested Paging Support in KVM

• Direct mapped page table is the same as the nested page table

• Shadow Paging Code for Real Mode creates a direct mapped page table

• Nested Paging support utilizes Shadow Paging Code

• This kept implementation very simple (5 files changed, 190 insertions(+), 12 deletions(-))

• Live Migration and Guest Swapping work out of the box

• Real performance boost for KVM on AMD processors

Page 16: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

16

Benchmarking - Environment

� Hardware: AMD Phenom™ 9550 2.2 GHz B3 silicon with 4GB RAM

� Host OS: Redhat Enterprise Linux 5.2

� KVM-69

� Xen-unstable 17731

� Guest OS: Redhat Enterprise Linux 5.1

� Guest: 2 VCPUs and 2 GB Memory

� For benchmarks on bare metal (Native) host was booted with “maxcpus=2 mem=2G”

Page 17: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

17

0

10

20

30

40

50

60

70

80

90

100

Native KVM Shadow

Paging

KVM Nested 4KB

pages

KVM Nested

2MB pages

Kernbench Performance: Shadow Paging vs. Native

Relative Performance

Page 18: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

18

0

10

20

30

40

50

60

70

80

90

100

Native KVM Shadow

Paging

KVM Nested 4KB

pages

KVM Nested

2MB pages

Kernbench Performance: Nested paging KVM Nested 4KB pages

Relative Performance

Page 19: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

19

0

10

20

30

40

50

60

70

80

90

100

Native KVM Shadow

Paging

KVM Nested 4KB

pages

KVM Nested

2MB pages

Kernbench Performance: Nested paging Performance benefits from large pages

Relative Performance

Page 20: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

20

0

1

2

3

4

5

6

7

8

9

10

Protection Fault Page Fault mmap latency

Native KVM Shadow Paging

KVM Nested 4KB pages KVM Nested 2MB pages

LMBench Performance: Shadow Paging vs. Native

Slowdown relative to native

Page 21: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

21

0

1

2

3

4

5

6

7

8

9

10

Protection Fault Page Fault mmap latency

Native KVM Shadow Paging

KVM Nested 4KB pages KVM Nested 2MB pages

LMBench Performance: Nested paging KVM Nested 4KB pages

Slowdown relative to native

Page 22: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

22

0

1

2

3

4

5

6

7

8

9

10

Protection Fault Page Fault mmap latency

Native KVM Shadow Paging

KVM Nested 4KB pages KVM Nested 2MB pages

LMBench Performance: Nested paging Performance benefits from large pages

Slowdown relative to native

Page 23: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

23

ConclusionNested Paging

• A HW solution to reduce memory management overhead

• Also introduces overhead on TLB misses

Hardware overhead can be significantly reduced

• Nested TLB to skip nested page walks and Page walk cache

• Approach native speed with these techniques

Overhead elimination more difficult

• Some 2D walk references always miss in PWC and L2 cache

• Exclusive use of 2MB pages in hypervisor is difficult

KVM Implements Nested Paging

• Performance improves and memory footprint shrinks

• Best performance from use of large nested page sizes

Page 24: Benjamin Serebrin Jörg Rödel Advanced Micro …...Advanced Micro Devices June 13, 2008 2 Outline 1. Background – AMD64 Page Walks and Caching – Virtualization Terminology –

24

Trademark Attribution

AMD, the AMD Arrow logo and combinations thereof are trademarks of Advanced Micro Devices, Inc. in the United States and/or other jurisdictions. Other names used in this presentation are for identification purposes only and may be trademarks of their respective owners.

©2008 Advanced Micro Devices, Inc. All rights reserved.