Kernel musings

0

Being a curious sort of person, I wonder about a lot of interesting things. For some reason, I’ve started wondering about the Linux kernel and how many lines of code it contains, and the size of the Linux kernel as it’s compiled for Fedora, my preferred distro.

I don’t especially care about exact numbers at a point in time, I just want to get a general feel for those questions. Turning to the Internet, I found this chart on Wikipedia, which indicates that kernel version 6.6 contains just over 37 million lines of source code.

Source: Wikipedia. This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.

Another source says that Linux has just passed 40 million lines of source code, and that makes sense since the most recent kernel is 6.13. That seems huge, but it’s important to understand that the Linux kernel code contains support for the following processor hardware architectures.

  1. alpha
  2. arc
  3. arm
  4. arm64
  5. csky
  6. hexagon
  7. loongarch
  8. m68k
  9. microbaze
  10. mips
  11. nios2
  12. openrisc
  13. parisc
  14. powerpc
  15. riscv
  16. s390
  17. sh
  18. sparc
  19. um
  20. x86
  21. xtensa

And this is the short list. Wikipedia has the longer and more detailed list.

That is impressive because Windows only supports one processor architecture, the Intel x86, which is what most PCs use. Microsoft doesn’t release statistics like lines of code, and the entire kernel is proprietary, so you can’t check it out on GitHub to count for yourself. However there are estimates that place it between 60 and 100 million lines of code. For just one hardware architecture.

Even better, compiled versions of Linux for any architecture, such as the Intel X86, don’t use all those lines. The actual number of lines of source code used in any compiled kernel, and therefore the size of the kernel, depends upon the target architecture and the options selected for the kernel at compile time.

Kernel files

The installed kernels are located in the /boot directory, along with other kernel related files. There are usually three kernels stored there, the most current and the two most recent prior to that. I personally keep a total of 5 kernels — not counting the so-called rescue kernel.

I had an instance several years ago, in which a critical software package would crash when running on the current kernel. I rebooted and selected the most recent previous kernel, and that software worked just fine. Eventually, another kernel update resolved the issue. Such problems are an excellent reason for keeping older kernels.

root@david:/boot# ll -h
total 509M
-rw-r--r--. 1 root root 274K Jan 22 19:00 config-6.12.11-200.fc41.x86_64
-rw-r--r--. 1 root root 274K Feb  7 19:00 config-6.12.13-200.fc41.x86_64
-rw-r--r--. 1 root root 274K Feb 17 19:00 config-6.12.15-200.fc41.x86_64
-rw-r--r--. 1 root root 276K Feb 21 19:00 config-6.13.4-200.fc41.x86_64
-rw-r--r--. 1 root root 276K Feb 26 19:00 config-6.13.5-200.fc41.x86_64
drwx------. 4 root root 4.0K Dec 31  1969 efi
drwxr-xr-x. 2 root root 4.0K Oct 29 12:31 extlinux
drwx------. 4 root root 4.0K Mar  4 10:28 grub2
-rw-------. 1 root root  83M Sep 10  2020 initramfs-0-rescue-0b07292c495a42ee9f5867ebff1ccee2.img
-rw-------. 1 root root  57M Jan 31 08:07 initramfs-6.12.11-200.fc41.x86_64.img
-rw-------. 1 root root  57M Feb 16 20:48 initramfs-6.12.13-200.fc41.x86_64.img
-rw-------. 1 root root  57M Feb 22 08:47 initramfs-6.12.15-200.fc41.x86_64.img
-rw-------. 1 root root  57M Feb 26 10:27 initramfs-6.13.4-200.fc41.x86_64.img
-rw-------. 1 root root  57M Mar  1 10:21 initramfs-6.13.5-200.fc41.x86_64.img
drwxrwxr-x. 3 root root 4.0K Sep 10  2020 loader
drwx------. 2 root root  16K Sep 10  2020 lost+found
-rw-r--r--. 1 root root 154K Nov 11 19:00 memtest86+x64.efi
-rw-r--r--. 1 root root 179K Jan 31 08:07 symvers-6.12.11-200.fc41.x86_64.xz
-rw-r--r--. 1 root root 179K Feb 16 20:48 symvers-6.12.13-200.fc41.x86_64.xz
-rw-r--r--. 1 root root 179K Feb 22 08:47 symvers-6.12.15-200.fc41.x86_64.xz
-rw-r--r--. 1 root root 181K Feb 26 10:27 symvers-6.13.4-200.fc41.x86_64.xz
-rw-r--r--. 1 root root 181K Mar  1 10:21 symvers-6.13.5-200.fc41.x86_64.xz
-rw-r--r--. 1 root root  11M Jan 22 19:00 System.map-6.12.11-200.fc41.x86_64
-rw-r--r--. 1 root root  11M Feb  7 19:00 System.map-6.12.13-200.fc41.x86_64
-rw-r--r--. 1 root root  11M Feb 17 19:00 System.map-6.12.15-200.fc41.x86_64
-rw-r--r--. 1 root root  11M Feb 21 19:00 System.map-6.13.4-200.fc41.x86_64
-rw-r--r--. 1 root root  11M Feb 26 19:00 System.map-6.13.5-200.fc41.x86_64
-rwxr-xr-x. 1 root root  11M Sep 10  2020 vmlinuz-0-rescue-0b07292c495a42ee9f5867ebff1ccee2
-rwxr-xr-x. 1 root root  16M Jan 22 19:00 vmlinuz-6.12.11-200.fc41.x86_64
-rwxr-xr-x. 1 root root  16M Feb  7 19:00 vmlinuz-6.12.13-200.fc41.x86_64
-rwxr-xr-x. 1 root root  16M Feb 17 19:00 vmlinuz-6.12.15-200.fc41.x86_64
-rwxr-xr-x. 1 root root  16M Feb 21 19:00 vmlinuz-6.13.4-200.fc41.x86_64
-rwxr-xr-x. 1 root root  16M Feb 26 19:00 vmlinuz-6.13.5-200.fc41.x86_64
root@david:/boot#

And since we’re here, there are some interesting files to understand. Each kernel has supporting files that are necessary to help get it loaded and up and running.

All of these explanations are rather simple — just enough to understand their function.

vmlinuz

The vmlinuz files are the Linux kernels. You can see that they are all about 16MB in size.

initramfs

The initramfs files are the initial boot images for each kernel. They are large compared to the kernel files because they contain not only the kernel, but also all the hardware modules necessary to load into memory, and basic system support such as hardware and filesystems to get the computer up and running enough to load the vmlinuz kernel and turn control over to it.

symvers

The symvers files are a map of system library versions, so that the running kernel can find the library it needs for particular function calls.

System.map

These files are, as their name implies, maps of where kernel symbols are located in RAM. This enables the kernel to easily locate functions identified by the symbols in the map.

config

The config files are a little different because they aren’t required to boot or run the system. They define the configuration of the kernels with variables used by the makefile during the kernel compilation. You could compile the kernel yourself and, using these configuration files, the result would be kernels identical to the ones already installed.

I’ve seen some software that requires the kernel to be compiled with one or more specific features included. You can use these configuration files to determine which features are compiled into the kernel you’re using.

memtest86+x64.efi

This program is a memory test. The GRUB menu has an entry for this tool so that it can be selected before the system boots up. Use this to test system memory without the kernel, other programs, and data taking up space that would prevent the most thorough test possible.

Final thoughts

Numbers such as the kernel contains 40 million lines of code are rather misleading since they don’t take into consideration other factors. Taking into account that the compiled kernel only contains those lines of code required for the target architecture and the specific features specified during the compile process, the actual number is far less.

Leave a Reply