The composition of the Linux kernel, Wang Ming learning Learn

Source: Internet
Author: User
Tags ming

The composition of the Linux kernel

First, the Linux kernel source code directory structure

  1. Arch: Contains code related to hardware architecture, each of which occupies a corresponding directory, such as i386, ARM, PowerPC, MIPS, etc.
  2. Block: Blocks device driver I/O scheduling.
  3. Crypto: Commonly used encryption and hashing algorithms (such as AES, SHA, etc.), as well as some compression and CRC check algorithms.
  4. Documentation: Common explanations and annotations for each part of the kernel.
  5. Drivers: Device drivers, each of which consumes a subdirectory, such as char, block, net, MTD, I²c, and so on.
  6. FS: Various file systems supported, such as EXT, F at, NTFS, JFFS2, and so on.
  7. Include: header files, System-related header files are placed under the Include/linux subdirectory.
  8. INIT: Kernel initialization code.
  9. IPC: Code for interprocess communication. Kernel: The core part of the kernel, including process scheduling, timers, and so on, and a portion of the Peace station code is placed in the Arch/*/kernel directory.
  10. LIB: library file code.
  11. MM: Memory management code, and part of the platform-related code is placed in the ARCH/*/MM directory.
  12. NET: Network-related code, the realization of a variety of common network protocols.
  13. Scripts: Contains the script file used to configure the kernel.
  14. Security: mainly includes SELinux module.
  15. Drive core code and common device drivers for Sound:alsa, OSS Audio Devices.
  16. USR: cpio for packaging and compression are implemented.

Components of the 1.1Linux kernel

The Linux kernel consists of 5 subsystems, such as process scheduling (SCHED), memory Management (MMU), virtual file system (VFS), network Interface (NET), and interprocess communication (IPC).

1.1.1 Process Scheduling

Multiple processes in the Precision scheduling control system access the CPU so that multiple processes can be micro-serial in the CPU, macro-parallel execution. Process scheduling is at the center of the system, and other subsystems in the kernel rely on it because each subsystem needs to suspend or resume the process.

The Linux process switches between several states. In device-driven programming, when the requested resource is not met, the driver typically dispatches other processes to execute and causes the driver to go to sleep until the resource it requests is freed before it is awakened to a ready state. Sleep is divided into interrupted sleep and non-interrupted sleep, and the difference is that interrupted sleep wakes up when you receive a signal.

In a device driver, if you need several concurrently executed tasks, you can start the kernel thread, and the function that starts the kernel thread is:

  int kernel_thread (int (*FN) (void *), void * arg, unsigned long flags);

1.1.2 Memory Management

The primary role of memory management is to control multiple processes to safely share the main memory area. When the CPU provides a memory management unit (MMU), Linux memory management completes the conversion of virtual memory to physical memory for each process.

In general, each process of Linux has 4GB of memory space, 0~3GB belongs to user space, 3~4GB belongs to kernel space, kernel space has different processing methods for conventional memory, I/O device memory and high-end memory.

1.1.3 Virtual File system

The Linux virtual file system (VFS) hides a variety of hardware specifics, providing a unified interface for all devices. Moreover, it is independent of the individual file system, is an abstraction of the various file systems, it uses super block super blocks to store file system information, using index node inode to store the physical information of the file, using the directory entry dentry to store the logical information of the file.

1.1.4 Network Interface

Network interfaces provide standard access to various networks and support for a variety of network hardware. Network interface can be divided into network protocols and network drivers, the network protocol is responsible for the implementation of each possible network transport protocol, the network device driver is responsible for communication with the hardware devices, each of the possible hardware devices have a corresponding device driver.

1.1.5 Process Communication

Linux supports a variety of communication mechanisms between processes, including semaphores, shared memory, pipelines, and other mechanisms that can assist in multiple processes, mutually exclusive access to multiple resources, synchronization between processes, and message delivery.

The dependencies between the 5 components of the Linux kernel are as follows:

    1. Relationship between process scheduling and memory management: These two subsystems depend on each other. In a multi-channel program environment, the process must be created for the program, and the first thing to create a process is to load the program and data into memory.
    2. Relationship between interprocess communication and memory management: The interprocess communication subsystem relies on memory management to support the shared memory communication mechanism, which allows two processes to access a common area of memory in addition to their own private space.
    3. The relationship between a virtual file system and a network interface: the virtual file system uses a network interface to support network file systems (NFS) and also uses memory management to support RAMDISK devices.
    4. The relationship between memory management and virtual file systems: Memory management leverages the virtual file system to support switching, and the switching process (SWAPD) is periodically dispatched by the scheduler, which is the only reason for memory management to depend on process scheduling. When a process accesses a memory map that is swapped out, memory management makes a request to the file system while suspending the currently running process.

In addition to these dependencies, all subsystems in the kernel depend on some common resources. These resources include routines used by all subsystems, such as functions to allocate and free memory space, functions to print warnings or error messages, and system-provided debug routines.

Second, Linux kernel space and user space

Different operating modes (levels) are often implemented within the CPU

For example, ARM processors have the following 7 modes of operation:

    1. User mode (USR): Most applications run in user mode, and some protected system resources cannot be accessed when the processor is running in user mode.
    2. Fast Interrupt Mode (FIQ): For high-speed data transmission or justification.
    3. External interrupt mode (IRQ): Used for general interrupt reason.
    4. Management Mode (SVC): The protected mode used by the operating system.
    5. Data access termination mode (ABT): Enters this mode when data or instruction prefetching is terminated, and can be used for virtual storage and storage protection.
    6. System mode (SYS): Runs a privileged operating system task.
    7. No instruction Abort mode defined (und): Enter this mode when undefined instruction is executed, which can be used to support software emulation of hardware coprocessor.

For example: The X86 processor contains 4 different privileged levels, called Ring0~ring3. Under RING0, you can execute privileged-level directives, have access to any I/O devices, and Ring3 have many operational limitations.

The Linux system takes full advantage of this hardware feature of the CPU, but it uses only level two. In a Linux system, the kernel can do anything, while the application is prohibited from direct access to the hardware and unauthorized access to memory. For example, if you use the X86 processor, the user code runs at privileged level 3, and the system kernel code runs at privileged level 0.

The two nouns of kernel space and user space are used to differentiate between these two different states of program execution, which use different address spaces. Linux systems can only complete control transfers from user space to kernel space through system calls and hardware interrupts

The composition of the Linux kernel, Wang Ming learning Learn

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.