46
The Android Linux Kernel (Part 3): Android Kernel Extensions Douglas C. Schmidt [email protected] www.dre.vanderbilt.edu/~schmidt Professor of Computer Science Institute for Software Integrated Systems Vanderbilt University Nashville, Tennessee, USA

The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

The Android Linux Kernel (Part 3):

Android Kernel Extensions

Douglas C. [email protected]

www.dre.vanderbilt.edu/~schmidt

Professor of Computer Science

Institute for Software

Integrated Systems

Vanderbilt University

Nashville, Tennessee, USA

Page 2: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

2

Learning Objectives in this Part of the Lesson1. Recognize the two types of storage

supported by Android Linux

2. Understand Android Linux’s local & remote communication mechanisms

3. Know how Android Linux’s processes& threads mediate access to one or more processor cores

4. Recognize extensions that Android Linux adds to the GNU Linux kernel

Page 3: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

3

Learning Objectives in this Part of the Lesson1. Recognize the two types of storage

supported by Android Linux

2. Understand Android Linux’s local & remote communication mechanisms

3. Know how Android Linux’s processes& threads mediate access to one or more processor cores

4. Recognize extensions that Android Linux adds to the GNU Linux kernel, e.g.

• Manage memory & power effectively on mobile devices

Page 4: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

4

Learning Objectives in this Part of the Lesson1. Recognize the two types of storage

supported by Android Linux

2. Understand Android Linux’s local & remote communication mechanisms

3. Know how Android Linux’s processes& threads mediate access to one or more processor cores

4. Recognize extensions that Android Linux adds to the GNU Linux kernel, e.g.

• Manage memory & power effectively on mobile devices

• Accelerate performance for local inter-process communication (IPC)

DownloadActivity

Client Process

IDownload.

Stub.Proxy

downloadImage()

initiateDownload()

DownloadService

Server Process

downloadImage()

IDownload.

Stub

Page 5: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

5

Android Linux Extensions: Memory Management

Page 6: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

6

Android Linux Extensions: Memory Management

C

• The Android Linux kernel manages primary storage efficiently for memory-constrained mobile devices

30%

Page 7: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

7

C

• GNU Linux kernel shields programmers from primary storage constraints

Android Linux Extensions: Memory Management

Page 8: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

8

C

• GNU Linux kernel shields programmers from primary storage constraints, e.g.

• Linux’s virtual memory manager allows applications to access an address space larger than RAM

See Part 1 of this lesson on “Overview of the Android Linux Kernel”

Android Linux Extensions: Memory Management

Page 9: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

9

C

• GNU Linux kernel shields programmers from primary storage constraints, e.g.

• Linux’s virtual memory manager allows applications to access an address space larger than RAM

• Swapping is used to automatically exchange the contents of primary storage with secondary storage

See stackoverflow.com/a/4420560/3312330

Android Linux Extensions: Memory Management

Page 10: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

10

C

• The Android Linux virtual memory manager behaves differently thanGNU Linux

Flash

Android Linux Extensions: Memory Management

Page 11: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

11

C

• The Android Linux virtual memory manager behaves differently thanGNU Linux

• e.g., to conserve power Android Linux doesn’t provide swap space for RAM

Flash

See developer.android.com/training/articles/memory.html#Android

Android Linux Extensions: Memory Management

Page 12: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

12See stackoverflow.com/a/17478535/3312330

C

• The Android Linux virtual memory manager behaves differently thanGNU Linux

• e.g., to conserve power Android Linux doesn’t provide swap space for RAM

Flash

RAM modified by an app is not written automatically

out to swap space

Android Linux Extensions: Memory Management

Page 13: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

13

C

• Android Linux defines a “low memory killer” extension

User Space

KernelSpace

See www.programering.com/a/MjNzADMwATE.html

Process CProcess BProcess A

100%

0%

MemoryLoad

Low

Memory

Killer

Android Linux Extensions: Memory Management

Page 14: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

14

C

• Android Linux defines a “low memory killer” extension

• Terminates app components when available RAM falls below a given threshold

Process CProcess BProcess A

User Space

KernelSpace

100%

0%

MemoryLoad

See www.programering.com/a/MjNzADMwATE.html

Low

Memory

Killer

Android Linux Extensions: Memory Management

Page 15: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

15

C

• App developers must know Android Linux kernel storage extensions

Flash

Android Linux Extensions: Memory Management

Page 16: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

16

C

• App developers must know Android Linux kernel storage extensions, e.g.

• Properly implement Activity & Service lifecycle methods

See www.vogella.com/tutorials/AndroidLifeCycle/article.html

Android Linux Extensions: Memory Management

Page 17: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

17

C

