57
Weak Persistency Semantics from the Ground Up: Formalising the Persistency Semantics of ARMv8 & Transactional Models Azalea Raad John Wickerson Viktor Vafeiadis Max Planck Institute for Software Systems (MPI-SWS) Imperial College London [email protected] @azalearaad SoundAndComplete.org

Parm Oopsla - soundandcomplete.org

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Parm Oopsla - soundandcomplete.org

Weak Persistency Semantics from the Ground Up: Formalising the Persistency Semantics of ARMv8 & Transactional Models

Azalea Raad John Wickerson Viktor VafeiadisMax Planck Institute for Software Systems (MPI-SWS)

Imperial College London

[email protected] @azalearaadSoundAndComplete.org

Page 2: Parm Oopsla - soundandcomplete.org

Computer Storage

HDD

RAM✓ fast ✗ volatile

✗ slow ✓ persistent

!2

Page 3: Parm Oopsla - soundandcomplete.org

What is Non-Volatile Memory (NVM)?

RAMNVM

NVM: Hybrid Storage + Memory Best of both worlds:

✓ persistent (like HDD) ✓ fast, random access (like RAM)

!3

Page 4: Parm Oopsla - soundandcomplete.org

!4

Page 5: Parm Oopsla - soundandcomplete.org

!5

Q: Why Formal NVM Semantics?

Volatile memory

x := 1// x = 1

// x = 0

// x = 0// no recovery

Page 6: Parm Oopsla - soundandcomplete.org

!5

Q: Why Formal NVM Semantics?

Volatile memory

x := 1// x = 1

// x = 0

// x = 0// no recovery

Non-Volatile memory

x := 1// x = 1

// x = 0

// x = 1// recovery routine

Page 7: Parm Oopsla - soundandcomplete.org

A: Program Verification

!5

Q: Why Formal NVM Semantics?

Volatile memory

x := 1// x = 1

// x = 0

// x = 0// no recovery

Non-Volatile memory

x := 1// x = 1

// x = 0

// x = 1// recovery routine

Page 8: Parm Oopsla - soundandcomplete.org

A: Program Verification

!5

Q: Why Formal NVM Semantics?

Volatile memory

x := 1// x = 1

// x = 0

// x = 0// no recovery

Non-Volatile memory

x := 1// x = 1

// x = 0

// x = 1// recovery routine

What about Concurrency?

C1 || C2 || ... || Cn// ???

// x = y = ... = 0

// ???// recovery routine

Page 9: Parm Oopsla - soundandcomplete.org

time

Difficulty

Sequential

!

!6

(1940s)

Formal Semantic Models

Page 10: Parm Oopsla - soundandcomplete.org

time

Difficulty

Sequential

!

!6

(1940s)SC

"

(1979)

Formal Semantic Models

Page 11: Parm Oopsla - soundandcomplete.org

time

Difficulty

Sequential

!WMC

(1990s)

!6

(1940s)SC

"

(1979)

Formal Semantic Models

Page 12: Parm Oopsla - soundandcomplete.org

Weak Memory Consistency (WMC)

!7

No total execution order (to) ⇒

weak behaviour absent under SC, caused by:

• instruction reordering by compiler • write propagation across cache hierarchy

Page 13: Parm Oopsla - soundandcomplete.org

Weak Memory Consistency (WMC)

!7

No total execution order (to) ⇒

weak behaviour absent under SC, caused by:

• instruction reordering by compiler • write propagation across cache hierarchy

Consistency Model

the order in which writes are made visible

to other threads

e.g. TSO, ARMv8, POWER, C11, Java

Page 14: Parm Oopsla - soundandcomplete.org

time

Difficulty

Sequential

!

!8

$

WNVMC

This Talk

(2017)(1940s)SC

"

(1979)WMC

(1990s)

Formal Semantic Models

Page 15: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=y=0

y := 1;

// x=y=1 OR x=y=0 OR x=1;y=0 OR x=0;y=1

What Can Go Wrong?

!9

Page 16: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=y=0

y := 1;

// x=y=1 OR x=y=0 OR x=1;y=0 OR x=0;y=1

What Can Go Wrong?

!9

!! Execution continues ahead of persistence — asynchronous persists

Page 17: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=y=0

y := 1;

// x=y=1 OR x=y=0 OR x=1;y=0 OR x=0;y=1

What Can Go Wrong?

!9

!! Writes may persist out of order — relaxed persists

!! Execution continues ahead of persistence — asynchronous persists

Page 18: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=y=0

y := 1;

