What is an Operating system? – Types of Kernel


Welcome :)

Let us start with definition of operating system.

An operating system is software that manages the computer hardware as well as providing an environment for application programs to run.Perhaps the most visible aspect of an operating system is the interface to the computer system, it provides to the human user.

We can primarily divide the operating system into kernel( core part + system services ) + user interface (command line or graphical)

Though each operating system has a kernel, this is buried behind a lot of other software and most users don’t even know it exists

 is user interface part of operating system?.

Well for an end-user a Linux distribution (say Ubuntu) is an Operating System while for a programmer the Linux kernel(kernel.org) itself is a perfectly valid OS depending on what you’re trying to achieve. For instance embedded systems are mostly just kernel with very small number of specialized processes running on top of them. In that case the kernel itself becomes the OS itself.

So what is kernel?

The kernel is a piece of software that constitutes the central core of a computer operating system. It has complete control over everything that occurs in the system.

Okay, but what does this mean for us? What exactly is an OS Kernel, and why should we care for it?

There is no rule that states, “a kernel is mandatory”. We can easily just load and execute programs at specific addresses without any “kernel”. In fact, all of the early computer systems started this way. However, it was eventually realized that convenience and efficiency could be increased by retaining small utility programs, such as program loaders and debuggers, in memory between applications. These programs gradually evolved into operating system kernels

More  details:- Accessing the hardware directly could  be very complex, so kernels usually implement a set of hardware abstractions. These abstractions are a way of hiding the complexity, and providing a clean and uniform interface to the underlying hardware, which makes it easier to application programmers.

And  provides secure access to the machine’s hardware to various computer programs. Since there are many programs, and access to the hardware is limited, the kernel is also responsible for deciding when and how long a program should be able to make use of a piece of hardware.

It does lot of other stuff , we will see it later.

Kernel Space vs User Space

Because of its critical nature, the kernel code is usually loaded into a protected area of memory, which prevents it from being overwritten by other, less frequently used parts of the operating system or by application programs. The kernel performs its tasks in kernel space.

whereas everything a user normally does, such as writing text in a text editor or running programs in a GUI (graphical user interface), is done in user space. This separation is made in order to prevent user data and kernel data from interfering with each other and thereby diminishing performance or causing the system to become unstable (and possibly crashing).

The system calls act as an interface between the user space and the kernel space.We will discuss about system calls later.

By definition kernel have to have direct control over every little thing.it needs to run in supervisor(kernel) mode. This is  enforced by the CPU hardware.

Kernel Mode

In Kernel mode, the executing code has complete and unrestricted access to the underlying hardware. It can execute any CPU instruction and reference any memory address. Kernel mode is generally reserved for the lowest-level, most trusted functions of the operating system. Crashes in kernel mode are catastrophic; they will halt the entire PC.

User Mode

In User mode, the executing code has no ability to directly access hardware or reference memory. Code running in user mode must delegate to system APIs to access hardware or memory. Due to the protection afforded by this sort of isolation, crashes in user mode are always recoverable. Most of the code running on your computer will execute in user mode.

x86 CPU hardware actually provides four protection rings: 0, 1, 2, and 3

Kernel Types

Kernels can be classified into three broad categories

1. Monolithic kernels

2. Micro kernel

3.Hybrid Kernel (This is bit controversial. We will see why it is )

Monolithic Kernel

Monolithic kernel got simple design and it  is a single large processes running entirely in a single address space and in the kernel space. It is a single static binariy file. All kernel services exist and execute in kernel address space. The kernel can invoke functions directly.

Applications run in the userspace(ring 3)

but one consequence of all parts of the kernel running in the same address space is that if there is an error (‘bug’) somewhere in the kernel, it will have an effect on the entire address space; in other words, a bug in the subsystem that  takes care of networking might crash the kernel as a whole, resulting in the user needing to reboot his system.

Example : MS-DOS, BSD, HP-UX, AIX, Windows 98, Linux ( with Module support )

Micro Kernel

Micro kernels designed to fix the  above problem, it try to limit the amount of damage a bug can cause. They do this by moving parts of the kernel away from the dangerous  kernelspace into userspace, where the parts run in isolated processes (so-called ‘servers’) as a consequence, they do not influence each other’s functioning. The bug in the networking subsystem which crashed monolithic kernel (in the above example) will have far less severe results in a microkernel design: the subsystem in question will crash, but all other subsystems will continue to function.  In fact, many microkernel operating systems have a system in place which will automatically reload crashed servers.

While this seems to be a  very elegant design, it has two major downsides compared to monolithic kernels: added complexity and performance penalties .In a microkernel design, only a small subset of the tasks a monolithic kernel performs reside in kernelspace, while all other tasks live in user space. Generally, the part residing in kernelspace (the actual ‘microkernel’) takes care of the communication between the servers running in userspace; this is called ‘inter-process communication (IPC)’ . These servers provide functionality such as sound, display, disk access, networking, and so on.

