In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
What are the actions that cause thread switching in linux? In response to this problem, this article gives the corresponding analysis and answer, hoping to help more friends who want to solve this problem find a simpler and easier way.
Linux uses a one-to-one threading model, and there is very little difference between user thread switching and kernel thread switching. At the same time, if we ignore the overhead caused by the user voluntarily giving up the execution right (yield) of the user thread, we only need to consider the overhead of kernel thread switching.
Note that this is only a simplification to aid understanding. In fact, the user thread library does a lot of work in the process of scheduling and synchronization of user threads, and this part of the overhead cannot be ignored.
For example, JVM interpretation of Thread#yield(): If the underlying OS does not support the semantics of yield, the JVM lets the user thread spin to the end of the time slice, and the thread switches passively to achieve a similar effect.
What causes thread switching
time slice rotation
thread blocks
Thread voluntarily relinquishes time slice
direct overhead
Direct overhead is caused by the thread switch itself, inevitable and inevitable.
Switching between user state and kernel state
Thread switching can only be done in kernel mode. If the current user is in user mode, it will inevitably cause a switch between user mode and kernel mode. (What is the specific cost of "switching between user state and kernel state")
context switch
As mentioned above, thread (or process) information needs to be stored in a task_struct. When switching threads, it is necessary to cut the task_struct of the old thread out of the kernel and cut in the new thread, bringing about context switching. In addition, switch registers, program counters, thread stacks (including operation stacks, data stacks), etc. are required.
thread scheduling algorithm
Thread scheduling algorithms need to manage thread status, wait conditions, etc. If scheduled according to priority, they also need to maintain priority queues. If thread switching is frequent, the cost should not be underestimated.
overhead
Overhead is a side effect of direct overhead and depends on system implementation and user code implementation.
cache miss
Switching processes requires new logic to be implemented. If the address spaces accessed by the two are not close, this will cause a cache miss, depending on the system implementation and user code implementation. If the cache of the system is large, the impact of cache miss can be reduced; if the address space of the user thread accessing the data is close, the cache miss rate of itself is also relatively low.
About linux thread switching caused by the operation to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
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.