Linux 2.6.31内核优化-1

阅读更多

介绍

本文档是一篇关于Linux Kernel 2.6.31的最简优化指南。作者旨在编译一份性能最佳且适合普通Application/Server开发用的内核。
本文提及的内核调优,主要是通过选择最佳编译选项,删除无用驱动,减少内核尺寸等方式来进行的。

由于作者水平有限,如果描述错误,还请不吝指教。

 

运行环境

虚拟机

Virtualbox 3.1.4

CPU

Core 2 Duo P9500 2.53G 双核 开启 vt-x, APIC

磁盘

虚拟 10GSATA磁盘

内存

分了1G物理内存

网卡

虚拟 AMD PCNet32 100M

其他

USB,串口,显卡,声卡全关

作者是在虚拟机中编译的内核,如果你与作者的运行环境不同,则本文档中的部分描述可能会与你的实际情况有一定出入。

不过,相信大部分用户在看到选项释义时,能做出适合自己的选择。

 

说明

下列选项中,通过 "// " 注释的行

通过红色 "<===" 注释的行,代表内核默认开启,本文档推荐关闭的选项,释义部分会给出关闭的理由。

 

 

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)  ---> <=== 对比默认的GzipBzip2拥有更高的压缩比

[*] 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 <=== 用于在真正内核装载前,做一些操作(俗称两阶段启动),比如加载modulemount一些非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 randomization

Choose 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 support

IO Schedulers  ---> // IO调度器支持,不同程序可以会选用不同的调度策略,这里我们不要动他

<*> Anticipatory I/O scheduler

<*> Deadline I/O scheduler

<*> CFQ I/O scheduler

    Default 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

[ ] Memtest

Processor 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 support

Preemption 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 support

High 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秒检查一次。一般这种脏数据是因某些Bios处理不当引起的。资料链接。我信任我目前的虚拟bios版本

[] Reserve low 64K of RAM on AMI/Phoenix BIOSen <=== 我不是 AMI/Phoenix BIOS

[ ] Math emulation

[ ] MTRR (Memory Type Range Register) support <=== 我没用 X windows

[ ]   MTRR cleanup support

[ ]   x86 PAT support <=== 我没用 X windows

[ ] EFI runtime service support <=== 我机器是BIOS引导的,用不到EFI(Extensible Firmware Interface),如果你有兴趣体验EFI,可以在Virtualbox中开启

[] Enable seccomp to safely compute untrusted bytecode <=== 只有嵌入式系统可以不选

[ ] Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)

Timer frequency (300 HZ)  ---> <=== Server场景建议设为300hz,减少内核事件响应速度,提高程序吞吐量,桌面场景可以保持不变

[ ] kexec system call <=== 我没有运行时替换内核的需求

[ ] kernel crash dumps <=== 内核崩溃时,dump运行时信息。就算crash了,我也不会去调试内核的core dump

[ ] Build a relocatable kernel <=== 官方说明 (建立一个移动的内核,并增加10%的内核尺寸,运行时会被丢弃),我认为没实质性的作用

(0x1000000) Physical address where the kernel is loaded

[] Support for hot-pluggable CPUs <=== 热拔插CPU,我用不到

[ ] Compat VDSO support

[ ] Built-in kernel command line

 

Power management and ACPI options  --->

[*] Power Management support

[ ]   Power Management Debug Support <=== 不想调试ACPI

[ ]     Verbose Power Management debugging

[ ] Suspend to RAM and standby <=== 我是用来跑server,一般不需要待机

[ ] Hibernation (aka 'suspend to disk')  <=== 我是用来跑server,一般不需要休眠

[*] ACPI (Advanced Configuration and Power Interface) Support  --->

[*]   Deprecated /proc/acpi files

[*]   Deprecated power /proc/acpi directories

[*]   Future power /sys interface

[*]   Deprecated /proc/acpi/event support

< >   AC Adapter <=== 我不需要从ACBattery之间做切换

< >   Battery <=== 没有电池

< >   Button <=== 没有Fn快捷键

-*-   Video

<*>   Fan

<*>   Processor

<*>     Thermal Zone

(0)   Disable ACPI for systems before Jan 1st this year

[ ]   Debug Statements

< >   PCI slot detection driver

< >   Smart Battery System

    CPU Frequency scaling  --->

[*] CPU Frequency scaling

[ ]   Enable CPUfreq debugging <=== 我不需要调试 CPUfreq

< >   CPU frequency translation statistics

Default CPUFreq governor (performance)  ---> <=== 默认用 performance高性能的CPU调频方式

<*>   'performance' governor

< >   'powersave' governor

<>   'userspace' governor for userspace frequency scaling <=== 既允许手动调整cpu频率,也允许用户空间的程序动态的调整cpu频率(需要额外的调频软件,比如cpufreqd)  我只用performance

<>   'ondemand' cpufreq policy governor <=== "周期性的考察CPU负载并自动的动态调整cpu频率",我只用 performance

