Lines Matching +full:suspend +full:- +full:to +full:- +full:ram
11 kernel threads are controlled during hibernation or system-wide suspend (on some
17 There are three per-task flags used for that, PF_NOFREEZE, PF_FROZEN
21 suspend state as well as before a hibernation image is created (in what follows
22 we only consider hibernation, but the description also applies to suspend).
25 freeze_processes() (defined in kernel/power/process.c) is called. A system-wide
26 variable system_freezing_cnt (as opposed to a per-task flag) is used to indicate
27 whether the system is to undergo a freezing operation. And freeze_processes()
29 fake signal to all user space processes, and wakes up all the kernel threads.
30 All freezable tasks must react to that by calling try_to_freeze(), which
31 results in a call to __refrigerator() (defined in kernel/freezer.c), which sets
32 the task's PF_FROZEN flag, changes its state to TASK_UNINTERRUPTIBLE and makes
35 to as 'the freezer' (these functions are defined in kernel/power/process.c,
41 if the task is to be frozen and makes the task enter __refrigerator().
44 signal-handling code, but the freezable kernel threads need to call it
47 that combine interruptible sleep with checking if the task is to be frozen and
61 If a freezable kernel thread fails to call try_to_freeze() after the freezer has
69 order to clear the PF_FROZEN flag for each frozen task. Then, the tasks that
74 -------------------------------------------------------------------------
77 - freezes only userspace tasks
80 - freezes all tasks (including kernel threads) because we can't freeze
84 - thaws only kernel threads; this is particularly useful if we need to do
86 userspace tasks, or if we want to postpone the thawing of userspace tasks
89 - thaws all tasks (including kernel threads) because we can't thaw userspace
104 Generally speaking, there is a couple of reasons to use the freezing of tasks:
106 1. The principal reason is to prevent filesystems from being damaged after
108 filesystems, so if there are any modifications made to filesystem data and/or
109 metadata on disks, we cannot bring them back to the state from before the
111 filesystem-related information that must be consistent with the state of the
112 on-disk data and metadata after the system memory state has been restored
114 usually making them almost impossible to repair). We therefore freeze
115 tasks that might cause the on-disk filesystems' data and metadata to be
119 to happen, they have to be freezable.
121 2. Next, to create the hibernation image we need to free a sufficient amount of
122 memory (approximately 50% of available RAM) and we need to do that before
125 to allocate additional memory and we prevent them from doing that by
127 should not allocate substantial amounts of memory from their .suspend()
130 3. The third reason is to prevent user space processes and some kernel threads
144 s2ram with some devices in the middle of a DMA. So we want to be able to
147 ways to do so.
152 Still, there are kernel threads that may want to be freezable. For example, if
153 a kernel thread that belongs to a device driver accesses the device directly, it
154 in principle needs to know when the device is suspended, so that it doesn't try
155 to access it at that time. However, if the kernel thread is freezable, it will
156 be frozen before the driver's .suspend() callback is executed and it will be
160 4. Another reason for freezing tasks is to prevent user space processes from
161 realizing that hibernation (or suspend) operation takes place. Ideally, user
162 space processes should not notice that such a system-wide operation has
164 (or resume from suspend). Unfortunately, in the most general case this
165 is quite difficult to achieve without the freezing of tasks. Consider,
167 running. Since we need to disable nonboot CPUs during the hibernation,
169 changed and may start to work incorrectly because of that.
171 V. Are there any problems related to the freezing of tasks?
178 TASK_UNINTERRUPTIBLE state) that needs to be done by freezable kernel thread B
182 Second, there are the following two problems related to the freezing of user
189 (https://lists.linux-foundation.org/pipermail/linux-pm/2007-May/012309.html).
191 The problem 1. seems to be fixable, although it hasn't been fixed so far. The
193 hibernation (and suspend) notifiers (in that case, though, we won't be able to
197 There are also problems that the freezing of tasks tends to expose, although
198 they are not directly related to it. For example, if request_firmware() is
200 fail, because the user land process that should respond to the request is frozen
201 at this point. So, seemingly, the failure is due to the freezing of tasks.
205 is used. Consequently, the problem is not really related to the freezing of
208 A driver must have all firmwares it may need in RAM before suspend() is called.
209 If keeping them is not practical, for example due to their size, they must be
210 requested early enough using the suspend notifier API described in
211 Documentation/driver-api/pm/notifiers.rst.
213 VI. Are there any precautions to be taken to prevent freezing failures?
218 First of all, grabbing the 'system_transition_mutex' lock to mutually exclude a
219 piece of code from system-wide sleep such as suspend/hibernation is not
221 suspend/hibernation notifiers to achieve mutual exclusion. Look at the
222 CPU-Hotplug code (kernel/cpu.c) for an example.
225 deemed necessary, it is strongly discouraged to directly call
226 mutex_[un]lock(&system_transition_mutex) since that could lead to freezing
227 failures, because if the suspend/hibernate code successfully acquired the
228 'system_transition_mutex' lock, and hence that other entity failed to acquire
230 consequence, the freezer would not be able to freeze that task, leading to
233 However, the [un]lock_system_sleep() APIs are safe to use in this scenario,
234 since they ask the freezer to skip freezing this task, since it is anyway
236 released only after the entire suspend/hibernation sequence is complete. So, to
243 /sys/power/pm_freeze_timeout controls how long it will cost at most to freeze