• App developers must know Android Linux kernel storage extensions, e.g.

• Properly implement Activity & Service lifecycle methods

• e.g., cleanup dynamically allocated resources in the onPause(), onStop(), & onDestroy() methods

See www.vogella.com/tutorials/AndroidLifeCycle/article.html

Android Linux Extensions: Memory Management

Page 18: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

18

C

• App developers must know Android Linux kernel storage extensions, e.g.

• Properly implement Activity & Service lifecycle methods

• Apply common Android idioms for managing app RAM

See developer.android.com/training/articles/memory.html

Android Linux Extensions: Memory Management

Page 19: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

19

C

• App developers must know Android Linux kernel storage extensions, e.g.

• Properly implement Activity & Service lifecycle methods

• Apply common Android idioms for managing app RAM

• e.g., use long-running servicessparingly & reduce size ofAndroid package kits (APKs)

See developer.android.com/topic/performance/reduce-apk-size.html

Android Linux Extensions: Memory Management

Page 20: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

20

C

• App developers must know Android Linux kernel storage extensions, e.g.

• Properly implement Activity & Service lifecycle methods

• Apply common Android idioms for managing app RAM

• Apply common Android tools for managing app RAM

See developer.android.com/topic/performance/memory.html#AnalyzeRam

Android Linux Extensions: Memory Management

Page 21: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

21

C

• App developers must know Android Linux kernel storage extensions, e.g.

• Properly implement Activity & Service lifecycle methods

• Apply common Android idioms for managing app RAM

• Apply common Android tools for managing app RAM

• e.g., Android Studio tools

See developer.android.com/studio/profile/investigate-ram.html

Android Linux Extensions: Memory Management

Page 22: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

22

C

• Android’s anonymous shared memory (ashmem) kernel extension allowsmultiple processes to share memory

See elinux.org/Android_Kernel_Features#ashmem

Client Process Server Process

VM Runtime VM Runtime

Shared

Memory

Mapped

Region

Mapped

Region

Android Linux Extensions: Memory Management

Page 23: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

23

Shared

Memory

C

• Android’s anonymous shared memory (ashmem) kernel extension allowsmultiple processes to share memory

• e.g., the Binder framework uses ashmem to optimize transfer of “blobs” by avoiding data copying

Client Process Server Process

libbinder libbinder

DownloadActivity

DownloadService

VM Runtime VM Runtime

Android Linux Extensions: Memory Management

Page 24: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

24See notjustburritos.tumblr.com/post/21442138796/an-introduction-to-android-shared-memory

C

• ashmem is targeted for mobile devices with limited RAM

Android Linux Extensions: Memory Management

Page 25: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

25

C

• ashmem is targeted for mobile devices with limited RAM, e.g.

• Shared memory regions can be discarded when RAM runs low

Shared

Memorylibbinder libbinder

DownloadActivity

DownloadService

VM Runtime VM Runtime

100%

0%

MemoryLoad

See notjustburritos.tumblr.com/post/21442138796/an-introduction-to-android-shared-memory

Android Linux Extensions: Memory Management

Page 26: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

26

C

• ashmem is targeted for mobile devices with limited RAM, e.g.

• Shared memory regions can be discarded when RAM runs low

• Memory allocated by ashmem isreleased when the process thatcreates it exits

Shared

Memorylibbinder libbinder

DownloadActivity

DownloadService

VM Runtime VM Runtime

See notjustburritos.tumblr.com/post/21442138796/an-introduction-to-android-shared-memory

Android Linux Extensions: Memory Management

Page 27: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

27

Android Linux Extensions: Power Management

Page 28: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

28

Android Linux Extensions: Power Management

C

• Android Linux provides kernel extensions& specialized device drivers tailored for the needs of mobile apps & services

Page 29: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

29

• Android Linux provides kernel extensions& specialized device drivers tailored for the needs of mobile apps & services

• e.g., mobile devices require kernel-level power management capabilities

C

See developer.android.com/training/monitoring-device-state

Android Linux Extensions: Power Management

Page 30: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

30

• Android Linux provides kernel extensions& specialized device drivers tailored for the needs of mobile apps & services

• e.g., mobile devices require kernel-level power management capabilities

• Common problems include keeping the screen on too long or running the CPU for extended periods of time

C

Android Linux Extensions: Power Management

Page 31: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

31

• Android Linux’s PowerManagement kernel extensions control when a device sleeps& wakes

C

See elinux.org/Android_Power_Management

Android Linux Extensions: Power Management

Page 32: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

32

C

• Android Linux’s PowerManagement kernel extensions control when a device sleeps& wakes

• Android middleware manages app power consumption via these kernel extensions

Android Linux Extensions: Power Management

