Skip to contentSkip to conversation

Remove process freezer from suspend to RAM pathway

PATCH In review Matthew Garrett 26 participants 656 messages Jul 3, 2007 – Jul 12, 2007 Page 1 of 3

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

PATCH 1/1 Remove process freezer from suspend to RAM pathway

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

kernel/power/main.c +2 -10
index 8812985..5f109d5 100644
@@ -19,7 +19,6 @@
 #include <linux/console.h>
 #include <linux/cpu.h>
 #include <linux/resume-trace.h>
-#include <linux/freezer.h>
 #include <linux/vmstat.h>
 
 #include "power.h"
@@ -81,11 +80,6 @@ static int suspend_prepare(suspend_state_t state)
 
 	pm_prepare_console();
 
-	if (freeze_processes()) {
-		error = -EAGAIN;
-		goto Thaw;
-	}
-
 	if ((free_pages = global_page_state(NR_FREE_PAGES))
 			< FREE_PAGE_NUMBER) {
 		pr_debug("PM: free some memory\n");
@@ -93,7 +87,7 @@ static int suspend_prepare(suspend_state_t state)
 		if (nr_free_pages() < FREE_PAGE_NUMBER) {
 			error = -ENOMEM;
 			printk(KERN_ERR "PM: No enough memory\n");
-			goto Thaw;
+			goto Restore_console;
 		}
 	}
 
@@ -118,8 +112,7 @@ static int suspend_prepare(suspend_state_t state)
 	device_resume();
  Resume_console:
 	resume_console();
- Thaw:
-	thaw_processes();
+ Restore_console:
 	pm_restore_console();
 	return error;
 }
@@ -170,7 +163,6 @@ static void suspend_finish(suspend_state_t state)
 	pm_finish(state);
 	device_resume();
 	resume_console();
-	thaw_processes();
 	pm_restore_console();
 }
 
Signature · 1 line
Matthew Garrett | [email protected]
#1 lore raw
Quoted 8 lines · On Tuesday 03 July 2007 14:29:18 Matthew Garrett wrote:

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Note, though, that this won't help at all when people use the "suspend-to-ram instead of powering down after writing a hibernation image" feature in (uswsusp | tuxonice). Fuse is just a broken idea in the first place, but given that it exists, we still need to find the underlying cause.

Regards,

Nigel

#2 lore raw
In reply to Matthew Garrett
Quoted 8 lines · On Tuesday 03 July 2007 14:29:18 Matthew Garrett wrote:

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Note, though, that this won't help at all when people use the "suspend-to-ram instead of powering down after writing a hibernation image" feature in (uswsusp | tuxonice). Fuse is just a broken idea in the first place, but given that it exists, we still need to find the underlying cause.

Regards,

Nigel

#3 lore raw
Quoted 4 lines · Nigel Cunningham

Note, though, that this won't help at all when people use the "suspend-to-ram instead of powering down after writing a hibernation image" feature in (uswsusp | tuxonice). Fuse is just a broken idea in the first place, but given that it exists, we still need to find the underlying cause.

If / is on fuse it's unlikely that hibernation is high on your list of priorities right now.

Signature · 1 line
Matthew Garrett | [email protected]
#4 lore raw
In reply to Nigel Cunningham
Quoted 4 lines · Nigel Cunningham

Note, though, that this won't help at all when people use the "suspend-to-ram instead of powering down after writing a hibernation image" feature in (uswsusp | tuxonice). Fuse is just a broken idea in the first place, but given that it exists, we still need to find the underlying cause.

If / is on fuse it's unlikely that hibernation is high on your list of priorities right now.

Signature · 1 line
Matthew Garrett | [email protected]
#5 lore raw

Hi.

Quoted 3 lines · On Tuesday 03 July 2007 15:21:30 Matthew Garrett wrote:
Quoted 1 line · Nigel Cunningham

Note, though, that this won't help at all when people use

the "suspend-to-ram

Quoted 6 lines
Quoted 3 lines

instead of powering down after writing a hibernation image" feature in (uswsusp | tuxonice). Fuse is just a broken idea in the first place, but given that it exists, we still need to find the underlying cause.

If / is on fuse it's unlikely that hibernation is high on your list of priorities right now.

Yeah, well... what can you say to that? :)

Nigel

Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing
lists, wiki and bugzilla info.
#6 lore raw
In reply to Matthew Garrett

Hi.

Quoted 3 lines · On Tuesday 03 July 2007 15:21:30 Matthew Garrett wrote:
Quoted 1 line · Nigel Cunningham

Note, though, that this won't help at all when people use

the "suspend-to-ram

Quoted 6 lines
Quoted 3 lines

instead of powering down after writing a hibernation image" feature in (uswsusp | tuxonice). Fuse is just a broken idea in the first place, but given that it exists, we still need to find the underlying cause.

If / is on fuse it's unlikely that hibernation is high on your list of priorities right now.

Yeah, well... what can you say to that? :)

Nigel

Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing
lists, wiki and bugzilla info.
#7 lore raw
In reply to Nigel Cunningham
Quoted 5 lines

Note, though, that this won't help at all when people use the "suspend-to-ram instead of powering down after writing a hibernation image" feature in (uswsusp | tuxonice). Fuse is just a broken idea in the first place, but given that it exists, we still need to find the underlying cause.

No, Fuse is not a broken idea in the first place. It's the freezer that is a totally broken idea. It has proven many times to be racy by design and cannot be made right. Ther usermode helper mess is just part of that, fuse is another example, etc etc ...

So I think Matthew is totally right. In fact, the presence of the freezer is the main reason why Paulus so far NACKed Johannes attempts at merging the PPC PM code with the generic code in kernel/power.c

We've been doing fine without it so far and intend to continue to do so.

As for suspend-to-disk, I refer you to the discussions we had in the past with Linus, where he explains I think quite clearly how wrong the current implementation of STR is :-)

Thing is, if you're going to do snapshots, you should probably not sync after you have "frozen" anyway.

Cheers,
Ben.

#8 lore raw
In reply to Nigel Cunningham
Quoted 5 lines

Note, though, that this won't help at all when people use the "suspend-to-ram instead of powering down after writing a hibernation image" feature in (uswsusp | tuxonice). Fuse is just a broken idea in the first place, but given that it exists, we still need to find the underlying cause.

No, Fuse is not a broken idea in the first place. It's the freezer that is a totally broken idea. It has proven many times to be racy by design and cannot be made right. Ther usermode helper mess is just part of that, fuse is another example, etc etc ...

So I think Matthew is totally right. In fact, the presence of the freezer is the main reason why Paulus so far NACKed Johannes attempts at merging the PPC PM code with the generic code in kernel/power.c

We've been doing fine without it so far and intend to continue to do so.

As for suspend-to-disk, I refer you to the discussions we had in the past with Linus, where he explains I think quite clearly how wrong the current implementation of STR is :-)

Thing is, if you're going to do snapshots, you should probably not sync after you have "frozen" anyway.

Cheers,
Ben.

Acked-by on v1 1/1
#468 lore raw
In reply to Matthew Garrett
Quoted 8 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

(And with much pleasure :-)

Cheers,
Ben.

Acked-by on v1 1/1
#469 lore raw
In reply to Matthew Garrett
Quoted 8 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

(And with much pleasure :-)

Cheers,
Ben.

#471 lore raw
In reply to Matthew Garrett
Quoted 6 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

Ben.

#472 lore raw
In reply to Matthew Garrett
Quoted 6 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

Ben.

#9 lore raw
In reply to Benjamin Herrenschmidt

Hi.

Quoted 2 lines · On Tuesday 03 July 2007 15:48:26 Benjamin Herrenschmidt wrote:
Quoted 2 lines

Note, though, that this won't help at all when people use

the "suspend-to-ram

Quoted 8 lines
Quoted 3 lines

instead of powering down after writing a hibernation image" feature in (uswsusp | tuxonice). Fuse is just a broken idea in the first place, but given that it exists, we still need to find the underlying cause.

No, Fuse is not a broken idea in the first place. It's the freezer that is a totally broken idea. It has proven many times to be racy by design and cannot be made right. Ther usermode helper mess is just part of that, fuse is another example, etc etc ...

To some extent, I agree. I think the ideal solution would be to simply not schedule processes that are supposed to be frozen. But who wants to play with scheduler code? Not me!

Quoted 5 lines

So I think Matthew is totally right. In fact, the presence of the freezer is the main reason why Paulus so far NACKed Johannes attempts at merging the PPC PM code with the generic code in kernel/power.c

We've been doing fine without it so far and intend to continue to do so.

Fuse depends on !PPC?

Quoted 3 lines

As for suspend-to-disk, I refer you to the discussions we had in the past with Linus, where he explains I think quite clearly how wrong the current implementation of STR is :-)

I assume you mean STD. The problem there is that Linus doesn't care about STD. If he did, I dare say he'd think through the issues more thoroughly than he apparently has.

Quoted 2 lines

Thing is, if you're going to do snapshots, you should probably not sync after you have "frozen" anyway.

Fully agree. But how do you stop things syncing while you're writing the image if you don't have a freezer or equivalent? (scheduler based, kexec.. they're all workarounds for this issue).

Regards,

Nigel

Signature · 4 lines
Nigel, Michelle and Alisdair Cunningham
5 Mitchell Street
Cobden 3266
Victoria, Australia
#10 lore raw
In reply to Benjamin Herrenschmidt

Hi.

Quoted 2 lines · On Tuesday 03 July 2007 15:48:26 Benjamin Herrenschmidt wrote:
Quoted 2 lines

Note, though, that this won't help at all when people use

the "suspend-to-ram

Quoted 8 lines
Quoted 3 lines

instead of powering down after writing a hibernation image" feature in (uswsusp | tuxonice). Fuse is just a broken idea in the first place, but given that it exists, we still need to find the underlying cause.

No, Fuse is not a broken idea in the first place. It's the freezer that is a totally broken idea. It has proven many times to be racy by design and cannot be made right. Ther usermode helper mess is just part of that, fuse is another example, etc etc ...

To some extent, I agree. I think the ideal solution would be to simply not schedule processes that are supposed to be frozen. But who wants to play with scheduler code? Not me!

Quoted 5 lines

So I think Matthew is totally right. In fact, the presence of the freezer is the main reason why Paulus so far NACKed Johannes attempts at merging the PPC PM code with the generic code in kernel/power.c

We've been doing fine without it so far and intend to continue to do so.

Fuse depends on !PPC?

Quoted 3 lines

As for suspend-to-disk, I refer you to the discussions we had in the past with Linus, where he explains I think quite clearly how wrong the current implementation of STR is :-)

I assume you mean STD. The problem there is that Linus doesn't care about STD. If he did, I dare say he'd think through the issues more thoroughly than he apparently has.

Quoted 2 lines

Thing is, if you're going to do snapshots, you should probably not sync after you have "frozen" anyway.

Fully agree. But how do you stop things syncing while you're writing the image if you don't have a freezer or equivalent? (scheduler based, kexec.. they're all workarounds for this issue).

Regards,

Nigel

Signature · 4 lines
Nigel, Michelle and Alisdair Cunningham
5 Mitchell Street
Cobden 3266
Victoria, Australia
#538 lore raw
In reply to Matthew Garrett

Am Dienstag, 3. Juli 2007 schrieb Matthew Garrett:

Quoted 6 lines

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Only if you want to audit all character devices' read() and write() methods for races against suspend().
/ on fuse is a bad idea.

Regards
Oliver

#539 lore raw
In reply to Matthew Garrett

Am Dienstag, 3. Juli 2007 schrieb Matthew Garrett:

Quoted 6 lines

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Only if you want to audit all character devices' read() and write() methods for races against suspend().
/ on fuse is a bad idea.

Regards
Oliver

#540 lore raw
Quoted 10 lines
Quoted 6 lines

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Only if you want to audit all character devices' read() and write() methods for races against suspend().
/ on fuse is a bad idea.

What makes / special? Why aren't all fuse filesystems affected? Suspend isn't trying to do I/O on the root fs, is it?

Miklos

#11 lore raw
In reply to Nigel Cunningham
Quoted 8 lines · Nigel Cunningham
Quoted 6 lines

So I think Matthew is totally right. In fact, the presence of the freezer is the main reason why Paulus so far NACKed Johannes attempts at merging the PPC PM code with the generic code in kernel/power.c

We've been doing fine without it so far and intend to continue to do so.

Fuse depends on !PPC?

No, that's not what I'm saying. I'm saying we've been doing STR without the freezer and that's the way to go imho.

Quoted 5 lines
Quoted 3 lines

As for suspend-to-disk, I refer you to the discussions we had in the past with Linus, where he explains I think quite clearly how wrong the current implementation of STR is :-)

I assume you mean STD.

Oops, yeah, sorry.

Quoted 3 lines

The problem there is that Linus doesn't care about STD.
If he did, I dare say he'd think through the issues more thoroughly than he apparently has.

Heh, that might be the case :-)

Quoted 6 lines
Quoted 2 lines

Thing is, if you're going to do snapshots, you should probably not sync after you have "frozen" anyway.

Fully agree. But how do you stop things syncing while you're writing the image if you don't have a freezer or equivalent? (scheduler based, kexec.. they're all workarounds for this issue).

Well, I was saying that in the context of the -current- snapshotting mechanism which is based on the freezer, then you should not sys_sync().

Some random user or kernel thread doing a sync is not a problem. It will stop in the middle of sync and resume on wakeup.

The problem is currently because STD -itself- attempts to sync after it has frozen things.

I think that should be changed. If you want to sync for whatever reason, (mostly save RAM ?) do it before the freeze. That means you may get new dirty data in memory that isn't written out by the sync before you freeze, but that's allright, that data will be in the suspend image anyway. If you fail to wakeup, that's akin to a normal crash, the user will only lose the last data written at the time of the suspend and journaling fs'es should take care of fs metadata integrity.

So to summarize, the plan that makes things work with fuse is:

- For STR, don't do the freezer thing.

- For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of them at least. Of course, you'll be in trouble if you try to do things like STD-to-a-file which sits on a fuse FS but there's a limit to insanity :-)

Cheers,
Ben.

#12 lore raw
In reply to Nigel Cunningham
Quoted 8 lines · Nigel Cunningham
Quoted 6 lines

So I think Matthew is totally right. In fact, the presence of the freezer is the main reason why Paulus so far NACKed Johannes attempts at merging the PPC PM code with the generic code in kernel/power.c

We've been doing fine without it so far and intend to continue to do so.

Fuse depends on !PPC?

No, that's not what I'm saying. I'm saying we've been doing STR without the freezer and that's the way to go imho.

Quoted 5 lines
Quoted 3 lines

As for suspend-to-disk, I refer you to the discussions we had in the past with Linus, where he explains I think quite clearly how wrong the current implementation of STR is :-)

I assume you mean STD.

Oops, yeah, sorry.

Quoted 3 lines

The problem there is that Linus doesn't care about STD.
If he did, I dare say he'd think through the issues more thoroughly than he apparently has.

Heh, that might be the case :-)

Quoted 6 lines
Quoted 2 lines

Thing is, if you're going to do snapshots, you should probably not sync after you have "frozen" anyway.

Fully agree. But how do you stop things syncing while you're writing the image if you don't have a freezer or equivalent? (scheduler based, kexec.. they're all workarounds for this issue).

Well, I was saying that in the context of the -current- snapshotting mechanism which is based on the freezer, then you should not sys_sync().

Some random user or kernel thread doing a sync is not a problem. It will stop in the middle of sync and resume on wakeup.

The problem is currently because STD -itself- attempts to sync after it has frozen things.

I think that should be changed. If you want to sync for whatever reason, (mostly save RAM ?) do it before the freeze. That means you may get new dirty data in memory that isn't written out by the sync before you freeze, but that's allright, that data will be in the suspend image anyway. If you fail to wakeup, that's akin to a normal crash, the user will only lose the last data written at the time of the suspend and journaling fs'es should take care of fs metadata integrity.

So to summarize, the plan that makes things work with fuse is:

- For STR, don't do the freezer thing.

- For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of them at least. Of course, you'll be in trouble if you try to do things like STD-to-a-file which sits on a fuse FS but there's a limit to insanity :-)

Cheers,
Ben.

#545 lore raw
In reply to Matthew Garrett
Quoted 2 lines · Matthew Garrett

or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

As a data point, I am running with this patch on top of 2.6.21.2 the last 3+ weeks, with an average of 5/6 STR cycles a day, and had no problems at all. (Sony vaio pcg-fx701). Just normal work, I didn't try to stress the thing, but I have quite a few times suspended/resumed over a big compile without a glitch.

What are the risks of this patch supposed to be?

Romano

--
La presente comunicación tiene carácter confidencial y es para el exclusivo uso del destinatario indicado en la misma. Si Ud. no es el destinatario indicado, le informamos que cualquier forma de distribución, reproducción o uso de esta comunicación y/o de la información contenida en la misma están estrictamente prohibidos por la ley. Si Ud. ha recibido esta comunicación por error, por favor, notifíquelo inmediatamente al remitente contestando a este mensaje y proceda a continuación a destruirlo. Gracias por su colaboración.

This communication contains confidential information. It is for the exclusive use of the intended addressee. If you are not the intended addressee, please note that any form of distribution, copying or use of this communication or the information in it is strictly prohibited by law. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy this message. Thank you for your cooperation.

#13 lore raw
In reply to Benjamin Herrenschmidt

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 7 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Regards
Oliver

#14 lore raw
In reply to Benjamin Herrenschmidt

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 7 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Regards
Oliver

#546 lore raw
In reply to Matthew Garrett
Quoted 2 lines · Matthew Garrett

or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

As a data point, I am running with this patch on top of 2.6.21.2 the last 3+ weeks, with an average of 5/6 STR cycles a day, and had no problems at all. (Sony vaio pcg-fx701). Just normal work, I didn't try to stress the thing, but I have quite a few times suspended/resumed over a big compile without a glitch.

What are the risks of this patch supposed to be?

Romano

--
La presente comunicación tiene carácter confidencial y es para el exclusivo uso del destinatario indicado en la misma. Si Ud. no es el destinatario indicado, le informamos que cualquier forma de distribución, reproducción o uso de esta comunicación y/o de la información contenida en la misma están estrictamente prohibidos por la ley. Si Ud. ha recibido esta comunicación por error, por favor, notifíquelo inmediatamente al remitente contestando a este mensaje y proceda a continuación a destruirlo. Gracias por su colaboración.

This communication contains confidential information. It is for the exclusive use of the intended addressee. If you are not the intended addressee, please note that any form of distribution, copying or use of this communication or the information in it is strictly prohibited by law. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy this message. Thank you for your cooperation.

#547 lore raw

Am Dienstag, 3. Juli 2007 schrieb Romano Giannetti:

Quoted 11 lines · Matthew Garrett
Quoted 2 lines

or alternatively we  could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

As a data point, I am running with this patch on top of 2.6.21.2 the last 3+ weeks, with an average of 5/6 STR cycles a day, and had no problems at all. (Sony vaio pcg-fx701). Just normal work, I didn't try to stress the thing, but I have quite a few times suspended/resumed over a big compile without a glitch.

What are the risks of this patch supposed to be?

You did this test only while stressing normal block devices. Try provoking races in character devices.

Regards
Oliver

#548 lore raw
In reply to Romano Giannetti

Am Dienstag, 3. Juli 2007 schrieb Romano Giannetti:

Quoted 11 lines · Matthew Garrett
Quoted 2 lines

or alternatively we  could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

As a data point, I am running with this patch on top of 2.6.21.2 the last 3+ weeks, with an average of 5/6 STR cycles a day, and had no problems at all. (Sony vaio pcg-fx701). Just normal work, I didn't try to stress the thing, but I have quite a few times suspended/resumed over a big compile without a glitch.

What are the risks of this patch supposed to be?

You did this test only while stressing normal block devices. Try provoking races in character devices.

Regards
Oliver

#15 lore raw
In reply to Oliver Neukum
Quoted 4 lines
Quoted 4 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

Quoted 8 lines
Quoted 3 lines

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Oliver, can you please explain your worries in a bit more detail?

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

And conceptually I can't see anything that would cause trouble either. The fuse kernel module just provides a specialized IPC mechanism, where one userspace process communicates with another using file operations and a char dev.

Miklos

#16 lore raw
In reply to Oliver Neukum
Quoted 4 lines
Quoted 4 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

Quoted 8 lines
Quoted 3 lines

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Oliver, can you please explain your worries in a bit more detail?

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

And conceptually I can't see anything that would cause trouble either. The fuse kernel module just provides a specialized IPC mechanism, where one userspace process communicates with another using file operations and a char dev.

Miklos

#17 lore raw

Am Dienstag, 3. Juli 2007 schrieb Miklos Szeredi:

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

Quoted 8 lines
Quoted 3 lines

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Quoted 5 lines

Oliver, can you please explain your worries in a bit more detail?

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

The problem is not with fuse. The problem is generic in nature.

If you remove the freezer, user space remains active until the last CPU goes into suspend. It can do syscalls. Or do you know a clean way to exempt only the tasks fuse might use?

Now device drivers have a guaranteed temporal sequence:

last io -> suspend() -> resume() [or disconnect()] -> new io

This is because suspend() is called after the freezer goes into action. If you remove the freezer, you need to deal with

1. io to suspended devices
2. resume() assuming that the device is in the state suspend() left it
3. io changing a device's state while suspend is saving it

and you need to fix this for all device drivers, not just those fuse is involved with. Removing the freezer means doing a more or less full audit of every driver and additional locking in many drivers.

Regards
Oliver

#18 lore raw
In reply to Miklos Szeredi

Am Dienstag, 3. Juli 2007 schrieb Miklos Szeredi:

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

Quoted 8 lines
Quoted 3 lines

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Quoted 5 lines

Oliver, can you please explain your worries in a bit more detail?

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

The problem is not with fuse. The problem is generic in nature.

If you remove the freezer, user space remains active until the last CPU goes into suspend. It can do syscalls. Or do you know a clean way to exempt only the tasks fuse might use?

Now device drivers have a guaranteed temporal sequence:

last io -> suspend() -> resume() [or disconnect()] -> new io

This is because suspend() is called after the freezer goes into action. If you remove the freezer, you need to deal with

1. io to suspended devices
2. resume() assuming that the device is in the state suspend() left it
3. io changing a device's state while suspend is saving it

and you need to fix this for all device drivers, not just those fuse is involved with. Removing the freezer means doing a more or less full audit of every driver and additional locking in many drivers.

Regards
Oliver

#19 lore raw
Quoted 19 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

Quoted 8 lines
Quoted 3 lines

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Quoted 5 lines

Oliver, can you please explain your worries in a bit more detail?

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

Quoted 5 lines

The problem is not with fuse. The problem is generic in nature.

If you remove the freezer, user space remains active until the last CPU goes into suspend. It can do syscalls. Or do you know a clean way to exempt only the tasks fuse might use?

You are talking about hibernate, right? Suspending (to ram) is instantaneous, in that _after_ suspend no CPU is active obviously.

Quoted 7 lines

Now device drivers have a guaranteed temporal sequence:

last io -> suspend() -> resume() [or disconnect()] -> new io

This is because suspend() is called after the freezer goes into action. If you remove the freezer, you need to deal with

Quoted 7 lines

1. io to suspended devices
2. resume() assuming that the device is in the state suspend() left it
3. io changing a device's state while suspend is saving it

and you need to fix this for all device drivers, not just those fuse is involved with. Removing the freezer means doing a more or less full audit of every driver and additional locking in many drivers.

OK, this has _nothing_ at all to do with fuse then, and everything to do with disk I/O.

Just because fuse is a filesystem, it doesn't have to do anything with block devices, just like procfs doesn't either.

So removing the freezer from the hibernate path would be problematic, but as I understand this is not what has been proposed, only removing the freezer from the STR path, which should be OK.

Miklos

#20 lore raw
In reply to Oliver Neukum
Quoted 19 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

Quoted 8 lines
Quoted 3 lines

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Quoted 5 lines

Oliver, can you please explain your worries in a bit more detail?

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

Quoted 5 lines

The problem is not with fuse. The problem is generic in nature.

If you remove the freezer, user space remains active until the last CPU goes into suspend. It can do syscalls. Or do you know a clean way to exempt only the tasks fuse might use?

You are talking about hibernate, right? Suspending (to ram) is instantaneous, in that _after_ suspend no CPU is active obviously.

Quoted 7 lines

Now device drivers have a guaranteed temporal sequence:

last io -> suspend() -> resume() [or disconnect()] -> new io

This is because suspend() is called after the freezer goes into action. If you remove the freezer, you need to deal with

Quoted 7 lines

1. io to suspended devices
2. resume() assuming that the device is in the state suspend() left it
3. io changing a device's state while suspend is saving it

and you need to fix this for all device drivers, not just those fuse is involved with. Removing the freezer means doing a more or less full audit of every driver and additional locking in many drivers.

OK, this has _nothing_ at all to do with fuse then, and everything to do with disk I/O.

Just because fuse is a filesystem, it doesn't have to do anything with block devices, just like procfs doesn't either.

So removing the freezer from the hibernate path would be problematic, but as I understand this is not what has been proposed, only removing the freezer from the STR path, which should be OK.

Miklos

#43 lore raw
In reply to Oliver Neukum
Quoted 4 lines · Oliver Neukum

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Going back to the old powerbook sleep code, we had a two-phase
suspend: drivers got notified once when userspace is still running, with interrupts enabled, in process context; and then a second time with interrupts disabled and with only one CPU up, so the process that is initiating the suspend is the only process running (since interrupts are disabled and nothing it does can sleep, no other process can get to run).

I still believe that is the right way to go, although we currently only have a single-phase suspend.

Most drivers suspended their hardware in the second call. If they are in the middle of a conversation with their device that *has* to be completed, they can do that by polling. If it's a character device, a better approach would be to set a flag or whatever in the first suspend call to make sure that no new conversations get started with the device, sleeping if necessary.

I'm actually having a hard time thinking of how to test your assertion since there are so few things on a typical computer that are plain character devices driving real hardware. A serial port would be about the only one; keyboards and mice (and serial ports :) are USB these days, or ADB on older powerbooks.

Or did you mean to include drivers for pseudo-devices (e.g. ptys)? I don't see why they would have a suspend method at all.

Paul.

#44 lore raw
In reply to Oliver Neukum
Quoted 4 lines · Oliver Neukum

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Going back to the old powerbook sleep code, we had a two-phase
suspend: drivers got notified once when userspace is still running, with interrupts enabled, in process context; and then a second time with interrupts disabled and with only one CPU up, so the process that is initiating the suspend is the only process running (since interrupts are disabled and nothing it does can sleep, no other process can get to run).

I still believe that is the right way to go, although we currently only have a single-phase suspend.

Most drivers suspended their hardware in the second call. If they are in the middle of a conversation with their device that *has* to be completed, they can do that by polling. If it's a character device, a better approach would be to set a flag or whatever in the first suspend call to make sure that no new conversations get started with the device, sleeping if necessary.

I'm actually having a hard time thinking of how to test your assertion since there are so few things on a typical computer that are plain character devices driving real hardware. A serial port would be about the only one; keyboards and mice (and serial ports :) are USB these days, or ADB on older powerbooks.

Or did you mean to include drivers for pseudo-devices (e.g. ptys)? I don't see why they would have a suspend method at all.

Paul.

#21 lore raw
In reply to Miklos Szeredi

Am Dienstag, 3. Juli 2007 schrieb Miklos Szeredi:

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 4 lines
Quoted 4 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

Quoted 8 lines
Quoted 3 lines

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Oliver, can you please explain your worries in a bit more detail?

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

Quoted 8 lines
Quoted 5 lines

The problem is not with fuse. The problem is generic in nature.

If you remove the freezer, user space remains active until the last CPU goes into suspend. It can do syscalls. Or do you know a clean way to exempt only the tasks fuse might use?

You are talking about hibernate, right?  Suspending (to ram) is instantaneous, in that _after_ suspend no CPU is active obviously.

If that is so, why do you care? If it is really atomic, fuse has no chance to call out to its component in user space either. Removing the freezer cannot make a difference.

Something is fishy here.

Regards
Oliver

#22 lore raw
In reply to Miklos Szeredi

Am Dienstag, 3. Juli 2007 schrieb Miklos Szeredi:

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 4 lines
Quoted 4 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

Quoted 8 lines
Quoted 3 lines

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Oliver, can you please explain your worries in a bit more detail?

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

Quoted 8 lines
Quoted 5 lines

The problem is not with fuse. The problem is generic in nature.

If you remove the freezer, user space remains active until the last CPU goes into suspend. It can do syscalls. Or do you know a clean way to exempt only the tasks fuse might use?

You are talking about hibernate, right?  Suspending (to ram) is instantaneous, in that _after_ suspend no CPU is active obviously.

If that is so, why do you care? If it is really atomic, fuse has no chance to call out to its component in user space either. Removing the freezer cannot make a difference.

Something is fishy here.

Regards
Oliver

#73 lore raw
In reply to Oliver Neukum
Quoted 5 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 4 lines

So to summarize, the plan that makes things work with fuse is:

- For STR, don't do the freezer thing.

Quoted 8 lines
Quoted 3 lines

- For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Ugh ... "character devices" ... that's a pretty wide statement... there's lots of those and very different one from the other...

Any sane device-driver will have to cope with being suspended in a "live" system. I've demonstrated multiple times in the past why this is necessary anyway, for things like dynamic power management, among others.

The whole freezer thing is a hack job to avoid fixing drivers that need fixing. Unfortunately, I believe in that area, it's simply not sustainable. Besides, getting drivers to behave properly isn't very hard in most cases.

Ben.

#45 lore raw
In reply to Paul Mackerras

Am Dienstag, 3. Juli 2007 schrieb Paul Mackerras:

Quoted 5 lines

I'm actually having a hard time thinking of how to test your assertion since there are so few things on a typical computer that are plain character devices driving real hardware.  A serial port would be about the only one; keyboards and mice (and serial ports :) are USB these days, or ADB on older powerbooks.

USB devices certainly have suspend methods.

Regards
Oliver

#28 lore raw
In reply to Oliver Neukum
Quoted 10 lines

The problem is not with fuse. The problem is generic in nature.

If you remove the freezer, user space remains active until the last CPU goes into suspend. It can do syscalls. Or do you know a clean way to exempt only the tasks fuse might use?

Now device drivers have a guaranteed temporal sequence:

last io -> suspend() -> resume() [or disconnect()] -> new io

No, that's always been bullshit. You can have IOs emitted by kernel threads (think knfsd, and that's just one among many others). Beside, relying on having userland frozen means that your driver will be unable to be "live" suspended/resumed for more ambitious dynamic power management schemes.

So it's always been wrong, imho, to rely on that. I've had powermac STR work fine without the freezer for years, and few drivers have been a problem, and we just fixed them.

The freezer thingy, at best, hides problems, causing them not to be fixed.

Quoted 10 lines

This is because suspend() is called after the freezer goes into action. If you remove the freezer, you need to deal with

1. io to suspended devices
2. resume() assuming that the device is in the state suspend() left it
3. io changing a device's state while suspend is saving it

and you need to fix this for all device drivers, not just those fuse is involved with. Removing the freezer means doing a more or less full audit of every driver and additional locking in many drivers.

Yes, more or less.

