Software Transactional Memory (STM) - PowerPoint PPT Presentation

About This Presentation
Title:

Software Transactional Memory (STM)

Description:

How to adjust the granularity of locking? Protect each data structure with separate locks ... Abort the current transaction and leave it to retry later ... – PowerPoint PPT presentation

Number of Views:205
Avg rating:3.0/5.0
Slides: 19
Provided by: csCor
Category:

less

Transcript and Presenter's Notes

Title: Software Transactional Memory (STM)


1
Software Transactional Memory(STM)
  • Harris, T. and Fraser, K. Language Support for
    Lightweight Transactions. In Proceedings of
    Object Oriented Programming, Systems, Languages
    Applications. October,2003.

Ramazan Bitirgen bitirgen_at_csl.cornell.edu
2
Outline
  • Introduction
  • Motivation
  • Conditional Critical Regions
  • Software Transactions
  • Evaluation
  • Future Work
  • References

3
Introduction
  • Software Transactional Memory (STM)
  • A generic non-blocking synchronization construct
    that allows correct sequential objects to be
    converted automatically into correct concurrent
    objects.
  • Requires hardware support
  • CAS in 1, LL/SC in 2
  • Basic requirement for an STM linearizability
  • Advantages of STM
  • Applicability to today's machines
  • Portability among machines
  • Resiliency in the face of timing anomalies

4
Motivation
  • Concurrency is a concern for all the platforms
  • Large cc-NUMA servers
  • Modest symmetric shared-memory MPs
  • Single processors with SMT or pre-emptive
    scheduling
  • How to adjust the granularity of locking?
  • Protect each data structure with separate locks
  • Reduces parallelism
  • Use many smaller locks for the same data
    structure
  • Juggling the locks

5
Conditional Critical Regions
atomic (condition) statements
  • Basic syntax

atomic (condition) statements
boolean done false while (!done) STMStart
() try if (condition)
statements done STMCommit ()
else STMWait() catch
(Throwable t) done STMCommit ()
if (done) throw t
  • Allows programmers to indicate what groups of
    operations should be executed in isolation

public synchronized int get() int
result while (items 0) wait () items
-- result bufferitems notifyAll
() return result
public int get() atomic (items ! 0) items
-- return bufferitems
6
Software Transactions
  • STM Interface
  • void STMStart()
  • void STMAbort()
  • boolean STMCommit()
  • boolean STMValidate()
  • void STMWait()
  • Memory Accesses
  • stm_word STMRead(addr a)
  • void STMWrite(addr a,
  • stm_word w)
  • Data structures
  • Application heap
  • Ownership records
  • Transaction Descriptors

7
STM Operations
  • STMStart
  • Allocate a fresh descriptor and set the status
    field to ACTIVE
  • STMRead
  • If TD already contains an entry TE return
    TE.new_value
  • Otherwise determine the logical state of that
    entry and initialize new entry in the TD with
    old_value new_value and the version seen as
    old_version.
  • If TD already contains an entry for this orec
    copy that entrys version number as new_version.
  • STMWrite
  • Ensure that TD contains an entry for the location
    being accessed.
  • Can be done by performing a read operation
  • Set te.new_value to the value being written and
    set te.new_version to te.old_version 1
  • STMAbort
  • Set the status field to ABORTED

8
STM Operations
  • STMCommit Acquire each of the orecs you need
  • If it acquires all of them
  • Set the status of TD to COMMITTED
  • Make any updates to the application heap
  • Release all the orecs you acquired
  • If it cannot acquire all of them (version
    inconsistency)
  • Set the status of TD to ABORTED
  • Release all the successfully acquired entries
  • If it cannot acquire all of them (already owned)
  • Abort the existing owner In 3, exponential
    back off abort
  • Wake it if it was blocked in STMWait
  • Abort the current transaction and leave it to
    retry later
  • (after the existing-owner released its ownership)

Eager Acquire (at open time) - Early conflict
detection Lazy Acquire (at commit) - Reduce
contention 4
9
STM Operations
  • STMWait
  • Acquire all the related orecs
  • Set the status of TD to ASLEEP
  • Leave references to its TD installed at the
    acquired orecs
  • These will act as software tripwires and signal
    the presence of sleeper to any other transaction
    that attempts to commit an update to those
    locations.
  • STMValidate
  • Entirely a read-only operation
  • Checks the orecs associated with each location
    accessed contain the version number held in TD
  • Returns true if every record holds the expected
    value, returns false otherwise.

10
Optimizations 1
  • Multiple sleeping threads
  • Extend each TD to include a list of other threads
    which wishes to sleep on locations acquired by
    that TD
  • Read Sharing
  • In the basic design, STMCommit should acquire and
    release each of the entries even when it is a
    read-only access

11
Optimizations 2
  • Read Sharing (contd)
  • 1-Acquire the locations subject to an update
  • 2-Check the states of the read locations
  • 3-Attempt to update TD.state to COMMITTED
  • Add another phase READ_PHASE
  • 1?READ_PHASE?2?3
  • If another transaction encounters one in
    READ_PHASE then it causes the one encountered to
    abort.

12
Optimizations 3
  • Non-Blocking Commit
  • If a thread encounters an orec that is already
    held, it must wait for the current holder to
    release it.
  • Solution Permit one thread to steal ownership
  • Stealer takes old_value, old_version if the
    victim is aborted or new_value, new_version if
    committed.

13
Optimizations Ownership Stealing
  • Previous owner committed but not updated the
    heap
  • No control over when those updates will occur.
  • We must ensure that writes made by new owner
    succeed those made by the previous owner.
  • Use counters, increment atomically for each
    steal, decrement for each release.
  • If a thread discovers that ownership has been
    stolen from it, it re-does the updates made by
    the new-owner.

14
Evaluation Small Systems
  • Hashtable update test (above)
  • Compound test (below)

15
Evaluation Large Systems
Hashtable test
1 writes
Hashtable test
16 writes
16
Evaluation Large Systems
Compound test
table size256
Compound test
table size4096
17
Future Work
  • Benchmarking and Evaluation
  • Use wide range of data structures
  • Alternative STM Implementations
  • If contention is rare, allow updates to be made
    in place without the indirection through a TD
  • Composable Transactions 5
  • Hardware Support

18
References
  • Harris, T. and Fraser, K. Language Support for
    Lightweight Transactions. In Proceedings of
    Object Oriented Programming, Systems, Languages
    Applications. October,2003.
  • Shavit, N. and Touitou, D. Software Transactional
    Memory. In 14th ACM Symposium on the Principles
    of Distributed Computing, 1995.
  • Herlihy, M., Luchangco, V., Moir, M., and Scherer
    III, W. N. Software Transactional Memory for
    Dynamic-Sized Data Structures. In Proceedings of
    the 22nd Annual ACM Symposium on Principles of
    Distributed Computing, July 2003.
  • Marathe, J. V., Scherer III, W. N., Scott, L.M.
    In DISC 2005, LNCS 3724, pp. 354368, 2005.
  • Harris, T., Marlow, S., Jones, S.P., Herlihy, M.
    Composable Memory Transactions. In PPoPP05, June
    2005.
  • Source Code http//www.cl.cam.ac.uk/Research/SRG/
    netos/lock-free
Write a Comment
User Comments (0)
About PowerShow.com