Android Kernel Issues
Android Kernel Issues
2008 Korea Android(www.kandroid.org)
CONTENTS
PART 1. Overview
PART 2. OpenBinder
PART 3. EABI
PART 4. Low Memory Killer
Date         Mar~13~2008, Thu (1300 ~ 1800)
Location     SeouI Samsung~Dong COEX(1fIoor Grand VoIume)
Presentator              - CTO - S/W Lab - Lim,GeunSik (geunsik.lim@samsung.com)
                 .
  Know-how             .
Overview 1.
PART 1. Overview
PART 2. OpenBinder
PART 3. EABI
PART 4. Low Memory Killer
4/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  1
License Related Android & OpenSource
Linux   IIands
DaIvik
Qemu
Openbinder Core
Ant
BSD Libc
OpenGL
OpenGL
SDL
KHTML
Expat
Python
SqIite3
D~BUS
SSL
zIib
  Openbinder System
Google (Skia) SGL
MIT Expat
GPL2 DBUS
GPL+BSD KHTML
LGPL KJS
LGPL WebCore
BSD (including 
LGPL)
Webkit
BSD  NetBSD C Library
SGI OpenGL 
(BSD/MPL) 
OpenGL
LGPL SDL
Apache ant
Python Python
GPL2 SQLite
GPL2 OpenBinder (Core)
Google 
(Apache)
Dalvik (JVM)
GPL2 QEMU Accelerator
GPL QEMU
GPL YAFFS2
GPL2 Linux Kernel
License OpenSource
What is Androids License? 
Currently, Android Platform is open source completely. The Android mobile OS 
will be released under Apache License. This means that anyone can customize 
the android platform and then keep it proprietary. 
5/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  1
Andr oi d Ker nel  Feat ur es
O  Needed 
   Option 
 init ramfs source ( To run /init - Exectuable Liking Format )
 Panic Timeout  ( To manage timout value when panic)
 Goldfish (Virtual Machine for QEMU based Emulator )
