Locking Protocols & Software Transactional Memory

Slides:



Advertisements
Similar presentations
Concurrency Control III. General Overview Relational model - SQL Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Advertisements

Guy Golan-GuetaTel-Aviv University Nathan Bronson Stanford University Alex Aiken Stanford University G. Ramalingam Microsoft Research Mooly Sagiv Tel-Aviv.
Lecture plan Transaction processing Concurrency control
Optimistic Methods for Concurrency Control By : H.T. Kung & John T. Robinson Presenters: Munawer Saeed.
Database Systems (資料庫系統)
Principles of Transaction Management. Outline Transaction concepts & protocols Performance impact of concurrency control Performance tuning.
CSIS 7102 Spring 2004 Lecture 5 : Non-locking based concurrency control (and some more lock-based ones, too) Dr. King-Ip Lin.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
1 Supplemental Notes: Practical Aspects of Transactions THIS MATERIAL IS OPTIONAL.
Database Systems, 8 th Edition Concurrency Control with Time Stamping Methods Assigns global unique time stamp to each transaction Produces explicit.
© 2009 Matthew J. Sottile, Timothy G. Mattson, and Craig E Rasmussen 1 Concurrency in Programming Languages Matthew J. Sottile Timothy G. Mattson Craig.
Quick Review of Apr 29 material
1 Lecture 21: Transactional Memory Topics: consistency model recap, introduction to transactional memory.
1 Lecture 7: Transactional Memory Intro Topics: introduction to transactional memory, “lazy” implementation.
Transaction Management and Concurrency Control
Transaction Management and Concurrency Control
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
What is a Transaction? Logical unit of work
CS510 Concurrent Systems Class 13 Software Transactional Memory Should Not be Obstruction-Free.
9 Chapter 9 Transaction Management and Concurrency Control Hachim Haddouti.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Concurrency Control In Dynamic Database Systems Laurel Jones.
Transaction Management Chapter 9. What is a Transaction? A logical unit of work on a database A logical unit of work on a database An entire program An.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Transaction Communications Yi Sun. Outline Transaction ACID Property Distributed transaction Two phase commit protocol Nested transaction.
Concurrency and Transaction Processing. Concurrency models 1. Pessimistic –avoids conflicts by acquiring locks on data that is being read, so no other.
Lecture 12 Recoverability and failure. 2 Optimistic Techniques Based on assumption that conflict is rare and more efficient to let transactions proceed.
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
Concurrency Control Concurrency Control By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
11/7/2012ISC329 Isabelle Bichindaritz1 Transaction Management & Concurrency Control.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
Chapter 20 Transaction Management Thomas Connolly, Carolyn Begg, Database System, A Practical Approach to Design Implementation and Management, 4 th Edition,
1 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
© 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael.
MULTIVIE W Slide 1 (of 21) Software Transactional Memory Should Not Be Obstruction Free Paper: Robert Ennals Presenter: Emerson Murphy-Hill.
Multidatabase Transaction Management COP5711. Multidatabase Transaction Management Outline Review - Transaction Processing Multidatabase Transaction Management.
Lecture 9- Concurrency Control (continued) Advanced Databases Masood Niazi Torshiz Islamic Azad University- Mashhad Branch
Novel Paradigms of Parallel Programming Prof. Smruti R. Sarangi IIT Delhi.
CS 440 Database Management Systems
Transaction Management
Minh, Trautmann, Chung, McDonald, Bronson, Casper, Kozyrakis, Olukotun
Part 2: Software-Based Approaches
Concurrency Control Techniques
Transaction Management and Concurrency Control
Database Systems (資料庫系統)
Advanced Operating Systems - Fall 2009 Lecture 8 – Wednesday February 4, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours: M,
COS 418: Advanced Computer Systems Lecture 5 Michael Freedman
Transaction Management
Transaction Properties
A Qualitative Survey of Modern Software Transactional Memory Systems
4. Concurrency control techniques
Concurrency Control II (OCC, MVCC)
Database Processing: David M. Kroenke’s Chapter Nine: Part One
Lecture 6: Transactions
Chapter 10 Transaction Management and Concurrency Control
Basic Two Phase Locking Protocol
6.830 Lecture 14 Two-phase Locking Recap Optimistic Concurrency Control 10/28/2015.
Lecture 22: Consistency Models, TM
Concurrency Unit 4.2 Dr Gordon Russell, Napier University
Database Security Transactions
Hybrid Transactional Memory
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Software Transactional Memory Should Not be Obstruction-Free
Transaction Management
CONCURRENCY Concurrency is the tendency for different tasks to happen at the same time in a system ( mostly interacting with each other ) .   Parallel.
Concurrency Unit 4.2 Dr Gordon Russell, Napier University
Controlled Interleaving for Transactions
Concurrency control (OCC and MVCC)
CSE 542: Operating Systems
Transactions, Properties of Transactions
Presentation transcript:

