38
Software Software Transactional Memory Transactional Memory for Dynamic-Sized for Dynamic-Sized Data Structures Data Structures Maurice Herlihy, Victor Luchangco, Maurice Herlihy, Victor Luchangco, Mark Moir, William Scherer Mark Moir, William Scherer Presented by: Gokul Soundararajan Presented by: Gokul Soundararajan

Software Transactional Memory for Dynamic-Sized Data Structures

  • Upload
    tacita

  • View
    41

  • Download
    0

Embed Size (px)

DESCRIPTION

Software Transactional Memory for Dynamic-Sized Data Structures. Maurice Herlihy, Victor Luchangco, Mark Moir, William Scherer Presented by: Gokul Soundararajan. Outline. Background Software Transactional Memory (STM) Implementation Long Example Experimental Results Conclusion. - PowerPoint PPT Presentation

Citation preview

Page 1: Software Transactional Memory for Dynamic-Sized Data Structures

Software Transactional Software Transactional Memory for Dynamic-Memory for Dynamic-Sized Data StructuresSized Data Structures

Maurice Herlihy, Victor Luchangco, Mark Maurice Herlihy, Victor Luchangco, Mark Moir, William SchererMoir, William Scherer

Presented by: Gokul SoundararajanPresented by: Gokul Soundararajan

Page 2: Software Transactional Memory for Dynamic-Sized Data Structures

22

OutlineOutline

BackgroundBackground Software Transactional Memory Software Transactional Memory

(STM)(STM)– ImplementationImplementation– Long ExampleLong Example

Experimental ResultsExperimental Results ConclusionConclusion

Page 3: Software Transactional Memory for Dynamic-Sized Data Structures

33

TransactionTransaction

A sequence of operations on components of a data structure executed by a single thread

AtomicAtomic: either– Commits: takes effect– Aborts: its effects are discarded

Linearizable: preserves program order

Page 4: Software Transactional Memory for Dynamic-Sized Data Structures

44

Transactional MemoryTransactional Memory

Any system that supports concurrent execution of transactions performed by threads

Originally, a hardware idea Now, implemented in software

Page 5: Software Transactional Memory for Dynamic-Sized Data Structures

55

Transactional ObjectsTransactional Objects

Is a containercontainer for a regular object A transaction accesses it

– Open – Read/modify– Changes are not seen until the transaction

commits Creation and initialization of a

transactional object is not a part of any transaction

Page 6: Software Transactional Memory for Dynamic-Sized Data Structures

66

DSTM ImplementationDSTM Implementation

Is a containercontainer for a regular object

TMObject classTMObject class– Implements a Implements a

transactional objecttransactional object

Class: TMObject

Locator {Transaction, oldObject, newObject}Locator * startopen( )release( )

Page 7: Software Transactional Memory for Dynamic-Sized Data Structures

77

DSTM ImplementationDSTM Implementation

transaction

oldObject

newObject

The transactionthat most recently opened the object

in WRITE mode

A new object version

An old objectversion

start

TMObject

Locator

Page 8: Software Transactional Memory for Dynamic-Sized Data Structures

88

Current VersionCurrent Version

Current version of a transactional objectCurrent version of a transactional object– Determined by the status of the transaction Determined by the status of the transaction

(T) that most recently opened the object in (T) that most recently opened the object in WRITE modeWRITE modeT StatusT Status Current Current

VersionVersionOther Other

VersionVersion

COMMITTEDCOMMITTED newObjectnewObject meaninglessmeaningless

ABORTEDABORTED oldObjectoldObject meaninglessmeaningless

ACTIVEACTIVE oldObjectoldObject TentativeTentativeVersionVersion

Page 9: Software Transactional Memory for Dynamic-Sized Data Structures

99

Open(WRITE): T is COMMITTEDOpen(WRITE): T is COMMITTED

transaction

oldObjectnewObject

T: COMMITTED

newVersion

oldVersionstart

myObj

Page 10: Software Transactional Memory for Dynamic-Sized Data Structures

1010

Open(WRITE): T is COMMITTEDOpen(WRITE): T is COMMITTED

transaction

oldObjectnewObject

T: COMMITTED

newVersion

oldVersionstart

transaction

oldObjectnewObject

A: ACTIVE

A opens myObjin WRITE mode

myObj

Page 11: Software Transactional Memory for Dynamic-Sized Data Structures

1111

Open(WRITE): T is COMMITTEDOpen(WRITE): T is COMMITTED

transaction

oldObjectnewObject

T: COMMITTED

newVersion

oldVersionstart

transaction

oldObjectnewObject

A: ACTIVE

Copy ofnewVersion

A opens myObjin WRITE mode

myObj

copy

