Skip to contentSkip to conversation

PM / Freezer: Remove the "userspace only" constraint from freezer[_do_not]_count()

PATCH Applied Srivatsa S. Bhat 4 participants 7 messages Dec 6, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 PM / Freezer: Remove the "userspace only" constraint from freezer[_do_not]_count()

At present, the functions freezer_count() and freezer_do_not_count() impose the restriction that they are effective only for userspace processes. However, now, these functions have found more utility than originally intended by the commit which introduced it: ba96a0c8 (freezer:
fix vfork problem). And moreover, even the vfork issue does not need the above restriction in these functions, since they are anyway called by userspace processes.

So, modify these functions to make them work even for kernel threads, so that they can be used at other places in the kernel, where the userspace restriction doesn't apply.

---

 include/linux/freezer.h |   28 +++++++++++-----------------
 1 files changed, 11 insertions(+), 17 deletions(-)
include/linux/freezer.h +11 -17
index 30f06c2..7bcfe73 100644
@@ -67,33 +67,27 @@ static inline bool cgroup_freezing(struct task_struct *task)
  * appropriately in case the child has exited before the freezing of tasks is
  * complete.  However, we don't want kernel threads to be frozen in unexpected
  * places, so we allow them to block freeze_processes() instead or to set
- * PF_NOFREEZE if needed and PF_FREEZER_SKIP is only set for userland vfork
- * parents.  Fortunately, in the ____call_usermodehelper() case the parent won't
- * really block freeze_processes(), since ____call_usermodehelper() (the child)
- * does a little before exec/exit and it can't be frozen before waking up the
- * parent.
+ * PF_NOFREEZE if needed. Fortunately, in the ____call_usermodehelper() case the
+ * parent won't really block freeze_processes(), since ____call_usermodehelper()
+ * (the child) does a little before exec/exit and it can't be frozen before
+ * waking up the parent.
  */
 
-/*
- * If the current task is a user space one, tell the freezer not to count it as
- * freezable.
- */
+
+/* Tell the freezer not to count the current task as freezable. */
 static inline void freezer_do_not_count(void)
 {
-	if (current->mm)
-		current->flags |= PF_FREEZER_SKIP;
+	current->flags |= PF_FREEZER_SKIP;
 }
 
 /*
- * If the current task is a user space one, tell the freezer to count it as
- * freezable again and try to freeze it.
+ * Tell the freezer to count the current task as freezable again and try to
+ * freeze it.
  */
 static inline void freezer_count(void)
 {
-	if (current->mm) {
-		current->flags &= ~PF_FREEZER_SKIP;
-		try_to_freeze();
-	}
+	current->flags &= ~PF_FREEZER_SKIP;
+	try_to_freeze();
 }
 
 /*
#1 lore raw

PATCH 2/2 PM: Use the freezer_count() functions in [un]lock_system_sleep() APIs

Now that freezer_count() and freezer_do_not_count() don't have the restriction that they are effective only when called by userspace processes, use them in lock_system_sleep() and unlock_system_sleep() instead of open-coding their parts.

---

 include/linux/suspend.h |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
include/linux/suspend.h +3 -4
index 1f7fff4..906d62c 100644
@@ -6,6 +6,7 @@
 #include <linux/init.h>
 #include <linux/pm.h>
 #include <linux/mm.h>
+#include <linux/freezer.h>
 #include <asm/errno.h>
 
 #ifdef CONFIG_VT
@@ -380,16 +381,14 @@ static inline void unlock_system_sleep(void) {}
 
 static inline void lock_system_sleep(void)
 {
-	/* simplified freezer_do_not_count() */
-	current->flags |= PF_FREEZER_SKIP;
+	freezer_do_not_count();
 	mutex_lock(&pm_mutex);
 }
 
 static inline void unlock_system_sleep(void)
 {
 	mutex_unlock(&pm_mutex);
-	/* simplified freezer_count() */
-	current->flags &= ~PF_FREEZER_SKIP;
+	freezer_count();
 }
 #endif
 
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] PM: Use the freezer_count() functions in [un]lock_system_sleep() APIs

