今天遇到一个开线程太多将虚拟内存耗尽的问题
我的应用程序的pid是2558,查看此时的状态:
[email protected]:/proc/2558# cat status
Name: sonia
State: S (sleeping)
Tgid: 2558
Pid: 2558
PPid: 2335
TracerPid: 0
Uid: 0 0 0 0
Gid: 0 0 0 0
FDSize: 256
Groups: 0
VmPeak: 2812816 kB
VmSize: 2799304 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 799404 kB
VmRSS: 790564 kB 物理内存使用,这里是4G物理内存,是没有问题的
VmData: 2721456 kB 可以看到此时已经消耗了2.7G虚拟内存,并且还在增长,一个进程总共有4G虚拟内才能空间,应用层3G,内核态1G,这3G快被耗尽
VmStk: 912 kB
VmExe: 19196 kB
VmLib: 7012 kB
VmPTE: 3336 kB
VmSwap: 0 kB
Threads: 371 可以看到这里开了371个线程,并且还在增长
SigQ: 0/29838
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000001000
SigCgt: 00000001800006a9
CapInh: 0000000000000000
CapPrm: 0000001fffffffff
CapEff: 0000001fffffffff
CapBnd: 0000001fffffffff
Seccomp: 0
Cpus_allowed: f
Cpus_allowed_list: 0-3
Mems_allowed: 1
Mems_allowed_list: 0
voluntary_ctxt_switches: 2881
nonvoluntary_ctxt_switches: 23528
这里还有其他的参数,也比较有意思,比如:VmRss:进程的物理内存使用
挂掉时的status:
[email protected]:/proc/2452# cat status
Name: sonia
State: S (sleeping)
Tgid: 2452
Pid: 2452
PPid: 2334
TracerPid: 0
Uid: 0 0 0 0
Gid: 0 0 0 0
FDSize: 256
Groups: 0
VmPeak: 3092408 kB
VmSize: 3092400 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 783332 kB
VmRSS: 779388 kB
VmData: 3014552 kB
VmStk: 912 kB
VmExe: 19196 kB
VmLib: 7012 kB
VmPTE: 3904 kB
VmSwap: 0 kB
Threads: 519
SigQ: 0/29838
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000001000
SigCgt: 00000001800006a9
CapInh: 0000000000000000
CapPrm: 0000001fffffffff
CapEff: 0000001fffffffff
CapBnd: 0000001fffffffff
Seccomp: 0
Cpus_allowed: f
Cpus_allowed_list: 0-3
Mems_allowed: 1
Mems_allowed_list: 0
voluntary_ctxt_switches: 2779
nonvoluntary_ctxt_switches: 29252
[email protected]:/proc/2452#