Linux kernel, this often hear, but do not know exactly what it is, do not feel very mysterious?

The Linux kernel is invisible, and we often don’t know what to do with things like that. This article will take you into the Linux kernel to see what it looks like in plain English.

The kernel is the core component of the Linux operating system, connecting applications upwards and dealing directly with hardware downwards. Its code is mainly written in C language and a little assembly language, and it can be adapted to a variety of different hardware architecture.

The kernel runs a series of concurrent processes and manages various resources on the hardware. Specifically, because the system’s resources are limited, the kernel allocates resources such as CPU time, memory space, network connections, and so on to each process.

Linux operating system architecture

The following figure shows a typical Linux operating system architecture.

The Linux operating system is divided into two parts:

  • The user space
  • The kernel space
1. User space

All user applications run in user space, not directly accessing hardware resources such as memory, but indirectly through the kernel. The GNU C library (Glibc) provides a mechanism for switching from user space to kernel space.

2. Kernel space

The kernel directly manages the CPU, memory, I/O devices, network devices and other peripherals of the system. It is divided into different modules to manage different operations of the system, such as file management, memory management, process management and so on.

User-space applications can access hardware resources by calling kernel-provided apis. For example, for file operations, we can call open(), read(), write() and so on.

The kernel directly manages the hardware and is independent of the hardware. It can be simply configured and run on Intel, ARM, Atemel and other chip architectures.

Major subsystems of the Linux kernel

According to the core functions of the kernel, the Linux kernel puts forward five subsystems, namely: system call, process management, memory management, file system, and network management, as shown below:

1. System Call Interface

System call interface. The process scheduling subsystem opens up the interface that needs to be provided to user space through the system call interface, while masking details that do not need to be cared for by user space programs.

SCI is actually a very useful function call multiplexing and demultiplexing service. You can find implementations of SCI in./ Linux /kernel, and architecture-dependent sections in./ Linux /arch.

2. Process Management

With so many processes in user space, keeping them organized is exactly what process management is all about. Each process needs to use CPU resources (such as CPU and memory), but CPU resources are limited, so it is impossible for a process to monopolize the resources.

Therefore, process management acts as the role of the administrator, it schedules all processes, when the need to choose the next process to run, the scheduling algorithm will choose the most need to run the process. If a process is waiting for other hardware resources, it will be suspended.

Therefore, the kernel uses CPU resources as fairly as possible for each process through a series of scheduling algorithms.

3. Memory Management

Memory management mainly provides access control over memory resources so that processes can safely share the memory resources of the machine. It provides a mapping relationship between physical memory and virtual memory, so that different processes can use the same virtual memory, and these same virtual memory can be mapped to different physical memory. This mapping is primarily done by the MMU.

In addition, memory management provides a virtual memory mechanism that allows processes to use more memory than is available to the system. Unused memory is stored in external non-volatile memory through the file system and retrieved back into memory when needed.

4. Virtual File System

The kernel hides the details of peripheral devices with different functions, such as hard disks, I/O devices, display devices, and so on, abstracting them into a unified file operation interface (open, Close, Read, write, and so on), known as “everything files.”

With the development of computer technology, there have been many file systems in history, such as FAT, FAT32, NTFS, EXT2, EXT3 and so on. To accommodate these file systems, the kernel abstracts them into a unified representation, which is the concept of a virtual file system.

Virtual file systems can be divided into logical file systems and device drivers. Logical file system refers to the file system supported by Linux, such as ext2 and FAT. Device driver refers to the device driver module written for each hardware controller.

5. Network Stack

The network subsystem in Linux kernel is mainly responsible for the management of various network devices, and the realization of various network protocol stacks, and finally realize the function of connecting other systems through the network.

The network interface provides access to various network standard protocols and supports various network hardware. Network interface can be divided into two parts: network protocol and network driver. The network protocol section is responsible for implementing every possible network transport protocol, the network device driver is responsible for communicating with the hardware device, and each possible hardware device has a corresponding device driver.

summary

The above is the Linux kernel some very basic knowledge, for the learning of the kernel there are very much content, is by no means an article can be written. Therefore, for the study of the kernel, you need to read more books, watch more videos, and do it yourself to practice, to really master.


Yesterday is a good xu public number operation anniversary day, originally wanted to send welfare yesterday, but yesterday’s article was too long, afraid of friends can not turn the last, so change to today.

In response to the readers’ support and help, I would like to offer you two benefits: 1. Kernel books; 2. Cash red envelopes.

1. Book giveaways

The kernel book is Linux Kernel Deep Parsing, sponsored by the asynchronous community, thanks to the support of the asynchronous community! This book is of high quality, and the price is 138 yuan more expensive, so 10 copies of this book are free. The books are described as follows:

Because I don’t want the person who really wants the book not to get it, but the person who just came to get it, so that the book doesn’t do its job. So in order to get books to people who really need them, the rules of book giving are as follows:

  1. Leave a comment in the comments section about why you want the book. To go to the heart, do not go to the wall oh;
  2. Invite your friends to like your comments, and the top 10 winners will win the prize.
  3. In order to prevent “likes”, friends with more than 100 likes must provide evidence of soliciting votes, or they will lose the award.
  4. The event starts now and ends at 8:00 PM on June 5. Winners need to contact Liang Xu to provide their address within 24 hours. Good xu has a number of wechat, contact one of them, there is no good xu wechat, please reply good xu two words in the public background can get the latest wechat of Good Xu.
2. Cash red envelopes

Yes, it is so rude, directly send red envelopes! Click the link below to collect, first come, first served! As liang Xu is still relatively poor, can not send a big red envelope, please forgive me!


Finally, recently, many friends asked me for Linux learning roadmap, so I stayed up for a month in my spare time according to my own experience, and sorted out an e-book. Whether you are interviewing or self-improvement, I believe will help you! The directory is as follows:

Free to everyone, just ask everyone to point to me!

Ebook | Linux development learning roadmap

Also hope to have a small partner can join me, do this e-book more perfect!

Have a harvest? Hope the old iron people come to a triple whammy, give more people to see this article

Recommended reading:

  • Dry goods | programmers advanced architect necessary resources free of charge
  • Artifact | support resource site search