The Design and Implementation of the 4.4BSD Operating System
Total Page:16
File Type:pdf, Size:1020Kb
The Design and Implementation of the 4.4BSD Operating System Marshall Kirk McKusick Keith Bostic Michael J. Karels John S. Quarterman The Design and Implementation of the 4.4BSD Operating System by Marshall Kirk McKusick, Keith Bostic, Michael J. Karels, and John S. Quarterman Revision: 76bf5f73 Copyright © 1996 Addison-Wesley Longman, Inc The second chapter of the book, The Design and Implementation of the 4.4BSD Operating System is excerpted here with the permission of the publisher. No part of it may be further reproduced or distributed without the publisher's express written permission. The rest of the book explores the concepts introduced in this chapter in incredible detail and is an excellent reference for anyone with an interest in BSD UNIX. More information about this book is available from the publisher, with whom you can also sign up to receive news of related titles. Information about BSD courses is available from Kirk McKusick. ii Table of Contents 2. Design Overview of 4.4BSD ......................................................................................................... 1 2.1. 4.4BSD Facilities and the Kernel ........................................................................................ 1 2.2. Kernel Organization ....................................................................................................... 2 2.3. Kernel Services ............................................................................................................. 4 2.4. Process Management ...................................................................................................... 4 2.5. Memory Management ..................................................................................................... 6 2.6. I/O System ................................................................................................................... 8 2.7. Filesystems ................................................................................................................. 11 2.8. Filestores .................................................................................................................... 14 2.9. Network Filesystem ...................................................................................................... 15 2.10. Terminals .................................................................................................................. 15 2.11. Interprocess Communication ......................................................................................... 16 2.12. Network Communication .............................................................................................. 16 2.13. Network Implementation .............................................................................................. 17 2.14. System Operation ....................................................................................................... 17 List of Figures 2.1. Process lifecycle .................................................................................................................... 4 2.2. A small filesystem ................................................................................................................ 12 List of Tables 2.1. Machine-independent software in the 4.4BSD kernel ..................................................................... 2 2.2. Machine-dependent software for the HP300 in the 4.4BSD kernel ..................................................... 3 Chapter 2. Design Overview of 4.4BSD 2.1. 4.4BSD Facilities and the Kernel The 4.4BSD kernel provides four basic facilities: processes, a filesystem, communications, and system startup. This section outlines where each of these four basic services is described in this book. 1. Processes constitute a thread of control in an address space. Mechanisms for creating, terminating, and other- wise controlling processes are described in Chapter 4. The system multiplexes separate virtual-address spaces for each process; this memory management is discussed in Chapter 5. 2. The user interface to the filesystem and devices is similar; common aspects are discussed in Chapter 6. The filesystem is a set of named les, organized in a tree-structured hierarchy of directories, and of operations to manipulate them, as presented in Chapter 7. Files reside on physical media such as disks. 4.4BSD supports several organizations of data on the disk, as set forth in Chapter 8. Access to les on remote machines is the subject of Chapter 9. Terminals are used to access the system; their operation is the subject of Chapter 10. 3. Communication mechanisms provided by traditional UNIX systems include simplex reliable byte streams be- tween related processes (see pipes, Section 11.1), and notification of exceptional events (see signals, Section 4.7). 4.4BSD also has a general interprocess-communication facility. This facility, described in Chapter 11, uses access mechanisms distinct from those of the filesystem, but, once a connection is set up, a process can access it as though it were a pipe. There is a general networking framework, discussed in Chapter 12, that is normally used as a layer underlying the IPC facility. Chapter 13 describes a particular networking implementation in detail. 4. Any real operating system has operational issues, such as how to start it running. Startup and operational issues are described in Chapter 14. Sections 2.3 through 2.14 present introductory material related to Chapters 3 through 14. We shall define terms, mention basic system calls, and explore historical developments. Finally, we shall give the reasons for many major design decisions. 2.1.1. The Kernel The kernel is the part of the system that runs in protected mode and mediates access by all user programs to the underlying hardware (e.g., CPU, disks, terminals, network links) and software constructs (e.g., filesystem, network protocols). The kernel provides the basic system facilities; it creates and manages processes, and provides functions to access the filesystem and communication facilities. These functions, called system calls appear to user processes as library subroutines. These system calls are the only interface that processes have to these facilities. Details of the system-call mechanism are given in Chapter 3, as are descriptions of several kernel mechanisms that do not execute as the direct result of a process doing a system call. A kernel in traditional operating-system terminology, is a small nucleus of software that provides only the minimal facilities necessary for implementing additional operating-system services. In contemporary research operating systems -- such as Chorus [11], Mach [1], Tunis [3], and the V Kernel [2] -- this division of functionality is more than just a logical one. Services such as filesystems and networking protocols are implemented as client application processes of the nucleus or kernel. The 4.4BSD kernel is not partitioned into multiple processes. This basic design decision was made in the earliest versions of UNIX. The rst two implementations by Ken Thompson had no memory mapping, and thus made no hardware-enforced distinction between user and kernel space [9]. A message-passing system could have been im- plemented as readily as the actually implemented model of kernel and user processes. The monolithic kernel was chosen for simplicity and performance. And the early kernels were small; the inclusion of facilities such as net- Kernel Organization working into the kernel has increased its size. The current trend in operating-systems research is to reduce the kernel size by placing such services in user space. Users ordinarily interact with the system through a command-language interpreter, called a shell, and perhaps through additional user application programs. Such programs and the shell are implemented with processes. De- tails of such programs are beyond the scope of this book, which instead concentrates almost exclusively on the kernel. Sections 2.3 and 2.4 describe the services provided by the 4.4BSD kernel, and give an overview of the latter's design. Later chapters describe the detailed design and implementation of these services as they appear in 4.4BSD. 2.2. Kernel Organization In this section, we view the organization of the 4.4BSD kernel in two ways: 1. As a static body of software, categorized by the functionality offered by the modules that make up the kernel 2. By its dynamic operation, categorized according to the services provided to users The largest part of the kernel implements the system services that applications access through system calls. In 4.4BSD, this software has been organized according to the following: • Basic kernel facilities: timer and system-clock handling, descriptor management, and process management • Memory-management support: paging and swapping • Generic system interfaces: the I/O, control, and multiplexing operations performed on descriptors • The filesystem: les, directories, pathname translation, le locking, and I/O buer management • Terminal-handling support: the terminal-interface driver and terminal line disciplines • Interprocess-communication facilities: sockets • Support for network communication: communication protocols and generic network facilities, such as routing Table 2.1. Machine-independent software in the 4.4BSD kernel Category Lines of code Percentage of kernel headers 9,393 4.6 initialization 1,107 0.6 kernel facilities 8,793 4.4 generic interfaces 4,782 2.4 interprocess communication 4,540 2.2 terminal handling 3,911 1.9 virtual