// x=y=1 OR x=y=0 OR x=1;y=0 OR x=0;y=1

What Can Go Wrong?

!9

!! Writes may persist out of order — relaxed persists

!! Execution continues ahead of persistence — asynchronous persists

Consistency Model

the order in which writesare made visible to other threads

Persistency Model

the order in which writes are persisted to NVM

Page 19: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=y=0

y := 1;

// x=y=1 OR x=y=0 OR x=1;y=0 OR x=0;y=1

What Can Go Wrong?

!9

!! Writes may persist out of order — relaxed persists

!! Execution continues ahead of persistence — asynchronous persists

Consistency Model

the order in which writesare made visible to other threads

Persistency Model

the order in which writes are persisted to NVM

NVM SemanticsConsistency + Persistency Model

Page 20: Parm Oopsla - soundandcomplete.org

% This Talk %

!10

PARMv8

(Persistent ARMv8):NVM Semantics

of theARMv8 Architecture

Page 21: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=0;y=0

y := 1;

// x=1;y=1 OR x=0;y=0 OR x=1;y=0 OR x=0;y=1

!11

!! out of order persists

Challenge #1: Relaxed Persists

Page 22: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=0;y=0

// x=1;y=1 OR x=0;y=0 OR x=1;y=0 OR x=0;y=1

Persist Barriers: Desiderata

!12

y := 1;☛

!! out of order persists☛ persist barriers?

Page 23: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=0;y=0

// x=1;y=1 OR x=0;y=0 OR x=1;y=0 OR x=0;y=1

Persist Barriers: Desiderata

!12

y := 1;☛

!! out of order persists☛ persist barriers?

ARMv8 does not provide persist barriers!

ARMv8 memory barriers (e.g. DSB-full) do not enforce persist ordering!

Page 24: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=0;y=0

y := 1;

!13

!! Execution continues ahead of persistence

Challenge #2: Asynchronous Persists

// x=1;y=1 OR x=0;y=0 OR x=1;y=0 OR x=0;y=1

Page 25: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=0;y=0

y := 1;

!14

Explicit Persists: Desiderata

☛ explicit persists?!! Execution continues ahead of persistence

persist x;☛

// x=1;y=1 OR x=0;y=0 OR x=1;y=0 OR x=0;y=1

Page 26: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=0;y=0

y := 1;

!15

Explicit Persists: Reality on ARMv8

☛ explicit persists?!! Execution continues ahead of persistence

DC-CVAP x;☛

// x=1;y=1 OR x=0;y=0 OR x=1;y=0 OR x=0;y=1

Page 27: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=0;y=0

y := 1;

!15

Explicit Persists: Reality on ARMv8

☛ explicit persists?!! Execution continues ahead of persistence

DC-CVAP x;☛

// x=1;y=1 OR x=0;y=0 OR x=1;y=0 OR x=0;y=1

DC-CVAP x: asynchronously persist cache line containing x

Page 28: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=0;y=0

y := 1;

!15

Explicit Persists: Reality on ARMv8

☛ explicit persists?!! Execution continues ahead of persistence

DC-CVAP x;☛

// x=1;y=1 OR x=0;y=0 OR x=1;y=0 OR x=0;y=1

DC-CVAP x: asynchronously persist cache line containing x

ARMv8 explicit persists are themselvesasynchronous!

Page 29: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=0;y=0

y := 1;

!16

DC-CVAP x; DSB-full;

// x=1;y=1 OR x=0;y=0 OR x=1;y=0 OR x=0;y=1

Solution: Persist Sequence

Page 30: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=0;y=0

y := 1;

!16

DC-CVAP x; DSB-full;

// x=1;y=1 OR x=0;y=0 OR x=1;y=0 OR x=0;y=1

Solution: Persist Sequence

✤ Waits until earlier writes on x are persisted ✓ synchronous persists

Page 31: Parm Oopsla - soundandcomplete.org

x := 1;

// recovery routine

// x=0;y=0

y := 1;

!16

DC-CVAP x; DSB-full;

// x=1;y=1 OR x=0;y=0 OR x=1;y=0 OR x=0;y=1

Solution: Persist Sequence

✤ Waits until earlier writes on x are persisted✤ Disallows reordering

✓ synchronous persists✓ no out of order persists

Page 32: Parm Oopsla - soundandcomplete.org

!17

PARMv8ARM® Architecture Reference Manual

6354 pages!

Page 33: Parm Oopsla - soundandcomplete.org

!17

PARMv8ARM® Architecture Reference Manual

6354 pages!

