linux参数之/proc/sys/kernel详解
时间:2015-01-06 12:05 来源:linux.it.net.cn 作者:IT
Modprobe/modules_disabled
前者包含一个路径指向内核模块加载器(kernel module loader),用于加载内核模块;而后一个用于控制是否允许在系统启动后热插拔模块,即进行modprobe/rmmod操作,0表示不禁止;
justin_$ more modprobe
/sbin/modprobe
Linux启动初始化时需执行/etc/rc.d/rc.sysinit,而该脚本其中一项就是加载用户自定义模块/etc/sysconfig/modules/*.modules
该系统在启动时会自动加载nvram/floppy/parport/lp/snd-powermac系统
justin_$ ls
udev-stw.modules
justin_$ more udev-stw.modules
#!/bin/sh
MODULES="nvram floppy parport lp snd-powermac"
[ -f /etc/sysconfig/udev-stw ] && . /etc/sysconfig/udev-stw
for i in $MODULES ; do
modprobe $i >/dev/null 2>&1
done
而执行完rc.sysinit后,则要启动外挂模块/etc/modprobe.conf,该文件用来修改模块的部分选项配置
justin_$ more /etc/modprobe.conf
alias scsi_hostadapter shpchp
alias bond0 bonding
alias eth0 bnx2
alias eth1 bnx2
alias eth2 bnx2
alias eth3 bnx2
alias eth4 be2net
alias eth5 be2net
alias scsi_hostadapter1 cciss
alias scsi_hostadapter2 ata_piix
alias scsi_hostadapter3 qla2xxx
alias net-pf-10 off
alias ipv6 off
options ipv6 disable=1
options bond0 mode=balance-alb miimon=100
系统支持的所有模块位于/lib/modules/`uname -r`/kernel,
threads-max
系统允许的最大线程数
justin_$ more threads-max
774028
Linux无法直接控制单个进程可拥有的线程数,但有参考公式max = VM/stack_size,默认stack为8k,可通过降低stack大小或增加虚拟内存来调大每个进程可拥有的最大线程数;
对于支持多线程的程序如Java,有可能会遇到一个进程无法创建更多线程的情形,其原因多种多样,而OS端可能由此参数造成;
http://dustycodes.wordpress.com/2012/02/09/increasing-number-of-threads-per-process/
http://www.linuxidc.com/Linux/2011-12/48616.htm
http://dimitrik.free.fr/blog/archives/2010/11/mysql-performance-hitting-error-cant-create-a-new-thread-errno-11-on-a-high-number-of-connections.html
pid_max
系统最大pid值,在大型系统里可适当调大
justin_$ more pid_max
32768
hung_task_panic/ softlockup_thresh
linux下每个CPU都有一个看门狗(watchdog)进程,可通过ps -ef | grep -i watchdog查看,该进程每秒获取其CPU的当前时间戳并保存于per-CPU,而timer interrupt()会调用softlock_tick(),该函数比较CPU当前时间与per-CPU保存的时间,若差值大于softlockup_thresh则系统产生一条告警信息,
BUG: soft lockup - CPU#1 stuck for 15s! [swapper:0] Pid: 0
如遇到此情形可配置kdump自动产生vcore跟踪文件;
默认情况下,当出现soft lockup时系统仅产生告警信息,而将hung_task_panic设置为1时系统会panic;
justin_$ more hung_task_panic
0
justin_$ more softlockup_thresh
60
justin_$ ps -ef | grep -i watchdog
root 5 2 0 2012 ? 00:00:00 [watchdog/0]
root 8 2 0 2012 ? 00:00:00 [watchdog/1]
root 11 2 0 2012 ? 00:00:00 [watchdog/2]
root 14 2 0 2012 ? 00:00:00 [watchdog/3]
root 17 2 0 2012 ? 00:00:00 [watchdog/4]
root 20 2 0 2012 ? 00:00:00 [watchdog/5]
root 23 2 0 2012 ? 00:00:00 [watchdog/6]
root 26 2 0 2012 ? 00:00:00 [watchdog/7]
root 29 2 0 2012 ? 00:00:00 [watchdog/8]
root 32 2 0 2012 ? 00:00:00 [watchdog/9]
root 35 2 0 2012 ? 00:00:00 [watchdog/10]
root 38 2 0 2012 ? 00:00:00 [watchdog/11]
root 41 2 0 2012 ? 00:00:00 [watchdog/12]
root 44 2 0 2012 ? 00:00:00 [watchdog/13]
root 47 2 0 2012 ? 00:00:00 [watchdog/14]
root 50 2 0 2012 ? 00:00:00 [watchdog/15]
root 53 2 0 2012 ? 00:00:00 [watchdog/16]
root 56 2 0 2012 ? 00:00:00 [watchdog/17]
root 59 2 0 2012 ? 00:00:00 [watchdog/18]
root 62 2 0 2012 ? 00:00:00 [watchdog/19]
root 65 2 0 2012 ? 00:00:00 [watchdog/20]
root 68 2 0 2012 ? 00:00:00 [watchdog/21]
root 71 2 0 2012 ? 00:00:00 [watchdog/22]
root 74 2 0 2012 ? 00:00:00 [watchdog/23]
justin_$ /sbin/modinfo softdog
filename: /lib/modules/2.6.32-100.26.2.el5/kernel/drivers/watchdog/softdog.ko
alias: char-major-10-130
license: GPL
description: Software Watchdog Device Driver
author: Alan Cox
srcversion: C7E767DB59D650F969C7438
depends:
vermagic: 2.6.32-100.26.2.el5 SMP mod_unload modversions
parm: soft_margin:Watchdog soft_margin in seconds. (0 < soft_margin < 65536, default=60) (int)
parm: nowayout:Watchdog cannot be stopped once started (default=0) (int)
parm: soft_noboot:Softdog action, set to 1 to ignore reboots, 0 to reboot (default depends on ONLY_TESTING) (int)
http://h10025.www1.hp.com/ewfrf/wc/document?cc=ca&dlc=en&docname=c02675677&lc=en
http://damntechnology.blogspot.co.uk/2010/04/linux-crash-debug-tips-i-have-soft.html
http://www.mjmwired.net/kernel/Documentation/lockup-watchdogs.txt
http://blog.kreyolys.com/2011/03/17/no-panic-its-just-a-kernel-panic/
nmi_watchdog
NMI watchdog(non maskable interrupt)又称硬件watchdog,用于检测OS是否hang,系统硬件定期产生一个NMI,而每个NMI调用内核查看其中断数量,如果一段时间(10秒)后其数量没有显著增长,则判定系统已经hung,接下来启用panic机制即重启OS,如果开启了Kdump还会产生crash dump文件;
APIC(advanced programmable interrupt controller):高级可编程中断控制器,默认内置于各个x86CPU中,在SMP中用于CPU间的中断;比较高档的主板配备有IO-APIC,负责收集硬件设备的中断请求并转发给APIC;
要使用NMI Watchdog必须先激活APIC,SMP内核默认启动
该参数有2个选项:0不激活;1/2激活,有的硬件支持1有的支持2;
当前系统便没有激活;
justin_$ more nmi_watchdog
0
justin_$ grep NMI /proc/interrupts
NMI: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Non-maskable interrupts
小结:
当watchdog启动后,如果/dev/watchdog一定时间间隔内没有被更新,则判定系统hang并根据相应参数决定是否重启
Watchdog有两种:软件/硬件模式,前者基于hrtimer而后者基于perf子系统,两者不能同时运行
http://publib.boulder.ibm.com/infocenter/lnxinfo/v3r0m0/index.jsp?topic=%2Fliaai%2Fcrashdump%2Fliaaicrashdumpnmiwatch.htm
http://slacksite.com/slackware/nmi.html
Panic
当内核panic时是否重启,0不重启,非0值表示N秒后重启
justin_$ more panic
0
panic_on_io_nmi
当内核收到因I/O错误导致的NMI时是否panic
0表示不
justin_$ more panic_on_io_nmi
0
panic_on_oops
内核oops不同于panic,后者会导致OS重启,而设备驱动引发的oops通常不会如此;
Oops是由于内核引用了无效指针;发生于用户空间程序通常产生一个段错误segfault,而用户态程序自身无法恢复;发生于内核空间时则称作oops;
由于X86架构限制,当linux系统panic时 默认无法保存crash dump,因为此时内核不工作无法保存当前内存信息,SPARC架构则可完成,而RedHat分别开发了NetDump/Diskdump从而做到此功能;
justin_$ more panic_on_oops
1
如下是一段oops信息,oops号码很重要,EIP显示了代码段和当前正在执行的指令集地址
Unable to handle kernel NULL pointer dereference at virtual address 00000014
*pde = 00000000
Oops: 0000
CPU: 0
EIP: 0010:[]
EFLAGS: 00210213
eax: 00000000 ebx: c6155c6c ecx: 00000038 edx: 00000000
esi: c672f000 edi: c672f07c ebp: 00000004 esp: c6155b0c
ds: 0018 es: 0018 ss: 0018
Process tar (pid: 2293, stackpage=c6155000)
Stack: c672f000 c672f07c 00000000 00000038 00000060 00000000 c6d7d2a0
c6c79018
00000001 c6155c6c 00000000 c6d7d2a0 c017eb4f c6155c6c 00000000
00000098
c017fc44 c672f000 00000084 00001020 00001000 c7129028 00000038
00000069
Call Trace: [] [] [] [] []
[] []
[] [] [] [] []
[] []
Code: 8b 40 14 ff d0 89 c2 8b 06 83 c4 10 01 c2 89 16 8b 83 8c 01
http://slacksite.com/slackware/oops.html
/proc/sys/kernel/slow-work
其实slow-work是个线程池机制,用于执行耗时相对较长的任务;
Linux中有slow-work的数据结构;
使用前需要调用int ret = slow_work_register_user();注册;
justin_$ ls
max-threads min-threads vslow-percentage
(责任编辑:IT)
Modprobe/modules_disabled
前者包含一个路径指向内核模块加载器(kernel module loader),用于加载内核模块;而后一个用于控制是否允许在系统启动后热插拔模块,即进行modprobe/rmmod操作,0表示不禁止;
justin_$ more modprobe
/sbin/modprobe
Linux启动初始化时需执行/etc/rc.d/rc.sysinit,而该脚本其中一项就是加载用户自定义模块/etc/sysconfig/modules/*.modules
该系统在启动时会自动加载nvram/floppy/parport/lp/snd-powermac系统
justin_$ ls
udev-stw.modules
justin_$ more udev-stw.modules
#!/bin/sh
MODULES="nvram floppy parport lp snd-powermac"
[ -f /etc/sysconfig/udev-stw ] && . /etc/sysconfig/udev-stw
for i in $MODULES ; do
modprobe $i >/dev/null 2>&1
done
而执行完rc.sysinit后,则要启动外挂模块/etc/modprobe.conf,该文件用来修改模块的部分选项配置
justin_$ more /etc/modprobe.conf
alias scsi_hostadapter shpchp
alias bond0 bonding
alias eth0 bnx2
alias eth1 bnx2
alias eth2 bnx2
alias eth3 bnx2
alias eth4 be2net
alias eth5 be2net
alias scsi_hostadapter1 cciss
alias scsi_hostadapter2 ata_piix
alias scsi_hostadapter3 qla2xxx
alias net-pf-10 off
alias ipv6 off
options ipv6 disable=1
options bond0 mode=balance-alb miimon=100
系统支持的所有模块位于/lib/modules/`uname -r`/kernel,
threads-max
系统允许的最大线程数
justin_$ more threads-max
774028
Linux无法直接控制单个进程可拥有的线程数,但有参考公式max = VM/stack_size,默认stack为8k,可通过降低stack大小或增加虚拟内存来调大每个进程可拥有的最大线程数;
对于支持多线程的程序如Java,有可能会遇到一个进程无法创建更多线程的情形,其原因多种多样,而OS端可能由此参数造成;
http://dustycodes.wordpress.com/2012/02/09/increasing-number-of-threads-per-process/
http://www.linuxidc.com/Linux/2011-12/48616.htm
http://dimitrik.free.fr/blog/archives/2010/11/mysql-performance-hitting-error-cant-create-a-new-thread-errno-11-on-a-high-number-of-connections.html
pid_max
系统最大pid值,在大型系统里可适当调大
justin_$ more pid_max
32768
hung_task_panic/ softlockup_thresh
linux下每个CPU都有一个看门狗(watchdog)进程,可通过ps -ef | grep -i watchdog查看,该进程每秒获取其CPU的当前时间戳并保存于per-CPU,而timer interrupt()会调用softlock_tick(),该函数比较CPU当前时间与per-CPU保存的时间,若差值大于softlockup_thresh则系统产生一条告警信息,
BUG: soft lockup - CPU#1 stuck for 15s! [swapper:0] Pid: 0
如遇到此情形可配置kdump自动产生vcore跟踪文件;
默认情况下,当出现soft lockup时系统仅产生告警信息,而将hung_task_panic设置为1时系统会panic;
justin_$ more hung_task_panic
0
justin_$ more softlockup_thresh
60
justin_$ ps -ef | grep -i watchdog
root 5 2 0 2012 ? 00:00:00 [watchdog/0]
root 8 2 0 2012 ? 00:00:00 [watchdog/1]
root 11 2 0 2012 ? 00:00:00 [watchdog/2]
root 14 2 0 2012 ? 00:00:00 [watchdog/3]
root 17 2 0 2012 ? 00:00:00 [watchdog/4]
root 20 2 0 2012 ? 00:00:00 [watchdog/5]
root 23 2 0 2012 ? 00:00:00 [watchdog/6]
root 26 2 0 2012 ? 00:00:00 [watchdog/7]
root 29 2 0 2012 ? 00:00:00 [watchdog/8]
root 32 2 0 2012 ? 00:00:00 [watchdog/9]
root 35 2 0 2012 ? 00:00:00 [watchdog/10]
root 38 2 0 2012 ? 00:00:00 [watchdog/11]
root 41 2 0 2012 ? 00:00:00 [watchdog/12]
root 44 2 0 2012 ? 00:00:00 [watchdog/13]
root 47 2 0 2012 ? 00:00:00 [watchdog/14]
root 50 2 0 2012 ? 00:00:00 [watchdog/15]
root 53 2 0 2012 ? 00:00:00 [watchdog/16]
root 56 2 0 2012 ? 00:00:00 [watchdog/17]
root 59 2 0 2012 ? 00:00:00 [watchdog/18]
root 62 2 0 2012 ? 00:00:00 [watchdog/19]
root 65 2 0 2012 ? 00:00:00 [watchdog/20]
root 68 2 0 2012 ? 00:00:00 [watchdog/21]
root 71 2 0 2012 ? 00:00:00 [watchdog/22]
root 74 2 0 2012 ? 00:00:00 [watchdog/23]
justin_$ /sbin/modinfo softdog
filename: /lib/modules/2.6.32-100.26.2.el5/kernel/drivers/watchdog/softdog.ko
alias: char-major-10-130
license: GPL
description: Software Watchdog Device Driver
author: Alan Cox
srcversion: C7E767DB59D650F969C7438
depends:
vermagic: 2.6.32-100.26.2.el5 SMP mod_unload modversions
parm: soft_margin:Watchdog soft_margin in seconds. (0 < soft_margin < 65536, default=60) (int)
parm: nowayout:Watchdog cannot be stopped once started (default=0) (int)
parm: soft_noboot:Softdog action, set to 1 to ignore reboots, 0 to reboot (default depends on ONLY_TESTING) (int)
http://h10025.www1.hp.com/ewfrf/wc/document?cc=ca&dlc=en&docname=c02675677&lc=en
http://damntechnology.blogspot.co.uk/2010/04/linux-crash-debug-tips-i-have-soft.html
http://www.mjmwired.net/kernel/Documentation/lockup-watchdogs.txt
http://blog.kreyolys.com/2011/03/17/no-panic-its-just-a-kernel-panic/
nmi_watchdog
NMI watchdog(non maskable interrupt)又称硬件watchdog,用于检测OS是否hang,系统硬件定期产生一个NMI,而每个NMI调用内核查看其中断数量,如果一段时间(10秒)后其数量没有显著增长,则判定系统已经hung,接下来启用panic机制即重启OS,如果开启了Kdump还会产生crash dump文件;
APIC(advanced programmable interrupt controller):高级可编程中断控制器,默认内置于各个x86CPU中,在SMP中用于CPU间的中断;比较高档的主板配备有IO-APIC,负责收集硬件设备的中断请求并转发给APIC;
要使用NMI Watchdog必须先激活APIC,SMP内核默认启动
该参数有2个选项:0不激活;1/2激活,有的硬件支持1有的支持2;
当前系统便没有激活;
justin_$ more nmi_watchdog
0
justin_$ grep NMI /proc/interrupts
NMI: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Non-maskable interrupts
小结:
当watchdog启动后,如果/dev/watchdog一定时间间隔内没有被更新,则判定系统hang并根据相应参数决定是否重启
Watchdog有两种:软件/硬件模式,前者基于hrtimer而后者基于perf子系统,两者不能同时运行
http://publib.boulder.ibm.com/infocenter/lnxinfo/v3r0m0/index.jsp?topic=%2Fliaai%2Fcrashdump%2Fliaaicrashdumpnmiwatch.htm
http://slacksite.com/slackware/nmi.html
Panic
当内核panic时是否重启,0不重启,非0值表示N秒后重启
justin_$ more panic
0
panic_on_io_nmi
当内核收到因I/O错误导致的NMI时是否panic
0表示不
justin_$ more panic_on_io_nmi
0
panic_on_oops
内核oops不同于panic,后者会导致OS重启,而设备驱动引发的oops通常不会如此;
Oops是由于内核引用了无效指针;发生于用户空间程序通常产生一个段错误segfault,而用户态程序自身无法恢复;发生于内核空间时则称作oops;
由于X86架构限制,当linux系统panic时 默认无法保存crash dump,因为此时内核不工作无法保存当前内存信息,SPARC架构则可完成,而RedHat分别开发了NetDump/Diskdump从而做到此功能;
justin_$ more panic_on_oops
1
如下是一段oops信息,oops号码很重要,EIP显示了代码段和当前正在执行的指令集地址
Unable to handle kernel NULL pointer dereference at virtual address 00000014
*pde = 00000000
Oops: 0000
CPU: 0
EIP: 0010:[]
EFLAGS: 00210213
eax: 00000000 ebx: c6155c6c ecx: 00000038 edx: 00000000
esi: c672f000 edi: c672f07c ebp: 00000004 esp: c6155b0c
ds: 0018 es: 0018 ss: 0018
Process tar (pid: 2293, stackpage=c6155000)
Stack: c672f000 c672f07c 00000000 00000038 00000060 00000000 c6d7d2a0
c6c79018
00000001 c6155c6c 00000000 c6d7d2a0 c017eb4f c6155c6c 00000000
00000098
c017fc44 c672f000 00000084 00001020 00001000 c7129028 00000038
00000069
Call Trace: [] [] [] [] []
[] []
[] [] [] [] []
[] []
Code: 8b 40 14 ff d0 89 c2 8b 06 83 c4 10 01 c2 89 16 8b 83 8c 01
http://slacksite.com/slackware/oops.html
/proc/sys/kernel/slow-work
其实slow-work是个线程池机制,用于执行耗时相对较长的任务;
Linux中有slow-work的数据结构;
使用前需要调用int ret = slow_work_register_user();注册;
justin_$ ls
max-threads min-threads vslow-percentage
(责任编辑:IT) |