<>   'conservative' cpufreq governor

*** CPUFreq processor drivers ***

<*>   ACPI Processor P-States driver

< >   AMD Mobile K6-2/K6-3 PowerNow!

< >   AMD Mobile Athlon/Duron PowerNow!

< >   AMD Opteron/Athlon64 PowerNow!

< >   Cyrix MediaGX/NatSemi Geode Suspend Modulation

< >   Intel Enhanced SpeedStep (deprecated)

< >   Intel Speedstep on ICH-M chipsets (ioport interface)

< >   Intel Pentium 4 clock modulation

< >   Transmeta LongRun

< >   VIA Cyrix III Longhaul

 

Bus options (PCI etc.)  --->

[*] PCI support

PCI access mode (Any)  --->

[*] PCI Express support

[*]   Root Port Advanced Error Reporting support // 硬件驱动会负责发送错误信息

[ ]     PCI Express ECRC settings control

< >     PCIE AER error injector support

[*] Message Signaled Interrupts (MSI and MSI-X)

[ ] Enable deprecated pci_find_* API

[ ] PCI Debugging

< > PCI Stub driver

[*] Interrupts on hypertransport devices

[ ] PCI IOV support

[ ] ISA support

[ ] MCA support

< > NatSemi SCx200 support

[ ] One Laptop Per Child support

< > PCCard (PCMCIA/CardBus) support  ---> <=== 一般笔记本电脑会配备PCCard接口(无线网卡之类的),看你的硬件和使用场景吧。虽然我也是NB,但我从来不用PCMCIA

< > Support for PCI Hotplug  ---> <=== 我没有要热拔插PCI设备的需求

 

Executable file formats / Emulations  --->

[*] Kernel support for ELF binaries

[*] Write ELF core dumps with partial segments

< > Kernel support for a.out and ECOFF binaries

<*> Kernel support for MISC binaries

 

[*] Networking support  --->

Networking options  --->

<*> Packet socket

[*]   Packet socket: mmapped IO

<*> Unix domain sockets

<*> Transformation user configuration interface

< > PF_KEY sockets

[*] TCP/IP networking

[*]   IP: multicasting

[*]   IP: advanced router

Choose IP: FIB lookup algorithm (choose FIB_HASH if unsure) (FIB_HASH)  --->

[*]   IP: policy routing

[*]   IP: equal cost multipath

[*]   IP: verbose route monitoring

[ ]   IP: kernel level autoconfiguration <=== 我很少用网络引导OS,内核级别的网络配置对我无用。

[ ]     IP: DHCP support

[ ]     IP: BOOTP support

[ ]     IP: RARP support

< >   IP: tunneling

< >   IP: GRE tunnels over IP

[*]   IP: multicast routing

[*]     IP: PIM-SM version 1 support

[*]     IP: PIM-SM version 2 support

[ ]   IP: ARP daemon support

[ ]   IP: TCP syncookie support (disabled per default) <=== 抵抗SYN flood攻击,我是开发机,暂不考虑安全特性

< >   IP: AH transformation

< >   IP: ESP transformation

 < >   IP: IPComp transformation

< >   IP: IPsec transport mode

< >   IP: IPsec tunnel mode

< >   IP: IPsec BEET mode

[*]   Large Receive Offload (ipv4/tcp)

< >   INET: socket monitoring interface

[ ]   TCP: advanced congestion control  ---> <=== 高级拥塞控制,如果没有特殊需求(比如无线网络)就别选了

< >   The IPv6 protocol  ---> <=== 我暂时没有要支持IPV6的需求

[ ]   NetLabel subsystem support <=== NetLabel子系统, 为诸如CIPSORIPSO之类能够在分组信息上添加标签的协议提供支持,我用不到

[ ] Security Marking <=== 对网络包进行安全标记,类似于nfmark,但主要是为安全目的而设计, 安全特性,我暂时不考虑

[ ] Network packet filtering framework (Netfilter)  ---> <=== 我不打算使用防火墙,要用到时再编译进去

< > Asynchronous Transfer Mode (ATM)

< > 802.1d Ethernet Bridging

< > 802.1Q VLAN Support

< > DECnet Support

< > ANSI/IEEE 802.2 LLC type 2 Support

< > The IPX protocol

< > Appletalk protocol support

< > Phonet protocols family

[ ] QoS and/or fair queueing  --->  <=== 通过IPRoute切换网络设备上的Qos策略,我不打算使用IP路由

[ ] Data Center Bridging support

Network testing  --->

[ ]   Amateur Radio support  ---> <=== 我没有无线电

< >   CAN bus subsystem support  --->

< >   IrDA (infrared) subsystem support  --->

< >   Bluetooth subsystem support  --->

[ ]   Wireless  ---> <=== 我没有使用无线网卡

< >   RF switch subsystem support  ---> <=== 我没有RF切换设备

你可能感兴趣的:(Linux,网络应用,performance,虚拟机,Mobile)