SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
Memory ManagementMemory Management
in Androidin Android
AnDevCon Boston 2016
CC-BY-SA 3.0 - Attribution requirements and misc., PLEASE READ:
This slide must remain as-is in this specific location (slide #1), everything else you are free to change;
including the logo :-)
Use of figures in other documents must feature the below "Originals at" URL immediately under that
figure and the below copyright notice where appropriate.
You are FORBIDDEN from using the default "About" slide as-is or any of its contents.
Copyright (C) 2014-2016, Opersys inc.
These slides created by: Karim Yaghmour
Originals at: http://www.opersys.com/training/
AboutAbout
Introduced Linux Trace Toolkit in 1999
Originated Adeos and relayfs (kernel/relay.c)
Ara Android Arch Oversight
Training, Custom Dev, Consulting, ...
"Note that memory usage on modern operating systems like Linux is an extremely complicated and
difficult to understand area. In fact the chances of you actually correctly interpreting whatever
numbers you get is extremely low. (Pretty much every time I look at memory usage numbers with
other engineers, there is always a long discussion about what they actually mean that only results in
a vague conclusion.)"
-- Dianne Hackborn, Feb 19, 2010, Stackoverflow
AgendaAgenda
Architecture Recap1.
Kernel's overall role2.
Kernel driver interfaces3.
Kernel user-space interfaces4.
Low-memory conditions5.
Bionic6.
App Dev Considerations7.
Tools8.
Misc.9.
References10.
Demo HardwareDemo Hardware
Nexus 7 (Flo 2013)
Qualcomm Snapdragon S4 Pro -- APQ8064
Krait CPU, 4-core, 1.51 GHz, 2MB L2 cache
2 GB on-board DDR3 (PCDDR 533MHz)
16 GB eMMC
Combined power/usb
Architecture RecapArchitecture Recap
AOSP
System startup
Memory layout
1. AOSP1. AOSP
2. System startup2. System startup
3. Memory layout3. Memory layout
Kernel's overall roleKernel's overall role
Manage physical memory
Manage virtual-to-physical mappings
Process isolation:
Protect the hardware from user-space
Protect processes from each other
Driver capabilities:
Memory-mapped registers
DMA
MTD maps
Filesystem cache
File mapping
Swapping
InternalsInternals
Architecture-independent:
Architecture-specific:
Per-task struct (include/linux/sched.h):
The memory structures (include/linux/mm_types.h):
mm/
arch/arm/mm/
struct task_struct {
...
struct mm_struct *mm, *active_mm;
...
struct mm_struct {
struct vm_area_struct * mmap; /* list of VMAs */
struct rb_root mm_rb;
struct vm_area_struct * mmap_cache; /* last find_vma result */
Kernel driver interfacesKernel driver interfaces
Memory-mapped registers
DMA
MTD maps
ION
Kernel user-space interfacesKernel user-space interfaces
brk
mmap/munmap
Low-memory conditionsLow-memory conditions
OOM killer
oom_adj
Android low-mem driver
oom_adj set during init
Modifications to oom_adj at runtime by framework
BionicBionic
malloc()/free()
Comes from Doug Lea's dlmalloc
Public Domain
See bionic/libc/upstream-dlmalloc/
Tutorial/doc:
Dates back to 1987
Uses CALL_MORECORE() macro do allocations
Based on sbrk()
dlopen()/dlsym()
http://g.oswego.edu/dl/html/malloc.html
https://en.wikipedia.org/wiki/C_dynamic_memory_allocation
Flags to debug/observe malloc/free Linux
Enable native monitoring by DDMS:
Open ~/.android/ddms.cfg
Add line stating: "native=true"
$ adb shell setprop libc.debug.malloc 1
$ adb shell stop
$ adb shell start
App Dev ConsiderationsApp Dev Considerations
Recommendations given by Google
Measuring app mem usage
Getting system mem usage
android.os.Debug
android:largeHeap="true"
https://developer.android.com/training/articles/memory.html
https://developer.android.com/reference/android
/app/ActivityManager.html#getProcessMemoryInfo%28int[]%29
public MemoryInfo[] getProcessMemoryInfo (int[] pids)
https://developer.android.com/reference/android
/app/ActivityManager.html#getMemoryInfo%28android.app.ActivityManager.MemoryInfo%29
public void getMemoryInfo (ActivityManager.MemoryInfo outInfo)
ToolsTools
Kernel
Native
Dalvik/ART
Framework
8.1 Kernel8.1 Kernel
Overall memory use
Physical-mapped reg address ranges
FS cache
"fragmentation"
/proc interface
RSS, VSS, USS, PSS, etc.
/proc/[pid]/maps, semantics of
8.2 Native8.2 Native
dumpstate
librank
procrank
procmem
showmap
tombstones
debuggerd
core files
8.3 ART/Dalvik8.3 ART/Dalvik
Heap size measurement
API in apps to get access to heap size from Runtime
Memory Monitor / Studio (no compare?)
MAT / Eclipse
dalvik.vm.heapsize
https://developer.android.com/reference
/java/lang/Runtime.html#maxMemory%28%29
public long maxMemory ()
8.4. Framework8.4. Framework
dumpsys meminfo
dumpsys procinfo
Misc.Misc.
DDOS on memory
KitKat efforts for low-mem
Security aspects
HAL use of mmap
Swap space?
zMAP
ION
CMA
ReferencesReferences
developer.android.com
source.android.com
strong/weak/soft/phantom references wrt Java GC: -
-
-->
http://source.android.com/devices/native-memory.html
http://source.android.com/devices/low-ram.html
https://developer.android.com/tools/debugging/debugging-memory.html
https://developer.android.com/training/articles/memory.html
http://android-developers.blogspot.com/2011/03/memory-analysis-for-android.html
http://android-developers.blogspot.com/2009/02/track-memory-allocations.html
https://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-
in-android
http://elinux.org/Android_Memory_Usage
https://www.youtube.com/watch?v=_CruQY55HOk
http://blog.yojimbocorp.com/2012/10/03/view-android-application-memory-usage-with-eclipse-
ddms-plugin/
https://lwn.net/Articles/480055/
https://lwn.net/Articles/565469/
https://weblogs.java.net/blog/2006/05/04
/understanding-weak-references http://docs.oracle.com/javase/7/docs/api/java/lang/ref/package-
summary.html
Thank You!Thank You!
karim.yaghmour@opersys.com

Más contenido relacionado

La actualidad más candente

Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Opersys inc.
 
Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UIOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowOpersys inc.
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things InternalsOpersys inc.
 
Running Code in the Android Stack at ABS 2014
Running Code in the Android Stack at ABS 2014Running Code in the Android Stack at ABS 2014
Running Code in the Android Stack at ABS 2014Opersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in AndroidOpersys inc.
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android WorkshopOpersys inc.
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Opersys inc.
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security InternalsOpersys inc.
 
Is Android the New Embedded Linux? at AnDevCon VI
Is Android the New Embedded Linux? at AnDevCon VIIs Android the New Embedded Linux? at AnDevCon VI
Is Android the New Embedded Linux? at AnDevCon VIOpersys inc.
 
Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIInside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIOpersys inc.
 
Android Security, From the Ground Up
Android Security, From the Ground UpAndroid Security, From the Ground Up
Android Security, From the Ground UpOpersys inc.
 
Android's Multimedia Framework
Android's Multimedia FrameworkAndroid's Multimedia Framework
Android's Multimedia FrameworkOpersys inc.
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in AndroidOpersys inc.
 
Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UIOpersys inc.
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Opersys inc.
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Opersys inc.
 

La actualidad más candente (20)

Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
 
Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UI
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with Marshmallow
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things Internals
 
Running Code in the Android Stack at ABS 2014
Running Code in the Android Stack at ABS 2014Running Code in the Android Stack at ABS 2014
Running Code in the Android Stack at ABS 2014
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in Android
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android Workshop
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security Internals
 
Is Android the New Embedded Linux? at AnDevCon VI
Is Android the New Embedded Linux? at AnDevCon VIIs Android the New Embedded Linux? at AnDevCon VI
Is Android the New Embedded Linux? at AnDevCon VI
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIInside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VI
 
Android Security, From the Ground Up
Android Security, From the Ground UpAndroid Security, From the Ground Up
Android Security, From the Ground Up
 
Android's Multimedia Framework
Android's Multimedia FrameworkAndroid's Multimedia Framework
Android's Multimedia Framework
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in Android
 
Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UI
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013
 

Destacado

Brillo / Weave Internals
Brillo / Weave InternalsBrillo / Weave Internals
Brillo / Weave InternalsOpersys inc.
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things InternalsOpersys inc.
 
Linux内存管理
Linux内存管理Linux内存管理
Linux内存管理zijia
 
Memory Usage in Android
Memory Usage in AndroidMemory Usage in Android
Memory Usage in AndroidPrashanth Nani
 
Introduction to Android by Demian Neidetcher
Introduction to Android by Demian NeidetcherIntroduction to Android by Demian Neidetcher
Introduction to Android by Demian NeidetcherMatthew McCullough
 
Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014Opersys inc.
 
Leveraging Android's Linux Heritage at AnDevCon VI
Leveraging Android's Linux Heritage at AnDevCon VILeveraging Android's Linux Heritage at AnDevCon VI
Leveraging Android's Linux Heritage at AnDevCon VIOpersys inc.
 
Developing Android Platform Tools
Developing Android Platform ToolsDeveloping Android Platform Tools
Developing Android Platform ToolsOpersys inc.
 
Embedded Android Workshop at AnDevCon VI
Embedded Android Workshop at AnDevCon VIEmbedded Android Workshop at AnDevCon VI
Embedded Android Workshop at AnDevCon VIOpersys inc.
 
Embedded Android Workshop at Embedded World 2014
Embedded Android Workshop at Embedded World 2014Embedded Android Workshop at Embedded World 2014
Embedded Android Workshop at Embedded World 2014Opersys inc.
 
Extending Android's Platform Toolsuite
Extending Android's Platform ToolsuiteExtending Android's Platform Toolsuite
Extending Android's Platform ToolsuiteOpersys inc.
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android WorkshopOpersys inc.
 
Android Microconf at Linux Plumber 2012
Android Microconf at Linux Plumber 2012Android Microconf at Linux Plumber 2012
Android Microconf at Linux Plumber 2012Opersys inc.
 
Embedded Android Workshop at ABS 2014
Embedded Android Workshop at ABS 2014Embedded Android Workshop at ABS 2014
Embedded Android Workshop at ABS 2014Opersys inc.
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android WorkshopOpersys inc.
 
Embedded Android Workshop at Embedded World Conference 2013
Embedded Android Workshop at Embedded World Conference 2013Embedded Android Workshop at Embedded World Conference 2013
Embedded Android Workshop at Embedded World Conference 2013Opersys inc.
 
Embedded Android Workshop with Lollipop
Embedded Android Workshop with LollipopEmbedded Android Workshop with Lollipop
Embedded Android Workshop with LollipopOpersys inc.
 

Destacado (20)

Brillo / Weave Internals
Brillo / Weave InternalsBrillo / Weave Internals
Brillo / Weave Internals
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things Internals
 
Linux内存管理
Linux内存管理Linux内存管理
Linux内存管理
 
Memory Usage in Android
Memory Usage in AndroidMemory Usage in Android
Memory Usage in Android
 
ANDROID APP LAUNCH
ANDROID APP LAUNCHANDROID APP LAUNCH
ANDROID APP LAUNCH
 
Anatomy of an android
Anatomy of an androidAnatomy of an android
Anatomy of an android
 
Introduction to Android by Demian Neidetcher
Introduction to Android by Demian NeidetcherIntroduction to Android by Demian Neidetcher
Introduction to Android by Demian Neidetcher
 
Linux memory
Linux memoryLinux memory
Linux memory
 
Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014
 
Leveraging Android's Linux Heritage at AnDevCon VI
Leveraging Android's Linux Heritage at AnDevCon VILeveraging Android's Linux Heritage at AnDevCon VI
Leveraging Android's Linux Heritage at AnDevCon VI
 
Developing Android Platform Tools
Developing Android Platform ToolsDeveloping Android Platform Tools
Developing Android Platform Tools
 
Embedded Android Workshop at AnDevCon VI
Embedded Android Workshop at AnDevCon VIEmbedded Android Workshop at AnDevCon VI
Embedded Android Workshop at AnDevCon VI
 
Embedded Android Workshop at Embedded World 2014
Embedded Android Workshop at Embedded World 2014Embedded Android Workshop at Embedded World 2014
Embedded Android Workshop at Embedded World 2014
 
Extending Android's Platform Toolsuite
Extending Android's Platform ToolsuiteExtending Android's Platform Toolsuite
Extending Android's Platform Toolsuite
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android Workshop
 
Android Microconf at Linux Plumber 2012
Android Microconf at Linux Plumber 2012Android Microconf at Linux Plumber 2012
Android Microconf at Linux Plumber 2012
 
Embedded Android Workshop at ABS 2014
Embedded Android Workshop at ABS 2014Embedded Android Workshop at ABS 2014
Embedded Android Workshop at ABS 2014
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android Workshop
 
Embedded Android Workshop at Embedded World Conference 2013
Embedded Android Workshop at Embedded World Conference 2013Embedded Android Workshop at Embedded World Conference 2013
Embedded Android Workshop at Embedded World Conference 2013
 
Embedded Android Workshop with Lollipop
Embedded Android Workshop with LollipopEmbedded Android Workshop with Lollipop
Embedded Android Workshop with Lollipop
 

Similar a Memory Management in Android

Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in AndroidOpersys inc.
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in AndroidOpersys inc.
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in AndroidOpersys inc.
 
Us 18-chen-keen lab-ios-jailbreak-internals
Us 18-chen-keen lab-ios-jailbreak-internalsUs 18-chen-keen lab-ios-jailbreak-internals
Us 18-chen-keen lab-ios-jailbreak-internalsLiang Chen
 
KeenLab iOS Jailbreak Internals: Userland Read-Only Memory can be Dangerous
KeenLab iOS Jailbreak Internals: Userland Read-Only Memory can be DangerousKeenLab iOS Jailbreak Internals: Userland Read-Only Memory can be Dangerous
KeenLab iOS Jailbreak Internals: Userland Read-Only Memory can be DangerousPriyanka Aash
 
Reliability, Availability and Serviceability on Linux
Reliability, Availability and Serviceability on LinuxReliability, Availability and Serviceability on Linux
Reliability, Availability and Serviceability on LinuxSamsung Open Source Group
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in AndroidOpersys inc.
 
Android on Intel Architecture: ROM Cooking Tutorial
Android on Intel Architecture: ROM Cooking TutorialAndroid on Intel Architecture: ROM Cooking Tutorial
Android on Intel Architecture: ROM Cooking TutorialRon Munitz
 
Chromium os architecture report
Chromium os  architecture reportChromium os  architecture report
Chromium os architecture reportAmr Abd El Latief
 
Memory Management in TIZEN - Samsung SW Platform Team
Memory Management in TIZEN - Samsung SW Platform TeamMemory Management in TIZEN - Samsung SW Platform Team
Memory Management in TIZEN - Samsung SW Platform TeamRyo Jin
 
OSSEU17: How Open Source Project Xen Puts Security Software Vendors Ahead of ...
OSSEU17: How Open Source Project Xen Puts Security Software Vendors Ahead of ...OSSEU17: How Open Source Project Xen Puts Security Software Vendors Ahead of ...
OSSEU17: How Open Source Project Xen Puts Security Software Vendors Ahead of ...The Linux Foundation
 
Ov psim demo_slides_power_pc
Ov psim demo_slides_power_pcOv psim demo_slides_power_pc
Ov psim demo_slides_power_pcsimon56
 
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...Ron Munitz
 
Lec9chap8f04
Lec9chap8f04Lec9chap8f04
Lec9chap8f04screaminc
 

Similar a Memory Management in Android (20)

Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
 
Us 18-chen-keen lab-ios-jailbreak-internals
Us 18-chen-keen lab-ios-jailbreak-internalsUs 18-chen-keen lab-ios-jailbreak-internals
Us 18-chen-keen lab-ios-jailbreak-internals
 
KeenLab iOS Jailbreak Internals: Userland Read-Only Memory can be Dangerous
KeenLab iOS Jailbreak Internals: Userland Read-Only Memory can be DangerousKeenLab iOS Jailbreak Internals: Userland Read-Only Memory can be Dangerous
KeenLab iOS Jailbreak Internals: Userland Read-Only Memory can be Dangerous
 
淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道 淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道
 
Memory management in linux
Memory management in linuxMemory management in linux
Memory management in linux
 
Reliability, Availability and Serviceability on Linux
Reliability, Availability and Serviceability on LinuxReliability, Availability and Serviceability on Linux
Reliability, Availability and Serviceability on Linux
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
 
Android on Intel Architecture: ROM Cooking Tutorial
Android on Intel Architecture: ROM Cooking TutorialAndroid on Intel Architecture: ROM Cooking Tutorial
Android on Intel Architecture: ROM Cooking Tutorial
 
Chromium os architecture report
Chromium os  architecture reportChromium os  architecture report
Chromium os architecture report
 
Memory Management in TIZEN - Samsung SW Platform Team
Memory Management in TIZEN - Samsung SW Platform TeamMemory Management in TIZEN - Samsung SW Platform Team
Memory Management in TIZEN - Samsung SW Platform Team
 
OSSEU17: How Open Source Project Xen Puts Security Software Vendors Ahead of ...
OSSEU17: How Open Source Project Xen Puts Security Software Vendors Ahead of ...OSSEU17: How Open Source Project Xen Puts Security Software Vendors Ahead of ...
OSSEU17: How Open Source Project Xen Puts Security Software Vendors Ahead of ...
 
Ov psim demo_slides_power_pc
Ov psim demo_slides_power_pcOv psim demo_slides_power_pc
Ov psim demo_slides_power_pc
 
Building
BuildingBuilding
Building
 
Ram Disk
Ram DiskRam Disk
Ram Disk
 
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
 
Walking around linux kernel
Walking around linux kernelWalking around linux kernel
Walking around linux kernel
 
Lec9chap8f04
Lec9chap8f04Lec9chap8f04
Lec9chap8f04
 
Xen io
Xen ioXen io
Xen io
 

Más de Opersys inc.

Android Automotive
Android AutomotiveAndroid Automotive
Android AutomotiveOpersys inc.
 
Android 10 Internals Update
Android 10 Internals UpdateAndroid 10 Internals Update
Android 10 Internals UpdateOpersys inc.
 
Embedded Android Workshop with Pie
Embedded Android Workshop with PieEmbedded Android Workshop with Pie
Embedded Android Workshop with PieOpersys inc.
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALOpersys inc.
 
Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?Opersys inc.
 
Embedded Android Workshop with Oreo
Embedded Android Workshop with OreoEmbedded Android Workshop with Oreo
Embedded Android Workshop with OreoOpersys inc.
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with NougatOpersys inc.
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with NougatOpersys inc.
 
Android Things: Android for IoT
Android Things: Android for IoTAndroid Things: Android for IoT
Android Things: Android for IoTOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with NougatOpersys inc.
 
Brillo / Weave Internals
Brillo / Weave InternalsBrillo / Weave Internals
Brillo / Weave InternalsOpersys inc.
 
Brillo/Weave Internals
Brillo/Weave InternalsBrillo/Weave Internals
Brillo/Weave InternalsOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowOpersys inc.
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowOpersys inc.
 

Más de Opersys inc. (18)

Android Automotive
Android AutomotiveAndroid Automotive
Android Automotive
 
Android 10 Internals Update
Android 10 Internals UpdateAndroid 10 Internals Update
Android 10 Internals Update
 
Embedded Android Workshop with Pie
Embedded Android Workshop with PieEmbedded Android Workshop with Pie
Embedded Android Workshop with Pie
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 
Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?
 
Embedded Android Workshop with Oreo
Embedded Android Workshop with OreoEmbedded Android Workshop with Oreo
Embedded Android Workshop with Oreo
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
 
Android Things: Android for IoT
Android Things: Android for IoTAndroid Things: Android for IoT
Android Things: Android for IoT
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
 
Brillo / Weave Internals
Brillo / Weave InternalsBrillo / Weave Internals
Brillo / Weave Internals
 
Project Ara
Project AraProject Ara
Project Ara
 
Brillo/Weave Internals
Brillo/Weave InternalsBrillo/Weave Internals
Brillo/Weave Internals
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with Marshmallow
 
Project Ara
Project AraProject Ara
Project Ara
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with Marshmallow
 

Último

What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdfSteve Caron
 
Key Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapKey Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapIshara Amarasekera
 
Understanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptxUnderstanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptxSasikiranMarri
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Effort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsEffort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsDEEPRAJ PATHAK
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfkalichargn70th171
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxAS Design & AST.
 
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...kalichargn70th171
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxRTS corp
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 

Último (20)

What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
 
Key Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapKey Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery Roadmap
 
Understanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptxUnderstanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptx
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Effort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsEffort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software Projects
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptx
 
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptx
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 

Memory Management in Android

  • 1. Memory ManagementMemory Management in Androidin Android AnDevCon Boston 2016
  • 2. CC-BY-SA 3.0 - Attribution requirements and misc., PLEASE READ: This slide must remain as-is in this specific location (slide #1), everything else you are free to change; including the logo :-) Use of figures in other documents must feature the below "Originals at" URL immediately under that figure and the below copyright notice where appropriate. You are FORBIDDEN from using the default "About" slide as-is or any of its contents. Copyright (C) 2014-2016, Opersys inc. These slides created by: Karim Yaghmour Originals at: http://www.opersys.com/training/
  • 4. Introduced Linux Trace Toolkit in 1999 Originated Adeos and relayfs (kernel/relay.c) Ara Android Arch Oversight Training, Custom Dev, Consulting, ...
  • 5. "Note that memory usage on modern operating systems like Linux is an extremely complicated and difficult to understand area. In fact the chances of you actually correctly interpreting whatever numbers you get is extremely low. (Pretty much every time I look at memory usage numbers with other engineers, there is always a long discussion about what they actually mean that only results in a vague conclusion.)" -- Dianne Hackborn, Feb 19, 2010, Stackoverflow
  • 6. AgendaAgenda Architecture Recap1. Kernel's overall role2. Kernel driver interfaces3. Kernel user-space interfaces4. Low-memory conditions5. Bionic6. App Dev Considerations7. Tools8. Misc.9. References10.
  • 7. Demo HardwareDemo Hardware Nexus 7 (Flo 2013) Qualcomm Snapdragon S4 Pro -- APQ8064 Krait CPU, 4-core, 1.51 GHz, 2MB L2 cache 2 GB on-board DDR3 (PCDDR 533MHz) 16 GB eMMC Combined power/usb
  • 10. 2. System startup2. System startup
  • 11. 3. Memory layout3. Memory layout
  • 12. Kernel's overall roleKernel's overall role Manage physical memory Manage virtual-to-physical mappings Process isolation: Protect the hardware from user-space Protect processes from each other Driver capabilities: Memory-mapped registers DMA MTD maps Filesystem cache File mapping Swapping
  • 13. InternalsInternals Architecture-independent: Architecture-specific: Per-task struct (include/linux/sched.h): The memory structures (include/linux/mm_types.h): mm/ arch/arm/mm/ struct task_struct { ... struct mm_struct *mm, *active_mm; ... struct mm_struct { struct vm_area_struct * mmap; /* list of VMAs */ struct rb_root mm_rb; struct vm_area_struct * mmap_cache; /* last find_vma result */
  • 14. Kernel driver interfacesKernel driver interfaces Memory-mapped registers DMA MTD maps ION
  • 15. Kernel user-space interfacesKernel user-space interfaces brk mmap/munmap
  • 16. Low-memory conditionsLow-memory conditions OOM killer oom_adj Android low-mem driver oom_adj set during init Modifications to oom_adj at runtime by framework
  • 17. BionicBionic malloc()/free() Comes from Doug Lea's dlmalloc Public Domain See bionic/libc/upstream-dlmalloc/ Tutorial/doc: Dates back to 1987 Uses CALL_MORECORE() macro do allocations Based on sbrk() dlopen()/dlsym() http://g.oswego.edu/dl/html/malloc.html https://en.wikipedia.org/wiki/C_dynamic_memory_allocation
  • 18. Flags to debug/observe malloc/free Linux Enable native monitoring by DDMS: Open ~/.android/ddms.cfg Add line stating: "native=true" $ adb shell setprop libc.debug.malloc 1 $ adb shell stop $ adb shell start
  • 19. App Dev ConsiderationsApp Dev Considerations Recommendations given by Google Measuring app mem usage Getting system mem usage android.os.Debug android:largeHeap="true" https://developer.android.com/training/articles/memory.html https://developer.android.com/reference/android /app/ActivityManager.html#getProcessMemoryInfo%28int[]%29 public MemoryInfo[] getProcessMemoryInfo (int[] pids) https://developer.android.com/reference/android /app/ActivityManager.html#getMemoryInfo%28android.app.ActivityManager.MemoryInfo%29 public void getMemoryInfo (ActivityManager.MemoryInfo outInfo)
  • 21. 8.1 Kernel8.1 Kernel Overall memory use Physical-mapped reg address ranges FS cache "fragmentation" /proc interface RSS, VSS, USS, PSS, etc. /proc/[pid]/maps, semantics of
  • 23. 8.3 ART/Dalvik8.3 ART/Dalvik Heap size measurement API in apps to get access to heap size from Runtime Memory Monitor / Studio (no compare?) MAT / Eclipse dalvik.vm.heapsize https://developer.android.com/reference /java/lang/Runtime.html#maxMemory%28%29 public long maxMemory ()
  • 24. 8.4. Framework8.4. Framework dumpsys meminfo dumpsys procinfo
  • 25. Misc.Misc. DDOS on memory KitKat efforts for low-mem Security aspects HAL use of mmap Swap space? zMAP ION CMA
  • 26. ReferencesReferences developer.android.com source.android.com strong/weak/soft/phantom references wrt Java GC: - - --> http://source.android.com/devices/native-memory.html http://source.android.com/devices/low-ram.html https://developer.android.com/tools/debugging/debugging-memory.html https://developer.android.com/training/articles/memory.html http://android-developers.blogspot.com/2011/03/memory-analysis-for-android.html http://android-developers.blogspot.com/2009/02/track-memory-allocations.html https://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application- in-android http://elinux.org/Android_Memory_Usage https://www.youtube.com/watch?v=_CruQY55HOk http://blog.yojimbocorp.com/2012/10/03/view-android-application-memory-usage-with-eclipse- ddms-plugin/ https://lwn.net/Articles/480055/ https://lwn.net/Articles/565469/ https://weblogs.java.net/blog/2006/05/04 /understanding-weak-references http://docs.oracle.com/javase/7/docs/api/java/lang/ref/package- summary.html