freezer: revert 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake TASK_KILLABLE tasks too"
Subsystems (7)
RFC PATCH 1/1 freezer: revert 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake TASK_KILLABLE tasks too"
Commit 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake TASK_KILLABLE tasks too" made freezer wake up tasks in TASK_KILLABLE sleep too citing non-interruptible but killable sleeps in cifs and nfs.
I don't think we can do this. We should not send spurious unsolicited non-interruptible wakeups. Most synchornization constructs are built to cope with spurious wakeups and any INTERRUPTIBLE sleep must be able to handle spurious wakeups but that's not true for KILLABLE sleeps - KILLABLE condition cannot be cancelled.
This is probably okay for most cases but circumventing fundamental wakeup condition like this is asking for trouble. Furthermore, I'm not sure the behavior change brought on by this change - breaking nfs/cifs uninterruptible operation guarantee - is correct. If such behavior is desirable, the right thing to do is using intr mount option, not circumventing it from PM layer.
---
Neil, Steve, do the network filesystems need a way to indicate "I can either be killed or enter freezer"?
Thanks.
kernel/freezer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/freezer.c +1 -1
@@ -67,7 +67,7 @@ static void fake_signal_wake_up(struct task_struct *p)unsigned long flags;spin_lock_irqsave (&p->sighand->siglock, flags); -signal_wake_up (p,1 ); +signal_wake_up (p,0 );spin_unlock_irqrestore (&p->sighand->siglock, flags); }
Quoted 18 lines · Tejun Heo
Commit
27920651fe"PM / Freezer: Makefake_signal_wake_up()wakeTASK_KILLABLEtasks too" made freezer wake up tasks inTASK_KILLABLEsleep too citing non-interruptible but killable sleeps in cifs and nfs.I don't think we can do this. We should not send spurious unsolicited non-interruptible wakeups. Most synchornization constructs are built to cope with spurious wakeups and any INTERRUPTIBLE sleep must be able to handle spurious wakeups but that's not true for KILLABLE sleeps - KILLABLE condition cannot be cancelled.
This is probably okay for most cases but circumventing fundamental wakeup condition like this is asking for trouble. Furthermore, I'm not sure the behavior change brought on by this change - breaking nfs/cifs uninterruptible operation guarantee - is correct. If such behavior is desirable, the right thing to do is using intr mount option, not circumventing it from PM layer.
Quoted 5 lines
Signed-off-by Tejun Heo <[email protected]>Cc Jeff Layton <[email protected]>---
Neil, Steve, do the network filesystems need a way to indicate "I can either be killed or enter freezer"?
Hmm... okay, so commit f06ac72e929 "cifs, freezer: add wait_event_freezekillable and have cifs use it" added freezable & killable sleep. If this is necessary, the right thing to do is adding another waking state, not modifying existing one's behavior.
But, before going there, is this *really* necessary? Do we really have to choose among different combinations of interruptible, killable and freezable? If something doesn't want to be bothered than being killed, assuming it doesn't want to go hibernating is kinda natural.
IOW, can we please update cifs, if it wants to allow hibernation, to use interruptible sleep in wait_for_response() than trying to modify basic sleep mechanism?
Thank you.
Signature · 1 line
tejun
Quoted 11 lines · Tejun Heo
Commit
27920651fe"PM / Freezer: Makefake_signal_wake_up()wakeTASK_KILLABLEtasks too" made freezer wake up tasks inTASK_KILLABLEsleep too citing non-interruptible but killable sleeps in cifs and nfs.I don't think we can do this. We should not send spurious unsolicited non-interruptible wakeups. Most synchornization constructs are built to cope with spurious wakeups and any INTERRUPTIBLE sleep must be able to handle spurious wakeups but that's not true for KILLABLE sleeps - KILLABLE condition cannot be cancelled.
Quoted 6 lines
This is probably okay for most cases but circumventing fundamental wakeup condition like this is asking for trouble. Furthermore, I'm not sure the behavior change brought on by this change - breaking nfs/cifs uninterruptible operation guarantee - is correct. If such behavior is desirable, the right thing to do is using intr mount option, not circumventing it from PM layer.
Do you have any specific examples of breakage, or is it just that you _think_ it's not quite right?
One patch depending on that change has been merged already and I have two more in the queue, so I'd like to clarify this ASAP. Jeff, Steve?
Quoted 16 lines
Signed-off-by Tejun Heo <[email protected]>Cc Jeff Layton <[email protected]>---
Neil, Steve, do the network filesystems need a way to indicate "I can either be killed or enter freezer"?Thanks.
kernel/freezer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/freezer.c +0
-0
kernel/freezer.c static void fake_signal_wake_up(struct task_struct *p) · line 72
Quoted 7 lines
kernel/freezer.c +1
-1@@ -67,7 +67,7 @@ static void fake_signal_wake_up(struct task_struct *p)unsigned long flags;spin_lock_irqsave (&p->sighand->siglock, flags); -signal_wake_up (p,1 ); +signal_wake_up (p,0 );spin_unlock_irqrestore (&p->sighand->siglock, flags); }
Thanks,
Rafael
Hello,
Quoted 9 lines · Rafael J. Wysocki
Quoted 6 lines
This is probably okay for most cases but circumventing fundamental wakeup condition like this is asking for trouble. Furthermore, I'm not sure the behavior change brought on by this change - breaking nfs/cifs uninterruptible operation guarantee - is correct. If such behavior is desirable, the right thing to do is using intr mount option, not circumventing it from PM layer.
Do you have any specific examples of breakage, or is it just that you _think_ it's not quite right?
I can't remember one off the top of my head but I'm pretty sure there at least are few which expect tight inter-locking between sleeps and wakeups. I'll look for examples and post reply. ISTR them being kernel threads so this might not apply directly but it's still a dangerous game to play.
Bugs caused by behaviors like this will be very difficult to reproduce and diagnose. There is no reason to play a gamble like this. If somebody *really* wants non-interruptible killable & freezable sleep, we really should be adding TASK_WAKE_FREEZER or something instead of modifying the behavior of TASK_KILLABLE.
Thanks.
Signature · 1 line
tejun
Hey, again.
Quoted 5 lines · Tejun Heo
I can't remember one off the top of my head but I'm pretty sure there at least are few which expect tight inter-locking between sleeps and wakeups. I'll look for examples and post reply. ISTR them being kernel threads so this might not apply directly but it's still a dangerous game to play.
Hmm... I couldn't find KILLABLE used like that but here are two UNINTERRUPTIBLE sleep examples.
* kthread_start() depends on the fact that a kthread won't be woken up from UNINTERRUPTIBLE sleep spuriously.
* jfs_flush_journal() doesn't check whether the wakeup was spurious after waiting if !tblkGC_COMMITTED.
Maybe we can re-define KILLABLE as killable && freezable but IMHO that requires pretty strong rationales. If at all possible, let's not diddle with that if it can be worked around some other way.
Thank you.
Signature · 1 line
tejun
Quoted 15 lines · On Mon, 31 Oct 2011 17:55:05 -0700 Tejun Heo…
Hey, again.
Quoted 5 lines · Tejun Heo
I can't remember one off the top of my head but I'm pretty sure there at least are few which expect tight inter-locking between sleeps and wakeups. I'll look for examples and post reply. ISTR them being kernel threads so this might not apply directly but it's still a dangerous game to play.
Hmm... I couldn't find KILLABLE used like that but here are two UNINTERRUPTIBLE sleep examples.
*
kthread_start()depends on the fact that a kthread won't be woken up from UNINTERRUPTIBLE sleep spuriously.
Quoted 9 lines
*
jfs_flush_journal()doesn't check whether the wakeup was spurious after waiting if !tblkGC_COMMITTED.Maybe we can re-define KILLABLE as killable && freezable but IMHO that requires pretty strong rationales. If at all possible, let's not diddle with that if it can be worked around some other way.
Thank you.
(cc'ing Trond and the linux-nfs mailing list -- fwiw, he maintains the NFS client code -- Bruce is the NFS server maintainer and probably has little interest in this thread).
The main reason for this change is primarily that we have people with laptops and nfs and cifs mounts that sometimes fail to suspend.
IIUC, the TASK_KILLABLE was mostly added to ensure that file-store writes would be uninterruptible, but still allow those tasks to be killed if the process is going down anyway.
The intr/nointr mount options in NFS have been deprecated since TASK_KILLABLE was added. The scheme now is basically that those sleeps ignore any signals except for fatal ones. So, that knob is meaningless and has been for a long time now.
cifs never had a working intr/nointr knob, but signal handling while waiting for replies was always a difficult thing to handle correctly. I don't think the right answer is to go back to using such a knob in cifs or nfs.
I suppose we could look at going back to the world of complicated signal handling and TASK_INTERRUPTIBLE, but that's not a trivial change either. The TASK_WAKE_FREEZABLE flag you mention might make more sense than doing that.
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 49 lines · On Tue, 1 Nov 2011 04:13:37 -0400 Jeff Layton…
Quoted 15 lines · On Mon, 31 Oct 2011 17:55:05 -0700 Tejun Heo…
Hey, again.
Quoted 5 lines · Tejun Heo
I can't remember one off the top of my head but I'm pretty sure there at least are few which expect tight inter-locking between sleeps and wakeups. I'll look for examples and post reply. ISTR them being kernel threads so this might not apply directly but it's still a dangerous game to play.
Hmm... I couldn't find KILLABLE used like that but here are two UNINTERRUPTIBLE sleep examples.
*
kthread_start()depends on the fact that a kthread won't be woken up from UNINTERRUPTIBLE sleep spuriously.Quoted 9 lines
*
jfs_flush_journal()doesn't check whether the wakeup was spurious after waiting if !tblkGC_COMMITTED.Maybe we can re-define KILLABLE as killable && freezable but IMHO that requires pretty strong rationales. If at all possible, let's not diddle with that if it can be worked around some other way.
Thank you.
(cc'ing Trond and the linux-nfs mailing list -- fwiw, he maintains the NFS client code -- Bruce is the NFS server maintainer and probably has little interest in this thread).
The main reason for this change is primarily that we have people with laptops and nfs and cifs mounts that sometimes fail to suspend.
IIUC, the
TASK_KILLABLEwas mostly added to ensure that file-store writes would be uninterruptible, but still allow those tasks to be killed if the process is going down anyway.The intr/nointr mount options in NFS have been deprecated since
TASK_KILLABLEwas added. The scheme now is basically that those sleeps ignore any signals except for fatal ones. So, that knob is meaningless and has been for a long time now.cifs never had a working intr/nointr knob, but signal handling while waiting for replies was always a difficult thing to handle correctly. I don't think the right answer is to go back to using such a knob in cifs or nfs.
Quoted 5 lines
I suppose we could look at going back to the world of complicated signal handling and
TASK_INTERRUPTIBLE, but that's not a trivial change either. TheTASK_WAKE_FREEZABLEflag you mention might make more sense than doing that.
Also, since task state and signal handling clearly isn't my forte...can you clarify what the main difference is in using a TASK_KILLABLE sleep vs. TASK_INTERRUPTIBLE with all signals but SIGKILL blocked?
I know that the process state would end up different (S vs. D state). Is there anything else we'd need to be concerned with if we converted all these call sites to use such a scheme in lieu of a new TASK_WAKE_FREEZABLE flag or similar?
Signature · 5 lines
Jeff Layton <[email protected]> -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hello, Jeff.
Quoted 4 lines · Jeff Layton
Quoted 4 lines
I suppose we could look at going back to the world of complicated signal handling and
TASK_INTERRUPTIBLE, but that's not a trivial change either. TheTASK_WAKE_FREEZABLEflag you mention might make more sense than doing that.
I see.
Quoted 8 lines
Also, since task state and signal handling clearly isn't my forte...can you clarify what the main difference is in using a
TASK_KILLABLEsleep vs.TASK_INTERRUPTIBLEwith all signals but SIGKILL blocked?I know that the process state would end up different (S vs. D state). Is there anything else we'd need to be concerned with if we converted all these call sites to use such a scheme in lieu of a new
TASK_WAKE_FREEZABLEflag or similar?
Manipulating sigmask would work in most cases but there are corner cases (e.g. debug signals will force the mask off) and diddling with sigmask in kernel generally isn't a good idea.
If TASK_KILLABLE is only used for killable && freezable, that probably would be the cleanest solution but given the name and the fact that people are in general much more aware of SIGKILL's then freezer, I think adding such assumption is likely to cause very subtle bugs. For example, mem_cgroup_handle_oom() seems to assume that if it's waken from TASK_KILLABLE either the condition it was waiting for is true or it is dying.
If there are only a handful sites which need this type of behavior, wouldn't something like the following work?
#define wait_event_freezekillable(wq, condition) \
do { \
DEFINE_WAIT(__wait); \
for (;;) { \
prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
if (condition || fatal_signal_pending(current)) \
break; \
schedule(); \
try_to_freeze(); \
} \
finish_wait(&wq, &__wait); \
} while (0)Thanks.
Signature · 1 line
tejun
Quoted 35 lines · Tejun Heo
Hello, Jeff.
Quoted 4 lines · Jeff Layton
Quoted 4 lines
I suppose we could look at going back to the world of complicated signal handling and
TASK_INTERRUPTIBLE, but that's not a trivial change either. TheTASK_WAKE_FREEZABLEflag you mention might make more sense than doing that.I see.
Quoted 8 lines
Also, since task state and signal handling clearly isn't my forte...can you clarify what the main difference is in using a
TASK_KILLABLEsleep vs.TASK_INTERRUPTIBLEwith all signals but SIGKILL blocked?I know that the process state would end up different (S vs. D state). Is there anything else we'd need to be concerned with if we converted all these call sites to use such a scheme in lieu of a new
TASK_WAKE_FREEZABLEflag or similar?Manipulating sigmask would work in most cases but there are corner cases (e.g. debug signals will force the mask off) and diddling with sigmask in kernel generally isn't a good idea.
If
TASK_KILLABLEis only used for killable && freezable, that probably would be the cleanest solution but given the name and the fact that people are in general much more aware of SIGKILL's then freezer, I think adding such assumption is likely to cause very subtle bugs. For example,mem_cgroup_handle_oom()seems to assume that if it's waken fromTASK_KILLABLEeither the condition it was waiting for is true or it is dying.If there are only a handful sites which need this type of behavior, wouldn't something like the following work?
#define
wait_event_freezekillable(wq, condition)\
Quoted 11 lines
do { \
DEFINE_WAIT(__wait); \
for (;;) { \
prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
if (condition || fatal_signal_pending(current)) \
break; \
schedule(); \
try_to_freeze(); \
} \
finish_wait(&wq, &__wait); \
} while (0)Err... Won't this end up busy-waiting if a non-fatal signal is received?
Signature · 11 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hello,
Quoted 13 lines · Trond Myklebust
Quoted 12 lines
#define
wait_event_freezekillable(wq, condition)\do { \ DEFINE_WAIT(__wait); \ for (;;) { \ prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \ if (condition || fatal_signal_pending(current)) \ break; \ schedule(); \ try_to_freeze(); \ } \ finish_wait(&wq, &__wait); \ } while (0)
Quoted 1 line
Err... Won't this end up busy-waiting if a non-fatal signal is received?
Ah... right, forgot about signal_pending_state() special case in schedule(). Any better ideas, anyone?
Signature · 1 line
tejun
Quoted 3 lines · Tejun Heo
diddling with
sigmask in kernel generally isn't a good idea.
Agreed.
Quoted 11 lines
If there are only a handful sites which need this type of behavior, wouldn't something like the following work?
#define
wait_event_freezekillable(wq, condition)\do { \ DEFINE_WAIT(__wait); \ for (;;) { \ prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \ if (condition || fatal_signal_pending(current)) \ break; \ schedule(); \
No, this can't work, afaics.
Once the caller recieves a non-fatal signal (gets TIF_SIGPENDING), schedule() won't block in TASK_INTERRUPTIBLE state.
IOW, wait_event_freezekillable() becomes a busy-wait loop.
Oleg.
Quoted 9 lines · Oleg Nesterov
Quoted 8 lines
#define
wait_event_freezekillable(wq, condition)\do { \ DEFINE_WAIT(__wait); \ for (;;) { \ prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \ if (condition || fatal_signal_pending(current)) \ break; \ schedule(); \
Quoted 6 lines
No, this can't work, afaics.
Once the caller recieves a non-fatal signal (gets
TIF_SIGPENDING),schedule()won't block inTASK_INTERRUPTIBLEstate.IOW,
wait_event_freezekillable()becomes a busy-wait loop.
Yeah yeah, Trond already pointed it out. I forgot about the sigpending special case in schedule(), which I think is rather odd, oh well. Any better ideas?
Signature · 1 line
tejun
Quoted 3 lines · Tejun Heo
Yeah yeah, Trond already pointed it out. I forgot about the sigpending special case in
schedule(), which I think is rather odd,
I disagree with "rather odd" ;)
We have a lot of examples of
current->state = TASK_INTERRUPTIBLE; ... if (signal_pending()) break; schedule();
Without that special case in schedule() the code above becomes racy. Just consider __wait_event_interruptible().
Quoted 1 line
Any better ideas?
Well. As a simple (probably temporary) fix, I'd suggest
#define wait_event_freezekillable(wq, condition)
{
freezer_do_not_count();
__retval = wait_event_killable(condition);
freezer_count();
__retval;
}Do you think it can work?
Oleg.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hello,
Quoted 9 lines · Oleg Nesterov
Quoted 3 lines · Tejun Heo
Yeah yeah, Trond already pointed it out. I forgot about the sigpending special case in
schedule(), which I think is rather odd,I disagree with "rather odd" ;)
We have a lot of examples of
Quoted 8 lines
current->state = TASK_INTERRUPTIBLE; ... if (signal_pending()) break; schedule();Without that special case in
schedule()the code above becomes racy. Just consider__wait_event_interruptible().
But __wait_event_interruptible() does proper set-TASK_*, check sigpending and schedule() sequence. As long as the waker performs seg-sigpending, wakeup sequence in the correct order, nothing is broken (as w/ any other wakeup conditions). The special case deals with callers which don't check sigpending between set-TASK_* and schedule() and that's the part I think is a bit odd. Whether I feel odd or not is irrelevant tho - it's already there.
Quoted 12 lines
Quoted 1 line
Any better ideas?
Well. As a simple (probably temporary) fix, I'd suggest
#define wait_event_freezekillable(wq, condition) { freezer_do_not_count(); __retval = wait_event_killable(condition); freezer_count(); __retval; }
Quoted 1 line
Do you think it can work?
Yeah, probably. I was hoping to remove count/do_not_count tho. Hmmm... maybe we can just flip PF_NOFREEZE instead with a bit of modification, I think.
Thanks.
Signature · 1 line
tejun
Quoted 22 lines · Tejun Heo
Hello,
Quoted 9 lines · Oleg Nesterov
Quoted 3 lines · Tejun Heo
Yeah yeah, Trond already pointed it out. I forgot about the sigpending special case in
schedule(), which I think is rather odd,I disagree with "rather odd" ;)
We have a lot of examples of
Quoted 8 lines
current->state = TASK_INTERRUPTIBLE; ... if (signal_pending()) break; schedule();Without that special case in
schedule()the code above becomes racy. Just consider__wait_event_interruptible().
Quoted 6 lines
But
__wait_event_interruptible()does proper set-TASK_*, check sigpending andschedule()sequence. As long as the waker performs seg-sigpending, wakeup sequence in the correct order, nothing is broken (as w/ any other wakeup conditions). The special case deals with callers which don't check sigpending between set-TASK_* andschedule()and that's the part I think is a bit odd.
OK, agreed, __wait_event_interruptible() was a bad example.
Yes, this is only needed for the code which doesn't check signal_pending() "properly", or doesn't check it at all before schedule(). OK, say, wait_for_completion_interruptible(). Or schedule_timeout_interruptible().
I suspect we have a lot more examples. Historically linux allows to set TASK_INTERRUPTIBLE and schedule() without any checks.
Quoted 2 lines
Whether I feel
odd or not is irrelevant tho - it's already there.
Yes, I don't think we can remove it.
Quoted 12 lines
Quoted 12 lines
Quoted 1 line
Any better ideas?
Well. As a simple (probably temporary) fix, I'd suggest
#define wait_event_freezekillable(wq, condition) { freezer_do_not_count(); __retval = wait_event_killable(condition); freezer_count(); __retval; }
Quoted 3 lines
Quoted 1 line
Do you think it can work?
Yeah, probably. I was hoping to remove count/do_not_count tho.
Or at least rename it ;)
Quoted 2 lines
Hmmm... maybe we can just flip
PF_NOFREEZEinstead with a bit of modification, I think.
Perhaps.
Or we can add TASK_FREEZABLE (like TASK_WAKEKILL), iirc we already discussed this some time ago. And probably it makes sense to add the generic wait_event_state().
Oleg.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Oleg Nesterov
Or we can add
TASK_FREEZABLE(likeTASK_WAKEKILL), iirc we already discussed this some time ago. And probably it makes sense to add the genericwait_event_state().
Forgot to mention. I think that before anything else we need signal_wake_up_state(). For example, note that none of the callers of signal_wake_up(resume => true) in ptrace code wants to wake up the killable task.
Oleg.
Hey, Oleg.
Quoted 10 lines · Oleg Nesterov
Quoted 4 lines · Oleg Nesterov
Or we can add
TASK_FREEZABLE(likeTASK_WAKEKILL), iirc we already discussed this some time ago. And probably it makes sense to add the genericwait_event_state().Forgot to mention. I think that before anything else we need
signal_wake_up_state(). For example, note that none of the callers ofsignal_wake_up(resume => true)in ptrace code wants to wake up the killable task.
Yeah, agreed for both wait_event_state() and signal_wake_up_state(). For now, let's go with the count/dont_count. Can you please write up a patch for that? Jeff, does this seem okay to you?
For TASK_FREEZABLE, I'm not entirely sure. Combined with wait_event_state(), it can definitely reduce the number of different variants of wait_event_*(). Let's see.
Thanks.
Signature · 1 line
tejun
Quoted 9 lines · On Tue, 1 Nov 2011 14:57:10 -0700 Tejun Heo…
Hey, Oleg.
Quoted 6 lines · Oleg Nesterov
Quoted 4 lines · Oleg Nesterov
Or we can add
TASK_FREEZABLE(likeTASK_WAKEKILL), iirc we already discussed this some time ago. And probably it makes sense to add the genericwait_event_state().
Quoted 9 lines
Quoted 4 lines
Forgot to mention. I think that before anything else we need
signal_wake_up_state(). For example, note that none of the callers ofsignal_wake_up(resume => true)in ptrace code wants to wake up the killable task.Yeah, agreed for both
wait_event_state()andsignal_wake_up_state(). For now, let's go with the count/dont_count. Can you please write up a patch for that? Jeff, does this seem okay to you?
Let me make sure I understand since I don't have a great grasp of the freezer internals...
This will set the PF_FREEZER_SKIP flag on the task, which prevents try_to_freeze_tasks from incrementing the "todo" var for this process and should let the suspend proceed.
So this really makes try_to_freeze_tasks set PF_FREEZING on the task, but not get upset that it doesn't actually call try_to_freeze().
Is that sufficient for a process that's just sleeping here?
If so, guess I'll need to respin the NFS/RPC patches for this to do something similar around the sleeps there since they don't use wait_event_*.
Quoted 4 lines
For
TASK_FREEZABLE, I'm not entirely sure. Combined withwait_event_state(), it can definitely reduce the number of different variants of wait_event_*(). Let's see.
wait_event_state() sounds like a wonderful idea regardless of what we do here.
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 11 lines · Jeff Layton
Quoted 3 lines · On Tue, 1 Nov 2011 14:57:10 -0700 Tejun Heo…
For now, let's go with the count/dont_count. Can you please write up a patch for that? Jeff, does this seem okay to you?
Let me make sure I understand since I don't have a great grasp of the freezer internals...
Quoted 6 lines
This will set the
PF_FREEZER_SKIPflag on the task, which preventstry_to_freeze_tasksfrom incrementing the "todo" var for this process and should let the suspend proceed.So this really makes
try_to_freeze_taskssetPF_FREEZINGon the task, but not get upset that it doesn't actually calltry_to_freeze().
Yes. PF_FREEZER_SKIP means, "please count me as frozen". This task can do nothing except refrigerator() after wakeup.
Quoted 1 line
Is that sufficient for a process that's just sleeping here?
I think this should work... but this is the question to you ;)
Oleg.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi,
Quoted 3 lines · Tejun Heo
For now, let's go with the count/dont_count. Can you please write up a patch for that? Jeff, does this seem okay to you?
OK, will do in a minute. On top of
"[PATCH pm] freezer: fix wait_event_freezable/__thaw_task races" you sent. (btw, thanks, I forgout about it ;)
Rafael, could you remind why freezer_do_not_count/freezer_count check ->mm != NULL ?
The comment says "However, we don't want kernel threads to be frozen", but it is not clear anyway. A kernel thread simply shouldn't use this interface if it doesn't want to freeze.
And in any case, PF_KTHREAD looks better if we really need to filter out the kernel threads.
Oleg.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 7 lines · Oleg Nesterov
Hi,
Quoted 3 lines · Tejun Heo
For now, let's go with the count/dont_count. Can you please write up a patch for that? Jeff, does this seem okay to you?
Quoted 6 lines
OK, will do in a minute. On top of
"[PATCH pm] freezer: fix wait_event_freezable/__thaw_task races" you sent. (btw, thanks, I forgout about it ;)Rafael, could you remind why freezer_do_not_count/freezer_count check ->mm != NULL ?
You're asking difficult questions. ;-)
The intention was to prevent PF_FREEZER_SKIP from having any effect on kernel threads, IIRC. Anyway, there are only two legitimate users of it (vfork and apm_ioctl) and in both cases the task in question is user space.
Quoted 6 lines
The comment says "However, we don't want kernel threads to be frozen", but it is not clear anyway. A kernel thread simply shouldn't use this interface if it doesn't want to freeze.
And in any case,
PF_KTHREADlooks better if we really need to filter out the kernel threads.
PF_FREEZER_SKIP was introduced specifically with vfork in mind and I'm not sure if it's a good idea to re-use it for something else (at least not for something entirely obvious).
Thanks,
Rafael
Quoted 25 lines · On Thu, 3 Nov 2011 00:11:23 +0100 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 7 lines · Oleg Nesterov
Hi,
Quoted 3 lines · Tejun Heo
For now, let's go with the count/dont_count. Can you please write up a patch for that? Jeff, does this seem okay to you?
Quoted 6 lines
OK, will do in a minute. On top of
"[PATCH pm] freezer: fix wait_event_freezable/__thaw_task races" you sent. (btw, thanks, I forgout about it ;)Rafael, could you remind why freezer_do_not_count/freezer_count check ->mm != NULL ?
You're asking difficult questions. ;-)
The intention was to prevent
PF_FREEZER_SKIPfrom having any effect on kernel threads, IIRC. Anyway, there are only two legitimate users of it (vfork andapm_ioctl) and in both cases the task in question is user space.Quoted 4 lines
The comment says "However, we don't want kernel threads to be frozen", but it is not clear anyway. A kernel thread simply shouldn't use this interface if it doesn't want to freeze.
Quoted 7 lines
Quoted 2 lines
And in any case,
PF_KTHREADlooks better if we really need to filter out the kernel threads.
PF_FREEZER_SKIPwas introduced specifically with vfork in mind and I'm not sure if it's a good idea to re-use it for something else (at least not for something entirely obvious).
FWIW, wrapping wait_event_killable in freezer_do_not_count/freezer_count seems to work. The machine suspends consistently with it. It sounds like Rafael has concerns about this scheme however, so I'll let you guys argue this out :)
Once you tell me the right scheme to use, I'll be happy to fix up cifs and nfs to use it.
Thanks,
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 7 lines · Rafael J. Wysocki
Quoted 3 lines · Oleg Nesterov
Rafael, could you remind why freezer_do_not_count/freezer_count check ->mm != NULL ?
You're asking difficult questions. ;-)
I am trying ;)
Quoted 3 lines
The intention was to prevent
PF_FREEZER_SKIPfrom having any effect on kernel threads, IIRC. Anyway, there are only two legitimate users of it (vfork andapm_ioctl) and in both cases the task in question is user space.
Actually CLONE_VFORK is used by call_usermodehelper() paths but this case is fine. The caller is the PF_NOFREEZE workqueue thread.
Quoted 10 lines
Quoted 6 lines
The comment says "However, we don't want kernel threads to be frozen", but it is not clear anyway. A kernel thread simply shouldn't use this interface if it doesn't want to freeze.
And in any case,
PF_KTHREADlooks better if we really need to filter out the kernel threads.
PF_FREEZER_SKIPwas introduced specifically with vfork in mind and I'm not sure if it's a good idea to re-use it for something else (at least not for something entirely obvious).
Indeed! So why do we check ->mm != NULL?
We can remove this check, right now it doesn't matter. And we are trying to avoid the new users of this interface.
Oleg.
PATCH 1/1 wait_event_freezekillable: use freezer_do_not_count/freezer_count
In reply to Tejun Heofake_signal_wake_up() should not wake up the TASK_KILLABLE tasks, we are going to fix this. This means that wait_event_freezekillable() can't rely on wakeup from freezer. Reimplement it using freezer_do_not_count/freezer_count. This is not really nice, just a simple fix for now.
---
include/linux/freezer.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
include/linux/freezer.h +3 -7
@@ -143,13 +143,9 @@ static inline void set_freezable_with_si#define wait_event_freezekillable (wq, condition) \ ({ \ int __retval; \ - for (;;) { \ - __retval = wait_event_killable(wq, \ - (condition) || freezing(current)); \ - if (__retval || (condition)) \ - break; \ - try_to_freeze(); \ - } \ + freezer_do_not_count(); \ + __retval = wait_event_killable(wq, (condition)); \ + freezer_count(); \ __retval; \ })
Re: [PATCH] wait_event_freezekillable: use freezer_do_not_count/freezer_count
Quoted 22 lines · On Wed, 2 Nov 2011 18:53:27 +0100 Oleg Nesterov <[email protected]> wrote:
fake_signal_wake_up()should not wake up theTASK_KILLABLEtasks, we are going to fix this. This means thatwait_event_freezekillable()can't rely on wakeup from freezer. Reimplement it using freezer_do_not_count/freezer_count. This is not really nice, just a simple fix for now.Signed-off-by Oleg Nesterov <[email protected]>---
include/linux/freezer.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)include/linux/freezer.h +0
-3@@ -143,13 +143,9 @@ static inline void set_freezable_with_si#define wait_event_freezekillable (wq, condition) \ ({ \ int __retval; \ - for (;;) { \ - __retval = wait_event_killable(wq, \ - (condition) || freezing(current)); \
include/linux/freezer.h static inline void set_freezable_with_si · line 151
Quoted 10 lines
include/linux/freezer.h +3
-4-if (__retval || (condition)) \ -break ; \ -try_to_freeze (); \ - } \ +freezer_do_not_count (); \ + __retval =wait_event_killable (wq, (condition)); \ +freezer_count (); \ __retval; \ })
I'm not sure we really need this macro anymore since this is much simpler. I could just move cifs back to using wait_event_killable and simply wrap it in freezer_do_not_count/freezer_count (with some comments to explain why we're doing that).
In any event, I plan to test this scheme out today and will let you know whether it works...
Thanks,
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH] wait_event_freezekillable: use freezer_do_not_count/freezer_count
Hello,
Quoted 7 lines · Jeff Layton
I'm not sure we really need this macro anymore since this is much simpler. I could just move cifs back to using
wait_event_killableand simply wrap it in freezer_do_not_count/freezer_count (with some comments to explain why we're doing that).In any event, I plan to test this scheme out today and will let you know whether it works...
I think it would be better to put this in a macro as the implementation is likely to change in future and I really don't want to see FREEZER_SKIP scattered around the tree.
Thank you.
Signature · 1 line
tejun
Re: [PATCH] wait_event_freezekillable: use freezer_do_not_count/freezer_count
Quoted 8 lines · On Thu, 3 Nov 2011 07:13:54 -0700 Tejun Heo <[email protected]> wrote:
Hello,
Quoted 5 lines · Jeff Layton
I'm not sure we really need this macro anymore since this is much simpler. I could just move cifs back to using
wait_event_killableand simply wrap it in freezer_do_not_count/freezer_count (with some comments to explain why we're doing that).
Quoted 7 lines
Quoted 2 lines
In any event, I plan to test this scheme out today and will let you know whether it works...
I think it would be better to put this in a macro as the implementation is likely to change in future and I really don't want to see
FREEZER_SKIPscattered around the tree.
Ok, note though that I also need to do a similar set of changes to the nfs and sunrpc code [1].
Those call sites do not use wait_event_* macros though. So I'll either need to add a separate set of functions/macros to handle those, or sprinkle freezer_do_not_count/freezer_count around the code there...
[1] Here are the older patches that depended on the change to fake_signal_wake_up. I'll need to convert these to use the new scheme once you guys settle on what it should be:
https://git.samba.org/jlayton/?p=jlayton/linux.git;a=commitdiff;h=0f85cbb747a0f9f8a582ae9bf642e094168001be
https://git.samba.org/jlayton/?p=jlayton/linux.git;a=commitdiff;h=084535708bcb33dd2448e73be5a0f4cac69bea92
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH] wait_event_freezekillable: use freezer_do_not_count/freezer_count
Hello,
Quoted 6 lines · Jeff Layton
Ok, note though that I also need to do a similar set of changes to the nfs and sunrpc code [1].
Those call sites do not use wait_event_* macros though. So I'll either need to add a separate set of functions/macros to handle those, or sprinkle freezer_do_not_count/freezer_count around the code there...
Yes, I still think it would be better to isolate implementation details from users. I really hate to see the 'count' functions scattered around the kernel.
Thank you.
Signature · 1 line
tejun
Quoted 12 lines · On Tue, 1 Nov 2011 11:06:01 -0700 Tejun Heo…
Quoted 11 lines · Oleg Nesterov
Quoted 8 lines
#define
wait_event_freezekillable(wq, condition)\do { \ DEFINE_WAIT(__wait); \ for (;;) { \ prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \ if (condition || fatal_signal_pending(current)) \ break; \ schedule(); \No, this can't work, afaics.
Quoted 9 lines
Quoted 4 lines
Once the caller recieves a non-fatal signal (gets
TIF_SIGPENDING),schedule()won't block inTASK_INTERRUPTIBLEstate.IOW,
wait_event_freezekillable()becomes a busy-wait loop.Yeah yeah, Trond already pointed it out. I forgot about the sigpending special case in
schedule(), which I think is rather odd, oh well. Any better ideas?
This is (obviously) not my area of expertise, but the TAKE_WAKEFREEZE flag that you mentioned earlier might be the best way to solve this.
Tasks that want to be awoken on freezer events can set that flag and we can have the freezer code wake them up. For the NFS and CIFS code, we'll just ensure that we set that flag
This does mean a rather nasty proliferation of new wait_event_* macros, and we'll need a new schedule_timeout_freezekillable() variant for the new state. It looks fairly straightforward to implement though.
Signature · 5 lines
Jeff Layton <[email protected]> -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 19 lines · Rafael J. Wysocki
Quoted 11 lines · Tejun Heo
Commit
27920651fe"PM / Freezer: Makefake_signal_wake_up()wakeTASK_KILLABLEtasks too" made freezer wake up tasks inTASK_KILLABLEsleep too citing non-interruptible but killable sleeps in cifs and nfs.I don't think we can do this. We should not send spurious unsolicited non-interruptible wakeups. Most synchornization constructs are built to cope with spurious wakeups and any INTERRUPTIBLE sleep must be able to handle spurious wakeups but that's not true for KILLABLE sleeps - KILLABLE condition cannot be cancelled.
Quoted 6 lines
This is probably okay for most cases but circumventing fundamental wakeup condition like this is asking for trouble. Furthermore, I'm not sure the behavior change brought on by this change - breaking nfs/cifs uninterruptible operation guarantee - is correct. If such behavior is desirable, the right thing to do is using intr mount option, not circumventing it from PM layer.
Quoted 11 lines
Do you have any specific examples of breakage, or is it just that you _think_ it's not quite right?
One patch depending on that change has been merged already and I have two more in the queue, so I'd like to clarify this ASAP. Jeff, Steve?
Quoted 5 lines
Signed-off-by Tejun Heo <[email protected]>Cc Jeff Layton <[email protected]>---
Neil, Steve, do the network filesystems need a way to indicate "I can either be killed or enter freezer"?
Probably, yes, but I will defer to Jeff as he has looked more recently at these issues.
I can explain cifs state, and disconnect/reconnection of sessions (and smb2 is a little more feature rich in this regard), but will let Jeff explain the more subtle points you are getting at.
Signature · 3 lines
Thanks, Steve
Hello,
Quoted 6 lines · Steve French
Quoted 5 lines
Quoted 5 lines
Signed-off-by Tejun Heo <[email protected]>Cc Jeff Layton <[email protected]>---
Neil, Steve, do the network filesystems need a way to indicate "I can either be killed or enter freezer"?
Quoted 6 lines
Probably, yes, but I will defer to Jeff as he has looked more recently at these issues.
I can explain cifs state, and disconnect/reconnection of sessions (and smb2 is a little more feature rich in this regard), but will let Jeff explain the more subtle points you are getting at.
Hmmm... I'm getting confused.
For nfs, this really is a non-issue. Either the user wants nointr or intr behavior. NFS nointr is rather crazy - it's basically "nothing can do anything to tasks which is doing NFS IO until it's complete" and really meant to be used for servers sharing filesystems for /usr, /home and stuff. It doesn't make whole lot of sense on systems which may go suspend and that's why there's intr option.
I suppose the problem is that cifs doesn't know how to do 'intr' yet, right? If that really is the problem, the correct long term solution would be implementing proper intr behavior and it doesn't make any sense to push this type of change to PM core to for short term workaround. Just use prepare_to_wait() / schedule() / finish_wait() directly w/ INTERRUPTIBLE sleep and don't break out of wait loop on signal_pending(). If this should be used in multiple places, write up a wait_event_XXX() wrapper. There is absolutely no reason to change wakeup condition.
Thank you.
Signature · 1 line
tejun
Quoted 25 lines · Tejun Heo
Hello,
Quoted 6 lines · Steve French
Quoted 5 lines
Quoted 5 lines
Signed-off-by Tejun Heo <[email protected]>Cc Jeff Layton <[email protected]>---
Neil, Steve, do the network filesystems need a way to indicate "I can either be killed or enter freezer"?Quoted 6 lines
Probably, yes, but I will defer to Jeff as he has looked more recently at these issues.
I can explain cifs state, and disconnect/reconnection of sessions (and smb2 is a little more feature rich in this regard), but will let Jeff explain the more subtle points you are getting at.
Hmmm... I'm getting confused.
For nfs, this really is a non-issue. Either the user wants nointr or intr behavior. NFS nointr is rather crazy - it's basically "nothing can do anything to tasks which is doing NFS IO until it's complete" and really meant to be used for servers sharing filesystems for /usr, /home and stuff. It doesn't make whole lot of sense on systems which may go suspend and that's why there's intr option.
Quoted 9 lines
I suppose the problem is that cifs doesn't know how to do 'intr' yet, right? If that really is the problem, the correct long term solution would be implementing proper intr behavior and it doesn't make any sense to push this type of change to PM core to for short term workaround. Just use
prepare_to_wait()/schedule()/finish_wait()directly w/ INTERRUPTIBLE sleep and don't break out of wait loop onsignal_pending(). If this should be used in multiple places, write up await_event_XXX()wrapper. There is absolutely no reason to change wakeup condition.
It isn't that simple (among other reasons due to much time waiting in the socket interface), but since this directly addresses problems Jeff has spent much time debugging, I would like him to chime in.
Signature · 3 lines
Thanks, Steve
Quoted 11 lines · Tejun Heo
Commit
27920651fe"PM / Freezer: Makefake_signal_wake_up()wakeTASK_KILLABLEtasks too" made freezer wake up tasks inTASK_KILLABLEsleep too citing non-interruptible but killable sleeps in cifs and nfs.I don't think we can do this. We should not send spurious unsolicited non-interruptible wakeups. Most synchornization constructs are built to cope with spurious wakeups and any INTERRUPTIBLE sleep must be able to handle spurious wakeups but that's not true for KILLABLE sleeps - KILLABLE condition cannot be cancelled.
Agreed.
For example. sys_read() or page can sleep in TASK_KILLABLE assuming that wait/down/whatever _killable can only fail if we can not return to the usermode.
TASK_TRACED case is obviously wrong too.
kernel/freezer.c static void fake_signal_wake_up(struct task_struct *p) · line 72
Quoted 10 lines
kernel/freezer.c +1
-1@@ -67,7 +67,7 @@ static void fake_signal_wake_up(struct task_struct *p)unsigned long flags;spin_lock_irqsave (&p->sighand->siglock, flags); -signal_wake_up (p,1 ); +signal_wake_up (p,0 );spin_unlock_irqrestore (&p->sighand->siglock, flags); }
Agreed, this looks like a bug fix to me.