Performance of Linux User threads in the kernel

Source: Internet
Author: User
The performance of Linux User threads in the kernel-general Linux technology-Linux programming and kernel information. The following is a detailed description. Original: SoHo

This article attempts to explain the principle of user thread creation and running in Linux, which does not involve kernel threads.

Structure of the kernel management thread

Task_struct
All thread-related information, huge

Thread_info
The thread has a small amount of related information, which can be put into a cache line

Kernel stack
The stack of a thread during kernel running, generally 2 pages, 8 KB

The thread_info structure is stored on the top of the kernel stack, and the bottom address of the stack is (thread_info + THREAD_SIZE-40). It is assumed that the stack is upgraded from the bottom to the top.

First thread
The second chicken was copied from the first chicken, and the third chicken was copied from the second chicken. The question is: Where did the first chicken come from?

In Linux, The task_struct of the first thread is init_task, thread_info is init_thread_info, and the kernel stack is init_stack. All of them are directly reserved space and directly initialized.

Child thread
All threads in the system are descendants of init_task. They get task_struct, thread_info, and kernel stack by applying for memory, and initialize them with the corresponding information of their parent process, but change a few of its unique variables, such as PID.

Fork and exec
Fork is used to create the task_struct, thread_info, and kernel stack of sub-processes, but the code executed is the same as that of the parent process.

If the sub-process wants to execute other code, it needs to call exec

Other

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.