SlideShare a Scribd company logo
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

More Related Content

What's hot (20)

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

Viewers also liked (20)

PDF
Brillo / Weave Internals
Opersys inc.
 
PDF
Android Things Internals
Opersys inc.
 
PPTX
Linux内存管理
zijia
 
PPTX
Memory Usage in Android
Prashanth Nani
 
PPTX
ANDROID APP LAUNCH
Shubham Agrawal
 
PDF
Anatomy of an android
Leonardo YongUk Kim
 
PDF
Introduction to Android by Demian Neidetcher
Matthew McCullough
 
PPT
Linux memory
ericrain911
 
PDF
Is Android the New King of Embedded OSes at Embedded World 2014
Opersys inc.
 
PDF
Leveraging Android's Linux Heritage at AnDevCon VI
Opersys inc.
 
PDF
Developing Android Platform Tools
Opersys inc.
 
PDF
Embedded Android Workshop at AnDevCon VI
Opersys inc.
 
PDF
Embedded Android Workshop at Embedded World 2014
Opersys inc.
 
PDF
Extending Android's Platform Toolsuite
Opersys inc.
 
PDF
Embedded Android Workshop
Opersys inc.
 
PDF
Android Microconf at Linux Plumber 2012
Opersys inc.
 
PDF
Embedded Android Workshop at ABS 2014
Opersys inc.
 
PDF
Embedded Android Workshop
Opersys inc.
 
PDF
Embedded Android Workshop at Embedded World Conference 2013
Opersys inc.
 
PDF
Embedded Android Workshop with Lollipop
Opersys inc.
 
Brillo / Weave Internals
Opersys inc.
 
Android Things Internals
Opersys inc.
 
Linux内存管理
zijia
 
Memory Usage in Android
Prashanth Nani
 
ANDROID APP LAUNCH
Shubham Agrawal
 
Anatomy of an android
Leonardo YongUk Kim
 
Introduction to Android by Demian Neidetcher
Matthew McCullough
 
Linux memory
ericrain911
 
Is Android the New King of Embedded OSes at Embedded World 2014
Opersys inc.
 
Leveraging Android's Linux Heritage at AnDevCon VI
Opersys inc.
 
Developing Android Platform Tools
Opersys inc.
 
Embedded Android Workshop at AnDevCon VI
Opersys inc.
 
Embedded Android Workshop at Embedded World 2014
Opersys inc.
 
Extending Android's Platform Toolsuite
Opersys inc.
 
Embedded Android Workshop
Opersys inc.
 
Android Microconf at Linux Plumber 2012
Opersys inc.
 
Embedded Android Workshop at ABS 2014
Opersys inc.
 
Embedded Android Workshop
Opersys inc.
 
Embedded Android Workshop at Embedded World Conference 2013
Opersys inc.
 
Embedded Android Workshop with Lollipop
Opersys inc.
 
Ad

Similar to Memory Management in Android (20)

PDF
Memory Management in Android
Opersys inc.
 
PDF
Memory Management in Android
Opersys inc.
 
PDF
Memory Management in Android
Opersys inc.
 
PDF
Memory Management in Android
Opersys inc.
 
PPTX
Android Memory Management
Sadmankabirsoumik
 
PPTX
Memory management in Andoid
Monkop Inc
 
PDF
Virtual memory 20070222-en
Tetsuyuki Kobayashi
 
PPTX
Linux Memory Management with CMA (Contiguous Memory Allocator)
Pankaj Suryawanshi
 
PDF
Android Memory , Where is all My RAM
Yossi Elkrief
 
PDF
Kernel Recipes 2017 - 20 years of Linux Virtual Memory - Andrea Arcangeli
Anne Nicolas
 
PDF
Linux Memory Management
Anil Kumar Pugalia
 
PDF
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
Ron Munitz
 
PDF
Memory management in Linux kernel
Vadim Nikitin
 
PDF
Tuning Android for low RAM
Chris Simmonds
 
PPTX
Linux Kernel MMC Storage driver Overview
RajKumar Rampelli
 
DOC
Lesson 8 Memory Storage And Management
Laguna State Polytechnic University
 
PDF
SO-Memoria.pdf
ssuser143a20
 
PDF
SO-Memoria.pdf
Kadu37
 
PDF
2014 valat-phd-defense-slides
Sébastien Valat
 
DOCX
virtual memory - Computer operating system
Electronics - Embedded System
 
Memory Management in Android
Opersys inc.
 
Memory Management in Android
Opersys inc.
 
Memory Management in Android
Opersys inc.
 
Memory Management in Android
Opersys inc.
 
Android Memory Management
Sadmankabirsoumik
 
Memory management in Andoid
Monkop Inc
 
Virtual memory 20070222-en
Tetsuyuki Kobayashi
 
Linux Memory Management with CMA (Contiguous Memory Allocator)
Pankaj Suryawanshi
 
Android Memory , Where is all My RAM
Yossi Elkrief
 
Kernel Recipes 2017 - 20 years of Linux Virtual Memory - Andrea Arcangeli
Anne Nicolas
 
Linux Memory Management
Anil Kumar Pugalia
 
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
Ron Munitz
 
Memory management in Linux kernel
Vadim Nikitin
 
Tuning Android for low RAM
Chris Simmonds
 
Linux Kernel MMC Storage driver Overview
RajKumar Rampelli
 
Lesson 8 Memory Storage And Management
Laguna State Polytechnic University
 
SO-Memoria.pdf
ssuser143a20
 
SO-Memoria.pdf
Kadu37
 
2014 valat-phd-defense-slides
Sébastien Valat
 
virtual memory - Computer operating system
Electronics - Embedded System
 
Ad

More from Opersys inc. (18)

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

Recently uploaded (20)

PDF
Salesforce Pricing Update 2025: Impact, Strategy & Smart Cost Optimization wi...
GetOnCRM Solutions
 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PDF
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PPTX
SAP Public Cloud PPT , SAP PPT, Public Cloud PPT
sonawanekundan2024
 
PDF
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
PPT
Brief History of Python by Learning Python in three hours
adanechb21
 
PDF
How Agentic AI Networks are Revolutionizing Collaborative AI Ecosystems in 2025
ronakdubey419
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PDF
System Center 2025 vs. 2022; What’s new, what’s next_PDF.pdf
Q-Advise
 
PDF
Infrastructure planning and resilience - Keith Hastings.pptx.pdf
Safe Software
 
PDF
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
PDF
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
PPTX
Chess King 25.0.0.2500 With Crack Full Free Download
cracked shares
 
PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
PPTX
Employee salary prediction using Machine learning Project template.ppt
bhanuk27082004
 
PDF
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
 
Salesforce Pricing Update 2025: Impact, Strategy & Smart Cost Optimization wi...
GetOnCRM Solutions
 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
Presentation about variables and constant.pptx
kr2589474
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
Enhancing Security in VAST: Towards Static Vulnerability Scanning
ESUG
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
SAP Public Cloud PPT , SAP PPT, Public Cloud PPT
sonawanekundan2024
 
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
Brief History of Python by Learning Python in three hours
adanechb21
 
How Agentic AI Networks are Revolutionizing Collaborative AI Ecosystems in 2025
ronakdubey419
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
System Center 2025 vs. 2022; What’s new, what’s next_PDF.pdf
Q-Advise
 
Infrastructure planning and resilience - Keith Hastings.pptx.pdf
Safe Software
 
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
Chess King 25.0.0.2500 With Crack Full Free Download
cracked shares
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
Employee salary prediction using Machine learning Project template.ppt
bhanuk27082004
 
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
 

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