In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
How to carry out Kernel space analysis in Linux CPU, I believe that many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
To put it simply, Kernel space is the running space of the Linux kernel, and User space is the running space of user programs. For security, they are isolated, and even if the user's program crashes, the kernel is not affected.
Kernel space can execute arbitrary commands and call all the resources of the system; User space can only perform simple operations, can not directly call system resources, and must pass through the system interface (also known as system call) to issue instructions to the kernel.
Str = "my string" / / user space x = x + 2file.write (str) / / switch to kernel space y = x + 4 / / switch back to user space
In the above code, the first and second lines are simple assignment operations that are performed in User space. If you need to write to the file on the third line, you have to switch to Kernel space, because the user cannot write the file directly and must be arranged through the kernel. The fourth line is the assignment operation again, so switch back to User space.
To see how CPU time is allocated between User space and Kernel Space, you can use the top command. Its third line of output is CPU time allocation statistics.
There are eight statistical indicators in this line.
Of these, the first item 24.8 us (abbreviation for user) is the percentage of time CPU spent in User space, and the second item 0.5 sy (abbreviation for system) is the percentage of time spent in Kernel space.
Casually talk about the meaning of the other six indicators.
Abbreviation for ni:niceness, the percentage of time CPU spent in the nice process (low priority)
Abbreviation for id:idle, the percentage of time CPU spent in idle processes. The lower this value, the busier CPU is.
The abbreviation of wa:wait, the percentage of time that CPU waits for external I wa:wait O, during which CPU cannot do anything else, but does not perform operations. This value is too high to indicate that there is something wrong with the external device.
Abbreviation for hi:hardware interrupt, percentage of time that CPU responds to hardware interrupt requests
Abbreviation for si:software interrupt, the percentage of time that CPU responds to software interrupt requests
Abbreviation for st:stole time, which is valid only for virtual machines and indicates the percentage of CPU time allocated to the current virtual machine that was stolen by other virtual machines on the same physical machine
If you want to see the time-consuming of a single program, you usually use the time command.
Add the time command before the program name, and three lines of statistics will be displayed by default after the program has been executed.
Real: the total time the program runs from start to finish, which is the time that the user can perceive, including the time when CPU switches to perform other tasks.
User: the time the program was executed in User space
Sys: the time the program was executed in Kernel space
The sum of user and sys, in general, should be less than real. But in the case of multicore CPU, these two metrics reflect the total time consumed by all CPU, so the sum of them may be greater than real.
[reference link]
User space vs kernel space
Using the Linux Top Command
Understanding Linux CPU stats
What do 'real',' user' and 'sys' mean in the output of time (1)?
Quote from: https://note.youdao.com/share/?id=799c86ffc9de49ff383b639d155a446e&type=note#/
First of all, let me briefly explain what the customer sees. In the third line of the figure below, top calculates the overall usage of Cpu, using eight indicators. These eight indicators are: user space process (us), kernel space process (sy), user space process with high nice value (ni), idle (id), idle waiting io (wa), interrupt top half (hi), interrupt bottom half (si), and steal time (st). In theory, the sum of these eight indicators should be 100%. Among the eight indicators, id and wa are the statistics of Cpu's idle time, and the smaller the sum of these two values, the busier Cpu is. The sum of id and wa of this server is 0, so the Cpu utilization of this server is 100%, of which ni accounts for the largest proportion.
In addition to the third row of Cpu overall statistical metrics, top will count the Cpu usage from the process dimension, that is, the CPU column. Because this server is 16 cores, the Cpu utilization of each process (multi-thread) can exceed 100%, and the sum of Cpu utilization of all processes cannot exceed 1600% (the average is 100% per core).
After reading the above, have you mastered the method of how to analyze Kernel space in Linux CPU? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.