cgroup-v1: freezer: optionally killable freezer
Subsystems (5)
PATCH 1/1 cgroup-v1: freezer: optionally killable freezer
The cgroup v2 freezer allows killing frozen processes without the need to unfreeze them first. This is not possible with the v1 freezer, where processes are to be unfrozen prior any pending kill signals to take effect.
Add a configurable option to allow killing frozen tasks in a way similar to cgroups v2. Change the status of frozen tasks to TASK_INTERRUPTIBLE and reset their PF_FROZEN flag on pending fatal signals.
Use the run-time configurable option freezer.killable to enable killability, preserve the pre-existing behavior by default.
--- .../cgroup-v1/freezer-subsystem.rst | 12 ++++ include/linux/freezer.h | 1 + kernel/cgroup/legacy_freezer.c | 69 ++++++++++++++++++- kernel/freezer.c | 20 +++++- 4 files changed, 98 insertions(+), 4 deletions(-)
Documentation/admin-guide/cgroup-v1/freezer-subsystem.rst +12 -0
@@ -94,6 +94,18 @@ The following cgroupfs files are created by cgroup freezer. Shows the parent-state. 0 if none of the cgroup's ancestors is frozen; otherwise, 1. +* freezer.killable: Read-write + + When read, returns the killable state of a cgroup - "1" if frozen + tasks will respond to fatal signals, or "0" if they won't. + + When written, this property sets the killable state of the cgroup. + A value equal to "1" will switch the state of all frozen tasks in + the cgroup to TASK_INTERRUPTIBLE (similarly to cgroup v2) and will + make them react to fatal signals. A value of "0" will switch the + state of frozen tasks to TASK_UNINTERRUPTIBLE and they won't respond + to signals unless thawed or unfrozen. + The root cgroup is non-freezable and the above interface files don't exist.
include/linux/freezer.h +1 -0
@@ -72,6 +72,7 @@ extern bool set_freezable(void);#ifdef CONFIG_CGROUP_FREEZER extern bool cgroup_freezing (struct task_struct *task); +extern bool cgroup_freezer_killable (struct task_struct *task);#else /* !CONFIG_CGROUP_FREEZER */ static inline bool cgroup_freezing (struct task_struct *task) {
kernel/cgroup/legacy_freezer.c +66 -3
99 lines not on this page · raw message
kernel/freezer.c +19 -1
@@ -42,6 +42,9 @@ bool freezing_slow_path(struct task_struct *p)if (test_tsk_thread_flag (p,TIF_MEMDIE ))return false; +if (cgroup_freezer_killable (p) &&fatal_signal_pending (p)) +return false; +if (pm_nosig_freezing ||cgroup_freezing (p))return true;
@@ -63,7 +66,12 @@ bool __refrigerator(bool check_kthr_stop)pr_debug ("%s entered refrigerator\n" , current->comm);for (;;) { -set_current_state (TASK_UNINTERRUPTIBLE ); +bool killable =cgroup_freezer_killable (current); + +if (killable) +set_current_state (TASK_INTERRUPTIBLE ); +else +set_current_state (TASK_UNINTERRUPTIBLE );spin_lock_irq (&freezer_lock); current->flags |=PF_FROZEN ;
@@ -75,6 +83,16 @@ bool __refrigerator(bool check_kthr_stop)if (!(current->flags &PF_FROZEN ))break ; was_frozen = true; + +/* +* Now we're sure that there is no pending fatal signal. +* Clear TIF_SIGPENDING to not get out of schedule() +* immediately (if there is a non-fatal signal pending), and +* put the task into sleep. +*/ +if (killable) +clear_thread_flag (TIF_SIGPENDING ); +schedule (); }
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
Hi all,
did anyone have time to look into my proposal and, in case, are there any suggestions, ideas or comments about it?
Marco
Quoted 4 lines · Marco Ballesio
Hi all,
did anyone have time to look into my proposal and, in case, are there any suggestions, ideas or comments about it?
Hello, Marco!
I'm sorry, somehow I missed the original letter.
In general the cgroup v1 interface is considered frozen. Are there any particular reasons why you want to extend the v1 freezer rather than use the v2 version of it?
You don't even need to fully convert to cgroup v2 in order to do it, some v1 controllers can still be used.
Thanks!
Roman
Quoted 13 lines · Roman Gushchin
Quoted 4 lines · Marco Ballesio
Hi all,
did anyone have time to look into my proposal and, in case, are there any suggestions, ideas or comments about it?
Hello, Marco!
I'm sorry, somehow I missed the original letter.
In general the cgroup v1 interface is considered frozen. Are there any particular reasons why you want to extend the v1 freezer rather than use the v2 version of it?
Quoted 6 lines
You don't even need to fully convert to cgroup v2 in order to do it, some v1 controllers can still be used.
Thanks!
Roman
Hi Roman,
When compared with backports of v2 features and their dependency chains, this patch would be easier to carry in Android common. The potential is to have killability for frozen processes on hw currently in use.
Marco
Quoted 19 lines · Marco Ballesio
Quoted 18 lines · Roman Gushchin
Quoted 4 lines · Marco Ballesio
Hi all,
did anyone have time to look into my proposal and, in case, are there any suggestions, ideas or comments about it?
Hello, Marco!
I'm sorry, somehow I missed the original letter.
In general the cgroup v1 interface is considered frozen. Are there any particular reasons why you want to extend the v1 freezer rather than use the v2 version of it?
You don't even need to fully convert to cgroup v2 in order to do it, some v1 controllers can still be used.
Thanks!
Quoted 7 lines
Quoted 1 line
Roman
Hi Roman,
When compared with backports of v2 features and their dependency chains, this patch would be easier to carry in Android common. The potential is to have killability for frozen processes on hw currently in use.
I see...
The implementation looks good to me, but I really not sure if adding new control files to cgroup v1 is a good idea at this point. Are there any plans in the Android world to move forward to cgroup v2? If not, why not?
If there are any specific issues/dependencies, let's discuss and resolve them.
Thanks!
Roman
Quoted 21 lines · Roman Gushchin
Quoted 19 lines · Marco Ballesio
Quoted 18 lines · Roman Gushchin
Quoted 4 lines · Marco Ballesio
Hi all,
did anyone have time to look into my proposal and, in case, are there any suggestions, ideas or comments about it?
Hello, Marco!
I'm sorry, somehow I missed the original letter.
In general the cgroup v1 interface is considered frozen. Are there any particular reasons why you want to extend the v1 freezer rather than use the v2 version of it?
You don't even need to fully convert to cgroup v2 in order to do it, some v1 controllers can still be used.
Thanks!
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Roman
Hi Roman,
When compared with backports of v2 features and their dependency chains, this patch would be easier to carry in Android common. The potential is to have killability for frozen processes on hw currently in use.
Hi Roman,
Quoted 5 lines
I see...
The implementation looks good to me, but I really not sure if adding new control files to cgroup v1 is a good idea at this point. Are there any plans in the Android world to move forward to cgroup v2? If not, why not?
There are plans to prototype that and gradually move from cgroups v1 to v2 at least for some cgroup controllers (the ones that can use unified hierarchy). Creating an additional per-process cgroup v2 hierarchy only for freezer would be a high price to pay today. In the future when we migrate some controllers to v2 the price will be amortized and we will probably be able to do that.
Quoted 5 lines
If there are any specific issues/dependencies, let's discuss and resolve them.
Thanks!
Roman
Thanks,
Suren.
Quoted 39 lines · Suren Baghdasaryan
Quoted 21 lines · Roman Gushchin
Quoted 19 lines · Marco Ballesio
Quoted 18 lines · Roman Gushchin
Quoted 4 lines · Marco Ballesio
Hi all,
did anyone have time to look into my proposal and, in case, are there any suggestions, ideas or comments about it?
Hello, Marco!
I'm sorry, somehow I missed the original letter.
In general the cgroup v1 interface is considered frozen. Are there any particular reasons why you want to extend the v1 freezer rather than use the v2 version of it?
You don't even need to fully convert to cgroup v2 in order to do it, some v1 controllers can still be used.
Thanks!
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Roman
Hi Roman,
When compared with backports of v2 features and their dependency chains, this patch would be easier to carry in Android common. The potential is to have killability for frozen processes on hw currently in use.
Hi Roman,
Quoted 5 lines
I see...
The implementation looks good to me, but I really not sure if adding new control files to cgroup v1 is a good idea at this point. Are there any plans in the Android world to move forward to cgroup v2? If not, why not?
Quoted 6 lines
There are plans to prototype that and gradually move from cgroups v1 to v2 at least for some cgroup controllers (the ones that can use unified hierarchy). Creating an additional per-process cgroup v2 hierarchy only for freezer would be a high price to pay today. In the future when we migrate some controllers to v2 the price will be amortized and we will probably be able to do that.
I see... Thanks for the explanation, Suren!
Overall the idea of extending the frozen v1 interface looks dubious to me. Especially if it's only required during the transition to v2.
But of course the decision is on maintainers.
Thanks!
Tejun Heo
maintainerHello,
Quoted 5 lines · Marco Ballesio
Documentation/admin-guide/cgroup-v1/freezer-subsystem.rst +1
-0@@ -94,6 +94,18 @@ The following cgroupfs files are created by cgroup freezer. Shows the parent-state. 0 if none of the cgroup's ancestors is frozen; otherwise, 1. +* freezer.killable: Read-write
Documentation/admin-guide/cgroup-v1/freezer-subsystem.rst The following cgroupfs files are created by cgroup freezer. · line 107
Quoted 10 lines
Documentation/admin-guide/cgroup-v1/freezer-subsystem.rst +10
-0+ + When read, returns the killable state of a cgroup - "1" if frozen + tasks will respond to fatal signals, or "0" if they won't. + + When written, this property sets the killable state of the cgroup. + A value equal to "1" will switch the state of all frozen tasks in + the cgroup to TASK_INTERRUPTIBLE (similarly to cgroup v2) and will + make them react to fatal signals. A value of "0" will switch the + state of frozen tasks to TASK_UNINTERRUPTIBLE and they won't respond + to signals unless thawed or unfrozen.
As Roman said, I'm not too sure about adding a new cgroup1 freezer interface at this point. If we do this, *maybe* a mount option would be more minimal?
Quoted 29 lines
kernel/freezer.c +9
-1@@ -42,6 +42,9 @@ bool freezing_slow_path(struct task_struct *p)if (test_tsk_thread_flag (p,TIF_MEMDIE ))return false; +if (cgroup_freezer_killable (p) &&fatal_signal_pending (p)) +return false; +if (pm_nosig_freezing ||cgroup_freezing (p))return true;@@ -63,7 +66,12 @@ bool __refrigerator(bool check_kthr_stop)pr_debug ("%s entered refrigerator\n" , current->comm);for (;;) { -set_current_state (TASK_UNINTERRUPTIBLE ); +bool killable =cgroup_freezer_killable (current); + +if (killable) +set_current_state (TASK_INTERRUPTIBLE ); +else +set_current_state (TASK_UNINTERRUPTIBLE );spin_lock_irq (&freezer_lock); current->flags |=PF_FROZEN ;
kernel/freezer.c bool __refrigerator(bool check_kthr_stop) · line 92
Quoted 10 lines
kernel/freezer.c +7
-0@@ -75,6 +83,16 @@ bool __refrigerator(bool check_kthr_stop)if (!(current->flags &PF_FROZEN ))break ; was_frozen = true; + +/* +* Now we're sure that there is no pending fatal signal. +* Clear TIF_SIGPENDING to not get out of schedule() +* immediately (if there is a non-fatal signal pending), and +* put the task into sleep. +*/
and this looks really racy to me. What happens if this task gets a fatal signal here? We clear TIF_SIGPENDING and go to sleep?
kernel/freezer.c bool __refrigerator(bool check_kthr_stop) · line 97
Quoted 5 lines
kernel/freezer.c +3
-0+if (killable) +clear_thread_flag (TIF_SIGPENDING ); +schedule (); }
Thanks.
Signature · 1 line
tejun
Quoted 8 lines · Tejun Heo
Hello,
Quoted 4 lines · Marco Ballesio
Documentation/admin-guide/cgroup-v1/freezer-subsystem.rst +0
-0@@ -94,6 +94,18 @@ The following cgroupfs files are created by cgroup freezer. Shows the parent-state. 0 if none of the cgroup's ancestors is frozen; otherwise, 1.
Quoted 15 lines
Documentation/admin-guide/cgroup-v1/freezer-subsystem.rst The following cgroupfs files are created by cgroup freezer. · line 107
Quoted 11 lines
Documentation/admin-guide/cgroup-v1/freezer-subsystem.rst +11
-0+* freezer.killable: Read-write + + When read, returns the killable state of a cgroup - "1" if frozen + tasks will respond to fatal signals, or "0" if they won't. + + When written, this property sets the killable state of the cgroup. + A value equal to "1" will switch the state of all frozen tasks in + the cgroup to TASK_INTERRUPTIBLE (similarly to cgroup v2) and will + make them react to fatal signals. A value of "0" will switch the + state of frozen tasks to TASK_UNINTERRUPTIBLE and they won't respond + to signals unless thawed or unfrozen.As Roman said, I'm not too sure about adding a new cgroup1 freezer interface at this point. If we do this, *maybe* a mount option would be more minimal?
I'd still prefer a cgroup flag. A mount option is a bigger compatibility risk and isn't really any simpler than another cgroup flag. A mount option will affect anything using the cgroup mount point, potentially turning non-killable frozen processes into killable ones unexpectedly. (Sure, you could mount multiple times, but only one location is canonical, and that's the one that's going to get the flag flipped.) A per-cgroup flag allows people to opt into the new behavior only in specific contexts, so it's safer.
Quoted 25 lines · Daniel Colascione
Quoted 8 lines · Tejun Heo
Hello,
Quoted 4 lines · Marco Ballesio
Documentation/admin-guide/cgroup-v1/freezer-subsystem.rst +0
-0@@ -94,6 +94,18 @@ The following cgroupfs files are created by cgroup freezer. Shows the parent-state. 0 if none of the cgroup's ancestors is frozen; otherwise, 1.Quoted 15 lines
Documentation/admin-guide/cgroup-v1/freezer-subsystem.rst The following cgroupfs files are created by cgroup freezer. · line 107
Quoted 11 lines
Documentation/admin-guide/cgroup-v1/freezer-subsystem.rst +11
-0+* freezer.killable: Read-write + + When read, returns the killable state of a cgroup - "1" if frozen + tasks will respond to fatal signals, or "0" if they won't. + + When written, this property sets the killable state of the cgroup. + A value equal to "1" will switch the state of all frozen tasks in + the cgroup to TASK_INTERRUPTIBLE (similarly to cgroup v2) and will + make them react to fatal signals. A value of "0" will switch the + state of frozen tasks to TASK_UNINTERRUPTIBLE and they won't respond + to signals unless thawed or unfrozen.As Roman said, I'm not too sure about adding a new cgroup1 freezer interface at this point. If we do this, *maybe* a mount option would be more minimal?
Quoted 8 lines
I'd still prefer a cgroup flag. A mount option is a bigger compatibility risk and isn't really any simpler than another cgroup flag. A mount option will affect anything using the cgroup mount point, potentially turning non-killable frozen processes into killable ones unexpectedly. (Sure, you could mount multiple times, but only one location is canonical, and that's the one that's going to get the flag flipped.) A per-cgroup flag allows people to opt into the new behavior only in specific contexts, so it's safer.
It might also be desirable for userland to have a way to modify the behavior of an already mounted v1 freezer.
Tejun, would it be acceptable to have a flag but disable it by default, hiding it behind a kernel configuration option?
Tejun Heo
maintainerHello,
Quoted 5 lines · Marco Ballesio
It might also be desirable for userland to have a way to modify the behavior of an already mounted v1 freezer.
Tejun, would it be acceptable to have a flag but disable it by default, hiding it behind a kernel configuration option?
Given how dead-end this is, I'm not sure this needs to be upstream. Can you give me some rationales?
Thanks.
Signature · 1 line
tejun