region based dynamic separation for stm haskell
play

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


  1. REGION-BASED DYNAMIC SEPARATION FOR STM HASKELL Laura Effinger-Dean and Dan Grossman University of Washington TRANSACT, San Jose, CA, June 5, 2011

  2. Region-Based Dynamic Separation Motivation • We want STM to be correct and fast • Do nontransactional accesses interact with STM? • Yes – reasonable behavior, but slow (strong atomicity) • No – fast but has strange behavior (weak atomicity) • This work focuses on one compromise: dynamic separation • Programmer inserts calls to STM when sharing behavior of data changes

  3. Region-Based Dynamic Separation Background: Transactional races • Growing consensus: the following code is racy and therefore the assertion might fail Thread ¡1 ¡ Thread ¡2 ¡ atomic ¡{ ¡ x ¡= ¡2; ¡ ¡ ¡r1 ¡= ¡x; ¡ ¡ ¡r2 ¡= ¡x; ¡ ¡ ¡assert ¡(r1 ¡== ¡r2); ¡ } ¡

  4. Region-Based Dynamic Separation Background: Privatization • Some non-racy idioms are unsafe in basic weak STMs • Canonical privatization example: Initially ptr-­‑>f ¡== ¡ptr-­‑>g ¡ ptr ¡ r ¡ Thread ¡1 ¡ Thread ¡2 ¡ … atomic ¡{ ¡ atomic ¡{ ¡ ¡ ¡r ¡= ¡ptr; ¡ ¡ ¡++ptr-­‑>f; ¡ ¡ ¡ptr ¡= ¡new ¡C(); ¡ ¡ ¡++ptr-­‑>g; ¡ f ¡ g ¡ } ¡ } ¡ assert(r-­‑>f ¡== ¡r-­‑>g); ¡

  5. Region-Based Dynamic Separation Background: Privatization • Eager update: assert sees update from zombie • Lazy update: assert sees a partially committed transaction Initially ptr-­‑>f ¡== ¡ptr-­‑>g ¡ Thread ¡1 ¡ Thread ¡2 ¡ atomic ¡{ ¡ atomic ¡{ ¡ ¡ ¡r ¡= ¡ptr; ¡ ¡ ¡++ptr-­‑>f; ¡ ¡ ¡ptr ¡= ¡new ¡C(); ¡ ¡ ¡++ptr-­‑>g; ¡ } ¡ } ¡ assert(r-­‑>f ¡== ¡r-­‑>g); ¡ • Symmetric problem: publication

  6. Region-Based Dynamic Separation Existing solutions • Special-case the privatization and publication idioms • Support “single global lock atomicity” • Require programs to obey a separation discipline • Separate objects into “always accessed in transactions” and “never accessed in transactions” (and other useful categories) • Weak implementation is correct for these programs • Static and dynamic approaches • Our work is on making the dynamic approach more convenient and expressive

  7. Region-Based Dynamic Separation Background: Static separation • Type system separates objects into “always accessed in transactions” and “never accessed in transactions” • State changes like privatization now illegal: Initially ptr-­‑>f ¡== ¡ptr-­‑>g ¡ Thread ¡1 ¡ Thread ¡2 ¡ atomic ¡{ ¡ atomic ¡{ ¡ ¡ ¡r ¡= ¡ptr; ¡ ¡ ¡++ptr-­‑>f; ¡ ¡ ¡ptr ¡= ¡new ¡C(); ¡ ¡ ¡++ptr-­‑>g; ¡ } ¡ } ¡ assert(r-­‑>f ¡== ¡r-­‑>g); ¡ does not typecheck – r’s target is accessed both inside and outside transactions [HMPJH05, ABHI08, MG08]

  8. Region-Based Dynamic Separation Background: Dynamic separation • Every object has a dynamic protection state • Programmer manually instruments state changes Initially ptr-­‑>f ¡== ¡ptr-­‑>g ¡ Thread ¡1 ¡ Thread ¡2 ¡ atomic ¡{ ¡ atomic ¡{ ¡ ¡ ¡r ¡= ¡ptr; ¡ ¡ ¡++ptr-­‑>f; ¡ ¡ ¡ptr ¡= ¡new ¡C(); ¡ ¡ ¡++ptr-­‑>g; ¡ } ¡ } ¡ unprotect(r); ¡ assert(r-­‑>f ¡== ¡r-­‑>g); ¡ Wait for any active transactions to complete [AHM08, ABHHI09]

  9. Region-Based Dynamic Separation Our contributions • Most important: Dynamic regions allow constant-time state changes for shared data structures • Extended set of protection states for variables • Read-only, thread-local • Static and dynamic separation exist side-by-side • Libraries can be agnostic with respect to transactions • Formal semantics and proof of correctness • Haskell implementation & evaluation

  10. Region-Based Dynamic Separation So why Haskell? • Static separation is a natural fit for Haskell • Add dynamic separation in order to handle cases where static separation is insufficient • E.g., privatization • Existing formal semantics and benchmark suite

  11. Region-Based Dynamic Separation STM Haskell • Static separation • Nontransactional variables are IORefs • Transactional variables are TVars • Impossible to use IORefs inside an atomic block • Natural application of Haskell’s monadic type system • Clean semantics for transactions: • Sequential and alternative composition • Exception handling • Manual retry [HMPJH05]

  12. Region-Based Dynamic Separation STM actions Example ¡ Interface ¡ data ¡STM ¡a ¡ atomically ¡(do ¡{ ¡ data ¡TVar ¡a ¡ ¡ ¡t ¡<-­‑ ¡newTVar ¡5; ¡ ¡ ¡x ¡<-­‑ ¡readTVar ¡t; ¡ newTVar ¡:: ¡a ¡-­‑> ¡STM ¡(TVar ¡a) ¡ ¡ ¡writeTVar ¡t ¡(x ¡+ ¡1) ¡ readTVar ¡:: ¡TVar ¡a ¡-­‑> ¡STM ¡a ¡ }) ¡ writeTVar ¡:: ¡TVar ¡a ¡-­‑> ¡a ¡-­‑> ¡STM ¡a ¡ atomically ¡:: ¡STM ¡a ¡-­‑> ¡IO ¡a ¡ • Actions on TVars can be composed to form STM actions • STM actions are executed via “atomically”

  13. Region-Based Dynamic Separation Adding dynamic separation • We will introduce our extensions to STM Haskell’s interface one at a time: New variable type for dynamic separation: DVars 1. How to execute dynamic-separation code 2. New protection states: read-only and thread-local 3. Shared protection states via regions 4.

  14. Region-Based Dynamic Separation 1. Adding DVars • Now three variable types: IORef, TVar, DVar • DVars correspond to normal variables in languages without static separation Static ¡separation ¡interface ¡ Dynamic ¡separation ¡interface ¡ data ¡STM ¡a ¡ data ¡DSTM ¡a ¡ data ¡TVar ¡a ¡ data ¡DVar ¡a ¡ newTVar ¡ ¡ ¡:: ¡a ¡-­‑> ¡STM ¡(TVar ¡a) ¡ newDVar ¡ ¡ ¡:: ¡a ¡-­‑> ¡DSTM ¡(DVar ¡a) ¡ readTVar ¡ ¡:: ¡TVar ¡a ¡-­‑> ¡STM ¡a ¡ readDVar ¡ ¡:: ¡DVar ¡a ¡-­‑> ¡DSTM ¡a ¡ writeTVar ¡:: ¡TVar ¡a ¡-­‑> ¡a ¡-­‑> ¡STM ¡a ¡ writeDVar ¡:: ¡DVar ¡a ¡-­‑> ¡a ¡-­‑> ¡DSTM ¡a ¡ protectDVar ¡ ¡ ¡:: ¡DVar ¡a ¡-­‑> ¡IO ¡() ¡ unprotectDVar ¡:: ¡DVar ¡a ¡-­‑> ¡IO ¡() ¡

  15. Region-Based Dynamic Separation 2. Running dynamic separation code Execution ¡interface ¡ protected ¡ ¡ ¡:: ¡DSTM ¡a ¡-­‑> ¡STM ¡a ¡ unprotected ¡:: ¡DSTM ¡a ¡-­‑> ¡IO ¡a ¡ atomically ¡ ¡:: ¡STM ¡a ¡-­‑> ¡IO ¡a ¡ • protected converts “DSTM action” to “STM action” • execute transaction using “atomically (protected (…))” • or, seamlessly combined with other STM actions, e.g. using standard sequential composition: Execution ¡example ¡ do ¡{ ¡ ¡ ¡x ¡<-­‑ ¡readTVar ¡t; ¡ ¡ ¡protected ¡(writeDVar ¡d ¡x)} ¡ • unprotected converts “DSTM action” to “IO action” • runs as a non-transaction

  16. Region-Based Dynamic Separation 3. Extra protection states • Prior work included three protection states • protected (always-accessed-in-transactions) • unprotected (never-accessed-in-transactions) • read-only • We add a fourth state: thread-local Protection ¡state ¡interface ¡ protectDVar ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡:: ¡DVar ¡a ¡-­‑> ¡IO ¡() ¡ unprotectDVar ¡ ¡ ¡ ¡ ¡ ¡ ¡:: ¡DVar ¡a ¡-­‑> ¡IO ¡() ¡ makeReadOnlyDVar ¡ ¡ ¡ ¡:: ¡DVar ¡a ¡-­‑> ¡IO ¡() ¡ makeThreadLocalDVar ¡:: ¡DVar ¡a ¡-­‑> ¡IO ¡() ¡

  17. Region-Based Dynamic Separation 4. Regions • Key feature: share protection state across objects in a single data structure • Each DVar is allocated in a DRgn • Constant-time protection state changes Region protection_state ¡ DVars rgn ¡ rgn ¡ rgn ¡ rgn ¡ Data structure

  18. Region-Based Dynamic Separation Final interface 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 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend