In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly talks about "what is the method of freezing the Linux process". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the method of freezing the Linux process?"
Linux needs to freeze all processes before hibernation, and then unfreeze the process after sleep and wake up. Some problems in driver development may cause the freeze process to fail.
1 what is a process freeze
Process freeze technology (freezing of tasks) refers to placing user processes and some kernel threads in a "controllable" paused state when the system hibernate or suspend.
2 Why do you need freezing technology
Assuming that there is no freeze technology, the process can be paused at any schedulable point and will not be paused and migrated until cpu_down. This will cause a lot of problems for the system:
(1) it is possible to destroy the file system. Between hibernate image and cpu down created by the system, if a process is still modifying the contents of the file system, it will cause the file system not to be fully restored after the system is restored.
(2) it may cause the creation of hibernation image to fail. Creating a hibernation image requires enough memory space, but if there are still processes requesting memory during this period, it may cause the creation to fail.
(3) suspend and resume that may interfere with the equipment. Before cpu down, during device suspend, if the process was still accessing devices, especially contending resources, it was possible to cause device suspend exceptions.
(4) it is possible to cause the process-aware system to sleep. The ideal state of system hibernation is that all tasks are unaware of the hibernation process and automatically resume work after waking up, but some processes, such as a process that needs all cpu online to work properly, will work abnormally during hibernation if the process is not frozen.
3 code implementation framework
Frozen objects are entities in the kernel that can be scheduled for execution, including user processes, kernel threads, and work_queue. User processes can be frozen by default, which can be implemented by signal processing mechanism; kernel threads and work_queue cannot be frozen by default. A few kernel threads and work_queue specify the freezable flag when they are created. These tasks need to judge the freeze status, and actively suspend the operation when the system enters freezing.
Kernel threads can determine the freezing status by calling kthread_freezable_should_stop, and actively call _ _ refrigerator to enter the freeze; work_queue can determine the max_active attribute, if max_active=0, it cannot join the new work, and all work execution will be delayed.
There are three important global variables that mark the freeze status of the system: pm_freezing, system_freezing_cnt, and pm_nosig_freezing. If all 0 means that the system has not entered the freeze, system_freezing_cnt "0 indicates that the system has entered the freeze, pm_freezing=true indicates that the user process is frozen, and pm_nosig_freezing=true indicates that the kernel thread and workqueue are frozen. They are set in freeze_processes and freeze_kernel_threads and zeroed in thaw_processes and thaw_kernel_threads.
The fake_signal_wake_up function skillfully uses the signal processing mechanism, only sets the TIF_SIGPENDING bit of the task, but does not transmit any signal, and then wakes up the task; so when the task returns to the user state, it will enter the signal processing flow, check the freeze state of the system, and do the corresponding processing.
The code for the task to actively call try_to_freeze is as follows:
Static inline bool try_to_freeze_unsafe (void) {if (likely (! Freezing (current) / / check whether the system is in freezing state return false;return _ _ refrigerator (false); / / actively enter frozen} static inline bool freezing (struct task_struct * p) {if (likely (! Atomic_read (& system_freezing_cnt)) / / the system generally enters freezingreturn false;return freezing_slow_path (p);} bool freezing_slow_path (struct task_struct * p) {if (p-"flags & PF_NOFREEZE) / / whether the current process allows return false;if to be frozen (pm_nosig_freezing | | cgroup_freezing (p)) / / system freezes kernel threadsreturn true;if (pm_freezing & &! (P-"flags & PF_KTHREAD)) / / the system freezes the user process return true;return false;} into the frozen state until the recovery of the main function: bool _ refrigerator (bool check_kthr_stop) {. .. for (;;) {set_current_state (TASK_UNINTERRUPTIBLE); / / set process to UNINTERRUPTIBLE status spin_lock_irq (& freezer_lock); current- "flags | = PF_FROZEN; / / set frozen state if (! Freezing (current) | (check_kthr_stop & & kthread_should_stop ()) / / determine whether the system is still frozen. "flags & = ~ PF_FROZEN; / / if the system has been unfrozen, unfreeze spin_unlock_irq (& freezer_lock); if (! (current- "flags & PF_FROZEN)) / / if the freeze has been lifted, jump out of the loop and resume execution break;was_frozen = true;schedule ();}. .. . ..} at this point, I believe you have a deeper understanding of "what is the method of freezing the Linux process". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.