Linux Kernel thread

Source: Internet
Author: User

MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font:
Minor-Fareast "> A kernel thread is a process directly started by the kernel itself. The kernel thread actually delegates the kernel function to an independent process and runs it in parallel with other processes in the system (in fact, it also runs in parallel with the kernel itself ), kernel threads are often called kernel "daemon processes ". They are mainly used to execute the following tasks:

MSO-bidi-font-family: wingdings "> L; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> periodically synchronizes the modified memory page with the page source block device.

MSO-bidi-font-family: wingdings "> L; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> If the Memory Page is rarely used, it is written to the swap zone.

MSO-bidi-font-family: wingdings "> L; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> Manage delayed actions

MSO-bidi-font-family: wingdings "> L; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> implements transaction logs of the file system.

Minor-Fareast; MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast;
MSO-Hansi-theme-Font: minor-Fareast ">

MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font:
Minor-Fareast "> There are two main types of kernel threads:

; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast;
MSO-bidi-font-family:; MSO-bidi-theme-Font: minor-Fareast "> 1.; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> the thread waits until it is started, until the kernel request thread executes a specific operation.

; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast;
MSO-bidi-font-family:; MSO-bidi-theme-Font: minor-Fareast "> 2.; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> the thread runs at periodic intervals after it is started, detects the usage of a specific resource and takes action when the usage exceeds or falls below the preset limit.

Minor-Fareast; MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast;
MSO-Hansi-theme-Font: minor-Fareast ">

MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font:
Minor-Fareast "> the kernel thread is generated by the kernel itself and has the following features:

; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast;
MSO-bidi-font-family:; MSO-bidi-theme-Font: minor-Fareast "> 1. MSO; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> they are executed in the CPU management mode, not the user mode.

; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast;
MSO-bidi-font-family:; MSO-bidi-theme-Font: minor-Fareast "> 2.; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> they can only access the kernel part of the virtual address space (all addresses higher than task_size), but cannot access the user space.

MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font:
Minor-Fareast ">

Minor-Fareast; MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast;
MSO-Hansi-theme-Font: minor-Fareast "> task_struct; MSO-ascii-theme-Font: minor-Fareast; MSO-Fareast-font-family:; MSO-Fareast-theme-Font:
Minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> the process descriptor contains two fields related to the process address space: mm and active_mm. For common user processes, MM points to the user space of the virtual address space. For kernel threads, mm is null.

Minor-Fareast; MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast;
MSO-Hansi-theme-Font: minor-Fareast ">

Minor-Fareast; MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast;
MSO-Hansi-theme-Font: minor-Fareast "> active_mm; MSO-ascii-theme-Font: minor-Fareast; MSO-Fareast-font-family:; MSO-Fareast-theme-Font:
Minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> is mainly used for optimization. Because the kernel thread is not related to any specific user-layer process, the kernel does not need to replace the user-layer part of the virtual address space. Just keep the old settings. Because the kernel thread may be executed by any user-layer process before, the content in the user space is random in nature, and the kernel thread cannot modify its content, so the MM is set to null, if the user process is switched out, the kernel stores the mm of the original process in the active_mm of the new kernel thread. If the process running after the kernel thread is the same as before, the kernel does not need to modify the user space address table, and the information in TLB is still valid; switch and clear the corresponding TLB data only when the process executed after the kernel thread is different from the previous user-layer process.

Minor-Fareast; MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast;
MSO-Hansi-theme-Font: minor-Fareast ">

MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font:
Minor-Fareast "> kernel threads can be implemented in two ways:

; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast;
MSO-bidi-font-family:; MSO-bidi-theme-Font: minor-Fareast "> 1.; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> transmits a function to kernel_thread, this function then helps the kernel to call daemonize and has been converted to a daemonize process, including the following operations:

MSO-bidi-font-family: wingdings "> L; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> This function releases all resources of its parent process. Otherwise, these resources will be locked until the thread ends.

MSO-bidi-font-family: wingdings "> L; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> blocks signal reception.

MSO-bidi-font-family: wingdings "> L; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> uses init as the parent process of the daemon.

; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast;
MSO-bidi-font-family:; MSO-bidi-theme-Font: minor-Fareast "> 2.; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font: minor-Fareast "> the more common method to create a kernel is the auxiliary function kthread_create, this function creates a new kernel thread. The first thread is stopped and needs to be started with wake_up_process. Or use kthread_run. Unlike kthread_create, kthread_create wakes up a new thread immediately after it is created.

Minor-Fareast; MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast;
MSO-Hansi-theme-Font: minor-Fareast ">

MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-theme-Font:
Minor-Fareast "> run the PS Fax command to view information about the kernel threads running in the system.

Minor-Fareast; MSO-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast;
MSO-Hansi-theme-Font: minor-Fareast ">

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.