Compile kernel options

Source: Internet
Author: User
Compile the kernel option-general Linux technology-Linux programming and kernel information. The following is a detailed description. 1) because the Linux kernel is too huge and the content involved is all-encompassing, and my own level is also very limited, it is impossible for me to write all aspects of Kernel configuration, in this article, I will only introduce some of the most important parts. Of course, the benevolent and wise may be wise. Others I think are not important, and vice versa. You are welcome to add this article and correct the mistakes.
?? 2) The Kernel configuration introduced in this article is for the i386 architecture and is not fully applicable to other architectures (of course most of them are also applicable ).
?? 3) in this article, we will introduce the Kernel configuration process and assume that your ubuntu is for the main purpose of desktop applications. That is to say, my recommended practices for Kernel configuration are to ensure system throughput (throughput) to improve the system's response capability (responsiveness ).
?? 4) this document only applies to the 2.6.x kernel. the kernel is 2.6.20.
?? 5) This article only introduces the configuration of the kernel, and does not introduce how to compile a kernel from start to end. Therefore, please refer to some related articles if you are not clear about the Kernel Compiling steps.
??
?? The core of Kernel configuration referred to in this article is a file named. config, which is located in the root directory of the kernel source code. This file does not exist after you extract the kernel source code. It will only be generated after you have performed a configuration. This file is a text file with many lines of information that determine what features and modules are supported when you compile the kernel. The following two examples are as follows. the config file contains a behavior: CONFIG_SMP = y, which indicates that the compiled kernel must support Symmetric multi-processing ), this means that a macro called CONFIG_SMP will be defined when compiling the c file of the kernel. There is also a line: CONFIG_NTFS_FS = m, this line indicates that a loadable kernel module (LKM, loadable kernel module) that supports NTFS file systems should be compiled during the kernel compilation process ).
?? The above example mentions the concept of the loadable kernel module (LKM, loadable kernel module). I need to introduce this concept here. First, linux is structured in a single kernel (monolithic kernel). After linux is compiled, it can be regarded as a large program that provides services for all callers (of course, there are still many kernel threads running in the kernel ). All functions (such as hardware support) that need to be supported should be compiled into the kernel image, but there are thousands of hardware devices in the world, if all programs supporting them are compiled into the kernel image, the kernel will be too large, and these devices do not exist on every machine, in fact, there are dozens of commonly used ones. compiling them into the kernel image will also cause a lot of waste. Therefore, kernel developers have designed a mechanism to dynamically add kernel functions-the LKM and loadable kernel modules (LKM ), LKM can be dynamically loaded to the kernel as needed. Once loaded, it becomes a part of the kernel, this expands the features of the original kernel (readers can use/sbin/lsmod to view which LKM is loaded in the system ). The CONFIG_NTFS_FS = m mentioned above will enable the tool for compiling the kernel to compile programs supporting the NTFS file system into an LKM. If you change this statement to CONFIG_NTFS_FS = y, the program implementing the NTFS file system will be directly compiled into the kernel image.
?? In general, the Kernel configuration process is the process of editing the. config file. Of course, you can use any text editor to manually edit the. config file. However, if you decide to do so, I can only say that I would like to bless you. In. there are thousands of items that can be edited in the config file. to simplify the editing process, kernel developers have developed some tools for editing. config file. These tools are included in the source code package of the kernel, however, these tools must be compiled before they can be used for the first time (because the Linux kernel source code package cannot directly input binary files, after all, it must be used on various hardware platforms ). Therefore, before using these tools, you must install the corresponding development environment for ubuntu, such as the development environment of GTK or QT. I will not go into details about how to install these environments. These tools can be called by entering the make xxx command in the root directory of the kernel source code. The following describes the methods respectively.
?? 1) menuconfig, call the command: sudo make menuconfig. This is a character Interface Configuration tool. Although it is a character interface, it also provides a simple menu interface, which has the advantage of being able to configure the kernel without X Window. This tool requires the development environment of libncurses.
?? 2) qconf: Call the command: sudo make xconfig. This is a GUI Configuration Tool Based on QT. This tool is intuitive and easy to use. A development environment with QT is required.
?? 3) gconf: Call the command: sudo make gconfig. Similar to the above, it is only based on GTK, so the GTK development environment is required.
??
?? I recommend using qconf for these three tools. Because menuconfig is not intuitive enough, gconf has bugs and gconf in the latest 2.6.20 kernel cannot be used successfully, it always pops up an empty form and does not respond. I don't know why.
?? Before using the tool mentioned above for configuration, you must prepare one. config file template, because. too many entries can be edited in the config file, most of which are related to the driver. If you perform configuration one by one, it takes a lot of effort (Frankly speaking, I have never had this experience, because there are too many drivers, and I don't know what is useful or useless ). Therefore, before configuration, you should find a template and focus on editing important configuration entries. There are some good templates in the/boot directory of ubuntu, such as/boot/config-2.6.17-11-generic, you just need to copy the file to the root directory of your kernel source code and rename it. config. In addition, note that in qconf, most entries can be in three states: Check, dot, and no check. The three statuses correspond to each other. = y, = m, = n in the config file, that is, directly compiled into the kernel image, compiled into LKM, indefinite macros or not compiled.
??
?? Next I will introduce the configuration items that I think are important to you one by one (most of them are related to desktop performance ). The name of each entry below is represented by its full path in the gconf menu.
??
?? 1) General setup --> Cpuset support:
?? This entry is y or n, and the CONFIG_CPUSETS macro is defined when y is used. We recommend that you do not select this option. This feature is mainly used for the NUMA architecture and SMP architecture with a large number of logic CPUs. Enabling this feature will waste some memory and will not help the average person's desktop environment.
??
?? 2) Processor type and features --> your Ric multi-processing support:
?? This entry is y or n. If it is y, the CONFIG_SMP macro is defined. Check this option to make the Kernel support symmetric multi-processor. We recommend that you select this option, because most of the latest CPUs support dual-core or hyper-threading. Even if you are using a single CPU, it is hard to ensure that you upgrade it one day :).
??
?? 3) Processor type and features --> Processor family
?? This is a single-choice entry to specify a specific CPU model for optimization. You should select it with caution. If you select an incorrect option, the kernel may not work properly. For example, if you select Athlon/Duron/K7, the kernel uses 3 DNow when performing memcpy! Version with optimized instruction sets. Which of the following is a rough classification of the common CPUs on the market:
??
?? CPU for AMD:
?? A) Sempron/Duron/Athlon: Select Athlon/Duron/K7.
?? B) Sempron64/Athlon64/Athlon64 X 2/Opteron (haolong): Select Opteron/Athlon64/Hammer/K8.
?? C) Older than the above CPUs: Select K6/K6-II/K6-III. (Of course, if your CPU is K5, you have to choose 586/K5/5x86/6x86/6 x86MX .)
??
?? CPU for INTEL:
?? A) Pentium 2: Select Pentium-II/celon (pre-Coppermine)
?? B) Pentium 3: Select Pentium-III/celon (Coppermine)/Pentium-III Xeon
?? C) Pentium 4/Pentium D/Sai Yang D: Select Pentium-4/celon (P4-based)/Pentium-4 M/older Xeon
?? D) Core 2: Select Core 2/newer Xeon
?? NOTE: If your CPU is Sai Yang (except for Sai Yang D), you must first confirm whether it is based on P2, P3 or P4. Generally, it is based on P4 when the clock speed is higher than 1g, those with a size greater than MB but less than 1 GB are based on P3, while those with a size greater than MB are based on P2. In addition, you also need to distinguish between the GPU Based on P3, P4, or Core 2.
??
?? 4) Processor type and features --> Generic x86 support
?? This entry is y or n. When y is used, the CONFIG_X86_GENERIC macro is defined to optimize the x86 architecture. For example, when the CONFIG_X86_GENERIC macro is defined (of course, The CONFIG_X86_TSC macro also needs to be defined, which depends on the previous Processor family selection .), The get_cycles () function in the kernel uses TSC (time stamp counter) to obtain the cycles value. This option must be checked.
??
?? 5) Processor type and features --> Maximum number of CPUs
?? This entry is a numeric macro (NR_CPUS, range: 2-255), which determines the maximum number of logical CPUs supported by the kernel. Setting this number appropriately can save some memory for your kernel, because many data structures in the kernel are allocated based on the size of NR_CPUS, even if your existing logical CPU is less than NR_CPUS, the space will be allocated, resulting in waste. How many logical CPUs do you have? For example, if your system is a single CPU but supports Hyper-threading, the number of logical CPUs is 2. If your system is a dual CPU, each CPU supports dual-core, so the number of logical CPUs is 4. Generally, you should set this value to greater than or equal to the number of logical CPUs in your system. Considering that most people should still use a single CPU system, we recommend that you set this value to 4 because some INTEL CPUs currently support both dual-core and hyper-threading, in addition, INTEL also launched four-core CPU, AMD should soon launch four-core CPU, therefore, setting this value to 4 is to protect your memory for friends with less than 4 logical CPUs in the near future.
??
?? 6) Processor type and features --> SMT (Hyperthreading) schedures support
?? This entry is y or n. If it is y, the CONFIG_SCHED_SMT macro is defined. It is defined to provide a good scheduling function for CPU that supports hyper-threading. For example, if a system has two CPUs and each CPU supports hyper-threading, there are four logical CPUs in the system. We will mark these four CPUs as C00, C01, C10, and C11, c00 and C01 are two hardware threads on one physical CPU, while C10 and C11 are two hardware threads on the other physical CPU. Assume that two threads are running in the system at a certain time. If the CONFIG_SCHED_SMT macro is not defined, the kernel may schedule the two threads to C00 and C01 respectively, however, this is not optimized because C00 and C01 are two hardware threads on the physical CPU, which share a lot of hardware resources, as a result, the resources of the system cannot be fully utilized when two threads are running. When the CONFIG_SCHED_SMT macro is defined, the scheduler of the kernel schedules these two threads to the logical CPUs of different physical CPUs, such as C00 and C10.
?? At first glance, it seems that as long as your CPU supports hyper-threading, you should select this option, but I don't think so. For example, if your system is single-CPU and supports hyper-threading, The CONFIG_SCHED_SMT macro has no significance for improving the scheduling effect (of course, if I understand the kernel scheduler correctly :)), in addition, defining the CONFIG_SCHED_SMT macro also adds additional overhead to scheduling.
?? My suggestion is: when your CPU supports hyper-threading, it is necessary to select this option only when your system has multiple CPUs or supports multiple cores.
??
?? 7) Processor type and features --> Multi-core schedures support
?? This entry is y or n. If it is y, the CONFIG_SCHED_MC macro is defined. Its role is similar to the CONFIG_SCHED_SMT mentioned above, except that it targets multiple cores ). It is recommended that you select this option only when your system has multiple physical CPUs. For example, the CPU of my home machine is single AMD Athlon 64X2 4200 +, although it is dual-core, but only one physical CPU, I do not need to define this macro.
??
?? 8) Processor type and features --> Preemption Model
?? This is a single-choice entry. It is an option that has great significance for Desktop response capabilities. I strongly recommend that you select Preemptible Kernel (Low-Latency Desktop) and select this option to define the CONFIG_PREEMPT macro, indicates that this Kernel supports the Preemptible Kernel feature. To highlight its importance, I will use an example to briefly introduce the concept of a preemptible kernel: Suppose there are two threads running in a system (assuming there is only one logical CPU, one is thread H and the other is thread L. The dynamic priority of thread H is higher than that of thread L. At a certain time point, thread H is blocked because it waits for the keyboard response, at this time, the kernel will schedule the thread L to run it, and assume that it enters the kernel space for some reason during the process of thread L running (this mainly refers to the system call or exception ), after L enters the kernel, the user presses the keyboard, and the keyboard is interrupted, causing thread H to enter the ready state from the blocking state, then, according to the normal logic, the CPU should be immediately handed over to thread H (because thread H has a high dynamic priority), so that thread H can immediately perform operations after user buttons. At this time, if the system supports the preemptible kernel feature, linux will indeed do the same as the logic just now, but if it does not support the preemptible kernel feature, then thread H cannot be executed immediately. It must wait until thread L completes all the work in the kernel space and returns to the user space for scheduling, this will cause a scheduling delay for thread H, which may be as many as several hundred milliseconds at the maximum, and a latency of several hundred milliseconds may lead to slow response. Therefore, preemptible kernel features are very important for desktop systems that take response capabilities as an important indicator (as far as I know, windows and mac OS x kernels are both preemptible kernels ), therefore, we strongly recommend that you select this option.
?? Preemptible kernel features are available from 2.6.x kernel. I have enabled this feature from fedora core 2 to fedora core 6 and ubuntu 6.10 self-compiled kernels, I have never encountered any stability problems, so please rest assured. In addition, do not confuse preemptible kernels with preemptive multitasking. From the very beginning, linux supports preemptible multitasking.
??
?? 9) Processor type and features --> Preempt The Big Kernel Lock
?? If this entry is y or n, the CONFIG_PREEMPT_BKL macro is defined. This macro is defined to be able to be preemptible and scheduled by other high-priority threads when a thread occupies the Big Kernel Lock. This feature is also used to improve the response capability of the desktop system. We recommend that you select this feature.
??
?? 10) Processor type and features --> High Memory Support
?? This is a single-choice entry. It is used to configure Linux Kernel support for high memory. This entry is difficult to explain and I will not elaborate on it. My suggestion is: If your physical memory is less than or equal to 896 MB, and there is no possibility of memory upgrade in the short term, you should choose off; if the memory is larger than MB or it may be upgraded to a memory larger than MB and smaller than 4 GB, select 4 GB. If your memory is larger than 4 GB, you should choose 64 GB in principle, however, to make full use of your system resources, we recommend that you install ubuntu x86_64.
??
?? 11) Processor type and features --> Allocate 3rd-level pagetables from highmem
?? This entry is y or n, and the CONFIG_HIGHPTE macro is defined when y is used. This macro function is also difficult to explain, so I will not elaborate on it. Note that this macro makes sense only when 4 GB or 64 GB is selected for the previous entry. My suggestion is: If your physical memory exceeds MB, do not select this option. For example, if you only have 1 GB of memory, I think it is unnecessary; however, it is necessary to select a larger number, for example, 2 GB memory.
??
?? 12) Processor type and features --> Timer frequency
?? This is another single-choice entry. After the selection is complete, a macro named HZ will be defined. This is a digital Macro. Currently, in the 2.6.20 kernel, this number can be 100,250,300 or 1000. This number determines the number of clock interruptions per second. Each clock interruption requires many things to be handled. However, in terms of desktop performance, its frequency determines the accuracy of the kernel timer and the user space timer. The larger the number, the higher the timer precision, and the higher the overhead used to handle timer interruptions. However, to improve the multimedia performance of the desktop system, we recommend that you set this entry to 1000 HZ. Of course, if you think your CPU performance is not high enough, you can also consider HZ_250 or HZ_300 (of course, performance is not an absolute criterion, I think there is no problem when selecting 1000 HZ for a CPU with a clock speed higher than 1 GB .).
??
?? 13) File systems --> Ext3 journalling file system support
?? This entry is y, m, or n. This entry determines the kernel's support for the Ext3 file system. We have mentioned the meaning of y/m/n. My suggestion is: if you use a large number of Ext3 file systems, select "y" (that is, check the qconf file to directly compile the Ext3 support code into the kernel image ); otherwise, select m (that is, mark the dot in qconf to compile the code supporting Ext3 into an LKM ).
?? So why choose "y" when using Ext3 in large quantities? This is because LKM will be loaded to the non-linear ing area of the kernel space when needed. The page tables in this area are dynamic and need to be synchronized between different processes. In addition, once a process is switched, the cache (TLB) of the page table items describing the region will be flushed, resulting in a reduction in the performance of accessing the same LKM after the process is switched; if the code is directly compiled into the kernel image, the code will be located in the linear ing area of the kernel space, and the page table items in this area are global, the cache is not flushed after the process is switched, thus improving the performance.
?? Similarly, if you use a large number of other file systems (such as Reiserfs), you can also select the corresponding entries as y.
??
?? 14) File systems --> DOS/FAT/NT Filesystems --> NTFS file system support
?? This entry is y, m, or n. This entry has nothing to do with desktop performance, but I guess most people are linux/windows dual systems. To be able to access the NTFS file system, remember to select m or y. In addition, it is worth mentioning that there is a sub-entry NTFS file system support under this entry. This entry can only be y or n, and NTFS_RW macro is defined for y, define the macro so that the module can write data to the NTFS file system. Note that for the early 2.6.x kernel, this write operation is not safe. In 2.6.20, the write operation is safe, but only the existing files can be written, in addition, the file length cannot be changed, which makes it useless. Therefore, we recommend that you do not select this entry.
??
?? 15) Kernel hacking --> Kernel debugging --> Use 4Kb for kernel stacks instead of 8Kb
?? This entry is y or n. Define the CONFIG_4KSTACKS macro for y. This feature reduces the core stack of each thread from 8 KB to 4 kb. When an external interruption occurs, an IRQ stack is prepared for each logical CPU to compensate for the loss caused by the reduction of the core stack. The advantage of this feature is that the memory usage is reduced when there are a large number of threads in the system, and more importantly, the size of a page in the i386 architecture is 4 kb, each 4 kb allocation reduces the memory fragmentation caused by page allocator allocation pages in the kernel. The disadvantage is that additional operations to switch the stack will occur when the page is interrupted. I only recommend that you enable this option if you have less memory and need to run a large number of threads at the same time.
??
?? Here, all the important items I can think of are listed. I deeply feel that my understanding of the Linux kernel is far from enough, in particular, I am deeply ashamed that I have not provided any useful suggestions for specific device configurations! In addition, please note that there are still many items that must be selected that I have not listed (for example, General setup --> Configure standard kernel features (for small systems) --> Enable futex support), but these entries have little to do with the desktop performance, or as mentioned above. the config file template is almost certainly already selected, so I will not mention it.
?? In fact, the main purpose of writing this article is not only to provide a reference for new users, but also hope it can play a leading role, this allows experts in the forum to share their experiences on Kernel configuration, so that we can all learn and make progress together.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.