1 / 87

Lock-Free Resizeable Concurrent Tries

Lock-Free Resizeable Concurrent Tries. Aleksandar Prokopec, Phil Bagwell, Martin Odersky LAMP, École Polytechnique Fédérale de Lausanne Switzerland. Motivation. xs.foreach { x => doSomething(x) }. Motivation. xs.foreach { x => doSomething (x) }. ys = xs.map { x => x * (-1) }.

cullen
Download Presentation

Lock-Free Resizeable Concurrent Tries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lock-Free Resizeable Concurrent Tries Aleksandar Prokopec, Phil Bagwell, Martin Odersky LAMP, École Polytechnique Fédérale de Lausanne Switzerland

  2. Motivation xs.foreach { x => doSomething(x) }

  3. Motivation xs.foreach { x => doSomething(x) } ys = xs.map { x => x * (-1) }

  4. Motivation ys = new ConcurrentMap xs.foreach { x => ys.insert(x * (-1)) }

  5. Hash Array Mapped Tries (HAMT)

  6. Hash Array Mapped Tries (HAMT) 0 = 0000002

  7. Hash Array Mapped Tries (HAMT) 0

  8. Hash Array Mapped Tries (HAMT) 16 = 0100002 0

  9. Hash Array Mapped Tries (HAMT) 0 16

  10. Hash Array Mapped Tries (HAMT) 4 = 0001002 0 16

  11. Hash Array Mapped Tries (HAMT) 4 = 0001002 16 0

  12. Hash Array Mapped Tries (HAMT) 16 0 4

  13. Hash Array Mapped Tries (HAMT) 12 = 0011002 16 0 4

  14. Hash Array Mapped Tries (HAMT) 12 = 0011002 16 0 4

  15. Hash Array Mapped Tries (HAMT) 16 0 4 12

  16. Hash Array Mapped Tries (HAMT) 16 33 0 4 12

  17. Hash Array Mapped Tries (HAMT) 16 33 48 0 4 12

  18. Hash Array Mapped Tries (HAMT) 16 48 0 4 12 33 37

  19. Hash Array Mapped Tries (HAMT) 16 48 4 12 33 37 0 3

  20. Hash Array Mapped Tries (HAMT) 4 12 16 20 25 33 37 48 57 0 1 3 8 9

  21. Hash Array Mapped Tries (HAMT) 4 12 16 20 25 33 37 48 57 0 1 3 8 9 Too much space!

  22. Hash Array Mapped Tries (HAMT) 4 12 16 20 25 33 37 48 57 0 1 3 8 9

  23. Hash Array Mapped Tries (HAMT) 4 12 16 20 25 33 37 48 57 0 1 3 8 9 Linear search at every level - slow!

  24. Hash Array Mapped Tries (HAMT) 4 12 16 20 25 33 37 48 57 0 1 3 8 9 Solution – bitmap index! Relying on BITPOP instruction.

  25. Hash Array Mapped Tries (HAMT) 48 57 1 0 1 0 48 57 1 0 1 0 48 57 10 48 57 BITPOP(((1 << ((hc >> lev) & 1F)) – 1) & BMP)

  26. Hash Array Mapped Tries (HAMT) 4 12 16 20 25 33 37 48 57 0 1 3 8 9 For 32-way tries – 32-bit bitmap.

  27. Hash Array Mapped Tries (HAMT) 4 12 16 20 25 33 37 48 57 0 1 3 8 9

  28. Hash Array Mapped Tries (HAMT) 4 12 16 20 25 33 37 48 57 0 1 3 9

  29. Hash Array Mapped Tries (HAMT) 4 9 12 16 20 25 33 37 48 57 0 1 3 Remove compresses the trie.

  30. Hash Array Mapped Tries (HAMT) • advantages: • low space consumption and shrinking • no contiguous memory region required • fast – logarithmic complexity, but with a low constant factor • used as efficient immutable maps • no global resize phase – real time applications, potentially more scalable concurrent operations?

  31. Concurrent Trie (Ctrie) • goals: • thread-safe concurrent trie • maintain the advantages of HAMT • rely solely on CAS instructions • ensure lock-freedom and linearizability • lookup – probably same as for HAMT

  32. CAS instruction CAS(address, expected_value, new_value) Atomically replaces the value at the address with the new_value if it is equal to the expected_value. Returns true if successful, false otherwise. May fail spuriously.

  33. Lock-freedom If multiple threads execute an operation, at least one of them will complete the operation within a finite number of steps.

  34. Lock-freedom If multiple threads execute an operation, at least one of them will complete the operation within a finite number of steps. do { a = READ(addr) b = a + 1 } while (!CAS(addr, a, b))

  35. Lock-freedom If multiple threads execute an operation, at least one of them will complete the operation within a finite number of steps. def counter() do { a = READ(addr) b = a + 1 } while (!CAS(addr, a, b))

  36. Insertion 4 9 12 16 20 25 33 37 48 57 0 1 3 17 = 0100012

  37. Insertion 4 9 12 16 20 25 33 37 48 57 0 1 3 16 17 17 = 0100012 1) allocate

  38. Insertion 4 9 12 20 25 33 37 48 57 0 1 3 16 17 17 = 0100012 2) CAS

  39. Insertion 4 9 12 20 25 33 37 48 57 0 1 3 16 17 17 = 0100012

  40. Insertion 4 9 12 20 25 33 37 48 57 0 1 3 16 17 18 = 0100102

  41. Insertion 4 9 12 20 25 33 37 48 57 1) allocate 0 1 3 16 17 16 17 18 18 = 0100102

  42. Insertion 4 9 12 20 25 33 37 48 57 2) CAS 0 1 3 16 17 18 18 = 0100102

  43. Insertion Unless… 4 9 12 20 25 33 37 48 57 2) CAS 0 1 3 16 17 18 18 = 0100102

  44. Insertion 28 = 0111002 Unless… T2 4 9 12 20 25 33 37 48 57 T1-1) allocate 0 1 3 16 17 16 17 18 T1 18 = 0100102

  45. Insertion 28 = 0111002 Unless… T2 T2-1) allocate 4 9 12 20 25 20 25 28 T1-1) allocate 0 1 3 16 17 16 17 18 T1 18 = 0100102

  46. Insertion 28 = 0111002 T2-2) CAS T2 4 9 12 20 25 20 25 28 T1-1) allocate 0 1 3 16 17 16 17 18 T1 18 = 0100102

  47. Insertion 28 = 0111002 T2-2) CAS T2 4 9 12 20 25 20 25 28 0 1 3 16 17 16 17 18 T1 T1-2) CAS 18 = 0100102

  48. Insertion 28 = 0111002 T2 4 9 12 20 25 28 0 1 3 16 17 T1 20 25 18 = 0100102 Lost insert! 16 17 18

  49. Insertion – 2nd attempt Solution: I-nodes 4 9 12 20 25 0 1 3 16 17

  50. Insertion – 2nd attempt 28 = 0111002 T2 4 9 12 20 25 0 1 3 16 17 T1 18 = 0100102

More Related