Chapter 10
SMPs and Multicore
operating system developed in single-processor environment in the 1970s. now most servers and many desktops are SMPs. near future is chip multiprocessors, possibly
heterogeneous.
10.1 Operating Systems for SMPs
10.1.1 Parallelism vs. Concurrency
with SMP, things really happen at the same time disabling interrupts doesn’t help
10.1.2 Kernel Locking
single global lock fine grain locking
10.1.3 Conflicts
different processors may take conflicting actions, e.g. regarding allocation of pages.
10.1.4 SMP Scheduling
10.1.5 Multiprocessor Scheduling
In recent years multiprocessor systems i.e. machines with more than one CPU are becoming more common. How does this affect scheduling?
187
Queueing analysis can help
The question we are posing is the following: is it better to have one shared ready queue, or should each processor have its own ready queue? A shared queue is similar
to common practice in banks and post offices, while separate queues are similar to supermarkets. Who is right?
CPU 4 CPU 1
CPU 1 CPU 2
CPU 3 CPU 4
CPU 2 CPU 3
jobs jobs
jobs jobs
jobs jobs
jobs jobs
arriving jobs
arriving jobs
departing departing
departing departing
departing departing
departing departing
queue 1 queue 2
queue 3 shared queue
queue 4
The queueing model for multiple independent queues is simply to take m copies of
the MM1 queue, each with an arrival rate of λm. This represents a system in which
arrivals are assigned at random to one of the processors. The queueing model for a shared queue is MMm, where
m is the number of pro- cessors servers. The state space is similar to that of an MM1 queue, except that
the transitions from state i to i
− 1 depend on how many servers are active:
m λ
µ λ
λ
µ 1
2 λ
µ λ
µ m
λ
µ m+1
µ 2
3 m
m
The mathematics for this case are a bit more complicated than for the MM1 queue, but follow the same principles. The result for the average response time is
¯ r =
1 µ
1 + q
m1 − ρ
where q is the probability of having to wait in the queue because all m servers are
busy, and is given by q = π
mρ
m
m1 − ρ
The expression for π
is also rather complicated... The resulting plots of the response time, assuming
µ = 1 and m = 4, are 188
5 10
15 20
25 30
0.2 0.4
0.6 0.8
1 average response time
utilization 4 x MM1
MM4
Obviously, using a shared queue is substantially better. The banks and post offices are right. And once you think about it, it also makes sense: with a shared queue, there
is never a situation where a client is queued and a server is idle, and clients that require only short service do not get stuck behind clients that require long service —
they simply go to another server.
Exercise 145 Why is it “obvious” from the graphs that MM4 is better?
But what about preemption?
The queueing analysis is valid for the non-preemptive case: each client sits in the queue until it is picked by a server, and then holds on to this server until it terminates.
With preemption, a shared queue is less important, because clients that only re- quire short service don’t get stuck behind clients that need long service. However,
this leaves the issue of load balancing. If each processor has its own local queue, the system needs explicit load balancing
— migrating jobs from overloaded processors to underloaded ones. This ensures fair- ness and overall low response times. However, implementing process migration is not
trivial, and creates overhead. It may therefore be better to use a shared queue after all. This ensures that there is never a case where some job is in the queue and some
processor is idle. As jobs are not assigned to processors in this case, this is called “load sharing” rather than “load balancing”.
The drawback of using a shared queue is that each job will probably run on a different processor each time it is scheduled. This leads to the corruption of cache
state. It is fixed by affinity scheduling, which takes the affinity of each process to each processor into account, where affinity is taken to represent the possibility that
relevant state is still in the cache. It is similar to simply using longer time quanta.
10.2 Supporting Multicore Environments