“ a DSB-full will not complete until all previous DC-CVAP have completed ”

“ DC-CVAP executes in program order relative to writes to an address in the same cache line”

Page 34: Parm Oopsla - soundandcomplete.org

!17

PARMv8ARM® Architecture Reference Manual

6354 pages!

“ a DSB-full will not complete until all previous DC-CVAP have completed ”

“ DC-CVAP executes in program order relative to writes to an address in the same cache line”

Ambiguities in text!

Page 35: Parm Oopsla - soundandcomplete.org

!17

PARMv8ARM® Architecture Reference Manual

6354 pages!

“ a DSB-full will not complete until all previous DC-CVAP have completed ”

“ DC-CVAP executes in program order relative to writes to an address in the same cache line”

Ambiguities in text!

PARMv8 Axiomatic Specification

Page 36: Parm Oopsla - soundandcomplete.org

!17

PARMv8ARM® Architecture Reference Manual

6354 pages!

“ a DSB-full will not complete until all previous DC-CVAP have completed ”

“ DC-CVAP executes in program order relative to writes to an address in the same cache line”

Ambiguities in text!

PARMv8 Axiomatic SpecificationProblem

ambiguous textcounter-intuitive semanticslow-level hardware details

Solution

high-level, hardware-agnostic NVM libraries:

Persistent Transactions

Page 37: Parm Oopsla - soundandcomplete.org

What is a Transaction?Concurrency control mechanism:

‣ atomic work unit: ➡ all-or-nothing writes

‣ consistent (e.g. serialisable)