The good news is that a whole lot of drivers don't really care much, and in some cases, things can be done trivially with a bit of help from the upper layers. But yeah, as I've been explaining over and over again, the lazy approach here doesn't work.

Ben.

#23 lore raw
In reply to Oliver Neukum
Quoted 8 lines · Oliver Neukum
Quoted 2 lines

You are talking about hibernate, right? Suspending (to ram) is instantaneous, in that _after_ suspend no CPU is active obviously.

If that is so, why do you care? If it is really atomic, fuse has no chance
to call out to its component in user space either. Removing the freezer
cannot make a difference.

It's not atomic. You will get called after suspend() in drivers. The thing is ... you just have to deal with it :-)

Ben.

#24 lore raw
In reply to Oliver Neukum
Quoted 8 lines · Oliver Neukum
Quoted 2 lines

You are talking about hibernate, right? Suspending (to ram) is instantaneous, in that _after_ suspend no CPU is active obviously.

If that is so, why do you care? If it is really atomic, fuse has no chance
to call out to its component in user space either. Removing the freezer
cannot make a difference.

It's not atomic. You will get called after suspend() in drivers. The thing is ... you just have to deal with it :-)

Ben.

#74 lore raw
In reply to Benjamin Herrenschmidt

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 10 lines · Oliver Neukum
Quoted 9 lines

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 7 lines

So to summarize, the plan that makes things work with fuse is:

- For STR, don't do the freezer thing.

- For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

Quoted 7 lines
Quoted 4 lines

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Ugh ... "character devices" ... that's a pretty wide statement... there's lots of those and very different one from the other...

That is a good summary of the problem ;-(

Quoted 4 lines

Any sane device-driver will have to cope with being suspended in a "live" system. I've demonstrated multiple times in the past why this is necessary anyway, for things like dynamic power management, among others.

That is an interesting notion. I'd rather see device drivers reporting their devices idle and requsting to be suspended.
But in any case it doesn't solve the problem.

Regards
Oliver

#25 lore raw
In reply to Benjamin Herrenschmidt

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 12 lines · Oliver Neukum
Quoted 8 lines
Quoted 2 lines

You are talking about hibernate, right?  Suspending (to ram) is instantaneous, in that _after_ suspend no CPU is active obviously.

If that is so, why do you care? If it is really atomic, fuse has no chance
to call out to its component in user space either. Removing the freezer
cannot make a difference.

It's not atomic. You will get called after suspend() in drivers. The thing is ... you just have to deal with it :-)

So you are volunteering to go through all drivers >:-> ?

Regards
Oliver

#29 lore raw
In reply to Benjamin Herrenschmidt

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 6 lines
Quoted 3 lines

Now device drivers have a guaranteed temporal sequence:

last io -> suspend() -> resume() [or disconnect()] -> new io

No, that's always been bullshit. You can have IOs emitted by kernel threads (think knfsd, and that's just one among many others). Beside,

That's why we have the problem of freezing the kernel threads or not. Short of knfsd very few kernel threads really operate on their own and those can use the new notifier chain.

Quoted 3 lines

relying on having userland frozen means that your driver will be unable to be "live" suspended/resumed for more ambitious dynamic power management schemes.

Only if they work without cooperation and idle detection in the drivers.

Quoted 3 lines

So it's always been wrong, imho, to rely on that. I've had powermac STR work fine without the freezer for years, and few drivers have been a problem, and we just fixed them.

Powermacs are somewhat limited in hardware used with them (OK, powerbook have PCMCIA, but how often is that used?)

You want to have all that pain for fuse?

Regards
Oliver

#30 lore raw
In reply to Benjamin Herrenschmidt

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 6 lines
Quoted 3 lines

Now device drivers have a guaranteed temporal sequence:

last io -> suspend() -> resume() [or disconnect()] -> new io

No, that's always been bullshit. You can have IOs emitted by kernel threads (think knfsd, and that's just one among many others). Beside,

That's why we have the problem of freezing the kernel threads or not. Short of knfsd very few kernel threads really operate on their own and those can use the new notifier chain.

Quoted 3 lines

relying on having userland frozen means that your driver will be unable to be "live" suspended/resumed for more ambitious dynamic power management schemes.

Only if they work without cooperation and idle detection in the drivers.

Quoted 3 lines

So it's always been wrong, imho, to rely on that. I've had powermac STR work fine without the freezer for years, and few drivers have been a problem, and we just fixed them.

Powermacs are somewhat limited in hardware used with them (OK, powerbook have PCMCIA, but how often is that used?)

You want to have all that pain for fuse?

Regards
Oliver

#541 lore raw
In reply to Oliver Neukum
Quoted 3 lines · Oliver Neukum

Only if you want to audit all character devices' read() and write() methods for races against suspend().
/ on fuse is a bad idea.

Any driver that assumes that userspace will be frozen during suspend has been broken forever. That behaviour has never been guaranteed.

Signature · 1 line
Matthew Garrett | [email protected]
#542 lore raw
In reply to Oliver Neukum
Quoted 3 lines · Oliver Neukum

Only if you want to audit all character devices' read() and write() methods for races against suspend().
/ on fuse is a bad idea.

Any driver that assumes that userspace will be frozen during suspend has been broken forever. That behaviour has never been guaranteed.

Signature · 1 line
Matthew Garrett | [email protected]
#550 lore raw
In reply to Matthew Garrett
Quoted 8 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Could you please rediff against the current -mm tree?

There are some patches in there that this will clash with.

I still think that this is a mistake, BTW. Please see the Alan's post at

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#76 lore raw
In reply to Benjamin Herrenschmidt
Quoted 38 lines · Benjamin Herrenschmidt
Quoted 8 lines · Nigel Cunningham
Quoted 6 lines

So I think Matthew is totally right. In fact, the presence of the freezer is the main reason why Paulus so far NACKed Johannes attempts at merging the PPC PM code with the generic code in kernel/power.c

We've been doing fine without it so far and intend to continue to do so.

Fuse depends on !PPC?

No, that's not what I'm saying. I'm saying we've been doing STR without the freezer and that's the way to go imho.

Quoted 5 lines
Quoted 3 lines

As for suspend-to-disk, I refer you to the discussions we had in the past with Linus, where he explains I think quite clearly how wrong the current implementation of STR is :-)

I assume you mean STD.

Oops, yeah, sorry.

Quoted 3 lines

The problem there is that Linus doesn't care about STD.
If he did, I dare say he'd think through the issues more thoroughly than he apparently has.

Heh, that might be the case :-)

Quoted 6 lines
Quoted 2 lines

Thing is, if you're going to do snapshots, you should probably not sync after you have "frozen" anyway.

Fully agree. But how do you stop things syncing while you're writing the image if you don't have a freezer or equivalent? (scheduler based, kexec.. they're all workarounds for this issue).

Well, I was saying that in the context of the -current- snapshotting mechanism which is based on the freezer, then you should not sys_sync().

Quoted 5 lines

Some random user or kernel thread doing a sync is not a problem. It will stop in the middle of sync and resume on wakeup.

The problem is currently because STD -itself- attempts to sync after it has frozen things.

To be precise, it tries to sync after it has frozen the user land.

Quoted 11 lines

I think that should be changed. If you want to sync for whatever reason, (mostly save RAM ?) do it before the freeze. That means you may get new dirty data in memory that isn't written out by the sync before you freeze, but that's allright, that data will be in the suspend image anyway. If you fail to wakeup, that's akin to a normal crash, the user will only lose the last data written at the time of the suspend and journaling fs'es should take care of fs metadata integrity.

So to summarize, the plan that makes things work with fuse is:

- For STR, don't do the freezer thing.

In the long run, I agree.

Still, can you please read this post from Alan Stern:

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

? I don't think I'm able to repeat the arguments given in there in a convincing way.

Quoted 1 line

- For STD, don't sys_sync() after you froze

Yeah, I think we can move the syncing before the freezing, so to speak.

And it need not be called from within the freezer, BTW.

Quoted 4 lines

There might be -other- issues, but that should get you through some of them at least. Of course, you'll be in trouble if you try to do things like STD-to-a-file which sits on a fuse FS but there's a limit to insanity :-)

Yes. :-)

Ggreetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#39 lore raw
In reply to Oliver Neukum
Quoted 33 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Miklos Szeredi:

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

Quoted 8 lines
Quoted 3 lines

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Quoted 5 lines

Oliver, can you please explain your worries in a bit more detail?

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

The problem is not with fuse. The problem is generic in nature.

If you remove the freezer, user space remains active until the last CPU goes into suspend. It can do syscalls. Or do you know a clean way to exempt only the tasks fuse might use?

Now device drivers have a guaranteed temporal sequence:

last io -> suspend() -> resume() [or disconnect()] -> new io

This is because suspend() is called after the freezer goes into action. If you remove the freezer, you need to deal with

Quoted 7 lines

1. io to suspended devices
2. resume() assuming that the device is in the state suspend() left it
3. io changing a device's state while suspend is saving it

and you need to fix this for all device drivers, not just those fuse is involved with. Removing the freezer means doing a more or less full audit of every driver and additional locking in many drivers.

Agreed.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#558 lore raw
In reply to Matthew Garrett
Quoted 8 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Could you please rediff against the current -mm tree?

There are some patches in there that this will clash with.

I still think that this is a mistake, BTW. Please see the Alan's post at

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#463 lore raw
In reply to Benjamin Herrenschmidt
Quoted 38 lines · Benjamin Herrenschmidt
Quoted 8 lines · Nigel Cunningham
Quoted 6 lines

So I think Matthew is totally right. In fact, the presence of the freezer is the main reason why Paulus so far NACKed Johannes attempts at merging the PPC PM code with the generic code in kernel/power.c

We've been doing fine without it so far and intend to continue to do so.

Fuse depends on !PPC?

No, that's not what I'm saying. I'm saying we've been doing STR without the freezer and that's the way to go imho.

Quoted 5 lines
Quoted 3 lines

As for suspend-to-disk, I refer you to the discussions we had in the past with Linus, where he explains I think quite clearly how wrong the current implementation of STR is :-)

I assume you mean STD.

Oops, yeah, sorry.

Quoted 3 lines

The problem there is that Linus doesn't care about STD.
If he did, I dare say he'd think through the issues more thoroughly than he apparently has.

Heh, that might be the case :-)

Quoted 6 lines
Quoted 2 lines

Thing is, if you're going to do snapshots, you should probably not sync after you have "frozen" anyway.

Fully agree. But how do you stop things syncing while you're writing the image if you don't have a freezer or equivalent? (scheduler based, kexec.. they're all workarounds for this issue).

Well, I was saying that in the context of the -current- snapshotting mechanism which is based on the freezer, then you should not sys_sync().

Quoted 5 lines

Some random user or kernel thread doing a sync is not a problem. It will stop in the middle of sync and resume on wakeup.

The problem is currently because STD -itself- attempts to sync after it has frozen things.

To be precise, it tries to sync after it has frozen the user land.

Quoted 11 lines

I think that should be changed. If you want to sync for whatever reason, (mostly save RAM ?) do it before the freeze. That means you may get new dirty data in memory that isn't written out by the sync before you freeze, but that's allright, that data will be in the suspend image anyway. If you fail to wakeup, that's akin to a normal crash, the user will only lose the last data written at the time of the suspend and journaling fs'es should take care of fs metadata integrity.

So to summarize, the plan that makes things work with fuse is:

- For STR, don't do the freezer thing.

In the long run, I agree.

Still, can you please read this post from Alan Stern:

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

? I don't think I'm able to repeat the arguments given in there in a convincing way.

Quoted 1 line

- For STD, don't sys_sync() after you froze

Yeah, I think we can move the syncing before the freezing, so to speak.

And it need not be called from within the freezer, BTW.

Quoted 4 lines

There might be -other- issues, but that should get you through some of them at least. Of course, you'll be in trouble if you try to do things like STD-to-a-file which sits on a fuse FS but there's a limit to insanity :-)

Yes. :-)

Ggreetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#40 lore raw
In reply to Oliver Neukum
Quoted 33 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Miklos Szeredi:

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

Quoted 8 lines
Quoted 3 lines

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Quoted 5 lines

Oliver, can you please explain your worries in a bit more detail?

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

The problem is not with fuse. The problem is generic in nature.

If you remove the freezer, user space remains active until the last CPU goes into suspend. It can do syscalls. Or do you know a clean way to exempt only the tasks fuse might use?

Now device drivers have a guaranteed temporal sequence:

last io -> suspend() -> resume() [or disconnect()] -> new io

This is because suspend() is called after the freezer goes into action. If you remove the freezer, you need to deal with

Quoted 7 lines

1. io to suspended devices
2. resume() assuming that the device is in the state suspend() left it
3. io changing a device's state while suspend is saving it

and you need to fix this for all device drivers, not just those fuse is involved with. Removing the freezer means doing a more or less full audit of every driver and additional locking in many drivers.

Agreed.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#75 lore raw
In reply to Oliver Neukum
Quoted 21 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 10 lines · Oliver Neukum
Quoted 9 lines

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 7 lines

So to summarize, the plan that makes things work with fuse is:

- For STR, don't do the freezer thing.

- For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

Quoted 7 lines
Quoted 4 lines

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Ugh ... "character devices" ... that's a pretty wide statement... there's lots of those and very different one from the other...

That is a good summary of the problem ;-(

Quoted 8 lines
Quoted 4 lines

Any sane device-driver will have to cope with being suspended in a "live" system. I've demonstrated multiple times in the past why this is necessary anyway, for things like dynamic power management, among others.

That is an interesting notion. I'd rather see device drivers reporting their devices idle and requsting to be suspended.
But in any case it doesn't solve the problem.

Agreed.

What I think will solve the problem in the long run is to:

1) Separate the hibernation code from the suspend code (ie. hibernation-related callbacks should generally be different from suspend-related callback for each driver).
2) Remove the freezing of kernel threads from each of them (in the hibernation case, if possible) an fix the things that get broken.
3) Remove the freezing of user space from the suspend code path and fix the things that get broken.

Going to step 3) before doing 1) and 2) doesn't seem to be the right thing to me.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#470 lore raw
In reply to Benjamin Herrenschmidt
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quoted 5 lines
Quoted 1 line

(And with much pleasure :-)

Clashes with some code already in -mm.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#473 lore raw
In reply to Benjamin Herrenschmidt
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 6 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#543 lore raw
In reply to Matthew Garrett
Quoted 8 lines · Matthew Garrett
Quoted 3 lines · Oliver Neukum

Only if you want to audit all character devices' read() and write() methods for races against suspend().
/ on fuse is a bad idea.

Any driver that assumes that userspace will be frozen during suspend has been broken forever. That behaviour has never been guaranteed.

Can we please fix those drivers _first_, then?

Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#549 lore raw
In reply to Romano Giannetti
Quoted 11 lines · Romano Giannetti
Quoted 2 lines · Matthew Garrett

or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

As a data point, I am running with this patch on top of 2.6.21.2 the last 3+ weeks, with an average of 5/6 STR cycles a day, and had no problems at all. (Sony vaio pcg-fx701). Just normal work, I didn't try to stress the thing, but I have quite a few times suspended/resumed over a big compile without a glitch.

What are the risks of this patch supposed to be?

See https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#537 lore raw
In reply to Benjamin Herrenschmidt
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 6 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#544 lore raw
In reply to Matthew Garrett
Quoted 8 lines · Matthew Garrett
Quoted 3 lines · Oliver Neukum

Only if you want to audit all character devices' read() and write() methods for races against suspend().
/ on fuse is a bad idea.

Any driver that assumes that userspace will be frozen during suspend has been broken forever. That behaviour has never been guaranteed.

Can we please fix those drivers _first_, then?

Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#77 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki

Still, can you please read this post from Alan Stern:

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

? I don't think I'm able to repeat the arguments given in there in a convincing way.

As I read it, Alan basically has two objections:
(1) drivers shouldn't need to worry about this
(2) suspend should be transparent to userspace

His proposed solution (freezing tasks when they cross the kernel boundary) helps for the s-t-r case, but in fact doesn't solve (1) because devices can be suspended at runtime and then you certainly do not want to freeze tasks that try to access the device.

(2) is related but not identical, what if you have a device suspended at runtime and some tasks tries to access it; should the task block until you wake up that device?

I think the core of the discussion isn't appreciated by everybody here yet---we need to solve both run-time and suspend-to-ram-time device suspend, not just one of them.

johannes

#78 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki

Still, can you please read this post from Alan Stern:

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

? I don't think I'm able to repeat the arguments given in there in a convincing way.

As I read it, Alan basically has two objections:
(1) drivers shouldn't need to worry about this
(2) suspend should be transparent to userspace

His proposed solution (freezing tasks when they cross the kernel boundary) helps for the s-t-r case, but in fact doesn't solve (1) because devices can be suspended at runtime and then you certainly do not want to freeze tasks that try to access the device.

(2) is related but not identical, what if you have a device suspended at runtime and some tasks tries to access it; should the task block until you wake up that device?

I think the core of the discussion isn't appreciated by everybody here yet---we need to solve both run-time and suspend-to-ram-time device suspend, not just one of them.

johannes

#79 lore raw
Quoted 9 lines · Johannes Berg
Quoted 6 lines · Rafael J. Wysocki

Still, can you please read this post from Alan Stern:

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

? I don't think I'm able to repeat the arguments given in there in a convincing way.

Quoted 7 lines

As I read it, Alan basically has two objections:
(1) drivers shouldn't need to worry about this
(2) suspend should be transparent to userspace

His proposed solution (freezing tasks when they cross the kernel boundary) helps for the s-t-r case, but in fact doesn't solve (1) because devices can be suspended at runtime

This is a different thing and a different infrastructure is needed for it (not present at the moment).

Quoted 6 lines

and then you certainly do not want to freeze tasks that try to access the device.

(2) is related but not identical, what if you have a device suspended at runtime and some tasks tries to access it; should the task block until you wake up that device?

I think the device should be woken up in that case.

Quoted 3 lines

I think the core of the discussion isn't appreciated by everybody here yet---we need to solve both run-time and suspend-to-ram-time device suspend, not just one of them.

For now, we're discussing the suspend-to-ram-time suspend only, for which we have (some) infrastrcuture (and which should be supported by all drivers, IMO).

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#80 lore raw
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines

His proposed solution (freezing tasks when they cross the kernel boundary) helps for the s-t-r case, but in fact doesn't solve (1) because devices can be suspended at runtime

This is a different thing and a different infrastructure is needed for it (not present at the moment).

Yeah I should've said "any of his proposed solutions"

Quoted 8 lines
Quoted 6 lines

and then you certainly do not want to freeze tasks that try to access the device.

(2) is related but not identical, what if you have a device suspended at runtime and some tasks tries to access it; should the task block until you wake up that device?

I think the device should be woken up in that case.

Ah, but that also means the device has to actually know about it.

Quoted 7 lines
Quoted 3 lines

I think the core of the discussion isn't appreciated by everybody here yet---we need to solve both run-time and suspend-to-ram-time device suspend, not just one of them.

For now, we're discussing the suspend-to-ram-time suspend only, for which we have (some) infrastrcuture (and which should be supported by all drivers, IMO).

Right but if we solve the run-time suspend case in favour of having the device driver know about it then the suspend-to-ram-time suspend case solves itself.

johannes

#81 lore raw
In reply to Johannes Berg
Quoted 13 lines · Johannes Berg
Quoted 6 lines · Rafael J. Wysocki

Still, can you please read this post from Alan Stern:

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

? I don't think I'm able to repeat the arguments given in there in a convincing way.

As I read it, Alan basically has two objections:
(1) drivers shouldn't need to worry about this
(2) suspend should be transparent to userspace

Quoted 8 lines

His proposed solution (freezing tasks when they cross the kernel boundary) helps for the s-t-r case, but in fact doesn't solve (1) because devices can be suspended at runtime and then you certainly do not want to freeze tasks that try to access the device.

(2) is related but not identical, what if you have a device suspended at runtime and some tasks tries to access it; should the task block until you wake up that device?

Time for me to jump in.

USB already implements runtime PM. If a device is suspended at runtime and a task tries to access it, the device is automatically resumed. No problem there.

The problem comes when the system is doing a STR. Right now the code doesn't keep track of the difference between a runtime suspend and a system suspend -- once the device is suspended, it's suspended, period. Consequently, a non-frozen user task trying to do I/O to a suspended device during STR will cause that device to resume, thereby forcing the system suspend to abort. Something much like this has actually happened and been reported as a bug on LKML (I don't have a URL handy, and it was actually a non-frozen kernel thread interfering with hibernate rather than a non-frozen user task interfering with STR, but the principle is the same).

Yes, the code could be changed to keep track of the reason for a device suspend. But that just raises the old problem of what to do when there's an I/O request for a suspended device during STR.

Quoted 3 lines

I think the core of the discussion isn't appreciated by everybody here yet---we need to solve both run-time and suspend-to-ram-time device suspend, not just one of them.

Runtime suspend isn't a problem. Only STR.

Consider a particularly troublesome case: During STR, a non-frozen task writes to /sys/bus/BBB/drivers/DDD/bind. The sysfs core grabs the device semaphore and calls the driver's probe routine. If the driver isn't PM-aware it simply tries to initialize the device and fails because the device is already suspended. That's no good; it isn't transparent.

So assume the driver is PM-aware. It tries to resume the device, which fails because STR is underway. Now what can it do? There's only one
possibility: It must block until the resume call can succeed. But when is that?

It has to be before the PM core tries to resume the device, because the core will try to acquire the device semaphore and will block waiting for the probe call to complete. But it has to be after the PM core resumes the device's parent, because obviously the device can't resume until its parent is awake.

As you can see, this is a very difficult problem to solve.

Alan Stern

#82 lore raw
Quoted 1 line · Alan Stern

Time for me to jump in.

:)

Quoted 3 lines

USB already implements runtime PM. If a device is suspended at runtime and a task tries to access it, the device is automatically resumed. No problem there.

Right.

Quoted 10 lines

The problem comes when the system is doing a STR. Right now the code doesn't keep track of the difference between a runtime suspend and a system suspend -- once the device is suspended, it's suspended, period. Consequently, a non-frozen user task trying to do I/O to a suspended device during STR will cause that device to resume, thereby forcing the system suspend to abort. Something much like this has actually happened and been reported as a bug on LKML (I don't have a URL handy, and it was actually a non-frozen kernel thread interfering with hibernate rather than a non-frozen user task interfering with STR, but the principle is the same).

Yeah, I can see that happen.

Quoted 9 lines

Yes, the code could be changed to keep track of the reason for a device suspend. But that just raises the old problem of what to do when there's an I/O request for a suspended device during STR.

Quoted 3 lines

I think the core of the discussion isn't appreciated by everybody here yet---we need to solve both run-time and suspend-to-ram-time device suspend, not just one of them.

Runtime suspend isn't a problem. Only STR.

Ah but for all those character devices people were saying are the problem we haven't even solved runtime suspend as far as I can tell from the discussion.

Quoted 12 lines

Consider a particularly troublesome case: During STR, a non-frozen task writes to /sys/bus/BBB/drivers/DDD/bind. The sysfs core grabs the device semaphore and calls the driver's probe routine. If the driver isn't PM-aware it simply tries to initialize the device and fails because the device is already suspended. That's no good; it isn't transparent.

So assume the driver is PM-aware. It tries to resume the device, which fails because STR is underway. Now what can it do? There's only one
possibility: It must block until the resume call can succeed. But when is that?

Quoted 7 lines

It has to be before the PM core tries to resume the device, because the core will try to acquire the device semaphore and will block waiting for the probe call to complete. But it has to be after the PM core resumes the device's parent, because obviously the device can't resume until its parent is awake.

As you can see, this is a very difficult problem to solve.

Indeed. Actually, one could argue that it's impossible to solve the problem as long as we try to call out to userspace during suspend and need to wait until that's finished, like in the case of sys_sync() and fuse filesystems, and probably other cases. Maybe we should make *those* calls return a failure so that the suspend isn't transparent inside the kernel but is transparent to userspace.

johannes

#83 lore raw
In reply to Alan Stern
Quoted 1 line · Alan Stern

Time for me to jump in.

:)

Quoted 3 lines

USB already implements runtime PM. If a device is suspended at runtime and a task tries to access it, the device is automatically resumed. No problem there.

Right.

Quoted 10 lines

