Darwin: Kernel Architecture Overview

Mac OS X provides many benefits to the Macintosh user and developer communities. These benefits include improved reliability and performance, enhanced networking features, an object-based system programming interface, and increased support for industry standards.

In creating Mac OS X, Apple has completely re-engineered the Mac OS core operating system. Forming the foundation of Mac OS X is the kernel. Figure 1 illustrates the Mac OS X architecture.


Figure 1 Mac OS X architecture

The kernel provides many enhancements for Mac OS X. These include preemption, memory protection, enhanced performance, improved networking facilities, support for both Macintosh (Extended and Standard) and non-Macintosh (UFS, ISO 9660, and so on) file systems, object-oriented APIs, and more. Two of these features, preemption and memory protection, lead to a more robust environment.

In Mac OS 9, applications cooperate to share processor time. Similarly, all applications share the memory of the computer among them. Mac OS 9 is a cooperative multitasking environment. The responsiveness of all processes is compromised if even a single application doesn’t cooperate. On the other hand, real-time applications such as multimedia need to be assured of predictable, time-critical, behavior.

In contrast, Mac OS X is a preemptive multitasking environment. In Mac OS X, the kernel provides enforcement of cooperation, scheduling processes to share time (preemption). This supports real-time behavior in applications that require it.

In Mac OS X, processes do not normally share memory. Instead, the kernel assigns each process its own address space, controlling access to these address spaces. This control ensures that no application can inadvertently access or modify another application’s memory (protection). Size is not an issue; with the virtual memory system included in Mac OS X, each application has access to its own 4 GB address space.

Viewed together, all applications are said to run in user space, but this does not imply that they share memory. User space is simply a term for the combined address spaces of all user-level applications. The kernel itself has its own address space, called kernel space. In Mac OS X, no application can directly modify the memory of the system software (the kernel).

Although user processes do not share memory by default as in Mac OS 9, communication (and even memory sharing) between applications is still possible. For example, the kernel offers a rich set of primitives to permit some sharing of information among processes. These primitives include shared libraries, frameworks, and POSIX shared memory. Mach messaging provides another approach, handing memory from one process to another. Unlike Mac OS 9, however, memory sharing cannot occur without explicit action by the programmer.

Use of Darwin

The Mac OS X kernel is a key part of Apple's Open Source initiative. The Mac OS X kernel is also the core of an operating system product called Darwin. Darwin is a complete operating system based on many of the same technologies that underlie Mac OS X. However, Darwin does not include Apple's proprietary graphics or applications layers, such as Quartz, QuickTime, or OpenGL.

The figure below shows the relationship between Darwin and Mac OS X. Both build upon the same kernel, but Mac OS X adds Core Services, Application Services and QuickTime, as well as the Classic, Carbon, Cocoa, and Java (JDK) application environments. Both Darwin and Mac OS X include the BSD command-line application environment; however, in Mac OS X, this environment is usually hidden.

Darwin technology is based on BSD, Mach 3.0, and Apple technologies. Best of all, Darwin technology is Open Source technology, which means that developers have full access to the source code. Developers can also see how Apple is doing things in the core operating system and adopt (or adapt) code to use within their own products.

Because the same system software forms the core of both Mac OS X and Darwin, system software developers can write software that runs on both Mac OS X and Darwin with few, if any, required changes. The only difference might be in the way the software interacts with the application environment.

The Mac OS X core operating system is based on proven technology from many sources. A large portion of this technology is derived from FreeBSD, a version of 4.4BSD that offers advanced networking, performance, security, and compatibility features. Other parts of the system software, such as Mach, are based on technology previously used in Apple's MkLinux project, in Mac OS X Server, and in technology acquired from NeXT. Much of the code is platform-independent. All of the core operating-system code is available in source form.

The core technologies have been chosen for several reasons. Mach provides a clean set of abstractions for dealing with memory management, interprocess (and interprocessor) communication, and other low-level operating-system functions. In today's rapidly changing hardware environment, this provides a form of separation between the operating system and the underlying hardware.

BSD is a carefully engineered, mature operating system with many capabilities. In fact, most of today's commercial Linux, UNIX, and other similar operating systems contain a great deal of BSD code. BSD also provides a set of industry-standard APIs.

Other Architectural Components

The above diagram describes the kernel architecture of Mac OS X. Normally, the kernel is a small collection of software that provides minimal devices for Operating System services. This is not the case for OS X.

Mac OS X's kernel includes Mach, BSD, the I/O kit, file systems, and networking components. While other Operating Systems have used this idea in the past, it is a first for Apple. Apple had reasoning for providing each of these components in the kernel.

Mach

Mach manages processor resources such as CPU usage and memory, handles scheduling, provides memory protection, and provides a messaging-centered infrastructure to the rest of the operating-system layers. The Mach component provides...

BSD

Above the Mach layer, the BSD layer provides "OS personality" APIs and services. The BSD layer is based on the BSD kernel, primarily FreeBSD. The BSD component provides

I/O Kit

The I/O Kit provides a framework for simplified driver development, supporting many categories of devices. The I/O Kit features an object-oriented I/O architecture implemented in a restricted subset of C++. The I/O Kit framework is both modular and extensible. The I/O Kit component provides

Networking

Mac OS X networking takes advantage of BSD's advanced networking capabilities to provide support for modern features, such as Network Address Translation (NAT) and firewalls. The networking component provides...

File Systems

Mac OS X provides support for numerous types of file systems, including HFS, HFS+, UFS, NFS, ISO 9660, and others. The default file-system type is HFS+; Mac OS X boots (and "roots") from HFS+. Advanced features of Mac OS X file systems include an enhanced Virtual File System (VFS) design. VFS provides for a layered architecture (file systems are stackable). The file system component provides

Source: http://developer.apple.com/techpubs/macosx/Darwin/General/KernelProgramming/Architecture/Kernel_Arch_re_Overview.html

2002 Apple Computer, Inc. (Last Updated November 2002)