Quoted 6 lines · Srivatsa S. Bhat

Now that freezer_count() and freezer_do_not_count() don't have the restriction that they are effective only when called by userspace processes, use them in lock_system_sleep() and unlock_system_sleep() instead of open-coding their parts.

Signature · 1 line
tejun
Acked-by on v1 1/2
#3 lore raw
In reply to Srivatsa S. Bhat
Quoted 8 lines · Srivatsa S. Bhat

At present, the functions freezer_count() and freezer_do_not_count() impose the restriction that they are effective only for userspace processes. However, now, these functions have found more utility than originally intended by the commit which introduced it: ba96a0c8 (freezer:
fix vfork problem). And moreover, even the vfork issue does not need the above restriction in these functions, since they are anyway called by userspace processes.

Quoted 7 lines

So, modify these functions to make them work even for kernel threads, so that they can be used at other places in the kernel, where the userspace restriction doesn't apply.

Thanks.

Signature · 1 line
tejun
Reviewed-by on v1 1/2
#4 lore raw
In reply to Srivatsa S. Bhat
Quoted 4 lines · Srivatsa S. Bhat

And moreover, even the vfork issue does not need
the above restriction in these functions, since they are anyway called by userspace processes.

This looks a bit confusing, as if CLONE_VFORK is not used by kthreads. It is actually used, but only by the non-freezeable workqueue threads, so the patch is fine.

author Acked-by Tejun Heo Reviewed-by Oleg Nesterov
#5 lore raw
Quoted 6 lines · Oleg Nesterov
Quoted 4 lines · Srivatsa S. Bhat

And moreover, even the vfork issue does not need
the above restriction in these functions, since they are anyway called by userspace processes.

Quoted 6 lines

This looks a bit confusing, as if CLONE_VFORK is not used by kthreads. It is actually used, but only by the non-freezeable workqueue threads, so the patch is fine.

Thank you! I have updated the commit message by omitting the confusing part:

---
From: Srivatsa S. Bhat <[email protected]>
[PATCH 1/2] PM / Freezer: Remove the "userspace only" constraint from freezer[_do_not]_count()

At present, the functions freezer_count() and freezer_do_not_count() impose the restriction that they are effective only for userspace processes. However, now, these functions have found more utility than originally intended by the commit which introduced it: ba96a0c8 (freezer:
fix vfork problem). And moreover, even the vfork issue actually does not need the above restriction in these functions.

So, modify these functions to make them work even for kernel threads, so that they can be used at other places in the kernel, where the userspace restriction doesn't apply.

---

 include/linux/freezer.h |   28 +++++++++++-----------------
 1 files changed, 11 insertions(+), 17 deletions(-)
include/linux/freezer.h +11 -17
index 30f06c2..7bcfe73 100644
@@ -67,33 +67,27 @@ static inline bool cgroup_freezing(struct task_struct *task)
  * appropriately in case the child has exited before the freezing of tasks is
  * complete.  However, we don't want kernel threads to be frozen in unexpected
  * places, so we allow them to block freeze_processes() instead or to set
- * PF_NOFREEZE if needed and PF_FREEZER_SKIP is only set for userland vfork
- * parents.  Fortunately, in the ____call_usermodehelper() case the parent won't
- * really block freeze_processes(), since ____call_usermodehelper() (the child)
- * does a little before exec/exit and it can't be frozen before waking up the
- * parent.
+ * PF_NOFREEZE if needed. Fortunately, in the ____call_usermodehelper() case the
+ * parent won't really block freeze_processes(), since ____call_usermodehelper()
+ * (the child) does a little before exec/exit and it can't be frozen before
+ * waking up the parent.
  */
 
