The system layer of the Android system is built on Linux, with a Java Virtual Machine called Dalvik and an ART runtime environment added in the middle, and the Android runtime library on the surface. Each Android application runs in its own process, enjoying a dedicated instance allocated by the ART and Dalvik virtual machines. To support the efficient operation of multiple virtual machines on the same device, Dalvik has been rewritten.
The Dalvik virtual machine executes executable files in Dalvik format (.dex) — this format is optimized to minimize memory usage. The underlying functions — such as thread management and low memory management — rely on the Linux kernel. Thus, it can be said that Android is an operating system that runs on top of Linux, but it cannot be considered a version of Linux itself.
The differences between the Android kernel and the Linux kernel mainly manifest in 11 aspects, as follows:
1. Android Binder
The source code for Android Binder is located at drivers/staging/android/binder.c
Android Binder is a driver based on the OpenBinder framework, providing inter-process communication (IPC) for the Android platform.
The inter-process communication for applications on the Linux kernel is mainly through D-bus (Desktop bus), using a message bus approach for IPC.
2. Android Power Management (PM)
Android Power Management is a lightweight Android power management driver based on the standard Linux power management system, optimized for embedded devices. It uses locks and timers to switch system states, controlling device power consumption in different states to achieve energy savings.
The source code for Android Power Management is located at:
kernel/power/earlysuspend.c
kernel/power/consoleearlysuspend.c
kernel/power/fbearlysuspend.c
kernel/power/wakelock.c
kernel/power/userwakelock.c
Android version 5.0 will reference the JobScheduler scheduler, which increases device battery life to save power.
3. Low Memory Manager (Low Memory Killer)
The low memory manager in Android is more flexible compared to the standard OOM in Linux; it can kill processes as needed to free up required memory. The code for Low Memory Killer is quite simple, with a key function being Lowmem_shrinker. As a module, it registers a lowmem_shrinker during initialization, which is called by vm when memory is tight. Lowmem_shrinker is used to perform specific operations. Simply put, it finds the most suitable process to kill to free the memory it occupies.
The source code for the low memory manager is located at drivers/staging/android/lowmemorykiller.c
4. Anonymous Shared Memory (Ashmem)
Anonymous shared memory provides large shared memory for inter-process communication while offering mechanisms for the kernel to reclaim and manage this memory. If a program attempts to access a shared memory block released by the kernel, it will receive an error message and then reallocate memory and reload data.
The source code for anonymous shared memory is located at mm/ashmem.c
5. Android PMEM
PMEM is used to provide a contiguous physical memory area to user space; DSP and some devices can only operate on contiguous physical memory. The driver provides interfaces such as mmap, open, release, ioctl, etc.
The source code for Android PMEM is located at drivers/misc/pmem.c
6. Android Logger
Android Logger is a lightweight logging device used to capture various logs from the Android system, which is not available in Linux.
The source code for Android Logger is located at drivers/staging/android/logger.c
7. Android Alarm
Android Alarm provides a timer to wake the device from sleep mode, and it also offers a clock reference that runs even when the device is asleep.
The source code for Android Alarm is located at drivers/rtc/alarm.c and drivers/rtc/alarm-dev.c
8. USB Gadget Driver
The USB Gadget driver is a device driver based on the standard Linux USB gadget driver framework; Android’s USB driver is based on the gadget framework.
The source code for the USB Gadget driver is located at:
drivers/usb/gadget/android.c
drivers/usb/gadget/f_adb.c
drivers/usb/gadget/f_mass_storage.c
9. Android Console
To provide debugging functionality, Android allows debug log information to be written to a device called RAM Console, which is a RAM-based buffer.
The source code for Android RAM Console is located at drivers/staging/android/ram_console.c
10. Android Timed Device
Android timed device provides timing control functions for devices, currently only supporting vibrator and LED devices.
The source code for Android timed device is located at drivers/staging/android/timed_output.c (timed_gpio.c)
11. Yaffs2 File System
In the Android system, Yaffs2 is used as the MTD NAND Flash file system. Yaffs2 is a fast and stable cross-platform embedded device file system for NAND and NOR Flash. Compared to other Flash file systems, Yaffs2 uses less memory to maintain its operating state, thus occupying less memory; Yaffs2’s garbage collection is very simple and fast, achieving better performance; Yaffs2 performs particularly well on large-capacity NAND Flash, making it very suitable for large-capacity Flash storage.
The Yaffs2 file system is located at fs/yaffs2/.
【Recent Articles Recommended】
1.Free self-learning resources for programmers are all here!
2.What are the career development directions in the embedded field?
3.Comics: Conquering domestic famous company HR in one sentence
4.Interview sharing from Sohu, LeTV, Didi, NetEase, etc. in 2017
5.Let’s listen to a programmer’s song to relax!
6.What should an excellent programmer’s resume look like?
Reply with any number from “0-71” to view selected previous articles~
Scan the QR code3 seconds
Make friends with 100,000 programming experts
Daily content to satisfy you
(Remember to scan the QR code)
Or search for Huqing Yuanjian on WeChat to follow us
Free lectures | Content sharing | Programmer’s life | Employment recruitment
High-endITEmployment training expert
m.embedu.org