Android Kernel Features
List of Kernel features unique to Android
See Greg KH blog post on -staging for 2.6.33, where he announces to remove various Android drivers from -staging.
- Binder - corba-like IPC
- Originally a feature in BeOS, Binder was a central construct for encapsulating software interfaces. One of the architects behind this mechanism was Dianne Hackborn, who is now a key employee at Android/Google. For more history see this interview.
- used instead of SysV IPC for interprocess communication
- The Linux version of Binder was originally derived from a project by PalmSource to implement a CORBA-like message-passing or method invocation system. Documentation on that system is at: http://www.angryredplanet.com/~hackbod/openbinder/docs/html/index.html
- implementation is at: drivers/android/binder.c, with include file: include/linux/binder.h
- ashmem - Android shared memory
- implementation is in mm/ashmem.c
According to the Kconfig help "The ashmem subsystem is a new shared memory allocator, similar to POSIX SHM but with different behavior and sporting a simpler file-based API."
Apparently it better-supports low memory devices, because it can discard shared memory units under memory pressure.
To use this, programs open /dev/ashmem, use mmap() on it, and can perform one or more of the following ioctls:
- PMEM - Process memory allocator
- implementation at: drivers/misc/pmem.c with include file at: include/linux/android_pmem.h
- Brian Swetland says:
The pmem driver is used to manage large (1-16+MB) physically contiguous regions of memory shared between userspace and kernel drivers (dsp, gpu, etc). It was written specifically to deal with hardware limitations of the MSM7201A, but could be used for other chipsets as well. For now, you're safe to turn it off on x86.
- logger - system logging facility
- This is the kernel support for the 'logcat' command
- The kernel driver for the serial devices for logging are in the source code drivers/android/logging.c
- See Android logger for more information
- wakelock - used for power management
- Holds machine awake on a per-event basis until wakelock is released
- See Android Power Management for detailed information
- oom handling modifications
- lowmem notifications
- implementation at: drivers/staging/android/lowmemorykiller.c
- also at: security/lowmem.c
Informally known as the Viking Killer, the OOM handler simply kills processes as available memory becomes low. The kernel module follows rules for this that are supplied from user space in two ways:
1. init writes information about memory levels and associated classes:
- The write value must be consistent with the above properties.
- Note that the driver only supports 6 slots, so we have combined some of the classes into the same memory level; the associated processes of higher classes will still be killed first.
- From /init.rc:
write /sys/module/lowmemorykiller/parameters/adj 0,1,2,4,7,15 write /sys/module/lowmemorykiller/parameters/minfree 2048,3072,4096,6144,7168,8192
2. User space sets the oom_adj of processes to put them in the correct class for their current operation. This redefines the meaning of oom_adj from that used by the standard OOM killer to something that is more aggressive and controlled.
These oom_adj levels end up being based on the process lifecycle defined here: http://developer.android.com/guide/topics/fundamentals.html#proclife
This is the kernel implementation to support Android's AlarmManager. It lets user space tell the kernel when it would like to wake up, allowing the kernel to schedule that appropriately and come back (holding a wake lock) when the time has expired regardless of the sleep state of the CPU.
paranoid network security
- paranoid network security
timed output / timed gpio
Generic gpio is a mechanism to allow programs to access and manipulate gpio registers from user space.
Timed output/gpio is a system to allow chaning a gpio pin and restore it automatically after a specified timeout. See drives/misc/timed_output.c and drives/misc/timed_gpio.c This expose a user space interface used by the vibrator code.
On ADP1, there is a driver at:
# cd /sys/bus/platform/drivers/timed-gpio # ls -l --w------- 1 0 0 4096 Nov 13 02:11 bind lrwxrwxrwx 1 0 0 0 Nov 13 02:11 timed-gpio -> ../../../../devices/platform/timed-gpio --w------- 1 0 0 4096 Nov 13 02:11 uevent --w------- 1 0 0 4096 Nov 13 02:11 unbind
Also, there is a device at:
# cd /sys/devices/platform/timed-gpio # ls -lR .: lrwxrwxrwx 1 0 0 0 Nov 13 01:34 driver -> ../../../bus/platform/drivers/timed-gpio -r--r--r-- 1 0 0 4096 Nov 13 01:34 modalias drwxr-xr-x 2 0 0 0 Nov 13 01:34 power lrwxrwxrwx 1 0 0 0 Nov 13 01:34 subsystem -> ../../../bus/platform -rw-r--r-- 1 0 0 4096 Nov 13 01:34 uevent ./power: -rw-r--r-- 1 0 0 4096 Nov 13 01:34 wakeup
This allows saving the kernel printk messages to a buffer in RAM, so that after a kernel panic they can be viewed in the next kernel invocation, by accessing /proc/last_kmsg.
[Would be good to get more details on how to set this up and use it here!] [I guess this is something like pramfs?]
other kernel changes
Here is a miscellaneous list of other kernel changes in the mistral Android kernel:
- switch events - drivers/switch/*
- USB gadget driver for ADB - drivers/usb/gadget/android.c
- yaffs2 flash filesystem
- support in FAT filesystem for FVAT_IOCTL_GET_VOLUME_ID
- RAM console
- and more...
Kernel configuration options
The file Documentation/android.txt has a list of required configuration options for a kernel to support an Android system.
- Peter McDermott's excellent description of his work to port Android to the Nokia N810.
- See http://www.linuxfordevices.com/c/a/Linux-For-Devices-Articles/Porting-Android-to-a-new-device/
- Also, see his annotated list of modified and added kernel files, at: http://www.linuxfordevices.com/files/misc/porting-android-to-a-new-device-p3.html
- Jollen Chen's excellent presentation on system-level Android features, including an overview of kernel features unique to Android: Note: Parts of the presentation are in Chinese
- Greg KH blogged on -staging for 2.6.33, where he announces to remove various Android drivers from -staging.