REGION-BASED DYNAMIC SEPARATION FOR STM HASKELL
Laura Effinger-Dean and Dan Grossman University of Washington TRANSACT, San Jose, CA, June 5, 2011
REGION-BASED DYNAMIC SEPARATION FOR STM HASKELL Laura Effinger-Dean - - PowerPoint PPT Presentation
REGION-BASED DYNAMIC SEPARATION FOR STM HASKELL Laura Effinger-Dean and Dan Grossman University of Washington TRANSACT, San Jose, CA, June 5, 2011 Region-Based Dynamic Separation Motivation We want STM to be correct and fast Do
Laura Effinger-Dean and Dan Grossman University of Washington TRANSACT, San Jose, CA, June 5, 2011
separation
changes
Region-Based Dynamic Separation
therefore the assertion might fail
Thread ¡1 ¡ x ¡= ¡2; ¡ Thread ¡2 ¡ atomic ¡{ ¡ ¡ ¡r1 ¡= ¡x; ¡ ¡ ¡r2 ¡= ¡x; ¡ ¡ ¡assert ¡(r1 ¡== ¡r2); ¡ } ¡
Region-Based Dynamic Separation
Thread ¡1 ¡ atomic ¡{ ¡ ¡ ¡r ¡= ¡ptr; ¡ ¡ ¡ptr ¡= ¡new ¡C(); ¡ } ¡ assert(r-‑>f ¡== ¡r-‑>g); ¡ Thread ¡2 ¡ atomic ¡{ ¡ ¡ ¡++ptr-‑>f; ¡ ¡ ¡++ptr-‑>g; ¡ } ¡ Initially ptr-‑>f ¡== ¡ptr-‑>g ¡ r ¡ ptr ¡ f ¡ g ¡ …
Region-Based Dynamic Separation
Thread ¡1 ¡ atomic ¡{ ¡ ¡ ¡r ¡= ¡ptr; ¡ ¡ ¡ptr ¡= ¡new ¡C(); ¡ } ¡ assert(r-‑>f ¡== ¡r-‑>g); ¡ Thread ¡2 ¡ atomic ¡{ ¡ ¡ ¡++ptr-‑>f; ¡ ¡ ¡++ptr-‑>g; ¡ } ¡ Initially ptr-‑>f ¡== ¡ptr-‑>g ¡
Region-Based Dynamic Separation
accessed in transactions” (and other useful categories)
convenient and expressive
Region-Based Dynamic Separation
transactions” and “never accessed in transactions”
Thread ¡1 ¡ atomic ¡{ ¡ ¡ ¡r ¡= ¡ptr; ¡ ¡ ¡ptr ¡= ¡new ¡C(); ¡ } ¡ assert(r-‑>f ¡== ¡r-‑>g); ¡ Thread ¡2 ¡ atomic ¡{ ¡ ¡ ¡++ptr-‑>f; ¡ ¡ ¡++ptr-‑>g; ¡ } ¡ Initially ptr-‑>f ¡== ¡ptr-‑>g ¡ does not typecheck – r’s target is accessed both inside and outside transactions [HMPJH05, ABHI08, MG08]
Region-Based Dynamic Separation
Thread ¡1 ¡ atomic ¡{ ¡ ¡ ¡r ¡= ¡ptr; ¡ ¡ ¡ptr ¡= ¡new ¡C(); ¡ } ¡ unprotect(r); ¡ assert(r-‑>f ¡== ¡r-‑>g); ¡ Thread ¡2 ¡ atomic ¡{ ¡ ¡ ¡++ptr-‑>f; ¡ ¡ ¡++ptr-‑>g; ¡ } ¡ Initially ptr-‑>f ¡== ¡ptr-‑>g ¡ [AHM08, ABHHI09] Wait for any active transactions to complete
Region-Based Dynamic Separation
state changes for shared data structures
Region-Based Dynamic Separation
static separation is insufficient
Region-Based Dynamic Separation
[HMPJH05]
Region-Based Dynamic Separation
Interface ¡ data ¡STM ¡a ¡ data ¡TVar ¡a ¡ newTVar ¡:: ¡a ¡-‑> ¡STM ¡(TVar ¡a) ¡ readTVar ¡:: ¡TVar ¡a ¡-‑> ¡STM ¡a ¡ writeTVar ¡:: ¡TVar ¡a ¡-‑> ¡a ¡-‑> ¡STM ¡a ¡ atomically ¡:: ¡STM ¡a ¡-‑> ¡IO ¡a ¡ Example ¡ atomically ¡(do ¡{ ¡ ¡ ¡t ¡<-‑ ¡newTVar ¡5; ¡ ¡ ¡x ¡<-‑ ¡readTVar ¡t; ¡ ¡ ¡writeTVar ¡t ¡(x ¡+ ¡1) ¡ }) ¡
Region-Based Dynamic Separation
interface one at a time:
1.
New variable type for dynamic separation: DVars
2.
How to execute dynamic-separation code
3.
New protection states: read-only and thread-local
4.
Shared protection states via regions
Region-Based Dynamic Separation
without static separation
Static ¡separation ¡interface ¡ data ¡STM ¡a ¡ data ¡TVar ¡a ¡ newTVar ¡ ¡ ¡:: ¡a ¡-‑> ¡STM ¡(TVar ¡a) ¡ readTVar ¡ ¡:: ¡TVar ¡a ¡-‑> ¡STM ¡a ¡ writeTVar ¡:: ¡TVar ¡a ¡-‑> ¡a ¡-‑> ¡STM ¡a ¡ Dynamic ¡separation ¡interface ¡ data ¡DSTM ¡a ¡ data ¡DVar ¡a ¡ newDVar ¡ ¡ ¡:: ¡a ¡-‑> ¡DSTM ¡(DVar ¡a) ¡ readDVar ¡ ¡:: ¡DVar ¡a ¡-‑> ¡DSTM ¡a ¡ writeDVar ¡:: ¡DVar ¡a ¡-‑> ¡a ¡-‑> ¡DSTM ¡a ¡ protectDVar ¡ ¡ ¡:: ¡DVar ¡a ¡-‑> ¡IO ¡() ¡ unprotectDVar ¡:: ¡DVar ¡a ¡-‑> ¡IO ¡() ¡
Region-Based Dynamic Separation
standard sequential composition:
Execution ¡interface ¡ protected ¡ ¡ ¡:: ¡DSTM ¡a ¡-‑> ¡STM ¡a ¡ unprotected ¡:: ¡DSTM ¡a ¡-‑> ¡IO ¡a ¡ atomically ¡ ¡:: ¡STM ¡a ¡-‑> ¡IO ¡a ¡ Execution ¡example ¡ do ¡{ ¡ ¡ ¡x ¡<-‑ ¡readTVar ¡t; ¡ ¡ ¡protected ¡(writeDVar ¡d ¡x)} ¡
Region-Based Dynamic Separation
Protection ¡state ¡interface ¡ protectDVar ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡:: ¡DVar ¡a ¡-‑> ¡IO ¡() ¡ unprotectDVar ¡ ¡ ¡ ¡ ¡ ¡ ¡:: ¡DVar ¡a ¡-‑> ¡IO ¡() ¡ makeReadOnlyDVar ¡ ¡ ¡ ¡:: ¡DVar ¡a ¡-‑> ¡IO ¡() ¡ makeThreadLocalDVar ¡:: ¡DVar ¡a ¡-‑> ¡IO ¡() ¡
Region-Based Dynamic Separation
single data structure
rgn ¡ rgn ¡ rgn ¡ rgn ¡
Data structure protection_state ¡ Region DVars
Region-Based Dynamic Separation
Dynamic ¡separation ¡interface ¡ data ¡DSTM ¡a ¡ data ¡DRgn ¡ data ¡DVar ¡a ¡ newDRgn ¡ ¡ ¡:: ¡DSTM ¡DRgn ¡ newDVar ¡ ¡ ¡:: ¡a ¡-‑> ¡DRgn ¡-‑> ¡DSTM ¡(DVar ¡a) ¡ readDVar ¡ ¡:: ¡DVar ¡a ¡-‑> ¡DSTM ¡a ¡ writeDVar ¡:: ¡DVar ¡a ¡-‑> ¡a ¡-‑> ¡DSTM ¡a ¡ protectDRgn ¡ ¡ ¡:: ¡DRgn ¡-‑> ¡IO ¡() ¡ unprotectDRgn ¡:: ¡DRgn ¡-‑> ¡IO ¡() ¡ makeReadOnlyDRgn ¡:: ¡DRgn ¡-‑> ¡IO ¡() ¡ makeThreadLocalDRgn ¡:: ¡DRgn ¡-‑> ¡IO ¡() ¡ protected ¡ ¡ ¡:: ¡DSTM ¡a ¡-‑> ¡STM ¡a ¡ unprotected ¡:: ¡DSTM ¡a ¡-‑> ¡IO ¡a ¡
Region-Based Dynamic Separation
inserts, lookups, and deletes using transactions
isolation (no concurrent operations)
“unprotecting” the table’s DRgn during rehash
Region-Based Dynamic Separation
Dynamic ¡separation ¡example ¡ insert ¡:: ¡DHash ¡k ¡v ¡-‑> ¡k ¡-‑> ¡v ¡-‑> ¡IO ¡() ¡ insert ¡hash ¡key ¡value ¡= ¡do ¡{ ¡ ¡ ¡doRehash ¡<-‑ ¡atomically ¡(...); ¡ ¡ ¡when ¡doRehash ¡(do ¡{ ¡ ¡ ¡ ¡ ¡unprotectDRgn ¡(rgn ¡hash); ¡ ¡ ¡ ¡ ¡unprotected ¡(do ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡table ¡<-‑ ¡readDVar ¡(dvar ¡hash); ¡ ¡ ¡ ¡ ¡ ¡ ¡table' ¡<-‑ ¡DHT.rehash ¡table; ¡ ¡ ¡ ¡ ¡ ¡ ¡writeDVar ¡(dvar ¡hash) ¡table' ¡}); ¡ ¡ ¡ ¡ ¡protectDRgn ¡(rgn ¡hash); ¡ ¡ ¡ ¡ ¡atomically ¡(...) ¡}); ¡ ¡ ¡atomically ¡(insertHelper ¡hash ¡key ¡value) ¡}; ¡ Check table size and acquire table lock. Unprotect table’s DRgn. Perform rehash as non- transaction. Re-protect table’s DRgn. Release lock. Do insert.
Region-Based Dynamic Separation
1.
Strong: describes a strongly-atomic STM.
2.
Weak: describes a lazy-update weakly-atomic STM.
Region-Based Dynamic Separation
Region-Based Dynamic Separation
a thread executes a read or write of a DVar and the DVar’s DRgn’s protection state is:
1.
protected – the thread must be in a transaction
2.
unprotected – the thread must NOT be in a transaction
3.
read-only – the action must be a read
4.
thread-local to θ – the thread’s ID must be θ
Region-Based Dynamic Separation
state and abort if inconsistent
DVar ¡ rgn ¡ value ¡ … ¡ DRgn ¡ state ¡ tid ¡ … ¡
Region-Based Dynamic Separation
DVars instead of TVars, measure slowdown: 0-20%
measure speedup: 2-8x for 4 threads
benefit from dynamic separation and rewrite it: future work
Region-Based Dynamic Separation
semantic issues with weakly-atomic STM implementations
regions and useful new protection states
separation code to be used side-by-side
implementation
Region-Based Dynamic Separation