Kernel programming and debugging mini-course labs

The Linux® kernel is the main component of a Linux operating system and is the core interface between a computer’s hardware and its processes.1  It communicates between the two; managing the hardware, running user programs, and maintaining the security and integrity of the whole system.

Starting work on the Linux Kernel can be daunting. However, after completing this detailed exercise, users will have an understanding of how to download, modify, build, install and debug their own Linux Kernel. This exercise will guide users through the process of building and loading kernel modules, defining, implementing and adding a new system call and investigating page-cache hits and misses.

-building

Building and installing the Linux Kernel is the first task and this guide takes users through the process step-by-step. Along the way users will be shown how to customise the Kernel to make it their own, so that changes that are made are reflected in the version number by editing the Makefile. Be sure to read the instructions carefully, mistakes in this phase can be rather time-consuming!

-loading kernel modules

Users will also find instructions on building and deploying a loadable kernel module, along with source code which is accessible through git or in the appendix. Although the basic exercise is primitive, there are suggestions for additional exercises related to this task, like exporting kernel internal constants.

-new syscall

Defining a new system call is relatively easy, however this doesn’t make it any less worth while. In this part of the exercise the reader is introduced to the system call table and gets to make their own entry. This does require a rebuild but after that users can say that they have added a new syscall to their own Linux Kernel!

-THE PAGE-CACHE

The page-cache is magical and this part of the exercise will show you how it turns a computer from a piece of junk to something functional- or the other way round. The reader can also expect to go into more source code to make a function count the page-cache hits and misses and write this data into the /proc filesystem. They will then write utilities to exercise the page-cache and see the difference that dropping the page-cache makes to performance Vs. turning page-cache look-ahead off altogether.

1 “What Is the Linux Kernel?” Red Hat – We Make Open Source Technologies for the Enterprise, www.redhat.com/en/topics/linux/what-is-the-linux-kernel.