Software Transactional Memory for Dynamic-Sized Data Structures

Preview:

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

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

22

OutlineOutline

BackgroundBackground Software Transactional Memory Software Transactional Memory

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

Experimental ResultsExperimental Results ConclusionConclusion

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

44

Transactional MemoryTransactional Memory

Any system that supports concurrent execution of transactions performed by threads

Originally, a hardware idea Now, implemented in software

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

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( )

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

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

99

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

transaction

oldObjectnewObject

T: COMMITTED

newVersion

oldVersionstart

myObj

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

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

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

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

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

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

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

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

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

?

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

2020

Integer Set Example:Integer Set Example:ConstructorConstructor

MINnext

MAXnext

start start

2121

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

MINnext

MAXnext

-20next

30next

first

thread

40next

newElm

TACTIVE

start startstartstart

TCOMMITEDstart

newNode

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

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

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

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

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

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

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

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.

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

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

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

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

3434

ResultsResults

3535

ResultsResults

3636

ResultsResults

3737

ResultsResults

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

Recommended