我的App有3个进程和2个服务,它们的关系如下:(UI启动并绑定BKService,UI启动并绑定LinkService,然后BKService绑定LinkService)
守护进程(BKService) / /(绑定A) | 界面流程 | (绑定 C) \(绑定 B)| \ 推送流程(LinkService)
并且推送进程的内存使用量远低于守护进程。
我使用 dumpsys 活动进程来检查它们的 adj 类型和值,如下所示:
Proc # 7: svc B/ /S trm: 5 1998:cc.okcall:daemon/u0a155 (started-services)
Proc # 6: svc B/ /S trm: 5 2017:cc.okcall:push/u0a155 (started-services)
Proc # 5: cch+1 B/ /CA trm:80 2697:cc.okcall/u0a155 (cch-act)
这是详细的 dumpsys 活动进程信息:
*APP* UID 10155 ProcessRecord{4297b510 12359:cc.okcall/u0a155}
user #0 uid=10155
class=cc.okcall.MyApplication
dir=/data/app/cc.okcall-1.apk publicDir=/data/app/cc.okcall-1.apk data=/data/data/cc.okcall
packageList={cc.okcall}
compat={320dpi}
thread=android.app.ApplicationThreadProxy@42970828
pid=12359 starting=false
lastActivityTime=-6m44s889ms lastPssTime=-3m57s159ms nextPssTime=+26m2s662ms
adjSeq=449275 lruSeq=0 lastPss=20116 lastCachedPss=20116
keeping=false cached=true empty=true
oom: max=16 curRaw=10 setRaw=10 cur=10 set=10
curSchedGroup=0 setSchedGroup=0 systemNoUi=false trimMemoryLevel=0
curProcState=11 repProcState=11 pssProcState=10 setProcState=11 lastStateTime=-6m39s857ms
hasShownUi=true pendingUiClean=false hasAboveClient=false
lastWakeTime=0 timeUsed=0
lastCpuTime=0 timeUsed=0
lastRequestedGc=-9m44s117ms lastLowMemory=-9m44s117ms reportLowMemory=false
Activities:
- ActivityRecord{4285f6b8 u0 cc.okcall/.ui.home.ActivityHome t140}
Connections:
- ConnectionRecord{428a5048 u0 CR cc.okcall/.push.LinkService:@4236a318}
- ConnectionRecord{428f3300 u0 CR cc.okcall/.service.BKService:@42383ef8}
- ConnectionRecord{42baac98 u0 CR cc.okcall/.push.LinkService:@4236a318}
- ConnectionRecord{42bb4dc0 u0 CR cc.okcall/.service.BKService:@42383ef8}
Connected Providers:
- 4217c8b8/com.android.providers.settings/.SettingsProvider->12359:cc.okcall/u0a155 s1/1 u0/0 +9m43s423ms
- 4216e458/com.motorola.android.providers.settings/.MotorolaSettingsProvider->12359:cc.okcall/u0a155 s1/1 u0/0 +9m43s330ms
Receivers:
- ReceiverList{4293d538 12359 cc.okcall/10155/u0 remote:4294d840}
*APP* UID 10155 ProcessRecord{429e1778 12416:cc.okcall:push/u0a155}
user #0 uid=10155
class=cc.okcall.MyApplication
dir=/data/app/cc.okcall-1.apk publicDir=/data/app/cc.okcall-1.apk data=/data/data/cc.okcall
packageList={cc.okcall}
compat={320dpi}
thread=android.app.ApplicationThreadProxy@4225b430
pid=12416 starting=false
lastActivityTime=-9m40s498ms lastPssTime=-4m6s679ms nextPssTime=+15m53s244ms
adjSeq=449275 lruSeq=0 lastPss=9259 lastCachedPss=0
keeping=true cached=false empty=true
oom: max=16 curRaw=5 setRaw=5 cur=5 set=5
curSchedGroup=0 setSchedGroup=0 systemNoUi=false trimMemoryLevel=0
curProcState=7 repProcState=7 pssProcState=7 setProcState=7 lastStateTime=-6m39s867ms
hasClientActivities=true foregroundActivities=false
hasStartedServices=true
lastRequestedGc=-9m42s433ms lastLowMemory=-9m42s433ms reportLowMemory=false
Services:
- ServiceRecord{43147398 u0 cc.okcall/.push.LinkService}
Connected Providers:
- 4217c8b8/com.android.providers.settings/.SettingsProvider->12416:cc.okcall:push/u0a155 s1/1 u0/0 +9m41s11ms
Receivers:
- ReceiverList{42982798 12416 cc.okcall:push/10155/u0 remote:42555c68}
- ReceiverList{42d1b248 12416 cc.okcall:push/10155/u0 remote:42d1b028}
*APP* UID 10155 ProcessRecord{42d66170 12195:cc.okcall:daemon/u0a155}
user #0 uid=10155
class=cc.okcall.MyApplication
dir=/data/app/cc.okcall-1.apk publicDir=/data/app/cc.okcall-1.apk data=/data/data/cc.okcall
packageList={cc.okcall}
compat={320dpi}
thread=android.app.ApplicationThreadProxy@42abfc68
pid=12195 starting=false
lastActivityTime=-9m40s601ms lastPssTime=-4m6s757ms nextPssTime=+15m53s144ms
adjSeq=449275 lruSeq=0 lastPss=19601 lastCachedPss=0
keeping=true cached=false empty=true
oom: max=16 curRaw=5 setRaw=5 cur=5 set=5
curSchedGroup=0 setSchedGroup=0 systemNoUi=false trimMemoryLevel=0
curProcState=7 repProcState=7 pssProcState=7 setProcState=7 lastStateTime=-6m39s967ms
hasClientActivities=true foregroundActivities=false
hasStartedServices=true
lastRequestedGc=-9m48s171ms lastLowMemory=-9m48s171ms reportLowMemory=false
Services:
- ServiceRecord{431d5770 u0 cc.okcall/.service.BKService}
Connections:
- ConnectionRecord{42d455f0 u0 cc.okcall/.push.LinkService:@41f9aa40}
Published Providers:
- cc.okcall.provider.AccountProvider
-> ContentProviderRecord{42f4d1e0 u0 cc.okcall/.provider.AccountProvider}
- cc.okcall.provider.MessageProvider
-> ContentProviderRecord{42f4d278 u0 cc.okcall/.provider.MessageProvider}
- cc.okcall.provider.MeetupProvider
-> ContentProviderRecord{42f4d310 u0 cc.okcall/.provider.MeetupProvider}
- cc.okcall.provider.ContactProvider
-> ContentProviderRecord{42f4d3a8 u0 cc.okcall/.provider.ContactProvider}
Connected Providers:
- 4217c8b8/com.android.providers.settings/.SettingsProvider->12195:cc.okcall:daemon/u0a155 s1/1 u0/0 +9m41s118ms
Receivers:
- ReceiverList{42a3ed60 12195 cc.okcall:daemon/10155/u0 remote:421374c0}
好的,据我了解,在内存不足的情况下,杀死顺序应该是:UI进程、守护进程、推送进程。(因为 BKService 是 LinkService 的客户端,所以 LinkService 在 unBind 之前不会死掉,并且相同的 oom_adj 值,LinkService 使用的内存更少)。
但实际上杀死的顺序始终是:UI进程、推送进程、守护进程。有人可以解释一下吗?
如果我改变绑定 C(LinkService 绑定 BKService)的方向,那么守护进程将比推送进程更早被杀死。
我不知道为什么,有人可以帮忙,在此先感谢。