说明
本文是个人学习用的非官方中英对照译文,原文:https://diveintosystems.org/book/C13-OS/advanced.html。
原书采用 CC BY-NC-ND 4.0 许可(禁止演绎),请勿公开传播本译文。
标为「译注」「现代更新」的内容是译者补充,不代表原书作者观点;代码与原文逐字一致,未作改动。
13.5. Summary and Other OS Functionality
在本章中,我们考察了操作系统是什么、它如何工作,以及它在计算机上运行应用程序时所起的作用。作为位于计算机硬件和应用程序之间的系统软件层,操作系统高效地管理计算机硬件,并实现让计算机更易于使用的各种抽象。操作系统实现了进程和虚拟内存这两个抽象,以支持多道程序设计(允许计算机系统上同时运行不止一个程序)。操作系统跟踪系统中所有的进程及其状态,并实现 CPU 核心上运行的进程之间的上下文切换。操作系统还为进程提供了创建新进程、退出以及相互通信的方式。通过虚拟内存,操作系统为每个进程实现了私有虚拟内存空间的抽象。虚拟内存抽象使进程看不到共享计算机物理内存空间的其他进程的影响。分页是虚拟内存的一种实现,它把每个进程虚拟地址空间中的各个页映射到物理 RAM 空间的页框上。虚拟内存也是操作系统更高效地利用 RAM 的一种方式:通过把 RAM 当作磁盘的缓存,它允许虚拟内存空间的页存放在 RAM 中或磁盘上。
In this chapter, we examined what an operating system is, how it works, and the role it plays in running application programs on the computer. As the system software layer between the computer hardware and application programs, the OS efficiently manages the computer hardware and implements abstractions that make the computer easier to use. Operating systems implement two abstractions, processes and virtual memory, to support multiprogramming (allowing more than one program running on the computer system at a time). The OS keeps track of all the processes in the system and their state, and it implements context switching of processes running on the CPU cores. The OS also provides a way for processes to create new processes, to exit, and to communicate with one another. Through virtual memory, the OS implements the abstraction of a private virtual memory space for each process. The virtual memory abstraction protects processes from seeing the effects of other processes sharing the computer’s physical memory space. Paging is one implementation of virtual memory that maps individual pages of each process’s virtual address space to frames of physical RAM space. Virtual memory is also a way in which the OS makes more efficient use of RAM; by treating RAM as a cache for disk, it allows pages of virtual memory space to be stored in RAM or on disk.
本章关注的是操作系统在运行程序中所起的作用,包括它为高效运行程序而实现的抽象和机制,但这绝不是全部。关于进程和进程管理、虚拟内存和内存管理,还有许多其他的实现选择、细节和策略问题。此外,操作系统还实现了许多其他重要的抽象、功能和策略,用于管理和使用计算机。例如,操作系统实现了用于访问存储数据的文件系统抽象、保护用户和系统的保护机制和安全策略,以及针对各种操作系统和硬件资源的调度策略。
Our focus in this chapter on the operating system’s role in running a program, including the abstractions and mechanisms it implements to efficiently run programs, is in no way complete. There are many other implementation options and details and policy issues related to processes and process management, and to virtual memory and memory management. Additionally, operating systems implement many other important abstractions, functionality, and policies for managing and using the computer. For example, the OS implements filesystem abstractions for accessing stored data, protection mechanisms and security policies to protect users and the system, and scheduling policies for different OS and hardware resources.
现代操作系统还实现了对进程间通信、网络以及并行和分布式计算的支持。此外,大多数操作系统都包含对虚拟机管理程序(hypervisor)的支持,它把系统硬件虚拟化,允许宿主操作系统运行多个虚拟的客户操作系统。虚拟化让管理计算机硬件的宿主操作系统能够在自身之上引导和运行多个其他操作系统,每个操作系统都有自己对底层硬件的私有虚拟化视图。宿主操作系统的虚拟机管理程序支持负责管理虚拟化,包括在各客户操作系统之间保护和共享底层的物理资源。
Modern operating systems also implement support for interprocess communication, networking, and parallel and distributed computing. In addition, most operating systems include hypervisor support, which virtualizes the system hardware and allows the host OS to run multiple virtual guest operating systems. Virtualization supports the host OS that manages the computer hardware in booting and running multiple other operating systems on top of itself, each with its own private virtualized view of the underlying hardware. The host operating system’s hypervisor support manages the virtualization, including protection and sharing of the underlying physical resources among the guest operating systems.
最后,大多数操作系统都提供了一定程度的可扩展性,让用户(通常是系统管理员)可以调优操作系统。例如,大多数类 Unix 系统允许用户(通常需要 root 即超级用户权限)改变操作系统缓冲区、缓存和交换分区的大小,并为操作系统子系统和硬件设备从一组不同的调度策略中进行选择。通过这些修改,用户可以针对自己运行的应用程序工作负载类型对系统进行调优。这类操作系统常常支持可加载内核模块(loadable kernel module),即可以加载到内核中、在内核态下运行的可执行代码。可加载内核模块常用来向内核添加额外的抽象或功能,也用来把用于管理特定硬件设备的设备驱动程序代码加载到内核中。
Finally, most operating systems provide some degree of extensibility by which a user (often a system administrator) can tune the OS. For example, most Unix-like systems allow users (usually requiring root, or superuser, privileges) to change sizes of OS buffers, caches, swap partitions, and to select from a set of different scheduling policies in OS subsystems and hardware devices. Through these modifications, a user can tune the system for the type of application workloads they run. These types of operating systems often support loadable kernel modules, which are executable code that can be loaded into the kernel and run in kernel mode. Loadable kernel modules are often used to add additional abstractions or functionality into the kernel as well as for loading device driver code into the kernel that is used to handle managing a particular hardware device.
要更广泛、更深入地了解操作系统,我们推荐阅读一本操作系统教材,例如《Operating Systems: Three Easy Pieces》1。
For more breadth and depth of coverage of operating systems, we recommend reading an operating systems textbook, such as “Operating Systems: Three Easy Pieces”1.
译注
这本书常简称 OSTEP,可在作者网站上免费阅读,中译本名为《操作系统导论》。
13.5.1. 参考文献
13.5.1. References
- Operating Systems: Three Easy Pieces, by Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, Arpaci-Dusseau Books, August, 2018.