Introduction to Linux Kernel

What is Kernel?

Looking at the dictionary, the meaning of the kernel is core. But, as we know kernel refers to the operating system. So, what is kernel core of? In fact, kernel is the core of the overall system. Kernel is the system manager. It manages the system resources. So, what all are resources, we have in the system? This is explained as below:

CPU: This is one of the important resource, we have in system. It is the brain of the system. So, it is very important to optimally use this resource. Now, the question comes, how to manage the CPU. One of the mechanism to optimally use the CPU is, what we call as multitasking. Literal meaning of multitasking is doing more than one thing at a time. But, actually speaking, since in the uniprocessor system, we have a single CPU, so at a time, we execute only program, but to get the feeling of multi-tasking, kernel switches among the processes and switching happens to be so fast that, it seems like processor is executing all the processes at once. The subsystem in kernel which enables to achieve this multi-tasking is called scheduler. The task of managing the CPU is what we call as Process Management or Process Scheduling.

Memory: Another important resource, which we have in the system is the memory. When I say memory, it refers to the RAM. Since all the processes require the memory to execute, memory has to be shared among the processes in such a way that one process should not interfere with another process’ memory. Also, there is concept of virtual addressing, which gives the illusion of having more memory than the available RAM. So, subsystem of the kernel which does this task is memory manager. This task of managing the memory is known as Memory Management.

Input/Output (I/O): As you understand, system has various IO devices such as keyboard, mice, and speakers and so on. The task of managing the IO’s is what we call as IO Management.

Storage: This resource is used for storing the data in the non-volatile memory such as hard-disk. We usually store the data in form of files. So the subsystem in the kernel which deals with creation/deletion and management of files is Filesystem. This task of the kernel is what we call as Storage Management.

Network: In order to communication across the systems, we require the network. So, what needs to be managed in the network? There is networking protocol stack and the network interface card (NIC). The task of managing the network is what we call as Network Management.

So, to summarize, kernel performs the five main tasks – Process Management, Memory Management, I/O Management, Storage Management and Network Management.

Linux Kernel Source Organization

As you might be aware, Linux was developed by Linus Torvalds as an academic project. So, he started to create the directory for each functionality. Figure 1 below shows the kernel source code organization at a higher level.

 

kernel_source

 Figure 1: Linux Kernel Source Organization

As seen, there are directories corresponding to all the five functionality. Process management includes two things, one is the processor related code and the other is scheduling. So, all the CPU related code falls in the arch directory. It contains the directories for various processors. And, for scheduling, there are files starting with sched in directory kernel. For memory management, there is a directory called ‘mm’. So, all the code for managing the memory among the processes, shared memory, managing the mallocs, lies over here. Similarly, for most of the Input/Output management, there is folder called drivers. For storage management, there is directory called fs. It contains the code for various filesystem logic such as Ext2, Ext3, Fat32 and so on. For network, there is a directory called net which contains the code for protocols stack and in the drivers, there is a directory called net for interfacing with network interface card.

Apart from this, there are kernel and lib directories, which contain the architecture independent code in kernel. Similarly, linux directory, under include, contains the headers for architecture independent code in kernel. init contains the code which is used during the kernel boot-up.

Next Article >>

Pradeep D Tewani (12 Posts)

The author used to work at Intel, Bangalore. The author is a Linux enthusiast and is interested in Linux porting, Linux Kernel Internal & Linux device drivers. He shares his learnings on Linux & embedded systems through his workshops & trainings. Learn more about his experiments at http://sysplay.in.


   Send article as PDF   

1 thought on “Introduction to Linux Kernel

  1. Pingback: Linux Kernel Module | Playing with Systems

Leave a Reply

Your email address will not be published. Required fields are marked *