The problem comes when the system is doing a STR. Right now the code doesn't keep track of the difference between a runtime suspend and a system suspend -- once the device is suspended, it's suspended, period. Consequently, a non-frozen user task trying to do I/O to a suspended device during STR will cause that device to resume, thereby forcing the system suspend to abort. Something much like this has actually happened and been reported as a bug on LKML (I don't have a URL handy, and it was actually a non-frozen kernel thread interfering with hibernate rather than a non-frozen user task interfering with STR, but the principle is the same).

Yeah, I can see that happen.

Quoted 9 lines

Yes, the code could be changed to keep track of the reason for a device suspend. But that just raises the old problem of what to do when there's an I/O request for a suspended device during STR.

Quoted 3 lines

I think the core of the discussion isn't appreciated by everybody here yet---we need to solve both run-time and suspend-to-ram-time device suspend, not just one of them.

Runtime suspend isn't a problem. Only STR.

Ah but for all those character devices people were saying are the problem we haven't even solved runtime suspend as far as I can tell from the discussion.

Quoted 12 lines

Consider a particularly troublesome case: During STR, a non-frozen task writes to /sys/bus/BBB/drivers/DDD/bind. The sysfs core grabs the device semaphore and calls the driver's probe routine. If the driver isn't PM-aware it simply tries to initialize the device and fails because the device is already suspended. That's no good; it isn't transparent.

So assume the driver is PM-aware. It tries to resume the device, which fails because STR is underway. Now what can it do? There's only one
possibility: It must block until the resume call can succeed. But when is that?

Quoted 7 lines

It has to be before the PM core tries to resume the device, because the core will try to acquire the device semaphore and will block waiting for the probe call to complete. But it has to be after the PM core resumes the device's parent, because obviously the device can't resume until its parent is awake.

As you can see, this is a very difficult problem to solve.

Indeed. Actually, one could argue that it's impossible to solve the problem as long as we try to call out to userspace during suspend and need to wait until that's finished, like in the case of sys_sync() and fuse filesystems, and probably other cases. Maybe we should make *those* calls return a failure so that the suspend isn't transparent inside the kernel but is transparent to userspace.

johannes

#474 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 6 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

Greetings,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.

---
 kernel/power/disk.c    |    4 ++++
 kernel/power/process.c |    1 -
 2 files changed, 4 insertions(+), 1 deletion(-)
kernel/power/disk.c +4 -0
Index: linux-2.6.22-rc7/kernel/power/disk.c
===================================================================
@@ -296,6 +296,10 @@ int hibernate(void)
 {
 	int error;
 
+	printk("Syncing filesystems ... \n");
+	sys_sync();
+	printk("done.\n");
+
 	mutex_lock(&pm_mutex);
 	/* The snapshot device should not be opened while we're running */
 	if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
kernel/power/process.c +0 -1
Index: linux-2.6.22-rc7/kernel/power/process.c
===================================================================
@@ -190,7 +190,6 @@ int freeze_processes(void)
 	if (error)
 		return error;
 
-	sys_sync();
 	error = try_to_freeze_tasks(FREEZER_KERNEL_THREADS);
 	if (error)
 		return error;
#534 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 6 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

Greetings,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.

---
 kernel/power/disk.c    |    4 ++++
 kernel/power/process.c |    1 -
 2 files changed, 4 insertions(+), 1 deletion(-)
kernel/power/disk.c +4 -0
Index: linux-2.6.22-rc7/kernel/power/disk.c
===================================================================
@@ -296,6 +296,10 @@ int hibernate(void)
 {
 	int error;
 
+	printk("Syncing filesystems ... \n");
+	sys_sync();
+	printk("done.\n");
+
 	mutex_lock(&pm_mutex);
 	/* The snapshot device should not be opened while we're running */
 	if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
kernel/power/process.c +0 -1
Index: linux-2.6.22-rc7/kernel/power/process.c
===================================================================
@@ -190,7 +190,6 @@ int freeze_processes(void)
 	if (error)
 		return error;
 
-	sys_sync();
 	error = try_to_freeze_tasks(FREEZER_KERNEL_THREADS);
 	if (error)
 		return error;
#84 lore raw
In reply to Johannes Berg
Quoted 57 lines · Johannes Berg
Quoted 1 line · Alan Stern

Time for me to jump in.

:)

Quoted 3 lines

USB already implements runtime PM. If a device is suspended at runtime and a task tries to access it, the device is automatically resumed. No problem there.

Right.

Quoted 10 lines

The problem comes when the system is doing a STR. Right now the code doesn't keep track of the difference between a runtime suspend and a system suspend -- once the device is suspended, it's suspended, period. Consequently, a non-frozen user task trying to do I/O to a suspended device during STR will cause that device to resume, thereby forcing the system suspend to abort. Something much like this has actually happened and been reported as a bug on LKML (I don't have a URL handy, and it was actually a non-frozen kernel thread interfering with hibernate rather than a non-frozen user task interfering with STR, but the principle is the same).

Yeah, I can see that happen.

Quoted 9 lines

Yes, the code could be changed to keep track of the reason for a device suspend. But that just raises the old problem of what to do when there's an I/O request for a suspended device during STR.

Quoted 3 lines

I think the core of the discussion isn't appreciated by everybody here yet---we need to solve both run-time and suspend-to-ram-time device suspend, not just one of them.

Runtime suspend isn't a problem. Only STR.

Ah but for all those character devices people were saying are the problem we haven't even solved runtime suspend as far as I can tell from the discussion.

Quoted 18 lines

Consider a particularly troublesome case: During STR, a non-frozen task writes to /sys/bus/BBB/drivers/DDD/bind. The sysfs core grabs the device semaphore and calls the driver's probe routine. If the driver isn't PM-aware it simply tries to initialize the device and fails because the device is already suspended. That's no good; it isn't transparent.

So assume the driver is PM-aware. It tries to resume the device, which fails because STR is underway. Now what can it do? There's only one
possibility: It must block until the resume call can succeed. But when is that?

It has to be before the PM core tries to resume the device, because the core will try to acquire the device semaphore and will block waiting for the probe call to complete. But it has to be after the PM core resumes the device's parent, because obviously the device can't resume until its parent is awake.

Quoted 8 lines
Quoted 1 line

As you can see, this is a very difficult problem to solve.

Indeed. Actually, one could argue that it's impossible to solve the problem as long as we try to call out to userspace during suspend and need to wait until that's finished, like in the case of sys_sync() and fuse filesystems, and probably other cases. Maybe we should make *those* calls return a failure so that the suspend isn't transparent inside the kernel but is transparent to userspace.

Well, it generally needs more consideration. :-)

I think that we should introduce mechanisms that will allow us to notify all kernel subsystems, including FUSE and similar, that the system is going to enter a sleep state (one of those is the notifier chain introduced recently).

Then, they may react to such a notification by entering a "suspend" mode of operation in which they will return errors from some callbacks that otherwise should have succeeded etc. That depends on the subsystem in question.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#41 lore raw
In reply to Oliver Neukum
Quoted 32 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

Quoted 8 lines
Quoted 3 lines

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Quoted 5 lines

Oliver, can you please explain your worries in a bit more detail?

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

The problem is not with fuse. The problem is generic in nature.

If you remove the freezer, user space remains active until the last CPU goes into suspend. It can do syscalls. Or do you know a clean way to exempt only the tasks fuse might use?

Now device drivers have a guaranteed temporal sequence:

last io -> suspend() -> resume() [or disconnect()] -> new io

This is because suspend() is called after the freezer goes into action. If you remove the freezer, you need to deal with

Quoted 6 lines

1. io to suspended devices
2. resume() assuming that the device is in the state suspend() left it
3. io changing a device's state while suspend is saving it

and you need to fix this for all device drivers, not just those fuse is involved with.

Fuse is not involved with _any_ device drivers. It is fully unaware of suspend issues and I think that's how it should stay ;)

Quoted 2 lines

Removing the freezer means doing a more or less full audit of every driver and additional locking in many drivers.

How about a "CONFIG_NOFREEZE (experimental): only turn this on if you want to fix buggy drivers that can fail during suspend with the freezer turned off"?

I'm guessing quite a few kernel developers would be willing to turn on such an option.

Miklos

#42 lore raw
In reply to Oliver Neukum
Quoted 32 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines

So to summarize, the plan that makes things work with fuse is:

 - For STR, don't do the freezer thing.

Quoted 8 lines
Quoted 3 lines

 - For STD, don't sys_sync() after you froze

There might be -other- issues, but that should get you through some of

At the risk of repeating myself. Character device drivers are written with the assumption that normal io and suspend/resume do not race with each other due to the freezer.
What do you intend to do about that?

Quoted 5 lines

Oliver, can you please explain your worries in a bit more detail?

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

The problem is not with fuse. The problem is generic in nature.

If you remove the freezer, user space remains active until the last CPU goes into suspend. It can do syscalls. Or do you know a clean way to exempt only the tasks fuse might use?

Now device drivers have a guaranteed temporal sequence:

last io -> suspend() -> resume() [or disconnect()] -> new io

This is because suspend() is called after the freezer goes into action. If you remove the freezer, you need to deal with

Quoted 6 lines

1. io to suspended devices
2. resume() assuming that the device is in the state suspend() left it
3. io changing a device's state while suspend is saving it

and you need to fix this for all device drivers, not just those fuse is involved with.

Fuse is not involved with _any_ device drivers. It is fully unaware of suspend issues and I think that's how it should stay ;)

Quoted 2 lines

Removing the freezer means doing a more or less full audit of every driver and additional locking in many drivers.

How about a "CONFIG_NOFREEZE (experimental): only turn this on if you want to fix buggy drivers that can fail during suspend with the freezer turned off"?

I'm guessing quite a few kernel developers would be willing to turn on such an option.

Miklos

#66 lore raw
In reply to Paul Mackerras
Quoted 8 lines · Paul Mackerras

Going back to the old powerbook sleep code, we had a two-phase
suspend: drivers got notified once when userspace is still running, with interrupts enabled, in process context; and then a second time with interrupts disabled and with only one CPU up, so the process that is initiating the suspend is the only process running (since interrupts are disabled and nothing it does can sleep, no other process can get to run).

Quoted 6 lines

I still believe that is the right way to go, although we currently only have a single-phase suspend.

Most drivers suspended their hardware in the second call. If they are in the middle of a conversation with their device that *has* to be completed, they can do that by polling.

Ugh. That will cause problems when you try to integrate runtime suspend. In fact this whole approach is unsuitable for runtime PM and it obscures the similarities between runtime PM and STR.

Quoted 10 lines

If it's a character device, a
better approach would be to set a flag or whatever in the first suspend call to make sure that no new conversations get started with the device, sleeping if necessary.

I'm actually having a hard time thinking of how to test your assertion since there are so few things on a typical computer that are plain character devices driving real hardware. A serial port would be about the only one; keyboards and mice (and serial ports :) are USB these days, or ADB on older powerbooks.

You don't have to restrict yourself to character devices driving real hardware. The same issues apply to USB and other buses.

Alan Stern

#559 lore raw
In reply to Matthew Garrett
Quoted 6 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quite apart from the sync() matter, _any_ synchronous call to a FUSE filesystem during STR will cause trouble. Even if the user task implementing the filesystem isn't frozen, when it tries to carry out some I/O to a suspended device it will either:

block until the system wakes up, or

cause the suspend to abort.

Neither outcome is desirable.

Alan Stern

#560 lore raw
Quoted 9 lines · Alan Stern
Quoted 6 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quoted 6 lines

Quite apart from the sync() matter, _any_ synchronous call to a FUSE filesystem during STR will cause trouble. Even if the user task implementing the filesystem isn't frozen, when it tries to carry out some I/O to a suspended device it will either:

block until the system wakes up, or

For the suspend to RAM case, that sounds absolutely fine.

Signature · 1 line
Matthew Garrett | [email protected]
#561 lore raw
Quoted 10 lines · Matthew Garrett
Quoted 9 lines · Alan Stern
Quoted 6 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quoted 8 lines
Quoted 6 lines

Quite apart from the sync() matter, _any_ synchronous call to a FUSE filesystem during STR will cause trouble. Even if the user task implementing the filesystem isn't frozen, when it tries to carry out some I/O to a suspended device it will either:

block until the system wakes up, or

For the suspend to RAM case, that sounds absolutely fine.

It's not so good when your suspend process has to wait for the call to complete!

Alan Stern

#562 lore raw
Quoted 7 lines · Alan Stern
Quoted 6 lines · Matthew Garrett
Quoted 5 lines · Alan Stern

Quite apart from the sync() matter, _any_ synchronous call to a FUSE filesystem during STR will cause trouble. Even if the user task implementing the filesystem isn't frozen, when it tries to carry out some I/O to a suspended device it will either:

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

block until the system wakes up, or

For the suspend to RAM case, that sounds absolutely fine.

It's not so good when your suspend process has to wait for the call to complete!

Why would it have to? Sorry, I suspect I'm missing something obvious here.

Signature · 1 line
Matthew Garrett | [email protected]
#475 lore raw
In reply to Rafael J. Wysocki

Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:

Quoted 21 lines · Rafael J. Wysocki
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Matthew Garrett
Quoted 6 lines

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

Greetings,
Rafael

Quoted 5 lines

---
From: Rafael J. Wysocki <[email protected]>

We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.

This seems fishy. Swsusp needs enough clean memory to make enough room for the image. If you sync before you freeze, the running tasks can redirty memory.
What makes you sure that you don't die as shrink_all_memory() writes out pages?

Regards
Oliver

#85 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines
Quoted 6 lines

Indeed. Actually, one could argue that it's impossible to solve the problem as long as we try to call out to userspace during suspend and need to wait until that's finished, like in the case of sys_sync() and fuse filesystems, and probably other cases. Maybe we should make *those* calls return a failure so that the suspend isn't transparent inside the kernel but is transparent to userspace.

Quoted 5 lines

Well, it generally needs more consideration. :-)

I think that we should introduce mechanisms that will allow us to notify all kernel subsystems, including FUSE and similar, that the system is going to enter a sleep state (one of those is the notifier chain introduced recently).

Ugh, please no.

Believe me, fuse is doing _nothing_ out of the ordinary, and should not need special treatment during suspend/resume. If suspend itself is doing something that triggers fuse activity, then that's a bug, such as the sync() thing that started this thread.

Quoted 4 lines

Then, they may react to such a notification by entering a "suspend" mode of operation in which they will return errors from some callbacks that otherwise should have succeeded etc. That depends on the subsystem in question.

Sounds horrible.

Why do we need to deal with subsystem interdependencies during suspend? Isn't it about saving device state to ram? That definitely _should not_ need to trigger anything that touches filesystems or other subsystems.

Miklos

#485 lore raw
In reply to Rafael J. Wysocki

Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

And a further question. The freezer is not atomic. What do you do if a task not yet frozen calls sys_sync(), but fuse is already frozen?

Regards
Oliver

#486 lore raw
Quoted 2 lines

And a further question. The freezer is not atomic. What do you do if a task not yet frozen calls sys_sync(), but fuse is already frozen?

What do you do if a task not yet frozen writes to a pipe, on the other end of which is a task already frozen?

It doesn't matter. The only thing that should matter during suspend (not hibernate) is saving the state of devices to ram, and putting the devices to sleep.

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.

Miklos

#530 lore raw
In reply to Rafael J. Wysocki

Hi!

Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

Greetings,
Rafael

Quoted 5 lines

---
From: Rafael J. Wysocki <[email protected]>

We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.

Actually... It is not _needed_ for suspend to disk, either. Snapshot is atomic, so it should be okay to suspend with filesystems dirty.

_But_, if anything goes wrong, we'd prefer to have at least filesystems synced. Battery running out during s2ram is not quite uncommon, so we perhaps should do sync somewhere there. (But we can do it before freezer just fine).
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#531 lore raw
In reply to Rafael J. Wysocki

Hi!

Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

Greetings,
Rafael

Quoted 5 lines

---
From: Rafael J. Wysocki <[email protected]>

We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.

Actually... It is not _needed_ for suspend to disk, either. Snapshot is atomic, so it should be okay to suspend with filesystems dirty.

_But_, if anything goes wrong, we'd prefer to have at least filesystems synced. Battery running out during s2ram is not quite uncommon, so we perhaps should do sync somewhere there. (But we can do it before freezer just fine).
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#487 lore raw
In reply to Miklos Szeredi

Am Dienstag, 3. Juli 2007 schrieb Miklos Szeredi:

Quoted 5 lines
Quoted 2 lines

And a further question. The freezer is not atomic. What do you do if a task not yet frozen calls sys_sync(), but fuse is already frozen?

What do you do if a task not yet frozen writes to a pipe, on the other end of which is a task already frozen?

The same as you do with a pipe when the reader is not ready.

Quoted 3 lines

It doesn't matter. The only thing that should matter during suspend (not hibernate) is saving the state of devices to ram, and putting the devices to sleep.

Well, but you did remove sys_sync() from the freezer, which is and must be called in the hibernate path.

Quoted 3 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Regards
Oliver

#563 lore raw
In reply to Matthew Garrett
Quoted 10 lines · Matthew Garrett
Quoted 9 lines · Alan Stern
Quoted 8 lines · Matthew Garrett
Quoted 6 lines · Alan Stern

Quite apart from the sync() matter, _any_ synchronous call to a FUSE filesystem during STR will cause trouble. Even if the user task implementing the filesystem isn't frozen, when it tries to carry out some I/O to a suspended device it will either:

block until the system wakes up, or

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

For the suspend to RAM case, that sounds absolutely fine.

It's not so good when your suspend process has to wait for the call to complete!

Why would it have to? Sorry, I suspect I'm missing something obvious here.

Well, the sys_sync() that caused your original problem did exactly that. It's the reason you get deadlocks, right?

I agree that in general the suspend process should not have to wait for a userspace callback to complete. Indeed, there's no particular reason that anything running during STR should have to wait for something in userspace to complete. Given that fact, I don't see anything wrong with freezing userspace when doing STR.

Alan Stern

#564 lore raw
Quoted 6 lines · Alan Stern
Quoted 4 lines · Matthew Garrett
Quoted 3 lines · Alan Stern
Quoted 1 line · Matthew Garrett

For the suspend to RAM case, that sounds absolutely fine.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

It's not so good when your suspend process has to wait for the call to complete!

Why would it have to? Sorry, I suspect I'm missing something obvious here.

Well, the sys_sync() that caused your original problem did exactly that. It's the reason you get deadlocks, right?

The sys_sync is unnecessary in the first case. There shouldn't be anything in the suspend path that's going to require userspace access to a device after that device has been suspended.

Quoted 5 lines

I agree that in general the suspend process should not have to wait for a userspace callback to complete. Indeed, there's no particular reason that anything running during STR should have to wait for something in userspace to complete. Given that fact, I don't see anything wrong with freezing userspace when doing STR.

There's nothing wrong with it as such, it's just that our implementation appears to suck in a myriad of small ways that keep cropping up and biting people. Even without the sys_sync(), freezing processes results in the suspend failing because syslog is stuck in D state and won't go into the refrigerator.

Signature · 1 line
Matthew Garrett | [email protected]
#488 lore raw
In reply to Oliver Neukum
Quoted 8 lines

Am Dienstag, 3. Juli 2007 schrieb Miklos Szeredi:

Quoted 5 lines
Quoted 2 lines

And a further question. The freezer is not atomic. What do you do if a task not yet frozen calls sys_sync(), but fuse is already frozen?

What do you do if a task not yet frozen writes to a pipe, on the other end of which is a task already frozen?

The same as you do with a pipe when the reader is not ready.

Yes. And if the fuse process is not ready, what will sys_sync() do?

(As a side note, sys_sync() actually does nothing in fuse, so these examples are slightly silly, but the concept applies to any filesystem operation).

Quoted 6 lines
Quoted 3 lines

It doesn't matter. The only thing that should matter during suspend (not hibernate) is saving the state of devices to ram, and putting the devices to sleep.

Well, but you did remove sys_sync() from the freezer, which is and must be called in the hibernate path.

Since I don't know why sync() needs to be called from hibernate, I can't argue about this. But for _suspend_ it definitely should not be needed.

Quoted 6 lines
Quoted 3 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Why exactly? That's like saying the pipe must be able to deal with writes until every task is frozen.

As I've said, fuse is just special kind of IPC. The task calling into fuse can assume nothing about when it's request will be served. Just like a task writing into a pipe can assume nothing about when that write will return.

Miklos

#565 lore raw
In reply to Matthew Garrett
Quoted 11 lines · Matthew Garrett
Quoted 5 lines

I agree that in general the suspend process should not have to wait for a userspace callback to complete. Indeed, there's no particular reason that anything running during STR should have to wait for something in userspace to complete. Given that fact, I don't see anything wrong with freezing userspace when doing STR.

There's nothing wrong with it as such, it's just that our implementation appears to suck in a myriad of small ways that keep cropping up and biting people. Even without the sys_sync(), freezing processes results in the suspend failing because syslog is stuck in D state and won't go into the refrigerator.

Okay, I can believe that. The proper response then is to fix the freezer, not eliminate it. Has the syslog problem been reported on linux-pm? I don't recall hearing of it before.

Alan Stern

#489 lore raw
In reply to Oliver Neukum
Quoted 2 lines · Oliver Neukum

Well, but you did remove sys_sync() from the freezer, which is and must be called in the hibernate path.

That's not really true. We _want_ to call sys_sync() in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.

Quoted 6 lines
Quoted 3 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?

I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.

Alan Stern

#490 lore raw
Quoted 15 lines
Quoted 2 lines

Well, but you did remove sys_sync() from the freezer, which is and must be called in the hibernate path.

That's not really true. We _want_ to call sys_sync() in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.

Quoted 6 lines
Quoted 3 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Quoted 7 lines

That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?

I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.

I strongly believe, that we don't want to deal with it. If we want to call sync(), do it while the system is fully operational. It's a best effort thing anyway, and you can loose data in other ways if resume fails.

Miklos

#491 lore raw
In reply to Alan Stern
Quoted 15 lines
Quoted 2 lines

Well, but you did remove sys_sync() from the freezer, which is and must be called in the hibernate path.

That's not really true. We _want_ to call sys_sync() in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.

Quoted 6 lines
Quoted 3 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Quoted 7 lines

That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?

I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.

I strongly believe, that we don't want to deal with it. If we want to call sync(), do it while the system is fully operational. It's a best effort thing anyway, and you can loose data in other ways if resume fails.

Miklos

#88 lore raw
In reply to Johannes Berg
Quoted 5 lines · Johannes Berg
Quoted 1 line

Runtime suspend isn't a problem. Only STR.

Ah but for all those character devices people were saying are the problem we haven't even solved runtime suspend as far as I can tell from the discussion.

The technique used by USB for runtime PM should work fine with other devices. They may not have implemented it yet, but I consider the matter more-or-less solved.

Quoted 8 lines
Quoted 1 line

As you can see, this is a very difficult problem to solve.

Indeed. Actually, one could argue that it's impossible to solve the problem as long as we try to call out to userspace during suspend and need to wait until that's finished, like in the case of sys_sync() and fuse filesystems, and probably other cases. Maybe we should make *those* calls return a failure so that the suspend isn't transparent inside the kernel but is transparent to userspace.

I disagree. The problem isn't the kernel calling userspace; it's userspace trying to do I/O at a time when everything is supposed to be quiescing. Detecting that and blocking it in drivers is hard and error-prone; preventing it by freezing userspace is easy and cheap.

The reasons why the PPC people dislike the whole idea aren't clear to me. If it were necessary to have some user task running in order to carry out the STR then their objection would make sense -- obviously that task couldn't do its job if it were frozen. But it isn't necessary, or at least it should not be.

Userspace will be effectively "frozen" while the system as a whole is suspended. So what's wrong with freezing it a little early? Despite Ben's comments, it seems to me that the freezer doesn't hide problems -- it prevents them.

Now people may claim that the freezer implementation itself is buggy. I wouldn't dispute it. But the bugs should be fixable; nobody has pointed out anything fundamentally wrong with the idea AFAICT.

Alan Stern

#89 lore raw
In reply to Johannes Berg
Quoted 5 lines · Johannes Berg
Quoted 1 line

Runtime suspend isn't a problem. Only STR.

Ah but for all those character devices people were saying are the problem we haven't even solved runtime suspend as far as I can tell from the discussion.

The technique used by USB for runtime PM should work fine with other devices. They may not have implemented it yet, but I consider the matter more-or-less solved.

Quoted 8 lines
Quoted 1 line

As you can see, this is a very difficult problem to solve.

Indeed. Actually, one could argue that it's impossible to solve the problem as long as we try to call out to userspace during suspend and need to wait until that's finished, like in the case of sys_sync() and fuse filesystems, and probably other cases. Maybe we should make *those* calls return a failure so that the suspend isn't transparent inside the kernel but is transparent to userspace.

I disagree. The problem isn't the kernel calling userspace; it's userspace trying to do I/O at a time when everything is supposed to be quiescing. Detecting that and blocking it in drivers is hard and error-prone; preventing it by freezing userspace is easy and cheap.

The reasons why the PPC people dislike the whole idea aren't clear to me. If it were necessary to have some user task running in order to carry out the STR then their objection would make sense -- obviously that task couldn't do its job if it were frozen. But it isn't necessary, or at least it should not be.

Userspace will be effectively "frozen" while the system as a whole is suspended. So what's wrong with freezing it a little early? Despite Ben's comments, it seems to me that the freezer doesn't hide problems -- it prevents them.

Now people may claim that the freezer implementation itself is buggy. I wouldn't dispute it. But the bugs should be fixable; nobody has pointed out anything fundamentally wrong with the idea AFAICT.

Alan Stern

#566 lore raw
In reply to Alan Stern
Quoted 10 lines · Alan Stern
Quoted 5 lines · Matthew Garrett

There's nothing wrong with it as such, it's just that our implementation appears to suck in a myriad of small ways that keep cropping up and biting people. Even without the sys_sync(), freezing processes results in the suspend failing because syslog is stuck in D state and won't go into the refrigerator.

Okay, I can believe that. The proper response then is to fix the freezer, not eliminate it. Has the syslog problem been reported on linux-pm? I don't recall hearing of it before.

See the start of this thread. It's just not clear what the freezer buys us - removing it gets rid of a load of subtle issues and complexity, and turns system suspend into something that looks more like runtime suspend (which might then encourage people to get runtime suspend right...)

Signature · 1 line
Matthew Garrett | [email protected]
#567 lore raw
In reply to Alan Stern
Quoted 10 lines · Alan Stern
Quoted 5 lines · Matthew Garrett

There's nothing wrong with it as such, it's just that our implementation appears to suck in a myriad of small ways that keep cropping up and biting people. Even without the sys_sync(), freezing processes results in the suspend failing because syslog is stuck in D state and won't go into the refrigerator.

Okay, I can believe that. The proper response then is to fix the freezer, not eliminate it. Has the syslog problem been reported on linux-pm? I don't recall hearing of it before.

See the start of this thread. It's just not clear what the freezer buys us - removing it gets rid of a load of subtle issues and complexity, and turns system suspend into something that looks more like runtime suspend (which might then encourage people to get runtime suspend right...)

Signature · 1 line
Matthew Garrett | [email protected]
#494 lore raw
In reply to Alan Stern

Am Dienstag, 3. Juli 2007 schrieben Sie:

Quoted 9 lines · Oliver Neukum
Quoted 3 lines

Well, but you did remove sys_sync() from the freezer, which is and must be called in the hibernate path.

That's not really true. We _want_ to call sys_sync() in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.

But the ability to launder pages is needed. During hibernation we need to shrink memory. I don't see how this would be fundamentally different from calling sync.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?

I don't and it might point to a fundamental problem.
But I cannot help but notice that syscalls may happen while the system is partially frozen. It must be dealt with.

Quoted 4 lines

I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.

Where exactly would that code notice the errors?

Regards
Oliver

#495 lore raw
In reply to Alan Stern

Am Dienstag, 3. Juli 2007 schrieben Sie:

Quoted 9 lines · Oliver Neukum
Quoted 3 lines

Well, but you did remove sys_sync() from the freezer, which is and must be called in the hibernate path.

That's not really true. We _want_ to call sys_sync() in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.

But the ability to launder pages is needed. During hibernation we need to shrink memory. I don't see how this would be fundamentally different from calling sync.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?

I don't and it might point to a fundamental problem.
But I cannot help but notice that syscalls may happen while the system is partially frozen. It must be dealt with.

Quoted 4 lines

I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.

Where exactly would that code notice the errors?

Regards
Oliver

#86 lore raw
In reply to Miklos Szeredi
Quoted 13 lines · Miklos Szeredi
Quoted 7 lines
Quoted 6 lines

Indeed. Actually, one could argue that it's impossible to solve the problem as long as we try to call out to userspace during suspend and need to wait until that's finished, like in the case of sys_sync() and fuse filesystems, and probably other cases. Maybe we should make *those* calls return a failure so that the suspend isn't transparent inside the kernel but is transparent to userspace.

Quoted 5 lines

Well, it generally needs more consideration. :-)

I think that we should introduce mechanisms that will allow us to notify all kernel subsystems, including FUSE and similar, that the system is going to enter a sleep state (one of those is the notifier chain introduced recently).

Quoted 6 lines

Ugh, please no.

Believe me, fuse is doing _nothing_ out of the ordinary, and should not need special treatment during suspend/resume. If suspend itself is doing something that triggers fuse activity, then that's a bug, such as the sync() thing that started this thread.

Apart from the sync, it shouldn't trigger any fs activity. Still, some other task running concurrently with the suspend code may do that and _if_ we are going to allow that to happen (and we do, if we remove the freezer from the suspend code path), we will have to take that into consideration.

Quoted 9 lines
Quoted 4 lines

Then, they may react to such a notification by entering a "suspend" mode of operation in which they will return errors from some callbacks that otherwise should have succeeded etc. That depends on the subsystem in question.

Sounds horrible.

Why do we need to deal with subsystem interdependencies during suspend? Isn't it about saving device state to ram?

No. In addition, the devices should be prevented from generating interrupts or initiating DMA transfers and put into low power states before we actually suspend the system (platform). This is a bit difficult to do while all user space is running.

Quoted 2 lines

That definitely _should not_ need to trigger anything that touches filesystems or other subsystems.

Right, but the subsystems may do something that affects devices.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#476 lore raw
In reply to Oliver Neukum
Quoted 25 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:

Quoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Matthew Garrett
Quoted 6 lines

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

Greetings,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

Quoted 8 lines
Quoted 2 lines

We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.

This seems fishy. Swsusp needs enough clean memory to make enough room for the image. If you sync before you freeze, the running tasks can redirty memory.
What makes you sure that you don't die as shrink_all_memory() writes out pages?

I don't think that would matter.

Still, I can remove the sync from the suspend code path only, leaving it in the hibernation code path. The patch will be bigger, but well.

Any objection to that?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#87 lore raw
In reply to Miklos Szeredi
Quoted 13 lines · Miklos Szeredi
Quoted 7 lines
Quoted 6 lines

Indeed. Actually, one could argue that it's impossible to solve the problem as long as we try to call out to userspace during suspend and need to wait until that's finished, like in the case of sys_sync() and fuse filesystems, and probably other cases. Maybe we should make *those* calls return a failure so that the suspend isn't transparent inside the kernel but is transparent to userspace.

Quoted 5 lines

Well, it generally needs more consideration. :-)

I think that we should introduce mechanisms that will allow us to notify all kernel subsystems, including FUSE and similar, that the system is going to enter a sleep state (one of those is the notifier chain introduced recently).

Quoted 6 lines

Ugh, please no.

Believe me, fuse is doing _nothing_ out of the ordinary, and should not need special treatment during suspend/resume. If suspend itself is doing something that triggers fuse activity, then that's a bug, such as the sync() thing that started this thread.

Apart from the sync, it shouldn't trigger any fs activity. Still, some other task running concurrently with the suspend code may do that and _if_ we are going to allow that to happen (and we do, if we remove the freezer from the suspend code path), we will have to take that into consideration.

Quoted 9 lines
Quoted 4 lines

Then, they may react to such a notification by entering a "suspend" mode of operation in which they will return errors from some callbacks that otherwise should have succeeded etc. That depends on the subsystem in question.

Sounds horrible.

Why do we need to deal with subsystem interdependencies during suspend? Isn't it about saving device state to ram?

No. In addition, the devices should be prevented from generating interrupts or initiating DMA transfers and put into low power states before we actually suspend the system (platform). This is a bit difficult to do while all user space is running.

Quoted 2 lines

That definitely _should not_ need to trigger anything that touches filesystems or other subsystems.

Right, but the subsystems may do something that affects devices.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#529 lore raw
In reply to Oliver Neukum
Quoted 10 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

And a further question. The freezer is not atomic. What do you do if a task not yet frozen calls sys_sync(), but fuse is already frozen?