Page 12: Software Transactional Memory for Dynamic-Sized Data Structures

1212

Open(WRITE): T is COMMITTEDOpen(WRITE): T is COMMITTED

transaction

oldObjectnewObject

T: COMMITTED

newVersion

oldVersionstart

transaction

oldObjectnewObject

A: ACTIVE

Copy ofnewVersion

A opens myObjin WRITE mode

myObj

copy

Page 13: Software Transactional Memory for Dynamic-Sized Data Structures

1313

Open(WRITE): T is COMMITTEDOpen(WRITE): T is COMMITTED

transaction

oldObjectnewObject

T: COMMITTED

newVersion

oldVersionstart

transaction

oldObjectnewObject

A: ACTIVE

Copy ofnewVersion

A opens myObjin WRITE mode

myObj

copy

CAS

Page 14: Software Transactional Memory for Dynamic-Sized Data Structures

1414

Open(WRITE): T is ABORTEDOpen(WRITE): T is ABORTED

transaction

oldObjectnewObject

T: ABORTED

newVersion

oldVersionstart

transaction

oldObjectnewObject

A: ACTIVE

A opens myObjin WRITE mode

myObj

Page 15: Software Transactional Memory for Dynamic-Sized Data Structures

1515

Open(WRITE): T is ABORTEDOpen(WRITE): T is ABORTED

transaction

oldObjectnewObject

T: ABORTED

newVersion

oldVersionstart

transaction

oldObjectnewObject

A: ACTIVE

Copy ofoldVersion

A opens myObjin WRITE mode

myObj

copy

Page 16: Software Transactional Memory for Dynamic-Sized Data Structures

1616

Open(WRITE): T is ABORTEDOpen(WRITE): T is ABORTED

transaction

oldObjectnewObject

T: ABORTED

newVersion

oldVersionstart

transaction

oldObjectnewObject

A: ACTIVE

Copy ofoldVersion

A opens myObjin WRITE mode

myObj

copy

Page 17: Software Transactional Memory for Dynamic-Sized Data Structures

1717

Open(WRITE): T is ABORTEDOpen(WRITE): T is ABORTED

transaction

oldObjectnewObject

T: ABORTED

newVersion

oldVersionstart

transaction

oldObjectnewObject

A: ACTIVE

Copy ofoldVersion

A opens myObjin WRITE mode

myObj

copy

Page 18: Software Transactional Memory for Dynamic-Sized Data Structures

1818

Open(WRITE): T is ACTIVEOpen(WRITE): T is ACTIVE

transaction

oldObjectnewObject

T: ACTIVE

newVersion

oldVersionstart

transaction

oldObjectnewObject

A: ACTIVE

A opens myObjin WRITE mode

myObj

A tries to abort T

?

Page 19: Software Transactional Memory for Dynamic-Sized Data Structures

1919

Example: Integer SetExample: Integer Set

Specifications:Specifications:– Object: Integer SetObject: Integer Set– Supports:Supports:

insert(v)insert(v) delete(v)delete(v) member(v)member(v)

Implementation:Implementation:– Linked list of a set of elementsLinked list of a set of elements– Sorted in ascending orderSorted in ascending order

Page 20: Software Transactional Memory for Dynamic-Sized Data Structures

2020

Integer Set Example:Integer Set Example:ConstructorConstructor

MINnext

MAXnext

start start

Page 21: Software Transactional Memory for Dynamic-Sized Data Structures

2121

Integer Set Example: Integer Set Example: insert(40)insert(40)

MINnext

MAXnext

-20next

30next

first

thread

40next

newElm

TACTIVE

start startstartstart

TCOMMITEDstart

newNode

Page 22: Software Transactional Memory for Dynamic-Sized Data Structures

2222

Integer Set Example: Integer Set Example: insert(40)insert(40)

MINnext

MAXnext

-20next

30next

MINnext

first

thread

40next

newElm

TACTIVE

start startstartstart

TNO

TCOMMITEDstart

newNode

Page 23: Software Transactional Memory for Dynamic-Sized Data Structures

2323

Integer Set Example: Integer Set Example: insert(40)insert(40)

MINnext

MAXnext

-20next

30next

MINnext

first

thread

-20next

40next

newElm

TACTIVE

start startstartstart

TNO

TNO

TCOMMITEDstart

newNode

Page 24: Software Transactional Memory for Dynamic-Sized Data Structures

2424

Integer Set Example: Integer Set Example: insert(40)insert(40)

MINnext

MAXnext

-20next

30next

MINnext

first

thread

-20next

40next

newElm

30next

TACTIVE

start startstartstart

TNO

TNO

TNO

TCOMMITEDstart

newNode

Page 25: Software Transactional Memory for Dynamic-Sized Data Structures

2525

