Transactional Memory - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Transactional Memory

Description:

High priority threads cannot proceed if a low priority thread holds the ... Software Transactional Memory,' by V. J. Marathe, M. F. Spear, Heriot,A. Acharya, ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 31
Provided by: www249
Category:

less

Transcript and Presenter's Notes

Title: Transactional Memory


1
Transactional Memory
  • Hao Tian
  • Instructor Dr. Barbara Chapman

2
Agenda
  • 1.Motivation
  • 2. What is Transactional Memory
  • 3. Software Transactional Memory (STM)
  • 3.1RSTM
  • 4. Summary
  • 5. References

3
Motivation
  • Drawbacks of lock-based synchronization
  • Conservative blocking approach
  • Acquiring locks whenever there is a possibility
    of conflict
  • Hard to find the right granularity
  • Coarse-grained locks not scale
  • Fine-grained locks overhead
  • Vulnerable to failure and fault
  • Blocking other threads if one thread dies,
    deadlock
  • Priority inversion
  • High priority threads cannot proceed if a low
    priority thread holds the lock

4
Motivation
  • Critical Section a piece of code that accesses a
    shared resource (data structure or device) that
    must not be concurrently accessed by more than
    one thread of execution.
  • A deadlock is a situation wherein two or more
    competing actions are waiting for the other to
    finish, and thus neither ever does.

5
Motivation
  • Priority inversion a low priority task holds a
    shared resource that is required by a high
    priority task, usually the lower task is called
    by a higher task.
  • these types of problems are time-sensitive, they
    are often very hard to find during normal testing
    and in some cases go undetected until after the
    application is deployed.

6
What is Transactional Memory
  • An idea from DBMS
  • A unit of interaction with a DBMS that is treated
    in a coherent and reliable way
  • A transaction several queries, each of them
    reading and/or writing information in the
    database.
  • It must be either entirely completed or aborted
    to ensure the integrity of a database.
  • 3 Conventional states ACTIVE, ABORTED, and
    COMMITTED

7
What is Transactional Memory
  • Transactional memory is a construct for
    concurrency control that enables access to data
    shared by threads.
  • Only one thread can contain given data item.
  • A transaction is a high-level construct that
    executes reads and writes to data as an
    indivisible operation.

8
What is Transactional Memory
  • Two trivial code examples
  • locking
  • Lock(L) x unlock(L)
  • atomic block construct
  • atomicx

9
What is Transactional Memory
  • A finite sequence of memory reads and writes
    executed by a single thread
  • Transactional Memory is optimal
  • Executing threads as if there are no other
    threads
  • Using log to record memory modifications
  • Checking the records for consistency
  • Aborted and re-executing transaction

10
Agenda
  • 1.Motivation
  • 2. What is Transactional Memory
  • 3. Software Transactional Memory (STM)
  • 3.1RSTM
  • 4. Summary
  • 5. References

11
What is Software Transactional Memory
  • Software Transactional Memory is a concurrent
    programming API in which conventional critical
    sections are replaced by transactions.
  • A transaction is a sequence of steps executed by
    a single thread.

12
What is Software Transactional Memory
  • Transaction properties ACID
  • Atomicity
  • Either all of the operations in a transaction are
    performed or none of them are.
  • Consistency
  • A legal database state before and after the
    transaction
  • Isolation
  • Changes made by operations in a transaction are
    not visible to other outside operations until the
    transaction is committed.
  • Durability
  • Once committed, the transaction will persist

13
Software Transactional Memory
  • Transaction Descriptor each thread reuses a
    single statically allocated Transaction
    Descriptor across all of its transactions, it
    contains some information we need during
    transaction.

14
Software Transactional Memory
  • Dynamic STM
  • ACTIVE/ABORTED the old version
  • COMMITTED the new version

15
Software Transactional Memory
  • Conflict detection
  • Eager Detection writer acquires objects at open
    time.
  • Lazy Detection writer delays acquiring objects
    until just before commit time.