Emulator
Android Power Driver( for power management of goldfish )
 /dev/android_power
 Android  RAM Buffer Console ( for goldfish's audio )
Android USB Gadget ( Gadget based Android USB Driver)
 /dev/usb
Android Log Driver (Android Log Subsystem  to display log messages like logcat)
 /dev/log/{main:log:event}
Android
 Low Memory KiIIer ( To Manage process When Memory is low) Misc
 Touch-Screen Device drivers
O OpenBinder  ( For IPC between processes )  /dev/binder (251 ~ 253)    
O Frame Buffer (Device Driver)  /dev/fb0
O ARM EABI ( Embedded ABI )
Option KerneI Feature
6/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  1
What  i s Cr oss Compi l er  t o bui l d Ker nel ?
Select  Cross Compiler for ARM v6
Cross CompiIr for Android KerneI
 Sourcery G++ Lite Edition (CodeSourcery's version of the GNU Toolchain) 
 arm-2007q3-53-arm-none-eabi-i686-pc-linux-gnu.tar.bz2
 export  PATH=$PATH :<cross_compiler_install_path>/bin/
 Android Kernel: http://android.googlecode.com/files/linux-2.6.23-
android-m3-rc20.tar.gz
 We need opensource for toolchain like Kernel, gcc, glibc, bintuils
http://www.codesourcery.com/gnu_toolchains/arm/download.html
 Download the ARM 2007q3 Release 
 Select "ARM EABI, IA32 GNU /Linux  Option (Radio Box)" and Download
- Target Platform: ARM EABI
- Host Platform: IA32 GNU/Linux
- Source Code: Unchecked
 Default Floating Point : Soft-Float
 If you are want to compile hard-float option to enable VFP Instruciton, 
Use -mfpu=vfp -mfloat-abit=softfp
How to  get CodeSource Toolchain
7/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  1
How t o bui l d Ker nel  Sour ce f or  Andr oi d Pl at f or m
Get default  .config file from rootFS of anroid emulator.
fc6#> tar xzf linux-2.6.18-arm1136jf-s.armadillo-500.android.tar.gz 
fc6#> cd  linux-2.6.18-arm1136jf-s.armadillo-500
fc6#> cp ./arch/arm/configs/goldfish_defconfig ./.config  (GoldFish Config File)
fc6#> make ARCH=arm CROSS_COMPILE=arm_none-linux-gnueabi- menuconfig 
fc6#> make ARCH=arm CROSS_COMPILE=arm_none-linux-gnueabi- zImage
fc6#> make ARCH=arm CROSS_COMPILE=arm_none-linux-gnueabi- modules
fc6#> make ARCH=arm CROSS_COMPILE=arm_none-linux-gnueabi- modules_install
fc6#> cp ./arch/arm/boot/zImage /tftpboot/
fc6#> cp rf /lib/modules/ linux-2.6.18-arm1136jf-s.armadillo-500 
/tftpboot/target/lib/modules/
Build 2.6 Kernel Source
fc6#> <android_sdk_install_path>/tools/emulator console debug-kernel kernel kernel-qemu
fc6#> adb pull /proc/config.gz ./
fc6#> gunzip config.gz
fc6#> vi ./.config
OpenBinder 2.
PART 1. Overview
PART 2. OpenBinder
PART 3. EABI
PART 4. Low Memory Killer
9/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  2
What  i s OpenBi nder ?
OpenBinder?
A complete open-source solution supporting new kinds of 
component-based system-level design.
 Resource management between processes.
 Binder is system oriented rather than application oriented.
 Support a new kind of component-based system-level development.
 Component/object representations of various basic system services.
 Binder itself does not impose a particular threading model.
 The Binder has been used to implement a wide variety of commercial-quality system-
level services.
Openbiners History
OHA
OHA
1998 Binder is developed by BeOS.
2001 Palm Company acquired BeOS.
2001 Palms Micro Kernel is consist of Binder.
2004 netBSD Cobalt Kernel http://www.netbsd.org/ports/cobalt/
2005 Contributed by Palm(OHA Member) , 
2005 Google used Openbinder for android. 
(Not Opensource : graphics , user interface , multimedia ramework)
2007 Current BeOS (http://www.beosmax.org)
10/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  2
Why OpenBi nder ?
Hardware Scalability 
System Customization
Robust Applications
These platforms were designed to run on small handheld or dedicated devices, 
 The mobile device world tends to have a much broader range of hardware capabilities 
than is found on desktops.  size and battery life
 ability to run on anything from a 50MHz ARM 7 CPU (without memory protection) up to 
a 400MHz ARM 9 CPU and beyond.  burden on system software 
 Both hardware manufacturers and phone carriers want to deeply customize their 
behavior.
 it much easier to support this kind of customizability in a manageable way.
 Usage of the screen can become a significant problem for more complicated 
applications, such as web browsers. 
 Binder helps address this issue by making it easy for one application to sandbox other 
parts of itself. 
11/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  2
How t o Use OpenBi nder Dr i ver  i n Ker nel
make menuconfig & Device Node & Binding Example 
 Upper Omission.
VFS: Mounted root (ext3 filesystem).
Freeing init memory: 120K
init: HOW ARE YOU GENTLEMEN
init: reading config file
init: device init
init: mtd partition -1, 
init: mtd partition 0, "nor.bootl
init: mtd partition 1, "nor.kerne
init: mtd partition 2, "nor.userl
init: mtd partition 3, "nor.confi
init: mtd partition 4, "nand.ipl"
init: mtd partition 5, "nand.kern
init: mtd partition 6, "nand.user
init: mtd partition 7, "nand.free
sh: can't access tty; job control turned off
# 
binder_open(c3be4438 c053b500) (pid 1593) got c2c81000
binder_open(c3be4438 c35291e0) (pid 1605) got c19b8000
binder_open(c3be4438 c06a35a0) (pid 1640) got c0cff000
binder_open(c3be4438 c06a3c80) (pid 1642) got c0db9000
binder_open(c3be4438 c3519e40) (pid 1601) got c099f000
binder_open(c3be4438 c09f4ee0) (pid 1654) got c0a9b000
 Below Omission 
OpenBinder    Device Driver      ioctl  .
 Character Device is 251 ~ 253
 http//www.Ianana.org/docs/device~Iist/
   Android  Process(Thread)  binder
 IPC Mechanism . 
F
o
r
 
I
P
C
12/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  2
Map i nf o of  Googl e Map Pr ocess
dd
 What is IPC Mechenism of Android pIatform for MobiIe ? Both Openbinder and D~bus.
D~BUS
Ver0.95
OpenBinder 
Ver 0.8
System for sending messages between applications.
(Systemwide message-bus service) http://www.freedesktop.org/software/dbus/
Don't worry about processes or IPC  Because of distributed architecture.
Provides resource management between processes.
Handle on an object in another proces.
Powerful facilities for doing multithreaded programming with the Binder.
http://www.open-binder.org
<ps information on android platform>
root      1657 1 100512 24852 ffffffff afe0d204 S /system/bin/runtime
bluetooth 1658 1   1224   776 c00a34e8 afe0d07c S /system/bin/dbus-daemon
<./dbus-daemon/bus/>
activation.c, bus.c, config-loader-expat.c
config-parser.c, connection.c, desktop-file.c, 
dispatch.c, driver.c, expirelist.c, 
bus/policy.c, services.c, signals.c
13/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  2
How t o combi ne  Openbi nder  and Udev i n r oot FS
Priority of Created Thread in Android Kernel
target#> cd /etc/udev/rules.d/
target#> vi binderdev.rules
KERNEL=="binder*", NAME="%k", MODE="0666"
target#> vi /etc/autobinder.sh
# you almost certainly want to run this with sudo
depmod
modprobe binderdev
echo lsmod | grep binder
lsmod | grep binder
ls /dev/binder
 Do you want to use Dynamic User~space Device in your rootFS?
How to make udev ruIe 
target#> insmod binderdev.ko
target#> lsmod
Module                  Size      Used      by  Not tainted
binderdev             63152        0      - Live 0xbf000000
target#> mknod /dev/binder c 253 0
target#> /bin/chmod -R a+rw /dev/binder
How to make static /dev/ ruIe 
14/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  2
OpenBi nder
OpenBinder Ver 0.8 Package
make_strings [OPTIONS] strings.xml,  
pidgen [flags] foo.idl  Google Web APIs (http://api.google.com/search/beta2 SOAP RPC Router )
tools
Binder Process(loop) , Custom Package Manager , Custom Package Manager servers
Script Collection ( boot, process_wrapper , setup_env ) scripts
Sample Code ( Binder Component , Binder Based System Service , Service  Process , Binder Shell Script) samples
Core Openbinder system (Openbinder Kernel Module) moduIes
binder lib(arm,generic,x86) , binder_component_glue lib , binder_glue lib , dmprovider
lib(Schema)
libraries
Interface Definition Language ( app , package , services, storage, support) interfaces
Header files ( app, dmprovider, pacakage ,pacakge_p , services , storage , support support_p , xml , xml_p ) headers
Quick Start Manual (doxgen) docs
Kits, services (MemoryDealer) , tools (BinderShell , commands) components
3way, bomber , bsh commands
Makefiles collection 
(ex:All binder libraries , PackageNamespace [org.openbinder.tools],  PackageLeaf [BinderShell])
build_system
Description Name
http://www.mozilla.org/MPL/
 OpenBinder OS             , 
 Kernel       .
         , Kernel Module Build OpenBinder 
        Binder    IPC  .
15/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  2
OpenBi nder  Cont r i but or s
Main Role of Conrtibutor
Pi dgen.
j i t sai @al umni . uchi cago. edu
Jenny Tsai
Package manager ,  set t i ngs cat al og,  Bi nder  Shel l ,  dat a model ,  
por t  t o Li nux
j ason. par ks@pal msour ce. com
Jason Par ks
Gener al  desi gn,  XML par ser ,  BBi nder ,  mar shal l i ng and pi dgen.
j oeo@onor at o. or g
Joe Onor at o
SBuf f er ,  SBuf f er Chai n,  SBi t st r eamReader
em@gl i t chpop. net
Er i c Moon
Ini t i al  desi gn and i mpl ement at i on.  especi al l y of  Ibi nder /  
BBi nder ,  t he Bi nder kernel  modul e ,  gehnaphor es
(l i ght wei ght  l ocks),  SAt om,  SHandl er
geh@geor geandj ul i a. com
Geor ge Hof f man
Bi nder kernel  modul e (ver si ons 2 and 4).
ar ve. hj onnevag@pal msour ce. com
Ar ve H j & osl ash
Gener al  desi gn,  suppor t  cl asses,  SVal ue,  SLocker and SAt om
debuggi ng ,  dat a model ,  document at i on
hackbod@angr yr edpl anet . com
Di anne Hackbor n
Mar shal l i ng and pi dgen,  BCat al ogMi r r or
dance@acm. or g
John Dance
Li nux Bi nder modul e,  IMemor y,  Memor y Deal er .
t r ey. boudr ea@pal msour ce. com
Tr ey Boudr eau
Por t  of  user -space code t o Li nux.
kennet h. al banowski @pal msour ce. co
m
Kennet h Al banowski
Rol e E-mai l Aut hor
(Cont r i but or )
16/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  2
Cor e OpenBi nder  Syst em
File List
i/o buffer Structure  45 Iobuf f er . h
Init, Read Raw, Write Raw, Drain, Remaining, Consumed, Remainder 112 Iobuf f er . c
binder_transaction Structure 128 bi nder . t r ansact i on. h
Transaction Init , Transaction Dtor , Transacton Debug Dump, Transaction Create, 
Transaction Destroy, Transaction ReleaseTarget
542 bi nder _t r ansact i on. c
binder_thread Structure 154 bi nder-t hread. h
Thread Cleanup , Thread WaitForReply , Thread WaitForRequest, Thread Return 
Transaction, Thread init , Thread GloablCount , Thread Released , Thread Die , 
Thread AttachProcess, Thread Wakeup , Thread Sync, Thread Write, Thread Read , 
Etc
1, 576 bi nder_t hread. c
Descriptor Sturcture , Reverse_mapping Structure, Local_mapping Structure, 
Range_map Structure, Death_notification Structure, binder_proc Structure
227 bi nder _pr oc. h
Process init , Process Spawn Looper , Process wakeup timer , process idle timer , 
set_thread_priority , Process Stop , Process Destroy , Process Die , Process 
AddThread , Process RemoteThread , Process Transact , Process FreeBuffter , Etc
2, 216 bi nder _pr oc. c
Binder nodes Structure
71 bi nder _node. h
Node Global, Node Init , Node AcquireHome, Node Send , Node Destroy 141 bi nder _node. c
cmpxchg32 , compare_and_swap32 341 bi nder -def s. h
open, mmap , release , ioctl, unlocked ioctl 692 bi nder . c
Description Li ne Fi l e Name
http://www.gnu.org/copyleft/gpl.html/
17/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  2
Thr ead s Pr i or i t y bi ndi ng t o t he OpenBi nder
Priority of Created Thread in Android Kernel
static void setthreadpriority(pid_t thread, int priority)
{// Android Kernels Scheduling is Dynamic Priority(=Normal Priority ) to schedule between threads.
int nice;
// The following must match SysThreadChangePriority in libbinder.
if(priority >= 80)  Worse Priority or low priority ( map 80..100 to 0..19)
{  nice = priority - 80;
if(nice > 19)
nice = 19;
}
else                    Better priority or High Priority ( map 0..79 to -20..-1)
{ nice = priority-3 - 80; 
nice /= 4;
}
//printk(*invains DEBUG: set_thread_priority tid %d pri %d == nice %dn", thread, priority, nice);
set_user_nice(find_task_by_pid(thread), nice);
} 
 Do you need ReaItime Characterestics for MobiIe?
 Why does nobody taIked about the characteristics of reaI~time kerneI androids not?
 We can use  PreemptibIe KerneI for ReaItime in KerneI Space, But  UserSpace ReaItime?
 We Implement Userspace Realtime Application  with Locked Mutex Method (FUTEX)
(Ex: Priority Queuing , Priority Inheritance , Robust Mutex )
A
p
p
s
 
L
a
t
e
n
c
y
A
p
p
s
 
T
h
r
o
u
g
h
p
u
t
EABI (Embedded Application Binary Interface) 3.
PART 1. Overview
PART 2. OpenBinder
PART 3. EABI
PART 4. Low Memory Killer
19/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  3
What  i s EABI?
EABI(Embedded Application Binary Interface) 
It sets the standard for the interoperation between relocated files, as well as executable 
files, for embedded architectures.
the standard makes it possible to combine object files built using different toolchains if 
both their compilers use EABI.  
GCC  : CS-2005Q3 release is a modified version of gcc-3.4.4 from gcc-4.1.0 
The commercial ARM RealView C/C++ compiler was the first to support EABI (GCC4.1)
Kernel: EABI is supported in the ARM Linux kernel from version 2.6.16.
Glibc : Earlier glibcs (2.3.3) support EABI userspace but had old-style syscalls to work 
with older kernels (2.6.8-2.6.15). 
Compatability with ARMv5t processors and above (for GCC 4.2). 5
More efficient syscall convention. ( Ref1) 4
More compatibility with various development tools. 3
Better structure packing capabilities. 2
Ability to mix soft and hardfloat code.  (GCC 4.2: --with-fpu=vfp --with-float=softfp) 1
Features No
- http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ihi0036a/
ARM Information Center 
Ref 1) Experience showed that those syscall wrappers can not cover all the needed ABI mismatch since some of 
them are simply hidden from the C library, especially with specialized applications like iptables for example.
The effective features for arm-linux users with the use of EABI are 
20/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  3
Ext endi ng t he ARM Pr ocessor  Por t f ol i o
Android
Continued licensing of both mature and new technology
Cortex-A9 Ecosystem  EDA, OS and Software companies supporting Cortex-A9
21/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  3
Ar ch & CPU i nf or mat i on of  GCC about  andr oi d
 Upper Omission 
{"armv4t",  arm7tdmi,   "4T",  FL_CO_PROC |        FL_FOR_ARCH4T, NULL},
{"armv5",   arm10tdmi,  "5",   FL_CO_PROC |           FL_FOR_ARCH5, NULL},
{"armv5t",  arm10tdmi,  "5T",  FL_CO_PROC |           FL_FOR_ARCH5T, NULL},
{"armv5e",  arm1026ejs, "5E",  FL_CO_PROC |           FL_FOR_ARCH5E, NULL},
{"armv5te", arm1026ejs, "5TE", FL_CO_PROC |           FL_FOR_ARCH5TE, NULL},
{"armv6",   arm1136js,  "6",   FL_CO_PROC |             FL_FOR_ARCH6, NULL},
{"armv6j",  arm1136js,  "6J",  FL_CO_PROC |             FL_FOR_ARCH6J, NULL},
{"armv6k",  mpcore, "6K",  FL_CO_PROC |             FL_FOR_ARCH6K, NULL},
{"armv6z",  arm1176jzs, "6Z",  FL_CO_PROC |             FL_FOR_ARCH6Z, NULL},
{"armv6zk", arm1176jzs, "6ZK", FL_CO_PROC |             FL_FOR_ARCH6ZK, NULL},
{"armv6t2", arm1156t2s, "6T2", FL_CO_PROC |             FL_FOR_ARCH6T2, NULL},
{"armv7",   cortexa8, "7",   FL_CO_PROC | FL_FOR_ARCH7, NULL},
{"armv7-a", cortexa8, "7A",  FL_CO_PROC | FL_FOR_ARCH7A, NULL},
{"armv7-r", cortexr4, "7R",  FL_CO_PROC | FL_FOR_ARCH7R, NULL},
{"armv7-m", cortexm3, "7M",  FL_CO_PROC | FL_FOR_ARCH7M, NULL},
{"ep9312",  ep9312,     "4T",  FL_LDSCHED | FL_CIRRUS | FL_FOR_ARCH4, NULL},
{"iwmmxt",  iwmmxt,     "5TE", FL_LDSCHED | FL_STRONG | FL_FOR_ARCH5TE | FL_XSCALE | FL_IWMMXT , NULL},
{NULL, arm_none, NULL, 0 , NULL}
};
 Upper Omission 
{"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
{"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
{"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
{"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
http://gcc.gnu.org/svn/gcc/branches/gcc-4_3-branch/gcc/config/arm/arm.c
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-arm.c?cvsroot=src
22/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
The common gcc command options that are available for EABI are
Part  3
Cr oss Compi l er  f or   EABI
ARM syscall entry convention
EABI user space binaries put the syscall number into r7 and use swi 0 to call the kernel. 
Syscall register arguments are also expected to have EABI arrangements , that is, 64-
bit arguments should be put in a pair of registers from an even register number.
Example ARM sycall entry convention with long ftruncate64 (unsigned int fd, loff_t
length.
Follow the EABI requirement of always creating a frame pointer whenever 
a stack frame is allocated. This option is enabled by default and can be 
disabled with -mno-linked-fp. 
-mlinked-fp
Generate position-independent EABI code. -mlibrary-pic
Specify both -mcall-sysv and -mno-eabi options. -mcall-sysv-noeabi
Specify both -mcall-sysv and -meabi options. -mcall-sysv-eabi
Generate code for the given ABI. -mabi=eabi
Description GCC Option
23/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
 put fd into r0
 put length into r1-r2
 use swi #(0x900000 + 194) to call the kernel
Legacy ABI
EABI
Compatibility
Part  3
Legacy ABI vs.  EABI
ExectuabIe Binary
EABI
 put fd into r0
 put length into r2-r3 (skipping over r1)
 put 194 into r7
 use swi 0" to call the kernel
It is important to use 0 for the swi argument because backward compatibility with legacy ABI 
userspace relies on this. The syscall macros in asm-arm/unistd.h were also updated to 
support both ABIs and implement the right call method automatically.
13 #ifndef __ASM_ARM_UNISTD_H
14 #define __ASM_ARM_UNISTD_H
15 #define __NR_OABI_SYSCALL_BASE  0x900000
16 #if defined(__thumb__) || defined(__ARM_EABI__)
17 #define __NR_SYSCALL_BASE       0
18 #else
19 #define __NR_SYSCALL_BASE       
__NR_OABI_SYSCALL_BASE
20 #endif
./include/asm-arm/unistd.h
fc6#> arm_v5t_le-objdump -xlD vmlinux | less
private flags = 602: [APCS-32] [VFP float format] 
[software FP] [has entry point]
fc6#> arm_v5t_le-objdump -xlD vmlinux | grep less
or arm_v5t_le-objdump -xlD /tftpboot/target/init | less 
private flags = 4000002: [Version4 EABI] [has entry point]
24/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  3
Legacy ABI vs.  EABI
* ABI flags passed to binutils: -mabi=apcs-gnu -mfpu=fpa
* gcc -dumpmachine: arm-unknown-linux
* objdump -x for compiled binary:
abi #>obj dump - xl D vml i nux |  l ess
pr i vat e f l ags = 602:  [ APCS- 32]  [ VFP f l oat  f or mat ]  [ sof t war e FP]  [ has ent r y poi nt ]
* "file" on compiled Fedora binary
ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.20, 
dynamically linked (uses shared libs), for GNU/Linux 2.4.20, stripped
Toolchain
& 
Binary
* ABI flags passed by gcc to binutils:
-mabi=aapcs-linux -mfloat-abi=soft -meabi=4
* gcc -dumpmachine: arm-unknown-linux-gnueabi
* objdump -x for compiled binary:
eabi #> obj dump - xl D vml i nux |  gr ep l ess
pr i vat e f l ags = 4000002:  [ Ver si on4 EABI]  [ has ent r y poi nt ]
* "file" on compiled binary (under Fedora)
ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.18, 
dymically linked(uses shared libs), for GNU/Linux 2.6.18, stripped
Toolchain
& 
Binary
Legacy ABI
New EABI
25/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  3
Cr oss Compi l er  f or   EABI
Is it possible to run both EABI and non-EABI binaries on the same system? 
EABI    . 
Yes, it is possible. However, running a dual-ABI system requires care. If you have an old-ABI system, and 
want to run EABI binaries, you have several choices. One option is to link your programs statically, using the 
-static option. However, linking dynamically is generally a superior approach. Generally, toolchains use a 
different dynamic loader (ld.so.3), so it is possible for old-ABI and EABI binaries to coexist. However, you will 
have to ensure that when you install the EABI libraries you do not overwrite existing libraries, and you will have 
to set LD_LIBRARY_PATH so that the dynamic loader can find them. 
 Support EABI Feature
make menuconfig  Kernel Features  [*]Use the ARM EABI to compile the kernel
26/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  3
If  EABI i s not  suppor t ed i n your  ker nel ?
For example, Your kernel is 2.6.15- . So You need EABI Feature.
32 arm-eabi-syscall-adjstments 16
arm_eabi_syscalls_compat_hack 31 arm-eabi-syscalls 15
arm_mempolicy_syscalls_compat_hack 30 arm-eabi-helper-func-names 14
arm-oabi-struct-sockaddr_un 29 arm-eabi-sp-align-2 13
arm-oabi-is-experimental 28 arm-eabi-sp-align-1 12
arm-nptl-compat-mb 27 arm-eabi-slab-align-to-64bits 11
arm-eabi-sigreturn-fix 26 arm-eabi-relocs-for-modules 10
arm-oabi-kconfig 25 arm_mno-thumb-interwork 9
arm-oabi-nwfpe 24 arm-fix-sys_sendto-and-sys_recvfrom-6-arg 8
arm-oabi-multi-abi 23 slab-add-more-arch-override 7
arm-oabi-syscall-wrappers 22 arm-optimized-libc-functions 6
arm-oabi-statfs64 21 arm-remove-udivdi3-from-kernel 5
arm-mempolicy-syscalls 20 arm-remove-udivdi3-from-nwfpe 4
arm-inotify-ioprio.syscalls 19 mmc-remove-ref-to-divdi3 3
arm-update-syscall-table 18 arm-remove-udivdi3-from-pxafb 2
arm-eabi-kconfig 17 use_mtune_arm1136j-s_for_ARMv6_targets 1
On any ARM toolchain (v5t_le, xscale_le), in the Processor Features area, the following new freatures need to 
be set  EABI. 
Low Memory Killer 4.
PART 1. Overview
PART 2. OpenBinder
PART 3. EABI
PART 4. Low Memory Killer
28/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  4
What  i s Low Memor y Ki l l er ?
Why Google develop Low Memory Killer without OOM?
TargetBoard       , OOM(Out Of Memory)   
 ,            Process  
 Kill Android       .  
      Low Memory Killer  udev  Kill  
. 
   .
printk: 8 messages suppressed.
oom-killer: gfp_mask=0x201d2, order=0
Mem-info:
DMA per-cpu:
cpu 0 hot: high 18, batch 3 used:12
cpu 0 cold: high 6, batch 1 used:2
DMA32 per-cpu: empty
Normal per-cpu: empty
HighMem per-cpu: empty
Free pages:        1436kB (0kB HighMem)
Active:6717 inactive:1641 dirty:0 writeback:0 unstable:0 free:359 slab:1458 mapped:61 pagetables:1700
DMA free:1436kB min:1024kB low:1280kB high:1536kB active:26868kB inactive:6564kB present:65536kB pages_scanned:14954 all_unreclaimable? no
lowmem_reserve[]: 0 0 0 0
DMA32 free:0kB min:0kB low:0kB high:0kB active:0kB inactive:0kB present:0kB pages_scanned:0 all_unreclaimable? no
lowmem_reserve[]: 0 0 0 0
Normal free:0kB min:0kB low:0kB high:0kB active:0kB inactive:0kB present:0kB pages_scanned:0 all_unreclaimable? no
lowmem_reserve[]: 0 0 0 0
HighMem free:0kB min:128kB low:128kB high:128kB active:0kB inactive:0kB present:0kB pages_scanned:0 
all_unreclaimable? no
lowmem_reserve[]: 0 0 0 0
DMA: 51*4kB 26*8kB 4*16kB 0*32kB 1*64kB 1*128kB 1*256kB 1*512kB 0*1024kB 0*2048kB 0*4096kB = 1436kB
DMA32: empty
Normal: empty
HighMem: empty
Swap cache: add 0, delete 0, find 0/0, race 0+0
Free swap  = 0kB
Total swap = 0kB
Out of Memory: Kill process 908 (udevd) score 122 and children.
Out of memory: Killed process 1922 (udev).
Free swap:            0kB
16384 pages of RAM
2623 free pages
924 reserved pages
1458 slab pages
279 pages shared
0 pages swap cached
    . 
 lowmem_reserver   kernel-2.6/mm/page_alloc.c 
show_free_areas( )   for_each_zone()  
29/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  4
OOM ( Out  of  Memor y )  Ki l l er
oom~kiIIer: gfp_mask=0x201d2, order=0
[<c0144b11>] out_of_memory+0x25/0x144
[<c0145fa7>] __alloc_pages+0x1f5/0x275
[<c0147117>] __do_page_cache_readahead+0xc8/0x1e8
[<c01162e5>] __wake_up_common+0x2f/0x53
[<c0116755>] __wake_up+0x2a/0x3d
[<c014420e>] filemap_nopage+0x151/0x30b
[<c014c731>] __handle_mm_fault+0x24e/0x705
[<c01248a3>] do_gettimeofday+0x31/0xce
[<c011554e>] do_page_fault+0x18a/0x46c
[<c01153c4>] do_page_fault+0x0/0x46c
[<c01037d5>] error_code+0x39/0x40
Mem-info:
DMA per-cpu:
cpu 0 hot: high 0, batch 1 used:0
. Below Omission .
Free pages:       21472kB (340kB HighMem)
. Below Omission .
OOM Example
 Kernel Messages Analysis: This is caused by DMA 
problem. Physical HDDs Problem? In fact , This Memory 
Allocation Policy Related Problem.
Case1) Program is allocating memory continually.
while (1) {
if (malloc(1<<50) == NULL) {
printf("malloc failure after %d MiBn", n);
return 0; }
printf ("Got %d Mbn", ++n);
}
Case2) Program allocate memory, and use memory 
immediately. 
while (1) {
if ((Temp = malloc(1<<50)) == NULL) {
printf("malloc failure after %d MiBn", n);
return 0;}
memset (p, 0, (1<<50));
printf ("Got %d Mbn", ++n);
}
Case3) Allocate needed memory using for(), Use 
allocated memory using for().
for (n = 0; num < 50,000 ; n++) {
temp[num] = malloc(1<<50);
if (temp[num] == NULL)
break;
}
printf("malloc failure after %d MiBn", n);
for (i = 0; i < num; i++) {
memset ( pp[i], 0, (1<<50) );
printf("Got %d Mbn", i+1);
}
Kenrle Messages When OOM
I
f
 
f
a
i
I
 
m
e
m
a
I
I
o
c
a
t
i
o
n
,
 
p
r
o
g
r
a
m
 
e
x
i
t
.
I
f
 
f
a
i
I
 
m
e
m
a
I
I
o
c
a
t
i
o
n
,
 
p
r
o
g
r
a
m
 
e
x
i
t
.
C
a
s
e
 3
O
O
M
  k
ille
r
in
it
P
ro
c
e
s
s
M
e
m
o
ry
 U
s
a
g
e
S
c
o
re
 
s
u
p
e
ru
s
e
r
P
ro
c
e
s
s
H
a
rd
w
a
re
A
c
c
e
s
s
P
ro
c
e
s
s
1
/4
S
c
o
re
P
ro
c
e
s
s
K
ill
.
Guide for Embedded Memory Programming
 What Every Programmer Should Know About Memory 
 Understanding The Linux Virtual Memory manager
 Understanding  Virtual Memory in Red Hat Enterprise 
Linux 4
30/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  4
Andr oi d Appl i cat i on  s Li f e Cycl e 1/ 2
How do we make Applications life cycle in Mobile/Embedded? 
          
      . ,     ?  
            
    . 
empty         .   
          (startup)    
 .  ,    empty       
         .
Empty
(Unlimited)
background      Activity  .   
      . activity      , 
  3               . 
      ,         
        LRU   .
Background
(64M)
service  startService()    Service    .  
   ,        , 
 foreground visibile      ,     
  . 
Serivce
(16M)
visible     foreground   Activity  .  
 foreground activity       activity     
 .            , 
foreground      .
Visible
(8M)
foreground         Activity   
IntentReceiver   .        ,  
         .     
  ,         .
Foreground
(6M)
Description
(Free Mem)
http://code.google.com/android/intro/lifecycle.html
Higher
Lower
31/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
Part  4
Andr oi d Appl i cat i on  s Li f e Cycl e 2/ 2
Why Applications life cycle is important in android platform?
         (, 
Activity, Service,  IntentReceiver)      .  
   ,          
     .       IntentReceiver
onReceveIntent()  Intent         . 
   ,  IntentReceiver     ,   
     . (,       
  ) ,           . 
             
   IntentReceiver  Service   .
Maps Service
  ,      , Android  
        " " .
32/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
.
Part  4
Ker nel  Modul e f or  Low Memor y Ki l l er
Location of Low memory killer 
./kernel-2.6/misw/lowmemorykiller/
Iowmemshrink()
lowmem_print()
module_param_named()
module_param_array_named()
module_param_array_named()
module_param_named()
lowmem_init()
lowmem_exit()
shrinker lowmem_shrinker Structure
lowmemorykiller.c
Make file to build Lowmemorykiller.ko kernel module Makefile
Description File Name
Process    ,  Process        
  . 
Process    Activity, Service,  IntentReceiver     
         code.google.com   . 
33/ 34
software stack for mobile devices (Android)
2008 Korea 
Android 
.
Part  4
About  Andr oi d s l ow memor y shr i nk t ask
 Iowmemshrink()
if(nr_to_scan > 0)
lowmem_print(3, "lowmem_shrink %d, %x, ofree %d, ma %dn", nr_to_scan, gfp_mask, other_free, min_adj);
read_lock(&tasklist_lock);
foreachprocess(p) {
if(p->oomkilladj >= 0 && p->mm) {
tasksize = get_mm_rss(p->mm);
if(nr_to_scan > 0 && tasksize > 0 && p->oomkilladj >= min_adj) {
if(selected == NULL ||
p->oomkilladj > selected->oomkilladj ||
(p->oomkilladj == selected->oomkilladj &&
tasksize > selected_tasksize)) {
selected = p;
selected_tasksize = tasksize;
lowmem_print(2, "select %d   (%s),     adj %d,      size %d  , to killn",
p->pid,    p->comm, p->oomkilladj, tasksize);
}
}
rem += tasksize;
}
}
if(selected != NULL) {
lowmem_print(1, "send sigkill to %d (%s), adj %d, size %dn",
selected->pid, selected->comm,
selected->oomkilladj, selected_tasksize);
forcesig(SIGKILL, seIected)
rem -= selected_tasksize;
}
lowmem_print(4, "lowmem_shrink %d, %x, return %dn", nr_to_scan, gfp_mask, rem);
read_unlock(&tasklist_lock);
return rem;
* static size_t lowmem_minfree[6]={
3*512,   // 6MB = 3 x 5123 x 4
2*1024,  // 8MB = 2 x 1024 x 4
4*1024,  // 16MB= 4 x 1024 x 4
16*1024, // 64MB = 16x1024 x 4  };
* Default lowmem_debug_level is 2. 
 If you want to debug , use 3+ value
Linux Cross Reference WebTool  http://lxr.linux.no/linux
34/ 34
software stack for mobile devices (Android)
2008 Korea 
Android