[T :x := 1; y := 1;

// x = y = 0

// x = y = 0 OR x = y = 1

!18

Page 38: Parm Oopsla - soundandcomplete.org

Concurrency & persistency control mechanism:

‣ atomic work unit: ➡ all-or-nothing writes ➡ all-or-nothing persists

‣ consistent (e.g. serialisable)

What is a Persistent Transaction?

!19

[T :x := 1; y := 1;

// x = y = 0

// recovery routine// x = y = 0 OR x = y = 1

Page 39: Parm Oopsla - soundandcomplete.org

Concurrency & persistency control mechanism:

‣ atomic work unit: ➡ all-or-nothing writes ➡ all-or-nothing persists

‣ consistent (e.g. serialisable)

What is a Persistent Transaction?

!19

[T :x := 1; y := 1;

// x = y = 0

// recovery routine// x = y = 0 OR x = y = 1

‣ persistent (e.g. persistently serialisable)

Page 40: Parm Oopsla - soundandcomplete.org

Serialisability (SER)

!20

All transactions appear to execute in a sequential order

[T1 : x := 1; a := y; [T2 : y := 1;

b := x;

T1 T2→ T1T2 →

Page 41: Parm Oopsla - soundandcomplete.org

Persistent Serialisability (PSER)

!21

All transactions appear to execute in a sequential order

[T1 : x := 1; a := y; [T2 : y := 1;

b := x;

T1 T2→ T1T2 →

A prefix of transactions appears to persist in the same sequential order

Page 42: Parm Oopsla - soundandcomplete.org

Persistent Serialisability (PSER)

!21

All transactions appear to execute in a sequential order

[T1 : x := 1; a := y; [T2 : y := 1;

b := x;

T1 T2→ T1T2 →

A prefix of transactions appears to persist in the same sequential order

// x = y = 0T1 T2⇢⇢

Page 43: Parm Oopsla - soundandcomplete.org

Persistent Serialisability (PSER)

!21

All transactions appear to execute in a sequential order

[T1 : x := 1; a := y; [T2 : y := 1;

b := x;

T1 T2→ T1T2 →

A prefix of transactions appears to persist in the same sequential order

// x = y = 0T1 T2⇢⇢

// x = 1 y = 0T1 T2⇢→

Page 44: Parm Oopsla - soundandcomplete.org

Persistent Serialisability (PSER)

!21

All transactions appear to execute in a sequential order

[T1 : x := 1; a := y; [T2 : y := 1;

b := x;

T1 T2→ T1T2 →

A prefix of transactions appears to persist in the same sequential order

// x = y = 0T1 T2⇢⇢

// x = 1 y = 0T1 T2⇢→

T1 → T2 → // x = y = 1

Page 45: Parm Oopsla - soundandcomplete.org

Persistent Serialisability (PSER)

!22

All transactions appear to execute in a sequential order

A prefix of transactions appears to persist in the same sequential order

T1 → → …→T3 T5 T7T2 T4 T6→ → → →

all persist none persist

Page 46: Parm Oopsla - soundandcomplete.org

Persistent Serialisability (PSER)

!23

All transactions appear to execute in a sequential order

A prefix of transactions appears to persist in the same sequential order in each era

→ → …→ → → → →

execution

recovery

execution

recovery

execution

no crashes

Page 47: Parm Oopsla - soundandcomplete.org

Persistent Serialisability (PSER)

!23

All transactions appear to execute in a sequential order

A prefix of transactions appears to persist in the same sequential order in each era

→ → …→ → → → →

execution

recovery

execution

recovery

execution

no crashesPSER

Strong guarantees Intuitive semantics

Page 48: Parm Oopsla - soundandcomplete.org

Persistent Serialisability (PSER)

!23

All transactions appear to execute in a sequential order

A prefix of transactions appears to persist in the same sequential order in each era

→ → …→ → → → →

execution

recovery

execution

recovery

execution

no crashesPSER

Strong guarantees Intuitive semantics

PSER Evaluation

1. Is PSER feasible?2. Is PSER useful?

Page 49: Parm Oopsla - soundandcomplete.org

✢ add code for persistence — i.e. persist sequences

Is PSER Feasible?

!24

✓ PSER implementation in ARM

✢ add code to log metadata for recovery

✢ add recovery mechanism

Take SER Implementation — e.g. 2-PL

Page 50: Parm Oopsla - soundandcomplete.org

✢ add code for persistence — i.e. persist sequences

Is PSER Feasible?

!24

✓ PSER implementation in ARM

✢ add code to log metadata for recovery

✢ add recovery mechanism

⇒recovery mechanism

check log for incomplete transactions:

either complete or rollback

Take SER Implementation — e.g. 2-PL

Page 51: Parm Oopsla - soundandcomplete.org

✢ add code for persistence — i.e. persist sequences

Is PSER Feasible?

!24

✓ PSER implementation in ARM

✢ add code to log metadata for recovery

✢ add recovery mechanism

⇒recovery mechanism

check log for incomplete transactions:

either complete or rollback

Take SER Implementation — e.g. 2-PL

Yes!

Correct Implementation in PARMv8

Page 52: Parm Oopsla - soundandcomplete.org

Is PSER Useful?

!25

1. Take any correct sequential implementation of LGiven library L (e.g. queue library):

enq(q,v)= < enq_body >

deq(q)= < deq_body >

sequential queue imp.

Page 53: Parm Oopsla - soundandcomplete.org

Is PSER Useful?

!25

1. Take any correct sequential implementation of LGiven library L (e.g. queue library):

enq(q,v)= pser{ < enq_body > }

deq(q)= pser{ < deq_body > }

enq(q,v)= < enq_body >

deq(q)= < deq_body >

sequential queue imp.

2. wrap each operation in a PSER transaction

Page 54: Parm Oopsla - soundandcomplete.org

Is PSER Useful?

!25

1. Take any correct sequential implementation of LGiven library L (e.g. queue library):

⇒ correct, concurrent & persistent implementation of L

enq(q,v)= pser{ < enq_body > }

deq(q)= pser{ < deq_body > }

enq(q,v)= < enq_body >

deq(q)= < deq_body >

sequential queue imp.correct

concurrent & persistent queue imp.

2. wrap each operation in a PSER transaction

Page 55: Parm Oopsla - soundandcomplete.org

Is PSER Useful?

!25

1. Take any correct sequential implementation of LGiven library L (e.g. queue library):

⇒ correct, concurrent & persistent implementation of L

enq(q,v)= pser{ < enq_body > }

deq(q)= pser{ < deq_body > }

enq(q,v)= < enq_body >

deq(q)= < deq_body >

sequential queue imp.correct

concurrent & persistent queue imp.

2. wrap each operation in a PSER transactionYes!

any correct sequential implementation

⇒correct, concurrent & persistent

implementation

Page 56: Parm Oopsla - soundandcomplete.org

Summary

✢ PSER✓ Formalised language-level NVM semantics:

✓ Formalised architecture-level NVM semantics:✢ PARMv8

? Future Work:✢ program logics ✢ model checking algorithms

✢ General framework for declarative persistency✓ More in the paper

Page 57: Parm Oopsla - soundandcomplete.org

Summary

[email protected] @azalearaadSoundAndComplete.org

✢ PSER✓ Formalised language-level NVM semantics:

✓ Formalised architecture-level NVM semantics:✢ PARMv8

? Future Work:✢ program logics ✢ model checking algorithms

Thank You for Listening!

✢ General framework for declarative persistency✓ More in the paper