Do you know what a Linux kernel is? What is its application in Android, why is it necessary in Android and how can it strengthen the performance of Android phones? In this article, we will answer these questions and tell you everything you need to know about the kernel and its different types.
Have you ever heard of the word Linux kernel? Android also uses the Linux kernel. In fact, the Android kernel, also known as the Android kernel, is an important part of the Linux operating system and has a very important effect on the performance of your phone; But what is a kernel?
The word Linux is easy to understand. In fact, the word Linux is a combination of the two words linus and Unix. Linus actually refers to Linus Torvalds, a software engineer, and Unix is the name of a software. Linus Torvalds is the name of the Unix operating system software engineer; But what is a kernel? What is the meaning of kernel in computers and other devices? What is the meaning of Linux kernel?
The kernel manages components such as the phone’s CPU resources, system memory, some of its hardware, and other items such as system files and network-related processes. The kernel is also responsible for managing all processes and tasks (tasks) running on smartphones.
In fact, when you run an application, this part of Android loads the application into memory, performs the required processing activities, and finally runs the application; In other words, when the application needs memory space, the kernel provides the required space, or when the application needs a network, the kernel performs low-level processing for this process.
The kernel is also responsible for directing and managing devices such as the phone’s Bluetooth and is considered the driver of these devices. When an application wants to perform tasks in the background of the operating system, it manages all the background strings (in the background strings, processing activities are performed in the background of the operating system, such as computational operations on input information received by the user).
In addition, after the user closes the application, the kernel clears all the information stored in memory and the resources that the application was using while running. As you can see, the kernel is an essential part of Android and was created with the goal of providing flawless performance for the phone’s operating system exactly as the user expects.
Take a closer look at the kernel
All operating systems that support multitasking and can perform multiple tasks simultaneously have one or more different forms of kernel; So operating systems like Windows, OS X and iOS and of course Android have kernels; Of course, only Android uses the Linux kernel. Windows has another kernel called the NT kernel, and iOS uses the Darwin kernel.
Of course, there are a variety of other types of kernels, including Unix-like kernels such as kernels used in FreeBSD, OpenBSD, and NetBSD projects, real-time kernels such as FreeRTOS projects, embedded kernels in projects such as Zephyr, and kernel kernels. OS with ARM architecture pointed out. In fact, all computing devices use the kernel; From IoT devices and wearable gadgets to supercomputers.
The kernel is a complex part of the operating system that contains millions of lines of source code. The contents of the kernel include all the drivers (most of the kernel code is related to the drivers) as well as the code needed to support various architectures including ARM, x86, RISC-V, PowerPC and so on.
It should be noted that when a kernel is created for a device such as a smartphone, not all of the code in it is used by the device; Of course, even if we separate those unnecessary codes that are not used from the kernel, it is still a complex part.
Comparison of Monolithic kernel with microkernel
Naturally, all complex systems are designed with different approaches, and the kernel is no exception. The Linux kernel is commonly known as the monolithic kernel. In fact, the monolithic kernel is an approach according to which the kernel is a computer program that uses a dedicated memory. The main alternative to the monolithic kernel approach is the microkernel approach; According to which the core parts of the kernel are placed in the smallest possible program and interact with other kernels that are used to run a separate service or services.
In 1992, when the newly created Linux was created, Linus Torvalds and Professor Andrew Tanenbaum, best known for writing operating system and networking kernels, had a heated online discussion (actually a struggle) that compared The design parameters were different from the monolithic kernel design with the microkernel parameters. Andrew preferred microkernels; But Linus was writing a monolithic kernel. For this reason, Linux as well as the kernel used in Android is a monolithic kernel and has not changed from the beginning.
Because Linux is a monolithic kernel; Therefore, there must be a way to enable or disable specific parts of the kernel to suit the needs of the user. This is possible during the compilation process by a system that allows the kernel to configure, delete unnecessary code, and configure.
Changes made by some configurations go beyond activating or deactivating activities, and they also have the ability to change kernel behaviors. Such a feature is a useful and practical feature when changing the hardware features of the smartphone. Since Linux is open source and the Android kernel is of this nature thanks to the Android Open Source Project (AOSP), a community of Android developers and enthusiasts has been created in which different kernels are released for Android phones; Of course, the popularity and availability of these published kernels depends on the brand and model of your phone.
How Android uses Linux
In appearance, Android is an operating system with popular applications such as Google Chrome for browsing, social networking apps and games, but this operating system has a complex structure and behind it there are many subsystems, libraries and frameworks.
Android provides many libraries and frameworks when running applications (either directly from the operating system itself or from the Java machine) to perform tasks such as displaying notifications, positioning services, rendering web pages, providing SSL, managing windows, and more. In addition, in the Android operating system, there is a special service called SurfaceFlinger, which is responsible for creating and collecting all the necessary items for displaying graphics on the phone screen.
In fact, the system kernel is a subset of Android-specific frameworks and libraries, and in addition to managing processes, memory, and processing power, it contains the code needed for the various chip architectures and hardware drivers that the main device supports. These drivers include camera drivers, bluetooth, wifi, flash memory, USB ports, and audio drivers.
In contrast to Android, it adds features to the Linux kernel that make it more suitable for Android phones. One of these features is the Low Memory Killer feature. This feature is created to check the memory status and clear the most insignificant data and processes to provide the required space. Creating this feature will allow the system to run without any problems and will not cause any problems in the Wake Lock process. Wake Lock is actually a way that applications can use to let the kernel know which hardware should stay active.
8 Android Treble projects were introduced in Android. This project is actually a re-creation of the Android architecture that creates a well-defined relationship between the operating system framework and the proprietary low-level software of each device. Based on the basics of this project, the on-chip system (SoC) and device-specific drivers are separated from the main kernel using Linux kernel modules.
Such a feature helps phone makers to work on specific features without having to change the core kernel. In fact, the Trebl project was created to help handset makers make it easier to update their handsets without worrying about low-level code.
How to change the kernels by Android phones
Due to the very high variety of Android phones, the kernel used in each of the Android phones with brand and model is slightly different. Each phone has dedicated drivers for components such as the on-chip system as well as other modules such as GPS, audio and more.
All handset makers partner with chip makers such as Qualcomm and MediaTek to configure the kernel to optimize it to the best of its ability for a particular model phone. This means that phone makers are making changes to common kernel configurations and adding new drivers to the Linux kernel.
A change in the CPU scheduler is a good example of a kernel change. The kernel uses the CPU scheduler when it has to decide which task to run next and in which kernel to run. Many Android phones are heterogeneous multi-processor (HMP) systems; In other words, not all the cores used in the processor of these phones are the same, and some of them have higher performance and some of them are less consuming. Using an Energy-Aware Scheduler (EAS), the kernel can predict the impact of its conclusions on CPU energy consumption as well as the level of performance available.
Manufacturers of handsets can improve the performance of the handset by increasing the energy consumption by changing the parameters of the energy conscious timer, or conversely, by reducing the level of performance, reduce the power consumption of the phone and thus increase its battery life. Phone makers can also replace the operating system timer with a timer they designed and created.
Each of the handset makers tries to optimize the kernel configuration in the best possible way so that it is possible to use all the desired features with the best performance and the lowest possible energy consumption. Some handset engineers, with the participation of active engineers in chip companies, try to customize the phone’s software and operating system to make the most of its hardware.
Of course, phone makers do not make mistakes when it comes to configuring the Linux kernel or making bad decisions about it; But sometimes they take unreasonable measures to preserve or even increase the battery life of the phone; For example, in order to maintain the battery life of OnePlus 9 Pro, OnePlus has reduced its performance level and deliberately reduced the speed of some applications in it significantly. Other companies also have a reputation for deceiving their customers, and when testing their phones with benchmarks, they artificially increase their CPU performance.
The future of using the Linux kernel in Android
One of the downsides of Linux is its rapid change; Of course, to create the right level of stability, you can use versions of the kernel with Long Term Support (LTS) that can be supported for several years. Android Common Kernels, also known as Android Common Kernels or AKCs, are derived from the original Linux kernel and include Android-specific folders.
With the release of Android 11, the use of shared Android kernels to create generic kernel images (GKIs) began. They can be used on any device.
The purpose of using these kernels is to solve the problem of kernel fragmentation by integrating the main kernel and moving the main parts of the system on the chip out of the water kernel and transferring them to loadable modules. Although this removes specific hardware components from the core kernel, it does reduce the strain on kernel maintenance for handset makers.
With the release of Android 12, the release of a number of devices with Generic Kernel Images began. Google is also committed to releasing boot.img file images on a regular basis and fixing the most important bugs. Because public kernel images are highly stable, they can be installed on hardware-specific drivers without any changes.
This could pave the way for Google to release newer Linux kernels for public use. In addition, such an improvement, in turn, can increase the security of phones and increase the length of time to support the phone to release new software updates and fix bugs.