Documentation/power/freezing-of-tasks.rst

Source file repositories/reference/linux-study-clean/Documentation/power/freezing-of-tasks.rst

File Facts

System
Linux kernel
Corpus path
Documentation/power/freezing-of-tasks.rst
Extension
.rst
Size
12970 bytes
Lines
257
Domain
Support Tooling And Documentation
Bucket
Documentation
Inferred role
Support Tooling And Documentation: documentation
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (oom_reaper_list != NULL) {
			tsk = oom_reaper_list;
			oom_reaper_list = tsk->oom_reaper_list;
		}
		spin_unlock_irq(&oom_reaper_lock);

		if (tsk)
			oom_reap_task(tsk);
	}

(from mm/oom_kill.c::oom_reaper()).

If a freezable kernel thread is not put to the frozen state after the freezer
has initiated a freezing operation, the freezing of tasks will fail and the
entire system-wide transition will be cancelled.  For this reason, freezable
kernel threads must call try_to_freeze() somewhere or use one of the
wait_event_freezable() and wait_event_freezable_timeout() macros.

After the system memory state has been restored from a hibernation image and
devices have been reinitialized, the function thaw_processes() is called in
order to wake up each frozen task.  Then, the tasks that have been frozen leave
__refrigerator() and continue running.


Rationale behind the functions dealing with freezing and thawing of tasks
-------------------------------------------------------------------------

freeze_processes():
  - freezes only userspace tasks

freeze_kernel_threads():
  - freezes all tasks (including kernel threads) because we can't freeze
    kernel threads without freezing userspace tasks

thaw_kernel_threads():
  - thaws only kernel threads; this is particularly useful if we need to do
    anything special in between thawing of kernel threads and thawing of
    userspace tasks, or if we want to postpone the thawing of userspace tasks

thaw_processes():
  - thaws all tasks (including kernel threads) because we can't thaw userspace
    tasks without thawing kernel threads


III. Which kernel threads are freezable?
========================================

Kernel threads are not freezable by default.  However, a kernel thread may clear
PF_NOFREEZE for itself by calling set_freezable() (the resetting of PF_NOFREEZE
directly is not allowed).  From this point it is regarded as freezable
and must call try_to_freeze() or variants of wait_event_freezable() in a
suitable place.

IV. Why do we do that?
======================

Generally speaking, there is a couple of reasons to use the freezing of tasks:

1. The principal reason is to prevent filesystems from being damaged after
   hibernation.  At the moment we have no simple means of checkpointing
   filesystems, so if there are any modifications made to filesystem data and/or
   metadata on disks, we cannot bring them back to the state from before the
   modifications.  At the same time each hibernation image contains some
   filesystem-related information that must be consistent with the state of the
   on-disk data and metadata after the system memory state has been restored
   from the image (otherwise the filesystems will be damaged in a nasty way,
   usually making them almost impossible to repair).  We therefore freeze
   tasks that might cause the on-disk filesystems' data and metadata to be
   modified after the hibernation image has been created and before the
   system is finally powered off. The majority of these are user space

Annotation

Implementation Notes