2.2. Kernel Organization In this section, we view the organization of the FreeBSD kernel in two ways. As a static body of software, categorized by the functionality offered by the modules that make up the kernel 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 FreeBSD, 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: files, directories, pathname translation, file locking, and I/O buffer management Terminal-handling support: the pseudo-terminal interface and terminal line disciplines Interprocess-communication facilities: sockets Support for network communication: communication protocols and generic network facilities, such as routing Most of the software in these categories is machine independent and is portable across different hardware architectures. The machine-dependent aspects of the kernel are isolated from the mainstream code. In particular, none of the machine-independent code contains conditional code for specific architectures. When an architecture-dependent action is needed, the machine-independent code calls an architecture-dependent function that is located in the machine-dependent code. The software that is machine dependent includes the following. Low-level system-startup actions Trap and fault handling Low-level manipulation of the run-time context of a process Configuration and initialization of hardware devices Run-time support for I/O devices Table 2.1 summarizes the machine-independent software that constitutes the FreeBSD kernel for the PC. The numbers in column 2 are for lines of C source code, header files, and assembly language. Virtually all the software in the kernel is written in the C programming language; a mere 0.6 percent is written in assembly language. As the statistics in Table 2.2 show, the machine-dependent software, excluding device support, accounts for a minuscule 6.9 percent of the kernel. Not shown are the 846,525 lines of code for the hundreds of supported devices, only a few of which will be loaded into any particular kernel. Table 2.1. Machine-independent software in the FreeBSD kernel.Category | Lines of Code | Percentage of Kernel |
---|
headers | 38,158 | 4.8% | initialization | 1,663 | 0.2% | kernel facilities | 53,805 | 6.7% | generic interfaces | 22,191 | 2.8% | interprocess communication | 10,019 | 1.3% | terminal handling | 5,798 | 0.7% | virtual memory | 24,714 | 3.1% | vnode management | 22,764 | 2.9% | local filesystem | 28,067 | 3.5% | miscellaneous filesystems (19) | 58,753 | 7.4% | network filesystem | 22,436 | 2.8% | network communication | 46,570 | 5.8% | Internet V4 protocols | 41,220 | 5.2% | Internet V6 protocols | 45,527 | 5.7% | IPsec | 17,956 | 2.2% | netgraph | 74,338 | 9.3% | cryptographic support | 7,515 | 0.9% | GEOM layer | 11,563 | 1.4% | CAM layer | 41,805 | 5.2% | ATA layer | 14,192 | 1.8% | ISA bus | 10,984 | 1.4% | PCI bus | 72,366 | 9.1% | pccard bus | 6,916 | 0.9% | Linux compatibility | 10,474 | 1.3% | total machine independent | 689,794 | 86.4% | Key: GEOM geometry; CAM Common Access Method; ATA Advanced Technology Attachment; ISA Industry Standard Architecture; PCI Peripheral Component Interconnect. |
Table 2.2. Machine-dependent software for the PC in the FreeBSD kernel.Category | Lines of Code | Percentage of Kernel |
---|
machine dependent headers | 16,115 | 2.0% | ISA bus | 50,882 | 6.4% | PCI bus | 2,266 | 0.3% | virtual memory | 3,118 | 0.4% | other machine dependent | 26,708 | 3.3% | routines in assembly language | 4,400 | 0.6% | Linux compatibility | 4,857 | 0.6% | Total machine dependent | 108,346 | 13.6% | Key: ISA Industry Standard Architecture; PCI Peripheral Component Interconnect. |
Only a small part of the kernel is devoted to initializing the system. This code is used when the system is bootstrapped into operation and is responsible for setting up the kernel hardware and software environment (see Chapter 14). Some operating systems (especially those with limited physical memory) discard or overlay the software that performs these functions after that software has been executed. The FreeBSD kernel does not reclaim the memory used by the startup code because that memory space is barely 0.2 percent of the kernel resources used on a typical machine. Also, the startup code does not appear in one place in the kernel it is scattered throughout, and it usually appears in places logically associated with what is being initialized. |