Hmm, if the sync is interruptible (I'm not sure), the task should be frozen while waiting for it to complete.

Otherwise, the freezing of tasks will fail (no deadlock).

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#568 lore raw
In reply to Matthew Garrett
Quoted 5 lines · Matthew Garrett

See the start of this thread. It's just not clear what the freezer buys us - removing it gets rid of a load of subtle issues and complexity, and turns system suspend into something that looks more like runtime suspend (which might then encourage people to get runtime suspend right...)

No, no -- you have it exactly backwards. Removing the freezer turns STR into something _less_ like runtime suspend, because it adds the requirement that devices must not automatically be resumed when an I/O request arrives.

Alan Stern

#569 lore raw
In reply to Matthew Garrett
Quoted 5 lines · Matthew Garrett

See the start of this thread. It's just not clear what the freezer buys us - removing it gets rid of a load of subtle issues and complexity, and turns system suspend into something that looks more like runtime suspend (which might then encourage people to get runtime suspend right...)

No, no -- you have it exactly backwards. Removing the freezer turns STR into something _less_ like runtime suspend, because it adds the requirement that devices must not automatically be resumed when an I/O request arrives.

Alan Stern

#570 lore raw
Quoted 4 lines · Alan Stern

No, no -- you have it exactly backwards. Removing the freezer turns STR into something _less_ like runtime suspend, because it adds the requirement that devices must not automatically be resumed when an I/O request arrives.

But that's fine - "Are we undergoing a systemwide suspend" is an easy question to ask. Freezing processes instead means that most of those paths will never be tested.

Signature · 1 line
Matthew Garrett | [email protected]
#571 lore raw
In reply to Alan Stern
Quoted 4 lines · Alan Stern

No, no -- you have it exactly backwards. Removing the freezer turns STR into something _less_ like runtime suspend, because it adds the requirement that devices must not automatically be resumed when an I/O request arrives.

But that's fine - "Are we undergoing a systemwide suspend" is an easy question to ask. Freezing processes instead means that most of those paths will never be tested.

Signature · 1 line
Matthew Garrett | [email protected]
#492 lore raw
In reply to Miklos Szeredi
Quoted 15 lines · Miklos Szeredi
Quoted 15 lines
Quoted 2 lines

Well, but you did remove sys_sync() from the freezer, which is and must be called in the hibernate path.

That's not really true. We _want_ to call sys_sync() in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.

Quoted 6 lines
Quoted 3 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Quoted 7 lines
Quoted 7 lines

That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?

I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.

Er, do_sync() doesn't return a result.

Quoted 4 lines

I strongly believe, that we don't want to deal with it. If we want to call sync(), do it while the system is fully operational. It's a best effort thing anyway, and you can loose data in other ways if resume fails.

The requirement of syncing when the system (including the user space) is fully operational is FUSE-specific. Thus we'd rather like to sync FUSE filesystems before freezing the user space and freeze the other filesystems after freezing the user space.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#282 lore raw
In reply to Rafael J. Wysocki
Quoted 11 lines
Quoted 2 lines

- For STR, don't do the freezer thing.

In the long run, I agree.

Still, can you please read this post from Alan Stern:

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

? I don't think I'm able to repeat the arguments given in there in a convincing way.

That's the same crackpot I've been hearing for the past 3 years or so ...

Both Paulus and I think the freezer is just a way to try to put your head in the sand and ignore the problem. It causes as many problems as it solves on its own, and is just not a solution that will be of any use once you start implementing dynamic PM schemes etc...

In many cases, having proper support for "live" suspend of devices is just a matter of having a couple of helpers in whatever subsystem those drivers hookup with. In the case of network, for example, it's mostly trivial (stop the queue). For block, it's not terribly hard neither, though you want to have some orderign/atomicity between the blocking of the incoming request queue and the sending of things like spindown & flush commands to the disk. For old-style IDE, that was fairly easily solved by piping suspend/resume command down the request queue itself and have the queue block/unblbock itself after processing them. Some of that logic could maybe be moved to the block layer for all block drivers to benefit.

But yes, overall, there is work to do on drivers and I'm doing the ones I hit on the platforms I use. I don't think the freezer is any kind of remotely good solution, just a way to continue avoiding the problem.

Ben.

#283 lore raw
In reply to Rafael J. Wysocki
Quoted 11 lines
Quoted 2 lines

- For STR, don't do the freezer thing.

In the long run, I agree.

Still, can you please read this post from Alan Stern:

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

? I don't think I'm able to repeat the arguments given in there in a convincing way.

That's the same crackpot I've been hearing for the past 3 years or so ...

Both Paulus and I think the freezer is just a way to try to put your head in the sand and ignore the problem. It causes as many problems as it solves on its own, and is just not a solution that will be of any use once you start implementing dynamic PM schemes etc...

In many cases, having proper support for "live" suspend of devices is just a matter of having a couple of helpers in whatever subsystem those drivers hookup with. In the case of network, for example, it's mostly trivial (stop the queue). For block, it's not terribly hard neither, though you want to have some orderign/atomicity between the blocking of the incoming request queue and the sending of things like spindown & flush commands to the disk. For old-style IDE, that was fairly easily solved by piping suspend/resume command down the request queue itself and have the queue block/unblbock itself after processing them. Some of that logic could maybe be moved to the block layer for all block drivers to benefit.

But yes, overall, there is work to do on drivers and I'm doing the ones I hit on the platforms I use. I don't think the freezer is any kind of remotely good solution, just a way to continue avoiding the problem.

Ben.

#535 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 6 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

Or rather, move it to before freeze_processes() so that you get at least some level of sync'ing just in case you never wake up. Not perfect (things may still get dirty) but it will help the immediate issue.

Ben.

#572 lore raw
In reply to Matthew Garrett
Quoted 10 lines · Matthew Garrett
Quoted 4 lines · Alan Stern

No, no -- you have it exactly backwards. Removing the freezer turns STR into something _less_ like runtime suspend, because it adds the requirement that devices must not automatically be resumed when an I/O request arrives.

But that's fine - "Are we undergoing a systemwide suspend" is an easy question to ask. Freezing processes instead means that most of those paths will never be tested.

The question is easy to ask, but it's not so easy to figure out what you should do if the answer is Yes. Freezing processes instead means that those "untested" paths -- in many, many drivers -- won't have to exist at all.

Alan Stern

#573 lore raw
In reply to Matthew Garrett
Quoted 10 lines · Matthew Garrett
Quoted 4 lines · Alan Stern

No, no -- you have it exactly backwards. Removing the freezer turns STR into something _less_ like runtime suspend, because it adds the requirement that devices must not automatically be resumed when an I/O request arrives.

But that's fine - "Are we undergoing a systemwide suspend" is an easy question to ask. Freezing processes instead means that most of those paths will never be tested.

The question is easy to ask, but it's not so easy to figure out what you should do if the answer is Yes. Freezing processes instead means that those "untested" paths -- in many, many drivers -- won't have to exist at all.

Alan Stern

#536 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 6 lines · Matthew Garrett

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

Or rather, move it to before freeze_processes() so that you get at least some level of sync'ing just in case you never wake up. Not perfect (things may still get dirty) but it will help the immediate issue.

Ben.

#532 lore raw
In reply to Pavel Machek
Quoted 19 lines · Pavel Machek

Hi!

Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

Greetings,
Rafael

Quoted 5 lines

---
From: Rafael J. Wysocki <[email protected]>

We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.

Quoted 7 lines

Actually... It is not _needed_ for suspend to disk, either. Snapshot is atomic, so it should be okay to suspend with filesystems dirty.

_But_, if anything goes wrong, we'd prefer to have at least filesystems synced. Battery running out during s2ram is not quite uncommon, so we perhaps should do sync somewhere there. (But we can do it before freezer just fine).

OK

So, should I add the sync() to suspend_prepare(), before freeze_processes() (in analogy with hibernate())?

Greetings
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#574 lore raw
In reply to Alan Stern
Quoted 9 lines · Alan Stern
Quoted 3 lines · Matthew Garrett

But that's fine - "Are we undergoing a systemwide suspend" is an easy question to ask. Freezing processes instead means that most of those paths will never be tested.

The question is easy to ask, but it's not so easy to figure out what you should do if the answer is Yes. Freezing processes instead means that those "untested" paths -- in many, many drivers -- won't have to exist at all.

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

Signature · 1 line
Matthew Garrett | [email protected]
#496 lore raw
In reply to Oliver Neukum
Quoted 7 lines · Oliver Neukum
Quoted 2 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,

that's

Quoted 1 line

an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Pipe dream

Ben.

#493 lore raw
In reply to Miklos Szeredi
Quoted 15 lines · Miklos Szeredi
Quoted 15 lines
Quoted 2 lines

Well, but you did remove sys_sync() from the freezer, which is and must be called in the hibernate path.

That's not really true. We _want_ to call sys_sync() in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.

Quoted 6 lines
Quoted 3 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Quoted 7 lines
Quoted 7 lines

That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?

I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.

Er, do_sync() doesn't return a result.

Quoted 4 lines

I strongly believe, that we don't want to deal with it. If we want to call sync(), do it while the system is fully operational. It's a best effort thing anyway, and you can loose data in other ways if resume fails.

The requirement of syncing when the system (including the user space) is fully operational is FUSE-specific. Thus we'd rather like to sync FUSE filesystems before freezing the user space and freeze the other filesystems after freezing the user space.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#533 lore raw
In reply to Pavel Machek
Quoted 19 lines · Pavel Machek

Hi!

Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

Greetings,
Rafael

Quoted 5 lines

---
From: Rafael J. Wysocki <[email protected]>

We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.

Quoted 7 lines

Actually... It is not _needed_ for suspend to disk, either. Snapshot is atomic, so it should be okay to suspend with filesystems dirty.

_But_, if anything goes wrong, we'd prefer to have at least filesystems synced. Battery running out during s2ram is not quite uncommon, so we perhaps should do sync somewhere there. (But we can do it before freezer just fine).

OK

So, should I add the sync() to suspend_prepare(), before freeze_processes() (in analogy with hibernate())?

Greetings
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#284 lore raw
In reply to Benjamin Herrenschmidt
Quoted 32 lines · Benjamin Herrenschmidt
Quoted 11 lines
Quoted 2 lines

- For STR, don't do the freezer thing.

In the long run, I agree.

Still, can you please read this post from Alan Stern:

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

? I don't think I'm able to repeat the arguments given in there in a convincing way.

That's the same crackpot I've been hearing for the past 3 years or so ...

Both Paulus and I think the freezer is just a way to try to put your head in the sand and ignore the problem. It causes as many problems as it solves on its own, and is just not a solution that will be of any use once you start implementing dynamic PM schemes etc...

In many cases, having proper support for "live" suspend of devices is just a matter of having a couple of helpers in whatever subsystem those drivers hookup with. In the case of network, for example, it's mostly trivial (stop the queue). For block, it's not terribly hard neither, though you want to have some orderign/atomicity between the blocking of the incoming request queue and the sending of things like spindown & flush commands to the disk. For old-style IDE, that was fairly easily solved by piping suspend/resume command down the request queue itself and have the queue block/unblbock itself after processing them. Some of that logic could maybe be moved to the block layer for all block drivers to benefit.

Quoted 3 lines

But yes, overall, there is work to do on drivers and I'm doing the ones I hit on the platforms I use. I don't think the freezer is any kind of remotely good solution, just a way to continue avoiding the problem.

Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#575 lore raw
In reply to Matthew Garrett
Quoted 6 lines · Matthew Garrett
Quoted 5 lines · Alan Stern
Quoted 3 lines · Matthew Garrett

But that's fine - "Are we undergoing a systemwide suspend" is an easy question to ask. Freezing processes instead means that most of those paths will never be tested.

Quoted 7 lines
Quoted 4 lines

The question is easy to ask, but it's not so easy to figure out what you should do if the answer is Yes. Freezing processes instead means that those "untested" paths -- in many, many drivers -- won't have to exist at all.

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

Now, please tell me how many driver writers even thought that something might try to access their devices after .suspend() had been executed (or even whilie it was being executed)?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#323 lore raw
In reply to Benjamin Herrenschmidt
Quoted 32 lines · Benjamin Herrenschmidt
Quoted 11 lines
Quoted 2 lines

- For STR, don't do the freezer thing.

In the long run, I agree.

Still, can you please read this post from Alan Stern:

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

? I don't think I'm able to repeat the arguments given in there in a convincing way.

That's the same crackpot I've been hearing for the past 3 years or so ...

Both Paulus and I think the freezer is just a way to try to put your head in the sand and ignore the problem. It causes as many problems as it solves on its own, and is just not a solution that will be of any use once you start implementing dynamic PM schemes etc...

In many cases, having proper support for "live" suspend of devices is just a matter of having a couple of helpers in whatever subsystem those drivers hookup with. In the case of network, for example, it's mostly trivial (stop the queue). For block, it's not terribly hard neither, though you want to have some orderign/atomicity between the blocking of the incoming request queue and the sending of things like spindown & flush commands to the disk. For old-style IDE, that was fairly easily solved by piping suspend/resume command down the request queue itself and have the queue block/unblbock itself after processing them. Some of that logic could maybe be moved to the block layer for all block drivers to benefit.

Quoted 3 lines

But yes, overall, there is work to do on drivers and I'm doing the ones I hit on the platforms I use. I don't think the freezer is any kind of remotely good solution, just a way to continue avoiding the problem.

Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#477 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines

I don't think that would matter.

Still, I can remove the sync from the suspend code path only, leaving it in the hibernation code path. The patch will be bigger, but well.

Any objection to that?

Makes sense to sync before suspend tho, to limit the amount of dirty non-written pages in case things go wrong.

Ben.

#285 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki

Still, do you really think that we're ready to drop it _right_ _now_ (I'm
referring to suspend only) and if so than on what basis (except that you
don't like it, which falls short of being a techical argument)?

Works fine for me without it ;-)

Ben.

#478 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines

I don't think that would matter.

Still, I can remove the sync from the suspend code path only, leaving it in the hibernation code path. The patch will be bigger, but well.

Any objection to that?

Makes sense to sync before suspend tho, to limit the amount of dirty non-written pages in case things go wrong.

Ben.

#576 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 2 lines · Matthew Garrett

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

Now, please tell me how many driver writers even thought that something might try to access their devices after .suspend() had been executed (or even whilie it was being executed)?

Every single driver that fails under those conditions is already broken, and has been forever. It's likely that they're broken under run-time suspend, too.

Signature · 1 line
Matthew Garrett | [email protected]
#577 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 2 lines · Matthew Garrett

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

Now, please tell me how many driver writers even thought that something might try to access their devices after .suspend() had been executed (or even whilie it was being executed)?

Every single driver that fails under those conditions is already broken, and has been forever. It's likely that they're broken under run-time suspend, too.

Signature · 1 line
Matthew Garrett | [email protected]
#641 lore raw
In reply to Matthew Garrett
Quoted 6 lines · Matthew Garrett
Quoted 5 lines · Alan Stern
Quoted 3 lines · Matthew Garrett

But that's fine - "Are we undergoing a systemwide suspend" is an easy question to ask. Freezing processes instead means that most of those paths will never be tested.

Quoted 7 lines
Quoted 4 lines

The question is easy to ask, but it's not so easy to figure out what you should do if the answer is Yes. Freezing processes instead means that those "untested" paths -- in many, many drivers -- won't have to exist at all.

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

Now, please tell me how many driver writers even thought that something might try to access their devices after .suspend() had been executed (or even whilie it was being executed)?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#286 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki

Still, do you really think that we're ready to drop it _right_ _now_ (I'm
referring to suspend only) and if so than on what basis (except that you
don't like it, which falls short of being a techical argument)?

Works fine for me without it ;-)

Ben.

#578 lore raw
In reply to Matthew Garrett

Am Dienstag, 3. Juli 2007 schrieb Matthew Garrett:

Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Matthew Garrett
Quoted 2 lines

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

Quoted 7 lines
Quoted 3 lines

Now, please tell me how many driver writers even thought that something might try to access their devices after .suspend() had been executed (or even whilie it was being executed)?

Every single driver that fails under those conditions is already broken, and has been forever. It's likely that they're broken under run-time suspend, too.

There _is_ no runtime syspend in working condition. The interface to do that has been scheduled for removal.

Oliver

#579 lore raw
In reply to Matthew Garrett

Am Dienstag, 3. Juli 2007 schrieb Matthew Garrett:

Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Matthew Garrett
Quoted 2 lines

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

Quoted 7 lines
Quoted 3 lines

Now, please tell me how many driver writers even thought that something might try to access their devices after .suspend() had been executed (or even whilie it was being executed)?

Every single driver that fails under those conditions is already broken, and has been forever. It's likely that they're broken under run-time suspend, too.

There _is_ no runtime syspend in working condition. The interface to do that has been scheduled for removal.

Oliver

#497 lore raw
In reply to Benjamin Herrenschmidt

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 10 lines · Oliver Neukum
Quoted 7 lines
Quoted 2 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated.  If it is,

that's

Quoted 1 line

an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Pipe dream

Then tell me how you want to avoid that condition.

Oliver

#498 lore raw
In reply to Benjamin Herrenschmidt

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 10 lines · Oliver Neukum
Quoted 7 lines
Quoted 2 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated.  If it is,

that's

Quoted 1 line

an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Pipe dream

Then tell me how you want to avoid that condition.

Oliver

#499 lore raw
Quoted 5 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 4 lines · Oliver Neukum
Quoted 3 lines
Quoted 2 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,

that's

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Pipe dream

Then tell me how you want to avoid that condition.

Don't freeze :-)

Ben.

#500 lore raw
In reply to Oliver Neukum
Quoted 5 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 4 lines · Oliver Neukum
Quoted 3 lines
Quoted 2 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,

that's

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Pipe dream

Then tell me how you want to avoid that condition.

Don't freeze :-)

Ben.

#501 lore raw

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 8 lines · Oliver Neukum
Quoted 7 lines

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 6 lines · Oliver Neukum
Quoted 5 lines
Quoted 2 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,

that's

Quoted 1 line

an indication about something wrong in the suspend procedure.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Pipe dream

Then tell me how you want to avoid that condition.

Don't freeze :-)

Then you will have to deal with all syscalls unfrozen tasks can make.

Regards
Oliver

#502 lore raw
In reply to Benjamin Herrenschmidt

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 8 lines · Oliver Neukum
Quoted 7 lines

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 6 lines · Oliver Neukum
Quoted 5 lines
Quoted 2 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,

that's

Quoted 1 line

an indication about something wrong in the suspend procedure.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Pipe dream

Then tell me how you want to avoid that condition.

Don't freeze :-)

Then you will have to deal with all syscalls unfrozen tasks can make.

Regards
Oliver

#642 lore raw
In reply to Matthew Garrett
Quoted 6 lines · Matthew Garrett
Quoted 5 lines · Alan Stern
Quoted 3 lines · Matthew Garrett

But that's fine - "Are we undergoing a systemwide suspend" is an easy question to ask. Freezing processes instead means that most of those paths will never be tested.

Quoted 7 lines
Quoted 4 lines

The question is easy to ask, but it's not so easy to figure out what you should do if the answer is Yes. Freezing processes instead means that those "untested" paths -- in many, many drivers -- won't have to exist at all.

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

You persist in evading my point. I'm not worried about applications; I'm worried about drivers.

Let me put it explicitly: You're writing a driver. You're working on the read, write, or probe method. You add code to check if a system sleep is underway. Suppose the answer is Yes -- what does your driver do next?

Make your answer as detailed as you reasonably can. And be careful to arrange things so that an ongoing I/O operation doesn't get messed up when your suspend method is called.

Alan Stern

#643 lore raw
In reply to Matthew Garrett
Quoted 6 lines · Matthew Garrett
Quoted 5 lines · Alan Stern
Quoted 3 lines · Matthew Garrett

But that's fine - "Are we undergoing a systemwide suspend" is an easy question to ask. Freezing processes instead means that most of those paths will never be tested.

Quoted 7 lines
Quoted 4 lines

The question is easy to ask, but it's not so easy to figure out what you should do if the answer is Yes. Freezing processes instead means that those "untested" paths -- in many, many drivers -- won't have to exist at all.

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

You persist in evading my point. I'm not worried about applications; I'm worried about drivers.

Let me put it explicitly: You're writing a driver. You're working on the read, write, or probe method. You add code to check if a system sleep is underway. Suppose the answer is Yes -- what does your driver do next?

Make your answer as detailed as you reasonably can. And be careful to arrange things so that an ongoing I/O operation doesn't get messed up when your suspend method is called.

Alan Stern

#479 lore raw
In reply to Benjamin Herrenschmidt
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 7 lines

I don't think that would matter.

Still, I can remove the sync from the suspend code path only, leaving it in the hibernation code path. The patch will be bigger, but well.

Any objection to that?

Makes sense to sync before suspend tho, to limit the amount of dirty non-written pages in case things go wrong.

OK, below is the updated patch.

Greetings,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

The syncing of filesystems from within the freezer in not needed for suspend to RAM and leads to problems with FUSE. Change freeze_processes() so that it doesn't execute sys_sync() and introduce the "syncing" version of it to be called from the hibernation code paths.

---
 include/linux/freezer.h |   14 ++++++++++++--
 kernel/power/disk.c     |    2 +-
 kernel/power/main.c     |    6 ++++++
 kernel/power/process.c  |    8 +++++---
 kernel/power/user.c     |    2 +-
 5 files changed, 25 insertions(+), 7 deletions(-)
include/linux/freezer.h +12 -2
Index: linux-2.6.22-rc7/include/linux/freezer.h
===================================================================
@@ -62,7 +62,7 @@ static inline int thaw_process(struct ta
 }
 
 extern void refrigerator(void);
-extern int freeze_processes(void);
+extern int __freeze_processes(int sync_filesystems);
 extern void thaw_processes(void);
 
 static inline int try_to_freeze(void)