Integer Set Example: Integer Set Example: insert(40)insert(40)

MINnext

MAXnext

-20next

30next

MINnext

first

thread

-20next

40next

newElm

30next

TACTIVE

start startstartstart

TNO

TNO

TNO

TCOMMITEDstart

newNode

Page 26: Software Transactional Memory for Dynamic-Sized Data Structures

2626

Integer Set Example: Integer Set Example: insert(40)insert(40)

MINnext

MAXnext

-20next

30next

MINnext

first

thread

-20next

40next

newElm

30next

MAXnext

TACTIVE

start startstartstart

TNO

TNO

TNO

TNO

TCOMMITEDstart

newNode

Page 27: Software Transactional Memory for Dynamic-Sized Data Structures

2727

Integer Set Example: Integer Set Example: insert(40)insert(40)

MINnext

MAXnext

-20next

30next

MINnext

first

thread

-20next

40next

newElm

30next

MAXnext

TACTIVE

start startstartstart

TNO

TNO

TNO

TNO

TCOMMITEDstart

newNode

Page 28: Software Transactional Memory for Dynamic-Sized Data Structures

2828

DSTM and Sequential CodeDSTM and Sequential Code

Differences:Differences:– Need to catch Denied exceptionNeed to catch Denied exception– Retry transaction that fails to commitRetry transaction that fails to commit– Distinguish between transactional Distinguish between transactional

objects and non-transactional objectsobjects and non-transactional objects

Page 29: Software Transactional Memory for Dynamic-Sized Data Structures

2929

Obstruction FreedomObstruction Freedom Guarantees progress for any thread that Guarantees progress for any thread that

eventually executes without interference eventually executes without interference for a sufficient number of stepsfor a sufficient number of steps

Strong enough to avoid problems Strong enough to avoid problems associated with locksassociated with locks

Ensures that no thread can be blocked by Ensures that no thread can be blocked by delays or failures of other threadsdelays or failures of other threads

Live-lockLive-lock– Livelock Freedom - If some process wants to Livelock Freedom - If some process wants to

enter the critical section, then some process enter the critical section, then some process will eventually enter the critical section.will eventually enter the critical section.

Page 30: Software Transactional Memory for Dynamic-Sized Data Structures

3030

Obstruction FreedomObstruction Freedom Weaker progress guarantee than wait-Weaker progress guarantee than wait-

freedom freedom – All processes are guaranteed to complete the All processes are guaranteed to complete the

access in finite time, regardless of the actions access in finite time, regardless of the actions of the other processes.of the other processes.

BUT:BUT:Efficient

Contention

Manager+

Obstruction

Freedom

Wait

Freedom

In Practice

Page 31: Software Transactional Memory for Dynamic-Sized Data Structures

3131

Contention ManagementContention Management

Methods:Methods:– AggressiveAggressive

Abort the conflicting transactionAbort the conflicting transaction Interrupting a partially executed Interrupting a partially executed

operation will not jeopardise correctnessoperation will not jeopardise correctness

– PolitePolite Operations “back off” when they Operations “back off” when they

encounter interferenceencounter interference Wait for some time before retryingWait for some time before retrying

Page 32: Software Transactional Memory for Dynamic-Sized Data Structures

3232

Contention ManagementContention Management

Contention manager is invoked only Contention manager is invoked only in case of contention in case of contention

In most lock-free and wait-free In most lock-free and wait-free implementations, mechanisms used implementations, mechanisms used to ensure progress impose significant to ensure progress impose significant overhead even in the absence of overhead even in the absence of contentioncontention

Page 33: Software Transactional Memory for Dynamic-Sized Data Structures

3333

ExperimentsExperiments

BenchmarksBenchmarks– IntSetIntSet– IntSet with Early ReleaseIntSet with Early Release– RBTreeRBTree

Contention ManagementContention Management– AggressiveAggressive – abort the conflicting – abort the conflicting

transactiontransaction– PolitePolite – have a back-off algorithm – have a back-off algorithm

Page 34: Software Transactional Memory for Dynamic-Sized Data Structures

3434

ResultsResults

Page 35: Software Transactional Memory for Dynamic-Sized Data Structures

3535

ResultsResults

Page 36: Software Transactional Memory for Dynamic-Sized Data Structures

3636

ResultsResults

Page 37: Software Transactional Memory for Dynamic-Sized Data Structures

3737

ResultsResults

Page 38: Software Transactional Memory for Dynamic-Sized Data Structures

3838

ConclusionConclusion

PresentedPresented– Transactional Memory in Java/C++Transactional Memory in Java/C++– Probably easier in Java (because of the Probably easier in Java (because of the

Object data type)Object data type)– Good performance over simple lockingGood performance over simple locking