-/*
- * If the current task is a user space one, tell the freezer not to count it as
- * freezable.
- */
+
+/* Tell the freezer not to count the current task as freezable. */
 static inline void freezer_do_not_count(void)
 {
-	if (current->mm)
-		current->flags |= PF_FREEZER_SKIP;
+	current->flags |= PF_FREEZER_SKIP;
 }
 
 /*
- * If the current task is a user space one, tell the freezer to count it as
- * freezable again and try to freeze it.
+ * Tell the freezer to count the current task as freezable again and try to
+ * freeze it.
  */
 static inline void freezer_count(void)
 {
-	if (current->mm) {
-		current->flags &= ~PF_FREEZER_SKIP;
-		try_to_freeze();
-	}
+	current->flags &= ~PF_FREEZER_SKIP;
+	try_to_freeze();
 }
 
 /*
#6 lore raw
Quoted 33 lines · Srivatsa S. Bhat
Quoted 6 lines · Oleg Nesterov
Quoted 4 lines · Srivatsa S. Bhat

And moreover, even the vfork issue does not need
the above restriction in these functions, since they are anyway called by userspace processes.

Quoted 6 lines

This looks a bit confusing, as if CLONE_VFORK is not used by kthreads. It is actually used, but only by the non-freezeable workqueue threads, so the patch is fine.

Thank you! I have updated the commit message by omitting the confusing part:

---
From: Srivatsa S. Bhat <[email protected]>
[PATCH 1/2] PM / Freezer: Remove the "userspace only" constraint from freezer[_do_not]_count()

At present, the functions freezer_count() and freezer_do_not_count() impose the restriction that they are effective only for userspace processes. However, now, these functions have found more utility than originally intended by the commit which introduced it: ba96a0c8 (freezer:
fix vfork problem). And moreover, even the vfork issue actually does not need the above restriction in these functions.

So, modify these functions to make them work even for kernel threads, so that they can be used at other places in the kernel, where the userspace restriction doesn't apply.

Quoted 5 lines

Applied to linux-pm/linux-next ([2/2] too).

Thanks,
Rafael

Quoted 58 lines

---

 include/linux/freezer.h |   28 +++++++++++-----------------
 1 files changed, 11 insertions(+), 17 deletions(-)
include/linux/freezer.h +11 -17
index 30f06c2..7bcfe73 100644
@@ -67,33 +67,27 @@ static inline bool cgroup_freezing(struct task_struct *task)
  * appropriately in case the child has exited before the freezing of tasks is
  * complete.  However, we don't want kernel threads to be frozen in unexpected
  * places, so we allow them to block freeze_processes() instead or to set
- * PF_NOFREEZE if needed and PF_FREEZER_SKIP is only set for userland vfork
- * parents.  Fortunately, in the ____call_usermodehelper() case the parent won't
- * really block freeze_processes(), since ____call_usermodehelper() (the child)
- * does a little before exec/exit and it can't be frozen before waking up the
- * parent.
+ * PF_NOFREEZE if needed. Fortunately, in the ____call_usermodehelper() case the
+ * parent won't really block freeze_processes(), since ____call_usermodehelper()
+ * (the child) does a little before exec/exit and it can't be frozen before
+ * waking up the parent.
  */
 
-/*
- * If the current task is a user space one, tell the freezer not to count it as
- * freezable.
- */
+
+/* Tell the freezer not to count the current task as freezable. */
 static inline void freezer_do_not_count(void)
 {
-	if (current->mm)
-		current->flags |= PF_FREEZER_SKIP;
+	current->flags |= PF_FREEZER_SKIP;
 }
 
 /*
- * If the current task is a user space one, tell the freezer to count it as
- * freezable again and try to freeze it.
+ * Tell the freezer to count the current task as freezable again and try to
+ * freeze it.
  */
 static inline void freezer_count(void)
 {
-	if (current->mm) {
-		current->flags &= ~PF_FREEZER_SKIP;
-		try_to_freeze();
-	}
+	current->flags &= ~PF_FREEZER_SKIP;
+	try_to_freeze();
 }
 
 /*