Page 33: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

33

C

See developer.android.com/training/scheduling/wakelock.html

• Android Linux’s PowerManagement kernel extensions control when a device sleeps& wakes

• Android middleware manages app power consumption via these kernel extensions

• e.g., the PowerManager system service provides wake locks to apps that can’t sleep when they are idle

Android Linux Extensions: Power Management

Page 34: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

34

C

Examples include Google Maps navigation

• Android Linux’s PowerManagement kernel extensions control when a device sleeps& wakes

• Android middleware manages app power consumption via these kernel extensions

• e.g., the PowerManager system service provides wake locks to apps that can’t sleep when they are idle

Android Linux Extensions: Power Management

Page 35: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

35

Android Linux Extensions: Local Inter-Process

Communication

Page 36: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

36

C

• The TCP/IP protocol stack is designed for remote communication

Android Linux Extensions: Local IPC

Page 37: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

37

C

• The TCP/IP protocol stack is designed for remote communication

• e.g., handles network congestion via“slow start” & exponential back-offalgorithms

See en.wikipedia.org/wiki/TCP_congestion_control

Android Linux Extensions: Local IPC

Page 38: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

38

C

• TCP/IP incurs gratuitousoverhead when used forIPC between processes on a mobile device

• e.g., unnecessarychecksums & code that handles networkcongestion

DownloadService

Server Process

downloadImage()

IDownload.

Stub

DownloadActivity

Client Process

IDownload.

Stub.Proxy

downloadImage()

initiateDownload()

See bhavin.directi.com/unix-domain-sockets-vs-tcp-sockets

Android Linux Extensions: Local IPC

Page 39: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

39

C

• Android’s Binder driveris optimized for IPC on the same device

DownloadActivity

Client Process

IDownload.

Stub.Proxy

downloadImage()

initiateDownload()

DownloadService

Server Process

downloadImage()

IDownload.

Stub

See elinux.org/Android_Binder

Android Linux Extensions: Local IPC

Page 40: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

40

C

• Android’s Binder driveris optimized for IPC on the same device

• e.g. AIDL is used to invoke “remote” calls

DownloadActivity

Client Process

IDownload.

Stub.Proxy

downloadImage()

initiateDownload()

DownloadService

Server Process

downloadImage()

IDownload.

Stub

Android Linux Extensions: Local IPC

See developer.android.com/guide/components/aidl.html

Page 41: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

41

C

• Android’s Binder driveris optimized for IPC on the same device

• e.g. AIDL is used to invoke “remote” calls

DownloadActivity

Client Process

IDownload.

Stub.Proxy

downloadImage()

initiateDownload()

DownloadService

Server Process

downloadImage()

IDownload.

Stub

Android Linux Extensions: Local IPC

Page 42: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

42

C

• Android’s Binder driveris optimized for IPC on the same device

• e.g. AIDL is used to invoke “remote” calls

DownloadActivity

Client Process

IDownload.

Stub.Proxy

downloadImage()

initiateDownload()

DownloadService

Server Process

downloadImage()

IDownload.

Stub

Android Linux Extensions: Local IPC

Page 43: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

43

C

• Android’s Binder driveris optimized for IPC on the same device

• e.g. AIDL is used to invoke “remote” calls

DownloadActivity

Client Process

IDownload.

Stub.Proxy

downloadImage()

initiateDownload()

DownloadService

Server Process

downloadImage()

IDownload.

StubC

Android Linux Extensions: Local IPC

Binder driver is written in C/C++ & runs in the kernel to enhance performance

Page 44: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

44

C

• Android’s Binder driveris optimized for IPC on the same device

• e.g. AIDL is used to invoke “remote” calls

DownloadActivity

Client Process

IDownload.

Stub.Proxy

downloadImage()

initiateDownload()

DownloadService

Server Process

downloadImage()

IDownload.

StubC

Binder driver collaborates with higher-layer Binder framework written in Java

Android Linux Extensions: Local IPC

Java

Page 45: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

45

C

• Android’s Binder driveris optimized for IPC on the same device

• e.g. AIDL is used to invoke “remote” calls

DownloadActivity

Client Process

IDownload.

Stub.Proxy

downloadImage()

initiateDownload()

DownloadService

Server Process

downloadImage()

IDownload.

StubC

These layers of software simplify/optimizre object-oriented local IPC

Android Linux Extensions: Local IPC

Page 46: The Android Linux Kernel (Part 3): Android Kernel Extensionsschmidt/cs891f/2018-PDFs/L3-pt3... · 2018-12-04 · •Android Linux provides kernel extensions & specialized device drivers

46

End of the Android Linux Kernel (Part 3): Android

Kernel Extensions