* [PATCH] Threads shouldn't inherit PF_NOFREEZE
@ 2005-10-18 19:29 Alan Stern
2005-10-19 21:01 ` [linux-pm] " Nigel Cunningham
0 siblings, 1 reply; 3+ messages in thread
From: Alan Stern @ 2005-10-18 19:29 UTC (permalink / raw)
To: Andrew Morton, Rusty Russell, Linus Torvalds, Pavel Machek
Cc: Kernel development list, Linux-pm mailing list
The PF_NOFREEZE process flag should not be inherited when a thread is
forked. This patch (as585) removes the flag from the child.
This problem is starting to show up more and more as drivers turn to the
kthread API instead of using kernel_thread(). As a result, their kernel
threads are now children of the kthread worker instead of modprobe, and
they inherit the PF_NOFREEZE flag. This can cause problems during system
suspend; the kernel threads are not getting frozen as they ought to be.
Alan Stern
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
---
What I said above may not be quite true. For all I know, there may be
threads which rely on inheriting PF_NOFREEZE from their parent. But it
should not be inherited by default.
Index: usb-2.6/kernel/fork.c
===================================================================
--- usb-2.6.orig/kernel/fork.c
+++ usb-2.6/kernel/fork.c
@@ -848,7 +848,7 @@ static inline void copy_flags(unsigned l
{
unsigned long new_flags = p->flags;
- new_flags &= ~PF_SUPERPRIV;
+ new_flags &= ~(PF_SUPERPRIV | PF_NOFREEZE);
new_flags |= PF_FORKNOEXEC;
if (!(clone_flags & CLONE_PTRACE))
p->ptrace = 0;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [linux-pm] [PATCH] Threads shouldn't inherit PF_NOFREEZE
2005-10-18 19:29 [PATCH] Threads shouldn't inherit PF_NOFREEZE Alan Stern
@ 2005-10-19 21:01 ` Nigel Cunningham
2005-10-20 14:42 ` Alan Stern
0 siblings, 1 reply; 3+ messages in thread
From: Nigel Cunningham @ 2005-10-19 21:01 UTC (permalink / raw)
To: Alan Stern
Cc: Andrew Morton, Rusty Russell, Linus Torvalds, Pavel Machek,
Linux-pm mailing list, Kernel development list
Hi Alan.
On Wed, 2005-10-19 at 05:29, Alan Stern wrote:
> The PF_NOFREEZE process flag should not be inherited when a thread is
> forked. This patch (as585) removes the flag from the child.
>
> This problem is starting to show up more and more as drivers turn to the
> kthread API instead of using kernel_thread(). As a result, their kernel
> threads are now children of the kthread worker instead of modprobe, and
> they inherit the PF_NOFREEZE flag. This can cause problems during system
> suspend; the kernel threads are not getting frozen as they ought to be.
>
> Alan Stern
I have this in kthread instead, so that multithreaded userspace
processes only need to have NOFREEZE set once (before forking). Yes, I
have one that fits this scenario - I'm working on a userspace storage
maanger, which will setup and tear down a network connection at
appropriate times during a suspend-to-disk cycle. The initial version is
based on nbd and uses two threads because the one that sets up storage
blocks in a syscall as Pavel & others have written it.
Anyway, I agree that the general need you're trying to address is real.
Regards,
Nigel
>
>
> Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
>
> ---
>
> What I said above may not be quite true. For all I know, there may be
> threads which rely on inheriting PF_NOFREEZE from their parent. But it
> should not be inherited by default.
>
> Index: usb-2.6/kernel/fork.c
> ===================================================================
> --- usb-2.6.orig/kernel/fork.c
> +++ usb-2.6/kernel/fork.c
> @@ -848,7 +848,7 @@ static inline void copy_flags(unsigned l
> {
> unsigned long new_flags = p->flags;
>
> - new_flags &= ~PF_SUPERPRIV;
> + new_flags &= ~(PF_SUPERPRIV | PF_NOFREEZE);
> new_flags |= PF_FORKNOEXEC;
> if (!(clone_flags & CLONE_PTRACE))
> p->ptrace = 0;
>
>
> ______________________________________________________________________
> _______________________________________________
> linux-pm mailing list
> linux-pm@lists.osdl.org
> https://lists.osdl.org/mailman/listinfo/linux-pm
--
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Threads shouldn't inherit PF_NOFREEZE
2005-10-19 21:01 ` [linux-pm] " Nigel Cunningham
@ 2005-10-20 14:42 ` Alan Stern
0 siblings, 0 replies; 3+ messages in thread
From: Alan Stern @ 2005-10-20 14:42 UTC (permalink / raw)
To: Nigel Cunningham; +Cc: Linux-pm mailing list
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1815 bytes --]
On Thu, 20 Oct 2005, Nigel Cunningham wrote:
> Hi Alan.
>
> On Wed, 2005-10-19 at 05:29, Alan Stern wrote:
> > The PF_NOFREEZE process flag should not be inherited when a thread is
> > forked. This patch (as585) removes the flag from the child.
> >
> > This problem is starting to show up more and more as drivers turn to the
> > kthread API instead of using kernel_thread(). As a result, their kernel
> > threads are now children of the kthread worker instead of modprobe, and
> > they inherit the PF_NOFREEZE flag. This can cause problems during system
> > suspend; the kernel threads are not getting frozen as they ought to be.
> >
> > Alan Stern
>
> I have this in kthread instead, so that multithreaded userspace
> processes only need to have NOFREEZE set once (before forking). Yes, I
> have one that fits this scenario - I'm working on a userspace storage
> maanger, which will setup and tear down a network connection at
> appropriate times during a suspend-to-disk cycle. The initial version is
> based on nbd and uses two threads because the one that sets up storage
> blocks in a syscall as Pavel & others have written it.
>
> Anyway, I agree that the general need you're trying to address is real.
Thanks.
I had in mind that any process needing NOFREEZE would have to set it
shortly after starting up. That's what all the kernel threads do (the
ones I've read, anyway).
Yes, this does make life more difficult for user threads. If you're
already got some mechanism for setting NOFREEZE in the initial thread,
then it shouldn't be too hard to have the child arrange to set it as well.
Of course, this does open up the possibility of a race if the child
thread is created just as processes are being frozen.
Hope this doesn't add a lot of extra trouble to your work...
Alan Stern
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-10-20 14:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-18 19:29 [PATCH] Threads shouldn't inherit PF_NOFREEZE Alan Stern
2005-10-19 21:01 ` [linux-pm] " Nigel Cunningham
2005-10-20 14:42 ` Alan Stern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox