SlideShare a Scribd company logo
1 of 30
Download to read offline
Memory ManagementMemory Management
in Androidin Android
ESTF 2015, Bengaluru
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-2015, 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 2013 ("flo")
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 Dalvik/ART8.3 Dalvik/ART
Heap size measurement
API in apps to get access to heap size from Runtime
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

More Related Content

What's hot

Android 10 Internals Update
Android 10 Internals UpdateAndroid 10 Internals Update
Android 10 Internals UpdateOpersys inc.
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security InternalsOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentKarim Yaghmour
 
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.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Enhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_osEnhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_osArnav Gupta
 
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.
 
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
 
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 crash debugging
Android crash debuggingAndroid crash debugging
Android crash debuggingAshish Agrawal
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessNanik Tolaram
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things InternalsOpersys inc.
 
Android Jumpstart ESC SV 2012 Part I
Android Jumpstart ESC SV 2012 Part IAndroid Jumpstart ESC SV 2012 Part I
Android Jumpstart ESC SV 2012 Part IOpersys inc.
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android WorkshopOpersys inc.
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowOpersys inc.
 
Android On Development Boards at AnDevCon3
Android On Development Boards at AnDevCon3Android On Development Boards at AnDevCon3
Android On Development Boards at AnDevCon3Opersys inc.
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in AndroidOpersys inc.
 
Workshop su Android Kernel Hacking
Workshop su Android Kernel HackingWorkshop su Android Kernel Hacking
Workshop su Android Kernel HackingDeveler S.r.l.
 
Embedded Android Workshop part I ESC SV 2012
Embedded Android Workshop part I ESC SV 2012Embedded Android Workshop part I ESC SV 2012
Embedded Android Workshop part I ESC SV 2012Opersys inc.
 

What's hot (20)

Android 10 Internals Update
Android 10 Internals UpdateAndroid 10 Internals Update
Android 10 Internals Update
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security Internals
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
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...
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Enhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_osEnhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_os
 
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 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
 
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 Internals
Android InternalsAndroid Internals
Android Internals
 
Android crash debugging
Android crash debuggingAndroid crash debugging
Android crash debugging
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things Internals
 
Android Jumpstart ESC SV 2012 Part I
Android Jumpstart ESC SV 2012 Part IAndroid Jumpstart ESC SV 2012 Part I
Android Jumpstart ESC SV 2012 Part I
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android Workshop
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with Marshmallow
 
Android On Development Boards at AnDevCon3
Android On Development Boards at AnDevCon3Android On Development Boards at AnDevCon3
Android On Development Boards at AnDevCon3
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in Android
 
Workshop su Android Kernel Hacking
Workshop su Android Kernel HackingWorkshop su Android Kernel Hacking
Workshop su Android Kernel Hacking
 
Embedded Android Workshop part I ESC SV 2012
Embedded Android Workshop part I ESC SV 2012Embedded Android Workshop part I ESC SV 2012
Embedded Android Workshop part I ESC SV 2012
 

Similar to 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.
 
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
 
Chromium os architecture report
Chromium os  architecture reportChromium os  architecture report
Chromium os architecture reportAmr Abd El Latief
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in AndroidOpersys inc.
 
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]RootedCON
 
Debugging Native heap OOM - JavaOne 2013
Debugging Native heap OOM - JavaOne 2013Debugging Native heap OOM - JavaOne 2013
Debugging Native heap OOM - JavaOne 2013MattKilner
 
Ov psim demo_slides_power_pc
Ov psim demo_slides_power_pcOv psim demo_slides_power_pc
Ov psim demo_slides_power_pcsimon56
 
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
 
Towards Software Defined Persistent Memory
Towards Software Defined Persistent MemoryTowards Software Defined Persistent Memory
Towards Software Defined Persistent MemorySwaminathan Sundararaman
 
LCE13: Android Graphics Upstreaming
LCE13: Android Graphics UpstreamingLCE13: Android Graphics Upstreaming
LCE13: Android Graphics UpstreamingLinaro
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversAnil Kumar Pugalia
 

Similar to 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
 
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
 
Reliability, Availability and Serviceability on Linux
Reliability, Availability and Serviceability on LinuxReliability, Availability and Serviceability on Linux
Reliability, Availability and Serviceability on Linux
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Chromium os architecture report
Chromium os  architecture reportChromium os  architecture report
Chromium os architecture report
 
淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道 淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道
 
Memory management in linux
Memory management in linuxMemory management in linux
Memory management in linux
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
 
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
 
Faults inside System Software
Faults inside System SoftwareFaults inside System Software
Faults inside System Software
 
Debugging Native heap OOM - JavaOne 2013
Debugging Native heap OOM - JavaOne 2013Debugging Native heap OOM - JavaOne 2013
Debugging Native heap OOM - JavaOne 2013
 
Ov psim demo_slides_power_pc
Ov psim demo_slides_power_pcOv psim demo_slides_power_pc
Ov psim demo_slides_power_pc
 
Operating system
Operating systemOperating system
Operating system
 
Walking around linux kernel
Walking around linux kernelWalking around linux kernel
Walking around linux kernel
 
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
 
Towards Software Defined Persistent Memory
Towards Software Defined Persistent MemoryTowards Software Defined Persistent Memory
Towards Software Defined Persistent Memory
 
LCE13: Android Graphics Upstreaming
LCE13: Android Graphics UpstreamingLCE13: Android Graphics Upstreaming
LCE13: Android Graphics Upstreaming
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
 

More from Opersys inc.

Android Automotive
Android AutomotiveAndroid Automotive
Android AutomotiveOpersys 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.
 
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.
 
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 Things Internals
Android Things InternalsAndroid Things Internals
Android Things 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 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.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys 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.
 

More from Opersys inc. (20)

Android Automotive
Android AutomotiveAndroid Automotive
Android Automotive
 
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
 
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
 
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 Things Internals
Android Things InternalsAndroid Things Internals
Android Things Internals
 
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 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
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
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
 

Recently uploaded

Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 

Recently uploaded (20)

Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 

Memory Management in Android

  • 1. Memory ManagementMemory Management in Androidin Android ESTF 2015, Bengaluru
  • 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-2015, 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 2013 ("flo") 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.
  • 11. 2. System startup2. System startup
  • 12.
  • 13. 3. Memory layout3. Memory layout
  • 14.
  • 15. 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
  • 16. 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 */
  • 17. Kernel driver interfacesKernel driver interfaces Memory-mapped registers DMA MTD maps ION
  • 18. Kernel user-space interfacesKernel user-space interfaces brk mmap/munmap
  • 19. 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
  • 20. 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
  • 21. 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
  • 22. 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)
  • 24. 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
  • 26. 8.3 Dalvik/ART8.3 Dalvik/ART Heap size measurement API in apps to get access to heap size from Runtime MAT/Eclipse dalvik.vm.heapsize https://developer.android.com /reference/java/lang/Runtime.html#maxMemory%28%29 public long maxMemory ()
  • 27. 8.4. Framework8.4. Framework dumpsys meminfo dumpsys procinfo
  • 28. Misc.Misc. DDOS on memory KitKat efforts for low-mem Security aspects HAL use of mmap Swap space? zMAP ION CMA
  • 29. 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