Android进程优先级相关概念_oom_adj_权重值

前置知识:

oom_adj :oom_adj(即权重值)的值用来标记进程的重要程度,值越小,越重要

1.查看当前在运行的进程

ps  命令  

基于api 21 

USER     PID   PPID  VSIZE  RSS     WCHAN    PC        NAME
root      1     0     2936   548   c02cb2ef 0806b8f0 S /init
root      2     0     0      0     c023edb3 00000000 S kthreadd
root      3     2     0      0     c0244320 00000000 S ksoftirqd/0
root      4     2     0      0     c023ae80 00000000 S kworker/0:0
root      5     2     0      0     c023ae80 00000000 S kworker/0:0H
root      6     2     0      0     c023ae80 00000000 S kworker/u8:0
root      7     2     0      0     c0244320 00000000 S migration/0
root      8     2     0      0     c026ffe2 00000000 S rcu_preempt
root      9     2     0      0     c026ffe2 00000000 S rcu_bh
root      10    2     0      0     c026ffe2 00000000 S rcu_sched
root      11    2     0      0     c0244320 00000000 S migration/1
root      12    2     0      0     c0244320 00000000 S ksoftirqd/1
root      13    2     0      0     c023ae80 00000000 S kworker/1:0
root      14    2     0      0     c023ae80 00000000 S kworker/1:0H
root      15    2     0      0     c0244320 00000000 S migration/2
root      16    2     0      0     c0244320 00000000 S ksoftirqd/2
root      17    2     0      0     c023ae80 00000000 S kworker/2:0
root      18    2     0      0     c023ae80 00000000 S kworker/2:0H
root      19    2     0      0     c0244320 00000000 S migration/3
root      20    2     0      0     c0244320 00000000 S ksoftirqd/3
root      21    2     0      0     c023ae80 00000000 S kworker/3:0
root      22    2     0      0     c023ae80 00000000 S kworker/3:0H
root      23    2     0      0     c023ac08 00000000 S khelper
root      24    2     0      0     c023ae80 00000000 S kworker/u8:1
root      263   2     0      0     c023ac08 00000000 S writeback
root      265   2     0      0     c023ac08 00000000 S bioset
root      267   2     0      0     c023ac08 00000000 S kblockd
root      362   2     0      0     c023ac08 00000000 S ata_sff
root      373   2     0      0     c04e04b1 00000000 S khubd
root      381   2     0      0     c023ac08 00000000 S md
root      389   2     0      0     c023ac08 00000000 S cfg80211
root      390   2     0      0     c023ae80 00000000 S kworker/1:1
root      507   2     0      0     c029b2f6 00000000 S kswapd0
root      570   2     0      0     c02ea9d0 00000000 S fsnotify_mark
root      589   2     0      0     c023ac08 00000000 S crypto
root      609   2     0      0     c023ae80 00000000 S kworker/0:1
root      610   2     0      0     c023ae80 00000000 S kworker/2:1
root      611   2     0      0     c023ae80 00000000 S kworker/3:1
root      624   2     0      0     c023ae80 00000000 S kworker/u8:2
root      717   2     0      0     c023ac08 00000000 S iscsi_eh
root      731   2     0      0     c0439c73 00000000 S scsi_eh_0
root      734   2     0      0     c0439c73 00000000 S scsi_eh_1
root      737   2     0      0     c023ae80 00000000 S kworker/u8:3
root      806   2     0      0     c023ac08 00000000 S binder
root      834   2     0      0     c023ac08 00000000 S deferwq
root      835   1     2928   440   c02cb2ef 0806b8f0 S /sbin/ueventd
root      1155  2     0      0     c023ae80 00000000 S kworker/0:1H
root      1156  2     0      0     c0347a36 00000000 S jbd2/vda-8
root      1157  2     0      0     c023ac08 00000000 S ext4-dio-unwrit
root      1159  2     0      0     c0347a36 00000000 S jbd2/vdb-8
root      1160  2     0      0     c023ac08 00000000 S ext4-dio-unwrit
root      1165  2     0      0     c0347a36 00000000 S jbd2/vdc-8
root      1166  2     0      0     c023ac08 00000000 S ext4-dio-unwrit
logd      1167  1     16008  2292  ffffffff b7731481 S /system/bin/logd
root      1168  1     4000   324   c02ed451 08095985 S /sbin/healthd
root      1169  1     5820   1412  c02ed451 b7668b05 S /system/bin/lmkd
system    1170  1     3844   736   c054e725 b773c7a6 S /system/bin/servicemanager
root      1171  1     11460  2024  ffffffff b77116f1 S /system/bin/vold
system    1172  1     90664  4072  ffffffff b7760b05 S /system/bin/surfaceflinger
shell     1175  1     3980   1012  c03f0b31 b7674b36 S /system/bin/sh
root      1176  1     101248 688   ffffffff 0806bdc5 S /sbin/adbd
root      1177  1     23016  1544  ffffffff b76a36f1 S /system/bin/netd
root      1178  1     4616   944   c0561671 b771ada3 S /system/bin/debuggerd
radio     1179  1     12352  1460  ffffffff b767e6f1 S /system/bin/rild
drm       1180  1     16828  3704  ffffffff b76597a6 S /system/bin/drmserver
media     1181  1     133996 12036 ffffffff b77027a6 S /system/bin/mediaserver
install   1183  1     3864   868   c05d4f03 b7749b36 S /system/bin/installd
keystore  1184  1     7828   1988  c054e725 b76c07a6 S /system/bin/keystore
root      1187  1     1217856 50224 ffffffff b76f43d5 S zygote
root      1238  2     0      0     c023ae80 00000000 S kworker/2:1H
root      1284  2     0      0     c02635e9 00000000 S kauditd
root      1291  2     0      0     c023ae80 00000000 S kworker/3:1H
root      1594  2     0      0     c023ae80 00000000 S kworker/1:1H
system    1613  1187  1382064 99156 ffffffff b76f3b05 S system_server
u0_a13    1943  1187  1301676 69172 ffffffff b76f3b05 S com.android.systemui
media_rw  1973  1     7828   764   ffffffff b76b1b36 S /system/bin/sdcard
u0_a31    2004  1187  1256756 38720 ffffffff b76f3b05 S com.android.inputmethod.latin
radio     2051  1187  1266232 45580 ffffffff b76f3b05 S com.android.phone
radio     2084  1187  1236352 30508 ffffffff b76f3b05 S com.android.server.telecom
system    2113  1187  1244972 28748 ffffffff b76f3b05 S com.android.settings
u0_a43    2131  1187  1237232 26700 ffffffff b76f3b05 S com.android.printspooler
u0_a5     2159  1187  1244104 37184 ffffffff b76f3b05 S android.process.media
u0_a2     2187  1187  1246832 36020 ffffffff b76f3b05 S android.process.acore
u0_a8     2303  1187  1286968 70752 ffffffff b76f3b05 S com.android.launcher
u0_a7     2323  1187  1399528 94508 ffffffff b76f3b05 S com.google.android.gms.persistent
u0_a28    2351  1187  1246124 29280 ffffffff b76f3b05 S com.android.exchange
u0_a7     2375  1187  1247684 33348 ffffffff b76f3b05 S com.google.process.gapps
u0_a26    2392  1187  1255464 36596 ffffffff b76f3b05 S com.android.email
u0_a7     2450  1187  1579872 101984 ffffffff b76f3b05 S com.google.android.gms
u0_a36    2565  1187  1238472 29068 ffffffff b76f3b05 S com.android.music
u0_a22    2589  1187  1242032 30744 ffffffff b76f3b05 S com.android.deskclock
u0_a4     2685  1187  1241972 27552 ffffffff b76f3b05 S com.android.dialer
system    2702  1187  1234492 25936 ffffffff b76f3b05 S com.android.keychain
u0_a18    2759  1187  1249848 31140 ffffffff b76f3b05 S com.android.calendar
u0_a1     2781  1187  1237824 31532 ffffffff b76f3b05 S com.android.providers.calendar
u0_a9     2803  1187  1235380 25868 ffffffff b76f3b05 S com.android.managedprovisioning
u0_a10    2830  1187  1248568 31756 ffffffff b76f3b05 S com.android.mms
u0_a7     2965  1187  1352828 42936 ffffffff b76f3b05 S com.google.android.gms.ui
u0_a7     3054  1187  1360172 47648 ffffffff b76f3b05 S com.google.android.gms.unstable
root      3425  1176  3980   1028  c023517f b7627481 S /system/bin/sh

