A Dialogue on Virtualization

Part I πŸ’¬ Dialogue OSTEP pp. 23–24 Β· ~5 min read

Part I opens with the book’s most famous analogy. You’ve already seen virtualization happen β€” four programs sharing one CPU in chapter 2 β€” so consider this the parable version.

Professor:And thus we reach the first of our three pieces on operating systems: virtualization.
Student:But what is virtualization, oh noble professor?
Professor:Imagine we have a peach.
Student:A peach? (incredulous)
Professor:Yes, a peach. Let us call that the physical peach. But we have many eaters who would like to eat this peach. What we would like to present to each eater is their own peach, so that they can be happy. We call the peach we give eaters virtual peaches; we somehow create many of these virtual peaches out of the one physical peach. And the important thing: in this illusion, it looks to each eater like they have a physical peach, but in reality they don’t.
Student:So you are sharing the peach, but you don’t even know it?
Professor:Right! Exactly.
Student:But there’s only one peach. If I was sharing a peach with somebody else, I think I would notice.
Professor:Ah yes! Good point. But that is the thing with many eaters; most of the time they are napping or doing something else, and thus, you can snatch that peach away and give it to someone else for a while. And thus we create the illusion of many virtual peaches, one peach for each person!
Student:Sounds like a bad campaign slogan. You are talking about computers, right Professor?
Professor:Ah, young grasshopper, you wish to have a more concrete example. Good idea! Let us take the most basic of resources, the CPU. Assume there is one physical CPU in a system (though now there are often two or four or more). What virtualization does is take that single CPU and make it look like many virtual CPUs to the applications running on the system. Thus, while each application thinks it has its own CPU to use, there is really only one. And thus the OS has created a beautiful illusion: it has virtualized the CPU.

The analogy, drawn out

The parableeater 1eater 2eater 3eater 4virtualvirtualvirtualvirtualphysicalone real peach, handed around while eaters napThe real thingapp Aapp Bapp Capp Dvirtual CPUvirtual CPUvirtual CPUvirtual CPU1 physical CPUfetch–decode–executeone real CPU, handed around while apps wait

One physical resource, many convincing virtual copies (dashed). The violet arrows are the OS’s doing β€” and how it pulls this off is the subject of the next seven chapters.

Tip: β€œNapping” has a technical name

The Professor’s trick β€” snatch the peach while its eater naps β€” is exactly what you watched in chapter 2’s timeline: at any instant one process runs while the others sit in the ready state (or sleep waiting for I/O), none the wiser. Chapter 4 gives the napping its proper names: time sharing and process states.

Student:Wow! That sounds like magic. Tell me more! How does that work?
Professor:In time, young student, in good time. Sounds like you are ready to begin.
Student:I am! Well, sort of. I must admit, I’m a little worried you are going to start talking about peaches again.
Professor:Don’t worry too much; I don’t even like peaches. And thus we begin…

Note what the dialogue deliberately doesn’t answer: the Student’s β€œhow does that work?” The mechanism β€” how the OS actually snatches a CPU away and hands it to someone else without anyone crashing β€” is the story of the chapters ahead: the process abstraction, its API, limited direct execution, and then the scheduling policies that decide who eats next.

Check yourself

1.In the peach analogy, what does the peach stand for?

2.The Student objects: "if I was sharing a peach, I would notice." What is the Professor's answer?

3.The Student asks "How does that work?" β€” and gets no answer. Which question does this dialogue deliberately leave open?

3 questions