Source Tour

The kernel source is made up of around two million lines of code. While that may seem intimidating, it is important to remember that very few people understand all the subsystems and associated source code in depth. You can improve your programming productivity if you know where to look for specific code, down to a directory and a source file.

What goes where

Fortunately, the source is well organised into a logical directory structure. This section gives a quick guide to the top level kernel source directory:

  • Documentation: Information about specific platforms & devices as well as general kernel information.

  • arch: Architecture specific code; i386, sparc etc.

  • drivers: Device specific code; sound card, network card etc.

  • fs: Filesystem specific code; ext2, vfat etc.

  • include: Kernel header files.

  • init: All the code associated with the boot and initialisation process.

  • IPC: Inter Process Communication code; shared memory implementation etc.

  • kernel: The core kernel code; scheduling, signals etc.

  • libs: Kernel related libraries; image decompression etc.

  • mm: Memory Management related code.

  • net: Network related code.

  • scripts: kernel related scripts (e.g. patch-kernel)

Key data structures

This section gives a quick guide to some of the fundamental data structures, including key fields and where to find them in the kernel source tree.

Process descriptor

Process Descriptor: task_struct: ~/include/linux/sched.h:281

Page descriptor

Page Descriptor:

Starting Points

This section will present a selection of good starting points for reading and understanding the kernel source code.

Your Turn

Find and read the driver code for some of the devices in your system.

Take a look at the Makefiles and see if you can figure out how the build process works. See Documentation/kbuild/makefiles.txt for help.