Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to treat the user space and kernel space of Linux operating system

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to treat the user space and kernel space of the Linux operating system". It is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to treat the user space and kernel space of the Linux operating system".

As the central core processing unit, CPU, in addition to the continuous innovation and progress of the production process, also needs to be balanced in terms of data processing and response speed. Anyone with a little basic principle of microcomputer knows that CPU of Intel X86 system provides four privileged modes ring0~ring3, among which ring0 privilege * * and ring3 privilege * *. The main purpose of this distinction is to protect resources. generally speaking, the resources to be protected are nothing more than "memory, Icancano port and the ability to execute special machine instructions". At any time, x86 CPU runs in a certain privileged mode. Similarly, there are seven operation modes for CPU of ARM system, namely: user mode (usr), fast interrupt mode (fiq), interrupt mode (irq), management mode (svc), system mode (sys), data access termination mode (abt) and undefined instruction termination mode (und). Except for the user mode, the other 6 working modes belong to the privileged mode, while in the privileged mode, except for the system mode, the other five modes are also called abnormal modes.

So what does this feature of the underlying hardware CPU have to do with the user mode and kernel mode that we're going to discuss? Let's go back to the source to correct our understanding of the operating system. Every teacher who teaches the operating system course will tell you that the so-called operating system is a software system that uniformly manages hardware resources and provides users with business interfaces. Generally speaking, the operating system should be able to manage your CPU and memory, drive your hard drive, manage your network card and monitor, and then respond correctly when you click the mouse and hit the keyboard. Is it popular enough?

So the question is, take CPU as an example, if you are an operating system designer, how do you deal with the differences between different CPU architectures (such as Intel, ARM, or AMD, MIPS, etc.)? Of course, this problem is not something that ordinary people can hold. The Daniel senior who developed the Dujiangyan operating system in the CU forum is really worthy of our admiration and admiration. To continue our topic, that is to say, different operating systems are different in dealing with the differentiation of CPU architecture. some operating systems provide mechanisms such as user mode and kernel mode (such as linux), while others have no distinction between user mode and kernel mode (such as vxWorks). The latter is not within the scope of our discussion. Interested children's shoes can go to google on their own.

Take the Linux system and Intel x86 CPU as an example, Linux uses ring0 mode to run kernel-state code, ring3 to run user-mode code, ring1 and ring2 are not used. 32 the addressable range of the operating system is 0~4GB, so the Linux system divides it into two parts: user space and kernel space:

Among them, the user space occupies the low 3GB space, ranging from 0x00000000 to 0xBFFFFFFFF of the virtual address, the kernel space occupies the high 1GB space, and the virtual address ranges from 0xC0000000 to 0xFFFFFFFF.

The kernel space stores the entire kernel code and all kernel modules, as well as the data maintained by the kernel. When a user runs a program, the process created by the program is initially run in user space. When it wants to perform actions such as sending data over the network, it must be completed by calling write, send and other system functions. These system calls will call the code in the kernel to complete the user's request operation. Then CPU must switch from ring3 to ring0, and then enter the kernel address space to execute the code to complete the operation. After completion, switch back to ring3 and back to user mode.

Therefore, we can see that if the operating system provides user mode and kernel mode, the programs in user mode can not manipulate the data in the kernel address space at will, which has a certain role of security protection; at the same time, there is a slight sacrifice in real-time. That is to say, as long as there is nothing wrong with the kernel code, errors in user-space programs and BUG generally do not cause the system to crash, improving the robustness of the system.

From this point of view, the kernel is really "dragging", and Linux also provides some mechanisms for communication between user space and kernel space, so that we can develop more efficient programs. But it is important to remember that a small mistake in the kernel can cause the entire system to crash, so you must be very careful when developing kernel programs.

The above is all the contents of the article "how to treat the user space and kernel space of the Linux operating system". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report