Linux 2.6.31内核优化指南作者:Ken WuEmail: ken.wug@介绍本文档是一篇关于Linux Kernel 2.6.31的最简优化指南。
作者旨在编译一份性能最佳且适合普通Application/Server开发用的内核。
(非生产环境)本文提及的内核调优,主要是通过选择最佳编译选项,删除无用驱动,减少内核尺寸,关闭部分安全特性等方式来进行的。
优化后的效果,主要体现在OS启动时间,启动后的内存占用以及应用程序运行性能。
由于作者水平有限,如果描述错误,还请不吝指教。
运行环境虚拟机Virtualbox 3.1.4CPU Core 2 Duo P9500 2.53G双核开启vt-x, APIC磁盘虚拟10G的SATA磁盘内存分了1G物理内存网卡虚拟AMD PCNet32 100M其他USB,串口,显卡,声卡全关作者是在虚拟机中编译的内核,如果你与作者的运行环境不同,则本文档中的部分描述可能会与你的实际情况有一定出入。
不过,相信大部分用户在看到选项释义时,能做出适合自己的选择。
说明下列选项中,通过"// "注释的行,代表金国步写的内核选项简介中未提及的选项释义。
通过红色"<==="注释的行,代表内核默认开启,本文档推荐关闭的选项,释义部分会给出关闭的理由。
参考资料金国步写的内核选项简介Linux Kernel DatabaseLinuxsir BBS优化前后性能对比项目优化前优化后内核尺寸 4.1M 1.6M启动时间(含dhcp+默认init service)22s14s启动后的内存占用25M22MAPP SPEC测试成绩待测待测General setup --->[ ] Prompt for development and/or incomplete code/drivers <===显示尚在开发中或尚未完成的代码和驱动.我不是内核或驱动开发人员。
() Local version - append to kernel release[ ] Automatically append version information to the version string Kernel compression mode (Bzip2) ---> <===对比默认的Gzip,Bzip2拥有更高的压缩比[*] Support for paging of anonymous memory (swap)[*] System V IPC[*] BSD Process Accounting[ ] BSD Process Accounting version 3 file format[ ] Export task/process statistics through netlink (EXPERIMENTAL) <===体验类选项一律关[ ] Auditing support <===给SELinux提供支持。
我的使用场景主要是开发应用程序,不需要那么高的安全性,另外安全总是以牺牲性能为代价RCU Subsystem ---> // 非对称读写锁系统是一种新的kernel锁机制,适用于读多写少环境RCU Implementation (Classic RCU) ---> <===选择标准的RCU系统,tree-base是给拥有大规模CPU集群的SMP系统用的< > Kernel .config support(18) Kernel log buffer size (16 => 64KB, 17 => 128KB)[] Control Group support ---><=== cgroups支持,文档资料,cgroups主要作用是给进程分组,并可以动态调控进程组的CPU占用率。
比如A进程分到apple组,给予20%CPU占用率,E进程分easy组,给予50%CPU占用率,最高100%。
我目前没有此类应用场景,用到时会选择将其编译进去。
[] Kernel->user space relay support (formerly relayfs) <===在某些文件系统上(比如debugfs)提供从内核空间向用户空间传递大量数据的接口,我目前没有此类应用场景-*- Namespaces support[] UTS namespace <===我没有已安装的应用程序要用到UTS ns[] IPC namespace <===我没有已安装的应用程序要用到IPC ns[] Initial RAM filesystem and RAM disk (initramfs/initrd) support <===用于在真正内核装载前,做一些操作(俗称两阶段启动),比如加载module,mount一些非root分区,提供灾难恢复shell环境等,资料,我是期望直接从kernel image直接启动,所以没选它[*] Optimize for size[ ] Configure standard kernel features (for small systems) ---> -*- Load all symbols for debugging/ksymoops[ ] Do an extra kallsyms pass <===除非你在kallsyms中发现了bug并需要报告这个bug才打开该选项Performance Counters --->[*] Kernel Performance Counters // CPU性能监听器,包括CPU 同一时间执行指令数,cache miss数,分支预测失败次数(Branch misprediction)。
调优其他程序时或许会用到,比如JVM[ ] Strip assembler-generated symbols during link[ ] Disable heap randomizationChoose SLAB allocator (SLUB (Unqueued Allocator)) --->[ ] Profiling support (EXPERIMENTAL) <===我不是内核开发人员,不需要profile内核[] Activate markers <===一种运行时状态分析诊断工具,类似instrumentation,资料,我用不到[ ] Kprobes <===我不是内核开发人员,不需要调试内核GCOV-based kernel profiling --->[ ] Enable gcov-based kernel profiling[*] Enable loadable module support ---> //我很少使用dynamic module loading,所以,下面的选项只留一个unloading即可(默认)--- Enable loadable module support[ ] Forced module loading[*] Module unloading[ ] Module versioning support[ ] Source checksum for all modules-*- Enable the block layer --->--- Enable the block layer[*] Support for large (2TB+) block devices and files //大硬盘支持,SATA设备如果不选,会发生kernel panic,具体原因未知[ ] Block layer SG support v4 <===支持通用scsi块设备第4版,我用的是SATA[ ] Block layer data integrity supportIO Schedulers ---> // IO调度器支持,不同程序可以会选用不同的调度策略,这里我们不要动他<*> Anticipatory I/O scheduler<*> Deadline I/O scheduler<*> CFQ I/O schedulerDefault I/O scheduler (CFQ) --->Processor type and features --->[*] Tickless System (Dynamic Ticks) // CPU节能,动态时间片意思是当CPU处于空闲时,降低内核定时器的轮询频率[*] High Resolution Timer Support //我有的时候要测试Real Time JVM,希望内核能支持这种高响应速度的内核定时器,一般用户可关闭[*] Symmetric multi-processing support[ ] Support sparse irq numbering <===如果你想支持大量CPU,又想使用较低的内核内存占用,请启用它。
我只有单块CPU[*] Enable MPS table//让多核/多CPU系统支持ACPI[ ] Support for big SMP systems with more than 8 CPUs[ ] Support for extended (non-PC) x86 platforms <===我是X86平台,不需要再支持其他平台[*] Single-depth WCHAN output //跟proc相关的最好不要关[ ] Paravirtualized guest support --->--- Paravirtualized guest support[ ] MemtestProcessor family (Core 2/newer Xeon) ---> <===这里请选择对应的CPU,我是core 2 duo[ ] Generic x86 support <===通用x86支持,如果你的CPU能够在上述"Processor family"中找到就别选了[*] HPET Timer Support(4) Maximum number of CPUs <===我的CPU是双核,算上超线程HT最多虚拟4颗逻辑CPU,所以我选4,默认是8[*] SMT (Hyperthreading) scheduler support[*] Multi-core scheduler supportPreemption Model (Voluntary Kernel Preemption (Server)) ---> <===这里我选择了Server,它最贴近我的使用场景[*] Reroute for broken boot IRQs //防止同时收到多个boot IRQ(中断)时,系统混乱[*] Machine Check Exception[ ] Use legacy machine check code (will go away)[*] Intel MCE features[ ] AMD MCE features <===我是intel CPU[ ] Support for old Pentium 5 / WinChip machine checks< > Machine check injector support< > Toshiba Laptop support< > Dell laptop support[ ] Enable X86 board specific fixups for reboot <===修正某些旧x86主板的重起bug,这种主板基本绝种了<*> /dev/cpu/microcode - microcode support[*] Intel microcode patch loading support[ ] AMD microcode patch loading support <===我是intel CPU<*> /dev/cpu/*/msr - Model-specific register support<*> /dev/cpu/*/cpuid - CPU information support< > /sys/kernel/debug/x86/cpu/* - CPU Debug supportHigh Memory Support (4GB) --->(4096) Low address space to protect from user allocation[*] Allocate 3rd-level pagetables from highmem<===在内存很多(大于4G)的机器上将用户空间的页表放到高位内存区,以节约宝贵的低端内存,我只虚拟了1G[ ] Check for low memory corruption <===低位内存脏数据检查,默认是每60秒检查一次。