Linux Kernel overview, Linux kernel Overview

Source: Internet
Author: User

Linux Kernel overview, Linux kernel Overview

Linux Kernel learning notes.

Unix

Unix has a history of 40, but computer scientists still regard it as the largest and most outstanding System in the existing operating system. It has become a legend and remains well known after time.

In 1973, after the Unix system was rewritten in C language, a large number of Unix-derived versions began to emerge. Many companies migrated unix to new models, developers are constantly enhancing system functions in their own ways. The Unix system is simple in design and provides source code at release, so many groups have further developed it. UC Berkeley is one of the most influential. On the basis of BSD, many manufacturers also launched their own unix, such as SunOS, HP-UX and so on. In 1991, linus published its Unix on the Internet. Since then, linux has started. Linux soon attracted a large number of developers and hackers to modify and improve its code. Thanks to its open source nature, Linux has quickly become an open-source project jointly developed by many people.

Operating System and Kernel

The operating system includes kernel, device driver, boot program, command line shell, and basic system tools. The kernel is the core of the operating system and is responsible for hardware device management and system resource allocation. The kernel is generally in the system state, with protected memory space and all permissions to access hardware devices. This system state and protected space are collectively referred to as the kernel space. In the user space, applications can only see part of the system resources they are allowed to access. They can only use certain system functions, and cannot directly access hardware or access the kernel to allocate memory to others, there are also some other restrictions. The application passes throughSystem CallCommunicates with the kernel to allow the kernel to complete different tasks on behalf of it.

The kernel is also responsible for managing system hardware devices. When a hardware device wants to communicate with the system, it sends an asynchronous interrupt signal to interrupt the processor and then interrupt the kernel. The interrupt usually corresponds to an interrupt number. The kernel searches for the corresponding interrupt service program through the interrupt number, and calls the program to respond to and handle the interrupt. The interrupt service program runs in a context that is unrelated to all processes and specifically processes the interrupt, to ensure that the interrupt service program can respond to and process the interrupt request immediately and exit quickly.

Single Kernel and micro kernel

The operating system kernel can be divided into two main camps: single kernel and micro kernel. A single kernel is implemented as a large process and runs in a separate address space. It features high performance. The microkernel is not implemented as a separate large process. It is divided into multiple independentProcessWhich featuresProcessIt runs independently to avoid the disaster of one module. Compared with the design of a single kernel, it has more inter-module communication mechanisms and other links, while a single kernel does not have the overhead for these messages. Therefore, most microkernel-based systems allow most or all of the functionsProcessAll of them run in the kernel, so that you can directly call the function to eliminate frequent context switches. The following are typical examples of the micro-kernel. Linux is a single kernel, but it draws on the essence of the micro kernel. Linux is a modular, multi-threaded operating system and the kernel itself can be scheduled.

Kernel version number

Major version number. Minor version number. Revision version number

The minor version number indicates whether the kernel is a stable version or a development version. If the number is an even number, this version is a stable version. If the number is an odd number, it is a development version.

Obtain source code

Official Website: www.kernel.org

Repository address: git.kernel.org

Compile the kernel

Because the kernel has never been configured, the default configuration is used to compile the kernel. It is said that this default configuration is the Linus configuration.

$make defconfig 

To reduce the output information during compilation, use the following command:

$make > .. /detritus

In this way, if you want to view the compilation information, you can view the file. Of course, you can directly $ make>/dev/null to redirect useless information.

Install Kernel
% make modules_install

The above command can install all compiled modules to the correct home directory. During compilation, a system. map File is generated in the root directory of the kernel code. This is a symbol table.

Kernel Development

Kernel development has high performance requirements. Kernel development cannot access the C library or the standard C header file. The gnu c must be used for kernel development. For the kernel, the complete C library (or even a subset) is too large and inefficient. However, most common C-library functions have been implemented in the kernel. The Linux kernel uses both the C language and the assembly language. It is generally used in close proximity to the underlying layer or strict execution time requirements. GCC supports the use of the asm () command to embed reporting code in C.

Conditional branch Optimization

When Condition Selection statements frequently or rarely appear, you can optimize the condition branch according to the branch declaration statement before compiling. Example:

/* Mark a condition as a branch that rarely occurs. */If (unlikely (err )){...}

Make sure that most of the current conditions are true. If you are correct, the program performance will be improved. Otherwise, the performance will be reduced.

No memory Protection Mechanism

If your program attempts to perform an illegal memory access, the kernel will find this error and end the process. However, if the kernel itself illegally accesses the memory, it will be difficult to control the consequences, because there is nothing else to monitor the kernel. In addition, the memory in the kernel is not paged.

Extension

The kernel has the highest permissions for the entire system. There are still many precautions for kernel development. You can learn more in this 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.