@@ -134,7 +134,7 @@ static inline void clear_freeze_flag(str
 static inline int thaw_process(struct task_struct *p) { return 1; }
 
 static inline void refrigerator(void) {}
-static inline int freeze_processes(void) { BUG(); return 0; }
+static inline int __freeze_processes(int s) { BUG(); return 0; }
 static inline void thaw_processes(void) {}
 
 static inline int try_to_freeze(void) { return 0; }
@@ -145,4 +145,14 @@ static inline int freezer_should_skip(st
 static inline void set_freezable(void) {}
 #endif
 
+static inline int freeze_processes(void)
+{
+	return __freeze_processes(0);
+}
+
+static inline int freeze_processes_with_sync(void)
+{
+	return __freeze_processes(1);
+}
+
 #endif	/* FREEZER_H_INCLUDED */
kernel/power/disk.c +1 -1
Index: linux-2.6.22-rc7/kernel/power/disk.c
===================================================================
@@ -281,7 +281,7 @@ static int prepare_processes(void)
 	int error = 0;
 
 	pm_prepare_console();
-	if (freeze_processes()) {
+	if (freeze_processes_with_sync()) {
 		error = -EBUSY;
 		unprepare_processes();
 	}
kernel/power/main.c +6 -0
Index: linux-2.6.22-rc7/kernel/power/main.c
===================================================================
@@ -20,6 +20,7 @@
 #include <linux/resume-trace.h>
 #include <linux/freezer.h>
 #include <linux/vmstat.h>
+#include <linux/syscalls.h>
 
 #include "power.h"
 
@@ -231,6 +232,11 @@ static int enter_state(suspend_state_t s
 
 	if (!valid_state(state))
 		return -ENODEV;
+
+	printk("Syncing filesystems ... ");
+	sys_sync();
+	printk("done.\n");
+
 	if (!mutex_trylock(&pm_mutex))
 		return -EBUSY;
 
kernel/power/process.c +5 -3
Index: linux-2.6.22-rc7/kernel/power/process.c
===================================================================
@@ -179,9 +179,9 @@ static int try_to_freeze_tasks(int freez
 }
 
 /**
- *	freeze_processes - tell processes to enter the refrigerator
+ *	__freeze_processes - tell processes to enter the refrigerator
  */
-int freeze_processes(void)
+int __freeze_processes(int sync_filesystems)
 {
 	int error;
 
@@ -190,7 +190,9 @@ int freeze_processes(void)
 	if (error)
 		return error;
 
-	sys_sync();
+	if (sync_filesystems)
+		sys_sync();
+
 	error = try_to_freeze_tasks(FREEZER_KERNEL_THREADS);
 	if (error)
 		return error;
kernel/power/user.c +1 -1
Index: linux-2.6.22-rc7/kernel/power/user.c
===================================================================
@@ -153,7 +153,7 @@ static int snapshot_ioctl(struct inode *
 		mutex_lock(&pm_mutex);
 		error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
 		if (!error) {
-			error = freeze_processes();
+			error = freeze_processes_with_sync();
 			if (error)
 				thaw_processes();
 		}
#480 lore raw
In reply to Benjamin Herrenschmidt
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 7 lines

I don't think that would matter.

Still, I can remove the sync from the suspend code path only, leaving it in the hibernation code path. The patch will be bigger, but well.

Any objection to that?

Makes sense to sync before suspend tho, to limit the amount of dirty non-written pages in case things go wrong.

OK, below is the updated patch.

Greetings,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

The syncing of filesystems from within the freezer in not needed for suspend to RAM and leads to problems with FUSE. Change freeze_processes() so that it doesn't execute sys_sync() and introduce the "syncing" version of it to be called from the hibernation code paths.

---
 include/linux/freezer.h |   14 ++++++++++++--
 kernel/power/disk.c     |    2 +-
 kernel/power/main.c     |    6 ++++++
 kernel/power/process.c  |    8 +++++---
 kernel/power/user.c     |    2 +-
 5 files changed, 25 insertions(+), 7 deletions(-)
include/linux/freezer.h +12 -2
Index: linux-2.6.22-rc7/include/linux/freezer.h
===================================================================
@@ -62,7 +62,7 @@ static inline int thaw_process(struct ta
 }
 
 extern void refrigerator(void);
-extern int freeze_processes(void);
+extern int __freeze_processes(int sync_filesystems);
 extern void thaw_processes(void);
 
 static inline int try_to_freeze(void)
@@ -134,7 +134,7 @@ static inline void clear_freeze_flag(str
 static inline int thaw_process(struct task_struct *p) { return 1; }
 
 static inline void refrigerator(void) {}
-static inline int freeze_processes(void) { BUG(); return 0; }
+static inline int __freeze_processes(int s) { BUG(); return 0; }
 static inline void thaw_processes(void) {}
 
 static inline int try_to_freeze(void) { return 0; }
@@ -145,4 +145,14 @@ static inline int freezer_should_skip(st
 static inline void set_freezable(void) {}
 #endif
 
+static inline int freeze_processes(void)
+{
+	return __freeze_processes(0);
+}
+
+static inline int freeze_processes_with_sync(void)
+{
+	return __freeze_processes(1);
+}
+
 #endif	/* FREEZER_H_INCLUDED */
kernel/power/disk.c +1 -1
Index: linux-2.6.22-rc7/kernel/power/disk.c
===================================================================
@@ -281,7 +281,7 @@ static int prepare_processes(void)
 	int error = 0;
 
 	pm_prepare_console();
-	if (freeze_processes()) {
+	if (freeze_processes_with_sync()) {
 		error = -EBUSY;
 		unprepare_processes();
 	}
kernel/power/main.c +6 -0
Index: linux-2.6.22-rc7/kernel/power/main.c
===================================================================
@@ -20,6 +20,7 @@
 #include <linux/resume-trace.h>
 #include <linux/freezer.h>
 #include <linux/vmstat.h>
+#include <linux/syscalls.h>
 
 #include "power.h"
 
@@ -231,6 +232,11 @@ static int enter_state(suspend_state_t s
 
 	if (!valid_state(state))
 		return -ENODEV;
+
+	printk("Syncing filesystems ... ");
+	sys_sync();
+	printk("done.\n");
+
 	if (!mutex_trylock(&pm_mutex))
 		return -EBUSY;
 
kernel/power/process.c +5 -3
Index: linux-2.6.22-rc7/kernel/power/process.c
===================================================================
@@ -179,9 +179,9 @@ static int try_to_freeze_tasks(int freez
 }
 
 /**
- *	freeze_processes - tell processes to enter the refrigerator
+ *	__freeze_processes - tell processes to enter the refrigerator
  */
-int freeze_processes(void)
+int __freeze_processes(int sync_filesystems)
 {
 	int error;
 
@@ -190,7 +190,9 @@ int freeze_processes(void)
 	if (error)
 		return error;
 
-	sys_sync();
+	if (sync_filesystems)
+		sys_sync();
+
 	error = try_to_freeze_tasks(FREEZER_KERNEL_THREADS);
 	if (error)
 		return error;
kernel/power/user.c +1 -1
Index: linux-2.6.22-rc7/kernel/power/user.c
===================================================================
@@ -153,7 +153,7 @@ static int snapshot_ioctl(struct inode *
 		mutex_lock(&pm_mutex);
 		error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
 		if (!error) {
-			error = freeze_processes();
+			error = freeze_processes_with_sync();
 			if (error)
 				thaw_processes();
 		}
#287 lore raw
In reply to Benjamin Herrenschmidt
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 6 lines · Rafael J. Wysocki

Still, do you really think that we're ready to drop it _right_ _now_ (I'm
referring to suspend only) and if so than on what basis (except that you
don't like it, which falls short of being a techical argument)?

Works fine for me without it ;-)

Yeah, that makes sense. ;-)

Still, someone needs to take care of bug reports from unlucky people and I wouldn't like to increase the number of these by doing such a high-level change without any preparations ...

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#580 lore raw
In reply to Matthew Garrett
Quoted 5 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Matthew Garrett

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

Quoted 7 lines
Quoted 3 lines

Now, please tell me how many driver writers even thought that something might try to access their devices after .suspend() had been executed (or even whilie it was being executed)?

Every single driver that fails under those conditions is already broken, and has been forever. It's likely that they're broken under run-time suspend, too.

Well, I won't argue with that, but do you actually know how many drivers are broken this way?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#644 lore raw
In reply to Alan Stern
Quoted 11 lines · Alan Stern
Quoted 2 lines · Matthew Garrett

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

You persist in evading my point. I'm not worried about applications; I'm worried about drivers.

Let me put it explicitly: You're writing a driver. You're working on the read, write, or probe method. You add code to check if a system sleep is underway. Suppose the answer is Yes -- what does your driver do next?

Leave the process blocked and defer any i/o until after resume. Why does it need to be any more complicated than that?

Signature · 1 line
Matthew Garrett | [email protected]
#645 lore raw
In reply to Alan Stern
Quoted 11 lines · Alan Stern
Quoted 2 lines · Matthew Garrett

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

You persist in evading my point. I'm not worried about applications; I'm worried about drivers.

Let me put it explicitly: You're writing a driver. You're working on the read, write, or probe method. You add code to check if a system sleep is underway. Suppose the answer is Yes -- what does your driver do next?

Leave the process blocked and defer any i/o until after resume. Why does it need to be any more complicated than that?

Signature · 1 line
Matthew Garrett | [email protected]
#288 lore raw
In reply to Benjamin Herrenschmidt
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 6 lines · Rafael J. Wysocki

Still, do you really think that we're ready to drop it _right_ _now_ (I'm
referring to suspend only) and if so than on what basis (except that you
don't like it, which falls short of being a techical argument)?

Works fine for me without it ;-)

Yeah, that makes sense. ;-)

Still, someone needs to take care of bug reports from unlucky people and I wouldn't like to increase the number of these by doing such a high-level change without any preparations ...

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#581 lore raw
In reply to Matthew Garrett
Quoted 5 lines · Matthew Garrett
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Matthew Garrett

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

Quoted 7 lines
Quoted 3 lines

Now, please tell me how many driver writers even thought that something might try to access their devices after .suspend() had been executed (or even whilie it was being executed)?

Every single driver that fails under those conditions is already broken, and has been forever. It's likely that they're broken under run-time suspend, too.

Well, I won't argue with that, but do you actually know how many drivers are broken this way?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#503 lore raw
In reply to Oliver Neukum
Quoted 12 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 11 lines · Oliver Neukum
Quoted 10 lines

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 9 lines · Oliver Neukum
Quoted 7 lines
Quoted 2 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,

that's

Quoted 1 line

an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Pipe dream

Then tell me how you want to avoid that condition.

Don't freeze :-)

Then you will have to deal with all syscalls unfrozen tasks can make.

Yup, and the majority of them is totally harmless. Looks like people around here have a problem with the idea of writing robust drivers ...

Ben.

#504 lore raw
In reply to Oliver Neukum
Quoted 12 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 11 lines · Oliver Neukum
Quoted 10 lines

Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 9 lines · Oliver Neukum
Quoted 7 lines
Quoted 2 lines

I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,

that's

Quoted 1 line

an indication about something wrong in the suspend procedure.

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Pipe dream

Then tell me how you want to avoid that condition.

Don't freeze :-)

Then you will have to deal with all syscalls unfrozen tasks can make.

Yup, and the majority of them is totally harmless. Looks like people around here have a problem with the idea of writing robust drivers ...

Ben.

#46 lore raw
In reply to Oliver Neukum
Quoted 1 line · Oliver Neukum

USB devices certainly have suspend methods.

Indeed, and the USB framework has code to know when the host controller is suspended and avoid trying to send out urbs in that case. Or at least it did last time I looked at it in any detail; it's been "just working" - including suspending and resuming, without the freezer - for quite a while now.

Paul.

#47 lore raw
In reply to Oliver Neukum
Quoted 1 line · Oliver Neukum

USB devices certainly have suspend methods.

Indeed, and the USB framework has code to know when the host controller is suspended and avoid trying to send out urbs in that case. Or at least it did last time I looked at it in any detail; it's been "just working" - including suspending and resuming, without the freezer - for quite a while now.

Paul.

#31 lore raw
In reply to Oliver Neukum
Quoted 1 line · Oliver Neukum

That's why we have the problem of freezing the kernel threads or not.

That problem is a symptom of the deeper conceptual problem, as is the problem with FUSE.

Quoted 1 line

You want to have all that pain for fuse?

I'd certainly rather get the drivers right, and maybe have an occasional deadlock if I miss something, than have a GUARANTEED deadlock every time I suspend with a FUSE filesystem mounted (which is pretty much every time, since I use encfs regularly).

Paul.

#32 lore raw
In reply to Oliver Neukum
Quoted 1 line · Oliver Neukum

That's why we have the problem of freezing the kernel threads or not.

That problem is a symptom of the deeper conceptual problem, as is the problem with FUSE.

Quoted 1 line

You want to have all that pain for fuse?

I'd certainly rather get the drivers right, and maybe have an occasional deadlock if I miss something, than have a GUARANTEED deadlock every time I suspend with a FUSE filesystem mounted (which is pretty much every time, since I use encfs regularly).

Paul.

#289 lore raw
In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki

Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?

The basis is that it (the freezer) causes more deadlocks and other problems than it avoids, so it's a net win to remove it.

Paul.

#582 lore raw
In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki

Now, please tell me how many driver writers even thought that something might try to access their devices after .suspend() had been executed (or even whilie it was being executed)?

Well, I believe that the USB framework copes with this, except possibly for some corner cases like the example that Alan Stern posted. The fact that powerbooks suspend and resume without the freezer implies that the IDE framework, the console code and the framebuffer code cope correctly (though possibly not all chipset drivers).

So I think that a lot of the frameworks already get it right. Of course the quality of the low-level chipset drivers has always been pretty variable. :)

Paul.

#249 lore raw
In reply to Alan Stern
Quoted 7 lines · Alan Stern

USB already implements runtime PM. If a device is suspended at runtime and a task tries to access it, the device is automatically resumed. No problem there.

The problem comes when the system is doing a STR. Right now the code doesn't keep track of the difference between a runtime suspend and a system suspend -- once the device is suspended, it's suspended, period.

Whether or not to resume a suspended device when an I/O request comes in is a policy decision, and there could be cases where the user wants I/O requests to be blocked, or to fail, or to be dropped while the device is suspended, even for runtime power management. For example, a sound card could be suspended due to a low-battery condition, and in that case you would want the driver to just drop any data that userspace tries to write to the soundcard.

Quoted 3 lines

Yes, the code could be changed to keep track of the reason for a device suspend. But that just raises the old problem of what to do when there's an I/O request for a suspended device during STR.

Is this actually a real problem? I would think the policy would be "block" for block devices (pun not intended :), "drop" for network devices, etc.

Quoted 6 lines

Consider a particularly troublesome case: During STR, a non-frozen task writes to /sys/bus/BBB/drivers/DDD/bind. The sysfs core grabs the device semaphore and calls the driver's probe routine. If the driver isn't PM-aware it simply tries to initialize the device and fails because the device is already suspended. That's no good; it isn't transparent.

How did the device get suspended if it didn't have a driver? If it did have a driver, why didn't the bind attempt fail?

Quoted 10 lines

So assume the driver is PM-aware. It tries to resume the device, which fails because STR is underway. Now what can it do? There's only one
possibility: It must block until the resume call can succeed. But when is that?

It has to be before the PM core tries to resume the device, because the core will try to acquire the device semaphore and will block waiting for the probe call to complete. But it has to be after the PM core resumes the device's parent, because obviously the device can't resume until its parent is awake.

Suppose the device-model core code simply blocked all bind and unbind requests while suspend is under way, until resume is finished. Wouldn't that solve the problem?

Paul.

#67 lore raw
In reply to Alan Stern
Quoted 7 lines · Alan Stern
Quoted 3 lines

Most drivers suspended their hardware in the second call. If they are in the middle of a conversation with their device that *has* to be completed, they can do that by polling.

Ugh. That will cause problems when you try to integrate runtime suspend. In fact this whole approach is unsuitable for runtime PM and it obscures the similarities between runtime PM and STR.

Yes there are similarities, but it would be a big mistake to say that a requirement for STR is that all drivers do runtime PM.

If a driver does runtime PM, that's great, and it is useful for implementing STR. However, there are a class of devices for which runtime PM is not possible or not useful, but which can suspend/resume just fine as part of suspending/resuming the complete system, and for which all that is needed is some small amount of simple hardware poking just before the system as a whole is put into suspend. For those a late-suspend call with interrupts off is the simplest and best way to go.

Think of a serial port on a motherboard for instance, where the only power control is the overall power control for the system. All that is needed is to poll for the transmitter being empty (with timeout, of course) in the late-suspend call (and possibly also turn off output drivers, perhaps), and to reinitialize some registers in an early-resume call.

The main attraction of the late-suspend call is that it really does, reliably, guarantee that the driver's I/O request methods won't get called between the late-suspend call and the early-resume call.

Paul.

#90 lore raw
In reply to Alan Stern
Quoted 4 lines · Alan Stern

I disagree. The problem isn't the kernel calling userspace; it's userspace trying to do I/O at a time when everything is supposed to be quiescing. Detecting that and blocking it in drivers is hard and error-prone; preventing it by freezing userspace is easy and cheap.

And unreliable, and prone to deadlocks, and invasive - requiring changes to kernel threads that have nothing to do with drivers or suspend/resume.

Quoted 2 lines

The reasons why the PPC people dislike the whole idea aren't clear to me.

Our experience is that it isn't necessary. It's extra code that in practice causes deadlocks and added maintenance burden for no discernable benefit.

Quoted 4 lines

If it were necessary to have some user task running in order to carry out the STR then their objection would make sense -- obviously that task couldn't do its job if it were frozen. But it isn't necessary, or at least it should not be.

The freezer doesn't achieve its stated goal of preventing drivers from getting I/O requests after suspend, since kernel threads can (and do) initiate I/O. So then we say that some kernel threads need to be frozen and others don't, but making that decision is difficult and error-prone.

Besides, any kernel thread that does I/O is potentially doing that in order to complete some other I/O request. So we want to freeze it in order to prevent new I/O requests from being initiated, but we don't want to freeze it so that existing I/O requests can be completed. Thus we have a fundamental conflict in the notion of the freezer.

In fact I believe that making a distinction between user and kernel threads is wrong and likely to lead to problems, since userspace can be involved in doing I/O (e.g. FUSE or the user-space driver framework). So the argument of the previous paragraph also applies to some userspace processes.

Quoted 4 lines

Userspace will be effectively "frozen" while the system as a whole is suspended. So what's wrong with freezing it a little early? Despite Ben's comments, it seems to me that the freezer doesn't hide problems -- it prevents them.

No, it appears to prevent them, but doesn't in fact.

I remain convinced that the right approach is to fix the drivers to do one of two things; either do something in the suspend call to block further requests to the device, or use a late-suspend call to put their device into a low-power state. Of course, correctly-written frameworks can do a lot to help the chipset drivers here.

Quoted 3 lines

Now people may claim that the freezer implementation itself is buggy. I wouldn't dispute it. But the bugs should be fixable; nobody has pointed out anything fundamentally wrong with the idea AFAICT.

The fundamental problem is the kernel threads and user processes that we need running to complete existing I/O requests, but which may initiate new I/O requests in doing so.

The right way to solve the problem is to do the request blocking in the drivers.

Paul.

#68 lore raw
In reply to Alan Stern
Quoted 7 lines · Alan Stern
Quoted 3 lines

Most drivers suspended their hardware in the second call. If they are in the middle of a conversation with their device that *has* to be completed, they can do that by polling.

Ugh. That will cause problems when you try to integrate runtime suspend. In fact this whole approach is unsuitable for runtime PM and it obscures the similarities between runtime PM and STR.

Yes there are similarities, but it would be a big mistake to say that a requirement for STR is that all drivers do runtime PM.

If a driver does runtime PM, that's great, and it is useful for implementing STR. However, there are a class of devices for which runtime PM is not possible or not useful, but which can suspend/resume just fine as part of suspending/resuming the complete system, and for which all that is needed is some small amount of simple hardware poking just before the system as a whole is put into suspend. For those a late-suspend call with interrupts off is the simplest and best way to go.

Think of a serial port on a motherboard for instance, where the only power control is the overall power control for the system. All that is needed is to poll for the transmitter being empty (with timeout, of course) in the late-suspend call (and possibly also turn off output drivers, perhaps), and to reinitialize some registers in an early-resume call.

The main attraction of the late-suspend call is that it really does, reliably, guarantee that the driver's I/O request methods won't get called between the late-suspend call and the early-resume call.

Paul.

#583 lore raw
In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki

Now, please tell me how many driver writers even thought that something might try to access their devices after .suspend() had been executed (or even whilie it was being executed)?

Well, I believe that the USB framework copes with this, except possibly for some corner cases like the example that Alan Stern posted. The fact that powerbooks suspend and resume without the freezer implies that the IDE framework, the console code and the framebuffer code cope correctly (though possibly not all chipset drivers).

So I think that a lot of the frameworks already get it right. Of course the quality of the low-level chipset drivers has always been pretty variable. :)

Paul.

#290 lore raw
In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki

Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?

The basis is that it (the freezer) causes more deadlocks and other problems than it avoids, so it's a net win to remove it.

Paul.

#250 lore raw
In reply to Alan Stern
Quoted 7 lines · Alan Stern

USB already implements runtime PM. If a device is suspended at runtime and a task tries to access it, the device is automatically resumed. No problem there.

The problem comes when the system is doing a STR. Right now the code doesn't keep track of the difference between a runtime suspend and a system suspend -- once the device is suspended, it's suspended, period.

Whether or not to resume a suspended device when an I/O request comes in is a policy decision, and there could be cases where the user wants I/O requests to be blocked, or to fail, or to be dropped while the device is suspended, even for runtime power management. For example, a sound card could be suspended due to a low-battery condition, and in that case you would want the driver to just drop any data that userspace tries to write to the soundcard.

Quoted 3 lines

Yes, the code could be changed to keep track of the reason for a device suspend. But that just raises the old problem of what to do when there's an I/O request for a suspended device during STR.

Is this actually a real problem? I would think the policy would be "block" for block devices (pun not intended :), "drop" for network devices, etc.

Quoted 6 lines

Consider a particularly troublesome case: During STR, a non-frozen task writes to /sys/bus/BBB/drivers/DDD/bind. The sysfs core grabs the device semaphore and calls the driver's probe routine. If the driver isn't PM-aware it simply tries to initialize the device and fails because the device is already suspended. That's no good; it isn't transparent.

How did the device get suspended if it didn't have a driver? If it did have a driver, why didn't the bind attempt fail?

Quoted 10 lines

So assume the driver is PM-aware. It tries to resume the device, which fails because STR is underway. Now what can it do? There's only one
possibility: It must block until the resume call can succeed. But when is that?

It has to be before the PM core tries to resume the device, because the core will try to acquire the device semaphore and will block waiting for the probe call to complete. But it has to be after the PM core resumes the device's parent, because obviously the device can't resume until its parent is awake.

Suppose the device-model core code simply blocked all bind and unbind requests while suspend is under way, until resume is finished. Wouldn't that solve the problem?

Paul.

#33 lore raw
In reply to Paul Mackerras
Quoted 11 lines
Quoted 1 line

That's why we have the problem of freezing the kernel threads or not.

That problem is a symptom of the deeper conceptual problem, as is the problem with FUSE.

Quoted 1 line

You want to have all that pain for fuse?

I'd certainly rather get the drivers right, and maybe have an occasional deadlock if I miss something, than have a GUARANTEED deadlock every time I suspend with a FUSE filesystem mounted (which is pretty much every time, since I use encfs regularly).

That's weird, I never had a suspend problem due to a fuse mount, though I have them all the time. And I suspect, that even the sync() thing that suspend does is not the real cause, because sync() actually does nothing in fuse filesystems.

So there's something else going on, which obviously has to do with freezing user processes, but it's not clear what.

Miklos

#34 lore raw
Quoted 2 lines · Miklos Szeredi

That's weird, I never had a suspend problem due to a fuse mount, though I have them all the time. And I suspect, that even the sync()

Well, I don't either, because we don't freeze processes on powerbooks. But I have heard that other people have problems with suspending with a fuse filesystem mounted. Maybe the difference is whether or not the filesystem is writable?

Quoted 2 lines

thing that suspend does is not the real cause, because sync() actually does nothing in fuse filesystems.

It's not the filesystem sync method, as I understand it, it's that if there are dirty pages in the page cache for files on the fuse filesystem, the system will initiate a write-out on them and wait for it to finish. But if the fuse userspace is frozen, the write-out will never complete.

Paul.

#505 lore raw
In reply to Benjamin Herrenschmidt

Am Mittwoch, 4. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Pipe dream

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Then tell me how you want to avoid that condition.

Don't freeze :-)

Then you will have to deal with all syscalls unfrozen tasks can make.

Yup, and the majority of them is totally harmless. Looks like people around here have a problem with the idea of writing robust drivers ...

The majority is meaningless here. The subsystem works or works not. Reliably failing to work is better than working most of the time.

What I am having a problem with is the rest of the system changing its behavior and expecting the drivers to cope with that out of the blue.

Oliver

#506 lore raw
In reply to Benjamin Herrenschmidt

Am Mittwoch, 4. Juli 2007 schrieb Benjamin Herrenschmidt:

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.

Pipe dream

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Then tell me how you want to avoid that condition.

Don't freeze :-)

Then you will have to deal with all syscalls unfrozen tasks can make.

Yup, and the majority of them is totally harmless. Looks like people around here have a problem with the idea of writing robust drivers ...

The majority is meaningless here. The subsystem works or works not. Reliably failing to work is better than working most of the time.

What I am having a problem with is the rest of the system changing its behavior and expecting the drivers to cope with that out of the blue.

Oliver

#48 lore raw
In reply to Paul Mackerras

Am Mittwoch, 4. Juli 2007 schrieb Paul Mackerras:

Quoted 9 lines
Quoted 1 line · Oliver Neukum

USB devices certainly have suspend methods.

Indeed, and the USB framework has code to know when the host controller is suspended and avoid trying to send out urbs in that case.  Or at least it did last time I looked at it in any detail; it's been "just working" - including suspending and resuming, without the freezer - for quite a while now.

And what happens to that IO? I suspended and lost data is not an acceptable behavior.

Oliver

#49 lore raw
In reply to Paul Mackerras

Am Mittwoch, 4. Juli 2007 schrieb Paul Mackerras:

Quoted 9 lines
Quoted 1 line · Oliver Neukum

USB devices certainly have suspend methods.

Indeed, and the USB framework has code to know when the host controller is suspended and avoid trying to send out urbs in that case.  Or at least it did last time I looked at it in any detail; it's been "just working" - including suspending and resuming, without the freezer - for quite a while now.

And what happens to that IO? I suspended and lost data is not an acceptable behavior.

Oliver

#35 lore raw
In reply to Paul Mackerras
Quoted 8 lines
Quoted 2 lines

That's weird, I never had a suspend problem due to a fuse mount, though I have them all the time. And I suspect, that even the sync()

Well, I don't either, because we don't freeze processes on powerbooks. But I have heard that other people have problems with suspending with a fuse filesystem mounted. Maybe the difference is whether or not the filesystem is writable?

Quoted 6 lines
Quoted 2 lines

thing that suspend does is not the real cause, because sync() actually does nothing in fuse filesystems.

It's not the filesystem sync method, as I understand it, it's that if there are dirty pages in the page cache for files on the fuse filesystem,

Currently fuse doesn't produce dirty pages. Normal writes are done synchronously, and writable mmap is not supported. So sync() should really be a no-op for fuse.

Quoted 3 lines

the system will initiate a write-out on them and wait for it to finish. But if the fuse userspace is frozen, the write-out will never complete.

Maybe there is some other fs operation being done, possibly not directly, but by waiting for a kernel thread, that does that.

It would be nice, if someone who can reproduce the deadlock could debug it. Does sysrq still work during suspend?

Miklos

#50 lore raw
In reply to Oliver Neukum
Quoted 8 lines · Oliver Neukum
Quoted 5 lines

Indeed, and the USB framework has code to know when the host controller is suspended and avoid trying to send out urbs in that case.  Or at least it did last time I looked at it in any detail; it's been "just working" - including suspending and resuming, without the freezer - for quite a while now.

And what happens to that IO? I suspended and lost data is not an acceptable behavior.

It's not lost, it's sitting in RAM, and will be sent out when you resume.

Paul.

#36 lore raw
In reply to Paul Mackerras
Quoted 8 lines
Quoted 2 lines

That's weird, I never had a suspend problem due to a fuse mount, though I have them all the time. And I suspect, that even the sync()

Well, I don't either, because we don't freeze processes on powerbooks. But I have heard that other people have problems with suspending with a fuse filesystem mounted. Maybe the difference is whether or not the filesystem is writable?

Quoted 6 lines
Quoted 2 lines

thing that suspend does is not the real cause, because sync() actually does nothing in fuse filesystems.

It's not the filesystem sync method, as I understand it, it's that if there are dirty pages in the page cache for files on the fuse filesystem,

Currently fuse doesn't produce dirty pages. Normal writes are done synchronously, and writable mmap is not supported. So sync() should really be a no-op for fuse.

Quoted 3 lines

the system will initiate a write-out on them and wait for it to finish. But if the fuse userspace is frozen, the write-out will never complete.

Maybe there is some other fs operation being done, possibly not directly, but by waiting for a kernel thread, that does that.

It would be nice, if someone who can reproduce the deadlock could debug it. Does sysrq still work during suspend?

Miklos

#51 lore raw
In reply to Oliver Neukum
Quoted 8 lines · Oliver Neukum
Quoted 5 lines

Indeed, and the USB framework has code to know when the host controller is suspended and avoid trying to send out urbs in that case.  Or at least it did last time I looked at it in any detail; it's been "just working" - including suspending and resuming, without the freezer - for quite a while now.

And what happens to that IO? I suspended and lost data is not an acceptable behavior.

It's not lost, it's sitting in RAM, and will be sent out when you resume.

Paul.

#52 lore raw

Am Mittwoch, 4. Juli 2007 schrieb Paul Mackerras:

Quoted 8 lines
Quoted 6 lines · Oliver Neukum
Quoted 5 lines

Indeed, and the USB framework has code to know when the host controller is suspended and avoid trying to send out urbs in that case.  Or at least it did last time I looked at it in any detail; it's been "just working" - including suspending and resuming, without the freezer - for quite a while now.

Quoted 5 lines
Quoted 2 lines

And what happens to that IO? I suspended and lost data is not an acceptable behavior.

It's not lost, it's sitting in RAM, and will be sent out when you resume.

Unfortunately this is not the case. The URB will error out.

Oliver

#53 lore raw
In reply to Paul Mackerras

Am Mittwoch, 4. Juli 2007 schrieb Paul Mackerras:

Quoted 8 lines
Quoted 6 lines · Oliver Neukum
Quoted 5 lines

Indeed, and the USB framework has code to know when the host controller is suspended and avoid trying to send out urbs in that case.  Or at least it did last time I looked at it in any detail; it's been "just working" - including suspending and resuming, without the freezer - for quite a while now.

Quoted 5 lines
Quoted 2 lines

And what happens to that IO? I suspended and lost data is not an acceptable behavior.

It's not lost, it's sitting in RAM, and will be sent out when you resume.

Unfortunately this is not the case. The URB will error out.

Oliver

#54 lore raw
Quoted 4 lines · Oliver Neukum
Quoted 2 lines

It's not lost, it's sitting in RAM, and will be sent out when you resume.

Unfortunately this is not the case. The URB will error out.

So the higher-level driver needs to do the sensible thing, i.e., resubmit the URB after resume. It's not rocket science. The data is not lost, it's sitting in RAM, and the higher-level driver will send it out when you resume. If not, then we fix the higher-level driver.

Of course with USB there is the interesting question of whether the device is still there when we resume. But if it isn't, the situation is no different to the user asynchronously unplugging the device during operation, and if we lose data in that situation, we can only blame the user. :)

Paul.

#55 lore raw
In reply to Oliver Neukum
Quoted 4 lines · Oliver Neukum
Quoted 2 lines

It's not lost, it's sitting in RAM, and will be sent out when you resume.

Unfortunately this is not the case. The URB will error out.

So the higher-level driver needs to do the sensible thing, i.e., resubmit the URB after resume. It's not rocket science. The data is not lost, it's sitting in RAM, and the higher-level driver will send it out when you resume. If not, then we fix the higher-level driver.

Of course with USB there is the interesting question of whether the device is still there when we resume. But if it isn't, the situation is no different to the user asynchronously unplugging the device during operation, and if we lose data in that situation, we can only blame the user. :)

Paul.

#56 lore raw

Am Mittwoch, 4. Juli 2007 schrieb Paul Mackerras:

Quoted 11 lines
Quoted 4 lines · Oliver Neukum
Quoted 2 lines

It's not lost, it's sitting in RAM, and will be sent out when you resume.

Unfortunately this is not the case. The URB will error out.

So the higher-level driver needs to do the sensible thing, i.e., resubmit the URB after resume.  It's not rocket science.  The data is not lost, it's sitting in RAM, and the higher-level driver will send it out when you resume.  If not, then we fix the higher-level driver.

You cannot simply restart the URB without thinking. The device after resumption may or may not be in the stage you left it. It needs to be rechecked and some settings must be renewed. You cannot simple throw an URB from an arbitrary stage of the protocol at it.
Suspension of devices can only happen at some points in the protocol.

Oliver

#57 lore raw
In reply to Paul Mackerras

Am Mittwoch, 4. Juli 2007 schrieb Paul Mackerras:

Quoted 11 lines
Quoted 4 lines · Oliver Neukum
Quoted 2 lines

It's not lost, it's sitting in RAM, and will be sent out when you resume.

Unfortunately this is not the case. The URB will error out.

So the higher-level driver needs to do the sensible thing, i.e., resubmit the URB after resume.  It's not rocket science.  The data is not lost, it's sitting in RAM, and the higher-level driver will send it out when you resume.  If not, then we fix the higher-level driver.

You cannot simply restart the URB without thinking. The device after resumption may or may not be in the stage you left it. It needs to be rechecked and some settings must be renewed. You cannot simple throw an URB from an arbitrary stage of the protocol at it.
Suspension of devices can only happen at some points in the protocol.

Oliver

#37 lore raw
In reply to Miklos Szeredi
Quoted 19 lines · Miklos Szeredi
Quoted 8 lines
Quoted 2 lines

That's weird, I never had a suspend problem due to a fuse mount, though I have them all the time. And I suspect, that even the sync()

Well, I don't either, because we don't freeze processes on powerbooks. But I have heard that other people have problems with suspending with a fuse filesystem mounted. Maybe the difference is whether or not the filesystem is writable?

Quoted 6 lines
Quoted 2 lines

thing that suspend does is not the real cause, because sync() actually does nothing in fuse filesystems.

It's not the filesystem sync method, as I understand it, it's that if there are dirty pages in the page cache for files on the fuse filesystem,

Currently fuse doesn't produce dirty pages. Normal writes are done synchronously, and writable mmap is not supported. So sync() should really be a no-op for fuse.

Quoted 6 lines
Quoted 3 lines

the system will initiate a write-out on them and wait for it to finish. But if the fuse userspace is frozen, the write-out will never complete.

Maybe there is some other fs operation being done, possibly not directly, but by waiting for a kernel thread, that does that.

We're going to limit the freezing of kernel threads to the ones that explicitly want to be frozen, so if that's the case, then I think it'll be fixed soon.

Quoted 2 lines

It would be nice, if someone who can reproduce the deadlock could debug it.

Agreed.

Quoted 1 line

Does sysrq still work during suspend?

Yes, it should work.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#291 lore raw
In reply to Paul Mackerras
Quoted 8 lines · Paul Mackerras
Quoted 3 lines · Rafael J. Wysocki

Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?

The basis is that it (the freezer) causes more deadlocks and other problems than it avoids, so it's a net win to remove it.

So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#38 lore raw
In reply to Miklos Szeredi
Quoted 19 lines · Miklos Szeredi
Quoted 8 lines
Quoted 2 lines

That's weird, I never had a suspend problem due to a fuse mount, though I have them all the time. And I suspect, that even the sync()

Well, I don't either, because we don't freeze processes on powerbooks. But I have heard that other people have problems with suspending with a fuse filesystem mounted. Maybe the difference is whether or not the filesystem is writable?

Quoted 6 lines
Quoted 2 lines

thing that suspend does is not the real cause, because sync() actually does nothing in fuse filesystems.

It's not the filesystem sync method, as I understand it, it's that if there are dirty pages in the page cache for files on the fuse filesystem,

Currently fuse doesn't produce dirty pages. Normal writes are done synchronously, and writable mmap is not supported. So sync() should really be a no-op for fuse.

Quoted 6 lines
Quoted 3 lines

the system will initiate a write-out on them and wait for it to finish. But if the fuse userspace is frozen, the write-out will never complete.

Maybe there is some other fs operation being done, possibly not directly, but by waiting for a kernel thread, that does that.

We're going to limit the freezing of kernel threads to the ones that explicitly want to be frozen, so if that's the case, then I think it'll be fixed soon.

Quoted 2 lines

It would be nice, if someone who can reproduce the deadlock could debug it.

Agreed.

Quoted 1 line

Does sysrq still work during suspend?

Yes, it should work.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#584 lore raw
In reply to Paul Mackerras
Quoted 6 lines · Paul Mackerras
Quoted 3 lines · Rafael J. Wysocki

Now, please tell me how many driver writers even thought that something might try to access their devices after .suspend() had been executed (or even whilie it was being executed)?

Quoted 6 lines

Well, I believe that the USB framework copes with this, except possibly for some corner cases like the example that Alan Stern posted. The fact that powerbooks suspend and resume without the freezer implies that the IDE framework, the console code and the framebuffer code cope correctly (though possibly not all chipset drivers).

Okay, so in fact you don't know.

And that's my point in this thread.

I won't fight for the freezer for what it's worth, but let's do things in the _right_ _order_. For example, let's make sure that by making the $subject change we won't introduce (too many) regressions and fix the frameworks that don't get it right.

Using the problems with FUSE as an argument for making this change immediately doesn't seem to be right to me.

Quoted 3 lines

So I think that a lot of the frameworks already get it right. Of course the quality of the low-level chipset drivers has always been pretty variable. :)

Yes, but that's another issue.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#58 lore raw
In reply to Oliver Neukum
Quoted 7 lines · Oliver Neukum

You cannot simply restart the URB without thinking. The device after resumption may or may not be in the stage you left it. It needs to be rechecked and some settings must be renewed. You cannot simple throw an URB from an arbitrary stage of the protocol at it.
Suspension of devices can only happen at some points in the protocol.

Yeah, and?

I said "the higher-level driver needs to do the sensible thing".

Paul.

#292 lore raw
In reply to Rafael J. Wysocki
Quoted 2 lines · Rafael J. Wysocki

So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?

Ben and I are happy to handle all the ones for the platform we maintain, which currently does suspend without freezing processes. :)

Paul.

#59 lore raw
In reply to Paul Mackerras

Am Mittwoch, 4. Juli 2007 schrieb Paul Mackerras:

Quoted 10 lines
Quoted 7 lines · Oliver Neukum

You cannot simply restart the URB without thinking. The device after resumption may or may not be in the stage you left it. It needs to be rechecked and some settings must be renewed. You cannot simple throw an URB from an arbitrary stage of the protocol at it.
Suspension of devices can only happen at some points in the protocol.

Quoted 3 lines

Yeah, and?

I said "the higher-level driver needs to do the sensible thing".

They can't. Device specific protocols are known to the drivers only. The fact remains, remove the freezer and you need to go through all drivers.

Oliver

#585 lore raw
In reply to Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki

Okay, so in fact you don't know.

Don't know what exactly?

It has been a while since I had my head in the USB code. I assume it's being maintained by competent people. :)

Quoted 1 line

And that's my point in this thread.

Well, I'd be interested in hearing from Matthew whether he has actually been using his patch in Ubuntu, and if so, what bug reports he has been receiving related to it?

Quoted 7 lines

I won't fight for the freezer for what it's worth, but let's do things in the _right_ _order_. For example, let's make sure that by making the $subject change we won't introduce (too many) regressions and fix the frameworks that don't get it right.

Using the problems with FUSE as an argument for making this change immediately doesn't seem to be right to me.

I can see your point, but I won't be moving powermac over to use the generic suspend path until the freezer is gone, since I am pretty confident that the drivers we care about behave sensibly, and I have seen a lot of traffic on linux-pm and lkml about problems caused by the freezer.

Also, no-one has yet answered my fundamental objection to the freezer, which is that the very kernel threads we would want to freeze are often the same ones that we must not freeze, namely the threads that issue I/O requests in order to satisfy incoming I/O requests.

If there was an automatic way to construct the graph of dependencies (including data flows) between tasks, and derive an ordering for freezing that guarantees that all I/Os will get completed without deadlocks, then I could accept the freezer. But we don't have anything like that.

Paul.

#293 lore raw
In reply to Rafael J. Wysocki
Quoted 2 lines · Rafael J. Wysocki

So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?

Ben and I are happy to handle all the ones for the platform we maintain, which currently does suspend without freezing processes. :)

Paul.

#60 lore raw
In reply to Oliver Neukum
Quoted 3 lines · Oliver Neukum

They can't. Device specific protocols are known to the drivers only. The fact remains, remove the freezer and you need to go through all drivers.

The freezer does not actually mean that you don't have to get the drivers right, because kernel threads can issue I/O requests.

Paul.

#61 lore raw
In reply to Oliver Neukum
Quoted 3 lines · Oliver Neukum

They can't. Device specific protocols are known to the drivers only. The fact remains, remove the freezer and you need to go through all drivers.

The freezer does not actually mean that you don't have to get the drivers right, because kernel threads can issue I/O requests.

Paul.

#62 lore raw

Am Mittwoch, 4. Juli 2007 schrieb Paul Mackerras:

Quoted 8 lines
Quoted 3 lines · Oliver Neukum

They can't. Device specific protocols are known to the drivers only. The fact remains, remove the freezer and you need to go through all drivers.

The freezer does not actually mean that you don't have to get the drivers right, because kernel threads can issue I/O requests.

Kernel threads do not issue requests for the hell of it. And yes, kernel threads must be aware of suspension. Threads are few, drivers many.

Oliver

#294 lore raw
In reply to Paul Mackerras
Quoted 7 lines · Paul Mackerras
Quoted 2 lines · Rafael J. Wysocki

So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?

Ben and I are happy to handle all the ones for the platform we maintain, which currently does suspend without freezing processes. :)

I mean all platforms. After all, the $subject change won't affect yours.

BTW, does your platform's suspend work on SMP systems?

Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#63 lore raw
In reply to Paul Mackerras

Am Mittwoch, 4. Juli 2007 schrieb Paul Mackerras:

Quoted 8 lines
Quoted 3 lines · Oliver Neukum

They can't. Device specific protocols are known to the drivers only. The fact remains, remove the freezer and you need to go through all drivers.

The freezer does not actually mean that you don't have to get the drivers right, because kernel threads can issue I/O requests.

Kernel threads do not issue requests for the hell of it. And yes, kernel threads must be aware of suspension. Threads are few, drivers many.

Oliver

#306 lore raw
In reply to Paul Mackerras
Quoted 7 lines · Paul Mackerras
Quoted 2 lines · Rafael J. Wysocki

So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?

Ben and I are happy to handle all the ones for the platform we maintain, which currently does suspend without freezing processes. :)

I mean all platforms. After all, the $subject change won't affect yours.

BTW, does your platform's suspend work on SMP systems?

Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#586 lore raw
In reply to Paul Mackerras
Quoted 5 lines · Paul Mackerras
Quoted 1 line · Rafael J. Wysocki

Okay, so in fact you don't know.

Don't know what exactly?

How many drivers will be adversely affected by the $subject change.

Quoted 2 lines

It has been a while since I had my head in the USB code. I assume it's being maintained by competent people. :)

I'm not talking about USB.

Quoted 5 lines
Quoted 1 line

And that's my point in this thread.

Well, I'd be interested in hearing from Matthew whether he has actually been using his patch in Ubuntu, and if so, what bug reports he has been receiving related to it?

Me too.

Quoted 5 lines
Quoted 5 lines

I won't fight for the freezer for what it's worth, but let's do things in the _right_ _order_. For example, let's make sure that by making the $subject change we won't introduce (too many) regressions and fix the frameworks that don't get it right.

Quoted 8 lines
Quoted 2 lines

Using the problems with FUSE as an argument for making this change immediately doesn't seem to be right to me.

I can see your point, but I won't be moving powermac over to use the generic suspend path until the freezer is gone, since I am pretty confident that the drivers we care about behave sensibly, and I have seen a lot of traffic on linux-pm and lkml about problems caused by the freezer.

They are mostly related to kernel threads, that we've already agreed no to freeze (except for the ones that want that, but they will be responsible for getting everything right). The initial patches for that are in -mm and more will come.

Quoted 4 lines

Also, no-one has yet answered my fundamental objection to the freezer, which is that the very kernel threads we would want to freeze are often the same ones that we must not freeze, namely the threads that issue I/O requests in order to satisfy incoming I/O requests.

See above. We're moving away from freezing kernel threads.

Quoted 5 lines

If there was an automatic way to construct the graph of dependencies (including data flows) between tasks, and derive an ordering for freezing that guarantees that all I/Os will get completed without deadlocks, then I could accept the freezer. But we don't have anything like that.

No we don't.

Still, my position is this:

1) The freezer (in the modified form, with the freezing of kernel threads limited to the ones that want to be frozen) is needed for hibernation.

2) The freezer is generally not needed for suspend, _but_ there are drivers in the tree that rely on it being used. Thus, at some point in time we can remove the freezer from the suspend code path, _but_ no sooner than we are sure that the majority of drivers is prepared for that.

3) In the meantime, if there are freezer-related problems, they should be fixed rather than used as arguments for immediate removal of it, because of 2).

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#295 lore raw
In reply to Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki

BTW, does your platform's suspend work on SMP systems?

Yes; currently we require userspace to offline all cpus other than the boot cpu before initiating the suspend.