This complexity also creates performance. Simply put, the communication between the servers of a micro kernel takes time. In a monolithic design, this communication is not needed as all the servers are tied into one big piece of computer code, instead of  several different pieces. The result is that a monolithic kernel will generally out perform a micro kernel  (provided they are similar feature-wise). This explains why Torvalds chose to write Linux in a  monolithic fashion; in the early ‘90s, computer resources were much more limited than they are today, and hence anything that could increase performance was a welcome addition.

This scheme adds a lot of complexity to the overall system. A good analogy (Microkernels: augmented criticism (no date)) is to take a piece of Goat (the monolithic kernel), chop it into small  parts (the servers), put each of those parts into hygienic plastic bags (the isolation), and then link the individual bags to one another with strings (the IPC). The total weight of the end result will be that of the original Goat, plus that of the plastic bags and string. Therefore, while a microkernel may appear simple on a very local level, at a global level it will be much more complex than a similar monolithic kernel.

Example : Mach, Minix, QNX, L4

Hybrid Kernel

As an answer to these concerns, a new type of kernel design was devised. This design combines the monolithic and microkernel design in that it has characteristics of both. It keeps some subsystems in kernel space to increase performance, while keeping others out of kernel space to improve stability.

That part of a hybrid kernel running in kernel space is in fact structured as if it were a microkernel; as a consequence, parts which run in kernel space can actually be ‘moved out’ of it to userspace relatively easily. Microsoft Corp. has   demonstrated this flexibility by moving large parts of its audio subsystem in the Windows operating system from kernel space to userspace .

The hybrid design   is controversial and  has been heavily criticised. Linus Torvalds  said the term hybrid was devised only for marketing reasons. He say that  hybrid kernel is a monolothic kernel trying to be a microkernel, or it is a microkernel trying to be monolithic

Hybrid kernels are used in most commercial operating systems such as Microsoft Windows NT, 2000, XP, Vista, and 7. Apple Inc’s own Mac OS X uses a hybrid kernel called XNU which is based upon code from Carnegie Mellon’s Mach kernel and FreeBSD’s monolithic kernel.

Hybrid kernels should not be confused with monolithic kernels that can load modules after booting (such as Linux).

Some monolithic kernels can be compiled to be modular (e.g Linux), what matters is that the module is inserted to and run from the same space that handles core functionality.

Monolithic  kernel vs  Micro kernel  with emphasis on Linux 

1)      Supporters of micro kernels point out that monolithic kernels have the disadvantage that an error in the kernel can cause the entire system to crash. However, with a micro kernel, if a kernel process crashes, it is still possible to prevent a crash of the system as a whole by merely restarting the service that caused the error. Although this sounds sensible, it is questionable how important it is in reality, because operating systems with monolithic kernels such as Linux have become extremely stable and can run for years without crashing.

2)      Monolithic kernels also appear to have the disadvantage that their source code can become extremely large
For example, the source code for the Linux kernel version 2.6.0 is 212MB and contains 5.93 million lines. This adds to the complexity of maintaining the kernel, and it also makes it difficult for new generations of computer science students to study and comprehend the kernel. However, the advocates of monolithic kernels claim that in spite of their size such kernels are easier to design correctly, and thus they can be improved more quickly than can micro kernel-based systems.

Moreover, the size of the compiled kernel is only a tiny fraction of that of the source code, for example roughly 1.1MB in the case of Linux version 2.4 on a typical Red Hat Linux 9 desktop installation. Contributing to the small size of the compiled Linux kernel is its ability to dynamically load modules at runtime, so that the basic kernel contains only those components that are necessary for the system to start itself and to load modules.

The monolithic Linux kernel can be made extremely small not only because of its ability to dynamically load modules but also because of its ease of customization. In fact, there are some versions that are small enough to fit together with a large number of utilities and other programs on a single floppy disk and still provide a fully functional operating system (one of the most popular of which is muLinux). This ability to miniaturize its kernel has also led to a rapid growth in the use of Linux in embedded systems

3)     Another disadvantage cited for monolithic kernels is that they are not easily portable; that is, they must be rewritten for each new architecture (i.e., processor type) that the operating system is to be used on. However, in practice, this has not appeared to be a major disadvantage, and it has not prevented Linux from being ported to numerous processors.

This topic is not complete without reading this http://en.wikipedia.org/wiki/Tanenbaum%E2%80%93Torvalds_debate

Conclusion : Which Kernel type I should choose.

I have mentioned about Pros and Cons of kernel  design types.  Decide your self based on requirement. Some researchers are claiming that with some tweaking in IPC and clever communication Micro kernel performance is  comparable with Monolithic Kernel.

Other than the Monolithic,Micro,Hybrid there are other kernel types like Exo ,Nano Kernel etc.We will discuss about these later.

In next post we will see about different types of Operating systems :)


About these ads

One thought on “What is an Operating system? – Types of Kernel

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s