skip to main content
research-article
Public Access

SC-Haskell: Sequential Consistency in Languages That Minimize Mutable Shared Heap

Published:26 January 2017Publication History
Skip Abstract Section

Abstract

A core, but often neglected, aspect of a programming language design is its memory (consistency) model. Sequential consistency~(SC) is the most intuitive memory model for programmers as it guarantees sequential composition of instructions and provides a simple abstraction of shared memory as a single global store with atomic read and writes. Unfortunately, SC is widely considered to be impractical due to its associated performance overheads.

Perhaps contrary to popular opinion, this paper demonstrates that SC is achievable with acceptable performance overheads for mainstream languages that minimize mutable shared heap. In particular, we modify the Glasgow Haskell Compiler to insert fences on all writes to shared mutable memory accessed in nonfunctional parts of the program. For a benchmark suite containing 1,279 programs, SC adds a geomean overhead of less than 0.4\% on an x86 machine.

The efficiency of SC arises primarily due to the isolation provided by the Haskell type system between purely functional and thread-local imperative computations on the one hand, and imperative computations on the global heap on the other. We show how to use new programming idioms to further reduce the SC overhead; these create a virtuous cycle of less overhead and even stronger semantic guarantees (static data-race freedom).

References

  1. criterion: a Haskell microbenchmarking library. http://www.serpentine.com/criterion/.Google ScholarGoogle Scholar
  2. S. Adve and K. Gharachorloo. Shared memory consistency models: a tutorial. Computer, 29(12):66--76, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. S. V. Adve and H.-J. Boehm. Memory models: A case for rethinking parallel languages and hardware. Commun. ACM, 53(8):90--101, Aug. 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. S. V. Adve and M. D. Hill. Weak Ordering--A New Definition. In Proceedings of the Seventeenth International Symposium on Computer Architecture, pages 2--14, Seattle, WA, May 1990.Google ScholarGoogle Scholar
  5. J. Alglave, D. Kroening, V. Nimal, and D. Poetzl. Don't sit on the fence - A static analysis approach to automatic fence insertion. In Computer Aided Verification - 26th International Conference, CAV 2014, pages 508--524, 2014.Google ScholarGoogle Scholar
  6. C. Blundell, M. Martin, and T. Wenisch. InvisiFence: performance-transparent memory ordering in conventional multiprocessors. In ISCA '09, pages 233--244, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. R. L. Bocchino Jr, V. S. Adve, D. Dig, S. V. Adve, S. Heumann, R. Komuravelli, J. Overbey, P. Simmons, H. Sung, and M. Vakilian. A type and effect system for deterministic parallel java. ACM Sigplan Notices, 44(10):97--116, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. H.-J. Boehm and S. V. Adve. Foundations of the CGoogle ScholarGoogle Scholar
  9. Concurrency Memory Model. In Proceedings of the SIGPLAN 2008 Conference on Programming Language Design and Implementation, Tucson, AZ, June 2008.Google ScholarGoogle Scholar
  10. G. Boudol and G. Petri. Relaxed memory models: An operational approach. In Proceedings of the 36th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL '09, pages 392--403, New York, NY, USA, 2009. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. C. Boyapati, R. Lee, and M. Rinard. Ownership types for safe programming: Preventing data races and deadlocks. In OOPSLA '02, pages 211--230, 2002.Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. C. Boyapati and M. Rinard. A parameterized type system for race-free Java programs. In OOPSLA '01, pages 56--69, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. L. Ceze, J. Tuck, P. Montesinos, and J. Torrellas. BulkSC: bulk enforcement of sequential consistency. In ISCA '07, pages 278--289, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Y. Duan, A. Muzahid, and J. Torrellas. Weefence: Toward making fences free in TSO. In Proceedings of the 40th Annual International Symposium on Computer Architecture, ISCA '13, pages 213--224. ACM, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. C. Flanagan and S. N. Freund. FastTrack: Efficient and precise dynamic race detection. In Proceedings of the 2009 ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI '09, pages 121--133, New York, NY, USA, 2009. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. K. Gharachorloo, A. Gupta, and J. Hennessy. Two techniques to enhance the performance of memory consistency models. In Proceedings of the 1991 International Conference on Parallel Processing, ICPP '91, pages 355--364, 1991.Google ScholarGoogle Scholar
  17. C. S. Gordon, M. J. Parkinson, J. Parsons, A. Bromfield, and J. Duffy. Uniqueness and reference immutability for safe parallelism. SIGPLAN Not., 47(10):21--40, Oct. 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. T. Harris, S. Marlow, S. Peyton-Jones, and M. Herlihy. Composable memory transactions. In Proceedings of the Tenth ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming, PPoPP '05, pages 48--60, New York, NY, USA, 2005. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. A. Kamil, J. Su, and K. Yelick. Making sequential consistency practical in Titanium. In Proceedings of the 2005 ACM/IEEE conference on Supercomputing, page 15. IEEE Computer Society, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. L. Kuper, A. Todd, S. Tobin-Hochstadt, and R. R. Newton. Taming the parallel effect zoo: Extensible deterministic parallelism with lvish. In Proceedings of the 35th ACM SIGPLAN Conference on Programming Language Design and Implementation, page 2. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. L. Kuper, A. Turon, N. R. Krishnaswami, and R. R. Newton. Freeze after writing: quasi-deterministic parallel programming with lvars. In POPL, pages 257--270, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. L. Lamport. How to make a multiprocessor computer that correctly executes multiprocess programs. IEEE transactions on computers, 100(9):690--691, 1979. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. J. Launchbury and S. L. Peyton Jones. Lazy functional state threads. In ACM SIGPLAN Notices, volume 29, pages 24--35. ACM, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. C. Lin, V. Nagarajan, R. Gupta, and B. Rajaram. Efficient sequential consistency via conflict ordering. In Proceedings of the Seventeenth International Conference on Architectural Support for Programming Languages and Operating Systems, ASPLOS XVII, pages 273--286, New York, NY, USA, 2012. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. J. M. Lucassen and D. K. Gifford. Polymorphic effect systems. In Proceedings of the 15th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL '88, pages 47--57, New York, NY, USA, 1988. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. P. Maier and P. Trinder. Implementing a high-level distributed-memory parallel haskell in haskell. In Implementation and Application of Functional Languages, pages 35--50. Springer, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. J. Manson, W. Pugh, and S. Adve. The Java Memory Model. In Conference Record of the Thirty-Second ACM Symposium on Principles of Programming Languages, Long Beach, CA, January 2005.Google ScholarGoogle Scholar
  28. D. Marino, A. Singh, T. Millstein, M. Musuvathi, and S. Narayanasamy. A case for an SC-preserving compiler. In Proceedings of the 32Nd ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI '11, pages 199--210, New York, NY, USA, 2011. ACM.Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. S. Marlow, R. Newton, and S. Peyton Jones. A monad for deterministic parallelism. In Proceedings of the 4th ACM symposium on Haskell, Haskell '11, pages 71--82. ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. K. Naden, R. Bocchino, J. Aldrich, and K. Bierhoff. A type system for borrowing permissions. In Proceedings of the 39th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL '12, pages 557--570, New York, NY, USA, 2012. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. M. Naik, A. Aiken, and J. Whaley. Effective static race detection for Java. In PLDI '06: Proceedings of the 2006 ACM SIGPLAN conference on Programming language design and implementation, pages 308--319, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. W. Partain. The nofib benchmark suite of Haskell programs. In Functional Programming, Glasgow 1992, Workshops in Computing, pages 195--202. Springer-Verlag, 1993. Google ScholarGoogle ScholarCross RefCross Ref
  33. S. Peyton Jones, A. Gordon, and S. Finne. Concurrent haskell. In Proceedings of the 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL '96, pages 295--308, New York, NY, USA, 1996. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. P. Pratikakis, J. S. Foster, and M. Hicks. LOCKSMITH: Context-sensitive correlation analysis for race detection. In Proceedings of the 2006 ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI '06, pages 320--331, New York, NY, USA, 2006. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. P. Ranganathan, V. S. Pai, and S. V. Adve. Using speculative retirement and larger instruction windows to narrow the performance gap between memory consistency models. In Proceedings of the Ninth Annual ACM Symposium on Parallel Algorithms and Architectures, SPAA '97, pages 199--210, New York, NY, USA, 1997. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. S. Sarkar, P. Sewell, F. Z. Nardelli, S. Owens, T. Ridge, T. Braibant, M. O. Myreen, and J. Alglave. The semantics of x86-cc multiprocessor machine code. SIGPLAN Not., 44(1):379--391, Jan. 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. D. Shasha and M. Snir. Efficient and Correct Execution of Parallel Programs that Share Memory. TOPLAS, 10(2), 1988.Google ScholarGoogle Scholar
  38. A. Singh, S. Narayanasamy, D. Marino, T. Millstein, and M. Musuvathi. End-to-end sequential consistency. SIGARCH Comput. Archit. News, 40(3):524--535, June 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Z. Sura, X. Fang, C. Wong, S. Midkiff, J. Lee, and D. Padua. Compiler Techniques for High Performance Sequentially Consistent Java Programs. In PPoPP, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. K. Takeuchi, K. Honda, and M. Kubo. An interaction-based language and its typing system. In In PARLE'94, volume 817 of LNCS, pages 398--413. Springer-Verlag, 1994.Google ScholarGoogle ScholarCross RefCross Ref
  41. D. Terei, S. Marlow, S. Peyton Jones, and D. Mazières. Safe Haskell. In Proceedings of the 2012 Haskell Symposium, Haskell '12, pages 137--148, New York, NY, USA, 2012. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. J. Terrace, S. R. Beard, and N. P. K. Katta. JavaScript in JavaScript (js.js): Sandboxing third-party scripts. In Proceedings of the 3rd USENIX Conference on Web Application Development, WebApps'12, pages 9--9, Berkeley, CA, USA, 2012. USENIX Association.Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. E. Z. Yang and D. Mazières. Dynamic Space Limits for Haskell. In Proceedings of the 35th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI '14, pages 588--598, New York, NY, USA, 2014. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. SC-Haskell: Sequential Consistency in Languages That Minimize Mutable Shared Heap

          Recommendations

          Reviews

          Jacques Carette

          Concurrency remains a hard problem. Efficient concurrency is even harder. But what if there were a setting where writing correct concurrent programs was significantly easier, at a very modest cost in efficiency Too good to be true, right But this is exactly what the authors show for Haskell and similar languages, which naturally promote minimal use of shared heap mutation. The most fundamental invariant in this setting is sequential consistency (SC), a very natural memory model to program with. The authors modify GHC, the main Haskell compiler, to enforce SC. They then extensively benchmark this in a variety of situations, and convincingly show that their solution not only works, but its overhead is remarkably small. One sometimes finds, buried behind a technically accurate title, a superb paper. While not a fundamental breakthrough, this paper is nevertheless scholarship at its best: well written, carefully motivated, based on extremely precise (and fully spelled out) theory, implemented in a real setting, and aggressively benchmarked in an adversarial manner (the authors go out of their way to show worst-case results). And as is increasingly standard, the full source is provided. They also go beyond this, proving preloaded virtual machines to allow independent verification. I will use this paper as an exemplar to my graduate students. Unsurprisingly, such work did uncover a couple of bugs in GHC (as documented in the paper). While the paper says that these would be fixed by GHC 8.2, it turns out that the bug fixes were already implemented in version 8.0.2, as a bit of spelunking in the public bug database reveals. Any referee depressed with all of the rotten papers they've been forced to read can gain a respite by reading this great paper, to remind them that there are excellent papers out there-whether or not they have any particular interest in Haskell or concurrency. Online Computing Reviews Service

          Access critical reviews of Computing literature here

          Become a reviewer for Computing Reviews.

          Comments

          Login options

          Check if you have access through your login credentials or your institution to get full access on this article.

          Sign in

          Full Access

          • Published in

            cover image ACM SIGPLAN Notices
            ACM SIGPLAN Notices  Volume 52, Issue 8
            PPoPP '17
            August 2017
            442 pages
            ISSN:0362-1340
            EISSN:1558-1160
            DOI:10.1145/3155284
            Issue’s Table of Contents
            • cover image ACM Conferences
              PPoPP '17: Proceedings of the 22nd ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming
              January 2017
              476 pages
              ISBN:9781450344937
              DOI:10.1145/3018743

            Copyright © 2017 ACM

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 26 January 2017

            Check for updates

            Qualifiers

            • research-article

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader
          About Cookies On This Site

          We use cookies to ensure that we give you the best experience on our website.

          Learn more

          Got it!