![Roman Gushchin](/assets/img/avatar_default.png)
Cgroup v1 implements the freezer controller, which provides an ability to stop the workload in a cgroup and temporarily free up some resources (cpu, io, network bandwidth and, potentially, memory) for some other tasks. Cgroup v2 lacks this functionality. This patch implements freezer for cgroup v2. Cgroup v2 freezer tries to put tasks into a state similar to jobctl stop. This means that tasks can be killed, ptraced (using PTRACE_SEIZE*), and interrupted. It is possible to attach to a frozen task, get some information (e.g. read registers) and detach. It's also possible to migrate a frozen tasks to another cgroup. This differs cgroup v2 freezer from cgroup v1 freezer, which mostly tried to imitate the system-wide freezer. However uninterruptible sleep is fine when all tasks are going to be frozen (hibernation case), it's not the acceptable state for some subset of the system. Cgroup v2 freezer is not supporting freezing kthreads. If a non-root cgroup contains kthread, the cgroup still can be frozen, but the kthread will remain running, the cgroup will be shown as non-frozen, and the notification will not be delivered. * PTRACE_ATTACH is not working because non-fatal signal delivery is blocked in frozen state. There are some interface differences between cgroup v1 and cgroup v2 freezer too, which are required to conform the cgroup v2 interface design principles: 1) There is no separate controller, which has to be turned on: the functionality is always available and is represented by cgroup.freeze and cgroup.events cgroup control files. 2) The desired state is defined by the cgroup.freeze control file. Any hierarchical configuration is allowed. 3) The interface is asynchronous. The actual state is available using cgroup.events control file ("frozen" field). There are no dedicated transitional states. 4) It's allowed to make any changes with the cgroup hierarchy (create new cgroups, remove old cgroups, move tasks between cgroups) no matter if some cgroups are frozen. Signed-off-by: Roman Gushchin <guro@fb.com> Signed-off-by: Tejun Heo <tj@kernel.org> No-objection-from-me-by: Oleg Nesterov <oleg@redhat.com> Cc: kernel-team@fb.com
40 lines
1.6 KiB
C
40 lines
1.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_SCHED_JOBCTL_H
|
|
#define _LINUX_SCHED_JOBCTL_H
|
|
|
|
#include <linux/types.h>
|
|
|
|
struct task_struct;
|
|
|
|
/*
|
|
* task->jobctl flags
|
|
*/
|
|
#define JOBCTL_STOP_SIGMASK 0xffff /* signr of the last group stop */
|
|
|
|
#define JOBCTL_STOP_DEQUEUED_BIT 16 /* stop signal dequeued */
|
|
#define JOBCTL_STOP_PENDING_BIT 17 /* task should stop for group stop */
|
|
#define JOBCTL_STOP_CONSUME_BIT 18 /* consume group stop count */
|
|
#define JOBCTL_TRAP_STOP_BIT 19 /* trap for STOP */
|
|
#define JOBCTL_TRAP_NOTIFY_BIT 20 /* trap for NOTIFY */
|
|
#define JOBCTL_TRAPPING_BIT 21 /* switching to TRACED */
|
|
#define JOBCTL_LISTENING_BIT 22 /* ptracer is listening for events */
|
|
#define JOBCTL_TRAP_FREEZE_BIT 23 /* trap for cgroup freezer */
|
|
|
|
#define JOBCTL_STOP_DEQUEUED (1UL << JOBCTL_STOP_DEQUEUED_BIT)
|
|
#define JOBCTL_STOP_PENDING (1UL << JOBCTL_STOP_PENDING_BIT)
|
|
#define JOBCTL_STOP_CONSUME (1UL << JOBCTL_STOP_CONSUME_BIT)
|
|
#define JOBCTL_TRAP_STOP (1UL << JOBCTL_TRAP_STOP_BIT)
|
|
#define JOBCTL_TRAP_NOTIFY (1UL << JOBCTL_TRAP_NOTIFY_BIT)
|
|
#define JOBCTL_TRAPPING (1UL << JOBCTL_TRAPPING_BIT)
|
|
#define JOBCTL_LISTENING (1UL << JOBCTL_LISTENING_BIT)
|
|
#define JOBCTL_TRAP_FREEZE (1UL << JOBCTL_TRAP_FREEZE_BIT)
|
|
|
|
#define JOBCTL_TRAP_MASK (JOBCTL_TRAP_STOP | JOBCTL_TRAP_NOTIFY)
|
|
#define JOBCTL_PENDING_MASK (JOBCTL_STOP_PENDING | JOBCTL_TRAP_MASK)
|
|
|
|
extern bool task_set_jobctl_pending(struct task_struct *task, unsigned long mask);
|
|
extern void task_clear_jobctl_trapping(struct task_struct *task);
|
|
extern void task_clear_jobctl_pending(struct task_struct *task, unsigned long mask);
|
|
|
|
#endif /* _LINUX_SCHED_JOBCTL_H */
|