If you spend enough time around Android or even PCs, you’ll soon hear the term “Linux kernel.” Android also runs on the Linux kernel. In fact, it’s an important aspect of how your phone functions, but what exactly is it?
The “Linux” component is straightforward: it’s a pun on Linus and Unix, as in Linus Torvalds, the original designer of the Unix-like operating system we now name Linux. What about kernel? In computers and other devices, what is a kernel? What exactly is the Linux kernel? Let’s investigate!
A kernel is the core programme that manages your phone’s CPU resources, system memory, and system devices in a nutshell (including the file systems and networking). It’s also in charge of keeping track of all the processes and tasks operating on your phone. That is, when you start an app, the kernel loads the software into memory, creates the necessary processes, and launches the app. The kernel allocates RAM when an app requires it. The kernel handles all low-level processing when the programme requests networking.
A kernel is the programme that controls the CPU, memory, and system devices on your phone.
The Bluetooth driver is also included in the kernel. The kernel is in charge of background threads when an app needs to do something in the background. When an app is closed, the kernel cleans up all of the memory and other resources that the app consumed. As you can see, the kernel is a critical component that ensures your Android phone performs as expected.
What exactly is a kernel? A closer examination
A kernel exists in some form in all multitasking operating systems. A kernel is present in Windows, OS X, iOS, and, of course, Android. Only Android, however, uses the Linux kernel. Windows has its own kernel, known as the NT kernel, while OS X and iOS use the Darwin kernel.
Other kernels exist, including Unix-like kernels from the FreeBSD, OpenBSD, and NetBSD projects; real-time kernels from FreeRTOS; embedded kernels from Zephyr; and even low-power kernels from Arm, such as the mbed OS kernel. This means that a kernel is used by any computing device, from an IoT gadget or wearable to a supercomputer.
A kernel exists in some form in all multitasking operating systems.
The Linux kernel is a complicated programme. There are millions of lines of source code in it. This comprises all drivers (the vast majority of the code) as well as support for various system architectures (ARM, x86, RISC-V, PowerPC, etc). Not all of that source code is used when the kernel is produced for a specific device, like as a smartphone, but even when it is stripped away from what isn’t needed for a specific build, it is still complex.
Microkernel vs. monolithic
When it comes to constructing a kernel, there are a variety of ways that can be applied. A monolithic kernel is what the Linux kernel is called. This means the kernel is a single programme with a single memory region. The microkernel technique is the main alternative. The kernel’s necessities are placed in the smallest possible programme using microkernels, and they interface with other kernel-level programmes that run as separate servers or services.
Linus Torvalds and Professor Andrew Tanenbaum (renowned for his works on operating system design and networking) had an online debate (some say a flame war) regarding the advantages of monolithic kernel designs against microkernels back in 1992, when Linux was still in its infancy. Linus was writing a monolithic kernel, but Tanenbaum advocated microkernels. That is now history, as Linux, like the kernel used in Android, has stayed monolithic. Minix 3 is a Unix-like microkernel operating system worth checking out if you’re looking for anything similar.
OS Structure: Monolithic vs Microkernel
Because Linux is a monolithic kernel, you’ll need a mechanism to enable and disable specific sections of it based on your needs. This is accomplished throughout the compilation process, utilising a system that allows the kernel to be tweaked, trimmed, and customised as needed. Some of the options modify the kernel’s behaviour rather than just activating or deactivating certain functionalities. When it comes to designing and altering smartphone hardware features, this is helpful.
Because Linux is open-source, and the Android core is open-source thanks to the Android Open Source Project (AOSP), a community of developers and enthusiasts have created alternative kernels for Android smartphones. Their popularity and availability, however, are determined by the specific make and model of your device.
Android’s Linux usage
The developer preview screen for Android 12 shows Android version S.
On the surface, Android appears to be a decent launcher with a few programmes, such as the Chrome web browser or your social media apps, and possibly some games. However, there is more to this story than meets the eye. There are numerous subsystems, libraries, and frameworks beneath the user interface.
Android provides many libraries and frameworks for things like alerts, location services, fonts, web rendering, SSL, window management, and so on, so that programmes can run natively or in a Java Virtual Machine. There’s also a specific service called SurfaceFlinger that combines all of the different items that need to be drawn into a single buffer, which is then displayed on the screen.
The Android system architecture, which includes the application framework, system services, and the Linux kernel
The Linux kernel sits behind the Android-specific modules and frameworks. The Linux kernel comprises code for all of the numerous chip architectures and hardware drivers it supports, in addition to controlling processes, memory, and power management. Cameras, Bluetooth, Wi-Fi, flash memory, USB, and audio drivers are among them.
Android also modifies the Linux kernel in order to make it more appropriate for smartphones. Low Memory Killer, a process that checks memory state and reacts to high memory demands by killing the least critical processes while keeping the system functioning, and wake locks, a means for apps to inform the kernel that the device needs to stay on, are two examples.
To make the Linux kernel more appropriate for smartphones, Android adds additional functionality.
Project Treble, a re-architecture of Android that developed a well-defined interface between the OS framework and device-specific low-level applications, was released in Android 8.0. The SoC and board-specific drivers were separated from the main kernel using Linux kernel modules, allowing smartphone designers to focus on specialised functionality without affecting the core kernel. Treble was created to make it easier for smartphone manufacturers to upgrade their devices without having to worry about low-level code.
How do smartphone manufacturers modify the kernel
Because of the wide variety of Android devices, the kernel that runs on each make and model will differ slightly. There will be drivers for the SoC as well as other modules such as GPS and audio. Each smartphone manufacturer will collaborate with the SoC provider (Qualcomm, MediaTek, and others) to optimise the kernel for each model. This means that smartphone manufacturers will frequently work on device-specific features, override common kernel configurations, and add new Linux kernel drivers.
The CPU scheduling is a nice example of a common adjustment. A scheduler is used by the kernel to determine which task should run next and on which CPU core. The majority of Android smartphones are HMP (heterogeneous multi-processor) devices. This indicates that not all of the processor’s cores are created equal. Some are high-performance, while others are more eco-friendly. The kernel may estimate the influence of its actions on the amount of energy consumed by CPUs as well as the performance level available using the Energy-Aware Scheduler (EAS).
Every smartphone has its own kernel that is tailored to its specific hardware. Smartphone manufacturers can alter the EAS parameters to favour higher performance while using more energy, or lesser performance while conserving battery. Smartphone manufacturers can also replace the scheduler with one of their own design.
Every smartphone manufacturer works to configure the kernel in the best feasible way to enable all of the features required while providing the best possible performance and efficiency. Engineers collaborate alongside the SoC maker to fine-tune the software to get the most out of the hardware.
However, smartphone manufacturers are not immune to making mistakes or poor decisions when configuring the Linux kernel. In the aim of long battery life, OEMs have been known to adopt too harsh configurations. For example, OnePlus was detected limiting the performance of the OnePlus 9 Pro to save battery life, while others have been caught cheating and artificially boosting CPU speed during benchmarks.
The future of Android’s Linux kernel usage
One of the disadvantages of Linux’s success is that it evolves rapidly. Long Term Support (LTS) versions of the kernel are supported for several years to give a level of stability. The Android Common Kernels (ACKs) are changes for the Linux kernel that are particular to Android.
The ACKs are used to produce Generic Kernel Images starting with Android 11. (GKIs). These are 64-bit Arm kernels that can be used on any device with vendor-supplied SoC and driver support. The goal is to reduce kernel fragmentation by unifying the core kernel and transferring SoC-specific components out of the kernel and into loadable modules. As a result, OEMs will have less kernel maintenance to deal with, and hardware-specific components will be separated from the core kernel.
More about Hardware Stuffs
One of the disadvantages of Linux’s success is that it evolves rapidly.
Some devices with GKI kernels were released for the first time in Android 12. Google has committed to delivering signed boot images with major bug fixes on a regular basis. These images can be installed with no changes to vendor images due to the binary stability provided by the GKIs.
As a result, Google will be able to deploy newer Linux kernels for widespread use, which will assist to improve security and perhaps increase the number of years that a device receives updates and patches. Crossing my fingers.