The main difficulty is actually that SMP powermacs that can suspend tend to have video cards that get powered off in suspend. We know how to re-initialize one (the Radeon RV100 QW) but not others. That's an orthogonal issue to the issues we have been discussing, though.

Paul.

#304 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines
Quoted 2 lines

So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?

Ben and I are happy to handle all the ones for the platform we maintain, which currently does suspend without freezing processes. :)

I mean all platforms. After all, the $subject change won't affect yours.

Well, I can't commit to handling all bug reports, but I am happy to help out where I can...

Paul.

#305 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines
Quoted 2 lines

So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?

Ben and I are happy to handle all the ones for the platform we maintain, which currently does suspend without freezing processes. :)

I mean all platforms. After all, the $subject change won't affect yours.

Well, I can't commit to handling all bug reports, but I am happy to help out where I can...

Paul.

#640 lore raw
In reply to Paul Mackerras
Quoted 5 lines · Paul Mackerras
Quoted 1 line · Rafael J. Wysocki

Okay, so in fact you don't know.

Don't know what exactly?

How many drivers will be adversely affected by the $subject change.

Quoted 2 lines

It has been a while since I had my head in the USB code. I assume it's being maintained by competent people. :)

I'm not talking about USB.

Quoted 5 lines
Quoted 1 line

And that's my point in this thread.

Well, I'd be interested in hearing from Matthew whether he has actually been using his patch in Ubuntu, and if so, what bug reports he has been receiving related to it?

Me too.

Quoted 5 lines
Quoted 5 lines

I won't fight for the freezer for what it's worth, but let's do things in the _right_ _order_. For example, let's make sure that by making the $subject change we won't introduce (too many) regressions and fix the frameworks that don't get it right.

Quoted 8 lines
Quoted 2 lines

Using the problems with FUSE as an argument for making this change immediately doesn't seem to be right to me.

I can see your point, but I won't be moving powermac over to use the generic suspend path until the freezer is gone, since I am pretty confident that the drivers we care about behave sensibly, and I have seen a lot of traffic on linux-pm and lkml about problems caused by the freezer.

They are mostly related to kernel threads, that we've already agreed no to freeze (except for the ones that want that, but they will be responsible for getting everything right). The initial patches for that are in -mm and more will come.

Quoted 4 lines

Also, no-one has yet answered my fundamental objection to the freezer, which is that the very kernel threads we would want to freeze are often the same ones that we must not freeze, namely the threads that issue I/O requests in order to satisfy incoming I/O requests.

See above. We're moving away from freezing kernel threads.

Quoted 5 lines

If there was an automatic way to construct the graph of dependencies (including data flows) between tasks, and derive an ordering for freezing that guarantees that all I/Os will get completed without deadlocks, then I could accept the freezer. But we don't have anything like that.

No we don't.

Still, my position is this:

1) The freezer (in the modified form, with the freezing of kernel threads limited to the ones that want to be frozen) is needed for hibernation.

2) The freezer is generally not needed for suspend, _but_ there are drivers in the tree that rely on it being used. Thus, at some point in time we can remove the freezer from the suspend code path, _but_ no sooner than we are sure that the majority of drivers is prepared for that.

3) In the meantime, if there are freezer-related problems, they should be fixed rather than used as arguments for immediate removal of it, because of 2).

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#587 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

They are mostly related to kernel threads, that we've already agreed no to freeze (except for the ones that want that, but they will be responsible for getting everything right). The initial patches for that are in -mm and more will come.

Serious question: which kernel threads would actually want to be frozen?

Threads that do no I/O at all don't care about suspend/resume and don't need to be frozen in any case. Threads that issue I/O requests in order to service incoming I/O requests can't be frozen because of the possibility of deadlock. Which leaves threads that do I/O just for the fun of it. :)

What am I missing?

Quoted 6 lines
Quoted 4 lines

Also, no-one has yet answered my fundamental objection to the freezer, which is that the very kernel threads we would want to freeze are often the same ones that we must not freeze, namely the threads that issue I/O requests in order to satisfy incoming I/O requests.

See above. We're moving away from freezing kernel threads.

I believe the distinction between threads and user processes is a false one, because user processes can now do things that were formerly only doable by kernel threads.

Quoted 8 lines
Quoted 5 lines

If there was an automatic way to construct the graph of dependencies (including data flows) between tasks, and derive an ordering for freezing that guarantees that all I/Os will get completed without deadlocks, then I could accept the freezer. But we don't have anything like that.

No we don't.

Quoted 7 lines

Still, my position is this:

1) The freezer (in the modified form, with the freezing of kernel threads limited to the ones that want to be frozen) is needed for hibernation.

2) The freezer is generally not needed for suspend, _but_ there are drivers in the tree that rely on it being used. Thus, at some point in time we can

Do you know which drivers they are? I'm happy to help hack things into shape.

Quoted 5 lines

remove the freezer from the suspend code path, _but_ no sooner than we are sure that the majority of drivers is prepared for that.

3) In the meantime, if there are freezer-related problems, they should be fixed rather than used as arguments for immediate removal of it, because of 2).

I don't know how you can make the freezer completely deadlock-free while still providing the guarantee that some drivers currently need, without constructing the dependency graph I mentioned.

Paul.

#588 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

They are mostly related to kernel threads, that we've already agreed no to freeze (except for the ones that want that, but they will be responsible for getting everything right). The initial patches for that are in -mm and more will come.

Serious question: which kernel threads would actually want to be frozen?

Threads that do no I/O at all don't care about suspend/resume and don't need to be frozen in any case. Threads that issue I/O requests in order to service incoming I/O requests can't be frozen because of the possibility of deadlock. Which leaves threads that do I/O just for the fun of it. :)

What am I missing?

Quoted 6 lines
Quoted 4 lines

Also, no-one has yet answered my fundamental objection to the freezer, which is that the very kernel threads we would want to freeze are often the same ones that we must not freeze, namely the threads that issue I/O requests in order to satisfy incoming I/O requests.

See above. We're moving away from freezing kernel threads.

I believe the distinction between threads and user processes is a false one, because user processes can now do things that were formerly only doable by kernel threads.

Quoted 8 lines
Quoted 5 lines

If there was an automatic way to construct the graph of dependencies (including data flows) between tasks, and derive an ordering for freezing that guarantees that all I/Os will get completed without deadlocks, then I could accept the freezer. But we don't have anything like that.

No we don't.

Quoted 7 lines

Still, my position is this:

1) The freezer (in the modified form, with the freezing of kernel threads limited to the ones that want to be frozen) is needed for hibernation.

2) The freezer is generally not needed for suspend, _but_ there are drivers in the tree that rely on it being used. Thus, at some point in time we can

Do you know which drivers they are? I'm happy to help hack things into shape.

Quoted 5 lines

remove the freezer from the suspend code path, _but_ no sooner than we are sure that the majority of drivers is prepared for that.

3) In the meantime, if there are freezer-related problems, they should be fixed rather than used as arguments for immediate removal of it, because of 2).

I don't know how you can make the freezer completely deadlock-free while still providing the guarantee that some drivers currently need, without constructing the dependency graph I mentioned.

Paul.

#594 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines

Still, my position is this:

1) The freezer (in the modified form, with the freezing of kernel threads limited to the ones that want to be frozen) is needed for hibernation.

2) The freezer is generally not needed for suspend, _but_ there are drivers in the tree that rely on it being used. Thus, at some point in time we can remove the freezer from the suspend code path, _but_ no sooner than we are sure that the majority of drivers is prepared for that.

And we won't know if drivers are OK until we remove the freezer, catch-22.

So I think we need to disable the freezer at least in -mm and/or optionally in -linus.

I applied Matthew's patch, and suspend did in fact stop working (thinkpad t60), but there was nothing catastrophic. Here's the dmesg if somebody is interested:

Suspending console(s)
usb_endpoint usbdev5.3_ep83: PM: suspend 0->2, parent 5-2:1.0 already 2 usb_endpoint usbdev5.3_ep02: PM: suspend 0->2, parent 5-2:1.0 already 2 usb_endpoint usbdev5.3_ep81: PM: suspend 0->2, parent 5-2:1.0 already 2 hub 2-0:1.0: suspend error -16
suspend_device(): usb_suspend+0x0/0x1c() returns -16
Could not suspend device usb2: error -16
usb_endpoint usbdev5.3_ep81: PM: resume from 0, parent 5-2:1.0 still 2 usb_endpoint usbdev5.3_ep02: PM: resume from 0, parent 5-2:1.0 still 2 usb_endpoint usbdev5.3_ep83: PM: resume from 0, parent 5-2:1.0 still 2 Some devices failed to suspend

Miklos

#595 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines

Still, my position is this:

1) The freezer (in the modified form, with the freezing of kernel threads limited to the ones that want to be frozen) is needed for hibernation.

2) The freezer is generally not needed for suspend, _but_ there are drivers in the tree that rely on it being used. Thus, at some point in time we can remove the freezer from the suspend code path, _but_ no sooner than we are sure that the majority of drivers is prepared for that.

And we won't know if drivers are OK until we remove the freezer, catch-22.

So I think we need to disable the freezer at least in -mm and/or optionally in -linus.

I applied Matthew's patch, and suspend did in fact stop working (thinkpad t60), but there was nothing catastrophic. Here's the dmesg if somebody is interested:

Suspending console(s)
usb_endpoint usbdev5.3_ep83: PM: suspend 0->2, parent 5-2:1.0 already 2 usb_endpoint usbdev5.3_ep02: PM: suspend 0->2, parent 5-2:1.0 already 2 usb_endpoint usbdev5.3_ep81: PM: suspend 0->2, parent 5-2:1.0 already 2 hub 2-0:1.0: suspend error -16
suspend_device(): usb_suspend+0x0/0x1c() returns -16
Could not suspend device usb2: error -16
usb_endpoint usbdev5.3_ep81: PM: resume from 0, parent 5-2:1.0 still 2 usb_endpoint usbdev5.3_ep02: PM: resume from 0, parent 5-2:1.0 still 2 usb_endpoint usbdev5.3_ep83: PM: resume from 0, parent 5-2:1.0 still 2 Some devices failed to suspend

Miklos

#636 lore raw
In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki
Quoted 1 line

Don't know what exactly?

How many drivers will be adversely affected by the $subject change.

Ok, so how about a CONFIG option which removes the freezer, so we can find out experimentally how many people without it? We can make it be experimental at first, or (my preference) make it be the default initially, and if people complain that their laptop's suspend feature is broken, we can tell them how to turn back on the CONFIG_FREEZER_DEPRECATED option.

- Ted

#637 lore raw
In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki
Quoted 1 line

Don't know what exactly?

How many drivers will be adversely affected by the $subject change.

Ok, so how about a CONFIG option which removes the freezer, so we can find out experimentally how many people without it? We can make it be experimental at first, or (my preference) make it be the default initially, and if people complain that their laptop's suspend feature is broken, we can tell them how to turn back on the CONFIG_FREEZER_DEPRECATED option.

- Ted

#589 lore raw
In reply to Paul Mackerras
Quoted 10 lines · Paul Mackerras
Quoted 4 lines · Rafael J. Wysocki

They are mostly related to kernel threads, that we've already agreed no to freeze (except for the ones that want that, but they will be responsible for getting everything right). The initial patches for that are in -mm and more will come.

Serious question: which kernel threads would actually want to be frozen?

Quoted 8 lines

Threads that do no I/O at all don't care about suspend/resume and don't need to be frozen in any case. Threads that issue I/O requests in order to service incoming I/O requests can't be frozen because of the possibility of deadlock. Which leaves threads that do I/O just for the fun of it. :)

What am I missing?

I like kseriod and kgameportd to be frozen. If fast resume of serio port fails we kick the task of full resume to kseriod. But when we hibernate and all the devices are resumed again so snapshot can be written I don't care if touchpad failed to resume - it can be dealt with later, when system is actually resumes. So I like that by freezing I do not delay hibernation and all requests get simply discarded as they are not in the image. This mostly affects hibernation though.

Having these threads frozen also guarantees that serio/gameport device tree is stable during susped/resume and I can process outstanding requests later, when system is fully up.

Signature · 1 line
Dmitry
#590 lore raw
In reply to Paul Mackerras
Quoted 10 lines · Paul Mackerras
Quoted 4 lines · Rafael J. Wysocki

They are mostly related to kernel threads, that we've already agreed no to freeze (except for the ones that want that, but they will be responsible for getting everything right). The initial patches for that are in -mm and more will come.

Serious question: which kernel threads would actually want to be frozen?

Quoted 8 lines

Threads that do no I/O at all don't care about suspend/resume and don't need to be frozen in any case. Threads that issue I/O requests in order to service incoming I/O requests can't be frozen because of the possibility of deadlock. Which leaves threads that do I/O just for the fun of it. :)

What am I missing?

I like kseriod and kgameportd to be frozen. If fast resume of serio port fails we kick the task of full resume to kseriod. But when we hibernate and all the devices are resumed again so snapshot can be written I don't care if touchpad failed to resume - it can be dealt with later, when system is actually resumes. So I like that by freezing I do not delay hibernation and all requests get simply discarded as they are not in the image. This mostly affects hibernation though.

Having these threads frozen also guarantees that serio/gameport device tree is stable during susped/resume and I can process outstanding requests later, when system is fully up.

Signature · 1 line
Dmitry
#296 lore raw
In reply to Paul Mackerras
Quoted 6 lines · Paul Mackerras
Quoted 1 line · Rafael J. Wysocki

BTW, does your platform's suspend work on SMP systems?

Yes; currently we require userspace to offline all cpus other than the boot cpu before initiating the suspend.

This is incompatible with the code in kernel/power/main.c, since we only disable the nonboot CPUs after devices have been suspended. Do you think that your framework can be modified to work without disabling the nonboot CPUs by the user space?

Quoted 4 lines

The main difficulty is actually that SMP powermacs that can suspend tend to have video cards that get powered off in suspend. We know how to re-initialize one (the Radeon RV100 QW) but not others. That's an orthogonal issue to the issues we have been discussing, though.

Sure.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#303 lore raw
In reply to Paul Mackerras
Quoted 6 lines · Paul Mackerras
Quoted 1 line · Rafael J. Wysocki

BTW, does your platform's suspend work on SMP systems?

Yes; currently we require userspace to offline all cpus other than the boot cpu before initiating the suspend.

This is incompatible with the code in kernel/power/main.c, since we only disable the nonboot CPUs after devices have been suspended. Do you think that your framework can be modified to work without disabling the nonboot CPUs by the user space?

Quoted 4 lines

The main difficulty is actually that SMP powermacs that can suspend tend to have video cards that get powered off in suspend. We know how to re-initialize one (the Radeon RV100 QW) but not others. That's an orthogonal issue to the issues we have been discussing, though.

Sure.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#638 lore raw
In reply to Theodore Tso
Quoted 11 lines · Theodore Tso
Quoted 3 lines · Rafael J. Wysocki
Quoted 1 line

Don't know what exactly?

How many drivers will be adversely affected by the $subject change.

Ok, so how about a CONFIG option which removes the freezer, so we can find out experimentally how many people without it? We can make it be experimental at first, or (my preference) make it be the default initially, and if people complain that their laptop's suspend feature is broken, we can tell them how to turn back on the CONFIG_FREEZER_DEPRECATED option.

The freezer is generally still necessary for hibernation, so I won't call it "DEPRECATED'.

Moreover, I'd prefer to make drivers use different callbacks for hibernation and suspend before we do that.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#596 lore raw
In reply to Miklos Szeredi
Quoted 5 lines · Miklos Szeredi
Quoted 5 lines

Still, my position is this:

1) The freezer (in the modified form, with the freezing of kernel threads limited to the ones that want to be frozen) is needed for hibernation.

Quoted 7 lines
Quoted 4 lines

2) The freezer is generally not needed for suspend, _but_ there are drivers in the tree that rely on it being used. Thus, at some point in time we can remove the freezer from the suspend code path, _but_ no sooner than we are sure that the majority of drivers is prepared for that.

And we won't know if drivers are OK until we remove the freezer, catch-22.

I disagree. We can learn that by auditing the drivers.

Quoted 7 lines

So I think we need to disable the freezer at least in -mm and/or optionally in -linus.

I applied Matthew's patch, and suspend did in fact stop working (thinkpad t60), but there was nothing catastrophic. Here's the dmesg if somebody is interested:

Quoted 11 lines

Suspending console(s)
usb_endpoint usbdev5.3_ep83: PM: suspend 0->2, parent 5-2:1.0 already 2 usb_endpoint usbdev5.3_ep02: PM: suspend 0->2, parent 5-2:1.0 already 2 usb_endpoint usbdev5.3_ep81: PM: suspend 0->2, parent 5-2:1.0 already 2 hub 2-0:1.0: suspend error -16
suspend_device(): usb_suspend+0x0/0x1c() returns -16
Could not suspend device usb2: error -16
usb_endpoint usbdev5.3_ep81: PM: resume from 0, parent 5-2:1.0 still 2 usb_endpoint usbdev5.3_ep02: PM: resume from 0, parent 5-2:1.0 still 2 usb_endpoint usbdev5.3_ep83: PM: resume from 0, parent 5-2:1.0 still 2 Some devices failed to suspend

No, it's not catastrophic, but something like this will result in a bug report with "regression" in the subject.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#646 lore raw
In reply to Matthew Garrett
Quoted 8 lines · Matthew Garrett
Quoted 7 lines · Alan Stern
Quoted 2 lines · Matthew Garrett

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

You persist in evading my point. I'm not worried about applications; I'm worried about drivers.

Quoted 7 lines
Quoted 4 lines

Let me put it explicitly: You're writing a driver. You're working on the read, write, or probe method. You add code to check if a system sleep is underway. Suppose the answer is Yes -- what does your driver do next?

Leave the process blocked and defer any i/o until after resume. Why does it need to be any more complicated than that?

(1) The driver will undoubtedly hold some mutex or semaphore at the time it checks whether a system sleep is underway. You will have to drop it before blocking and then reacquire it afterward.

(2) The driver may have been called by some other routine which holds a mutex needed for resuming the device. In this case the driver _can't_ drop the mutex and so the resume will deadlock.

Okay, I agree that (1) can be handled without too much effort. But doing it adds an extra test to _every_ driver's I/O pathway. Freezing userspace does not incur all this additional overhead.

(2) shouldn't arise during normal read and write operations, but it certainly _will_ arise during probe.

Alan Stern

#647 lore raw
In reply to Matthew Garrett
Quoted 8 lines · Matthew Garrett
Quoted 7 lines · Alan Stern
Quoted 2 lines · Matthew Garrett

We're used to the idea of applications blocking when a resource they're using goes away - NFS has done it forever.

You persist in evading my point. I'm not worried about applications; I'm worried about drivers.

Quoted 7 lines
Quoted 4 lines

Let me put it explicitly: You're writing a driver. You're working on the read, write, or probe method. You add code to check if a system sleep is underway. Suppose the answer is Yes -- what does your driver do next?

Leave the process blocked and defer any i/o until after resume. Why does it need to be any more complicated than that?

(1) The driver will undoubtedly hold some mutex or semaphore at the time it checks whether a system sleep is underway. You will have to drop it before blocking and then reacquire it afterward.

(2) The driver may have been called by some other routine which holds a mutex needed for resuming the device. In this case the driver _can't_ drop the mutex and so the resume will deadlock.

Okay, I agree that (1) can be handled without too much effort. But doing it adds an extra test to _every_ driver's I/O pathway. Freezing userspace does not incur all this additional overhead.

(2) shouldn't arise during normal read and write operations, but it certainly _will_ arise during probe.

Alan Stern

#639 lore raw
In reply to Theodore Tso
Quoted 11 lines · Theodore Tso
Quoted 3 lines · Rafael J. Wysocki
Quoted 1 line

Don't know what exactly?

How many drivers will be adversely affected by the $subject change.

Ok, so how about a CONFIG option which removes the freezer, so we can find out experimentally how many people without it? We can make it be experimental at first, or (my preference) make it be the default initially, and if people complain that their laptop's suspend feature is broken, we can tell them how to turn back on the CONFIG_FREEZER_DEPRECATED option.

The freezer is generally still necessary for hibernation, so I won't call it "DEPRECATED'.

Moreover, I'd prefer to make drivers use different callbacks for hibernation and suspend before we do that.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#64 lore raw
In reply to Paul Mackerras
Quoted 9 lines · Paul Mackerras
Quoted 1 line · Oliver Neukum

USB devices certainly have suspend methods.

Indeed, and the USB framework has code to know when the host controller is suspended and avoid trying to send out urbs in that case. Or at least it did last time I looked at it in any detail; it's been "just working" - including suspending and resuming, without the freezer - for quite a while now.

Evidently you haven't been stressing it. You might try suspending while printing to a USB printer.

Alan Stern

#65 lore raw
In reply to Paul Mackerras
Quoted 9 lines · Paul Mackerras
Quoted 1 line · Oliver Neukum

USB devices certainly have suspend methods.

Indeed, and the USB framework has code to know when the host controller is suspended and avoid trying to send out urbs in that case. Or at least it did last time I looked at it in any detail; it's been "just working" - including suspending and resuming, without the freezer - for quite a while now.

Evidently you haven't been stressing it. You might try suspending while printing to a USB printer.

Alan Stern

#597 lore raw
In reply to Rafael J. Wysocki
Quoted 11 lines · Miklos Szeredi
Quoted 10 lines
Quoted 9 lines

Still, my position is this:

1) The freezer (in the modified form, with the freezing of kernel threads limited to the ones that want to be frozen) is needed for hibernation.

2) The freezer is generally not needed for suspend, _but_ there are drivers in the tree that rely on it being used. Thus, at some point in time we can remove the freezer from the suspend code path, _but_ no sooner than we are sure that the majority of drivers is prepared for that.

Quoted 4 lines
Quoted 2 lines

And we won't know if drivers are OK until we remove the freezer, catch-22.

I disagree. We can learn that by auditing the drivers.

In theory, yes. But it scales far worse than letting everyone experiment/report/fix problems as they crop up.

Quoted 19 lines
Quoted 7 lines

So I think we need to disable the freezer at least in -mm and/or optionally in -linus.

I applied Matthew's patch, and suspend did in fact stop working (thinkpad t60), but there was nothing catastrophic. Here's the dmesg if somebody is interested:

Quoted 11 lines

Suspending console(s)
usb_endpoint usbdev5.3_ep83: PM: suspend 0->2, parent 5-2:1.0 already 2 usb_endpoint usbdev5.3_ep02: PM: suspend 0->2, parent 5-2:1.0 already 2 usb_endpoint usbdev5.3_ep81: PM: suspend 0->2, parent 5-2:1.0 already 2 hub 2-0:1.0: suspend error -16
suspend_device(): usb_suspend+0x0/0x1c() returns -16
Could not suspend device usb2: error -16
usb_endpoint usbdev5.3_ep81: PM: resume from 0, parent 5-2:1.0 still 2 usb_endpoint usbdev5.3_ep02: PM: resume from 0, parent 5-2:1.0 still 2 usb_endpoint usbdev5.3_ep83: PM: resume from 0, parent 5-2:1.0 still 2 Some devices failed to suspend

Quoted 2 lines

No, it's not catastrophic, but something like this will result in a bug report with "regression" in the subject.

If it was due to a config option marked experimental, then it's not a regression.

It's a bug, and it needs looking at, but while the freezer is not completely removed, it's not a serious problem.

So I agree with Ted, a config option (or maybe a runtime sysctl tunable) to turn off the freezer for suspend should only have positive effects.

Miklos

#91 lore raw
In reply to Paul Mackerras
Quoted 10 lines · Paul Mackerras
Quoted 4 lines · Alan Stern

I disagree. The problem isn't the kernel calling userspace; it's userspace trying to do I/O at a time when everything is supposed to be quiescing. Detecting that and blocking it in drivers is hard and error-prone; preventing it by freezing userspace is easy and cheap.

And unreliable, and prone to deadlocks, and invasive - requiring changes to kernel threads that have nothing to do with drivers or suspend/resume.

Let's agree the kernel threads and the freezer are a separate issue. In the most recent kernels, the freezer does not suspend kernel threads by default.

I agree the kernel threads which try to do I/O during a suspend will need extra attention. However if these threads are necessary for the suspend procedure, then blocking them (which is how people on this thread have been saying driver should treat I/O requests during a suspend) will cause additional problems. There's no way around it; these threads _will_ require more work.

Quoted 6 lines
Quoted 2 lines

The reasons why the PPC people dislike the whole idea aren't clear to me.

Our experience is that it isn't necessary. It's extra code that in practice causes deadlocks and added maintenance burden for no discernable benefit.

I have discussed the benefits elsewhere. As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

Quoted 5 lines

The freezer doesn't achieve its stated goal of preventing drivers from getting I/O requests after suspend, since kernel threads can (and do) initiate I/O. So then we say that some kernel threads need to be frozen and others don't, but making that decision is difficult and error-prone.

No -- we say that the kernel threads which generate I/O requests during suspend need to be changed.

Quoted 5 lines

In fact I believe that making a distinction between user and kernel threads is wrong and likely to lead to problems, since userspace can be involved in doing I/O (e.g. FUSE or the user-space driver framework). So the argument of the previous paragraph also applies to some userspace processes.

Userspace cannot do I/O directly on its own, apart from some exceptional situations where a privileged task directly twiddles some I/O ports or the equivalent.

There remains the problem of user tasks whose assistance is required to carry out some I/O (as with FUSE). If the I/O can be deferred until after the resume, then there's no problem. If the I/O can be carried out before the suspend, then it should be. And finally, if the I/O must be done during the suspend, you're in real trouble -- how do you do I/O to a suspended device?

Quoted 5 lines

I remain convinced that the right approach is to fix the drivers to do one of two things; either do something in the suspend call to block further requests to the device, or use a late-suspend call to put their device into a low-power state. Of course, correctly-written frameworks can do a lot to help the chipset drivers here.

The first alternative is a possibility. My argument all along has been that it is difficult and error-prone, and it adds more overhead to system operation (even when not suspending!) than simply freezing userspace.

Alan Stern

#92 lore raw
In reply to Paul Mackerras
Quoted 10 lines · Paul Mackerras
Quoted 4 lines · Alan Stern

I disagree. The problem isn't the kernel calling userspace; it's userspace trying to do I/O at a time when everything is supposed to be quiescing. Detecting that and blocking it in drivers is hard and error-prone; preventing it by freezing userspace is easy and cheap.

And unreliable, and prone to deadlocks, and invasive - requiring changes to kernel threads that have nothing to do with drivers or suspend/resume.

Let's agree the kernel threads and the freezer are a separate issue. In the most recent kernels, the freezer does not suspend kernel threads by default.

I agree the kernel threads which try to do I/O during a suspend will need extra attention. However if these threads are necessary for the suspend procedure, then blocking them (which is how people on this thread have been saying driver should treat I/O requests during a suspend) will cause additional problems. There's no way around it; these threads _will_ require more work.

Quoted 6 lines
Quoted 2 lines

The reasons why the PPC people dislike the whole idea aren't clear to me.

Our experience is that it isn't necessary. It's extra code that in practice causes deadlocks and added maintenance burden for no discernable benefit.

I have discussed the benefits elsewhere. As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

Quoted 5 lines

The freezer doesn't achieve its stated goal of preventing drivers from getting I/O requests after suspend, since kernel threads can (and do) initiate I/O. So then we say that some kernel threads need to be frozen and others don't, but making that decision is difficult and error-prone.

No -- we say that the kernel threads which generate I/O requests during suspend need to be changed.

Quoted 5 lines

In fact I believe that making a distinction between user and kernel threads is wrong and likely to lead to problems, since userspace can be involved in doing I/O (e.g. FUSE or the user-space driver framework). So the argument of the previous paragraph also applies to some userspace processes.

Userspace cannot do I/O directly on its own, apart from some exceptional situations where a privileged task directly twiddles some I/O ports or the equivalent.

There remains the problem of user tasks whose assistance is required to carry out some I/O (as with FUSE). If the I/O can be deferred until after the resume, then there's no problem. If the I/O can be carried out before the suspend, then it should be. And finally, if the I/O must be done during the suspend, you're in real trouble -- how do you do I/O to a suspended device?

Quoted 5 lines

I remain convinced that the right approach is to fix the drivers to do one of two things; either do something in the suspend call to block further requests to the device, or use a late-suspend call to put their device into a low-power state. Of course, correctly-written frameworks can do a lot to help the chipset drivers here.

The first alternative is a possibility. My argument all along has been that it is difficult and error-prone, and it adds more overhead to system operation (even when not suspending!) than simply freezing userspace.

Alan Stern

#648 lore raw
In reply to Alan Stern
Quoted 3 lines · Alan Stern

Okay, I agree that (1) can be handled without too much effort. But doing it adds an extra test to _every_ driver's I/O pathway. Freezing userspace does not incur all this additional overhead.

For runtime PM to work it's already necessary to have a test in that path to check if the device is suspended. I can't see how this adds any overhead to the common case.

Signature · 1 line
Matthew Garrett | [email protected]
#649 lore raw
In reply to Alan Stern
Quoted 3 lines · Alan Stern

Okay, I agree that (1) can be handled without too much effort. But doing it adds an extra test to _every_ driver's I/O pathway. Freezing userspace does not incur all this additional overhead.

For runtime PM to work it's already necessary to have a test in that path to check if the device is suspended. I can't see how this adds any overhead to the common case.

Signature · 1 line
Matthew Garrett | [email protected]
#650 lore raw

Am Mittwoch, 4. Juli 2007 schrieb Matthew Garrett:

Quoted 9 lines · Alan Stern
Quoted 4 lines

Okay, I agree that (1) can be handled without too much effort.  But doing it adds an extra test to _every_ driver's I/O pathway.  Freezing userspace does not incur all this additional overhead.

For runtime PM to work it's already necessary to have a test in that path to check if the device is suspended. I can't see how this adds any overhead to the common case.

No,

you just make sure the device reports to upper layers when it might be busy. The USB layer manages this quite well without burdening the common case.

Regards
Oliver

#651 lore raw
In reply to Matthew Garrett

Am Mittwoch, 4. Juli 2007 schrieb Matthew Garrett:

Quoted 9 lines · Alan Stern
Quoted 4 lines

Okay, I agree that (1) can be handled without too much effort.  But doing it adds an extra test to _every_ driver's I/O pathway.  Freezing userspace does not incur all this additional overhead.

For runtime PM to work it's already necessary to have a test in that path to check if the device is suspended. I can't see how this adds any overhead to the common case.

No,

you just make sure the device reports to upper layers when it might be busy. The USB layer manages this quite well without burdening the common case.

Regards
Oliver

#598 lore raw
In reply to Miklos Szeredi

Am Mittwoch, 4. Juli 2007 schrieb Miklos Szeredi:

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

And we won't know if drivers are OK until we remove the freezer, catch-22.

I disagree.  We can learn that by auditing the drivers.

In theory, yes.  But it scales far worse than letting everyone experiment/report/fix problems as they crop up.

You will open many but small races. This would be very painfull to debug.

Regards
Oliver

#599 lore raw
In reply to Miklos Szeredi

Am Mittwoch, 4. Juli 2007 schrieb Miklos Szeredi:

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

And we won't know if drivers are OK until we remove the freezer, catch-22.

