SlideShare a Scribd company logo
Memory ManagementMemory Management
in Androidin Android
AnDevCon Santa Clara 2015
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 (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 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

PDF
Memory Management in Android
PDF
Customizing Android's UI
PDF
Memory Management in Android
PDF
Memory Management in Android
PDF
Inside Android's UI at AnDevCon VI
PDF
Android's Multimedia Framework
PDF
Memory Management in Android
PDF
Android Security, From the Ground Up
Memory Management in Android
Customizing Android's UI
Memory Management in Android
Memory Management in Android
Inside Android's UI at AnDevCon VI
Android's Multimedia Framework
Memory Management in Android
Android Security, From the Ground Up

What's hot (20)

PDF
Scheduling in Android
PDF
Leveraging Android's Linux Heritage at AnDevCon VI
PDF
Running Code in the Android Stack at ABS 2014
PDF
Android Platform Debugging and Development
PDF
Android Security Internals
PDF
Customizing Android's UI
PDF
Android Platform Debugging and Development
ODP
Enhancing and modifying_the_core_android_os
PDF
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
PDF
Android 10 Internals Update
PDF
Android Platform Debugging and Development
PDF
Android Platform Debugging & Development
PDF
Working with the AOSP - Linaro Connect Asia 2013
PDF
Is Android the New Embedded Linux? at AnDevCon VI
PDF
Extending Android's Platform Toolsuite
PDF
Android Things Internals
PDF
Android Platform Debugging and Development
PDF
Android Internals
PDF
Android Jumpstart ESC SV 2012 Part I
PDF
Embedded Android Workshop
Scheduling in Android
Leveraging Android's Linux Heritage at AnDevCon VI
Running Code in the Android Stack at ABS 2014
Android Platform Debugging and Development
Android Security Internals
Customizing Android's UI
Android Platform Debugging and Development
Enhancing and modifying_the_core_android_os
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Android 10 Internals Update
Android Platform Debugging and Development
Android Platform Debugging & Development
Working with the AOSP - Linaro Connect Asia 2013
Is Android the New Embedded Linux? at AnDevCon VI
Extending Android's Platform Toolsuite
Android Things Internals
Android Platform Debugging and Development
Android Internals
Android Jumpstart ESC SV 2012 Part I
Embedded Android Workshop
Ad

Viewers also liked (15)

PPT
Vietnam Mobile Day 2013: Memory Management For Android Apps
PPTX
Android ppt
PPTX
Presentation on Android operating system
PPTX
What's new in Android M
PDF
Memory management in Android
PDF
Android Overview
PPTX
Introduction to Android Development
PPTX
Introduction to android
PPTX
Memory in Android
PPTX
Introduction to Android development - Presentation
PPTX
Memory management in Andoid
PDF
Android memory fundamentals
PPTX
Android seminar ppt
PDF
Memory management
PPT
Vietnam Mobile Day 2013: Memory Management For Android Apps
Android ppt
Presentation on Android operating system
What's new in Android M
Memory management in Android
Android Overview
Introduction to Android Development
Introduction to android
Memory in Android
Introduction to Android development - Presentation
Memory management in Andoid
Android memory fundamentals
Android seminar ppt
Memory management
Ad

Similar to Memory Management in Android (20)

PDF
Memory Management in Android
PDF
Memory Management in Android
PDF
Reliability, Availability and Serviceability on Linux
PDF
Android memory analysis Debug slides.pdf
PDF
KeenLab iOS Jailbreak Internals: Userland Read-Only Memory can be Dangerous
PDF
Us 18-chen-keen lab-ios-jailbreak-internals
PPT
Memory management in linux
PDF
淺談探索 Linux 系統設計之道
PDF
Memory Management in TIZEN - Samsung SW Platform Team
PDF
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
DOCX
Chromium os architecture report
PPTX
OSSEU17: How Open Source Project Xen Puts Security Software Vendors Ahead of ...
PDF
Towards Software Defined Persistent Memory
PDF
Crash dump analysis - experience sharing
PDF
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
PDF
Ov psim demo_slides_power_pc
PPTX
virtualization.pptx
PDF
Linux Memory Management
PDF
Faults inside System Software
PDF
Walking around linux kernel
Memory Management in Android
Memory Management in Android
Reliability, Availability and Serviceability on Linux
Android memory analysis Debug slides.pdf
KeenLab iOS Jailbreak Internals: Userland Read-Only Memory can be Dangerous
Us 18-chen-keen lab-ios-jailbreak-internals
Memory management in linux
淺談探索 Linux 系統設計之道
Memory Management in TIZEN - Samsung SW Platform Team
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
Chromium os architecture report
OSSEU17: How Open Source Project Xen Puts Security Software Vendors Ahead of ...
Towards Software Defined Persistent Memory
Crash dump analysis - experience sharing
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
Ov psim demo_slides_power_pc
virtualization.pptx
Linux Memory Management
Faults inside System Software
Walking around linux kernel

More from Opersys inc. (20)

PDF
Android Automotive
PDF
Embedded Android Workshop with Pie
PDF
Android's HIDL: Treble in the HAL
PDF
Android Treble: Blessing or Trouble?
PDF
Embedded Android Workshop with Oreo
PDF
Scheduling in Android
PDF
Embedded Android Workshop with Nougat
PDF
Embedded Android Workshop with Nougat
PDF
Android Things: Android for IoT
PDF
Android Things Internals
PDF
Brillo / Weave Internals
PDF
Android Platform Debugging and Development
PDF
Embedded Android Workshop with Nougat
PDF
Brillo / Weave Internals
PDF
Project Ara
PDF
Android Platform Debugging and Development
PDF
Brillo/Weave Internals
PDF
Embedded Android Workshop with Marshmallow
PDF
Android Platform Debugging and Development
PDF
Embedded Android Workshop with Marshmallow
Android Automotive
Embedded Android Workshop with Pie
Android's HIDL: Treble in the HAL
Android Treble: Blessing or Trouble?
Embedded Android Workshop with Oreo
Scheduling in Android
Embedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
Android Things: Android for IoT
Android Things Internals
Brillo / Weave Internals
Android Platform Debugging and Development
Embedded Android Workshop with Nougat
Brillo / Weave Internals
Project Ara
Android Platform Debugging and Development
Brillo/Weave Internals
Embedded Android Workshop with Marshmallow
Android Platform Debugging and Development
Embedded Android Workshop with Marshmallow

Recently uploaded (20)

PDF
Softaken Excel to vCard Converter Software.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
AI in Product Development-omnex systems
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
medical staffing services at VALiNTRY
PDF
System and Network Administraation Chapter 3
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPT
Introduction Database Management System for Course Database
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
Softaken Excel to vCard Converter Software.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Upgrade and Innovation Strategies for SAP ERP Customers
Design an Analysis of Algorithms II-SECS-1021-03
Wondershare Filmora 15 Crack With Activation Key [2025
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Navsoft: AI-Powered Business Solutions & Custom Software Development
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
AI in Product Development-omnex systems
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
How Creative Agencies Leverage Project Management Software.pdf
Digital Strategies for Manufacturing Companies
Odoo Companies in India – Driving Business Transformation.pdf
medical staffing services at VALiNTRY
System and Network Administraation Chapter 3
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Introduction Database Management System for Course Database
ManageIQ - Sprint 268 Review - Slide Deck

Memory Management in Android

  • 1. Memory ManagementMemory Management in Androidin Android AnDevCon Santa Clara 2015
  • 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 (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 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 ()
  • 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