Locking Protocols & Software Transactional Memory 2/25/2019 Locking Protocols and Software Transactional Memory Locking Protocols & Software Transactional Memory

Why Study (Software) Transactions 2/25/2019 Locking Protocols and Software Transactional Memory Why Study (Software) Transactions

Why Study (Software) Transactions 2/25/2019 Locking Protocols and Software Transactional Memory Why Study (Software) Transactions Transactions are good abstractions

Why Study (Software) Transactions 2/25/2019 Locking Protocols and Software Transactional Memory Why Study (Software) Transactions Transactions are good abstractions Design choices and issues can guide your concurrent data structures

Coarse/Fine Grained Locking 2/25/2019 Locking Protocols and Software Transactional Memory Coarse/Fine Grained Locking Locking discipline enforce protection Each object is protected by some lock One lock protects a set of objects Lock leveling for deadlock avoidance Assign a partial ordering to locks, Level(X) After acquiring a lock X, the transaction is only allowed to acquire locks Y with Level(Y) > Level(X) Enforce locking discipline and lock leveling using static analysis tools

Two Phase Locking (Revisited) 2/25/2019 Locking Protocols and Software Transactional Memory Two Phase Locking (Revisited) Transactions acquire a lock on an object before accessing the object Transactions cannot acquire a lock once the transaction has released some lock Works with shared/exclusive locks Deadlock avoidance

Use Hardware Primitives 2/25/2019 Locking Protocols and Software Transactional Memory Use Hardware Primitives Lock (L); x = x + 1; Unlock(L); InterlockedIncrement(&x); Interlocked operations are implemented by low-level locking by the hardware asm{ lock inc [x]; }

Using Compare And Exchange 2/25/2019 Locking Protocols and Software Transactional Memory Using Compare And Exchange If you need to protect more than one logical variables But the variables can be compressed into a 32/64 bits Lock(L); // protects x and y x = f(x, y); y = g(x, y); Unlock(L);

Using Compare and Exchange 2/25/2019 Locking Protocols and Software Transactional Memory Using Compare and Exchange Compress x and y into a single ‘state’ variable retry: s = state; // compress state into 64 bits x = s.x; y = s.y; x = f(x,y); y = g(x,y) t.x = x; t.y = y; if(! CompareAndExchange(&state, t, s)) goto retry;

Locking Protocols and Software Transactional Memory 2/25/2019 Locking Protocols and Software Transactional Memory Progress Guarantees Wait freedom Every thread makes progress in the presence of conflicts Lock freedom Some thread makes progress in the presence of conflicts Obstruction freedom A thread makes progress when all other threads are suspended

What is the progress guarantee? 2/25/2019 Locking Protocols and Software Transactional Memory What is the progress guarantee? Lock(L); x = f(x, y); y = g(x, y); Unlock(L); Lock(L); x = f(x, y); y = g(x, y); Unlock(L);

What is the progress guarantee? 2/25/2019 Locking Protocols and Software Transactional Memory What is the progress guarantee? retry: s = state; x = s.x; y = s.y; x = f(x,y); y = g(x,y) t.x = x; t.y = y; if(!CAS(&state,t,s)) goto retry; retry: s = state; x = s.x; y = s.y; x = f(x,y); y = g(x,y) t.x = x; t.y = y; if(!CAS(&state,t,s)) goto retry;

Sophisticated Fine Grained Locking Protocols 2/25/2019 Locking Protocols and Software Transactional Memory Sophisticated Fine Grained Locking Protocols Locking protocols for guaranteeing linearizability Even when not following the 2-phase locking discipline Allows early release of locks for more concurrency Proof of correctness is complicated Never roll out your own

Locking Protocols and Software Transactional Memory 2/25/2019 Locking Protocols and Software Transactional Memory Tree Locking The objects form a tree Transactions acquire a lock on an object before accessing the object Henceforth not state this constraint explicitly A transaction may begin executing by locking any object Can acquire a lock on X only if already holding the lock on parent of X Can acquire a lock on X at most once (Can otherwise release locks in arbitrary order)

