Kernel is often decribed as The layer between hardware and software in a device. This is very much accurate but is not clear enough to understand for many people. Many people wonder What is Android Kernel exactly and What does Kernel do. Hence this Kernel thing needs some clarification to make.
What is Kernel?
Kernel means Core. It is like the nucleus of the Operating System. Kernel is the lowest level part of Operating System that “talks” to hardwares like camera, display, speaker, touch panel, phone or WiFi chips etc and controls them.
Every major Operating System has such a Kernel that is directly in connection with different hardwares and devices. All your smart devices, your phone, computer has a kernel of its own.
Android uses a Linux Kernel:
You may have heard that Android is based on Linux Kernel. That is very true but it doesn’t mean Android is Linux that is run on a computer. Linux has several OSes (called “distro”s) based on it, Ubuntu, Fedora, Kali Linux etc and they are closely related to each other. But Android, on the other hand, is completely different. It is made using different programming language and coded to run differenty. Thus, although a Linux package may run in different Linux distro but it won’t work on Android (unless ported). Here I will be discussing only about the Android Kernel.
What does it do?
Kernel does everything in order to run your device. It has complete control to everything that occurs in the system.
When an Android phone is first turned on, Bootloader is executed and it finds and runs the Android Kernel. Then Kernel loads the Rest of the Operating System and all its features so that you can use it normally.
The apps that you use on your phone do not have direct access to hardwares. The camera app does not directly talk to the camera sensor and shutter; the music app does not directly output the music playing through the speaker or headphone jack; instead, all apps and processes request kernel to send data to and recieve data from any hardware.
Kernel is in charge of managing and controlling every hardware from CPU, GPU to RAM, Storage Devices; from display, touchscreen to speaker, camera; from WiFi, Bluetooth chips to phone modem that is used to make phone calls, every single piece of hardware and device. Whenever an app requires access to hardware, it tells the kernel and kernel translats and submits that request to the corresponding device/hardware, and in turn, if a device needs to send some data to an app it passes that to the app through the Kernel. The operations of a Kernel. Source: Wikipedia
Also read: Android Bootloader and Fastboot explained. What are they Bootloader and Fastboot Mode and what they do?
How does it do that?
Kernel has all the privileges to control any devices. It does so with the help of Drivers. Drivers (also called “modules“) are extensions of kernel that enables the use of a piece of hardware by the kernel. Without proper driver for a device, kernel will not be able to communicate with that device.
If your computer has a WiFi chip but you do not have a wireless network driver, WiFi simply won’t work. Unlike Windows computers, the Linux Kernel inside Android OS has all the proper drivers installed so you can use your camera and microphone and touchscreen and other devices seamlessly.
But what I just described above is an over simplification of Kernel’s features. I feel the need to elaborate them as easily as below. And also what you can do to your kernel if you have root access. Its main functions can be broken into some catagories:
- Device Management:
Like I just said, Kernel is the middle man that connects hardware with software. Kernel also has its own language, called the API. If an app or a process needs access to a piece of hardware, it must know this language to talk to the Kernel. When the Kernel understands the request, it communicates with that intended piece of hardware via a proper driver. Lets break thinks down to simple examples.
- When you open the Camera app, the app does not immediately connect with the Camera module (the complete set of hardware required for camera) of your phone.
Instead, the app asks kernel that it needs to open the camera shutter and it also needs the camera feed. Kernel submits that request to camera module. The camera shutter is then opened, light hits the camera sensor and the sensor records the data and forwards that data to the camera app via kernel.
- I’d like one more commonly used example to bring here. Suppose you are using Nova Launcher and in the bottom left corner you have placed the dialer app. When you touch the dialer app icon, what happens is, kernel “listens” where you have touched.
Actually, the touchscreen panel is another hardware that the kernel manages. So when you touch on bottom left, the touch panel records that touch point and sends it to kernel. Kernel now tells the launcher the point of touch. The launcher calculates what is there in that location of touch, when it finds there is the dialer app, it opens the dialer.
There are several such steps for any action you make in your phone. But your the CPU in your phone is so fast, you don’t notice anything. You just see you touched the icon and it opened immediately.
- Process Management:
Process is an instance of a program. Whenever you run an app, it starts one or several processes.
Kernel manages the processes and controls where their resources go. It decides what process to keep where in memory: what to keep in foreground, what to push in background. If you are not using an app for some time, it is killed by the kernel because it thinks you don’t need this app right now. Also if an app or game is using a large amount of RAM, kernel may kill some background processes to run the app/game smoothly.
CPU and RAM management:
The phone’s processor: CPU and GPU, and RAM are just another pieces of hardwares and kernel is in charge of them too.
It determines the frequency at which the CPU/GPU should operate at different times in different conditions, how many cores to keep online and how to balance the load on the processor.
In the case of RAM, kernel determines how many processes and resources to keep in memory and where to keep them. Linux kernel has a built-in task manager (called the Low Memory Killer or LMK) that kills processes if free RAM is below some predefined value. If free RAM is going down, it can kill some apps based on this settings.
- Filesystem and I/O:
You got the filesystem part, it is how data is stored on storage like SD Card.
When you record a video or capture a photo, or download a song, kernel is in charge of storing that data properly into the storage devices available. It keeps(buffers certain amount of data first into RAM and then writes it eventually into the memory card (or internal memory). When a process asks for a file, it delivers this file.
I/O means Input-Output. There is millions of operations going on every single second inside your phone. This generates large amount of data that needs to be processed by the CPU or GPU. Kernel sorts that data based on priorities and sends them one by one to the processor via something called I/O Scheduler. The processor recieves and processes that data and outputs to destination via Kernel. It is Kernel’s responsibility to sort the data and enqueue them so that important tasks get finished first and Android runs smoothly.
what is android kernel and what does kernel do
Related: What is Recovery Mode in Android phones? What is Custom Recovery? Everything you need to know.
Those are hell massive amount of tasks assigned to the android kernel but you may always ask:
Why is there a need of Kernel?
Kernel is said to be the “brain” of an Operating System. But it is not mandatory for an operating system to have a kernel. Earlier OSes didn’t have kernel. Processes used to directly talk to hardware. But kernel makes lots of things easier. First of all, Kernel and its operations are run in Kernel Space (which is part of memory with high priority and less control to user). And the rest of Operating System and apps you use are run in User Space. Operations of Kernel are kept separate from anything else. And kernel does not let processes in user space access the hardware directly. This makes two improvements.
- Keep tasks organized:
without kernel, one process could consume lots of resources and keep them too busy to be used by other services. This would break the normal functionality of android. Tasks need to be organized properly and is done by kernel.
- Security reasons:
kernel runs apps in user space so no user process is directly in touch of the hardware. This keeps the hardware secure and malicious apps cannot abuse hardwares.
- Keeping apps small:
Whenever an app requires hardware level access, it just asks the kernel. Kernel does every job to fulfill that request. It loads the device specific driver and communicates with the device.
Without kernel, apps still could do it. But then they need to pack everything including the drivers to talk to the hardware.
As for the previous example, the launcher app would have to include drivers to listen to touch events and it would be much larger, because every phone has different touch panels, so in order to work on every phone, the launcher app had to include every variant of drivers and the app would be monstrously large. And if a new phone introduced a new kind of touchscreen, the app needed to be updated.
Instead, because the kernel exists, every app just packes the instructions to talk to the kernel via the API and kernel does the rest, translates the app’s command and send to hardware. This keeps things minimal and tidy and easier to build.
Rooting and tweaking the Android Kernel:
Rooting grants you system level permission and you can change kernel settings and its behavior. There are several apps but Kernel Adiutor is my favorite.
It lets you change the maximum and minimum frequency of CPU and GPU, or even overclock it like you do on your computer, adjust the frequency via CPU governors to balance between battery saving and performance. There are also settings to set different disc buffer size for better read-write speeds, configure the Low Memory Killer for smooth run, and change I/O Scheduler for better task handling.
Most of the stock android kernels are limited in these settings, so you may feel flashing a custom Kernel if available for your phone.
Beware before changing kernel settings, bad configuration can break your operating system and leave it useless. Search in Google and refer to XDA for any settings before modifying it.
Knowing the kernel may be greatly useful if you are looking forward to freely customize your phone to your needs. No other app that claims to improve performance or battery life can match the power of kernel. It is the overlord of everything inside your device. I tried to explain things as easily as possible but this turned out to be a really long and probably boring article. If you read it and got me missing something, feel free to drop your suggestions below.