I disagree.  We can learn that by auditing the drivers.

In theory, yes.  But it scales far worse than letting everyone experiment/report/fix problems as they crop up.

You will open many but small races. This would be very painfull to debug.

Regards
Oliver

#69 lore raw
In reply to Paul Mackerras
Quoted 6 lines · Paul Mackerras
Quoted 4 lines · Alan Stern
Quoted 3 lines

Most drivers suspended their hardware in the second call. If they are in the middle of a conversation with their device that *has* to be completed, they can do that by polling.

Quoted 6 lines
Quoted 3 lines

Ugh. That will cause problems when you try to integrate runtime suspend. In fact this whole approach is unsuitable for runtime PM and it obscures the similarities between runtime PM and STR.

Yes there are similarities, but it would be a big mistake to say that a requirement for STR is that all drivers do runtime PM.

That's not what I'm saying. What I'm saying is that it would be a big mistake to force all drivers which implement runtime PM to do it using a separate code path from system PM.

Quoted 3 lines

The main attraction of the late-suspend call is that it really does, reliably, guarantee that the driver's I/O request methods won't get called between the late-suspend call and the early-resume call.

For some drivers (like USB), carrying out an actual suspend requires a delay. Right now we implement those delays using wait_event(), wait_for_completion(), and so on. Would you have us check at runtime whether or not a system suspend is underway and in each case use a busy-loop instead if it is?

What happens if, in order to carry out the late-suspend, a driver needs to acquire a mutex which happens to be held by some other task? That other task won't be able to run and release the mutex, so you will deadlock.

Alan Stern

#70 lore raw
In reply to Paul Mackerras
Quoted 6 lines · Paul Mackerras
Quoted 4 lines · Alan Stern
Quoted 3 lines

Most drivers suspended their hardware in the second call. If they are in the middle of a conversation with their device that *has* to be completed, they can do that by polling.

Quoted 6 lines
Quoted 3 lines

Ugh. That will cause problems when you try to integrate runtime suspend. In fact this whole approach is unsuitable for runtime PM and it obscures the similarities between runtime PM and STR.

Yes there are similarities, but it would be a big mistake to say that a requirement for STR is that all drivers do runtime PM.

That's not what I'm saying. What I'm saying is that it would be a big mistake to force all drivers which implement runtime PM to do it using a separate code path from system PM.

Quoted 3 lines

The main attraction of the late-suspend call is that it really does, reliably, guarantee that the driver's I/O request methods won't get called between the late-suspend call and the early-resume call.

For some drivers (like USB), carrying out an actual suspend requires a delay. Right now we implement those delays using wait_event(), wait_for_completion(), and so on. Would you have us check at runtime whether or not a system suspend is underway and in each case use a busy-loop instead if it is?

What happens if, in order to carry out the late-suspend, a driver needs to acquire a mutex which happens to be held by some other task? That other task won't be able to run and release the mutex, so you will deadlock.

Alan Stern

#600 lore raw
In reply to Oliver Neukum
Quoted 11 lines · Oliver Neukum

Am Mittwoch, 4. Juli 2007 schrieb Miklos Szeredi:

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

And we won't know if drivers are OK until we remove the freezer, catch-22.

I disagree.  We can learn that by auditing the drivers.

In theory, yes.  But it scales far worse than letting everyone experiment/report/fix problems as they crop up.

You will open many but small races. This would be very painfull to debug.

Agreed.

They will not trigger 100% of the time, but sporadically and generally at random.

At least the freezer problems are reproducible. ;-)

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#251 lore raw
In reply to Paul Mackerras
Quoted 7 lines · Paul Mackerras

Whether or not to resume a suspended device when an I/O request comes in is a policy decision, and there could be cases where the user wants I/O requests to be blocked, or to fail, or to be dropped while the device is suspended, even for runtime power management. For example, a sound card could be suspended due to a low-battery condition, and in that case you would want the driver to just drop any data that userspace tries to write to the soundcard.

We have provisions for that (my earlier description was somewhat incomplete).

Quoted 7 lines
Quoted 3 lines

Yes, the code could be changed to keep track of the reason for a device suspend. But that just raises the old problem of what to do when there's an I/O request for a suspended device during STR.

Is this actually a real problem? I would think the policy would be "block" for block devices (pun not intended :), "drop" for network devices, etc.

It is indeed a real problem, or at least, it can be.

Quoted 9 lines
Quoted 6 lines

Consider a particularly troublesome case: During STR, a non-frozen task writes to /sys/bus/BBB/drivers/DDD/bind. The sysfs core grabs the device semaphore and calls the driver's probe routine. If the driver isn't PM-aware it simply tries to initialize the device and fails because the device is already suspended. That's no good; it isn't transparent.

How did the device get suspended if it didn't have a driver? If it did have a driver, why didn't the bind attempt fail?

Bus subsystems can suspend devices with no drivers.

Quoted 3 lines

Suppose the device-model core code simply blocked all bind and unbind requests while suspend is under way, until resume is finished. Wouldn't that solve the problem?

It would help. It would help even more if the sysfs core also blocked all I/O while suspend is under way. (Although this might be tricky, considering that the suspend is initiated by a sysfs write...)

The fact remains that lots of drivers would still need to be changed. In the read and write methods someone would have to add code amounting to this:

	if (suspend_is_under_way()) {
		mutex_unlock(...);
		block_until_resume();
		goto restart;
	}

Freezing userspace is a small amount of code by comparison.

Alan Stern

#252 lore raw
In reply to Paul Mackerras
Quoted 7 lines · Paul Mackerras

Whether or not to resume a suspended device when an I/O request comes in is a policy decision, and there could be cases where the user wants I/O requests to be blocked, or to fail, or to be dropped while the device is suspended, even for runtime power management. For example, a sound card could be suspended due to a low-battery condition, and in that case you would want the driver to just drop any data that userspace tries to write to the soundcard.

We have provisions for that (my earlier description was somewhat incomplete).

Quoted 7 lines
Quoted 3 lines

Yes, the code could be changed to keep track of the reason for a device suspend. But that just raises the old problem of what to do when there's an I/O request for a suspended device during STR.

Is this actually a real problem? I would think the policy would be "block" for block devices (pun not intended :), "drop" for network devices, etc.

It is indeed a real problem, or at least, it can be.

Quoted 9 lines
Quoted 6 lines

Consider a particularly troublesome case: During STR, a non-frozen task writes to /sys/bus/BBB/drivers/DDD/bind. The sysfs core grabs the device semaphore and calls the driver's probe routine. If the driver isn't PM-aware it simply tries to initialize the device and fails because the device is already suspended. That's no good; it isn't transparent.

How did the device get suspended if it didn't have a driver? If it did have a driver, why didn't the bind attempt fail?

Bus subsystems can suspend devices with no drivers.

Quoted 3 lines

Suppose the device-model core code simply blocked all bind and unbind requests while suspend is under way, until resume is finished. Wouldn't that solve the problem?

It would help. It would help even more if the sysfs core also blocked all I/O while suspend is under way. (Although this might be tricky, considering that the suspend is initiated by a sysfs write...)

The fact remains that lots of drivers would still need to be changed. In the read and write methods someone would have to add code amounting to this:

	if (suspend_is_under_way()) {
		mutex_unlock(...);
		block_until_resume();
		goto restart;
	}

Freezing userspace is a small amount of code by comparison.

Alan Stern

#606 lore raw
In reply to Oliver Neukum
Quoted 11 lines · Oliver Neukum

Am Mittwoch, 4. Juli 2007 schrieb Miklos Szeredi:

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

And we won't know if drivers are OK until we remove the freezer, catch-22.

I disagree.  We can learn that by auditing the drivers.

In theory, yes.  But it scales far worse than letting everyone experiment/report/fix problems as they crop up.

You will open many but small races. This would be very painfull to debug.

Agreed.

They will not trigger 100% of the time, but sporadically and generally at random.

At least the freezer problems are reproducible. ;-)

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#591 lore raw
In reply to Paul Mackerras
Quoted 9 lines · Paul Mackerras
Quoted 4 lines · Rafael J. Wysocki

They are mostly related to kernel threads, that we've already agreed no to freeze (except for the ones that want that, but they will be responsible for getting everything right). The initial patches for that are in -mm and more will come.

Serious question: which kernel threads would actually want to be frozen?

khubd and ksuspend_usbd.

Quoted 7 lines

Threads that do no I/O at all don't care about suspend/resume and don't need to be frozen in any case. Threads that issue I/O requests in order to service incoming I/O requests can't be frozen because of the possibility of deadlock. Which leaves threads that do I/O just for the fun of it. :)

What am I missing?

Those two threads will try to resume USB devices in response to wakeup requests. Such requests arrive during a suspend or resume transition more often than one would expect.

If the resume attempt occurs before the host controller has been suspended, it will abort the system suspend. If it occurs after the host controller is suspended (and before the controller resumes) it will fail and try to unregister the USB device -- something else we don't like happening while the sytem is only partially up (not to mention the annoyance caused by the unregistration of a perfectly functional device).

Alan Stern

#607 lore raw
In reply to Miklos Szeredi
Quoted 10 lines · Miklos Szeredi

And we won't know if drivers are OK until we remove the freezer, catch-22.

So I think we need to disable the freezer at least in -mm and/or optionally in -linus.

I applied Matthew's patch, and suspend did in fact stop working (thinkpad t60), but there was nothing catastrophic. Here's the dmesg if somebody is interested:

Quoted 11 lines

Suspending console(s)
usb_endpoint usbdev5.3_ep83: PM: suspend 0->2, parent 5-2:1.0 already 2 usb_endpoint usbdev5.3_ep02: PM: suspend 0->2, parent 5-2:1.0 already 2 usb_endpoint usbdev5.3_ep81: PM: suspend 0->2, parent 5-2:1.0 already 2 hub 2-0:1.0: suspend error -16
suspend_device(): usb_suspend+0x0/0x1c() returns -16
Could not suspend device usb2: error -16
usb_endpoint usbdev5.3_ep81: PM: resume from 0, parent 5-2:1.0 still 2 usb_endpoint usbdev5.3_ep02: PM: resume from 0, parent 5-2:1.0 still 2 usb_endpoint usbdev5.3_ep83: PM: resume from 0, parent 5-2:1.0 still 2 Some devices failed to suspend

Remember what I wrote a few minutes ago about khubd and ksuspend_usbd wanting to resume devices during a system suspend transition? This is exactly what happens when those threads aren't frozen.

Alan Stern

#652 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 3 lines · Alan Stern

Okay, I agree that (1) can be handled without too much effort. But doing it adds an extra test to _every_ driver's I/O pathway. Freezing userspace does not incur all this additional overhead.

For runtime PM to work it's already necessary to have a test in that path to check if the device is suspended. I can't see how this adds any overhead to the common case.

Actually it isn't necessary to have a test to check if the device is suspended. We simply call the autoresume routine; if the device isn't suspended that routine doesn't have to do anything.

I agree that that the extra test (for system-wide suspend underway) is needed only if the autoresume fails, which isn't part of the main pathway. So it doesn't add runtime overhead -- but handling it does add code overhead.

Alan Stern

#653 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 3 lines · Alan Stern

Okay, I agree that (1) can be handled without too much effort. But doing it adds an extra test to _every_ driver's I/O pathway. Freezing userspace does not incur all this additional overhead.

For runtime PM to work it's already necessary to have a test in that path to check if the device is suspended. I can't see how this adds any overhead to the common case.

Actually it isn't necessary to have a test to check if the device is suspended. We simply call the autoresume routine; if the device isn't suspended that routine doesn't have to do anything.

I agree that that the extra test (for system-wide suspend underway) is needed only if the autoresume fails, which isn't part of the main pathway. So it doesn't add runtime overhead -- but handling it does add code overhead.

Alan Stern

#592 lore raw
In reply to Alan Stern
Quoted 12 lines · Alan Stern
Quoted 7 lines

Threads that do no I/O at all don't care about suspend/resume and don't need to be frozen in any case. Threads that issue I/O requests in order to service incoming I/O requests can't be frozen because of the possibility of deadlock. Which leaves threads that do I/O just for the fun of it. :)

What am I missing?

Those two threads will try to resume USB devices in response to wakeup requests. Such requests arrive during a suspend or resume transition more often than one would expect.

Quoted 7 lines

If the resume attempt occurs before the host controller has been suspended, it will abort the system suspend. If it occurs after the host controller is suspended (and before the controller resumes) it will fail and try to unregister the USB device -- something else we don't like happening while the sytem is only partially up (not to mention the annoyance caused by the unregistration of a perfectly functional device).

Actually the situation may not be quite this bad any more. It's been a while since I tried suspending a system without freezing khubd and ksuspend_usbd. But Miklos's mail shows that problems can and will occur.

Alan Stern

#593 lore raw
In reply to Alan Stern
Quoted 12 lines · Alan Stern
Quoted 7 lines

Threads that do no I/O at all don't care about suspend/resume and don't need to be frozen in any case. Threads that issue I/O requests in order to service incoming I/O requests can't be frozen because of the possibility of deadlock. Which leaves threads that do I/O just for the fun of it. :)

What am I missing?

Those two threads will try to resume USB devices in response to wakeup requests. Such requests arrive during a suspend or resume transition more often than one would expect.

Quoted 7 lines

If the resume attempt occurs before the host controller has been suspended, it will abort the system suspend. If it occurs after the host controller is suspended (and before the controller resumes) it will fail and try to unregister the USB device -- something else we don't like happening while the sytem is only partially up (not to mention the annoyance caused by the unregistration of a perfectly functional device).

Actually the situation may not be quite this bad any more. It's been a while since I tried suspending a system without freezing khubd and ksuspend_usbd. But Miklos's mail shows that problems can and will occur.

Alan Stern

#608 lore raw
In reply to Alan Stern
Quoted 3 lines

Remember what I wrote a few minutes ago about khubd and ksuspend_usbd wanting to resume devices during a system suspend transition? This is exactly what happens when those threads aren't frozen.

OK, let me summarize the situation as I see it now: there are two camps, the pro-freezers and the anti-freezers.

Pro-freezers say:

- don't remove the freezer, otherwise we'll have to deal with numerous problems in drivers

Anti-freezers say:

- let's remove the freezer, which causes numerous problems

Alan summerized the pro-freezer arguments well I think. What are the anti-freezer arguments then?

After having looked at the freezer and done some experiments with it, the most obvious problem looks to be, that it can get stuck on a process doing uninterruptible sleep. And yes, this can happen if a fuse filesystem daemon is frozen before a filesystem user is. And this is not something that can be fixed in fuse, some filesystem calls (rename(2) for example) are simply not restartable.

This doesn't explain the deadlocks, but it could cause failure to suspend which would be pretty annoying.

Does this affect other things than fuse?

Can this be fixed?

It seems to be a fundamental problem with the freezer: while it does make sure that user processes are not calling into drivers during suspend, it also disallows perfectly harmless non-driver calls as well.

Miklos

#609 lore raw
In reply to Alan Stern
Quoted 3 lines

Remember what I wrote a few minutes ago about khubd and ksuspend_usbd wanting to resume devices during a system suspend transition? This is exactly what happens when those threads aren't frozen.

OK, let me summarize the situation as I see it now: there are two camps, the pro-freezers and the anti-freezers.

Pro-freezers say:

- don't remove the freezer, otherwise we'll have to deal with numerous problems in drivers

Anti-freezers say:

- let's remove the freezer, which causes numerous problems

Alan summerized the pro-freezer arguments well I think. What are the anti-freezer arguments then?

After having looked at the freezer and done some experiments with it, the most obvious problem looks to be, that it can get stuck on a process doing uninterruptible sleep. And yes, this can happen if a fuse filesystem daemon is frozen before a filesystem user is. And this is not something that can be fixed in fuse, some filesystem calls (rename(2) for example) are simply not restartable.

This doesn't explain the deadlocks, but it could cause failure to suspend which would be pretty annoying.

Does this affect other things than fuse?

Can this be fixed?

It seems to be a fundamental problem with the freezer: while it does make sure that user processes are not calling into drivers during suspend, it also disallows perfectly harmless non-driver calls as well.

Miklos

#610 lore raw
Quoted 11 lines · Miklos Szeredi
Quoted 3 lines

Remember what I wrote a few minutes ago about khubd and ksuspend_usbd wanting to resume devices during a system suspend transition? This is exactly what happens when those threads aren't frozen.

OK, let me summarize the situation as I see it now: there are two camps, the pro-freezers and the anti-freezers.

Pro-freezers say:

- don't remove the freezer, otherwise we'll have to deal with numerous problems in drivers

And these problems will generally be difficult to reproduce reliably and debug.

Quoted 10 lines

Anti-freezers say:

- let's remove the freezer, which causes numerous problems

Alan summerized the pro-freezer arguments well I think. What are the anti-freezer arguments then?

After having looked at the freezer and done some experiments with it, the most obvious problem looks to be, that it can get stuck on a process doing uninterruptible sleep.

That's correct.

Quoted 6 lines

And yes, this can happen if a fuse filesystem daemon is frozen before a filesystem user is. And this is not something that can be fixed in fuse, some filesystem calls (rename(2) for example) are simply not restartable.

This doesn't explain the deadlocks, but it could cause failure to suspend which would be pretty annoying.

I think the only thing that can deadlock in that context is the sync. At least, I don't see anything else.

Quoted 1 line

Does this affect other things than fuse?

Not that I know of. It may affect user space drivers, but there's no data on that.

Quoted 6 lines

Can this be fixed?

It seems to be a fundamental problem with the freezer: while it does make sure that user processes are not calling into drivers during suspend, it also disallows perfectly harmless non-driver calls as well.

The problem is that when the freezer was designed (I didn't do that, BTW), there was no FUSE and similar things, so it's not prepared to cope with such interdependencies between user space tasks.

We had an analogous problem with vfork() and it was solved by using the PF_FREEZER_SKIP flag. Perhaps we can do similar thing with FUSE.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#307 lore raw

The big suspend mess

In reply to Paul Mackerras
Quoted 8 lines · Paul Mackerras
Quoted 3 lines · Rafael J. Wysocki

Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?

The basis is that it (the freezer) causes more deadlocks and other problems than it avoids, so it's a net win to remove it.

You forget one important point:
Regressions are much worse than normal bugs.

It's not about the question whether the driver was "correct" or "buggy" - for a user the important question is whether it worked in practice, and if yes, whether it continues to work.

And my impression is that every time someone touches some part of the suspend code some drivers break.

During 2.6.21-rc, it wasn't unusual for users to run with one kernel into up to three distinct suspend regressions on one machine.

And no, it wasn't always the same set of distinct regressions.

IMHO the suspend code is currently way too much of a moving target which results in this mess.

The correct order seems to be:
1. agree on what the suspend code as a whole should look like
2. implement this
3. fix ALL drivers to work at least as good as they do today
4. get it tested in -mm
5. fix all bugs people run into
6. submit it for inclusion in Linus' tree
7. quickly work on the most likely big amount of bug reports

Step 1 is the most important one - evolving code is often something good, but in this case with different people trying to evolve the suspend code in different directions it simply results in a big mess.

Quoted 1 line

Paul.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#322 lore raw

The big suspend mess

In reply to Paul Mackerras
Quoted 8 lines · Paul Mackerras
Quoted 3 lines · Rafael J. Wysocki

Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?

The basis is that it (the freezer) causes more deadlocks and other problems than it avoids, so it's a net win to remove it.

You forget one important point:
Regressions are much worse than normal bugs.

It's not about the question whether the driver was "correct" or "buggy" - for a user the important question is whether it worked in practice, and if yes, whether it continues to work.

And my impression is that every time someone touches some part of the suspend code some drivers break.

During 2.6.21-rc, it wasn't unusual for users to run with one kernel into up to three distinct suspend regressions on one machine.

And no, it wasn't always the same set of distinct regressions.

IMHO the suspend code is currently way too much of a moving target which results in this mess.

The correct order seems to be:
1. agree on what the suspend code as a whole should look like
2. implement this
3. fix ALL drivers to work at least as good as they do today
4. get it tested in -mm
5. fix all bugs people run into
6. submit it for inclusion in Linus' tree
7. quickly work on the most likely big amount of bug reports

Step 1 is the most important one - evolving code is often something good, but in this case with different people trying to evolve the suspend code in different directions it simply results in a big mess.

Quoted 1 line

Paul.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#654 lore raw
In reply to Matthew Garrett

Hi!

Quoted 8 lines

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Sorry, no.

* this needs audit of all drivers. Or we can just merge it and then fix all the problems it causes. If you are willing to become suspend maintainer and handle all that mess, perhaps we can do this.

* it does not solve FUSE vs. hibernation

* it does not solve FUSE vs. suspend-to-both

* userspace will now see CPUs going up and down at minimum

Now, we want to do something like this long-term, but I do not think we can just remove the freezer like this.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#655 lore raw
In reply to Matthew Garrett

Hi!

Quoted 8 lines

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Sorry, no.

* this needs audit of all drivers. Or we can just merge it and then fix all the problems it causes. If you are willing to become suspend maintainer and handle all that mess, perhaps we can do this.

* it does not solve FUSE vs. hibernation

* it does not solve FUSE vs. suspend-to-both

* userspace will now see CPUs going up and down at minimum

Now, we want to do something like this long-term, but I do not think we can just remove the freezer like this.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#481 lore raw
In reply to Oliver Neukum
Quoted 25 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:

Quoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Matthew Garrett
Quoted 6 lines

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

Greetings,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

Quoted 8 lines
Quoted 2 lines

We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.

This seems fishy. Swsusp needs enough clean memory to make enough room for the image. If you sync before you freeze, the running tasks can redirty memory.
What makes you sure that you don't die as shrink_all_memory() writes out pages?

Shrink_all_memory should just free enough memory, what's the problem? Yes, we can have dirty memory, shrink_all_memory() can write that out just fine.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#482 lore raw
In reply to Oliver Neukum
Quoted 25 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:

Quoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Matthew Garrett
Quoted 6 lines

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

Greetings,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

Quoted 8 lines
Quoted 2 lines

We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.

This seems fishy. Swsusp needs enough clean memory to make enough room for the image. If you sync before you freeze, the running tasks can redirty memory.
What makes you sure that you don't die as shrink_all_memory() writes out pages?

Shrink_all_memory should just free enough memory, what's the problem? Yes, we can have dirty memory, shrink_all_memory() can write that out just fine.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#507 lore raw
In reply to Oliver Neukum
Quoted 6 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Miklos Szeredi:

Quoted 5 lines
Quoted 2 lines

And a further question. The freezer is not atomic. What do you do if a task not yet frozen calls sys_sync(), but fuse is already frozen?

What do you do if a task not yet frozen writes to a pipe, on the other end of which is a task already frozen?

There's some difference between uninterruptible and interruptible sleep I'd say.

Quoted 6 lines
Quoted 3 lines

It doesn't matter. The only thing that should matter during suspend (not hibernate) is saving the state of devices to ram, and putting the devices to sleep.

Well, but you did remove sys_sync() from the freezer, which is and must be called in the hibernate path.

Not "must". In fact, hibernation should be safe without sys_sync(). It is just user un-friendly.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#508 lore raw
In reply to Oliver Neukum
Quoted 6 lines · Oliver Neukum

Am Dienstag, 3. Juli 2007 schrieb Miklos Szeredi:

Quoted 5 lines
Quoted 2 lines

And a further question. The freezer is not atomic. What do you do if a task not yet frozen calls sys_sync(), but fuse is already frozen?

What do you do if a task not yet frozen writes to a pipe, on the other end of which is a task already frozen?

There's some difference between uninterruptible and interruptible sleep I'd say.

Quoted 6 lines
Quoted 3 lines

It doesn't matter. The only thing that should matter during suspend (not hibernate) is saving the state of devices to ram, and putting the devices to sleep.

Well, but you did remove sys_sync() from the freezer, which is and must be called in the hibernate path.

Not "must". In fact, hibernation should be safe without sys_sync(). It is just user un-friendly.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#26 lore raw
In reply to Miklos Szeredi

Hi!

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

Quoted 8 lines
Quoted 5 lines

The problem is not with fuse. The problem is generic in nature.

If you remove the freezer, user space remains active until the last CPU goes into suspend. It can do syscalls. Or do you know a clean way to exempt only the tasks fuse might use?

You are talking about hibernate, right? Suspending (to ram) is instantaneous, in that _after_ suspend no CPU is active obviously.

No, suspend to ram is not instantaneous.

We may have 16 cpus, and we may have 250 disks that need to be spun down. That takes time, and is really not atomic operation.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#27 lore raw
In reply to Miklos Szeredi

Hi!

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

I don't claim to know anything about how STR or hibernate works, but neither seem to have any problem with I/O on the fuse device "racing" with them.

Quoted 8 lines
Quoted 5 lines

The problem is not with fuse. The problem is generic in nature.

If you remove the freezer, user space remains active until the last CPU goes into suspend. It can do syscalls. Or do you know a clean way to exempt only the tasks fuse might use?

You are talking about hibernate, right? Suspending (to ram) is instantaneous, in that _after_ suspend no CPU is active obviously.

No, suspend to ram is not instantaneous.

We may have 16 cpus, and we may have 250 disks that need to be spun down. That takes time, and is really not atomic operation.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#464 lore raw
In reply to Benjamin Herrenschmidt

Hi!

Quoted 6 lines

So I think Matthew is totally right. In fact, the presence of the freezer is the main reason why Paulus so far NACKed Johannes attempts at merging the PPC PM code with the generic code in kernel/power.c

We've been doing fine without it so far and intend to continue to do so.

How well does it work on SMP PPC?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#465 lore raw
In reply to Benjamin Herrenschmidt

Hi!

Quoted 6 lines

So I think Matthew is totally right. In fact, the presence of the freezer is the main reason why Paulus so far NACKed Johannes attempts at merging the PPC PM code with the generic code in kernel/power.c

We've been doing fine without it so far and intend to continue to do so.

How well does it work on SMP PPC?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#297 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

This is incompatible with the code in kernel/power/main.c, since we only disable the nonboot CPUs after devices have been suspended. Do you think that your framework can be modified to work without disabling the nonboot CPUs by the user space?

Sure. It was a "if it can be done in userspace, do it in userspace" kind of decision, but I'm not wedded to it.

I actually do want to converge to using the generic suspend-to-ram code on powerbooks. I just want to avoid causing regressions for powerbook users, including myself. :)

Paul.

#93 lore raw
In reply to Alan Stern
Quoted 1 line · Alan Stern

Let's agree the kernel threads and the freezer are a separate issue.

No, I don't think they are a separate issue, because I think the distinction the freezer makes between kernel threads and user threads is a false and misleading distinction.

Quoted 2 lines

In the most recent kernels, the freezer does not suspend kernel threads by default.

And therefore doesn't guarantee that drivers won't get I/O requests after being suspended, as far as I can see...

Quoted 6 lines

I agree the kernel threads which try to do I/O during a suspend will need extra attention. However if these threads are necessary for the suspend procedure, then blocking them (which is how people on this thread have been saying driver should treat I/O requests during a suspend) will cause additional problems. There's no way around it; these threads _will_ require more work.

There is a way around it; do the request blocking in the drivers, where it belongs.

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

The reasons why the PPC people dislike the whole idea aren't clear to me.

Our experience is that it isn't necessary. It's extra code that in practice causes deadlocks and added maintenance burden for no discernable benefit.

I have discussed the benefits elsewhere. As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks. Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

The "don't freeze kernel threads" thing is an attempt to make a crude approximation to the dependency graph (by saying kernel threads only depend on other kernel threads), but the approximation breaks down when you have FUSE or user-level device drivers.

Quoted 3 lines

Userspace cannot do I/O directly on its own, apart from some exceptional situations where a privileged task directly twiddles some I/O ports or the equivalent.

Userspace can be involved in servicing I/O requests; not just FUSE, but also user-level nfsd and user-level PPP demonstrate that.

Quoted 6 lines

There remains the problem of user tasks whose assistance is required to carry out some I/O (as with FUSE). If the I/O can be deferred until after the resume, then there's no problem. If the I/O can be carried out before the suspend, then it should be. And finally, if the I/O must be done during the suspend, you're in real trouble -- how do you do I/O to a suspended device?

So why doesn't that argument apply to kernel threads? :)

Quoted 10 lines
Quoted 5 lines

I remain convinced that the right approach is to fix the drivers to do one of two things; either do something in the suspend call to block further requests to the device, or use a late-suspend call to put their device into a low-power state. Of course, correctly-written frameworks can do a lot to help the chipset drivers here.

The first alternative is a possibility. My argument all along has been that it is difficult and error-prone, and it adds more overhead to system operation (even when not suspending!) than simply freezing userspace.

It does actually provably solve the problem though, which is more than the freezer does.

Paul.

#298 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

This is incompatible with the code in kernel/power/main.c, since we only disable the nonboot CPUs after devices have been suspended. Do you think that your framework can be modified to work without disabling the nonboot CPUs by the user space?

Sure. It was a "if it can be done in userspace, do it in userspace" kind of decision, but I'm not wedded to it.

I actually do want to converge to using the generic suspend-to-ram code on powerbooks. I just want to avoid causing regressions for powerbook users, including myself. :)

Paul.

#308 lore raw

Re: The big suspend mess

In reply to Adrian Bunk
Quoted 5 lines

IMHO the suspend code is currently way too much of a moving target which results in this mess.

The correct order seems to be:

0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)

Quoted 11 lines

1. agree on what the suspend code as a whole should look like
2. implement this
3. fix ALL drivers to work at least as good as they do today
4. get it tested in -mm
5. fix all bugs people run into
6. submit it for inclusion in Linus' tree
7. quickly work on the most likely big amount of bug reports

Step 1 is the most important one - evolving code is often something good, but in this case with different people trying to evolve the suspend code in different directions it simply results in a big mess.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#309 lore raw

Re: The big suspend mess

In reply to Adrian Bunk
Quoted 5 lines

IMHO the suspend code is currently way too much of a moving target which results in this mess.

The correct order seems to be:

0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)

Quoted 11 lines

1. agree on what the suspend code as a whole should look like
2. implement this
3. fix ALL drivers to work at least as good as they do today
4. get it tested in -mm
5. fix all bugs people run into
6. submit it for inclusion in Linus' tree
7. quickly work on the most likely big amount of bug reports

Step 1 is the most important one - evolving code is often something good, but in this case with different people trying to evolve the suspend code in different directions it simply results in a big mess.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#71 lore raw
In reply to Alan Stern
Quoted 3 lines · Alan Stern

That's not what I'm saying. What I'm saying is that it would be a big mistake to force all drivers which implement runtime PM to do it using a separate code path from system PM.

OK; I can accept that provided there is a way to change the "what to do with an I/O request" policy from auto-resume to something else while we're suspending the system (and presumably restore the old policy on system resume if the device was runtime-suspended at the point where the system was suspended).

Quoted 9 lines
Quoted 3 lines

The main attraction of the late-suspend call is that it really does, reliably, guarantee that the driver's I/O request methods won't get called between the late-suspend call and the early-resume call.

For some drivers (like USB), carrying out an actual suspend requires a delay. Right now we implement those delays using wait_event(), wait_for_completion(), and so on. Would you have us check at runtime whether or not a system suspend is underway and in each case use a busy-loop instead if it is?

