本文共 3367 字,大约阅读时间需要 11 分钟。
在使用top查看进程状态时,我们有时候会看到D状态的进程。
w: S -- Process Status The status of the task which can be one of: ’D’ = uninterruptible sleep ’R’ = running ’S’ = sleeping ’T’ = traced or stopped ’Z’ = zombie
D是一种不可中断的sleep,如果你发现大量的D状态的进程,这个时候这些进程实际上是没有在处理业务逻辑的。
例如使用PostgreSQL时,批量的往数据库导入数据,如果导入的数据量大到OS脏页回写的速度赶不上写入的速度时,并且用户刷dirty page的阈值到达,用户进程会需要主动刷脏页。vm.dirty_background_ratio = 10vm.dirty_background_bytes = 0vm.dirty_ratio = 20vm.dirty_bytes = 0vm.dirty_writeback_centisecs = 50vm.dirty_expire_centisecs = 6000
例如以上配置,OS脏页超过20%时,用户调write也需要主动的刷脏页,就会看到进程处于D状态,直到脏页水位下降到10%以下。
当然还有其他的原因会导致进程进入D状态,我们需要观察进程的stack,看看它处于什么状态。 例如处于R状态的COPY PostgreSQL进程,它的stack是什么样的?cat /proc/17944/status ; echo -e "\n"; cat /proc/17944/stackName: postgresState: R (running)Tgid: 17944Pid: 17944PPid: 57925TracerPid: 0Uid: 123293 123293 123293 123293Gid: 100 100 100 100Utrace: 0FDSize: 64Groups: 100 19001 VmPeak: 272294920 kBVmSize: 119788 kBVmLck: 0 kBVmHWM: 3244 kBVmRSS: 2812 kBVmData: 2140 kBVmStk: 152 kBVmExe: 5852 kBVmLib: 2400 kBVmPTE: 64 kBVmSwap: 0 kBThreads: 1SigQ: 0/4131614SigPnd: 0000000000000000ShdPnd: 0000000000000000SigBlk: 0000000000000000SigIgn: 0000000001301800SigCgt: 0000000180006287CapInh: 0000000000000000CapPrm: 0000000000000000CapEff: 0000000000000000CapBnd: ffffffffffffffffCpus_allowed: ffffffff,ffffffffCpus_allowed_list: 0-63Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001Mems_allowed_list: 0voluntary_ctxt_switches: 55758nonvoluntary_ctxt_switches: 103995[] sys_semtimedop+0x81a/0x840[ ] 0xffffffffffffffff
例如处于D状态的COPY PostgreSQL进程,它的stack是什么样的?
可以看到它处于刷脏页速度受限的状态,与ext4内核有关。cat /proc/17944/status ; echo -e "\n"; cat /proc/17944/stackName: postgresState: D (disk sleep)Tgid: 17944Pid: 17944PPid: 57925TracerPid: 0Uid: 123293 123293 123293 123293Gid: 100 100 100 100Utrace: 0FDSize: 64Groups: 100 19001 VmPeak: 272294920 kBVmSize: 119788 kBVmLck: 0 kBVmHWM: 3244 kBVmRSS: 2812 kBVmData: 2140 kBVmStk: 152 kBVmExe: 5852 kBVmLib: 2400 kBVmPTE: 64 kBVmSwap: 0 kBThreads: 1SigQ: 0/4131614SigPnd: 0000000000000000ShdPnd: 0000000000000000SigBlk: 0000000000000000SigIgn: 0000000001301800SigCgt: 0000000180006287CapInh: 0000000000000000CapPrm: 0000000000000000CapEff: 0000000000000000CapBnd: ffffffffffffffffCpus_allowed: ffffffff,ffffffffCpus_allowed_list: 0-63Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001Mems_allowed_list: 0voluntary_ctxt_switches: 55922nonvoluntary_ctxt_switches: 104189[] balance_dirty_pages_ratelimited_nr+0x2d0/0x9a0[ ] generic_file_buffered_write+0x1da/0x2e0[ ] __generic_file_aio_write+0x260/0x490[ ] generic_file_aio_write+0x88/0x100[ ] ext4_file_write+0x43/0xe0 [ext4][ ] do_sync_write+0xfa/0x140[ ] vfs_write+0xb8/0x1a0[ ] sys_write+0x51/0x90[ ] system_call_fastpath+0x16/0x1b[ ] 0xffffffffffffffff
转载地址:http://uejpx.baihongyu.com/