PM / Freezer: Remove the "userspace only" constraint from freezer[_do_not]_count()
Subsystems (3)
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
@@ -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 (); }/*
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
@@ -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
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()andfreezer_do_not_count()don't have the restriction that they are effective only when called by userspace processes, use them inlock_system_sleep()andunlock_system_sleep()instead of open-coding their parts.Signed-off-by Srivatsa S. Bhat <[email protected]>
Signature · 1 line
tejun
Quoted 8 lines · Srivatsa S. Bhat
At present, the functions
freezer_count()andfreezer_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.
Suggested-by Oleg Nesterov <[email protected]>Suggested-by Tejun Heo <[email protected]>Signed-off-by Srivatsa S. Bhat <[email protected]>
Thanks.
Signature · 1 line
tejun
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.
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_VFORKis not used by kthreads. It is actually used, but only by the non-freezeable workqueue threads, so the patch is fine.Reviewed-by Oleg Nesterov <[email protected]>
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
@@ -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 (); }/*
Rafael J. Wysocki
AppliedQuoted 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_VFORKis not used by kthreads. It is actually used, but only by the non-freezeable workqueue threads, so the patch is fine.Reviewed-by Oleg Nesterov <[email protected]>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()andfreezer_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
Suggested-by Oleg Nesterov <[email protected]>Suggested-by Tejun Heo <[email protected]>Acked-by Tejun Heo <[email protected]>Reviewed-by Oleg Nesterov <[email protected]>Signed-off-by Srivatsa S. Bhat <[email protected]>
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@@ -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 (); }/*