Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Memory Management in Android

Rajesh
January 19, 2019

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
Tweet

More Decks by Rajesh

Other Decks in Technology

Transcript

  1. 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.
  2. 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
  3. 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
  4. Process Types NATIVE Init , installd , serviceregistry , adbd

    SYSTEM System server PERSISTENT telephony , wifi , buetooth
  5. 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
  6. 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
  7. 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.
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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.
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. 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
  25. Why memory management for applications LOW RANGE (LOW MEMORY) MID

    RANGE PREMIUM (HIGH MEMORY) OEMS APPLICATIONS
  26. Why memory management for applications LOW RANGE (LOW MEMORY) MID

    RANGE PREMIUM (HIGH MEMORY) OEMS APPLICATIONS
  27. Application Memory • Restricted application memory (dalvik.vm.heapgrowthlimit) • getMemoryClass() •

    Large memory applications (dalvik.vm.heapsize) • android:largeHeap=“true” in mainfest • getLargeMemoryClass();
  28. # Pages used by the application ? NO Processes share

    memory , which process is accountable for that ?
  29. Parameters Resident Set Size(RSS) Physical memory currently allocated and used

    by a process . App is completely responsible for shared pages.
  30. 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
  31. 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
  32. 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
  33. 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