560 likes | 796 Views
Tornado: Maximizing Locality and Concurrency in a Shared Memory Multiprocessor Operating System. Ben Gamsa , Orran Krieger, Jonathan Appavoo , Michael Stumm. Locality. What do they mean by l ocality? locality of reference? temporal locality? spatial locality? . Temporal Locality.
E N D
Tornado: Maximizing Locality and Concurrencyin a Shared Memory Multiprocessor Operating System Ben Gamsa, Orran Krieger, Jonathan Appavoo, Michael Stumm
Locality • What do they mean by locality? • locality of reference? • temporal locality? • spatial locality?
Temporal Locality • Recently accessed data and instructions are likely to be accessed in the near future
Spatial Locality • Data and instructions close to recently accessed data and instructions are likely to be accessed in the near future
Locality of Reference • If we have good locality of reference, is that a good thing for multiprocessors?
Locality in Multiprocessors • Good performance depends on data being local to a CPU • Each CPU uses data from its own cache • cache hit rate is high • each CPU has good locality of reference • Once data is brought into cache it stays there • cache contents not invalidated by other CPUs • different CPUs have different locality of reference
Example: Shared Counter CPU CPU Cache Cache Memory Counter
Example: Shared Counter CPU CPU Memory 0
Example: Shared Counter CPU CPU 0 Memory 0
Example: Shared Counter CPU CPU 1 Memory 1
Example: Shared Counter Read : OK CPU CPU 1 1 Memory 1
Example: Shared Counter Invalidate CPU CPU 2 Memory 2
Problems • Counter bounces between CPU caches • cache miss rate is high • Why not give each CPU its own piece of the counter to increment? • take advantage of commutativity of addition • counter updates can be local • reads require all counters
Array-based Counter CPU CPU Memory 0 0
Array-based Counter CPU CPU 1 Memory 1 0
Array-based Counter CPU CPU 1 1 Memory 1 1
Array-based Counter Read Counter CPU 2 CPU CPU 1 1 Add All Counters (1 + 1) Memory 1 1
Performance Performs no better than ‘shared counter’!
Problem: False Sharing • Caches operate at the granularity of cache lines • if two pieces of the counter are in the same cache line they can not be cached (for writing) on more than one CPU at a time
False Sharing CPU CPU Memory 0,0
False Sharing CPU CPU 0,0 Memory 0,0
False Sharing Sharing CPU CPU 0,0 0,0 Memory 0,0
False Sharing Invalidate CPU CPU 1,0 Memory 1,0
False Sharing Sharing CPU CPU 1,0 1,0 Memory 1,0
False Sharing Invalidate CPU CPU 1,1 Memory 1,1
Solution? • Spread the counter components out in memory: pad the array
Padded Array CPU CPU Memory 0 0
Padded Array Updates independent of each other CPU CPU 1 1 Memory 1 1
Performance Works better
Locality in OS • Serious performance impact • Difficult to retrofit • Tornado • Ground up design • Object Oriented approach(natural locality)
Tornado • Object oriented approach • Clustered objects • Protected procedure call • Semi-automatic garbage collection • Simplifies locking protocols
Object Oriented Structure • Each resource is represented by an object • Requests to virtual resources handled independently • No shared data structure access • No shared locks
Why Object Oriented? Process 1 Process 2 … Process Table
Why Object Oriented? Coarse-grain locking: Process 1 Lock Process 2 Process 1 … Process Table
Why Object Oriented? Coarse-grain locking: Process 1 Lock Process 2 Process 1 … Process Table Process 2
Object Oriented Approach Class ProcessTableEntry{ data lock code }
Object Oriented Approach Fine-grain, instance locking: Process 1 Lock Process 2 Process 1 … Lock Process Table Process 2
Clustered Objects • Problem: how to improve locality for widely shared objects? • A single logical object can be composed of multiple local representatives • the reps coordinate with each other to manage the object’s state • they share the object’s reference
Clustered Objects : Implementation • A translation table per processor • Located at same virtual address • Pointer to rep • Clustered object reference is just a pointer into the table • created on demand when first accessed • global miss handling object
Clustered Objects • Degree of clustering • Management of state • partitioning • distribution • replication (how to maintain consistency?) • Coordination between reps? • Shared memory • Remote PPCs
Counter: Clustered Object CPU CPU Object Reference Counter – Clustered Object rep 1 rep 1
Counter: Clustered Object CPU CPU 1 1 Object Reference Counter – Clustered Object rep 1 rep 1
Counter: Clustered Object Update independent of each other CPU CPU 2 1 Object Reference Counter – Clustered Object rep 2 rep 1
Counter: Clustered Object CPU CPU 1 1 Object Reference Counter – Clustered Object rep 1 rep 1
Counter: Clustered Object Read Counter CPU CPU 1 1 Object Reference Counter – Clustered Object rep 1 rep 1 rep 1 rep 1
Counter: Clustered Object Add All Counters (1 + 1) CPU CPU 1 1 Object Reference Counter – Clustered Object rep 1 rep 1 rep 1 rep 1
Synchronization • Two distinct locking issues • Locking • mutually exclusive access to objects • Existence guarantees • making sure an object is not freed while still in use