No; the late suspend call isn't appropriate for all drivers. It is a simple and safe way to do the suspend for some drivers, mostly the simpler ones. Things that are complex enough to have a subsystem (e.g. USB) would want to use the early suspend call.

Quoted 4 lines

What happens if, in order to carry out the late-suspend, a driver needs to acquire a mutex which happens to be held by some other task? That other task won't be able to run and release the mutex, so you will deadlock.

Then late-suspend is not appropriate for that driver, and it needs to use the early-suspend call, and do something such as setting a flag that the I/O request function tests.

Paul.

#601 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

They will not trigger 100% of the time, but sporadically and generally at random.

At least the freezer problems are reproducible. ;-)

Our experience with powermacs has been that it isn't actually all that hard to get it right for the drivers you care about.

Paul.

#253 lore raw
In reply to Alan Stern
Quoted 9 lines · Alan Stern
Quoted 7 lines
Quoted 3 lines

Yes, the code could be changed to keep track of the reason for a device suspend. But that just raises the old problem of what to do when there's an I/O request for a suspended device during STR.

Is this actually a real problem? I would think the policy would be "block" for block devices (pun not intended :), "drop" for network devices, etc.

It is indeed a real problem, or at least, it can be.

How so? Can you give me an example?

Quoted 4 lines
Quoted 2 lines

How did the device get suspended if it didn't have a driver? If it did have a driver, why didn't the bind attempt fail?

Bus subsystems can suspend devices with no drivers.

Interesting. I assume this is for buses for which there is a bus-specific but device-independent suspend procedure defined.

It would seem sensible to me that the PM core should get the bus to resume such a device before calling a driver probe routine. The resume should be blocked or deferred while a system suspend is underway. In fact I think that all driver bind/unbind and probe operations should be deferred while the system is suspending (i.e. put on a list to be done after the system resumes).

Quoted 3 lines

It would help. It would help even more if the sysfs core also blocked all I/O while suspend is under way. (Although this might be tricky, considering that the suspend is initiated by a sysfs write...)

I didn't think sysfs got involved at all in normal read and write requests, so I don't know how it would block them...

Quoted 11 lines

The fact remains that lots of drivers would still need to be changed. In the read and write methods someone would have to add code amounting to this:

	if (suspend_is_under_way()) {
		mutex_unlock(...);
		block_until_resume();
		goto restart;
	}

Freezing userspace is a small amount of code by comparison.

Normally devices have some sort of queue of pending operations. So all that is required on suspend is to stop processing the queue and wait for any currently-underway operations to complete. The blocking then happens naturally using the normal I/O wait mechanisms.

Paul.

#623 lore raw
In reply to Alan Stern
Quoted 3 lines · Alan Stern

Remember what I wrote a few minutes ago about khubd and ksuspend_usbd wanting to resume devices during a system suspend transition? This is exactly what happens when those threads aren't frozen.

So, I wonder why I don't see that error on my powerbook?

Paul.

#619 lore raw
In reply to Miklos Szeredi
Quoted 8 lines · Miklos Szeredi

OK, let me summarize the situation as I see it now: there are two camps, the pro-freezers and the anti-freezers.

Pro-freezers say:

- don't remove the freezer, otherwise we'll have to deal with numerous problems in drivers

Quoted 6 lines

Anti-freezers say:

- let's remove the freezer, which causes numerous problems

Alan summerized the pro-freezer arguments well I think. What are the anti-freezer arguments then?

1. The freezer cannot be guaranteed deadlock-free without constructing a dependency graph between tasks (both user and kernel), which is virtually impossible since the dependencies are not externally observable.

2. As a consequence of (1), we try to make a crude approximation of the graph by saying "only kernel threads that want to be frozen will be frozen" or some other similar statement.

3. However, (2) means that we can no longer guarantee that drivers will not get any I/O requests after their suspend method has been called, and therefore the freezer fails in its main objective.

4. We have an existence proof that reliable suspend can be achieved without the freezer.

To summarize, the argument is that the freezer is deadlock-prone and ineffective.

Paul.

#620 lore raw
In reply to Miklos Szeredi
Quoted 8 lines · Miklos Szeredi

OK, let me summarize the situation as I see it now: there are two camps, the pro-freezers and the anti-freezers.

Pro-freezers say:

- don't remove the freezer, otherwise we'll have to deal with numerous problems in drivers

Quoted 6 lines

Anti-freezers say:

- let's remove the freezer, which causes numerous problems

Alan summerized the pro-freezer arguments well I think. What are the anti-freezer arguments then?

1. The freezer cannot be guaranteed deadlock-free without constructing a dependency graph between tasks (both user and kernel), which is virtually impossible since the dependencies are not externally observable.

2. As a consequence of (1), we try to make a crude approximation of the graph by saying "only kernel threads that want to be frozen will be frozen" or some other similar statement.

3. However, (2) means that we can no longer guarantee that drivers will not get any I/O requests after their suspend method has been called, and therefore the freezer fails in its main objective.

4. We have an existence proof that reliable suspend can be achieved without the freezer.

To summarize, the argument is that the freezer is deadlock-prone and ineffective.

Paul.

#602 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

They will not trigger 100% of the time, but sporadically and generally at random.

At least the freezer problems are reproducible. ;-)

Our experience with powermacs has been that it isn't actually all that hard to get it right for the drivers you care about.

Paul.

#72 lore raw
In reply to Alan Stern
Quoted 3 lines · Alan Stern

That's not what I'm saying. What I'm saying is that it would be a big mistake to force all drivers which implement runtime PM to do it using a separate code path from system PM.

OK; I can accept that provided there is a way to change the "what to do with an I/O request" policy from auto-resume to something else while we're suspending the system (and presumably restore the old policy on system resume if the device was runtime-suspended at the point where the system was suspended).

Quoted 9 lines
Quoted 3 lines

The main attraction of the late-suspend call is that it really does, reliably, guarantee that the driver's I/O request methods won't get called between the late-suspend call and the early-resume call.

For some drivers (like USB), carrying out an actual suspend requires a delay. Right now we implement those delays using wait_event(), wait_for_completion(), and so on. Would you have us check at runtime whether or not a system suspend is underway and in each case use a busy-loop instead if it is?

No; the late suspend call isn't appropriate for all drivers. It is a simple and safe way to do the suspend for some drivers, mostly the simpler ones. Things that are complex enough to have a subsystem (e.g. USB) would want to use the early suspend call.

Quoted 4 lines

What happens if, in order to carry out the late-suspend, a driver needs to acquire a mutex which happens to be held by some other task? That other task won't be able to run and release the mutex, so you will deadlock.

Then late-suspend is not appropriate for that driver, and it needs to use the early-suspend call, and do something such as setting a flag that the I/O request function tests.

Paul.

#624 lore raw
In reply to Alan Stern
Quoted 3 lines · Alan Stern

Remember what I wrote a few minutes ago about khubd and ksuspend_usbd wanting to resume devices during a system suspend transition? This is exactly what happens when those threads aren't frozen.

So, I wonder why I don't see that error on my powerbook?

Paul.

#466 lore raw
In reply to Pavel Machek
Quoted 1 line · Pavel Machek

How well does it work on SMP PPC?

Just fine, on those machines where we know how to reinitialize the video card. We currently require userspace to offline all except the boot cpu before suspending, but that could be moved into the kernel. I have no particular attachment to that way of doing it; it was just a "don't do things in the kernel that can be reasonably be done in userspace" kind of thing.

Paul.

#467 lore raw
In reply to Pavel Machek
Quoted 1 line · Pavel Machek

How well does it work on SMP PPC?

Just fine, on those machines where we know how to reinitialize the video card. We currently require userspace to offline all except the boot cpu before suspending, but that could be moved into the kernel. I have no particular attachment to that way of doing it; it was just a "don't do things in the kernel that can be reasonably be done in userspace" kind of thing.

Paul.

#310 lore raw

Re: The big suspend mess

In reply to Pavel Machek
Quoted 2 lines · Pavel Machek

0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)

I thought that was Rafael?

Paul.

#311 lore raw

Re: The big suspend mess

In reply to Pavel Machek
Quoted 2 lines · Pavel Machek

0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)

I thought that was Rafael?

Paul.

#317 lore raw

Re: The big suspend mess

In reply to Pavel Machek
Quoted 8 lines · Pavel Machek
Quoted 5 lines

IMHO the suspend code is currently way too much of a moving target which results in this mess.

The correct order seems to be:

0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)

The "SOFTWARE SUSPEND" entry in MAINTAINERS already contains a victim... ;-)

My impression is that suspend is an area of the kernel that does not lack maintainers - you and Rafael are doing a good job, and there's e.g. also the maintained code formerly known as suspend2.

But some basic questions like e.g.
- What should be done in the kernel and what in userspace?
- How should this be implemented?
- What must subsystems and drivers do?
- What must subsystems and drivers not do?
seem to be in a constant flux because the big picture everyone agrees upon seems to be missing.

Quoted 8 lines
Quoted 8 lines

1. agree on what the suspend code as a whole should look like
2. implement this
3. fix ALL drivers to work at least as good as they do today
4. get it tested in -mm
5. fix all bugs people run into
6. submit it for inclusion in Linus' tree
7. quickly work on the most likely big amount of bug reports

Quoted 5 lines
Quoted 3 lines

Step 1 is the most important one - evolving code is often something good, but in this case with different people trying to evolve the suspend code in different directions it simply results in a big mess.

Pavel

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#320 lore raw

Re: The big suspend mess

In reply to Pavel Machek
Quoted 8 lines · Pavel Machek
Quoted 5 lines

IMHO the suspend code is currently way too much of a moving target which results in this mess.

The correct order seems to be:

0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)

The "SOFTWARE SUSPEND" entry in MAINTAINERS already contains a victim... ;-)

My impression is that suspend is an area of the kernel that does not lack maintainers - you and Rafael are doing a good job, and there's e.g. also the maintained code formerly known as suspend2.

But some basic questions like e.g.
- What should be done in the kernel and what in userspace?
- How should this be implemented?
- What must subsystems and drivers do?
- What must subsystems and drivers not do?
seem to be in a constant flux because the big picture everyone agrees upon seems to be missing.

Quoted 8 lines
Quoted 8 lines

1. agree on what the suspend code as a whole should look like
2. implement this
3. fix ALL drivers to work at least as good as they do today
4. get it tested in -mm
5. fix all bugs people run into
6. submit it for inclusion in Linus' tree
7. quickly work on the most likely big amount of bug reports

Quoted 5 lines
Quoted 3 lines

Step 1 is the most important one - evolving code is often something good, but in this case with different people trying to evolve the suspend code in different directions it simply results in a big mess.

Pavel

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#483 lore raw
In reply to Pavel Machek

Am Donnerstag, 5. Juli 2007 schrieb Pavel Machek:

Quoted 35 lines · Oliver Neukum
Quoted 25 lines

Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:

Quoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Matthew Garrett
Quoted 6 lines

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

Greetings,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

Quoted 8 lines
Quoted 2 lines

We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.

This seems fishy. Swsusp needs enough clean memory to make enough room for the image. If you sync before you freeze, the running tasks can redirty memory.
What makes you sure that you don't die as shrink_all_memory() writes out pages?

Quoted 3 lines

Shrink_all_memory should just free enough memory, what's the problem? Yes, we can have dirty memory, shrink_all_memory() can write that out just fine.

If there's any dirty memory to be written out through fuse, this will not work as user space is already frozen. Now I am told that with fuse writes are synchronous. Therefore I don't understand why having a call to sys_sync() can make a difference. IMHO removing it to make fuse work covers over a symptom but hides the bug.

Regards
Oliver

#484 lore raw
In reply to Pavel Machek

Am Donnerstag, 5. Juli 2007 schrieb Pavel Machek:

Quoted 35 lines · Oliver Neukum
Quoted 25 lines

Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:

Quoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Matthew Garrett
Quoted 6 lines

Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.

Quoted 4 lines
Quoted 2 lines

The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.

So why don't we remove the sys_sync() from freeze_processes() instead?

The patch follows (untested).

Greetings,
Rafael

---
From: Rafael J. Wysocki <[email protected]>

Quoted 8 lines
Quoted 2 lines

We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.

This seems fishy. Swsusp needs enough clean memory to make enough room for the image. If you sync before you freeze, the running tasks can redirty memory.
What makes you sure that you don't die as shrink_all_memory() writes out pages?

Quoted 3 lines

Shrink_all_memory should just free enough memory, what's the problem? Yes, we can have dirty memory, shrink_all_memory() can write that out just fine.

If there's any dirty memory to be written out through fuse, this will not work as user space is already frozen. Now I am told that with fuse writes are synchronous. Therefore I don't understand why having a call to sys_sync() can make a difference. IMHO removing it to make fuse work covers over a symptom but hides the bug.

Regards
Oliver

#94 lore raw
In reply to Paul Mackerras

Am Donnerstag, 5. Juli 2007 schrieb Paul Mackerras:

Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

Regards
Oliver

#95 lore raw
In reply to Paul Mackerras

Am Donnerstag, 5. Juli 2007 schrieb Paul Mackerras:

Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

Regards
Oliver

#96 lore raw
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

- process A calls rename() on a fuse fs
- process B, the fuse server, starts to process the rename request
- process B is frozen before it can reply

Now process A is unfreezable. We cannot make rename() restartable, hence it cannot be interruptible.

Miklos

#97 lore raw
In reply to Oliver Neukum
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

- process A calls rename() on a fuse fs
- process B, the fuse server, starts to process the rename request
- process B is frozen before it can reply

Now process A is unfreezable. We cannot make rename() restartable, hence it cannot be interruptible.

Miklos

#98 lore raw

Am Donnerstag, 5. Juli 2007 schrieb Miklos Szeredi:

Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

Quoted 6 lines

 - process A calls rename() on a fuse fs
 - process B, the fuse server, starts to process the rename request
 - process B is frozen before it can reply

Now process A is unfreezable.  We cannot make rename() restartable, hence it cannot be interruptible.

Then this is a problem specific to fuse. You should teach fuse to block suspension while such operations are being performed.

Regards
Oliver

#99 lore raw
In reply to Miklos Szeredi

Am Donnerstag, 5. Juli 2007 schrieb Miklos Szeredi:

Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

Quoted 6 lines

 - process A calls rename() on a fuse fs
 - process B, the fuse server, starts to process the rename request
 - process B is frozen before it can reply

Now process A is unfreezable.  We cannot make rename() restartable, hence it cannot be interruptible.

Then this is a problem specific to fuse. You should teach fuse to block suspension while such operations are being performed.

Regards
Oliver

#611 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines
Quoted 4 lines

Pro-freezers say:

- don't remove the freezer, otherwise we'll have to deal with numerous problems in drivers

And these problems will generally be difficult to reproduce reliably and debug.

I see exactly the opposite.

With the freezer I can have very rarely occuring failures, due to freeze ordering effects.

And without the freezer I have a 100% reproducable problem, that is not hard to fix according to Alan Stern. OK, I don't know what the next problem would be, but the powermac experience shows, that it's not nearly as bad as you and Oliver try to make it out.

Quoted 7 lines
Quoted 6 lines

Can this be fixed?

It seems to be a fundamental problem with the freezer: while it does make sure that user processes are not calling into drivers during suspend, it also disallows perfectly harmless non-driver calls as well.

Quoted 6 lines

The problem is that when the freezer was designed (I didn't do that, BTW), there was no FUSE and similar things, so it's not prepared to cope with such interdependencies between user space tasks.

We had an analogous problem with vfork() and it was solved by using the PF_FREEZER_SKIP flag. Perhaps we can do similar thing with FUSE.

It cannot be just worked around in fuse, as a task might be sleeping on a number of VFS mutexes as well (i_mutex, s_vfs_rename_mutex, etc). It would be a gigantic hack, possible at all.

Miklos

#612 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines
Quoted 4 lines

Pro-freezers say:

- don't remove the freezer, otherwise we'll have to deal with numerous problems in drivers

And these problems will generally be difficult to reproduce reliably and debug.

I see exactly the opposite.

With the freezer I can have very rarely occuring failures, due to freeze ordering effects.

And without the freezer I have a 100% reproducable problem, that is not hard to fix according to Alan Stern. OK, I don't know what the next problem would be, but the powermac experience shows, that it's not nearly as bad as you and Oliver try to make it out.

Quoted 7 lines
Quoted 6 lines

Can this be fixed?

It seems to be a fundamental problem with the freezer: while it does make sure that user processes are not calling into drivers during suspend, it also disallows perfectly harmless non-driver calls as well.

Quoted 6 lines

The problem is that when the freezer was designed (I didn't do that, BTW), there was no FUSE and similar things, so it's not prepared to cope with such interdependencies between user space tasks.

We had an analogous problem with vfork() and it was solved by using the PF_FREEZER_SKIP flag. Perhaps we can do similar thing with FUSE.

It cannot be just worked around in fuse, as a task might be sleeping on a number of VFS mutexes as well (i_mutex, s_vfs_rename_mutex, etc). It would be a gigantic hack, possible at all.

Miklos

#100 lore raw
In reply to Oliver Neukum
Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

 - process A calls rename() on a fuse fs
 - process B, the fuse server, starts to process the rename request
 - process B is frozen before it can reply

Quoted 5 lines
Quoted 2 lines

Now process A is unfreezable.  We cannot make rename() restartable, hence it cannot be interruptible.

Then this is a problem specific to fuse. You should teach fuse to block suspension while such operations are being performed.

And teach VFS to block suspension, while waiting on a mutex held by another process performing a fuse operation.

I can already hear the beautiful praise from Al Viro at the sight of that ;)

Miklos

#101 lore raw
In reply to Oliver Neukum
Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

 - process A calls rename() on a fuse fs
 - process B, the fuse server, starts to process the rename request
 - process B is frozen before it can reply

Quoted 5 lines
Quoted 2 lines

Now process A is unfreezable.  We cannot make rename() restartable, hence it cannot be interruptible.

Then this is a problem specific to fuse. You should teach fuse to block suspension while such operations are being performed.

And teach VFS to block suspension, while waiting on a mutex held by another process performing a fuse operation.

I can already hear the beautiful praise from Al Viro at the sight of that ;)

Miklos

#102 lore raw

Am Donnerstag, 5. Juli 2007 schrieb Miklos Szeredi:

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

 - process A calls rename() on a fuse fs
 - process B, the fuse server, starts to process the rename request
 - process B is frozen before it can reply

Now process A is unfreezable.  We cannot make rename() restartable, hence it cannot be interruptible.

Quoted 8 lines
Quoted 2 lines

Then this is a problem specific to fuse. You should teach fuse to block suspension while such operations are being performed.

And teach VFS to block suspension, while waiting on a mutex held by another process performing a fuse operation.

I can already hear the beautiful praise from Al Viro at the sight of that ;)

There is that.

OK, bite the bullet. Tasks involved in fuse are special. Give them a flag and teach the freezer to put them on ice only after all other task are frozen. In a way they are kernel, there's no use denying that.

Regards
Oliver

#103 lore raw
In reply to Miklos Szeredi

Am Donnerstag, 5. Juli 2007 schrieb Miklos Szeredi:

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

 - process A calls rename() on a fuse fs
 - process B, the fuse server, starts to process the rename request
 - process B is frozen before it can reply

Now process A is unfreezable.  We cannot make rename() restartable, hence it cannot be interruptible.

Quoted 8 lines
Quoted 2 lines

Then this is a problem specific to fuse. You should teach fuse to block suspension while such operations are being performed.

And teach VFS to block suspension, while waiting on a mutex held by another process performing a fuse operation.

I can already hear the beautiful praise from Al Viro at the sight of that ;)

There is that.

OK, bite the bullet. Tasks involved in fuse are special. Give them a flag and teach the freezer to put them on ice only after all other task are frozen. In a way they are kernel, there's no use denying that.

Regards
Oliver

#104 lore raw
Quoted 11 lines
Quoted 5 lines

And teach VFS to block suspension, while waiting on a mutex held by another process performing a fuse operation.

I can already hear the beautiful praise from Al Viro at the sight of that ;)

There is that.

OK, bite the bullet. Tasks involved in fuse are special. Give them a flag and teach the freezer to put them on ice only after all other task are frozen. In a way they are kernel, there's no use denying that.

And flag every other process, that the flagged process is communicating with? How are you proposing to do that?

Quoting Paul:

"1. The freezer cannot be guaranteed deadlock-free without constructing
a dependency graph between tasks (both user and kernel), which is virtually impossible since the dependencies are not externally observable."

Miklos

#105 lore raw
In reply to Oliver Neukum
Quoted 11 lines
Quoted 5 lines

And teach VFS to block suspension, while waiting on a mutex held by another process performing a fuse operation.

I can already hear the beautiful praise from Al Viro at the sight of that ;)

There is that.

OK, bite the bullet. Tasks involved in fuse are special. Give them a flag and teach the freezer to put them on ice only after all other task are frozen. In a way they are kernel, there's no use denying that.

And flag every other process, that the flagged process is communicating with? How are you proposing to do that?

Quoting Paul:

"1. The freezer cannot be guaranteed deadlock-free without constructing
a dependency graph between tasks (both user and kernel), which is virtually impossible since the dependencies are not externally observable."

Miklos

#254 lore raw

removing refrigerator does not help with s2ram vs. fuse deadlocks (was Re: Re: [PATCH] Remove process freezer from suspend to RAM pathway)

In reply to Paul Mackerras

Hi!

Quoted 10 lines
Quoted 10 lines

The fact remains that lots of drivers would still need to be changed. In the read and write methods someone would have to add code amounting to this:

	if (suspend_is_under_way()) {
		mutex_unlock(...);
		block_until_resume();
		goto restart;
	}
Quoted 6 lines
Quoted 1 line

Freezing userspace is a small amount of code by comparison.

Normally devices have some sort of queue of pending operations. So all that is required on suspend is to stop processing the queue and wait for any currently-underway operations to complete. The blocking then happens naturally using the normal I/O wait mechanisms.

So... instead of one big freezer (we know it is problematic), you have 100 small freezers, problematic in same way :-(.

Let's take current FUSE problems, and see if they have problem on PPC, ok?

Let's say FUSE thread touches one of those "blocking" devices. It is now in D state, somewhere in kernel.... exactly same way refrigerator works.

Now, if kernel needs FUSE services for some reason (that's the problem we hit in s2ram case, right?), we have a deadlock.

So main problem still seems to be "kernel should not depend on userland services during suspend", refrigerator or not.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#255 lore raw

removing refrigerator does not help with s2ram vs. fuse deadlocks (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)

In reply to Paul Mackerras

Hi!

Quoted 10 lines
Quoted 10 lines

The fact remains that lots of drivers would still need to be changed. In the read and write methods someone would have to add code amounting to this:

	if (suspend_is_under_way()) {
		mutex_unlock(...);
		block_until_resume();
		goto restart;
	}
Quoted 6 lines
Quoted 1 line

Freezing userspace is a small amount of code by comparison.

Normally devices have some sort of queue of pending operations. So all that is required on suspend is to stop processing the queue and wait for any currently-underway operations to complete. The blocking then happens naturally using the normal I/O wait mechanisms.

So... instead of one big freezer (we know it is problematic), you have 100 small freezers, problematic in same way :-(.

Let's take current FUSE problems, and see if they have problem on PPC, ok?

Let's say FUSE thread touches one of those "blocking" devices. It is now in D state, somewhere in kernel.... exactly same way refrigerator works.

Now, if kernel needs FUSE services for some reason (that's the problem we hit in s2ram case, right?), we have a deadlock.

So main problem still seems to be "kernel should not depend on userland services during suspend", refrigerator or not.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#140 lore raw
In reply to Miklos Szeredi
Quoted 12 lines · Miklos Szeredi
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

Quoted 6 lines

- process A calls rename() on a fuse fs
- process B, the fuse server, starts to process the rename request
- process B is frozen before it can reply

Now process A is unfreezable. We cannot make rename() restartable, hence it cannot be interruptible.

Yes, we are claiming fuse is very special in this regard, and perhaps even broken.

Let's see. If I SIGSTOP the fuse server, I can get unrelated tasks unkillable (even for SIGKILL!) forever. That's very special, and maybe even a FUSE bug. And that is also what makes FUSE special w.r.t. s2ram.

So no, you can't claim "FUSE is just IPC". It is very special IPC.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#141 lore raw
In reply to Miklos Szeredi
Quoted 12 lines · Miklos Szeredi
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

Quoted 6 lines

- process A calls rename() on a fuse fs
- process B, the fuse server, starts to process the rename request
- process B is frozen before it can reply

Now process A is unfreezable. We cannot make rename() restartable, hence it cannot be interruptible.

Yes, we are claiming fuse is very special in this regard, and perhaps even broken.

Let's see. If I SIGSTOP the fuse server, I can get unrelated tasks unkillable (even for SIGKILL!) forever. That's very special, and maybe even a FUSE bug. And that is also what makes FUSE special w.r.t. s2ram.

So no, you can't claim "FUSE is just IPC". It is very special IPC.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#324 lore raw
In reply to Benjamin Herrenschmidt

Hi!

Quoted 11 lines
Quoted 10 lines
Quoted 1 line

- For STR, don't do the freezer thing.

In the long run, I agree.

Still, can you please read this post from Alan Stern:

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

? I don't think I'm able to repeat the arguments given in there in a convincing way.

Quoted 7 lines

That's the same crackpot I've been hearing for the past 3 years or so ...

Both Paulus and I think the freezer is just a way to try to put your head in the sand and ignore the problem. It causes as many problems as it solves on its own, and is just not a solution that will be of any use once you start implementing dynamic PM schemes etc...

Well, yep, you can view freezer as a head in the sand...

Quoted 11 lines

In many cases, having proper support for "live" suspend of devices is just a matter of having a couple of helpers in whatever subsystem those drivers hookup with. In the case of network, for example, it's mostly trivial (stop the queue). For block, it's not terribly hard neither, though you want to have some orderign/atomicity between the blocking of the incoming request queue and the sending of things like spindown & flush commands to the disk. For old-style IDE, that was fairly easily solved by piping suspend/resume command down the request queue itself and have the queue block/unblbock itself after processing them. Some of that logic could maybe be moved to the block layer for all block drivers to benefit.

...but the moment you start blocking tasks that done driver request, you _do_ have mini-freezer of your own, with pretty much the same problems.

In another message I shown that removing freezer will not help with FUSE in general case.

It probably does not help with firmware, too; as soon as udev attempts to do something with your wireless card, it is blocked, and if the wireless card needs the firmware from udev, you are deadlocked.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#325 lore raw
In reply to Benjamin Herrenschmidt

Hi!

Quoted 11 lines
Quoted 10 lines
Quoted 1 line

- For STR, don't do the freezer thing.

In the long run, I agree.

Still, can you please read this post from Alan Stern:

https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html

? I don't think I'm able to repeat the arguments given in there in a convincing way.

Quoted 7 lines

That's the same crackpot I've been hearing for the past 3 years or so ...

Both Paulus and I think the freezer is just a way to try to put your head in the sand and ignore the problem. It causes as many problems as it solves on its own, and is just not a solution that will be of any use once you start implementing dynamic PM schemes etc...

Well, yep, you can view freezer as a head in the sand...

Quoted 11 lines

In many cases, having proper support for "live" suspend of devices is just a matter of having a couple of helpers in whatever subsystem those drivers hookup with. In the case of network, for example, it's mostly trivial (stop the queue). For block, it's not terribly hard neither, though you want to have some orderign/atomicity between the blocking of the incoming request queue and the sending of things like spindown & flush commands to the disk. For old-style IDE, that was fairly easily solved by piping suspend/resume command down the request queue itself and have the queue block/unblbock itself after processing them. Some of that logic could maybe be moved to the block layer for all block drivers to benefit.

...but the moment you start blocking tasks that done driver request, you _do_ have mini-freezer of your own, with pretty much the same problems.

In another message I shown that removing freezer will not help with FUSE in general case.

It probably does not help with firmware, too; as soon as udev attempts to do something with your wireless card, it is blocked, and if the wireless card needs the firmware from udev, you are deadlocked.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#142 lore raw
In reply to Pavel Machek
Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

- process A calls rename() on a fuse fs
- process B, the fuse server, starts to process the rename request
- process B is frozen before it can reply

Quoted 8 lines
Quoted 2 lines

Now process A is unfreezable. We cannot make rename() restartable, hence it cannot be interruptible.

Yes, we are claiming fuse is very special in this regard, and perhaps even broken.

Let's see. If I SIGSTOP the fuse server, I can get unrelated tasks unkillable (even for SIGKILL!) forever.

Actually fuse allows SIGKILL, because it's always fatal, and the syscall may not be restarted.

Quoted 2 lines

That's very special, and maybe even a FUSE bug. And that is also what makes FUSE special w.r.t. s2ram.

What makes fuse special is that some file operations are synchronous and non-restartable. That's just how the UNIX filesystem API works and is hardly a bug in fuse.

Quoted 1 line

So no, you can't claim "FUSE is just IPC". It is very special IPC.

I did say it's special. Sure, it has some "interesting" properties, and with a bit of malice you can do very ugly things with it. If you are interested, read Documentation/filesystems/fuse.txt, especially the "Tricky deadlock" section ;)

Miklos

#312 lore raw

Re: The big suspend mess

In reply to Paul Mackerras
Quoted 6 lines · Paul Mackerras
Quoted 2 lines · Pavel Machek

0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)

I thought that was Rafael?

Rafael is good job trying to fix suspend when he can, but we do not actually have "SUSPEND" entry in MAINTAINERS file.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#143 lore raw
In reply to Pavel Machek
Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

I have discussed the benefits elsewhere.  As for the deadlocks -- do you still observe them if you use the version of the freezer which doesn't freeze kernel threads?

In general the only way to guarantee there are no deadlocks is to construct the graph of dependencies between tasks.  Those dependencies are not in practice observable from outside the tasks, so it is virtually impossible to construct the graph.

In which way can user space tasks depend on each other in a way that allows a them members of that cycle to be in uninterruptible sleep?

- process A calls rename() on a fuse fs
- process B, the fuse server, starts to process the rename request
- process B is frozen before it can reply

Quoted 8 lines
Quoted 2 lines

Now process A is unfreezable. We cannot make rename() restartable, hence it cannot be interruptible.

Yes, we are claiming fuse is very special in this regard, and perhaps even broken.

Let's see. If I SIGSTOP the fuse server, I can get unrelated tasks unkillable (even for SIGKILL!) forever.

Actually fuse allows SIGKILL, because it's always fatal, and the syscall may not be restarted.

Quoted 2 lines

That's very special, and maybe even a FUSE bug. And that is also what makes FUSE special w.r.t. s2ram.

What makes fuse special is that some file operations are synchronous and non-restartable. That's just how the UNIX filesystem API works and is hardly a bug in fuse.

Quoted 1 line

So no, you can't claim "FUSE is just IPC". It is very special IPC.

I did say it's special. Sure, it has some "interesting" properties, and with a bit of malice you can do very ugly things with it. If you are interested, read Documentation/filesystems/fuse.txt, especially the "Tricky deadlock" section ;)

Miklos

#313 lore raw

Re: The big suspend mess

In reply to Paul Mackerras
Quoted 6 lines · Paul Mackerras
Quoted 2 lines · Pavel Machek

0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)

I thought that was Rafael?

Rafael is good job trying to fix suspend when he can, but we do not actually have "SUSPEND" entry in MAINTAINERS file.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html