16
Software Transactional Memory
  • Eager Detection It allows conflicts between
    transactions to be detected early, some useless
    work can be aborted early, but some transaction
    will fail to commit itself.
  • Lazy Detection It allows doomed transactions to
    continue, but it can not see the potential
    conflicts

17
RSTM
  • The Rochester Software Transactional Memory
    Runtime
  • RSTM is a C library for multithreaded,
    non-blocking transaction-based code.
  • Why non-blocking?
  • Non-blocking data structures avoid many of the
    principal problems with locks, including
    deadlock, convoying, priority inversion, and
    performance anomalies due to preemption and page
    faults.

18
RSTM
  • 9 instructions in the RSTM API
  • stm_init() - must be called in each thread before
    any transactions are issued
  • stm_dest() - call once a thread shuts down
  • open_RO() - open an object for reading
  • open_RW() - open an object for writing
  • shared() - get a transactional wrapper for an
    open object
  • release() - "close" an object opened with
    open_RO()
  • tx_alloc() - get memory from the transaction heap
  • tx_free() - free memory allocated with tx_alloc
  • BEGIN_TRANSACTION - begin a transaction
  • END_TRANSACTION - end a transaction (must be at
    same nesting level as BEGIN_TRANSACTION)

19
RSTM
20
RSTM
21
RSTM
Begin_Transaction()
Judges which thread starts the transaction
Yes, continue
No, goes into slowpath(), Enters a backoff
section
b64 128, 2564096
22
RSTM
23
What is Software Transactional Memory
  • STM is optimistic
  • Every thread completes its modifications to
    shared memory without regard for what other do.
  • It is placed on the reader to make sure other
    threads didnt make changes to the memory it
    accessed.( using log to record)
  • A transaction may abort at any time, causing all
    of its prior changes to be rolled back or undone.
  • If a transaction can not be finished due to
    conflicting changes, it is aborted and
    re-executed from the beginning.
  • Commit if validation is successful

24
Performance
  • The benefits of this approach increases
    concurrency
  • No thread needs to wait to access to a resource.
  • Theoretically, when there are n concurrent
    transactions running in the same time, there
    could be need of O(n) memory and processor time
    consumption.

25
Advantages
  • STM simplifies conceptual understanding of
    multithreaded programs, but lock-based
    programming still need to do following
  • They require thinking about overlapping
    operations and partial operations in separated
    and unrelated sections of code.
  • They require programmers to adopt a locking
    policy to prevent deadlock and other failures to
    make progress.
  • They can lead to priority inversion.

26
Proposed language support
  • // Insert a node into a doubly-linked list
    atomically atomic
  • newNode-gtprev node
  • newNode-gtnext node-gtnext
  • node-gtnext-gtprev newNode
  • node-gtnext newNode
  • When the end of the program is reached, the
    transaction is committed.

27
Proposed language support
  • atomic (queueSize gt 0)
  • remove item from queue and use it

28
Proposed language support
  • atomic
  • if (queueSize gt 0)
  • remove item from queue and use it
  • else
  • retry
  • This ability to retry dynamically late in the
    transaction simplifies the programming model and
    opens up new possibilities

29
Summary
  • How can the programmer write parallel code more
    effectively, that is, write robust code that
    doesnt have bugs, but still scales and benefits
    from additional cores that each successive
    generation provides Asked by Ali-Reza, Intel
    Principal Engineer.
  • Maybe TM can provide us a easy way to implement
    our codes.

30
References
  • Lowering the Overhead of Nonblocking Software
    Transactional Memory, by V. J. Marathe, M. F.
    Spear, Heriot,A. Acharya,
  • http//www.cs.rochester.edu/research/synchronizati
    on/rstm/
  • http//en.wikipedia.org/wiki/Transactional_memory
  • http//www.hpcwire.com/hpc/1196095.html
  • http//softwareblogs.intel.com/2007/01/17/transact
    ional-memory-whats-all-the-hubbub-bub/
Write a Comment
User Comments (0)
About PowerShow.com