u0_a59    4264  1187  1254880 41968 ffffffff b76f3b05 S calc.superdy.ttest
root      3430  3425  3980   1024  c023517f b76b2481 S sh
root      3466  3430  5708   1088  00000000 b7728b36 R ps

2. 查看某个进程的优先级

cat /proc/进程id/oom_adj

例如:

cat /proc/1187/oom_adj   查看zygote进程的优先级

zygote 的 oom_adj value为-17

cat /proc/1613/oom_adj   查看system_server 进程的优先级

system_server 进程优先级为-15

cat /proc/2303/oom_adj   查看launcher进程的优先级

launcher进程优先级为0

cat /proc/4264/oom_adj  查看当前activity可见的进程的优先级

当前可见的进程ttest的进程优先级为0

3.ProcessList.java文件

ProcessList.java文件内部定义了一些进程的adj值

如下:


    // OOM adjustments for processes in various states:

    // Adjustment used in certain places where we don't know it yet.
    // (Generally this is something that is going to be cached, but we
    // don't know the exact value in the cached range to assign yet.)
    static final int UNKNOWN_ADJ = 16;

    // This is a process only hosting activities that are not visible,
    // so it can be killed without any disruption.
    static final int CACHED_APP_MAX_ADJ = 15;
    static final int CACHED_APP_MIN_ADJ = 9;

    // The B list of SERVICE_ADJ -- these are the old and decrepit
    // services that aren't as shiny and interesting as the ones in the A list.
    static final int SERVICE_B_ADJ = 8;

    // This is the process of the previous application that the user was in.
    // This process is kept above other things, because it is very common to
    // switch back to the previous app.  This is important both for recent
    // task switch (toggling between the two top recent apps) as well as normal
    // UI flow such as clicking on a URI in the e-mail app to view in the browser,
    // and then pressing back to return to e-mail.
    static final int PREVIOUS_APP_ADJ = 7;

    // This is a process holding the home application -- we want to try
    // avoiding killing it, even if it would normally be in the background,
    // because the user interacts with it so much.
    static final int HOME_APP_ADJ = 6;

    // This is a process holding an application service -- killing it will not
    // have much of an impact as far as the user is concerned.
    static final int SERVICE_ADJ = 5;

    // This is a process with a heavy-weight application.  It is in the
    // background, but we want to try to avoid killing it.  Value set in
    // system/rootdir/init.rc on startup.
    static final int HEAVY_WEIGHT_APP_ADJ = 4;

    // This is a process currently hosting a backup operation.  Killing it
    // is not entirely fatal but is generally a bad idea.
    static final int BACKUP_APP_ADJ = 3;

    // This is a process only hosting components that are perceptible to the
    // user, and we really want to avoid killing them, but they are not
    // immediately visible. An example is background music playback.
    static final int PERCEPTIBLE_APP_ADJ = 2;

    // This is a process only hosting activities that are visible to the
    // user, so we'd prefer they don't disappear.
    static final int VISIBLE_APP_ADJ = 1;

    // This is the process running the current foreground app.  We'd really
    // rather not kill it!
    static final int FOREGROUND_APP_ADJ = 0;

    // This is a process that the system or a persistent process has bound to,
    // and indicated it is important.
    static final int PERSISTENT_SERVICE_ADJ = -11;

    // This is a system persistent process, such as telephony.  Definitely
    // don't want to kill it, but doing so is not completely fatal.
    static final int PERSISTENT_PROC_ADJ = -12;

    // The system process runs at the default adjustment.
    static final int SYSTEM_ADJ = -16;

 

参考:

https://www.jianshu.com/p/6201dc3a447a

https://www.jianshu.com/p/10cce92fc7b1

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值