4. 4
Agenda
What is Software Transactional Memory (STM)?
Contention in STM
Enable Switching on Transactions
SchedSTM – a Flexible Scheduling Framework for STM
Experiments
Conclusion
5. 5
Agenda
What is Software Transactional Memory (STM)?
Contention in STM
Enable Switching on Transactions
SchedSTM – a Flexible Scheduling Framework for STM
Experiments
Conclusion
6. Software Transactional Memory (STM)
A model for controlling concurrent memory accesses in the scope of
parallel programming
Optimistic transaction execution
Dynamically detect and resolve memory conflicts
Three guarantees [1.1]:
Atomicity
Consistency
Isolation
6
7. Advantages of STM
Coarse-grained locking programming interface
Critical sections -> transactions
Non-blocking synchronization
Avoid deadlock
More scalable
Learn more about TM:
Introduction to Transactional Memory and Its Implementation (COSCUP 2021)
7
8. Transaction Execution Three Phases
Begin
Registration, allocation, notification, …
Proceed
Read/ write address set recording
Memory conflict detection
Store buffering
End (validation)
Consistency: commit, write back data
Inconsistency: abort, rollback data 8
9. Transaction Optimistic Execution
9
Thread 0 Thread 1
Begin:
x=x+1
y=y+1
End:
Begin:
z=z+1
k=k+1
End:
Begin
x=x+1
y=y+1
End
Tx0: Tx1:
Begin:
k=k+2
End:
Tx2:
Begin
z=z+1
k=k+1
End
10. Transaction Optimistic Execution
10
Thread 0 Thread 1
Begin:
x=x+1
y=y+1
End:
Begin:
z=z+1
k=k+1
End:
Begin
x=x+1
y=y+1
End Validation
No conflicts
Tx0: Tx1:
Commit
Begin:
k=k+2
End:
Tx2:
Begin
z=z+1
k=k+1
End
11. Transaction Optimistic Execution
11
Thread 0 Thread 1
Begin:
x=x+1
y=y+1
End:
Begin:
z=z+1
k=k+1
End:
Begin
x=x+1
y=y+1
End
Tx0: Tx1:
Commit
Begin:
k=k+2
End:
Tx2:
Begin
z=z+1
k=k+1
End
Begin
k=k+1
End
12. Transaction Optimistic Execution
12
Thread 0 Thread 1
Begin:
x=x+1
y=y+1
End:
Begin:
z=z+1
k=k+1
End:
Begin
x=x+1
y=y+1
End
Tx0: Tx1:
Commit
Begin:
k=k+2
End:
Tx2:
Begin
z=z+1
k=k+1
End
Begin
k=k+1
End
13. Transaction Optimistic Execution
13
Thread 0 Thread 1
Begin:
x=x+1
y=y+1
End:
Begin:
z=z+1
k=k+1
End:
Begin
x=x+1
y=y+1
End
Tx0: Tx1:
Commit
Begin:
k=k+2
End:
Tx2:
Begin
z=z+1
k=k+1
End
Begin
k=k+1
End
Commit
Abort
14. Transaction Optimistic Execution
14
Thread 0 Thread 1
Begin:
x=x+1
y=y+1
End:
Begin:
z=z+1
k=k+1
End:
Begin
x=x+1
y=y+1
End
Tx0: Tx1:
Commit
Begin:
k=k+2
End:
Tx2:
Begin
z=z+1
k=k+1
End
Begin
k=k+1
End Commit
Abort Aborting a transaction
makes overhead!!
15. Transaction Optimistic Execution
15
Thread 0 Thread 1
Begin:
x=x+1
y=y+1
End:
Begin:
z=z+1
k=k+1
…
…
…
…
End:
Begin
x=x+1
y=y+1
End
Tx0: Tx1:
Begin:
k=k+2
End:
Tx2:
Begin
z=z+1
k=k+1
End
...
Begin
k=k+1
End
Abort Immediately Restart
Tx2
Begin
k=k+1
End
16. Transaction Optimistic Execution
16
Thread 0 Thread 1
Begin:
x=x+1
y=y+1
End:
Begin:
z=z+1
k=k+1
…
…
…
…
End:
Begin
x=x+1
y=y+1
End
Tx0: Tx1:
Begin:
k=k+2
End:
Tx2:
Begin
z=z+1
k=k+1
End
...
Begin
k=k+1
End
Abort
Begin
k=k+1
End
17. Transaction Optimistic Execution
17
Thread 0
Thread 1
Begin:
x=x+1
y=y+1
End:
Begin:
z=z+1
k=k+1
…
…
…
…
End:
Begin
x=x+1
y=y+1
End
Tx0: Tx1:
Begin:
k=k+2
End:
Tx2:
Begin
z=z+1
k=k+1
End
...
Begin
k=k+1
End
Abort
Begin
k=k+1
End
Abort
Repeat aborting transaction
worsens the performance
18. 18
Agenda
What is Software Transactional Memory (STM)?
Contention in STM
Enable Switching on Transactions
SchedSTM – a Flexible Scheduling Framework for STM
Experiments
Conclusion
19. Contention in STM
When a process scales up
Thread number ↑
Conflict probability ↑
Interleaving conflict probability ↑
Abort ratio ↑
Overhead ↑
Scalability ↓
19
20. Contention Resolving Techniques
Contention Managers [2.1]
Delaying aborted transactions restarting for reducing repeated conflicts
Schedulers [2.2]
Thread scheduling
Concurrency control -> dynamic adjustment of thread number
Transaction scheduling
Serializing collide transactions
20
21. STM Execution with 16 threads
21
SU: Suicide(restart); BO: Backoff (CM); ATS: Adaptive Transaction Scheduler
22. Observations on Previous Works
Previous CMs or schedulers suspend execution for reducing contention
Sacrificing parallelism degree
Seldom of them can further improve performance
Maintaining a level of speedup without improving potential
All of them lack switch action
Similar to OS uses context switch to hide IO latency
22
23. Observations on Previous Works
23
Trans B
Trans A
Trans B
Thread 0
Thread 1
Trans B Trans B
Thread 1
Trans B
Naïve
(Suicide)
CM
(Backoff)
Trans B Trans B
Thread 1
time
Sched
❷ Immediately restart Trans B. but keeps aborting.
Committed Aborted
❸ Delays the restart of Trans B with undetermined delay
❶ Trans A kills Trans B
❹ Thread 1 halts until Trans A signal
Trans A signal
Trans B Trans B
Thread 1
Oracle
Trans C
❺ Switches to independent Trans C
24. 24
Agenda
What is Software Transactional Memory (STM)?
Contention in STM
Enable Switching on Transactions
SchedSTM – a Flexible Scheduling Framework for STM
Experiments
Conclusion
25. Switching Transactions
Can the system switch to another transaction during execution?
Programming model
Runtime support
Can we find a non-collide transaction to switch to?
Scheduling algorithm design
25
26. Programming Model Modification
STM applications are usually iterative convergent. [2.3]
Existing an objective value to minimize or maximize.
Iteratively determining if the objective value is small or big enough.
E.g. machine learning, KNN, NLP, and other scientific computing.
26
28. Example: Learning A Bayes Network
28
Rain Sprinkler Grass Wet
1 1 1
1 0 1
0 1 0
… … …
Observed data:
Sprinkler Rain
Grass
Wet
Rain
T F
Sprinkler
T F
Rain
T
F
Learn
T F
Rain
T
F
Grass Wet
Sprinkler
F
F
T
T
F
T
0.2 0.8
0.4
0.01
0.6
0.99
0.0 1.0
0.8
0.9
0.99
0.2
0.1
0.01
34. Example: Learning A Bayes Network
34
Insert new arguments for next
iteration.
35. Loop Parallelization + Coroutine
Split iterations to individual tasks [3.4]
A task should be executed serially
But the execution of order between tasks is flexible
Use coroutine to switch between tasks [3.1]
No additional interrupt
Lightweight
Switching is controlled by process
35
36. 36
Transaction A
Transaction B
Transaction C
Loop:
Transaction A
Transaction B
Transaction C
Iteration 0
Iteration 1
Iteration 2
Yield to
Iteration 0’s
Transaction B
Loop Parallelization + Coroutine
parallelization
37. 37
Agenda
What is Software Transactional Memory (STM)?
Contention in STM
Enable Switching on Transactions
SchedSTM – a Flexible Scheduling Framework for STM
Experiments
Conclusion
38. SchedSTM Objective
Seamless integration of the switch action to STM scheduler
Unified & clear interface
Customized scheduler input information
Runtime conflict tracking
Statistical analysis
Trivial or no modification need on application slide
38
44. Conclusion
Switching to another transaction is an indispensable action to avoid
contention overhead.
SchedSTM provides unified and powerful interface for both
scheduler designers and parallel programmers.
Our experiments validates that the addition of switch action can
further improve performance.
44
45. References
1. Introduction
[1.1] IBM: Transactional memory
[1.2] Meltdown: Reading Kernel Memory from User Space
[1.3] C++-Transactional Memory
2. Contention Resolving Techniques
[2.1] Dragojević, Aleksandar, Rachid Guerraoui, and Michal Kapalka. "Stretching transactional memory." ACM sigplan notices 44.6 (2009):
155-165.
[2.2] Di Sanzo, Pierangelo, et al. "Adaptive model-based scheduling in software transactional memory." IEEE Transactions on
Computers 69.5 (2019): 621-632.
[2.3] Harlap, Aaron, et al. "Addressing the straggler problem for iterative convergent parallel ML." Proceedings of the seventh ACM
symposium on cloud computing. 2016.
45
46. References (cont.)
3. Implementation
[3.1] Moodycamel::Concurrent queue
[3.2] Libaco – A blazing fast and lightweight C asymmetric coroutine libaray
[3.3] TinySTM Github
[3.4] Aiken, Alexander, and Alexandru Nicolau. "Optimal loop parallelization." ACM SIGPLAN Notices 23.7 (1988): 308-317.
[3.5] STAMP-Standford Transactional Memory for Multi-Processing
4. Experiments
[4.1] Dorigo, Marco, Mauro Birattari, and Thomas Stutzle. "Ant colony optimization." IEEE computational intelligence magazine 1.4 (2006):
28-39.
[4.2] Dragojević, Aleksandar, et al. "Preventing versus curing: avoiding conflicts in transactional memories." Proceedings of the 28th ACM
symposium on Principles of distributed computing. 2009.
[4.3] Scherer III, William N., and Michael L. Scott. "Advanced contention management for dynamic software transactional
memory." Proceedings of the twenty-fourth annual ACM symposium on Principles of distributed computing. 2005.
46