Share
Embed
Memory Management in Android
In this talk I discuss the following :
How android manages memory .
Evaluating application memory .
How to reduce application memory usage .
Rajesh
January 19, 2019
Transcript
66 slides
-
AGENDA • How android manages memory • Evaluating application memory
• How to reduce application memory usage -
Android Memory Management • Android uses paging and memory-mapping .
• Extensive use of shared memory • Framework code and resources • Most static data(Dalvik code , app resources , .so files) is mmapped into a process. • Android shares the same dynamic RAM across processes using explicitly allocated shared memory regions. -
Low memory killer • Kernel module. • Moves task of
managing out of memory (oom) issues to the user space • It does this by allowing the user-space to maintain a list of adjustments and a corresponding list of thresholds (units are in memory pages - usually 4K) at which point processes with these adjustments should be killed. • The actually killing of process is done by the lowmemorykiller -
Low memory killer • ActivityManagerService is responsible to update the
adjustments (oom_adj) to processes continuously. • Lower value has higher priority • Range is from -17 (not killable) to 15 (hidden/cached apps) • System process runs at -16 -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE Process not being directly interacted by user like music app , keyboard -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE Process not being directly interacted by user like music app , keyboard SERVICE A Process running background services which are recently started -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE Process not being directly interacted by user like music app , keyboard SERVICE A Process running background services which are recently started HOME Launcher application process -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE Process not being directly interacted by user like music app , keyboard SERVICE A Process running background services which are recently started HOME Launcher application process PREVIOUS Last used application process -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE Process not being directly interacted by user like music app , keyboard SERVICE A Process running background services which are recently started HOME Launcher application process PREVIOUS Last used application process SERVICE B Process running background services since long time. -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE Process not being directly interacted by user like music app , keyboard SERVICE A Process running background services which are recently started HOME Launcher application process PREVIOUS Last used application process SERVICE B Process running background services since long time. CACHED Other process which you can see in the recent apps -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE Process not being directly interacted by user like music app , keyboard SERVICE A Process running background services which are recently started HOME Launcher application process PREVIOUS Last used application process SERVICE B Process running background services since long time. CACHED Other process which you can see in the recent apps -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE Process not being directly interacted by user like music app , keyboard SERVICE A Process running background services which are recently started HOME Launcher application process PREVIOUS Last used application process SERVICE B Process running background services since long time. CACHED Other process which you can see in the recent apps -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE Process not being directly interacted by user like music app , keyboard SERVICE A Process running background services which are recently started HOME Launcher application process PREVIOUS Last used application process SERVICE B Process running background services since long time. CACHED Other process which you can see in the recent apps -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE Process not being directly interacted by user like music app , keyboard SERVICE A Process running background services which are recently started HOME Launcher application process WALLPAPER GONE !! PREVIOUS Last used application process SERVICE B Process running background services since long time. CACHED Other process which you can see in the recent apps -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE Process not being directly interacted by user like music app , keyboard SERVICE A Process running background services which are recently started HOME Launcher application process WALLPAPER GONE !! PREVIOUS Last used application process SERVICE B Process running background services since long time. CACHED Other process which you can see in the recent apps -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE MUSIC GONE!! SERVICE A Process running background services which are recently started HOME Launcher application process WALLPAPER GONE !! PREVIOUS Last used application process SERVICE B Process running background services since long time. CACHED Other process which you can see in the recent apps -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE MUSIC GONE!! SERVICE A Process running background services which are recently started HOME Launcher application process WALLPAPER GONE !! PREVIOUS Last used application process SERVICE B Process running background services since long time. CACHED Other process which you can see in the recent apps -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE MUSIC GONE!! SERVICE A Process running background services which are recently started HOME Launcher application process WALLPAPER GONE !! PREVIOUS Last used application process SERVICE B Process running background services since long time. CACHED Other process which you can see in the recent apps -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE MUSIC GONE!! SERVICE A Process running background services which are recently started HOME Launcher application process WALLPAPER GONE !! PREVIOUS Last used application process SERVICE B Process running background services since long time. CACHED Other process which you can see in the recent apps -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE MUSIC GONE!! SERVICE A Process running background services which are recently started HOME Launcher application process WALLPAPER GONE !! PREVIOUS Last used application process SERVICE B Process running background services since long time. CACHED Other process which you can see in the recent apps -
Process Types NATIVE Init , installd , serviceregistry , adbd
SYSTEM System server DEVICE REBOOTS PERSISTENT telephony , wifi , buetooth PERSISTENT SERVICE This is a process that the system or a persistent process has bound to FOREGROUND This is the process running the current foreground app VISIBLE hosting only activities that are visible to the user. PERCEPTIBLE MUSIC GONE!! SERVICE A Process running background services which are recently started HOME Launcher application process WALLPAPER GONE !! PREVIOUS Last used application process SERVICE B Process running background services since long time. CACHED Other process which you can see in the recent apps -
Why memory management for applications LOW RANGE (LOW MEMORY) MID
RANGE PREMIUM (HIGH MEMORY) OEMS -
Why memory management for applications LOW RANGE (LOW MEMORY) MID
RANGE PREMIUM (HIGH MEMORY) OEMS -
Why memory management for applications LOW RANGE (LOW MEMORY) MID
RANGE PREMIUM (HIGH MEMORY) OEMS APPLICATIONS -
Why memory management for applications LOW RANGE (LOW MEMORY) MID
RANGE PREMIUM (HIGH MEMORY) OEMS APPLICATIONS -
Why memory management for applications MID RANGE PREMIUM (HIGH MEMORY)
OEMS APPLICATIONS -
Why memory management for applications MID RANGE PREMIUM (HIGH MEMORY)
OEMS APPLICATIONS -
Application Memory • Restricted application memory (dalvik.vm.heapgrowthlimit) • getMemoryClass() •
Large memory applications (dalvik.vm.heapsize) • android:largeHeap=“true” in mainfest • getLargeMemoryClass(); -
# Pages used by the application ? NO Processes share
memory , which process is accountable for that ? -
Parameters Resident Set Size(RSS) Physical memory currently allocated and used
by a process . App is completely responsible for shared pages. -
Parameters Proportional Set Size(PSS) App is proportionally responsible for shared
pages. Private pages : 2 Private pages used by 2 other process : 6 PPS = 2 + 6/3 = 4 -
How to reduce memory usage ? • Reduce Java Heap
Memory • Optimize Images • Release Memory when Android asks for more memory • Use specific containers . • Favor static inner classes over non-static -
How to reduce memory usage ? • Reduce your apk
size • Things that take space in your APK tend to take memory at runtime too • Resources , bitmaps , .so files etc. • 3rd party libraries • Use App Bundle -
THANK YOU References : • Google IO ‘18 Android memory
usage(https://www.youtube.com/watch?v=w7K0jio8afM) • Source.android.com • StackOverflow.com • https://developer.android.com/topic/performance/memory-overview