MAIN MEMORYCORE 0CACHECORE 1CACHEQUEUE 0QUEUE 1SHARED QUEUESLICE0RELOADS0/0ABCD
Back: main memory; middle: two cores, each with its own cacheFront: a queue per core, and one shared queue with a lockBlocks: jobs A to D; discs: data reloaded into a cacheMain memory at the back; two cores in the middle, each with its own cache; a run queue in front of each core; one shared queue with a lock at the front, next to a counter of slices and cache reloads. With the shared queue, every pick takes the lock and every job lands on the other core each slice, so every run reloads its data. With a queue per core the jobs stay put and their caches stay warm, until the queues fall out of balance and core 0 steals D. The figure plays a slice-by-slice simulation. Taking the lock, switching jobs and reloading data are drawn as free; on a real machine each costs time, which is why affinity and fewer locks matter.

One shared queue

  1. A multicore chip has several cores. Each core is a CPU that runs one job at a time. Here there are two. Each has its own small, fast cache, and both share one big, slow main memory.

A queue per core

Keeping the balance

What happens

;; step 1/11 · cores
core      runs one job at a time
cache     small and fast, one per core
memory    big and slow, shared by every core

a value already in the cache: a few nanoseconds
a value fetched from memory:  tens to hundreds of ns
(OSTEP ch. 10)

new question for the scheduler: not only who runs
next and for how long, but also on WHICH core

The figure plays a slice-by-slice simulation. Taking the lock, switching jobs and reloading data are drawn as free; on a real machine each costs time, which is why affinity and fewer locks matter. Each cache is drawn holding the data of the last two jobs that ran on its core. A real cache holds small lines of data from many jobs, so a moved job loses much, not all, of its warm data. Hardware cache coherence keeps every copy correct either way: moving costs speed, never correctness.