Firefox OS/Performance/Memory/OOMKiller

From MozillaWiki
Jump to: navigation, search

Android Low Memory Killer

  • Executes when kernel attempts to “shrink” resources
  • Kills process with highest “oom_adjust” value regardless of size
  • Attempts to use LRU to kill least relevant app
  • Code here: ./kernel/drivers/staging/android/lowmemorykiller.c
  • Will see the following in adb shell dmesg:
[  793.376328] select 378 (Usage), adj 10, size 5552, to kill
[  793.376354] send sigkill to 378 (Usage), adj 10, size 5552
[  794.313554] select 409 (Homescreen), adj 8, size 4065, to kill
[  794.313576] select 500 ((Preallocated a), adj 10, size 2787, to kill
[  794.313591] send sigkill to 500 ((Preallocated a), adj 10, size 2787
[  796.038379] select 409 (Homescreen), adj 8, size 4213, to kill
[  796.038398] send sigkill to 409 (Homescreen), adj 8, size 4213

Linux OOM Killer

  • Executes when Linux detects out-of-memory
  • Typically we trigger when a page-fault fails because there are no more pages available
  • Uses more complex algorithm that combines “oom_adj” and size.
    • This means b2g parent process can be killed if big enough
  • Code here: ./kernel/mm/oom_kill.c
  • Provides a lot more dmesg output:
    • Will have DataAbort CPU exception with stack trace including page-fault
    • Large table of processes and their current OOM scores
    • Single selection of a process to kill after table
<4>[ 3471.413659] Cupcakes vs. Ve invoked oom-killer: gfp_mask=0x200da, order=0, oom_adj=2, oom_score_adj=134
<4>[ 3471.413721] [<c00497f4>] (unwind_backtrace+0x0/0x12c) from [<c0135760>] (dump_header.clone.1+0x6c/0x18c)
<4>[ 3471.413747] [<c0135760>] (dump_header.clone.1+0x6c/0x18c) from [<c01358c0>] (oom_kill_process.clone.0+0x40/0x21c)
<4>[ 3471.413772] [<c01358c0>] (oom_kill_process.clone.0+0x40/0x21c) from [<c0135cf8>] (out_of_memory+0x25c/0x330)
<4>[ 3471.413799] [<c0135cf8>] (out_of_memory+0x25c/0x330) from [<c0139728>] (__alloc_pages_nodemask+0x4fc/0x6ac)
<4>[ 3471.413826] [<c0139728>] (__alloc_pages_nodemask+0x4fc/0x6ac) from [<c014ec30>] (handle_pte_fault+0x188/0x818)
<4>[ 3471.413849] [<c014ec30>] (handle_pte_fault+0x188/0x818) from [<c014f8e0>] (handle_mm_fault+0x1c0/0x1dc)
<4>[ 3471.413874] [<c014f8e0>] (handle_mm_fault+0x1c0/0x1dc) from [<c05b8d10>] (do_page_fault+0x164/0x314)
<4>[ 3471.413902] [<c05b8d10>] (do_page_fault+0x164/0x314) from [<c003d240>] (do_DataAbort+0x34/0x94)
<4>[ 3471.413932] [<c003d240>] (do_DataAbort+0x34/0x94) from [<c05b7160>] (ret_from_exception+0x0/0x10)
<4>[ 3471.413947] Exception stack(0xc4679fb0 to 0xc4679ff8)
<4>[ 3471.413962] 9fa0:                                     4b52b000 00000000 00000fe0 00000000
<4>[ 3471.413981] 9fc0: beb74180 fffff634 41db70a8 000002ea 00000800 00002000 4b52c000 00000000
<4>[ 3471.413999] 9fe0: 00000000 beb74144 00000000 41423bc4 20000010 ffffffff
<4>[ 3471.414009] Mem-info:
<4>[ 3471.414017] Normal per-cpu:
<4>[ 3471.414029] CPU    0: hi:   90, btch:  15 usd:  23
<4>[ 3471.414049] active_anon:31481 inactive_anon:8346 isolated_anon:0
<4>[ 3471.414056]  active_file:0 inactive_file:0 isolated_file:0
<4>[ 3471.414061]  unevictable:167 dirty:0 writeback:0 unstable:0
<4>[ 3471.414066]  free:440 slab_reclaimable:553 slab_unreclaimable:1333
<4>[ 3471.414072]  mapped:8466 shmem:8354 pagetables:452 bounce:0
<4>[ 3471.414106] Normal free:1760kB min:1772kB low:2212kB high:2656kB active_anon:125924kB inactive_anon:33384kB active_file:0kB inactive_file:0kB unevictable:668kB isolated(anon):0kB isolated(file):0kB present:196912kB mlocked:0kB dirty:0kB writeback:0kB mapped:33864kB shmem:33416kB slab_reclaimable:2212kB slab_unreclaimable:5332kB kernel_stack:2104kB pagetables:1808kB unstable:0kB bounce:0kB writeback_tmp:0kB pages_scanned:0 all_unreclaimable? no
<4>[ 3471.414139] lowmem_reserve[]: 0 0 0
<4>[ 3471.414156] Normal: 24*4kB 1*8kB 0*16kB 0*32kB 2*64kB 4*128kB 2*256kB 1*512kB 0*1024kB 0*2048kB 0*4096kB = 1768kB
<4>[ 3471.414204] 8531 total pagecache pages
<4>[ 3471.414212] 0 pages in swap cache
<4>[ 3471.414222] Swap cache stats: add 0, delete 0, find 0/0
<4>[ 3471.414231] Free swap  = 0kB
<4>[ 3471.414237] Total swap = 0kB
<4>[ 3471.417124] 55808 pages of RAM
<4>[ 3471.417134] 824 free pages
<4>[ 3471.417142] 9624 reserved pages
<4>[ 3471.417149] 1243 slab pages
<4>[ 3471.417157] 19255 pages shared
<4>[ 3471.417164] 0 pages swap cached
<6>[ 3471.417172] [ pid ]   uid  tgid total_vm      rss cpu oom_adj oom_score_adj name
<6>[ 3471.417214] [   98]     0    98       78        1   0     -16          -941 ueventd
<6>[ 3471.417234] [  129]  1000   129      213       15   0     -16          -941 servicemanager
<6>[ 3471.417252] [  130]     0   130     1009       45   0     -16          -941 vold
<6>[ 3471.417269] [  133]     0   133      834       29   0     -16          -941 fakeperm
<6>[ 3471.417287] [  137]     0   137     1958       67   0     -16          -941 netd
<6>[ 3471.417304] [  138]     0   138      180       14   0     -16          -941 debuggerd
<6>[ 3471.417322] [  139]  1001   139     5089      327   0     -16          -941 rild
<6>[ 3471.417341] [  140]  1013   140     4665      340   0     -16          -941 mediaserver
<6>[ 3471.417359] [  141]  1002   141      338       27   0     -16          -941 dbus-daemon
<6>[ 3471.417376] [  142]  1017   142      437       35   0     -16          -941 keystore
<6>[ 3471.417394] [  153]  1000   153      481       23   0     -16          -941 mm-pp-daemon
<6>[ 3471.417412] [  158]  1000   158      763       76   0     -16          -941 mm-qcamera-daem
<6>[ 3471.417431] [  159]     0   159      297       27   0     -16          -941 gpu_dcvsd
<6>[ 3471.417449] [  163]     0   163      865       41   0     -16          -941 adbd
<6>[ 3471.417467] [  186]     0   186      218       40   0     -16          -941 location-mq
<6>[ 3471.417486] [  192]  1001   192     1508       58   0     -16          -941 qmuxd
<6>[ 3471.417502] [  200]     0   200     3651       73   0     -16          -941 xtwifi-inet-age
<6>[ 3471.417521] [  201]  2000   201      198       26   0     -16          -941 sh
<6>[ 3471.417539] [  205]  1001   205     1549       72   0     -16          -941 netmgrd
<6>[ 3471.417556] [  207]     0   207     3046       83   0     -16          -941 xtwifi-client
<6>[ 3471.417576] [  373]  1000   373      337       27   0     -16          -941 qosmgr
<6>[ 3471.417594] [  593]     0   593    53746    20038   0       0             0 b2g
<6>[ 3471.417612] [  633]     0   633    13039     2299   0       0             0 (Nuwa)
<6>[ 3471.417629] [  665]  1007   665      176       14   0     -16          -941 logwrapper
<6>[ 3471.417647] [  666]  1010   666      661       74   0     -16          -941 wpa_supplicant
<6>[ 3471.417666] [  692]  1014   692      235       20   0     -16          -941 dhcpcd
<6>[ 3471.417684] [  970] 10970   970    17530     4262   0       2           134 Homescreen
<6>[ 3471.417702] [ 1028] 11028  1028    44344    21431   0       2           134 Cupcakes vs. Ve
<3>[ 3471.417717] Out of memory: Kill process 1028 (Cupcakes vs. Ve) score 599 or sacrifice child
<3>[ 3471.417737] Killed process 1028 (Cupcakes vs. Ve) total-vm:177376kB, anon-rss:52964kB, file-rss:32760kB