“Hand Over Hand” Locking 2/25/2019 Locking Protocols and Software Transactional Memory “Hand Over Hand” Locking void IncrementAll(List list, int k) { Node c = list; while( c != null ) { c.data += k; c = c.next ; } A List B C D

“Hand Over Hand” Locking 2/25/2019 Locking Protocols and Software Transactional Memory “Hand Over Hand” Locking void IncrementAll(List list, int k) { Node c = list; Lock(c); while( c != null ) { c.data += k; if(c.next != null) Lock(c.next); c = c.next ; Unlock(c); } A List B C D

Locking Protocols and Software Transactional Memory 2/25/2019 Locking Protocols and Software Transactional Memory Proof of Tree Locking If two transactions conflict, one of the two acquires all shared locks before the other This ordering enforces the serialization order => Serializability Is this protocol linearizable?

Locking Protocols and Software Transactional Memory 2/25/2019 Locking Protocols and Software Transactional Memory DAG Locking The objects form a DAG A transaction may begin executing by locking any object Can acquire a lock on X only if already holding the lock on some parent of X Has previously acquired locks on all parents of X Can acquire a lock on X at most once (Can otherwise release locks in arbitrary order)

Locking Protocols and Software Transactional Memory 2/25/2019 Locking Protocols and Software Transactional Memory Domination Locking Leverages the restricted semantics of software modules thread can access n3 only after n1 & n2 Allows early release Allows for dynamic modification to the underlying struture n1 List n2 n3 n4

Locking Protocols and Software Transactional Memory 2/25/2019 Locking Protocols and Software Transactional Memory Two types of objects Distinguishes between exposed and hidden objects Exposed objects “roots” of data structures may be pointed by transaction arguments Hidden objects may not be pointed by transaction arguments may be reachable via exposed objects void insert(List l, int k) {…} List ... exposed hidden

Domination Protocol Rules 2/25/2019 Locking Protocols and Software Transactional Memory Domination Protocol Rules A hidden object u can be acquired by t only if every path between an exposed object to u includes an object which is locked by t Perform leveled two phase locking on exposed objects

Software Transactional Memory 2/25/2019 Locking Protocols and Software Transactional Memory Software Transactional Memory Different tradeoffs than database transactions Disk access ~10ms vs Memory access ~10ns Durability (the D in ACID is not necessary) Databases can control all access to the data, while STMs should deal with non-transactional accesses

Locking Protocols and Software Transactional Memory 2/25/2019 Locking Protocols and Software Transactional Memory Pessimism vs Optimism Pessimistic concurrency control Expect conflict Prevent conflict (by holding locks) Need to avoid deadlocks Useful when conflicts are frequent Optimistic concurrency control Expect no conflicts Rollback and retry Need to avoid livelocks, wasted work on retry Useful when conflicts are rare Combination possible

What is the concurrency control in TL2? 2/25/2019 Locking Protocols and Software Transactional Memory What is the concurrency control in TL2?

Version Management : How to perform writes 2/25/2019 Locking Protocols and Software Transactional Memory Version Management : How to perform writes “Eager” writes Perform writes in place Maintain undo-logs to revert writes on abort “Lazy” writes Perform writes in a local log Write to memory at commit time Need to guarantee read-your-own-writes

Dealing with inconsistent reads 2/25/2019 Locking Protocols and Software Transactional Memory Dealing with inconsistent reads atomic { X = 1; Y = 1; } atomic { if(X != Y) while(1); }

Obstruction Freedom: Is it acceptable to hold locks? 2/25/2019 Locking Protocols and Software Transactional Memory Obstruction Freedom: Is it acceptable to hold locks? Long running transactions can block progress ? A switched out thread can block progress ? A failed thread can block progress ? Priority inversion?

Optimisitic Concurrency For Reads 2/25/2019 Locking Protocols and Software Transactional Memory Optimisitic Concurrency For Reads Work loads tend to be read mostly Should allow efficient concurrent reads Look out for writes introduced in a read-only transaction

Locking Protocols and Software Transactional Memory 2/25/2019 Locking Protocols and Software Transactional Memory TL2 Algorithm read_ver = global_clock; on_read(x): (x_ver, x_locked) = version(x); validate_read(x): if(x_locked || x_ver > read_ver) abort; on_write(x): write (x,v) to log forall w in write_set lock(w); atomic{ write_ver = ++global_clock; } forall r in read_set valid_read(r); forall w in write_set{ version(w) = write_ver; unlock(w); }