Operating System Kernels Patrick Bitterling Computer Systems and Telematics Institute of Computer Science Freie Universität Berlin, Germany [email protected]
Total Page:16
File Type:pdf, Size:1020Kb
1 Operating System Kernels Patrick Bitterling Computer Systems and Telematics Institute of Computer Science Freie Universität Berlin, Germany [email protected] Abstract—A Kernel is the backbone of most operating series (till ME). Between this two designs exists the systems. This paper provides information about kernel Hybrid kernel, which is found in the Windows NT series architectures with their features and advantages. The three (includes XP and Vista) and in Mac’s OS/2 and OS/X. In most actual desktop operating systems are distributions of section 2 the different kernel architectures are explained. Linux, (free)BSD and Windows Vista. The kernels (even This include the benefits of these architectures. Section when they have the same architecture) of these OS differs greatly in there subsystems. So this paper shows how the 3 gives a overview of the subsystems of three operating subsystems of these kernels work. Following subsystems system kernels which is followed by a comparison of are viewed: process management and scheduling, system these subsystems. calls, interrupts, kernel synchronization, time and memory management management and additionally a short look II. THE DIFFERENT KERNEL ARCHITECTURES: into the networking stack. But not all operating systems have a kernel. So there must be alternatives which are These section discusses the differences between the shown in the last part of section 3. microkernel, the monolithic kernel and the hybrid kernel. A. The microkernel I. INTRODUCTION In the past there are huge metal machines that are feed with magnetic tapes to perform some work. Today you can start your fair-size computer or even smaller laptop with pressing on a button. In a short time you have nice graphical user interface and a lot of applications, that can be used for the desired work. Between these two scenarios past more then fifty years has elapsed. In the beginning there are no operating systems for computers and the first operating systems did not include any kernel. The time elapsed and the computer had to support more hardware. But OS were developed further and it was time for the kernel-based operating systems. The first kernels were microkernels. The microkernel is a minimal computer operating system kernel. The The design of a microkernel determines that it has only first operating system kernels were small, because the functions for a simple inter-process communication, computer memory was limited. Computers became more memory management and scheduling. All these efficient and the operating system kernel had to control a functions are operation in the kernel mode but the larger number of devices. The address spaces increased rest runs in the user mode. The microkernel is not from 16 to 32 bits, so the kernel design was not limited implemented as one huge process. The functionality by hardware architecture and the size of the kernel began of the Microkernel is divided in several processes the to grow. With the the grow of the kernel there was a new so called Servers. In best case only these Servers get upcoming design the monolithic kernel. The monolithic more privileges which need them to do their tasks. kernel is used in operating systems with Linux-kernel All servers are separated from the system and each and a lot of known BSD-derivatives as FreeBSD. It process has his own address space. The result is that was also used by MS DOS and the MS Windows 9x the microkernel cannot start functions directly. It has 2 to communicate via "Message Passing" which is an C. The hybrid kernel inter-process communication mechanism which allows Servers to communicate to other Servers. Because of this implementation errors affect only the process in which it occurs. These modularization allows to exchange servers without jamming the hole system. The communication via inter-process communication produce more overhead then a function call and more context switches the a monolithic kernel. The result of the context switches is a major latency, which results in a negative performance. The hybrid kernel design is something between the microkernel and the monolithic kernel (that is the B. The monolithic kernel reason for the name). The hybrid kernel runs the same processes in kernel-mode microkernel. Additional the hybrid kernel runs the application IPC and the device drivers in kernel mode. In the user-mode is used for UNIX-Server, File-Server and applications. The goal of this architecture is to get the performance benefits of a monolithic kernel, with the stability of a microkernel The result is a microkernel-like structure in monolithic kernel and a controversy about the need of an extra category for this kernel or only have the two categories microkernel and monolithic kernel. III. KERNEL SUBSYSTEMS This section gives a overview of the Windows Vista, Linux 2.6.28 and FreeBSD 7.0 kernel subsystems. The overview begins with all Linux kernel subsystem, fol- lowing by the FreeBSD and Vista kernel subsystem. At In contrast to the microkernel the monolithic kernel last there is a short look into the network protocol stack. includes more functions, so there are more services that run in kernel-mode like all device drivers, A. The Linux kernel architecture dispatcher,scheduling, virtual memory, all inter-process The Linux kernel is a monolithic kernel, but it also a communication (not only the simple IPC as in a modular kernel. The Linux kernel possesses the ability microkernel), the (virtual) file system and the system to load and unload kernel-code. So the Linux kernel can calls, so only applications run in user-mode. The load drivers for new devices on demand. monolithic kernel is implemented as one process, which runs in one single address space. All kernel services are running in one kernel address space, so B. Linux process management the communication between these services is more Linux kernel saves all pieces of information in a data simple, because the kernel processes the ability to call structure.[1] These data structure contains information all functions directly like a program in user-space. like open files, the address space of the process, status The ability to perform system calls results in better of the process. To identify a process each process performance and simpler implementation of the kernel. contains a process identifier called PID. The PID is a The crash or bug in one module which is running in number of the type (in most cases ) int but uses only kernel-mode can crash the hole system. the length of short int (32768) to be compatible with 3 older UNIX or Linux versions. Linux, FreeBSD and are only the the resources duplicated which are used Windows Vista using a five-state process management by both processes (called copy-on-write). The exec() model. function loads code in the address space and execute it. (Often a fork() is used before exec()). In Linux threads are only processes that are both share some resources and address space. For a computation in the background the kernel can spawn kernel-threads that are only working in the kernel-space and have no address space. To end a process the system call exit() is used or when a process must end because of an exception or a signal. When a process ends the parent gets a signal, free resources and calls schedule() to switch to another process. At last the process descriptor is freed. If parent process ends before the child process the child process must bound to another process, because of the process hierarchy. C. Linux process scheduling Since the 2.6.23 kernel Linux uses a Completely Fair Scheduler (CFS) [2], [3]. On real hardware only one single task can run at once. Most fair would be running each process with 1/n of the processors physical Each process is in one of the following five states: power. So while one task runs, the other tasks that are RUNNING the task is running or in runqueue and waiting for the CPU are at a disadvantage, because the awaits to run, INTERRUBTIBLE the process sleeps current task gets an unfair amount of CPU time. In (blocked) and waits on a condition or a wake up signal CFS this fairness imbalance is expressed and tracked to switch in the RUNNING state, UNINTERRUBTILE via the per-task p->wait_runtime (nanosec-unit) value. − like INTERRUBTIBLE but the process cannot wait_runtimeïs¨ the amount of time the task should now wake up via signal to switch in the RUNNING state, run on the CPU for it to become completely fair and ZOMBIE the task has finished but the parent has made balanced. CFS’s task picking logic is based on this p- the wait4() system call to free the process descriptor, >wait_runtime value. It always tries to run the task with STOPPED the execution of the process was stopped the largest p->wait_runtime value. In other words, CFS and the process has no possibility to switch back to tries to run the task with most need for more CPU time. RUNNING state. One important aspect of the process In practice the task runs only the amount of time until is the executed code which is read from a executable the p->wait_runtime value is low enough so that another file and runs in within the address space. In general the task needs to run. To decide which task should run they execution of the program is placed in user-space till a are sorted in a time ordered red-black-tree. The CFS has system call or exception switch it to the kernel-space. additionally classes with variable priorities. When they The kernel is now in the process context which means are no more runnable task in one class the the CFS runs that the kernel proceed a job in the name of this task.