目录
1. Preface(前言)
The three easy pieces refer to the three major thematic elements the book is organized around: virtualization, concurrency, and persistence.
The three easy pieces refer to the three major thematic elements the book is organized around: virtualization, concurrency, and persistence.
Running real code on real systems is the best way to learn about operating systems, so we encourage you to do so when you can.
And thus the real point of the educational process: to go forth, to study many new and fascinating topics, to learn, to mature, and most importantly, to find something that lights a fire for you.
In learning about these ideas, we’ll learn all about how an operating system works, including how it decides what program to run next on a CPU, how it handles memory overload in a virtual memory system, how virtual machine monitors work, how to manage information on disks, and even a little about how to build a distributed system that works when parts have failed. That sort of stuff.
操作系统如何决定下一个时刻哪个程序在CPU上执行?
它如何处理虚拟存储系统上的内存加载??
虚拟机监视程序如何工作?
如何在磁盘上管理信息?
如何构建一个分布式系统在部分宕机的情况下仍然工作
So what happens when a program runs? Well,a running program does one very simple thing: it executes instructions.the processor fetches an instruction from memory, decodes it (i.e., figures out which instruction this is), and executes it (i.e., it does the thing that it is supposed to do, like add two numbers together, access memory, check a condition, jump to a function, and so forth).After it is done with this instruction, the processor moves on to the next instruction, and so on, and so on, until the program finally completes.
Thus, we have just described the basics of the Von Neumann model of computing.
While a program runs, a lot of other wild things are going on with the primary goal of making the system easy to use.
There is a body of software, in fact, that is responsible for making it easy to run programs (even allowing you to seemingly run many at the same time), allowing programs to share memory, enabling programs to interact with devices, and other fun stuff like that. That body of software is called the operating system (OS), as it is in charge of making sure the system operates correctly and efficiently in an easy-to-use manner.
how does the operating system virtualize resources?操作系统如何虚拟化资源?
Why the OS does this is not the main question, as the answer should be obvious: it makes the system easier to use.
That is, the OS takes a physical resource (such as the processor, or memory, or a disk) and transforms it into a more general, powerful, and easy-to-use virtual form of itself. Thus, we sometimes refer to the operating system as a virtual machine.
the OS also provides some interfaces (APIs) that you can call. A typical OS, in fact, exports a few hundred system calls that are available to applications.Because the OS provides these calls to run programs, access memory and devices, and other related actions, we also sometimes say that the OS provides a standard library to applications.
Finally, because virtualization allows many programs to run (thus sharing the CPU), and many programs to concurrently access their own instructions and data (thus sharing memory), and many programs to access devices (thus sharing disks and so forth), the OS is sometimes known as a resource manager. Each of the CPU, memory, and disk is a resource of the system; it is thus the operating system’s role to manage those resources, doing so efficiently or fairly or indeed with many other possible goals in mind.
It turns out that the operating system, with some help from the hardware, is in charge of this illusion, i.e., the illusion that the system has a very large number of virtual CPUs. Turning a single CPU (or small set of them) into a seemingly infinite number of CPUs and thus allowing many programs to seemingly run at once is what we call virtualizing the CPU, the focus of the first major part of this book.
You might also notice that the ability to run multiple programs at once raises all sorts of new questions. For example, if two programs want to run at a particular time, which should run? This question is answered by a policy of the OS; policies are used in many different places within an OS to answer these types of questions, and thus we will study them as we learn about the basic mechanisms that operating systems implement (such as the ability to run multiple programs at once). Hence the role of the OS as a resource manager.