Skip to contentSkip to conversation

Hibernation considerations

DISCUSSION Rafael J. Wysocki 21 participants 362 messages Jul 15, 2007 – Aug 21, 2007 2 messages not in the archive Page 2 of 2

Subsystems (4)
lore
Share & tools
lore
#198 lore raw
In reply to Alan Stern
Quoted 10 lines · Alan Stern
Quoted 8 lines · Milton Miller
Quoted 3 lines

We can't do this unless we have frozen tasks (this way, or another) before
carrying out the entire operation.

What can't we do? We've already worked with the drivers to quesce the
hardware and put any information to resume the device in ram. Now we ask them to put their device in low power mode so we can go to sleep. Even if we schedule, the only thing userspace could touch is memory.

Quoted 4 lines

Userspace can submit I/O requests. Someone will have to audit every driver to make sure that such I/O requests don't cause a quiesced device to become active. If the device is active, it will make the memory snapshot inconsistent with the on-device data.

If a driver is waking a device between the time it was told by hibernation "suspend all operations and save your device state to ram" and "resume your device" then it is a buggy driver.

I argue the process can make the io request after we write to disk, we just can't service it. If we are suspended it will go to the request queue, and eventually the process will wait for normal throttling mechanisms until the driver is woken up.

It may mean the driver has to set a flag so that it knows it had an iorequest arrive while it was suspended and needs to wake the queue during its resume function.

Actually, my point was more "what kernel services do the drivers need to transition from quiesced to low power for acpi S4 or suspend-to-ram"? We can't give them allocate-memory (but we give them a call "we are going to suspend" when they can), but does "run this tasklet" help? What timer facilities are needed?

Do we need to differentate init (por by bios) and resume from quiesced (for reboot, kexec start/resume)? I hope not.

milton

#199 lore raw
Quoted 12 lines · Milton Miller
Quoted 11 lines · Alan Stern
Quoted 9 lines · Milton Miller
Quoted 3 lines

We can't do this unless we have frozen tasks (this way, or another) before
carrying out the entire operation.

What can't we do? We've already worked with the drivers to quesce
the
hardware and put any information to resume the device in ram. Now we ask them to put their device in low power mode so we can go to sleep. Even if we schedule, the only thing userspace could touch is memory.

Quoted 8 lines
Quoted 4 lines

Userspace can submit I/O requests. Someone will have to audit every driver to make sure that such I/O requests don't cause a quiesced device to become active. If the device is active, it will make the memory snapshot inconsistent with the on-device data.

If a driver is waking a device between the time it was told by hibernation "suspend all operations and save your device state to ram" and "resume your device" then it is a buggy driver.

That's exactly my point. As far as I know nobody has done a survey, but I bet you'd find _many_ drivers are buggy either in this way or the converse (forcing an I/O request to fail immediately instead of waiting until the suspend is over when it could succeed). They have this bug because they were written -- those which include any suspend/resume support at all -- under the assumption that they could rely on the freezer.

And that's why Rafael said "We can't do this unless we have frozen tasks (this way, or another) before carrying out the entire operation." Until the drivers are fixed -- which seems like a tremendous job -- none of this will work.

Quoted 4 lines

I argue the process can make the io request after we write to disk, we just can't service it. If we are suspended it will go to the request queue, and eventually the process will wait for normal throttling mechanisms until the driver is woken up.

Many drivers don't have request queues. Even for the ones that do, there are I/O pathways that bypass the queue (think of ioctl or sysfs).

Quoted 5 lines

Actually, my point was more "what kernel services do the drivers need to transition from quiesced to low power for acpi S4 or suspend-to-ram"? We can't give them allocate-memory (but we give them a call "we are going to suspend" when they can), but does "run this tasklet" help? What timer facilities are needed?

Some drivers need the ability to schedule. Some will need the ability to allocate memory (although GFP_ATOMIC is probably sufficient). Some will need timers to run.

Quoted 2 lines

Do we need to differentate init (por by bios) and resume from quiesced (for reboot, kexec start/resume)? I hope not.

Yes we do.

Alan Stern

#200 lore raw
In reply to Milton Miller
Quoted 12 lines · Milton Miller
Quoted 11 lines · Alan Stern
Quoted 9 lines · Milton Miller
Quoted 3 lines

We can't do this unless we have frozen tasks (this way, or another) before
carrying out the entire operation.

What can't we do? We've already worked with the drivers to quesce
the
hardware and put any information to resume the device in ram. Now we ask them to put their device in low power mode so we can go to sleep. Even if we schedule, the only thing userspace could touch is memory.

Quoted 8 lines
Quoted 4 lines

Userspace can submit I/O requests. Someone will have to audit every driver to make sure that such I/O requests don't cause a quiesced device to become active. If the device is active, it will make the memory snapshot inconsistent with the on-device data.

If a driver is waking a device between the time it was told by hibernation "suspend all operations and save your device state to ram" and "resume your device" then it is a buggy driver.

That's exactly my point. As far as I know nobody has done a survey, but I bet you'd find _many_ drivers are buggy either in this way or the converse (forcing an I/O request to fail immediately instead of waiting until the suspend is over when it could succeed). They have this bug because they were written -- those which include any suspend/resume support at all -- under the assumption that they could rely on the freezer.

And that's why Rafael said "We can't do this unless we have frozen tasks (this way, or another) before carrying out the entire operation." Until the drivers are fixed -- which seems like a tremendous job -- none of this will work.

Quoted 4 lines

I argue the process can make the io request after we write to disk, we just can't service it. If we are suspended it will go to the request queue, and eventually the process will wait for normal throttling mechanisms until the driver is woken up.

Many drivers don't have request queues. Even for the ones that do, there are I/O pathways that bypass the queue (think of ioctl or sysfs).

Quoted 5 lines

Actually, my point was more "what kernel services do the drivers need to transition from quiesced to low power for acpi S4 or suspend-to-ram"? We can't give them allocate-memory (but we give them a call "we are going to suspend" when they can), but does "run this tasklet" help? What timer facilities are needed?

Some drivers need the ability to schedule. Some will need the ability to allocate memory (although GFP_ATOMIC is probably sufficient). Some will need timers to run.

Quoted 2 lines

Do we need to differentate init (por by bios) and resume from quiesced (for reboot, kexec start/resume)? I hope not.

Yes we do.

Alan Stern

#201 lore raw
Quoted 31 lines · Alan Stern
Quoted 12 lines · Milton Miller
Quoted 11 lines · Alan Stern
Quoted 9 lines · Milton Miller
Quoted 3 lines

We can't do this unless we have frozen tasks (this way, or another) before
carrying out the entire operation.

What can't we do? We've already worked with the drivers to quesce
the
hardware and put any information to resume the device in ram. Now we ask them to put their device in low power mode so we can go to sleep. Even if we schedule, the only thing userspace could touch is memory.

Quoted 8 lines
Quoted 4 lines

Userspace can submit I/O requests. Someone will have to audit every driver to make sure that such I/O requests don't cause a quiesced device to become active. If the device is active, it will make the memory snapshot inconsistent with the on-device data.

If a driver is waking a device between the time it was told by hibernation "suspend all operations and save your device state to ram" and "resume your device" then it is a buggy driver.

That's exactly my point. As far as I know nobody has done a survey, but I bet you'd find _many_ drivers are buggy either in this way or the converse (forcing an I/O request to fail immediately instead of waiting until the suspend is over when it could succeed). They have this bug because they were written -- those which include any suspend/resume support at all -- under the assumption that they could rely on the freezer.

Quoted 4 lines

And that's why Rafael said "We can't do this unless we have frozen tasks (this way, or another) before carrying out the entire operation." Until the drivers are fixed -- which seems like a tremendous job -- none of this will work.

So this is in the way of removing the freezer ... but as we are not relying on doing any io other than suspend device operation, save state to ram, then later put device in low power mode for s3 and/or s4, and finally restore and resume to running.

Quoted 7 lines
Quoted 4 lines

I argue the process can make the io request after we write to disk, we just can't service it. If we are suspended it will go to the request queue, and eventually the process will wait for normal throttling mechanisms until the driver is woken up.

Many drivers don't have request queues. Even for the ones that do, there are I/O pathways that bypass the queue (think of ioctl or sysfs).

So its not a flag in make_request, fine.

Quoted 9 lines
Quoted 5 lines

Actually, my point was more "what kernel services do the drivers need to transition from quiesced to low power for acpi S4 or suspend-to-ram"? We can't give them allocate-memory (but we give them a call "we are going to suspend" when they can), but does "run this tasklet" help? What timer facilities are needed?

Some drivers need the ability to schedule. Some will need the ability to allocate memory (although GFP_ATOMIC is probably sufficient). Some will need timers to run.

Can they allocate the memory in advance? (Call them when we know we want to suspend, they make the allocations they will need; we later call them again to release the allocations).

If you need timers, you probably want some scheduling?

Quoted 4 lines
Quoted 2 lines

Do we need to differentate init (por by bios) and resume from quiesced (for reboot, kexec start/resume)? I hope not.

Yes we do.

can you elabrate? Note I was not asking resume-from-low power vs init-from-por. We still get that distinction.

How do these drivers work today when we kexec?

The reason I'm asking is its hard to tell the first kernel what happened. We can say "we powered off, and we were restarted", but it becomes much harder when each device may or may not have a driver in the save kernel if we have to differentate for each device if it was initialized and later quiesced by the jump kernel during save or never touched. And we need to tell the resume from hybernate code "i touched it" "no i didn't" and "we resumed from s4" "no it was from s5".

This is why I've been proposing that we don't create the suspend image with devices in the low power state, but only in a quiesced state similar to the initial state.

I'm proposing a sequence like:

(1) start allocating pinned memory to reduce saved image size
(2) allocate and map blocks to save maximum image (we know how much ram is not in 1, so the max size)
(3) tell drivers we are going to suspend. userspace is still running, swaping still active, etc. now is the time to allocate memory to save device state.
(4) do what we want to slow down userspace making requests (ie run freezer today)
(5) call drivers while still scheduling with interrupts "save oppertunitiy". From this point, any new request should be queued or the process put on a wait queue.
(6) suspend timers, turn off interrupts
(7) call drivers with interrupts off (final save)
(8) jump to other kernel to save the image
(9) call drivers to transition to low power
(10) finish operations to platform suspend on hybernate
(11) call drivers to resume, telling them if from suspend-to-ram or suspend-to-disk, possibly in two stages (interrupts off no scheduling and interrupts on scheduling allowed)
(12) unfreeze processes, kill the the thread holding the extra memroy used to reserve

So I'm asking what needs to happen in 9. If we have to turn interrupts on and schedule, that's ok. If the low power state is the initial state then fine.

Note that in 11, we could further differentate "from image restore in S4" and "from image restore in S5", and "from failed image save", but what needs to happen differently?

I'm guessing that the work that will take some time is seperating the go to low power from quiesce operations for snapshot, as it sounds like this is done with one driver call today? Making this separation will give us our driver audit :-), but only if we decide on the requiements before the start.

miton

#202 lore raw
In reply to Alan Stern
Quoted 31 lines · Alan Stern
Quoted 12 lines · Milton Miller
Quoted 11 lines · Alan Stern
Quoted 9 lines · Milton Miller
Quoted 3 lines

We can't do this unless we have frozen tasks (this way, or another) before
carrying out the entire operation.

What can't we do? We've already worked with the drivers to quesce
the
hardware and put any information to resume the device in ram. Now we ask them to put their device in low power mode so we can go to sleep. Even if we schedule, the only thing userspace could touch is memory.

Quoted 8 lines
Quoted 4 lines

Userspace can submit I/O requests. Someone will have to audit every driver to make sure that such I/O requests don't cause a quiesced device to become active. If the device is active, it will make the memory snapshot inconsistent with the on-device data.

If a driver is waking a device between the time it was told by hibernation "suspend all operations and save your device state to ram" and "resume your device" then it is a buggy driver.

That's exactly my point. As far as I know nobody has done a survey, but I bet you'd find _many_ drivers are buggy either in this way or the converse (forcing an I/O request to fail immediately instead of waiting until the suspend is over when it could succeed). They have this bug because they were written -- those which include any suspend/resume support at all -- under the assumption that they could rely on the freezer.

Quoted 4 lines

And that's why Rafael said "We can't do this unless we have frozen tasks (this way, or another) before carrying out the entire operation." Until the drivers are fixed -- which seems like a tremendous job -- none of this will work.

So this is in the way of removing the freezer ... but as we are not relying on doing any io other than suspend device operation, save state to ram, then later put device in low power mode for s3 and/or s4, and finally restore and resume to running.

Quoted 7 lines
Quoted 4 lines

I argue the process can make the io request after we write to disk, we just can't service it. If we are suspended it will go to the request queue, and eventually the process will wait for normal throttling mechanisms until the driver is woken up.

Many drivers don't have request queues. Even for the ones that do, there are I/O pathways that bypass the queue (think of ioctl or sysfs).

So its not a flag in make_request, fine.

Quoted 9 lines
Quoted 5 lines

Actually, my point was more "what kernel services do the drivers need to transition from quiesced to low power for acpi S4 or suspend-to-ram"? We can't give them allocate-memory (but we give them a call "we are going to suspend" when they can), but does "run this tasklet" help? What timer facilities are needed?

Some drivers need the ability to schedule. Some will need the ability to allocate memory (although GFP_ATOMIC is probably sufficient). Some will need timers to run.

Can they allocate the memory in advance? (Call them when we know we want to suspend, they make the allocations they will need; we later call them again to release the allocations).

If you need timers, you probably want some scheduling?

Quoted 4 lines
Quoted 2 lines

Do we need to differentate init (por by bios) and resume from quiesced (for reboot, kexec start/resume)? I hope not.

Yes we do.

can you elabrate? Note I was not asking resume-from-low power vs init-from-por. We still get that distinction.

How do these drivers work today when we kexec?

The reason I'm asking is its hard to tell the first kernel what happened. We can say "we powered off, and we were restarted", but it becomes much harder when each device may or may not have a driver in the save kernel if we have to differentate for each device if it was initialized and later quiesced by the jump kernel during save or never touched. And we need to tell the resume from hybernate code "i touched it" "no i didn't" and "we resumed from s4" "no it was from s5".

This is why I've been proposing that we don't create the suspend image with devices in the low power state, but only in a quiesced state similar to the initial state.

I'm proposing a sequence like:

(1) start allocating pinned memory to reduce saved image size
(2) allocate and map blocks to save maximum image (we know how much ram is not in 1, so the max size)
(3) tell drivers we are going to suspend. userspace is still running, swaping still active, etc. now is the time to allocate memory to save device state.
(4) do what we want to slow down userspace making requests (ie run freezer today)
(5) call drivers while still scheduling with interrupts "save oppertunitiy". From this point, any new request should be queued or the process put on a wait queue.
(6) suspend timers, turn off interrupts
(7) call drivers with interrupts off (final save)
(8) jump to other kernel to save the image
(9) call drivers to transition to low power
(10) finish operations to platform suspend on hybernate
(11) call drivers to resume, telling them if from suspend-to-ram or suspend-to-disk, possibly in two stages (interrupts off no scheduling and interrupts on scheduling allowed)
(12) unfreeze processes, kill the the thread holding the extra memroy used to reserve

So I'm asking what needs to happen in 9. If we have to turn interrupts on and schedule, that's ok. If the low power state is the initial state then fine.

Note that in 11, we could further differentate "from image restore in S4" and "from image restore in S5", and "from failed image save", but what needs to happen differently?

I'm guessing that the work that will take some time is seperating the go to low power from quiesce operations for snapshot, as it sounds like this is done with one driver call today? Making this separation will give us our driver audit :-), but only if we decide on the requiements before the start.

miton

#203 lore raw
Quoted 13 lines · Milton Miller
Quoted 8 lines

That's exactly my point. As far as I know nobody has done a survey, but I bet you'd find _many_ drivers are buggy either in this way or the converse (forcing an I/O request to fail immediately instead of waiting until the suspend is over when it could succeed). They have this bug because they were written -- those which include any suspend/resume support at all -- under the assumption that they could rely on the freezer.

Quoted 4 lines

And that's why Rafael said "We can't do this unless we have frozen tasks (this way, or another) before carrying out the entire operation." Until the drivers are fixed -- which seems like a tremendous job -- none of this will work.

Quoted 4 lines

So this is in the way of removing the freezer ... but as we are not relying on doing any io other than suspend device operation, save state to ram, then later put device in low power mode for s3 and/or s4, and finally restore and resume to running.

We aren't relying on doing any other I/O... and we have to prevent any other I/O from taking place. That's the hard part.

Quoted 7 lines
Quoted 3 lines

Some drivers need the ability to schedule. Some will need the ability to allocate memory (although GFP_ATOMIC is probably sufficient). Some will need timers to run.

Can they allocate the memory in advance? (Call them when we know we want to suspend, they make the allocations they will need; we later call them again to release the allocations).

Some yes, some no. The ones that can't generally don't need very much.

Quoted 1 line

If you need timers, you probably want some scheduling?

Yes, scheduling was one of the items I listed above.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Do we need to differentate init (por by bios) and resume from quiesced (for reboot, kexec start/resume)? I hope not.

Yes we do.

can you elabrate? Note I was not asking resume-from-low power vs
init-from-por. We still get that distinction.

To be more precise, drivers need to know whether they are doing a complete initialization, a resume from low-power, or a resume from hibernate. Currently there's no way to distinguish the last two (they both involve calling the resume() method), but that's going to change. The first can be told apart because it involves probe() rather than resume().

Quoted 1 line

How do these drivers work today when we kexec?

We don't kexec during a resume from hibernation. When kexec does run, drivers in the new kernel do a complete reinitialization.

Quoted 7 lines

The reason I'm asking is its hard to tell the first kernel what happened. We can say "we powered off, and we were restarted", but it becomes much harder when each device may or may not have a driver in the save kernel if we have to differentate for each device if it was initialized and later quiesced by the jump kernel during save or never touched. And we need to tell the resume from hybernate code "i touched it" "no i didn't" and "we resumed from s4" "no it was from s5".

You merely have to distinguish between suspend and hibernate.

Quoted 3 lines

I'm guessing that the work that will take some time is seperating the go to low power from quiesce operations for snapshot, as it sounds like this is done with one driver call today?

There's a single call with different arguments. How much do you know about the way the Power Management core actually works now? Have you read the files in Documentation/power?

Quoted 3 lines

Making this separation will
give us our driver audit :-), but only if we decide on the requiements before the start.

No it won't, although it will be a good start.

Alan Stern

#204 lore raw
In reply to Milton Miller
Quoted 13 lines · Milton Miller
Quoted 8 lines

That's exactly my point. As far as I know nobody has done a survey, but I bet you'd find _many_ drivers are buggy either in this way or the converse (forcing an I/O request to fail immediately instead of waiting until the suspend is over when it could succeed). They have this bug because they were written -- those which include any suspend/resume support at all -- under the assumption that they could rely on the freezer.

Quoted 4 lines

And that's why Rafael said "We can't do this unless we have frozen tasks (this way, or another) before carrying out the entire operation." Until the drivers are fixed -- which seems like a tremendous job -- none of this will work.

Quoted 4 lines

So this is in the way of removing the freezer ... but as we are not relying on doing any io other than suspend device operation, save state to ram, then later put device in low power mode for s3 and/or s4, and finally restore and resume to running.

We aren't relying on doing any other I/O... and we have to prevent any other I/O from taking place. That's the hard part.

Quoted 7 lines
Quoted 3 lines

Some drivers need the ability to schedule. Some will need the ability to allocate memory (although GFP_ATOMIC is probably sufficient). Some will need timers to run.

Can they allocate the memory in advance? (Call them when we know we want to suspend, they make the allocations they will need; we later call them again to release the allocations).

Some yes, some no. The ones that can't generally don't need very much.

Quoted 1 line

If you need timers, you probably want some scheduling?

Yes, scheduling was one of the items I listed above.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Do we need to differentate init (por by bios) and resume from quiesced (for reboot, kexec start/resume)? I hope not.

Yes we do.

can you elabrate? Note I was not asking resume-from-low power vs
init-from-por. We still get that distinction.

To be more precise, drivers need to know whether they are doing a complete initialization, a resume from low-power, or a resume from hibernate. Currently there's no way to distinguish the last two (they both involve calling the resume() method), but that's going to change. The first can be told apart because it involves probe() rather than resume().

Quoted 1 line

How do these drivers work today when we kexec?

We don't kexec during a resume from hibernation. When kexec does run, drivers in the new kernel do a complete reinitialization.

Quoted 7 lines

The reason I'm asking is its hard to tell the first kernel what happened. We can say "we powered off, and we were restarted", but it becomes much harder when each device may or may not have a driver in the save kernel if we have to differentate for each device if it was initialized and later quiesced by the jump kernel during save or never touched. And we need to tell the resume from hybernate code "i touched it" "no i didn't" and "we resumed from s4" "no it was from s5".

You merely have to distinguish between suspend and hibernate.

Quoted 3 lines

I'm guessing that the work that will take some time is seperating the go to low power from quiesce operations for snapshot, as it sounds like this is done with one driver call today?

There's a single call with different arguments. How much do you know about the way the Power Management core actually works now? Have you read the files in Documentation/power?

Quoted 3 lines

Making this separation will
give us our driver audit :-), but only if we decide on the requiements before the start.

No it won't, although it will be a good start.

Alan Stern

#205 lore raw
In reply to Alan Stern

Am Freitag 20 Juli 2007 schrieb Alan Stern:

Quoted 3 lines

Some drivers need the ability to schedule.  Some will need the ability to allocate memory (although GFP_ATOMIC is probably sufficient).  Some will need timers to run.

Some will have to request firmware. It can add up to some megabytes. In addition, if we don't freeze, some drivers, eg. video drivers, can do allocations in the megabyte range.

It seems to me that without the freezer we will end up with many drivers needing a two step notification process. Furthermore there are requirements on the order of shutting down system facilities, eg. device addition must be stopped before drivers allocate firmware.

Regards
Oliver

#206 lore raw
Quoted 5 lines · Oliver Neukum

Am Freitag 20 Juli 2007 schrieb Alan Stern:

Quoted 3 lines

Some drivers need the ability to schedule.  Some will need the ability to allocate memory (although GFP_ATOMIC is probably sufficient).  Some will need timers to run.

Quoted 8 lines

Some will have to request firmware. It can add up to some megabytes. In addition, if we don't freeze, some drivers, eg. video drivers, can do allocations in the megabyte range.

It seems to me that without the freezer we will end up with many drivers needing a two step notification process. Furthermore there are requirements on the order of shutting down system facilities, eg. device addition must be stopped before drivers allocate firmware.

These are really separate issues, since they refer to things that have to happen well before the memory snapshot is captured.

We already have a pre-suspend notification available for drivers that need to allocate large amounts of memory.

You are correct about the need to delay/stop device addition. I don't know how this can be done in general; each code path calling device_add() may have to be treated individually.

Alan Stern

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

Am Freitag 20 Juli 2007 schrieb Alan Stern:

Quoted 3 lines

Some drivers need the ability to schedule.  Some will need the ability to allocate memory (although GFP_ATOMIC is probably sufficient).  Some will need timers to run.

Quoted 8 lines

Some will have to request firmware. It can add up to some megabytes. In addition, if we don't freeze, some drivers, eg. video drivers, can do allocations in the megabyte range.

It seems to me that without the freezer we will end up with many drivers needing a two step notification process. Furthermore there are requirements on the order of shutting down system facilities, eg. device addition must be stopped before drivers allocate firmware.

These are really separate issues, since they refer to things that have to happen well before the memory snapshot is captured.

We already have a pre-suspend notification available for drivers that need to allocate large amounts of memory.

You are correct about the need to delay/stop device addition. I don't know how this can be done in general; each code path calling device_add() may have to be treated individually.

Alan Stern

#208 lore raw

Am Freitag 20 Juli 2007 schrieb Alan Stern:

Quoted 16 lines · Oliver Neukum
Quoted 6 lines

Am Freitag 20 Juli 2007 schrieb Alan Stern:

Quoted 3 lines

Some drivers need the ability to schedule.  Some will need the ability to allocate memory (although GFP_ATOMIC is probably sufficient).  Some will need timers to run.

Quoted 8 lines

Some will have to request firmware. It can add up to some megabytes. In addition, if we don't freeze, some drivers, eg. video drivers, can do allocations in the megabyte range.

It seems to me that without the freezer we will end up with many drivers needing a two step notification process. Furthermore there are requirements on the order of shutting down system facilities, eg. device addition must be stopped before drivers allocate firmware.

Quoted 5 lines

These are really separate issues, since they refer to things that have to happen well before the memory snapshot is captured.

We already have a pre-suspend notification available for drivers that need to allocate large amounts of memory.

Is that facility fine grained enough?

Quoted 3 lines

You are correct about the need to delay/stop device addition. I don't know how this can be done in general; each code path calling device_add() may have to be treated individually.

What about the old API? Do we have to block module loading? What happens if a scsi error handler is woken? If it cannot be woken, how are errors handled?

Regards
Oliver

#209 lore raw
Quoted 4 lines · Oliver Neukum
Quoted 2 lines

We already have a pre-suspend notification available for drivers that need to allocate large amounts of memory.

Is that facility fine grained enough?

It's a notifier chain that gets called at several points during the suspend transition. One of those points is right at the start, while userspace is still running and reasonably large amounts of memory can be allocated.

Is it fine-grained enough? I don't know -- hard to tell, since nothing much is using it yet.

Quoted 5 lines
Quoted 3 lines

You are correct about the need to delay/stop device addition. I don't know how this can be done in general; each code path calling device_add() may have to be treated individually.

What about the old API?

What old API do you mean?

Quoted 1 line

Do we have to block module loading?

No. Registering new drivers is okay, registering new devices is bad.

Of course, some modules do want to register a new device in their init method. I don't know what we should do about them. Force the registration to fail, I suppose. How often will people suspend while a module is loading?

Quoted 2 lines

What happens if a scsi error handler is woken? If it cannot be woken, how are errors handled?

Why should the error handler wake up? There isn't supposed to be any I/O going on, hence no errors to handle.

Alan Stern

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

We already have a pre-suspend notification available for drivers that need to allocate large amounts of memory.

Is that facility fine grained enough?

It's a notifier chain that gets called at several points during the suspend transition. One of those points is right at the start, while userspace is still running and reasonably large amounts of memory can be allocated.

Is it fine-grained enough? I don't know -- hard to tell, since nothing much is using it yet.

Quoted 5 lines
Quoted 3 lines

You are correct about the need to delay/stop device addition. I don't know how this can be done in general; each code path calling device_add() may have to be treated individually.

What about the old API?

What old API do you mean?

Quoted 1 line

Do we have to block module loading?

No. Registering new drivers is okay, registering new devices is bad.

Of course, some modules do want to register a new device in their init method. I don't know what we should do about them. Force the registration to fail, I suppose. How often will people suspend while a module is loading?

Quoted 2 lines

What happens if a scsi error handler is woken? If it cannot be woken, how are errors handled?

Why should the error handler wake up? There isn't supposed to be any I/O going on, hence no errors to handle.

Alan Stern

#211 lore raw

Am Samstag 21 Juli 2007 schrieb Alan Stern:

Quoted 15 lines · Oliver Neukum
Quoted 5 lines
Quoted 3 lines

We already have a pre-suspend notification available for drivers that need to allocate large amounts of memory.

Is that facility fine grained enough?

It's a notifier chain that gets called at several points during the suspend transition. One of those points is right at the start, while userspace is still running and reasonably large amounts of memory can be allocated.

Is it fine-grained enough? I don't know -- hard to tell, since nothing much is using it yet.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

You are correct about the need to delay/stop device addition. I don't know how this can be done in general; each code path calling device_add() may have to be treated individually.

What about the old API?

What old API do you mean?

The find_device() stuff.

Quoted 3 lines
Quoted 1 line

Do we have to block module loading?

No. Registering new drivers is okay, registering new devices is bad.

What if it is a driver for virtual devices that don't need probe() for actual hardware?

Quoted 10 lines

Of course, some modules do want to register a new device in their init method. I don't know what we should do about them. Force the registration to fail, I suppose. How often will people suspend while a module is loading?

Quoted 2 lines

What happens if a scsi error handler is woken? If it cannot be woken, how are errors handled?

Why should the error handler wake up? There isn't supposed to be any I/O going on, hence no errors to handle.

What about shared busses? Firewire, FibreChannel? They can get external resets, etc ...

Regards
Oliver

#212 lore raw

Towards eliminating the freezer

[Note changed $SUBJECT]

Quoted 9 lines · Oliver Neukum
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

You are correct about the need to delay/stop device addition. I don't know how this can be done in general; each code path calling device_add() may have to be treated individually.

What about the old API?

What old API do you mean?

The find_device() stuff.

You mean like bus_find_device() or driver_find_device()? I don't see any problem with them. They aren't involved in device registration or locking.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Do we have to block module loading?

No. Registering new drivers is okay, registering new devices is bad.

What if it is a driver for virtual devices that don't need probe() for actual hardware?

Like I said, registering the new driver is okay. Registering the virtual devices could cause a problem.

Quoted 5 lines
Quoted 5 lines

Of course, some modules do want to register a new device in their init method. I don't know what we should do about them. Force the registration to fail, I suppose. How often will people suspend while a module is loading?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

What happens if a scsi error handler is woken? If it cannot be woken, how are errors handled?

Why should the error handler wake up? There isn't supposed to be any I/O going on, hence no errors to handle.

What about shared busses? Firewire, FibreChannel? They can get external resets, etc ...

The same reasoning applies: If no I/O is going on, why should there be a reset? If a reset or any other event is generated externally then it is handled in the kernel by some device driver for the bus, which should be smart enough not to register new devices or start up an error handler until I/O is once again permitted.

=============================

Now here's an idea which might work. Can we require every caller of device_add() to hold some existing device's semaphore? Normally it would be the semaphore of the new device's parent, but it could be a higher ancestor. There even could be a single "root" semaphore for drivers registering a top-level device with no parent.

(Some testing shows that during startup things like ACPI and IDE don't fulfill this requirement, so maybe we should require it only after userspace has begun running. After all, the system can't suspend until then.)

It seems like a reasonable sort of thing to do. Hotplugged devices tend to be registered as they are discovered by their parent's driver, so it shouldn't be too much to ask that the parent's semaphore be held when the new device is registered. Static devices generally aren't quite so nice; the serial and floppy drivers in particular would need a little work (and probably some other drivers too).

If we do this, then once the PM core has acquired the semaphore for every device it will be guaranteed that no new devices can be added. It would be a simple solution to a rather nasty problem.

Alan Stern

#213 lore raw

Towards eliminating the freezer

In reply to Oliver Neukum

[Note changed $SUBJECT]

Quoted 9 lines · Oliver Neukum
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

You are correct about the need to delay/stop device addition. I don't know how this can be done in general; each code path calling device_add() may have to be treated individually.

What about the old API?

What old API do you mean?

The find_device() stuff.

You mean like bus_find_device() or driver_find_device()? I don't see any problem with them. They aren't involved in device registration or locking.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Do we have to block module loading?

No. Registering new drivers is okay, registering new devices is bad.

What if it is a driver for virtual devices that don't need probe() for actual hardware?

Like I said, registering the new driver is okay. Registering the virtual devices could cause a problem.

Quoted 5 lines
Quoted 5 lines

Of course, some modules do want to register a new device in their init method. I don't know what we should do about them. Force the registration to fail, I suppose. How often will people suspend while a module is loading?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

What happens if a scsi error handler is woken? If it cannot be woken, how are errors handled?

Why should the error handler wake up? There isn't supposed to be any I/O going on, hence no errors to handle.

What about shared busses? Firewire, FibreChannel? They can get external resets, etc ...

The same reasoning applies: If no I/O is going on, why should there be a reset? If a reset or any other event is generated externally then it is handled in the kernel by some device driver for the bus, which should be smart enough not to register new devices or start up an error handler until I/O is once again permitted.

=============================

Now here's an idea which might work. Can we require every caller of device_add() to hold some existing device's semaphore? Normally it would be the semaphore of the new device's parent, but it could be a higher ancestor. There even could be a single "root" semaphore for drivers registering a top-level device with no parent.

(Some testing shows that during startup things like ACPI and IDE don't fulfill this requirement, so maybe we should require it only after userspace has begun running. After all, the system can't suspend until then.)

It seems like a reasonable sort of thing to do. Hotplugged devices tend to be registered as they are discovered by their parent's driver, so it shouldn't be too much to ask that the parent's semaphore be held when the new device is registered. Static devices generally aren't quite so nice; the serial and floppy drivers in particular would need a little work (and probably some other drivers too).

If we do this, then once the PM core has acquired the semaphore for every device it will be guaranteed that no new devices can be added. It would be a simple solution to a rather nasty problem.

Alan Stern

#214 lore raw

Re: Towards eliminating the freezer

Am Montag 23 Juli 2007 schrieb Alan Stern:

Quoted 5 lines

Now here's an idea which might work.  Can we require every caller of device_add() to hold some existing device's semaphore?  Normally it would be the semaphore of the new device's parent, but it could be a higher ancestor.  There even could be a single "root" semaphore for drivers registering a top-level device with no parent.

What prevents us from having a device addition semaphore? Adding device is not critical to performance, is it?

Regards
Oliver

#215 lore raw

Re: Towards eliminating the freezer

Quoted 9 lines · Oliver Neukum

Am Montag 23 Juli 2007 schrieb Alan Stern:

Quoted 5 lines

Now here's an idea which might work.  Can we require every caller of device_add() to hold some existing device's semaphore?  Normally it would be the semaphore of the new device's parent, but it could be a higher ancestor.  There even could be a single "root" semaphore for drivers registering a top-level device with no parent.

What prevents us from having a device addition semaphore? Adding device is not critical to performance, is it?

It would create a locking order violation. Many drivers hold a device semaphore while registering a child device, so they would acquire your new semaphore while holding a device sem. But the PM core needs to prevent registration while calling suspend() methods, so it would need to acquire the device sems while holding your new semaphore.

Alan Stern

#216 lore raw

Re: Towards eliminating the freezer

In reply to Oliver Neukum
Quoted 9 lines · Oliver Neukum

Am Montag 23 Juli 2007 schrieb Alan Stern:

Quoted 5 lines

Now here's an idea which might work.  Can we require every caller of device_add() to hold some existing device's semaphore?  Normally it would be the semaphore of the new device's parent, but it could be a higher ancestor.  There even could be a single "root" semaphore for drivers registering a top-level device with no parent.

What prevents us from having a device addition semaphore? Adding device is not critical to performance, is it?

It would create a locking order violation. Many drivers hold a device semaphore while registering a child device, so they would acquire your new semaphore while holding a device sem. But the PM core needs to prevent registration while calling suspend() methods, so it would need to acquire the device sems while holding your new semaphore.

Alan Stern

#217 lore raw

Re: Towards eliminating the freezer

In reply to Alan Stern

Am Montag 23 Juli 2007 schrieb Alan Stern:

Quoted 5 lines

Now here's an idea which might work.  Can we require every caller of device_add() to hold some existing device's semaphore?  Normally it would be the semaphore of the new device's parent, but it could be a higher ancestor.  There even could be a single "root" semaphore for drivers registering a top-level device with no parent.

What prevents us from having a device addition semaphore? Adding device is not critical to performance, is it?

Regards
Oliver

#218 lore raw

Re: Towards eliminating the freezer

In reply to Alan Stern
Quoted 1 line · Alan Stern

[Note changed $SUBJECT]

[--snip--]

Quoted 21 lines

=============================

Now here's an idea which might work. Can we require every caller of device_add() to hold some existing device's semaphore? Normally it would be the semaphore of the new device's parent, but it could be a higher ancestor. There even could be a single "root" semaphore for drivers registering a top-level device with no parent.

(Some testing shows that during startup things like ACPI and IDE don't fulfill this requirement, so maybe we should require it only after userspace has begun running. After all, the system can't suspend until then.)

It seems like a reasonable sort of thing to do. Hotplugged devices tend to be registered as they are discovered by their parent's driver, so it shouldn't be too much to ask that the parent's semaphore be held when the new device is registered. Static devices generally aren't quite so nice; the serial and floppy drivers in particular would need a little work (and probably some other drivers too).

Quoted 3 lines

If we do this, then once the PM core has acquired the semaphore for every device it will be guaranteed that no new devices can be added. It would be a simple solution to a rather nasty problem.

Hmm, in device_pm_add() and device_pm_remove() we acquire dpm_list_mtx which also is acquired by device_suspend() and device_resume(). Thus, every attempt to register a new device or unregister an existing one will be blocked while either device_suspend() or device_resume() is running.

If we arrange things so that dpm_list_mtx is acquired, but not released, by device_suspend() and released, but not acquired, by device_resume(), then it won't be possible to register/unregister a device during a suspend-resume cycle.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#219 lore raw

Re: Towards eliminating the freezer

Quoted 27 lines · Rafael J. Wysocki
Quoted 18 lines

Now here's an idea which might work. Can we require every caller of device_add() to hold some existing device's semaphore? Normally it would be the semaphore of the new device's parent, but it could be a higher ancestor. There even could be a single "root" semaphore for drivers registering a top-level device with no parent.

(Some testing shows that during startup things like ACPI and IDE don't fulfill this requirement, so maybe we should require it only after userspace has begun running. After all, the system can't suspend until then.)

It seems like a reasonable sort of thing to do. Hotplugged devices tend to be registered as they are discovered by their parent's driver, so it shouldn't be too much to ask that the parent's semaphore be held when the new device is registered. Static devices generally aren't quite so nice; the serial and floppy drivers in particular would need a little work (and probably some other drivers too).

Quoted 3 lines

If we do this, then once the PM core has acquired the semaphore for every device it will be guaranteed that no new devices can be added. It would be a simple solution to a rather nasty problem.

Hmm, in device_pm_add() and device_pm_remove() we acquire dpm_list_mtx which also is acquired by device_suspend() and device_resume(). Thus, every attempt to register a new device or unregister an existing one will be blocked while either device_suspend() or device_resume() is running.

Quoted 4 lines

If we arrange things so that dpm_list_mtx is acquired, but not released, by device_suspend() and released, but not acquired, by device_resume(), then it won't be possible to register/unregister a device during a suspend-resume cycle.

As with Oliver's suggestion, this would create a locking order violation. Drivers registering children (and thus acquiring dpm_list_mtx) will often already hold the parent's sem. But device_suspend() needs to acquire device sems while holding dpm_list_mtx.

Alan Stern

#220 lore raw

Re: Towards eliminating the freezer

In reply to Rafael J. Wysocki
Quoted 27 lines · Rafael J. Wysocki
Quoted 18 lines

Now here's an idea which might work. Can we require every caller of device_add() to hold some existing device's semaphore? Normally it would be the semaphore of the new device's parent, but it could be a higher ancestor. There even could be a single "root" semaphore for drivers registering a top-level device with no parent.

(Some testing shows that during startup things like ACPI and IDE don't fulfill this requirement, so maybe we should require it only after userspace has begun running. After all, the system can't suspend until then.)

It seems like a reasonable sort of thing to do. Hotplugged devices tend to be registered as they are discovered by their parent's driver, so it shouldn't be too much to ask that the parent's semaphore be held when the new device is registered. Static devices generally aren't quite so nice; the serial and floppy drivers in particular would need a little work (and probably some other drivers too).

Quoted 3 lines

If we do this, then once the PM core has acquired the semaphore for every device it will be guaranteed that no new devices can be added. It would be a simple solution to a rather nasty problem.

Hmm, in device_pm_add() and device_pm_remove() we acquire dpm_list_mtx which also is acquired by device_suspend() and device_resume(). Thus, every attempt to register a new device or unregister an existing one will be blocked while either device_suspend() or device_resume() is running.

Quoted 4 lines

If we arrange things so that dpm_list_mtx is acquired, but not released, by device_suspend() and released, but not acquired, by device_resume(), then it won't be possible to register/unregister a device during a suspend-resume cycle.

As with Oliver's suggestion, this would create a locking order violation. Drivers registering children (and thus acquiring dpm_list_mtx) will often already hold the parent's sem. But device_suspend() needs to acquire device sems while holding dpm_list_mtx.

Alan Stern

#221 lore raw

Re: Towards eliminating the freezer

Quoted 34 lines · Alan Stern
Quoted 27 lines · Rafael J. Wysocki
Quoted 18 lines

Now here's an idea which might work. Can we require every caller of device_add() to hold some existing device's semaphore? Normally it would be the semaphore of the new device's parent, but it could be a higher ancestor. There even could be a single "root" semaphore for drivers registering a top-level device with no parent.

(Some testing shows that during startup things like ACPI and IDE don't fulfill this requirement, so maybe we should require it only after userspace has begun running. After all, the system can't suspend until then.)

It seems like a reasonable sort of thing to do. Hotplugged devices tend to be registered as they are discovered by their parent's driver, so it shouldn't be too much to ask that the parent's semaphore be held when the new device is registered. Static devices generally aren't quite so nice; the serial and floppy drivers in particular would need a little work (and probably some other drivers too).

Quoted 3 lines

If we do this, then once the PM core has acquired the semaphore for every device it will be guaranteed that no new devices can be added. It would be a simple solution to a rather nasty problem.

Hmm, in device_pm_add() and device_pm_remove() we acquire dpm_list_mtx which also is acquired by device_suspend() and device_resume(). Thus, every attempt to register a new device or unregister an existing one will be blocked while either device_suspend() or device_resume() is running.

Quoted 4 lines

If we arrange things so that dpm_list_mtx is acquired, but not released, by device_suspend() and released, but not acquired, by device_resume(), then it won't be possible to register/unregister a device during a suspend-resume cycle.

Quoted 5 lines

As with Oliver's suggestion, this would create a locking order violation. Drivers registering children (and thus acquiring dpm_list_mtx) will often already hold the parent's sem. But device_suspend() needs to acquire device sems while holding dpm_list_mtx.

Hmm, but this is done already (ie. device_suspend() acquires device sems while holding dpm_list_mtx in the current code).

What I'm suggesting is not to let device_suspend() release dpm_list_mtx when it's finished. The appended patch illustrates that I mean.

Greetings,
Rafael

---
dpm_list_mtx is used by the PM core to prevent device objects from being added/removed while device_suspend() and device_resume() are running. However, it should also be impossible to add a device after device_suspend() has finished, because at that time the dpm_active list is empty and adding new devices to it would break the ordering of devices during the next suspend. Thus, it seems reasonable to leave device_suspend() with dpm_list_mtx held and release at the end of device_resume().

In that case device_suspend() and device_resume() cannot be run concurrently and dpm_mtx is no longer needed. Also, it's a bug to run device_resume() after a failing device_suspend(), so the APM code needs to be updated.

---
 arch/i386/kernel/apm.c       |    5 ++++-
 drivers/base/power/main.c    |    1 -
 drivers/base/power/power.h   |    5 -----
 drivers/base/power/resume.c  |    3 ---
 drivers/base/power/suspend.c |    3 ---
 5 files changed, 4 insertions(+), 13 deletions(-)
arch/i386/kernel/apm.c +4 -1
Index: linux-2.6.23-rc1/arch/i386/kernel/apm.c
===================================================================
@@ -1202,7 +1202,9 @@ static int suspend(int vetoable)
 		printk(KERN_CRIT "apm: suspend was vetoed, but suspending anyway.\n");
 	}
 
-	device_suspend(PMSG_SUSPEND);
+	err = device_suspend(PMSG_SUSPEND);
+	if (err)
+		goto send_resume;
 	local_irq_disable();
 	device_power_down(PMSG_SUSPEND);
 
@@ -1224,6 +1226,7 @@ static int suspend(int vetoable)
 	device_power_up();
 	local_irq_enable();
 	device_resume();
+ send_resume:
 	pm_send_all(PM_RESUME, (void *)0);
 	queue_event(APM_NORMAL_RESUME, NULL);
  out:
drivers/base/power/resume.c +0 -3
Index: linux-2.6.23-rc1/drivers/base/power/resume.c
===================================================================
@@ -72,7 +72,6 @@ static int resume_device_early(struct de
  */
 void dpm_resume(void)
 {
-	mutex_lock(&dpm_list_mtx);
 	while(!list_empty(&dpm_off)) {
 		struct list_head * entry = dpm_off.next;
 		struct device * dev = to_device(entry);
@@ -99,9 +98,7 @@ void dpm_resume(void)
 void device_resume(void)
 {
 	might_sleep();
-	mutex_lock(&dpm_mtx);
 	dpm_resume();
-	mutex_unlock(&dpm_mtx);
 }
 
 EXPORT_SYMBOL_GPL(device_resume);
drivers/base/power/suspend.c +0 -3
Index: linux-2.6.23-rc1/drivers/base/power/suspend.c
===================================================================
@@ -127,7 +127,6 @@ int device_suspend(pm_message_t state)
 	int error = 0;
 
 	might_sleep();
-	mutex_lock(&dpm_mtx);
 	mutex_lock(&dpm_list_mtx);
 	while (!list_empty(&dpm_active) && error == 0) {
 		struct list_head * entry = dpm_active.prev;
@@ -153,11 +152,9 @@ int device_suspend(pm_message_t state)
 				error == -EAGAIN ? " (please convert to suspend_late)" : "");
 		put_device(dev);
 	}
-	mutex_unlock(&dpm_list_mtx);
 	if (error)
 		dpm_resume();
 
-	mutex_unlock(&dpm_mtx);
 	return error;
 }
 
drivers/base/power/main.c +0 -1
Index: linux-2.6.23-rc1/drivers/base/power/main.c
===================================================================
@@ -28,7 +28,6 @@ LIST_HEAD(dpm_active);
 LIST_HEAD(dpm_off);
 LIST_HEAD(dpm_off_irq);
 
-DEFINE_MUTEX(dpm_mtx);
 DEFINE_MUTEX(dpm_list_mtx);
 
 int (*platform_enable_wakeup)(struct device *dev, int is_on);
drivers/base/power/power.h +0 -5
Index: linux-2.6.23-rc1/drivers/base/power/power.h
===================================================================
@@ -12,11 +12,6 @@ extern void device_shutdown(void);
  */
 
 /*
- * Used to synchronize global power management operations.
- */
-extern struct mutex dpm_mtx;
-
-/*
  * Used to serialize changes to the dpm_* lists.
  */
 extern struct mutex dpm_list_mtx;
#222 lore raw

Re: Towards eliminating the freezer

Quoted 11 lines · Rafael J. Wysocki
Quoted 5 lines

As with Oliver's suggestion, this would create a locking order violation. Drivers registering children (and thus acquiring dpm_list_mtx) will often already hold the parent's sem. But device_suspend() needs to acquire device sems while holding dpm_list_mtx.

Hmm, but this is done already (ie. device_suspend() acquires device sems while holding dpm_list_mtx in the current code).

What I'm suggesting is not to let device_suspend() release dpm_list_mtx when it's finished. The appended patch illustrates that I mean.

Oh, okay, I see what you mean.

I should have explained earlier that my proposal was meant to be in the context of a previous discussion, where I suggested that device_suspend() should go through a preliminary step of acquiring all the device semaphores. This would have the beneficial effect of blocking all attempts at driver binding or unbinding while a suspend is underway.

Still, this isn't a bad approach. Maybe the following algorithm could be used:

get_more:

	For each device on dpm_list
		Acquire dev->sem
		Move dev from dpm_list to a temporary list
	Lock dpm_list_mutex
	If (!list_empty(dpm_list)) {
		Unlock dpm_list_mutex
		Goto get_more
	}

(The "For each" loop would have to be written carefully to allow for device removal.)

The total number of iterations should never be large. At the end the PM core would own all the device semaphores and no more devices could be added. Then it would be safe to call each device's suspend() method.

This will remove one of the barriers to eliminating the freezer.

Alan Stern

#223 lore raw

Re: Towards eliminating the freezer

In reply to Rafael J. Wysocki
Quoted 11 lines · Rafael J. Wysocki
Quoted 5 lines

As with Oliver's suggestion, this would create a locking order violation. Drivers registering children (and thus acquiring dpm_list_mtx) will often already hold the parent's sem. But device_suspend() needs to acquire device sems while holding dpm_list_mtx.

Hmm, but this is done already (ie. device_suspend() acquires device sems while holding dpm_list_mtx in the current code).

What I'm suggesting is not to let device_suspend() release dpm_list_mtx when it's finished. The appended patch illustrates that I mean.

Oh, okay, I see what you mean.

I should have explained earlier that my proposal was meant to be in the context of a previous discussion, where I suggested that device_suspend() should go through a preliminary step of acquiring all the device semaphores. This would have the beneficial effect of blocking all attempts at driver binding or unbinding while a suspend is underway.

Still, this isn't a bad approach. Maybe the following algorithm could be used:

get_more:

	For each device on dpm_list
		Acquire dev->sem
		Move dev from dpm_list to a temporary list
	Lock dpm_list_mutex
	If (!list_empty(dpm_list)) {
		Unlock dpm_list_mutex
		Goto get_more
	}

(The "For each" loop would have to be written carefully to allow for device removal.)

The total number of iterations should never be large. At the end the PM core would own all the device semaphores and no more devices could be added. Then it would be safe to call each device's suspend() method.

This will remove one of the barriers to eliminating the freezer.

Alan Stern

#224 lore raw

Re: Towards eliminating the freezer

Quoted 36 lines · Alan Stern
Quoted 11 lines · Rafael J. Wysocki
Quoted 5 lines

As with Oliver's suggestion, this would create a locking order violation. Drivers registering children (and thus acquiring dpm_list_mtx) will often already hold the parent's sem. But device_suspend() needs to acquire device sems while holding dpm_list_mtx.

Hmm, but this is done already (ie. device_suspend() acquires device sems while holding dpm_list_mtx in the current code).

What I'm suggesting is not to let device_suspend() release dpm_list_mtx when it's finished. The appended patch illustrates that I mean.

Oh, okay, I see what you mean.

I should have explained earlier that my proposal was meant to be in the context of a previous discussion, where I suggested that device_suspend() should go through a preliminary step of acquiring all the device semaphores. This would have the beneficial effect of blocking all attempts at driver binding or unbinding while a suspend is underway.

Still, this isn't a bad approach. Maybe the following algorithm could be used:

get_more:

	For each device on dpm_list
		Acquire dev->sem
		Move dev from dpm_list to a temporary list
	Lock dpm_list_mutex
	If (!list_empty(dpm_list)) {
		Unlock dpm_list_mutex
		Goto get_more
	}
Quoted 2 lines

(The "For each" loop would have to be written carefully to allow for device removal.)

Hmm, I still don't understand why we can't lock dpm_list_mutex before the "For each" loop (we already do something like this in device_suspend() and device_resume()) and that would simplify things.

It seems that we can do something like this:

device_suspend:
Lock dpm_list_mutex (from now on, new devices cannot be added) For each device on dpm_active, reverse
acquire dev->sem (from now on, no new drivers can bind to dev) suspend(dev)
move dev to dpm_off

device_resume:
For each device on dpm_off
move dev to dpm_active
resume(dev) (this cannot fail)
release dev->sem (allow new drivers to bind to dev)
Unlock dpm_list_mutex (allow new devices to be added)

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#225 lore raw

Re: Towards eliminating the freezer

Quoted 4 lines · Rafael J. Wysocki

Hmm, I still don't understand why we can't lock dpm_list_mutex before the "For each" loop (we already do something like this in device_suspend() and device_resume()) and that would simplify things.

Quoted 8 lines

It seems that we can do something like this:

device_suspend:
Lock dpm_list_mutex (from now on, new devices cannot be added) For each device on dpm_active, reverse
acquire dev->sem (from now on, no new drivers can bind to dev) suspend(dev)
move dev to dpm_off

You have a minor error there; it's necessary to unlock dpm_list_mutex while acquiring dev-sem and then lock it again. But more importantly, this code acquires the device semaphores in the wrong order. They have to be acquired going forward (from the top of the device tree down), not backward.

Here's my proposal in a more explicit form. Before doing device_suspend() we call lock_all_devices():

struct list_head dpm_locked;

static void lock_all_devices()

{
	mutex_lock(&dpm_list_mtx);
	while (!list_empty(&dpm_active)) {
		struct list_head *entry = dpm_active.next;
		struct device *dev = to_device(entry);

		get_device(dev);
		mutex_unlock(&dpm_list_mtx);
		down(&dev->sem);
		mutex_lock(&dpm_list_mtx);

		if (list_empty(entry))		/* Device was removed */
			up(&dev->sem);
		else			/* Move it to the dpm_locked list */
			list_move_tail(entry, &dpm_locked);
		put_device(dev);
	}
}

Then device_suspend() can be simplified:

int device_suspend(pm_message_t state)

{
	int error = 0;

	might_sleep();
	list_for_each_entry_reverse(dev, &dpm_locked, power.entry) {
		error = suspend_device(dev, state);

		if (error) {
			printk(KERN_ERR "Could not suspend device %s: "
				"error %d%s\n",
				kobject_name(&dev->kobj), error,
				error == -EAGAIN ? " (please convert to suspend_late)" : "");
			break;
		}
		list_move(&dev->power.entry, &dpm_off);
	}
	if (error)
		dpm_resume();
	return error;
}

Appropriate changes are needed in the resume pathway as well, together with an unlock_all_devices() routine:

static void unlock_all_devices(void)

{
	while (!list_empty(&dpm_locked)) {
		struct list_head *entry = dpm_locked.prev;
		struct device *dev = to_device(entry);

		list_move(entry, &dpm_active);
		up(&dev->sem);
	}
	mutex_unlock(&dpm_list_mtx);
}

Incidentally, what is dpm_mtx for? It doesn't seem to do anything useful. Is it a relic of the former runtime PM support?

Alan Stern

#226 lore raw

Re: Towards eliminating the freezer

Quoted 15 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki

Hmm, I still don't understand why we can't lock dpm_list_mutex before the "For each" loop (we already do something like this in device_suspend() and device_resume()) and that would simplify things.

Quoted 8 lines

It seems that we can do something like this:

device_suspend:
Lock dpm_list_mutex (from now on, new devices cannot be added) For each device on dpm_active, reverse
acquire dev->sem (from now on, no new drivers can bind to dev) suspend(dev)
move dev to dpm_off

Quoted 2 lines

You have a minor error there; it's necessary to unlock dpm_list_mutex while acquiring dev-sem and then lock it again.

Ah, right, now I see that.

Quoted 3 lines

But more importantly, this code acquires the device semaphores in the wrong order. They have to be acquired going forward (from the top of the device tree down), not backward.

Yes, I've overlooked that too.

Quoted 28 lines

Here's my proposal in a more explicit form. Before doing device_suspend() we call lock_all_devices():

struct list_head dpm_locked;

static void lock_all_devices()

{
	mutex_lock(&dpm_list_mtx);
	while (!list_empty(&dpm_active)) {
		struct list_head *entry = dpm_active.next;
		struct device *dev = to_device(entry);

		get_device(dev);
		mutex_unlock(&dpm_list_mtx);
		down(&dev->sem);
		mutex_lock(&dpm_list_mtx);

		if (list_empty(entry))		/* Device was removed */
			up(&dev->sem);
		else			/* Move it to the dpm_locked list */
			list_move_tail(entry, &dpm_locked);
		put_device(dev);
	}
}

Then device_suspend() can be simplified:

int device_suspend(pm_message_t state)

Quoted 15 lines
{
	int error = 0;

	might_sleep();
	list_for_each_entry_reverse(dev, &dpm_locked, power.entry) {
		error = suspend_device(dev, state);

		if (error) {
			printk(KERN_ERR "Could not suspend device %s: "
				"error %d%s\n",
				kobject_name(&dev->kobj), error,
				error == -EAGAIN ? " (please convert to suspend_late)" : "");
			break;
		}
		list_move(&dev->power.entry, &dpm_off);

Is that safe with list_for_each_entry_reverse?

Quoted 8 lines
	}
	if (error)
		dpm_resume();
	return error;
}

Appropriate changes are needed in the resume pathway as well, together with an unlock_all_devices() routine:

Sure.

Quoted 11 lines

static void unlock_all_devices(void)

{
	while (!list_empty(&dpm_locked)) {
		struct list_head *entry = dpm_locked.prev;
		struct device *dev = to_device(entry);

		list_move(entry, &dpm_active);
		up(&dev->sem);
	}
	mutex_unlock(&dpm_list_mtx);
}

Yes, that looks fine.

So, who's writing the patch? ;-)

Quoted 2 lines

Incidentally, what is dpm_mtx for? It doesn't seem to do anything useful. Is it a relic of the former runtime PM support?

I think so. IMO it can be removed.

I also think it would be nicer to have all of the functions in drivers/base/power/{main|suspend|resume}.c moved to one file.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#227 lore raw

Re: Towards eliminating the freezer

Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines

Then device_suspend() can be simplified:

int device_suspend(pm_message_t state)

{
	int error = 0;

	might_sleep();
	list_for_each_entry_reverse(dev, &dpm_locked, power.entry) {
		error = suspend_device(dev, state);

		if (error) {
			printk(KERN_ERR "Could not suspend device %s: "
				"error %d%s\n",
				kobject_name(&dev->kobj), error,
				error == -EAGAIN ? " (please convert to suspend_late)" : "");
			break;
		}
		list_move(&dev->power.entry, &dpm_off);
Quoted 1 line

Is that safe with list_for_each_entry_reverse?

No. I guess it'll have to resemble the other code.

Quoted 3 lines

Yes, that looks fine.

So, who's writing the patch? ;-)

I can do it. You haven't made any changes to this part of the code, have you? My work tends to be based on Linus's tree, not -mm.

Something to watch out for: With all the extra locking, we run the risk of blocking the keventd workqueue. This may or may not matter, but to be safe perhaps there should be a new general-purpose workqueue which _expects_ to block (or freeze) during suspends. Any work routine that involves adding or removing a device should go on the new workqueue.

Quoted 7 lines
Quoted 2 lines

Incidentally, what is dpm_mtx for? It doesn't seem to do anything useful. Is it a relic of the former runtime PM support?

I think so. IMO it can be removed.

I also think it would be nicer to have all of the functions in drivers/base/power/{main|suspend|resume}.c moved to one file.

Yes, they are all similar enough that there isn't much point keeping them separate.

Alan Stern

#228 lore raw

Re: Towards eliminating the freezer

In reply to Rafael J. Wysocki
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines

Then device_suspend() can be simplified:

int device_suspend(pm_message_t state)

{
	int error = 0;

	might_sleep();
	list_for_each_entry_reverse(dev, &dpm_locked, power.entry) {
		error = suspend_device(dev, state);

		if (error) {
			printk(KERN_ERR "Could not suspend device %s: "
				"error %d%s\n",
				kobject_name(&dev->kobj), error,
				error == -EAGAIN ? " (please convert to suspend_late)" : "");
			break;
		}
		list_move(&dev->power.entry, &dpm_off);
Quoted 1 line

Is that safe with list_for_each_entry_reverse?

No. I guess it'll have to resemble the other code.

Quoted 3 lines

Yes, that looks fine.

So, who's writing the patch? ;-)

I can do it. You haven't made any changes to this part of the code, have you? My work tends to be based on Linus's tree, not -mm.

Something to watch out for: With all the extra locking, we run the risk of blocking the keventd workqueue. This may or may not matter, but to be safe perhaps there should be a new general-purpose workqueue which _expects_ to block (or freeze) during suspends. Any work routine that involves adding or removing a device should go on the new workqueue.

Quoted 7 lines
Quoted 2 lines

Incidentally, what is dpm_mtx for? It doesn't seem to do anything useful. Is it a relic of the former runtime PM support?

I think so. IMO it can be removed.

I also think it would be nicer to have all of the functions in drivers/base/power/{main|suspend|resume}.c moved to one file.

Yes, they are all similar enough that there isn't much point keeping them separate.

Alan Stern

#229 lore raw

Re: Towards eliminating the freezer

Quoted 23 lines · Alan Stern
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines

Then device_suspend() can be simplified:

int device_suspend(pm_message_t state)

{
	int error = 0;

	might_sleep();
	list_for_each_entry_reverse(dev, &dpm_locked, power.entry) {
		error = suspend_device(dev, state);

		if (error) {
			printk(KERN_ERR "Could not suspend device %s: "
				"error %d%s\n",
				kobject_name(&dev->kobj), error,
				error == -EAGAIN ? " (please convert to suspend_late)" : "");
			break;
		}
		list_move(&dev->power.entry, &dpm_off);
Quoted 1 line

Is that safe with list_for_each_entry_reverse?

Quoted 8 lines

No. I guess it'll have to resemble the other code.

Quoted 3 lines

Yes, that looks fine.

So, who's writing the patch? ;-)

I can do it. You haven't made any changes to this part of the code, have you?

Yes, I have, quite recently. :-)

Quoted 1 line

My work tends to be based on Linus's tree, not -mm.

At the moment they are pretty much in line, at least as far as this code is concerned. Anyway, I'm trying to keep track of PM-related patches, at http://www.sisk.pl/kernel/hibernation_and_suspend/2.6.23-rc1/

Quoted 5 lines

Something to watch out for: With all the extra locking, we run the risk of blocking the keventd workqueue. This may or may not matter, but to be safe perhaps there should be a new general-purpose workqueue which _expects_ to block (or freeze) during suspends. Any work routine that involves adding or removing a device should go on the new workqueue.

Yes, this sounds like a good idea. Still, I think we can check if there are problems with the keventd workqueue alone, first.

Quoted 10 lines
Quoted 7 lines
Quoted 2 lines

Incidentally, what is dpm_mtx for? It doesn't seem to do anything useful. Is it a relic of the former runtime PM support?

I think so. IMO it can be removed.

I also think it would be nicer to have all of the functions in drivers/base/power/{main|suspend|resume}.c moved to one file.

Yes, they are all similar enough that there isn't much point keeping them separate.

Plus some variables might be made static, like dpm_off or even dpm_list_mtx.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#230 lore raw

Re: Towards eliminating the freezer

Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines
Quoted 1 line

So, who's writing the patch? ;-)

I can do it. You haven't made any changes to this part of the code, have you?

Quoted 7 lines

Yes, I have, quite recently. :-)

Quoted 1 line

My work tends to be based on Linus's tree, not -mm.

At the moment they are pretty much in line, at least as far as this code is concerned. Anyway, I'm trying to keep track of PM-related patches, at http://www.sisk.pl/kernel/hibernation_and_suspend/2.6.23-rc1/

I got your snapshot file. None of the patches in it modify anything in drivers/base/power/*, so there shouldn't be any interference.

By the way, just checking: Apparently when device_power_down() in suspend.c calls sysdev_suspend(), if there's an error it doesn't then call dpm_power_up(). Is it correct to assume this is a bug?

Alan Stern

#231 lore raw

Re: Towards eliminating the freezer

Quoted 9 lines · Alan Stern
Quoted 7 lines · Rafael J. Wysocki
Quoted 4 lines
Quoted 1 line

So, who's writing the patch? ;-)

I can do it. You haven't made any changes to this part of the code, have you?

Yes, I have, quite recently. :-)

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

My work tends to be based on Linus's tree, not -mm.

At the moment they are pretty much in line, at least as far as this code is concerned. Anyway, I'm trying to keep track of PM-related patches, at http://www.sisk.pl/kernel/hibernation_and_suspend/2.6.23-rc1/

I got your snapshot file. None of the patches in it modify anything in drivers/base/power/*, so there shouldn't be any interference.

I think that's correct.

Quoted 3 lines

By the way, just checking: Apparently when device_power_down() in suspend.c calls sysdev_suspend(), if there's an error it doesn't then call dpm_power_up(). Is it correct to assume this is a bug?

Yes.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#232 lore raw

Re: Towards eliminating the freezer

In reply to Alan Stern
Quoted 23 lines · Alan Stern
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines

Then device_suspend() can be simplified:

int device_suspend(pm_message_t state)

{
	int error = 0;

	might_sleep();
	list_for_each_entry_reverse(dev, &dpm_locked, power.entry) {
		error = suspend_device(dev, state);

		if (error) {
			printk(KERN_ERR "Could not suspend device %s: "
				"error %d%s\n",
				kobject_name(&dev->kobj), error,
				error == -EAGAIN ? " (please convert to suspend_late)" : "");
			break;
		}
		list_move(&dev->power.entry, &dpm_off);
Quoted 1 line

Is that safe with list_for_each_entry_reverse?

Quoted 8 lines

No. I guess it'll have to resemble the other code.

Quoted 3 lines

Yes, that looks fine.

So, who's writing the patch? ;-)

I can do it. You haven't made any changes to this part of the code, have you?

Yes, I have, quite recently. :-)

Quoted 1 line

My work tends to be based on Linus's tree, not -mm.

At the moment they are pretty much in line, at least as far as this code is concerned. Anyway, I'm trying to keep track of PM-related patches, at http://www.sisk.pl/kernel/hibernation_and_suspend/2.6.23-rc1/

Quoted 5 lines

Something to watch out for: With all the extra locking, we run the risk of blocking the keventd workqueue. This may or may not matter, but to be safe perhaps there should be a new general-purpose workqueue which _expects_ to block (or freeze) during suspends. Any work routine that involves adding or removing a device should go on the new workqueue.

Yes, this sounds like a good idea. Still, I think we can check if there are problems with the keventd workqueue alone, first.

Quoted 10 lines
Quoted 7 lines
Quoted 2 lines

Incidentally, what is dpm_mtx for? It doesn't seem to do anything useful. Is it a relic of the former runtime PM support?

I think so. IMO it can be removed.

I also think it would be nicer to have all of the functions in drivers/base/power/{main|suspend|resume}.c moved to one file.

Yes, they are all similar enough that there isn't much point keeping them separate.

Plus some variables might be made static, like dpm_off or even dpm_list_mtx.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#233 lore raw

Re: Towards eliminating the freezer

In reply to Alan Stern
Quoted 15 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki

Hmm, I still don't understand why we can't lock dpm_list_mutex before the "For each" loop (we already do something like this in device_suspend() and device_resume()) and that would simplify things.

Quoted 8 lines

It seems that we can do something like this:

device_suspend:
Lock dpm_list_mutex (from now on, new devices cannot be added) For each device on dpm_active, reverse
acquire dev->sem (from now on, no new drivers can bind to dev) suspend(dev)
move dev to dpm_off

Quoted 2 lines

You have a minor error there; it's necessary to unlock dpm_list_mutex while acquiring dev-sem and then lock it again.

Ah, right, now I see that.

Quoted 3 lines

But more importantly, this code acquires the device semaphores in the wrong order. They have to be acquired going forward (from the top of the device tree down), not backward.

Yes, I've overlooked that too.

Quoted 28 lines

Here's my proposal in a more explicit form. Before doing device_suspend() we call lock_all_devices():

struct list_head dpm_locked;

static void lock_all_devices()

{
	mutex_lock(&dpm_list_mtx);
	while (!list_empty(&dpm_active)) {
		struct list_head *entry = dpm_active.next;
		struct device *dev = to_device(entry);

		get_device(dev);
		mutex_unlock(&dpm_list_mtx);
		down(&dev->sem);
		mutex_lock(&dpm_list_mtx);

		if (list_empty(entry))		/* Device was removed */
			up(&dev->sem);
		else			/* Move it to the dpm_locked list */
			list_move_tail(entry, &dpm_locked);
		put_device(dev);
	}
}

Then device_suspend() can be simplified:

int device_suspend(pm_message_t state)

Quoted 15 lines
{
	int error = 0;

	might_sleep();
	list_for_each_entry_reverse(dev, &dpm_locked, power.entry) {
		error = suspend_device(dev, state);

		if (error) {
			printk(KERN_ERR "Could not suspend device %s: "
				"error %d%s\n",
				kobject_name(&dev->kobj), error,
				error == -EAGAIN ? " (please convert to suspend_late)" : "");
			break;
		}
		list_move(&dev->power.entry, &dpm_off);

Is that safe with list_for_each_entry_reverse?

Quoted 8 lines
	}
	if (error)
		dpm_resume();
	return error;
}

Appropriate changes are needed in the resume pathway as well, together with an unlock_all_devices() routine:

Sure.

Quoted 11 lines

static void unlock_all_devices(void)

{
	while (!list_empty(&dpm_locked)) {
		struct list_head *entry = dpm_locked.prev;
		struct device *dev = to_device(entry);

		list_move(entry, &dpm_active);
		up(&dev->sem);
	}
	mutex_unlock(&dpm_list_mtx);
}

Yes, that looks fine.

So, who's writing the patch? ;-)

Quoted 2 lines

Incidentally, what is dpm_mtx for? It doesn't seem to do anything useful. Is it a relic of the former runtime PM support?

I think so. IMO it can be removed.

I also think it would be nicer to have all of the functions in drivers/base/power/{main|suspend|resume}.c moved to one file.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#234 lore raw

Re: Towards eliminating the freezer

In reply to Alan Stern
Quoted 36 lines · Alan Stern
Quoted 11 lines · Rafael J. Wysocki
Quoted 5 lines

As with Oliver's suggestion, this would create a locking order violation. Drivers registering children (and thus acquiring dpm_list_mtx) will often already hold the parent's sem. But device_suspend() needs to acquire device sems while holding dpm_list_mtx.

Hmm, but this is done already (ie. device_suspend() acquires device sems while holding dpm_list_mtx in the current code).

What I'm suggesting is not to let device_suspend() release dpm_list_mtx when it's finished. The appended patch illustrates that I mean.

Oh, okay, I see what you mean.

I should have explained earlier that my proposal was meant to be in the context of a previous discussion, where I suggested that device_suspend() should go through a preliminary step of acquiring all the device semaphores. This would have the beneficial effect of blocking all attempts at driver binding or unbinding while a suspend is underway.

Still, this isn't a bad approach. Maybe the following algorithm could be used:

get_more:

	For each device on dpm_list
		Acquire dev->sem
		Move dev from dpm_list to a temporary list
	Lock dpm_list_mutex
	If (!list_empty(dpm_list)) {
		Unlock dpm_list_mutex
		Goto get_more
	}
Quoted 2 lines

(The "For each" loop would have to be written carefully to allow for device removal.)

Hmm, I still don't understand why we can't lock dpm_list_mutex before the "For each" loop (we already do something like this in device_suspend() and device_resume()) and that would simplify things.

It seems that we can do something like this:

device_suspend:
Lock dpm_list_mutex (from now on, new devices cannot be added) For each device on dpm_active, reverse
acquire dev->sem (from now on, no new drivers can bind to dev) suspend(dev)
move dev to dpm_off

device_resume:
For each device on dpm_off
move dev to dpm_active
resume(dev) (this cannot fail)
release dev->sem (allow new drivers to bind to dev)
Unlock dpm_list_mutex (allow new devices to be added)

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#235 lore raw

Re: Towards eliminating the freezer

In reply to Alan Stern
Quoted 34 lines · Alan Stern
Quoted 27 lines · Rafael J. Wysocki
Quoted 18 lines

Now here's an idea which might work. Can we require every caller of device_add() to hold some existing device's semaphore? Normally it would be the semaphore of the new device's parent, but it could be a higher ancestor. There even could be a single "root" semaphore for drivers registering a top-level device with no parent.

(Some testing shows that during startup things like ACPI and IDE don't fulfill this requirement, so maybe we should require it only after userspace has begun running. After all, the system can't suspend until then.)

It seems like a reasonable sort of thing to do. Hotplugged devices tend to be registered as they are discovered by their parent's driver, so it shouldn't be too much to ask that the parent's semaphore be held when the new device is registered. Static devices generally aren't quite so nice; the serial and floppy drivers in particular would need a little work (and probably some other drivers too).

Quoted 3 lines

If we do this, then once the PM core has acquired the semaphore for every device it will be guaranteed that no new devices can be added. It would be a simple solution to a rather nasty problem.

Hmm, in device_pm_add() and device_pm_remove() we acquire dpm_list_mtx which also is acquired by device_suspend() and device_resume(). Thus, every attempt to register a new device or unregister an existing one will be blocked while either device_suspend() or device_resume() is running.

Quoted 4 lines

If we arrange things so that dpm_list_mtx is acquired, but not released, by device_suspend() and released, but not acquired, by device_resume(), then it won't be possible to register/unregister a device during a suspend-resume cycle.

Quoted 5 lines

As with Oliver's suggestion, this would create a locking order violation. Drivers registering children (and thus acquiring dpm_list_mtx) will often already hold the parent's sem. But device_suspend() needs to acquire device sems while holding dpm_list_mtx.

Hmm, but this is done already (ie. device_suspend() acquires device sems while holding dpm_list_mtx in the current code).

What I'm suggesting is not to let device_suspend() release dpm_list_mtx when it's finished. The appended patch illustrates that I mean.

Greetings,
Rafael

---
dpm_list_mtx is used by the PM core to prevent device objects from being added/removed while device_suspend() and device_resume() are running. However, it should also be impossible to add a device after device_suspend() has finished, because at that time the dpm_active list is empty and adding new devices to it would break the ordering of devices during the next suspend. Thus, it seems reasonable to leave device_suspend() with dpm_list_mtx held and release at the end of device_resume().

In that case device_suspend() and device_resume() cannot be run concurrently and dpm_mtx is no longer needed. Also, it's a bug to run device_resume() after a failing device_suspend(), so the APM code needs to be updated.

---
 arch/i386/kernel/apm.c       |    5 ++++-
 drivers/base/power/main.c    |    1 -
 drivers/base/power/power.h   |    5 -----
 drivers/base/power/resume.c  |    3 ---
 drivers/base/power/suspend.c |    3 ---
 5 files changed, 4 insertions(+), 13 deletions(-)
arch/i386/kernel/apm.c +4 -1
Index: linux-2.6.23-rc1/arch/i386/kernel/apm.c
===================================================================
@@ -1202,7 +1202,9 @@ static int suspend(int vetoable)
 		printk(KERN_CRIT "apm: suspend was vetoed, but suspending anyway.\n");
 	}
 
-	device_suspend(PMSG_SUSPEND);
+	err = device_suspend(PMSG_SUSPEND);
+	if (err)
+		goto send_resume;
 	local_irq_disable();
 	device_power_down(PMSG_SUSPEND);
 
@@ -1224,6 +1226,7 @@ static int suspend(int vetoable)
 	device_power_up();
 	local_irq_enable();
 	device_resume();
+ send_resume:
 	pm_send_all(PM_RESUME, (void *)0);
 	queue_event(APM_NORMAL_RESUME, NULL);
  out:
drivers/base/power/resume.c +0 -3
Index: linux-2.6.23-rc1/drivers/base/power/resume.c
===================================================================
@@ -72,7 +72,6 @@ static int resume_device_early(struct de
  */
 void dpm_resume(void)
 {
-	mutex_lock(&dpm_list_mtx);
 	while(!list_empty(&dpm_off)) {
 		struct list_head * entry = dpm_off.next;
 		struct device * dev = to_device(entry);
@@ -99,9 +98,7 @@ void dpm_resume(void)
 void device_resume(void)
 {
 	might_sleep();
-	mutex_lock(&dpm_mtx);
 	dpm_resume();
-	mutex_unlock(&dpm_mtx);
 }
 
 EXPORT_SYMBOL_GPL(device_resume);
drivers/base/power/suspend.c +0 -3
Index: linux-2.6.23-rc1/drivers/base/power/suspend.c
===================================================================
@@ -127,7 +127,6 @@ int device_suspend(pm_message_t state)
 	int error = 0;
 
 	might_sleep();
-	mutex_lock(&dpm_mtx);
 	mutex_lock(&dpm_list_mtx);
 	while (!list_empty(&dpm_active) && error == 0) {
 		struct list_head * entry = dpm_active.prev;
@@ -153,11 +152,9 @@ int device_suspend(pm_message_t state)
 				error == -EAGAIN ? " (please convert to suspend_late)" : "");
 		put_device(dev);
 	}
-	mutex_unlock(&dpm_list_mtx);
 	if (error)
 		dpm_resume();
 
-	mutex_unlock(&dpm_mtx);
 	return error;
 }
 
drivers/base/power/main.c +0 -1
Index: linux-2.6.23-rc1/drivers/base/power/main.c
===================================================================
@@ -28,7 +28,6 @@ LIST_HEAD(dpm_active);
 LIST_HEAD(dpm_off);
 LIST_HEAD(dpm_off_irq);
 
-DEFINE_MUTEX(dpm_mtx);
 DEFINE_MUTEX(dpm_list_mtx);
 
 int (*platform_enable_wakeup)(struct device *dev, int is_on);
drivers/base/power/power.h +0 -5
Index: linux-2.6.23-rc1/drivers/base/power/power.h
===================================================================
@@ -12,11 +12,6 @@ extern void device_shutdown(void);
  */
 
 /*
- * Used to synchronize global power management operations.
- */
-extern struct mutex dpm_mtx;
-
-/*
  * Used to serialize changes to the dpm_* lists.
  */
 extern struct mutex dpm_list_mtx;
#236 lore raw

Re: Towards eliminating the freezer

In reply to Alan Stern
Quoted 1 line · Alan Stern

[Note changed $SUBJECT]

[--snip--]

Quoted 21 lines

=============================

Now here's an idea which might work. Can we require every caller of device_add() to hold some existing device's semaphore? Normally it would be the semaphore of the new device's parent, but it could be a higher ancestor. There even could be a single "root" semaphore for drivers registering a top-level device with no parent.

(Some testing shows that during startup things like ACPI and IDE don't fulfill this requirement, so maybe we should require it only after userspace has begun running. After all, the system can't suspend until then.)

It seems like a reasonable sort of thing to do. Hotplugged devices tend to be registered as they are discovered by their parent's driver, so it shouldn't be too much to ask that the parent's semaphore be held when the new device is registered. Static devices generally aren't quite so nice; the serial and floppy drivers in particular would need a little work (and probably some other drivers too).

Quoted 3 lines

If we do this, then once the PM core has acquired the semaphore for every device it will be guaranteed that no new devices can be added. It would be a simple solution to a rather nasty problem.

Hmm, in device_pm_add() and device_pm_remove() we acquire dpm_list_mtx which also is acquired by device_suspend() and device_resume(). Thus, every attempt to register a new device or unregister an existing one will be blocked while either device_suspend() or device_resume() is running.

If we arrange things so that dpm_list_mtx is acquired, but not released, by device_suspend() and released, but not acquired, by device_resume(), then it won't be possible to register/unregister a device during a suspend-resume cycle.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#237 lore raw
In reply to Alan Stern

Am Samstag 21 Juli 2007 schrieb Alan Stern:

Quoted 15 lines · Oliver Neukum
Quoted 5 lines
Quoted 3 lines

We already have a pre-suspend notification available for drivers that need to allocate large amounts of memory.

Is that facility fine grained enough?

It's a notifier chain that gets called at several points during the suspend transition. One of those points is right at the start, while userspace is still running and reasonably large amounts of memory can be allocated.

Is it fine-grained enough? I don't know -- hard to tell, since nothing much is using it yet.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

You are correct about the need to delay/stop device addition. I don't know how this can be done in general; each code path calling device_add() may have to be treated individually.

What about the old API?

What old API do you mean?

The find_device() stuff.

Quoted 3 lines
Quoted 1 line

Do we have to block module loading?

No. Registering new drivers is okay, registering new devices is bad.

What if it is a driver for virtual devices that don't need probe() for actual hardware?

Quoted 10 lines

Of course, some modules do want to register a new device in their init method. I don't know what we should do about them. Force the registration to fail, I suppose. How often will people suspend while a module is loading?

Quoted 2 lines

What happens if a scsi error handler is woken? If it cannot be woken, how are errors handled?

Why should the error handler wake up? There isn't supposed to be any I/O going on, hence no errors to handle.

What about shared busses? Firewire, FibreChannel? They can get external resets, etc ...

Regards
Oliver

#238 lore raw
In reply to Alan Stern

Hi!

Quoted 8 lines
Quoted 1 line

Do we have to block module loading?

No. Registering new drivers is okay, registering new devices is bad.

Of course, some modules do want to register a new device in their init method. I don't know what we should do about them. Force the registration to fail, I suppose. How often will people suspend while a module is loading?

Well... plug this pcmcia card into the slot so that I do not have to carry it separately, close the lid and go?

...not that impossible to imagine...
Pavel

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

Hi!

Quoted 8 lines
Quoted 1 line

Do we have to block module loading?

No. Registering new drivers is okay, registering new devices is bad.

Of course, some modules do want to register a new device in their init method. I don't know what we should do about them. Force the registration to fail, I suppose. How often will people suspend while a module is loading?

Well... plug this pcmcia card into the slot so that I do not have to carry it separately, close the lid and go?

...not that impossible to imagine...
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#240 lore raw
Quoted 11 lines · Pavel Machek

Hi!

Quoted 8 lines
Quoted 1 line

Do we have to block module loading?

No. Registering new drivers is okay, registering new devices is bad.

Of course, some modules do want to register a new device in their init method. I don't know what we should do about them. Force the registration to fail, I suppose. How often will people suspend while a module is loading?

Quoted 4 lines

Well... plug this pcmcia card into the slot so that I do not have to carry it separately, close the lid and go?

...not that impossible to imagine...

I useually leave my broadband card in the slot, but not seated. I wouldn't bet against it getting pushed in enough to be detected while putting the laptop in the bag.

David Lang

#241 lore raw
In reply to Pavel Machek
Quoted 11 lines · Pavel Machek

Hi!

Quoted 8 lines
Quoted 1 line

Do we have to block module loading?

No. Registering new drivers is okay, registering new devices is bad.

Of course, some modules do want to register a new device in their init method. I don't know what we should do about them. Force the registration to fail, I suppose. How often will people suspend while a module is loading?

Quoted 4 lines

Well... plug this pcmcia card into the slot so that I do not have to carry it separately, close the lid and go?

...not that impossible to imagine...

I useually leave my broadband card in the slot, but not seated. I wouldn't bet against it getting pushed in enough to be detected while putting the laptop in the bag.

David Lang

#242 lore raw
In reply to Alan Stern

Am Freitag 20 Juli 2007 schrieb Alan Stern:

Quoted 16 lines · Oliver Neukum
Quoted 6 lines

Am Freitag 20 Juli 2007 schrieb Alan Stern:

Quoted 3 lines

Some drivers need the ability to schedule.  Some will need the ability to allocate memory (although GFP_ATOMIC is probably sufficient).  Some will need timers to run.

Quoted 8 lines

Some will have to request firmware. It can add up to some megabytes. In addition, if we don't freeze, some drivers, eg. video drivers, can do allocations in the megabyte range.

It seems to me that without the freezer we will end up with many drivers needing a two step notification process. Furthermore there are requirements on the order of shutting down system facilities, eg. device addition must be stopped before drivers allocate firmware.

Quoted 5 lines

These are really separate issues, since they refer to things that have to happen well before the memory snapshot is captured.

We already have a pre-suspend notification available for drivers that need to allocate large amounts of memory.

Is that facility fine grained enough?

Quoted 3 lines

You are correct about the need to delay/stop device addition. I don't know how this can be done in general; each code path calling device_add() may have to be treated individually.

What about the old API? Do we have to block module loading? What happens if a scsi error handler is woken? If it cannot be woken, how are errors handled?

Regards
Oliver

#243 lore raw
In reply to Alan Stern

Am Freitag 20 Juli 2007 schrieb Alan Stern:

Quoted 3 lines

Some drivers need the ability to schedule.  Some will need the ability to allocate memory (although GFP_ATOMIC is probably sufficient).  Some will need timers to run.

Some will have to request firmware. It can add up to some megabytes. In addition, if we don't freeze, some drivers, eg. video drivers, can do allocations in the megabyte range.

It seems to me that without the freezer we will end up with many drivers needing a two step notification process. Furthermore there are requirements on the order of shutting down system facilities, eg. device addition must be stopped before drivers allocate firmware.

Regards
Oliver

#244 lore raw
In reply to Alan Stern
Quoted 11 lines · Alan Stern
Quoted 8 lines · Milton Miller
Quoted 3 lines

We can't do this unless we have frozen tasks (this way, or another) before
carrying out the entire operation.

What can't we do? We've already worked with the drivers to quesce the
hardware and put any information to resume the device in ram. Now we ask them to put their device in low power mode so we can go to sleep. Even if we schedule, the only thing userspace could touch is memory.

Quoted 4 lines

Userspace can submit I/O requests. Someone will have to audit every driver to make sure that such I/O requests don't cause a quiesced device to become active. If the device is active, it will make the memory snapshot inconsistent with the on-device data.

assuming this is the suspend-from-ram after a kexec back from the write-to-disk kernel I don't think you are correct.

when doing a suspend-to-ram you get to a point where you just don't use any userspace. from that point on you are just walking the device tree putting things into low-power mode. This is the point where we are talking about jumping to.

david Lang

#245 lore raw
Quoted 10 lines · On Fri, 20 Jul 2007 [email protected] wrote:
Quoted 4 lines

Userspace can submit I/O requests. Someone will have to audit every driver to make sure that such I/O requests don't cause a quiesced device to become active. If the device is active, it will make the memory snapshot inconsistent with the on-device data.

assuming this is the suspend-from-ram after a kexec back from the write-to-disk kernel I don't think you are correct.

when doing a suspend-to-ram you get to a point where you just don't use any userspace.

What do you mean? How can you prevent user tasks from running? That's basically what the freezer does, and the whole point of this approach is to eliminate the freezer. Right?

Quoted 3 lines

from that point on you are just walking the device tree putting things into low-power mode. This is the point where we are talking about jumping to.

Yes. And putting things into low-power mode requires the ability to run the scheduler, which means that user tasks can be scheduled, which means that they can run.

Alan Stern

#246 lore raw
Quoted 17 lines · Alan Stern
Quoted 10 lines · On Fri, 20 Jul 2007 [email protected] wrote:
Quoted 4 lines

Userspace can submit I/O requests. Someone will have to audit every driver to make sure that such I/O requests don't cause a quiesced device to become active. If the device is active, it will make the memory snapshot inconsistent with the on-device data.

assuming this is the suspend-from-ram after a kexec back from the write-to-disk kernel I don't think you are correct.

when doing a suspend-to-ram you get to a point where you just don't use any userspace.

What do you mean? How can you prevent user tasks from running? That's basically what the freezer does, and the whole point of this approach is to eliminate the freezer. Right?

Quoted 7 lines
Quoted 3 lines

from that point on you are just walking the device tree putting things into low-power mode. This is the point where we are talking about jumping to.

Yes. And putting things into low-power mode requires the ability to run the scheduler, which means that user tasks can be scheduled, which means that they can run.

I did not know that getting into low-power mode required scheduling.

does it require userspace?

if so this is a problem and I say punt on suspend-to-disk-and-ram until suspend-to-ram is working independantly ;-)

if not, then can you schedule but not consider non-kernel tasks runnable?

freezing all of userspace is easy (see above)

freezing all of kernelspace is easy (unplug all non-boot CPU's and don't schedule)

where freezing gets hard is when you need to partially freeze either one of these.

David Lang

#247 lore raw
In reply to Alan Stern
Quoted 9 lines · Alan Stern
Quoted 8 lines · On Fri, 20 Jul 2007 [email protected] wrote:
Quoted 4 lines

Userspace can submit I/O requests. Someone will have to audit every driver to make sure that such I/O requests don't cause a quiesced device to become active. If the device is active, it will make the memory snapshot inconsistent with the on-device data.

assuming this is the suspend-from-ram after a kexec back from the write-to-disk kernel I don't think you are correct.

Quoted 6 lines
Quoted 2 lines

when doing a suspend-to-ram you get to a point where you just don't use any userspace.

What do you mean? How can you prevent user tasks from running? That's basically what the freezer does, and the whole point of this approach is to eliminate the freezer. Right?

Presumably no tasks at all would be scheduled.

Quoted 7 lines
Quoted 3 lines

from that point on you are just walking the device tree putting things into low-power mode. This is the point where we are talking about jumping to.

Yes. And putting things into low-power mode requires the ability to run the scheduler, which means that user tasks can be scheduled, which means that they can run.

Does it really (fundamentally) require scheduling tasks, particularly in the case that the devices have already been put in the "quiesced" state?

Signature · 1 line
Jeremy Maitin-Shepard
#248 lore raw
In reply to Alan Stern
Quoted 9 lines · Alan Stern
Quoted 8 lines · On Fri, 20 Jul 2007 [email protected] wrote:
Quoted 4 lines

Userspace can submit I/O requests. Someone will have to audit every driver to make sure that such I/O requests don't cause a quiesced device to become active. If the device is active, it will make the memory snapshot inconsistent with the on-device data.

assuming this is the suspend-from-ram after a kexec back from the write-to-disk kernel I don't think you are correct.

Quoted 6 lines
Quoted 2 lines

when doing a suspend-to-ram you get to a point where you just don't use any userspace.

What do you mean? How can you prevent user tasks from running? That's basically what the freezer does, and the whole point of this approach is to eliminate the freezer. Right?

Presumably no tasks at all would be scheduled.

Quoted 7 lines
Quoted 3 lines

from that point on you are just walking the device tree putting things into low-power mode. This is the point where we are talking about jumping to.

Yes. And putting things into low-power mode requires the ability to run the scheduler, which means that user tasks can be scheduled, which means that they can run.

Does it really (fundamentally) require scheduling tasks, particularly in the case that the devices have already been put in the "quiesced" state?

Signature · 1 line
Jeremy Maitin-Shepard
#249 lore raw
Quoted 8 lines · Jeremy Maitin-Shepard
Quoted 6 lines
Quoted 2 lines

when doing a suspend-to-ram you get to a point where you just don't use any userspace.

What do you mean? How can you prevent user tasks from running? That's basically what the freezer does, and the whole point of this approach is to eliminate the freezer. Right?

Presumably no tasks at all would be scheduled.

How would you prevent tasks from being scheduled? How would you prevent drivers from deadlocking because in order to put their device in a low-power state they need to acquire a lock which is held by a user task?

Quoted 10 lines
Quoted 7 lines
Quoted 3 lines

from that point on you are just walking the device tree putting things into low-power mode. This is the point where we are talking about jumping to.

Yes. And putting things into low-power mode requires the ability to run the scheduler, which means that user tasks can be scheduled, which means that they can run.

Does it really (fundamentally) require scheduling tasks, particularly in the case that the devices have already been put in the "quiesced" state?

I can't say for sure. That's the way we have been doing it. It wouldn't be easy to change, because the driver would have to busy-wait during delays -- which would mean it would need to use different code for system-wide suspend and runtime suspend.

Alan Stern

#250 lore raw
Quoted 9 lines · Alan Stern
Quoted 7 lines · Jeremy Maitin-Shepard
Quoted 6 lines
Quoted 2 lines

when doing a suspend-to-ram you get to a point where you just don't use any userspace.

What do you mean? How can you prevent user tasks from running? That's basically what the freezer does, and the whole point of this approach is to eliminate the freezer. Right?

Quoted 6 lines
Quoted 1 line

Presumably no tasks at all would be scheduled.

How would you prevent tasks from being scheduled? How would you prevent drivers from deadlocking because in order to put their device in a low-power state they need to acquire a lock which is held by a user task?

you give up on the suspend becouse you have no way of getting the user task to give up the lock.

however, kernel locks should not be held by user tasks, user tasks are not expected to behave in rational ways, allowing them to compete with kernel tasks for locks is a sure way to get a deadlock or indefinate stall.

what locks are accessed this way?

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

from that point on you are just walking the device tree putting things into low-power mode. This is the point where we are talking about jumping to.

Yes. And putting things into low-power mode requires the ability to run the scheduler, which means that user tasks can be scheduled, which means that they can run.

Quoted 7 lines
Quoted 2 lines

Does it really (fundamentally) require scheduling tasks, particularly in the case that the devices have already been put in the "quiesced" state?

I can't say for sure. That's the way we have been doing it. It wouldn't be easy to change, because the driver would have to busy-wait during delays -- which would mean it would need to use different code for system-wide suspend and runtime suspend.

please define terms so that we are all on the same page

what do you mean by
system-wide suspend
runtime suspend

David Lang

#251 lore raw
In reply to Alan Stern
Quoted 8 lines · Alan Stern
Quoted 7 lines · Jeremy Maitin-Shepard
Quoted 6 lines
Quoted 2 lines

when doing a suspend-to-ram you get to a point where you just don't use any userspace.

What do you mean? How can you prevent user tasks from running? That's basically what the freezer does, and the whole point of this approach is to eliminate the freezer. Right?

Quoted 6 lines
Quoted 1 line

Presumably no tasks at all would be scheduled.

How would you prevent tasks from being scheduled? How would you prevent drivers from deadlocking because in order to put their device in a low-power state they need to acquire a lock which is held by a user task?

Perhaps this isn't an issue once the device is already quiesced. I'm just conjecturing.

[snip]

Signature · 1 line
Jeremy Maitin-Shepard
#252 lore raw
In reply to Alan Stern
Quoted 9 lines · Alan Stern
Quoted 7 lines · Jeremy Maitin-Shepard
Quoted 6 lines
Quoted 2 lines

when doing a suspend-to-ram you get to a point where you just don't use any userspace.

What do you mean? How can you prevent user tasks from running? That's basically what the freezer does, and the whole point of this approach is to eliminate the freezer. Right?

Quoted 6 lines
Quoted 1 line

Presumably no tasks at all would be scheduled.

How would you prevent tasks from being scheduled? How would you prevent drivers from deadlocking because in order to put their device in a low-power state they need to acquire a lock which is held by a user task?

you give up on the suspend becouse you have no way of getting the user task to give up the lock.

however, kernel locks should not be held by user tasks, user tasks are not expected to behave in rational ways, allowing them to compete with kernel tasks for locks is a sure way to get a deadlock or indefinate stall.

what locks are accessed this way?

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

from that point on you are just walking the device tree putting things into low-power mode. This is the point where we are talking about jumping to.

Yes. And putting things into low-power mode requires the ability to run the scheduler, which means that user tasks can be scheduled, which means that they can run.

Quoted 7 lines
Quoted 2 lines

Does it really (fundamentally) require scheduling tasks, particularly in the case that the devices have already been put in the "quiesced" state?

I can't say for sure. That's the way we have been doing it. It wouldn't be easy to change, because the driver would have to busy-wait during delays -- which would mean it would need to use different code for system-wide suspend and runtime suspend.

please define terms so that we are all on the same page

what do you mean by
system-wide suspend
runtime suspend

David Lang

#253 lore raw

Hi.

Quoted 18 lines · On Saturday 21 July 2007 08:43:20 [email protected] wrote:
Quoted 9 lines · Alan Stern
Quoted 7 lines · Jeremy Maitin-Shepard
Quoted 6 lines
Quoted 2 lines

when doing a suspend-to-ram you get to a point where you just don't use any userspace.

What do you mean? How can you prevent user tasks from running? That's basically what the freezer does, and the whole point of this approach is to eliminate the freezer. Right?

Quoted 6 lines
Quoted 1 line

Presumably no tasks at all would be scheduled.

How would you prevent tasks from being scheduled? How would you prevent drivers from deadlocking because in order to put their device in a low-power state they need to acquire a lock which is held by a user task?

Quoted 8 lines

you give up on the suspend becouse you have no way of getting the user task to give up the lock.

however, kernel locks should not be held by user tasks, user tasks are not expected to behave in rational ways, allowing them to compete with kernel tasks for locks is a sure way to get a deadlock or indefinate stall.

what locks are accessed this way?

Any userspace process can do a syscall. In the process of the syscall, it can take kernel locks, and it can schedule (eg, while seeking to take a second lock).

Regards,

Nigel

#254 lore raw
In reply to [email protected]

Hi.

Quoted 18 lines · On Saturday 21 July 2007 08:43:20 [email protected] wrote:
Quoted 9 lines · Alan Stern
Quoted 7 lines · Jeremy Maitin-Shepard
Quoted 6 lines
Quoted 2 lines

when doing a suspend-to-ram you get to a point where you just don't use any userspace.

What do you mean? How can you prevent user tasks from running? That's basically what the freezer does, and the whole point of this approach is to eliminate the freezer. Right?

Quoted 6 lines
Quoted 1 line

Presumably no tasks at all would be scheduled.

How would you prevent tasks from being scheduled? How would you prevent drivers from deadlocking because in order to put their device in a low-power state they need to acquire a lock which is held by a user task?

Quoted 8 lines

you give up on the suspend becouse you have no way of getting the user task to give up the lock.

however, kernel locks should not be held by user tasks, user tasks are not expected to behave in rational ways, allowing them to compete with kernel tasks for locks is a sure way to get a deadlock or indefinate stall.

what locks are accessed this way?

Any userspace process can do a syscall. In the process of the syscall, it can take kernel locks, and it can schedule (eg, while seeking to take a second lock).

Regards,

Nigel

#255 lore raw
In reply to [email protected]
Quoted 7 lines · On Fri, 20 Jul 2007 [email protected] wrote:
Quoted 4 lines

How would you prevent tasks from being scheduled? How would you prevent drivers from deadlocking because in order to put their device in a low-power state they need to acquire a lock which is held by a user task?

you give up on the suspend becouse you have no way of getting the user task to give up the lock.

Once the deadlock has occurred it's too late. You can't give up; in fact you can't do anything at all. The system has hung.

Quoted 3 lines

however, kernel locks should not be held by user tasks, user tasks are not expected to behave in rational ways, allowing them to compete with kernel tasks for locks is a sure way to get a deadlock or indefinate stall.

What on Earth are you talking about? "Kernel locks should not be held by user tasks"? Then who _should_ hold them? You are aware, I hope, that down() and mutex_lock() can be called only in process context?

Quoted 1 line

what locks are accessed this way?

Lots of them. For example, most drivers won't want a suspend to occur right in the middle of an I/O transfer. To prevent this, the driver might use a mutex. The task doing the I/O (which will be a user task) acquires the mutex during a transfer and the suspend routine acquires the mutex while quiescing the device.

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

Does it really (fundamentally) require scheduling tasks, particularly in the case that the devices have already been put in the "quiesced" state?

I can't say for sure. That's the way we have been doing it. It wouldn't be easy to change, because the driver would have to busy-wait during delays -- which would mean it would need to use different code for system-wide suspend and runtime suspend.

please define terms so that we are all on the same page

Please read Documentation/power/devices.txt.

Quoted 2 lines

what do you mean by
system-wide suspend

That's what you would call standby, suspend-to-RAM, or hibernate. The entire system goes to sleep.

Quoted 1 line

runtime suspend

That's when an individual device is placed in a low-power state to save energy while it isn't being used. The system as a whole remains awake and the device will be resumed the next time it is needed for anything.

Alan Stern

#256 lore raw
In reply to [email protected]
Quoted 7 lines · On Fri, 20 Jul 2007 [email protected] wrote:
Quoted 4 lines

How would you prevent tasks from being scheduled? How would you prevent drivers from deadlocking because in order to put their device in a low-power state they need to acquire a lock which is held by a user task?

you give up on the suspend becouse you have no way of getting the user task to give up the lock.

Once the deadlock has occurred it's too late. You can't give up; in fact you can't do anything at all. The system has hung.

Quoted 3 lines

however, kernel locks should not be held by user tasks, user tasks are not expected to behave in rational ways, allowing them to compete with kernel tasks for locks is a sure way to get a deadlock or indefinate stall.

What on Earth are you talking about? "Kernel locks should not be held by user tasks"? Then who _should_ hold them? You are aware, I hope, that down() and mutex_lock() can be called only in process context?

Quoted 1 line

what locks are accessed this way?

Lots of them. For example, most drivers won't want a suspend to occur right in the middle of an I/O transfer. To prevent this, the driver might use a mutex. The task doing the I/O (which will be a user task) acquires the mutex during a transfer and the suspend routine acquires the mutex while quiescing the device.

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

Does it really (fundamentally) require scheduling tasks, particularly in the case that the devices have already been put in the "quiesced" state?

I can't say for sure. That's the way we have been doing it. It wouldn't be easy to change, because the driver would have to busy-wait during delays -- which would mean it would need to use different code for system-wide suspend and runtime suspend.

please define terms so that we are all on the same page

Please read Documentation/power/devices.txt.

Quoted 2 lines

what do you mean by
system-wide suspend

That's what you would call standby, suspend-to-RAM, or hibernate. The entire system goes to sleep.

Quoted 1 line

runtime suspend

That's when an individual device is placed in a low-power state to save energy while it isn't being used. The system as a whole remains awake and the device will be resumed the next time it is needed for anything.

Alan Stern

#257 lore raw
Quoted 21 lines · Alan Stern
Quoted 7 lines · On Fri, 20 Jul 2007 [email protected] wrote:
Quoted 4 lines

How would you prevent tasks from being scheduled? How would you prevent drivers from deadlocking because in order to put their device in a low-power state they need to acquire a lock which is held by a user task?

you give up on the suspend becouse you have no way of getting the user task to give up the lock.

Once the deadlock has occurred it's too late. You can't give up; in fact you can't do anything at all. The system has hung.

Quoted 3 lines

however, kernel locks should not be held by user tasks, user tasks are not expected to behave in rational ways, allowing them to compete with kernel tasks for locks is a sure way to get a deadlock or indefinate stall.

What on Earth are you talking about? "Kernel locks should not be held by user tasks"? Then who _should_ hold them? You are aware, I hope, that down() and mutex_lock() can be called only in process context?

Quoted 7 lines
Quoted 1 line

what locks are accessed this way?

Lots of them. For example, most drivers won't want a suspend to occur right in the middle of an I/O transfer. To prevent this, the driver might use a mutex. The task doing the I/O (which will be a user task) acquires the mutex during a transfer and the suspend routine acquires the mutex while quiescing the device.

wait a min her, it's possible we are misunderstanding each other.

as I see it.

if userspace can aquire locks that prevent the kernel from shutting off (or doing anything else in particular) then it's possible for misbehaving userspace code to stop the kernel by simply choosing to never release the lock.

this would be a trivial DOS from userspace.

now, if you are talking instead about the fact that when userspace makes a system call, the execution of that system call involves aquiring locks that are released before the system call completes you have a very different situation.

if you have locks that are held across system calls then you should already have problems. becouse you can't count on userspace ever taking whatever action is appropriate to release the lock.

what am I missing that concerns you so much?

Quoted 11 lines
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

Does it really (fundamentally) require scheduling tasks, particularly in the case that the devices have already been put in the "quiesced" state?

I can't say for sure. That's the way we have been doing it. It wouldn't be easy to change, because the driver would have to busy-wait during delays -- which would mean it would need to use different code for system-wide suspend and runtime suspend.

please define terms so that we are all on the same page

Please read Documentation/power/devices.txt.

I have done so.

Quoted 6 lines
Quoted 2 lines

what do you mean by
system-wide suspend

That's what you would call standby, suspend-to-RAM, or hibernate. The entire system goes to sleep.

Quoted 6 lines
Quoted 1 line

runtime suspend

That's when an individual device is placed in a low-power state to save energy while it isn't being used. The system as a whole remains awake and the device will be resumed the next time it is needed for anything.

thanks for the defintitions.

having read through Documentation/power/devices.txt I remain convinced that you are making a fundamental mistake.

you are designing a system that will only work if everything (every driver, every state transition) participates fully in the process at all times. You started with the facts 'this is the info that ACPI provides and this is how it is designed to be used' and worked from there instead of looking to see what the kernel really needed and figuring how to provide a good interface for that that happens to be implemented (today) with ACPI. (a proper power management framework shouldn't care if you have ACPI, APM, or some other method of controlling the devices)

this leads to resume functions that can only work if the proper suspend function was called rather then makeing 'resume' just mean 'go to full operation', which is the same thing that gets called when the device is first initialized. internally it can examine the hardware and follow different paths depending on what it finds the current state of the hardware is, but the outside world (including the rest of the kernel) should not care. the fact that the rest of the kernel needs to know if it should call 'resume' or 'initialize' is a failure in the abstraction.

in fact, a better abstraction would be something like

report_power_modes
which would return a series of modes (sorted only by modeID) modeID, %power_used_in_this_mode, %capability_in_this_mode (I would make mode 0 always be complete power off, and mode 1 always be
full capacity)

report_power_mode_speed
which would return a matrix giving how long it takes to transition from
any mode to any other mode. this should be a relative number, not an absolute number since it will be different at different clock speeds.

set_operational_mode(modeID)
which would take you from whatever mode you are in now to the requested
mode.

most devices would report the simple list of modes

0,0,0
1,100,100

with a mode_speed matrix of
0 1
---
0|0 1
1|1 0

it may be that there is more info needed for the powr management engine to decide what modes it wants to put things into, if so identify what type of info you need and add another column to the modes list. for example:
you may want to add a flag for 'does this mode allow downstream devices
to operate?'
you may want to make a mode for 'this mode doesn't allow any new
requests, but continues to process pending requests' and have a flag that indicates this

currently it looks like there's no way to find out what modes are available, and you have to know what mode something is in currently before you can request it change to a different mode. both of these prevent effective power management without encoding intimate knowledge of the capability of the particular hardware in your management tool.

some of this may be discoverable via the ACPI interface (it's not talked about much in the devices.txt file), but the mode setting is still wrong.

note that in the example above it's accpetable for a driver to cache what mode it thinks the device is in, but it needs to properly set the new mode even if it's cached data is incorrect.

this approach would allow the transition of ALL drivers to the new mode of operation in one fell swoop, and then adding additional power management features is just adding to the existing list rather then implementing new functions.

David Lang

#258 lore raw
In reply to Alan Stern
Quoted 21 lines · Alan Stern
Quoted 7 lines · On Fri, 20 Jul 2007 [email protected] wrote:
Quoted 4 lines

How would you prevent tasks from being scheduled? How would you prevent drivers from deadlocking because in order to put their device in a low-power state they need to acquire a lock which is held by a user task?

you give up on the suspend becouse you have no way of getting the user task to give up the lock.

Once the deadlock has occurred it's too late. You can't give up; in fact you can't do anything at all. The system has hung.

Quoted 3 lines

however, kernel locks should not be held by user tasks, user tasks are not expected to behave in rational ways, allowing them to compete with kernel tasks for locks is a sure way to get a deadlock or indefinate stall.

What on Earth are you talking about? "Kernel locks should not be held by user tasks"? Then who _should_ hold them? You are aware, I hope, that down() and mutex_lock() can be called only in process context?

Quoted 7 lines
Quoted 1 line

what locks are accessed this way?

Lots of them. For example, most drivers won't want a suspend to occur right in the middle of an I/O transfer. To prevent this, the driver might use a mutex. The task doing the I/O (which will be a user task) acquires the mutex during a transfer and the suspend routine acquires the mutex while quiescing the device.

wait a min her, it's possible we are misunderstanding each other.

as I see it.

if userspace can aquire locks that prevent the kernel from shutting off (or doing anything else in particular) then it's possible for misbehaving userspace code to stop the kernel by simply choosing to never release the lock.

this would be a trivial DOS from userspace.

now, if you are talking instead about the fact that when userspace makes a system call, the execution of that system call involves aquiring locks that are released before the system call completes you have a very different situation.

if you have locks that are held across system calls then you should already have problems. becouse you can't count on userspace ever taking whatever action is appropriate to release the lock.

what am I missing that concerns you so much?

Quoted 11 lines
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

Does it really (fundamentally) require scheduling tasks, particularly in the case that the devices have already been put in the "quiesced" state?

I can't say for sure. That's the way we have been doing it. It wouldn't be easy to change, because the driver would have to busy-wait during delays -- which would mean it would need to use different code for system-wide suspend and runtime suspend.

please define terms so that we are all on the same page

Please read Documentation/power/devices.txt.

I have done so.

Quoted 6 lines
Quoted 2 lines

what do you mean by
system-wide suspend

That's what you would call standby, suspend-to-RAM, or hibernate. The entire system goes to sleep.

Quoted 6 lines
Quoted 1 line

runtime suspend

That's when an individual device is placed in a low-power state to save energy while it isn't being used. The system as a whole remains awake and the device will be resumed the next time it is needed for anything.

thanks for the defintitions.

having read through Documentation/power/devices.txt I remain convinced that you are making a fundamental mistake.

you are designing a system that will only work if everything (every driver, every state transition) participates fully in the process at all times. You started with the facts 'this is the info that ACPI provides and this is how it is designed to be used' and worked from there instead of looking to see what the kernel really needed and figuring how to provide a good interface for that that happens to be implemented (today) with ACPI. (a proper power management framework shouldn't care if you have ACPI, APM, or some other method of controlling the devices)

this leads to resume functions that can only work if the proper suspend function was called rather then makeing 'resume' just mean 'go to full operation', which is the same thing that gets called when the device is first initialized. internally it can examine the hardware and follow different paths depending on what it finds the current state of the hardware is, but the outside world (including the rest of the kernel) should not care. the fact that the rest of the kernel needs to know if it should call 'resume' or 'initialize' is a failure in the abstraction.

in fact, a better abstraction would be something like

report_power_modes
which would return a series of modes (sorted only by modeID) modeID, %power_used_in_this_mode, %capability_in_this_mode (I would make mode 0 always be complete power off, and mode 1 always be
full capacity)

report_power_mode_speed
which would return a matrix giving how long it takes to transition from
any mode to any other mode. this should be a relative number, not an absolute number since it will be different at different clock speeds.

set_operational_mode(modeID)
which would take you from whatever mode you are in now to the requested
mode.

most devices would report the simple list of modes

0,0,0
1,100,100

with a mode_speed matrix of
0 1
---
0|0 1
1|1 0

it may be that there is more info needed for the powr management engine to decide what modes it wants to put things into, if so identify what type of info you need and add another column to the modes list. for example:
you may want to add a flag for 'does this mode allow downstream devices
to operate?'
you may want to make a mode for 'this mode doesn't allow any new
requests, but continues to process pending requests' and have a flag that indicates this

currently it looks like there's no way to find out what modes are available, and you have to know what mode something is in currently before you can request it change to a different mode. both of these prevent effective power management without encoding intimate knowledge of the capability of the particular hardware in your management tool.

some of this may be discoverable via the ACPI interface (it's not talked about much in the devices.txt file), but the mode setting is still wrong.

note that in the example above it's accpetable for a driver to cache what mode it thinks the device is in, but it needs to properly set the new mode even if it's cached data is incorrect.

this approach would allow the transition of ALL drivers to the new mode of operation in one fell swoop, and then adding additional power management features is just adding to the existing list rather then implementing new functions.

David Lang

#259 lore raw
Quoted 1 line · On Sat, 21 Jul 2007 [email protected] wrote:

wait a min her, it's possible we are misunderstanding each other.

I'd describe it as: You are misunderstanding me. :-)

Quoted 8 lines

as I see it.

if userspace can aquire locks that prevent the kernel from shutting off (or doing anything else in particular) then it's possible for misbehaving userspace code to stop the kernel by simply choosing to never release the lock.

this would be a trivial DOS from userspace.

You are confusing "userspace" with "user tasks". And not only that, you often use the term "userspace" when you should say "user mode".

If you want I can explain the differences.

Quoted 4 lines

now, if you are talking instead about the fact that when userspace makes a system call, the execution of that system call involves aquiring locks that are released before the system call completes you have a very different situation.

That is exactly what I have been talking about. It may be different from what you _thought_, but it's not different from what I actually _said_.

Quoted 5 lines

if you have locks that are held across system calls then you should already have problems. becouse you can't count on userspace ever taking whatever action is appropriate to release the lock.

what am I missing that concerns you so much?

Here's what you are missing:

The new kexec approach eliminates the freezer and relies instead on the fact that none of the tasks in the original kernel can execute while the new kexec'd kernel is running. This means the new kernel can write out a memory image with no fear of interference or corruption.

But it also means that tasks which otherwise would have been frozen are actually free to run before the kexec call is made (and after the call returns, if the kexec'd kernel returns back to the original kernel). Any driver which was written with the assumption that tasks would be frozen at those times will need to be changed.

For example, drivers know that they have to quiesce their device in preparation for creating the memory snapshot. But they assume that no I/O requests will be made while the device is quiesced (because no user task is capable of generating an I/O request if they are all frozen), so the driver doesn't try to prevent such requests from reactivating the device.

The situation as regards locking is harder to discuss since I don't know of any code examples to use as a guide. The fact remains that if user tasks aren't frozen then they can make system calls, and while running in kernel mode they can acquire locks, which might cause problems -- even though I can't identify any definite examples.

Because of these problems, it's too early to start trying to use kexec to avoid the need for the freezer.

Of course, exactly the same possible problems exist when one tries to remove the freezer from suspend-to-RAM. It has nothing to do with kexec in particular (and certainly nothing to do with ACPI).

Quoted 4 lines

having read through Documentation/power/devices.txt I remain convinced that you are making a fundamental mistake.

you are designing a system

I'm not designing anything! _You_ are. I'm merely pointing out problems in your design which you haven't considered.

Quoted 3 lines

that will only work if everything (every
driver, every state transition) participates fully in the process at all times. You started with the facts 'this is the info that ACPI provides

Look again; I wasn't talking about ACPI. You have mixed up the issues in this email thread. (Not hard to do, since it has been a very long and complicated thread.)

Quoted 6 lines

and
this is how it is designed to be used' and worked from there instead of looking to see what the kernel really needed and figuring how to provide a good interface for that that happens to be implemented (today) with ACPI. (a proper power management framework shouldn't care if you have ACPI, APM, or some other method of controlling the devices)

This and the rest of your email have no bearing on what I was talking about, so I have snipped out the remainder.

Alan Stern

#260 lore raw
Quoted 5 lines · Alan Stern
Quoted 1 line · On Sat, 21 Jul 2007 [email protected] wrote:

wait a min her, it's possible we are misunderstanding each other.

I'd describe it as: You are misunderstanding me. :-)

very possibly :-)

Quoted 7 lines
Quoted 7 lines

as I see it.

if userspace can aquire locks that prevent the kernel from shutting off (or doing anything else in particular) then it's possible for misbehaving userspace code to stop the kernel by simply choosing to never release the lock.

Quoted 6 lines
Quoted 1 line

this would be a trivial DOS from userspace.

You are confusing "userspace" with "user tasks". And not only that, you often use the term "userspace" when you should say "user mode".

If you want I can explain the differences.

please do, I have been treating all three as the same catagory.

Quoted 8 lines
Quoted 4 lines

now, if you are talking instead about the fact that when userspace makes a system call, the execution of that system call involves aquiring locks that are released before the system call completes you have a very different situation.

That is exactly what I have been talking about. It may be different from what you _thought_, but it's not different from what I actually _said_.

Ok, I did misunderstand you. it sound slike all you need to do to make sure that locks are not held is to allow system calls to return before trying to do the suspend/kexec/etc. that sounds like not only a trivial thing to do, but something that would probably be done anyway.

although syscalls that then call out to userspace tasks before they can complete cause potential deadlocks (without that issue you can just wait until all syscalls have returned, and not allow anything to issue new syscalls) is this the issue that's killing FUSE+suspend?

Quoted 4 lines
Quoted 4 lines

if you have locks that are held across system calls then you should already have problems. becouse you can't count on userspace ever taking whatever action is appropriate to release the lock.

Quoted 8 lines
Quoted 1 line

what am I missing that concerns you so much?

Here's what you are missing:

The new kexec approach eliminates the freezer and relies instead on the fact that none of the tasks in the original kernel can execute while the new kexec'd kernel is running. This means the new kernel can write out a memory image with no fear of interference or corruption.

correct

Quoted 5 lines

But it also means that tasks which otherwise would have been frozen are actually free to run before the kexec call is made (and after the call returns, if the kexec'd kernel returns back to the original kernel). Any driver which was written with the assumption that tasks would be frozen at those times will need to be changed.

here is where you loose me.

why should jumping back to the original kernel immedialty start running these processes? the process of doing a kexec requires things to happen in the drivers before normal activity can happen, so there is a phase in there where the kernel being jumped to has drivers initializing, but still does not allow anything else to run. why can't this phase be extended to allow for the possibility of transitioning these drivers to a sleep mode instead of to full operation?

Quoted 7 lines

For example, drivers know that they have to quiesce their device in preparation for creating the memory snapshot. But they assume that no I/O requests will be made while the device is quiesced (because no user task is capable of generating an I/O request if they are all frozen), so the driver doesn't try to prevent such requests from reactivating the device.

Quoted 5 lines

The situation as regards locking is harder to discuss since I don't know of any code examples to use as a guide. The fact remains that if user tasks aren't frozen then they can make system calls, and while running in kernel mode they can acquire locks, which might cause problems -- even though I can't identify any definite examples.

yes, if userspace is running jobs and submitting I/O and system calls while drivers are trying to initalize there is a big problem, but I am missing the reason this must be the case.

Quoted 6 lines

Because of these problems, it's too early to start trying to use kexec to avoid the need for the freezer.

Of course, exactly the same possible problems exist when one tries to remove the freezer from suspend-to-RAM. It has nothing to do with kexec in particular (and certainly nothing to do with ACPI).

the part of the freezer that everyone is trying to eliminate is the exceptions (freeze everything except X,Y,Z becouse we will need to use those later for A)

Quoted 7 lines
Quoted 4 lines

having read through Documentation/power/devices.txt I remain convinced that you are making a fundamental mistake.

you are designing a system

I'm not designing anything! _You_ are. I'm merely pointing out problems in your design which you haven't considered.

a better way of phrasing what I meant goes more along the lines of 'the current design of the system...'

Quoted 7 lines
Quoted 3 lines

that will only work if everything (every
driver, every state transition) participates fully in the process at all times. You started with the facts 'this is the info that ACPI provides

Look again; I wasn't talking about ACPI. You have mixed up the issues in this email thread. (Not hard to do, since it has been a very long and complicated thread.)

very possibly. there are so many different sub-threads that part of my answer was to you, and part is addressing other things brought up during the thread

Quoted 9 lines
Quoted 6 lines

and
this is how it is designed to be used' and worked from there instead of looking to see what the kernel really needed and figuring how to provide a good interface for that that happens to be implemented (today) with ACPI. (a proper power management framework shouldn't care if you have ACPI, APM, or some other method of controlling the devices)

This and the rest of your email have no bearing on what I was talking about, so I have snipped out the remainder.

this was in reaction to reading the power/devices.txt. my first thought was along the lines of "no wonder device driver authors don't implement all this, it's obviously evolved from the needs of the people doing the suspend, one call at a time" and from there I started thinking about what would make sense to driver authors and provide the capability that's needed for the job. I broke that off into a seperate thread anyway.

David Lang

#261 lore raw
Quoted 6 lines · On Sun, 22 Jul 2007 [email protected] wrote:
Quoted 4 lines

You are confusing "userspace" with "user tasks". And not only that, you often use the term "userspace" when you should say "user mode".

If you want I can explain the differences.

please do, I have been treating all three as the same catagory.

Very briefly then: "User mode" and "kernel mode" refer to the CPU's hardware privilege level. A process makes the transition from user mode to kernel mode by executing a system call. Interrupt and exception handlers also run in kernel mode, but they generally are not considered to be part of any process. The reverse transition occurs when a process returns from a system call, or when an interrupt which occurred while the CPU was in user mode completes. (It's interesting to note that system calls are somewhat similar to interrupts; in fact sometimes they are implemented by a "software interrupt".)

"Kernel threads" are processes that run entirely in kernel mode. They usually don't have a memory mapping for any user-owned memory and they never go into user mode. All other processes are "user threads".

"Userspace" is a rather general term referring to things not in the kernel. It comprises both user tasks (while running in user mode) and user memory.

Quoted 4 lines

Ok, I did misunderstand you. it sound slike all you need to do to make sure that locks are not held is to allow system calls to return before trying to do the suspend/kexec/etc. that sounds like not only a trivial thing to do, but something that would probably be done anyway.

If you could actually do it, it would work. But you can't do it. If it were feasible, the freezer would have used that approach in the first place.

For one thing, checking for a suspend-in-progress at the beginning of each and every system call would add overhead to a hot path in the kernel, one which is already very heavily optimized. People wouldn't stand for it.

Quoted 4 lines

although syscalls that then call out to userspace tasks before they can complete cause potential deadlocks (without that issue you can just wait until all syscalls have returned, and not allow anything to issue new syscalls) is this the issue that's killing FUSE+suspend?

You get similar problems from system calls that wait in kernel mode until something has happened. For example, a read() call for the console device will wait until somebody types on the keyboard. At any point in time, many (or even most) user threads are blocked in a system call.

Quoted 15 lines
Quoted 6 lines

Here's what you are missing:

The new kexec approach eliminates the freezer and relies instead on the fact that none of the tasks in the original kernel can execute while the new kexec'd kernel is running. This means the new kernel can write out a memory image with no fear of interference or corruption.

correct

Quoted 5 lines

But it also means that tasks which otherwise would have been frozen are actually free to run before the kexec call is made (and after the call returns, if the kexec'd kernel returns back to the original kernel). Any driver which was written with the assumption that tasks would be frozen at those times will need to be changed.

Quoted 4 lines

here is where you loose me.

why should jumping back to the original kernel immedialty start running these processes?

Let's let kernel K1 be the original kernel, the one which is going into hibernation. Kernel K2 is the one started by kexec to write out the memory image.

Your question becomes: Why should K2 jumping back to K1 cause K1 immediately to start running user tasks? Answer: Because K1 has been running user tasks all along (except while K2 was active) and nothing has told it to stop. In fact, about the only things which _can_ cause K1 to stop running user threads are the freezer (which you want to eliminate) and disabling interrupts (not possible since some drivers require interrupts to be enabled when putting devices in low-power mode).

Quoted 4 lines

the process of doing a kexec requires things to happen in
the drivers before normal activity can happen, so there is a phase in there where the kernel being jumped to has drivers initializing, but still does not allow anything else to run.

So when K2 starts up, it will have a phase in which user threads don't run. That doesn't affect K1. When K2 returns to K1, K1 does not go through this sort of phase. It simply picks up from where it left off.

Quoted 3 lines

why can't this phase be extended to
allow for the possibility of transitioning these drivers to a sleep mode instead of to full operation?

Indeed, Rafael has suggested that K2 be responsible for putting devices in low-power mode. This has the disadvantage of requiring K2 to include drivers for every device used by K1, but otherwise it would work.

However there still remains the problem of user tasks running after devices are supposed to be quiescent and before K1 starts. There's currently nothing to stop such tasks from making I/O requests and thereby causing a quiescent device to become active again.

Quoted 9 lines
Quoted 5 lines

The situation as regards locking is harder to discuss since I don't know of any code examples to use as a guide. The fact remains that if user tasks aren't frozen then they can make system calls, and while running in kernel mode they can acquire locks, which might cause problems -- even though I can't identify any definite examples.

yes, if userspace is running jobs and submitting I/O and system calls while drivers are trying to initalize there is a big problem, but I am missing the reason this must be the case.

We aren't talking about drivers initializing devices. We are talking about what happens during the time when drivers are trying to quiesce devices (i.e., before K1 has started up K2) or power them down (after K2 has returned to K1).

Quoted 3 lines

the part of the freezer that everyone is trying to eliminate is the exceptions (freeze everything except X,Y,Z becouse we will need to use those later for A)

Wrong. People are trying to eliminate the freezer entirely. Go back and reread some of the postings at the beginning of this long thread, especially those from Paul Mackerras and Ben Herrenschmidt.

Alan Stern

#262 lore raw
In reply to [email protected]
Quoted 6 lines · On Sun, 22 Jul 2007 [email protected] wrote:
Quoted 4 lines

You are confusing "userspace" with "user tasks". And not only that, you often use the term "userspace" when you should say "user mode".

If you want I can explain the differences.

please do, I have been treating all three as the same catagory.

Very briefly then: "User mode" and "kernel mode" refer to the CPU's hardware privilege level. A process makes the transition from user mode to kernel mode by executing a system call. Interrupt and exception handlers also run in kernel mode, but they generally are not considered to be part of any process. The reverse transition occurs when a process returns from a system call, or when an interrupt which occurred while the CPU was in user mode completes. (It's interesting to note that system calls are somewhat similar to interrupts; in fact sometimes they are implemented by a "software interrupt".)

"Kernel threads" are processes that run entirely in kernel mode. They usually don't have a memory mapping for any user-owned memory and they never go into user mode. All other processes are "user threads".

"Userspace" is a rather general term referring to things not in the kernel. It comprises both user tasks (while running in user mode) and user memory.

Quoted 4 lines

Ok, I did misunderstand you. it sound slike all you need to do to make sure that locks are not held is to allow system calls to return before trying to do the suspend/kexec/etc. that sounds like not only a trivial thing to do, but something that would probably be done anyway.

If you could actually do it, it would work. But you can't do it. If it were feasible, the freezer would have used that approach in the first place.

For one thing, checking for a suspend-in-progress at the beginning of each and every system call would add overhead to a hot path in the kernel, one which is already very heavily optimized. People wouldn't stand for it.

Quoted 4 lines

although syscalls that then call out to userspace tasks before they can complete cause potential deadlocks (without that issue you can just wait until all syscalls have returned, and not allow anything to issue new syscalls) is this the issue that's killing FUSE+suspend?

You get similar problems from system calls that wait in kernel mode until something has happened. For example, a read() call for the console device will wait until somebody types on the keyboard. At any point in time, many (or even most) user threads are blocked in a system call.

Quoted 15 lines
Quoted 6 lines

Here's what you are missing:

The new kexec approach eliminates the freezer and relies instead on the fact that none of the tasks in the original kernel can execute while the new kexec'd kernel is running. This means the new kernel can write out a memory image with no fear of interference or corruption.

correct

Quoted 5 lines

But it also means that tasks which otherwise would have been frozen are actually free to run before the kexec call is made (and after the call returns, if the kexec'd kernel returns back to the original kernel). Any driver which was written with the assumption that tasks would be frozen at those times will need to be changed.

Quoted 4 lines

here is where you loose me.

why should jumping back to the original kernel immedialty start running these processes?

Let's let kernel K1 be the original kernel, the one which is going into hibernation. Kernel K2 is the one started by kexec to write out the memory image.

Your question becomes: Why should K2 jumping back to K1 cause K1 immediately to start running user tasks? Answer: Because K1 has been running user tasks all along (except while K2 was active) and nothing has told it to stop. In fact, about the only things which _can_ cause K1 to stop running user threads are the freezer (which you want to eliminate) and disabling interrupts (not possible since some drivers require interrupts to be enabled when putting devices in low-power mode).

Quoted 4 lines

the process of doing a kexec requires things to happen in
the drivers before normal activity can happen, so there is a phase in there where the kernel being jumped to has drivers initializing, but still does not allow anything else to run.

So when K2 starts up, it will have a phase in which user threads don't run. That doesn't affect K1. When K2 returns to K1, K1 does not go through this sort of phase. It simply picks up from where it left off.

Quoted 3 lines

why can't this phase be extended to
allow for the possibility of transitioning these drivers to a sleep mode instead of to full operation?

Indeed, Rafael has suggested that K2 be responsible for putting devices in low-power mode. This has the disadvantage of requiring K2 to include drivers for every device used by K1, but otherwise it would work.

However there still remains the problem of user tasks running after devices are supposed to be quiescent and before K1 starts. There's currently nothing to stop such tasks from making I/O requests and thereby causing a quiescent device to become active again.

Quoted 9 lines
Quoted 5 lines

The situation as regards locking is harder to discuss since I don't know of any code examples to use as a guide. The fact remains that if user tasks aren't frozen then they can make system calls, and while running in kernel mode they can acquire locks, which might cause problems -- even though I can't identify any definite examples.

yes, if userspace is running jobs and submitting I/O and system calls while drivers are trying to initalize there is a big problem, but I am missing the reason this must be the case.

We aren't talking about drivers initializing devices. We are talking about what happens during the time when drivers are trying to quiesce devices (i.e., before K1 has started up K2) or power them down (after K2 has returned to K1).

Quoted 3 lines

the part of the freezer that everyone is trying to eliminate is the exceptions (freeze everything except X,Y,Z becouse we will need to use those later for A)

Wrong. People are trying to eliminate the freezer entirely. Go back and reread some of the postings at the beginning of this long thread, especially those from Paul Mackerras and Ben Herrenschmidt.

Alan Stern

#263 lore raw
Quoted 8 lines · Alan Stern
Quoted 4 lines · On Sun, 22 Jul 2007 [email protected] wrote:

Ok, I did misunderstand you. it sound slike all you need to do to make sure that locks are not held is to allow system calls to return before trying to do the suspend/kexec/etc. that sounds like not only a trivial thing to do, but something that would probably be done anyway.

Quoted 8 lines

If you could actually do it, it would work. But you can't do it. If it were feasible, the freezer would have used that approach in the first place.

For one thing, checking for a suspend-in-progress at the beginning of each and every system call would add overhead to a hot path in the kernel, one which is already very heavily optimized. People wouldn't stand for it.

I thought that the suspend stuff did this easily, but the freezer really starts running into trouble when it wants to freeze some things, but not other things. this seems to be the biggest area of churn and problems.

Quoted 10 lines
Quoted 4 lines

although syscalls that then call out to userspace tasks before they can complete cause potential deadlocks (without that issue you can just wait until all syscalls have returned, and not allow anything to issue new syscalls) is this the issue that's killing FUSE+suspend?

You get similar problems from system calls that wait in kernel mode until something has happened. For example, a read() call for the console device will wait until somebody types on the keyboard. At any point in time, many (or even most) user threads are blocked in a system call.

but are locks held while they are blocked like this?

Quoted 15 lines
Quoted 10 lines
Quoted 5 lines

But it also means that tasks which otherwise would have been frozen are actually free to run before the kexec call is made (and after the call returns, if the kexec'd kernel returns back to the original kernel). Any driver which was written with the assumption that tasks would be frozen at those times will need to be changed.

here is where you loose me.

why should jumping back to the original kernel immedialty start running these processes?

Let's let kernel K1 be the original kernel, the one which is going into hibernation. Kernel K2 is the one started by kexec to write out the memory image.

Quoted 8 lines

Your question becomes: Why should K2 jumping back to K1 cause K1 immediately to start running user tasks? Answer: Because K1 has been running user tasks all along (except while K2 was active) and nothing has told it to stop. In fact, about the only things which _can_ cause K1 to stop running user threads are the freezer (which you want to eliminate) and disabling interrupts (not possible since some drivers require interrupts to be enabled when putting devices in low-power mode).

when you jump to a body of code you jump to a specific point in the code, not to some nebulous 'everything running' state.

Quoted 8 lines
Quoted 4 lines

the process of doing a kexec requires things to happen in
the drivers before normal activity can happen, so there is a phase in there where the kernel being jumped to has drivers initializing, but still does not allow anything else to run.

So when K2 starts up, it will have a phase in which user threads don't run. That doesn't affect K1. When K2 returns to K1, K1 does not go through this sort of phase. It simply picks up from where it left off.

then how can it restart drivers before the user threads need them?

Quoted 9 lines
Quoted 3 lines

why can't this phase be extended to
allow for the possibility of transitioning these drivers to a sleep mode instead of to full operation?

Indeed, Rafael has suggested that K2 be responsible for putting devices in low-power mode. This has the disadvantage of requiring K2 to include drivers for every device used by K1, but otherwise it would work.

Quoted 4 lines

However there still remains the problem of user tasks running after devices are supposed to be quiescent and before K1 starts. There's currently nothing to stop such tasks from making I/O requests and thereby causing a quiescent device to become active again.

but if the devices are in low power mode then K1 needs to get them out of low power mode before user tasks try to access them.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

The situation as regards locking is harder to discuss since I don't know of any code examples to use as a guide. The fact remains that if user tasks aren't frozen then they can make system calls, and while running in kernel mode they can acquire locks, which might cause problems -- even though I can't identify any definite examples.

Quoted 8 lines
Quoted 3 lines

yes, if userspace is running jobs and submitting I/O and system calls while drivers are trying to initalize there is a big problem, but I am missing the reason this must be the case.

We aren't talking about drivers initializing devices. We are talking about what happens during the time when drivers are trying to quiesce devices (i.e., before K1 has started up K2) or power them down (after K2 has returned to K1).

or if you are doing a resume instead of a suspend to ram the drivers need to initialize or otherwise move to full power on K1 before user tasks hit them.

Quoted 11 lines
Quoted 3 lines

the part of the freezer that everyone is trying to eliminate is the exceptions (freeze everything except X,Y,Z becouse we will need to use those later for A)

Wrong. People are trying to eliminate the freezer entirely. Go back and reread some of the postings at the beginning of this long thread, especially those from Paul Mackerras and Ben Herrenschmidt.

Alan Stern

#264 lore raw
In reply to Alan Stern
Quoted 8 lines · Alan Stern
Quoted 4 lines · On Sun, 22 Jul 2007 [email protected] wrote:

Ok, I did misunderstand you. it sound slike all you need to do to make sure that locks are not held is to allow system calls to return before trying to do the suspend/kexec/etc. that sounds like not only a trivial thing to do, but something that would probably be done anyway.

Quoted 8 lines

If you could actually do it, it would work. But you can't do it. If it were feasible, the freezer would have used that approach in the first place.

For one thing, checking for a suspend-in-progress at the beginning of each and every system call would add overhead to a hot path in the kernel, one which is already very heavily optimized. People wouldn't stand for it.

I thought that the suspend stuff did this easily, but the freezer really starts running into trouble when it wants to freeze some things, but not other things. this seems to be the biggest area of churn and problems.

Quoted 10 lines
Quoted 4 lines

although syscalls that then call out to userspace tasks before they can complete cause potential deadlocks (without that issue you can just wait until all syscalls have returned, and not allow anything to issue new syscalls) is this the issue that's killing FUSE+suspend?

You get similar problems from system calls that wait in kernel mode until something has happened. For example, a read() call for the console device will wait until somebody types on the keyboard. At any point in time, many (or even most) user threads are blocked in a system call.

but are locks held while they are blocked like this?

Quoted 15 lines
Quoted 10 lines
Quoted 5 lines

But it also means that tasks which otherwise would have been frozen are actually free to run before the kexec call is made (and after the call returns, if the kexec'd kernel returns back to the original kernel). Any driver which was written with the assumption that tasks would be frozen at those times will need to be changed.

here is where you loose me.

why should jumping back to the original kernel immedialty start running these processes?

Let's let kernel K1 be the original kernel, the one which is going into hibernation. Kernel K2 is the one started by kexec to write out the memory image.

Quoted 8 lines

Your question becomes: Why should K2 jumping back to K1 cause K1 immediately to start running user tasks? Answer: Because K1 has been running user tasks all along (except while K2 was active) and nothing has told it to stop. In fact, about the only things which _can_ cause K1 to stop running user threads are the freezer (which you want to eliminate) and disabling interrupts (not possible since some drivers require interrupts to be enabled when putting devices in low-power mode).

when you jump to a body of code you jump to a specific point in the code, not to some nebulous 'everything running' state.

Quoted 8 lines
Quoted 4 lines

the process of doing a kexec requires things to happen in
the drivers before normal activity can happen, so there is a phase in there where the kernel being jumped to has drivers initializing, but still does not allow anything else to run.

So when K2 starts up, it will have a phase in which user threads don't run. That doesn't affect K1. When K2 returns to K1, K1 does not go through this sort of phase. It simply picks up from where it left off.

then how can it restart drivers before the user threads need them?

Quoted 9 lines
Quoted 3 lines

why can't this phase be extended to
allow for the possibility of transitioning these drivers to a sleep mode instead of to full operation?

Indeed, Rafael has suggested that K2 be responsible for putting devices in low-power mode. This has the disadvantage of requiring K2 to include drivers for every device used by K1, but otherwise it would work.

Quoted 4 lines

However there still remains the problem of user tasks running after devices are supposed to be quiescent and before K1 starts. There's currently nothing to stop such tasks from making I/O requests and thereby causing a quiescent device to become active again.

but if the devices are in low power mode then K1 needs to get them out of low power mode before user tasks try to access them.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

The situation as regards locking is harder to discuss since I don't know of any code examples to use as a guide. The fact remains that if user tasks aren't frozen then they can make system calls, and while running in kernel mode they can acquire locks, which might cause problems -- even though I can't identify any definite examples.

Quoted 8 lines
Quoted 3 lines

yes, if userspace is running jobs and submitting I/O and system calls while drivers are trying to initalize there is a big problem, but I am missing the reason this must be the case.

We aren't talking about drivers initializing devices. We are talking about what happens during the time when drivers are trying to quiesce devices (i.e., before K1 has started up K2) or power them down (after K2 has returned to K1).

or if you are doing a resume instead of a suspend to ram the drivers need to initialize or otherwise move to full power on K1 before user tasks hit them.

Quoted 11 lines
Quoted 3 lines

the part of the freezer that everyone is trying to eliminate is the exceptions (freeze everything except X,Y,Z becouse we will need to use those later for A)

Wrong. People are trying to eliminate the freezer entirely. Go back and reread some of the postings at the beginning of this long thread, especially those from Paul Mackerras and Ben Herrenschmidt.

Alan Stern

#265 lore raw
Quoted 6 lines · On Mon, 23 Jul 2007 [email protected] wrote:
Quoted 4 lines

For one thing, checking for a suspend-in-progress at the beginning of each and every system call would add overhead to a hot path in the kernel, one which is already very heavily optimized. People wouldn't stand for it.

I thought that the suspend stuff did this easily,

It does not do it at all. Do you know how the freezer works?

Quoted 3 lines

but the freezer really
starts running into trouble when it wants to freeze some things, but not other things. this seems to be the biggest area of churn and problems.

No. The freezer starts running into trouble when it wants to freeze a thread but can't, because that thread is waiting for some event to occur and the only thread which can cause the event is already frozen. Or is itself waiting for a third thread which is already frozen...

Quoted 7 lines
Quoted 5 lines

You get similar problems from system calls that wait in kernel mode until something has happened. For example, a read() call for the console device will wait until somebody types on the keyboard. At any point in time, many (or even most) user threads are blocked in a system call.

but are locks held while they are blocked like this?

Sometimes they are, sometimes they aren't.

Quoted 13 lines
Quoted 4 lines

Let's let kernel K1 be the original kernel, the one which is going into hibernation. Kernel K2 is the one started by kexec to write out the memory image.

Quoted 8 lines

Your question becomes: Why should K2 jumping back to K1 cause K1 immediately to start running user tasks? Answer: Because K1 has been running user tasks all along (except while K2 was active) and nothing has told it to stop. In fact, about the only things which _can_ cause K1 to stop running user threads are the freezer (which you want to eliminate) and disabling interrupts (not possible since some drivers require interrupts to be enabled when putting devices in low-power mode).

Quoted 2 lines

when you jump to a body of code you jump to a specific point in the code, not to some nebulous 'everything running' state.

How is that relevant? When K2 jumps back to K1, it jumps to some designated location in K1. It might just after the place where K1 called K2; I'm not familiar with the details of kexec. In any event, K1 will still be in the same state as it was when it called K2.

Quoted 5 lines
Quoted 3 lines

So when K2 starts up, it will have a phase in which user threads don't run. That doesn't affect K1. When K2 returns to K1, K1 does not go through this sort of phase. It simply picks up from where it left off.

then how can it restart drivers before the user threads need them?

It can't. Indeed, in the absence of a freezer, user threads will need devices (more accurately, will submit I/O requests for devices) that have to be kept quiescent or low-power. Drivers will need to delay those requests until the devices are returned to full operation.

That's exactly what I've been saying all along: Drivers will need to be changed to delay I/O requests, if there is no freezer.

Quoted 7 lines
Quoted 4 lines

However there still remains the problem of user tasks running after devices are supposed to be quiescent and before K1 starts. There's currently nothing to stop such tasks from making I/O requests and thereby causing a quiescent device to become active again.

but if the devices are in low power mode then K1 needs to get them out of low power mode before user tasks try to access them.

No -- which is good because it can't. If a user task is running there's no way to stop it from submitting I/O requests. K1 needs to delay these requests until after the device has returned to full operation.

Quoted 8 lines
Quoted 4 lines

We aren't talking about drivers initializing devices. We are talking about what happens during the time when drivers are trying to quiesce devices (i.e., before K1 has started up K2) or power them down (after K2 has returned to K1).

or if you are doing a resume instead of a suspend to ram the drivers need to initialize or otherwise move to full power on K1 before user tasks hit them.

Correct. User tasks are allowed to submit requests, but the requests can't be carried out until the device returns to full operation.

Alan Stern

#266 lore raw
Quoted 8 lines

From: Alan Stern [mailto:[email protected]]
It can't. Indeed, in the absence of a freezer, user threads will need devices (more accurately, will submit I/O requests for devices) that have to be kept quiescent or low-power. Drivers will need to delay those requests until the devices are returned to full operation.

That's exactly what I've been saying all along: Drivers will need to be changed to delay I/O requests, if there is no freezer.

If it is a too big work to implement "delaying I/O requests" for every driver, is it possible to implement it as follow:

1. It is triggered to suspend to RAM/DISK.
2. Replace the driver related syscall entries (such as sys_read, sys_write, sys_ioctl, etc) in sys_call_table with special wrapper entries provided by "suspend to RAM/DISK" subsystem, which will delay I/O requests if appropriate.
3. When devices are quiesced, they are put into "low power" state and system is put into suspend state; or the image is written to disk (through snapshot/uswsusp or kexeced kernel).
4. After resuming from RAM/DISK, devices are put into "normal" state and the syscall entries replaced in step 2 are restored.

Best Regards,
Huang Ying

#267 lore raw
In reply to Alan Stern
Quoted 8 lines

From: Alan Stern [mailto:[email protected]]
It can't. Indeed, in the absence of a freezer, user threads will need devices (more accurately, will submit I/O requests for devices) that have to be kept quiescent or low-power. Drivers will need to delay those requests until the devices are returned to full operation.

That's exactly what I've been saying all along: Drivers will need to be changed to delay I/O requests, if there is no freezer.

If it is a too big work to implement "delaying I/O requests" for every driver, is it possible to implement it as follow:

1. It is triggered to suspend to RAM/DISK.
2. Replace the driver related syscall entries (such as sys_read, sys_write, sys_ioctl, etc) in sys_call_table with special wrapper entries provided by "suspend to RAM/DISK" subsystem, which will delay I/O requests if appropriate.
3. When devices are quiesced, they are put into "low power" state and system is put into suspend state; or the image is written to disk (through snapshot/uswsusp or kexeced kernel).
4. After resuming from RAM/DISK, devices are put into "normal" state and the syscall entries replaced in step 2 are restored.

Best Regards,
Huang Ying

#268 lore raw
Quoted 12 lines · Ying
Quoted 8 lines

From: Alan Stern [mailto:[email protected]]
It can't. Indeed, in the absence of a freezer, user threads will need devices (more accurately, will submit I/O requests for devices) that have to be kept quiescent or low-power. Drivers will need to delay those requests until the devices are returned to full operation.

That's exactly what I've been saying all along: Drivers will need to be changed to delay I/O requests, if there is no freezer.

If it is a too big work to implement "delaying I/O requests" for every driver, is it possible to implement it as follow:

Quoted 10 lines

1. It is triggered to suspend to RAM/DISK.
2. Replace the driver related syscall entries (such as sys_read, sys_write, sys_ioctl, etc) in sys_call_table with special wrapper entries provided by "suspend to RAM/DISK" subsystem, which will delay I/O requests if appropriate.
3. When devices are quiesced, they are put into "low power" state and system is put into suspend state; or the image is written to disk (through snapshot/uswsusp or kexeced kernel).
4. After resuming from RAM/DISK, devices are put into "normal" state and the syscall entries replaced in step 2 are restored.

Ha! I made exactly this same suggestion (URL lost in the mists of time), except that I proposed changing the syscall entries for every system call, not just the driver-related ones.

Nobody seemed to think it would work very well.

It leaves a few loose ends. For example, suppose a user thread is already in the middle of a system call and is about to start doing some I/O (maybe it's waiting for a timer to expire).

In the end, this doesn't seem to be very different from freezing all user threads.

Alan Stern

#269 lore raw
In reply to Alan Stern
Quoted 17 lines · Alan Stern
Quoted 10 lines · On Fri, 20 Jul 2007 [email protected] wrote:
Quoted 4 lines

Userspace can submit I/O requests. Someone will have to audit every driver to make sure that such I/O requests don't cause a quiesced device to become active. If the device is active, it will make the memory snapshot inconsistent with the on-device data.

assuming this is the suspend-from-ram after a kexec back from the write-to-disk kernel I don't think you are correct.

when doing a suspend-to-ram you get to a point where you just don't use any userspace.

What do you mean? How can you prevent user tasks from running? That's basically what the freezer does, and the whole point of this approach is to eliminate the freezer. Right?

Quoted 7 lines
Quoted 3 lines

from that point on you are just walking the device tree putting things into low-power mode. This is the point where we are talking about jumping to.

Yes. And putting things into low-power mode requires the ability to run the scheduler, which means that user tasks can be scheduled, which means that they can run.

I did not know that getting into low-power mode required scheduling.

does it require userspace?

if so this is a problem and I say punt on suspend-to-disk-and-ram until suspend-to-ram is working independantly ;-)

if not, then can you schedule but not consider non-kernel tasks runnable?

freezing all of userspace is easy (see above)

freezing all of kernelspace is easy (unplug all non-boot CPU's and don't schedule)

where freezing gets hard is when you need to partially freeze either one of these.

David Lang

#270 lore raw
Quoted 36 lines · On Friday, 20 July 2007 23:34, [email protected] wrote:
Quoted 17 lines · Alan Stern
Quoted 10 lines · On Fri, 20 Jul 2007 [email protected] wrote:
Quoted 4 lines

Userspace can submit I/O requests. Someone will have to audit every driver to make sure that such I/O requests don't cause a quiesced device to become active. If the device is active, it will make the memory snapshot inconsistent with the on-device data.

assuming this is the suspend-from-ram after a kexec back from the write-to-disk kernel I don't think you are correct.

when doing a suspend-to-ram you get to a point where you just don't use any userspace.

What do you mean? How can you prevent user tasks from running? That's basically what the freezer does, and the whole point of this approach is to eliminate the freezer. Right?

Quoted 7 lines
Quoted 3 lines

from that point on you are just walking the device tree putting things into low-power mode. This is the point where we are talking about jumping to.

Yes. And putting things into low-power mode requires the ability to run the scheduler, which means that user tasks can be scheduled, which means that they can run.

I did not know that getting into low-power mode required scheduling.

does it require userspace?

if so this is a problem and I say punt on suspend-to-disk-and-ram until suspend-to-ram is working independantly ;-)

if not, then can you schedule but not consider non-kernel tasks runnable?

Quoted 7 lines

freezing all of userspace is easy (see above)

freezing all of kernelspace is easy (unplug all non-boot CPU's and don't schedule)

where freezing gets hard is when you need to partially freeze either one of these.

If you use the scheduler to "freeze" tasks, you never know where they are stopped and what locks they may hold.

We would have done that already if that was so easy, because we really want to freeze _all_ user space tasks (even if not all kernel threads).

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#271 lore raw
In reply to [email protected]
Quoted 36 lines · On Friday, 20 July 2007 23:34, [email protected] wrote:
Quoted 17 lines · Alan Stern
Quoted 10 lines · On Fri, 20 Jul 2007 [email protected] wrote:
Quoted 4 lines

Userspace can submit I/O requests. Someone will have to audit every driver to make sure that such I/O requests don't cause a quiesced device to become active. If the device is active, it will make the memory snapshot inconsistent with the on-device data.

assuming this is the suspend-from-ram after a kexec back from the write-to-disk kernel I don't think you are correct.

when doing a suspend-to-ram you get to a point where you just don't use any userspace.

What do you mean? How can you prevent user tasks from running? That's basically what the freezer does, and the whole point of this approach is to eliminate the freezer. Right?

Quoted 7 lines
Quoted 3 lines

from that point on you are just walking the device tree putting things into low-power mode. This is the point where we are talking about jumping to.

Yes. And putting things into low-power mode requires the ability to run the scheduler, which means that user tasks can be scheduled, which means that they can run.

I did not know that getting into low-power mode required scheduling.

does it require userspace?

if so this is a problem and I say punt on suspend-to-disk-and-ram until suspend-to-ram is working independantly ;-)

if not, then can you schedule but not consider non-kernel tasks runnable?

Quoted 7 lines

freezing all of userspace is easy (see above)

freezing all of kernelspace is easy (unplug all non-boot CPU's and don't schedule)

where freezing gets hard is when you need to partially freeze either one of these.

If you use the scheduler to "freeze" tasks, you never know where they are stopped and what locks they may hold.

We would have done that already if that was so easy, because we really want to freeze _all_ user space tasks (even if not all kernel threads).

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#272 lore raw
In reply to Milton Miller
Quoted 85 lines · Milton Miller
Quoted 9 lines · Rafael J. Wysocki
Quoted 7 lines · Milton Miller

The currently identified problems under discussion include:
(1) how to interact with acpi to enter into S4.
(2) how to identify which memory needs to be saved
(3) how to communicate where to save the memory
(4) what state should devices be in when switching kernels
(5) the complicated setup required with the current patch
(6) what code restores the image

Quoted 3 lines

(7) how to avoid corrupting filesystems mounted by the hibernated kernel

Ok I talked on this too.

Quoted 69 lines
Quoted 32 lines

I'll now start with quotes from several articles in this thread and my responses.

Message-ID: <[email protected]>

Quoted 9 lines · Rafael J. Wysocki

(1) Upon entering the sleep state, which IMO can be done _after_ the image
has been saved:
* figure out which devices can wake up
* put devices into low power states (wake-up devices are placed in
the Dx
states compatible with the wake capability, the others are
powered
off)

Quoted 8 lines

* execute the _PTS global control method
* switch off the nonlocal CPUs (eg. nonboot CPUs on x86)
* execute the _GTS global control method
* set the GPE enable registers corresponding to the wake-up
devices)
* make the platform enter S4 (there's a well defined procedure for
that)
I think that this should be done by the image-saving kernel.

Message-ID: <[email protected]>
On Tue Jul 17 13:35:52 2007, Jeremy Maitin-Shepard expressed his agreement with this block but also confusion on the other
blocks.

I strongly disagree.

Quoted 7 lines

(1) as has been pointed out, this requires the new kernel to understand
all io devices in the first kernel.
(2) it requires both kernels to talk to ACPI. This is doomed to
failure. How can the second kernel initialize ACPI? The platform
thinks it has already been initialized. Do we plan to always undo all acpi initialization?

Good question. I don't know.

Quoted 25 lines
Quoted 8 lines

(2) Upon start-up (by which I mean what happens after the user has pressed
the power button or something like that):
* check if the image is present (and valid) _without_ enabling ACPI
(we don't
do that now, but I see no reason for not doing it in the new
framework)
* if the image is present (and valid), load it

Quoted 8 lines

* turn on ACPI (unless already turned on by the BIOS, that is)
* execute the _BFS global control method
* execute the _WAK global control method
* continue
Here, the first two things should be done by the image-loading
kernel, but
the remaining operations have to be carried out by the restored
kernel.

Here I agree.

Here is my proposal. Instead of trying to both write the image and suspend, I think this all becomes much simpler if we limit the scope the work of the second kernel. Its purpose is to write the image.
After that its done. The platform can be powered off if we are going
to S5. However, to support suspend to ram and suspend to disk, we
return to the first kernel.

Quoted 7 lines
Quoted 3 lines

We can't do this unless we have frozen tasks (this way, or another) before
carrying out the entire operation.

What can't we do? We've already worked with the drivers to quesce the
hardware and put any information to resume the device in ram. Now we ask them to put their device in low power mode so we can go to sleep.

For that to work, we have to require the image-saving kernel to leave devices in the same state, or in a state compatible with the state, in which they were when it got control.

Quoted 8 lines

Even if we schedule, the only thing userspace could touch is memory. If we resume, they just run those computations again.

Quoted 4 lines

In that case, however, the kexec-based
approach would have only one advantage over the current one. Namely, it
would allow us to create bigger images.

Quoted 4 lines

The advantage is we don't have to come up with a way to teach drivers "wake up to run these requests, but no other requests". We don't have to figure out what we need to resume to allow them to process a request.

I'm not sure what you mean here. Please explain.

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines

This means that the first kernel will need to know why it got resumed.
Was the system powered off, and this is the resume from the user? Or
was it restarted because the image has been saved, and its now time to actually suspend until woken up? If you look at it, this is the same interface we have with the magic arch_suspend hook -- did we just suspend and its time to write the image, or did we just resume and its time to wake everything up.

I think this can be easily solved by giving the image saving kernel two
resume points: one for the image has been written, and one for we rebooted and have restored the image. I'm not familiar with ACPI. Perhaps we need a third to differentiate we read the image from S4 instead of from S5, but that information must be available to the OS because it needs that to know if it should resume from hibernate.

By making the split at image save and restore we have several advantages:

(1) the kernel always initializes with devices in the init or quiesced but active state.

(2) the kernel always resumes with devices in the init or quiesced but active state.

(3) the kjump save and restore kernel does not need to know how to suspend all devices in the platform.

(4) we have a merged path for suspend to disk, suspend to ram, and suspend to both.

(5) because of (4), we can implement sleep policys where we save the image to disk but try to stay in ram based on expected remaining battery life.

(6) we confine all platform (acpi) interaction to the main kernel

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

(7) we limit the knowledge needed in the second kernel. It needs to
know how to do its job and then put the hardware back how it found it. Nothing more.

This would have been nice if we had been able to do it.

I don't understand this comment. "if we had been able"? I don't
think we have tried yet.

That's related to the discussion above. If we are unable to do (3) and (6) without the freezing of tasks, which I'm not sure is not the case, the entire scheme won't be viable.

Well, we might be able to do it provided that drivers will block the tasks on I/O effectively, but I see a big 'if' here ...

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

For the suspend to ram and then woken up case, we simply need to invalidate the image before restarting normal kernel operation.

People have worried about how to boot and restore the kernel, and what
to do if reading the image fails. They worry about needing memory
hotplug or delayed acpi parsing. They are forgetting one thing. This kernel has support for kexec.

This is all easily solved by having the bootloader from the bios always
boot the restore kernel.

Quoted 6 lines
Quoted 3 lines

Well, I think this is not generally acceptable, although I agree that it would
be simpler.

For those that don't find it acceptable they can teach their bootloader when they may have a image to resume.

Yes, and I think we need to seriously consider this possibility.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

It will boot with limited useable memory and
no acpi support. If the restore kernel userspace detects that there is
no restore image, it simply loads the normal main kernel and initrd / initramfs and calls the normal kexec. The cost is the time to init the
restore kernel, read the kernel with full drivers (vs reading it from the bootloader). If you want a boot menu, use kboot (on sourceforge).

Quoted 5 lines
Quoted 1 line

Well, I'm afraid of adding more and more infrastructure to the mix.

Requiring the hibernated kernel to be able to start from kexec should
not be bad. If you were referring to adding kboot, that is just an
option.

Yes, I was.

Quoted 3 lines

One can still use bootloaders menus to select alternate kernels. However, as you said, you want to boot differently for resume (no acpi until after image loaded) from full boot.

That's correct and I think some kind of cooperation with the bootloader is needed for that.

Quoted 22 lines
Quoted 22 lines
Quoted 21 lines · Rafael J. Wysocki
Quoted 13 lines · On Tuesday, 17 July 2007 22:27, [email protected] wrote:
Quoted 12 lines · Alan Stern
Quoted 10 lines

But what about the freezer? The original reason for using kexec was
to
avoid the need for the freezer. With no freezer, while the original
kernel is busy powering down its devices, user tasks will be free to
carry out I/O -- which will make the memory snapshot inconsistent with
the on-disk data structures.

Quoted 5 lines
Quoted 5 lines

no, user tasks just don't get scheduled during shutdown.

the big problem with the freezer isn't stopping anything from happening,
it's _selectivly_ stopping things.

Agreed. Or rather, selectively not stopping and resuming things.

Quoted 7 lines
Quoted 1 line

I don't quite understant this statement. Can you please elaborate?

Feel free to list other problems with the freezer, but I'm saying that the problems are stemming from trying to freeze most of userspace and some selection of kernel threads so that new requests to the outside are not made, but then turning around and saying "ok now do some io, but only what this thread of execution originates".

We're _not_ doing anything like this.

Quoted 2 lines

Its originates not generates so we are trying to teach the whole stack these limits, including going back to userspace for FUSE.

Again, I don't understand what you're talking about. This is not like things work right now, that's for sure. :-)

The problem with FUSE is related to the fact that the freezer can't freeze uninterruptible tasks and we said that perhaps we might avoid it if FUSE was made freezing-aware. Still, no one has gone in this direction and I don't know of any plans to do that.

Please, stop trying to blame the freezer for all evil.

Also, it's better if you know how the things that you want to improve really work.

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines

It's selectively stopping kernel threads, which is just about right. If you
that _this_ is a main problem with the freezer, then think again.

Quoted 2 lines

with kexec you don't need to let any portion of the origional kernel or userspace operate so you don't have a problem.

In fact, the main problem with the freezer is that it is a coarse-grained
solution. Therefore, what I believe we should do is to evolve in the directoin
of more fine-grained solutions and gradually phase out the freezer.

The kexec-based approach is an attempt to replace one coarse-grained solution
(the freezer) with even more coarse-grained solution (stopping the entire
kernel with everything), which IMO doesn't address the main problem.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

I think this addresses teh problem. Its probably a bit harder than
powermac because we have to fully quiesce devices; we can't cheat by
leaving interrupts off. But once the drivers save the state of their
devices and stop their queues, it should be easy to audit the paths to powerdown devices and call the platform suspend and ram wakeup paths.

In other words, I'm replacing a course-grained solution with an absolute solution. "From this point on you can only write to ram."

Which means that we need to take care of the drivers _before_ doing anything else.

I agree with that, of course. :-)

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

Going back to the requirements document that started this thread:

Message-ID: <[email protected]>

Quoted 1 line · Rafael J. Wysocki

(1) Filesystems mounted before the hibernation are untouchable

This is because some file systems do a fsck or other activity even when
mounted read only. For the kexec case, however, this should be "file
systems mounted by the hibernated system must not be written". As
has
been mentioned in the past, we should be able to use something like dm snapshot to allow fsck and the file system to see the cleaned copy while not actually writing the media.

Quoted 7 lines
Quoted 3 lines

We can't _require_ users to use the dm snapshot in order for the hibernation
to work, sorry.

I actually listed three ways to start. Not all of them required dm-snapshot. I was proposing "if you need to read ext3, then use dm-snapshot".

I don't think we should differentiate filesystems this way. We should just do the same thing with all of them.

Quoted 3 lines
Quoted 1 line

And by _reading_ from a filesystem you generally update metadata.

not on ones mounted read-only. I'll reply more later in the thread.

OK

Quoted 32 lines
Quoted 23 lines
Quoted 15 lines

The kjump kernel must not have any knowledge retained if we reuse it.

Quoted 2 lines

(2) Swap space in use before the hibernation must be handled with care

Yes. Actually, even though they have been used by the write-in-the kernel users, they will be among the most difficult devices to use for snapshots by a userspace second kernel.

Quoted 1 line

(3) There are memory regions that must not be saved or restored

because they may not exist. This means that we must identify the
memory to be saved and restored in a format to be passed between the kernel.

Quoted 5 lines
Quoted 1 line

(4) The user should be able to limit the size of a hibernation image

This means the suspending kernel must arrange to reduce its active memory. The limited save can be done by providing a limited list in (3).

It seems to me that you don't understand the problem here.

Quoted 8 lines

Assume you have 90% of RAM allocated before the hibernation and the user has
requested the image to be not greater than 50% of RAM. In that case you have
to free some memory _before_ identifying memory to save and you must not
race with applications that attempt to allocate memory while you're doing it.

Quoted 3 lines

Hmm... I didn't say how to reduce the memory or identify it, did I?

Ok fine. I'll allocate a bunch of memory and put it on a list.

And you cause the OOM killer to show up. Not good.

Quoted 22 lines

Normal memory pressure will swap things out or drop filesystem pages. When I build the list of memory to backup, I filter out this list. After resume, I'll free it back.

We can arrange for this "task" to be preferred by the oom killer, if case the user is trying to suspend into less than memory than can be freed.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

(5) Hibernation should be transparent from the applications' point of view

People have pointed out they may want userspace to be aware of the
suspend. I believed this can be done with /proc/apm emulation today
or by other means; it seems that should be hooked up to dbus in some fashion.

Quoted 5 lines

Not a solution, because there still will be programs not needing to know
anything about hibernation. After all, we don't require all applications to
know anything about SMP, even if they are executed on an SMP system.

Quoted 4 lines

How do any of those methods require userpsace to know anything about
hibernation? I was talking about a general framework consistent with
todays kernel to user communication for those parts of userspace that *want* to know about suspend and hibernation.

OK, I didn't understand, then.

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 2 lines

(6) State of devices from before hibernation should be restored, if possible

related to suspend should be transparent ... yes.

Quoted 4 lines

(7) On ACPI systems special platform-related actions have to be carried out at
the right points, so that the platform works correctly after the
restore

I believe I have explained my suggestion.

Quoted 1 line

(8) Hibernation and restore should not be too slow

We control the added code. We are using full runtime drivers and
will
run at hardware speeds.

Quoted 8 lines
Quoted 3 lines

That may not be enough. If you're going to save, say, 80% of RAM on a 2 GB
machine, then you'll have to be using image compression.

Yea, so? We have a full kernel and userspace, adding compression before writing should be easy. The is no struct page for memory in the old kernel, so we likely need to be copying them in userspace anyways. Adding compression should be easy.

Yes, it's not that difficult.

Quoted 89 lines
Quoted 73 lines
Quoted 67 lines
Quoted 1 line

(9) Hibernation framework should not be too difficult to set up

Ok the current patch is presently too difficult. But I think it will be much simpler with a few small changes.

As noted in the thread

Message-ID: <[email protected]>
Subject: [linux-pm] Re: hibernation/snapshot design

Quoted 5 lines · Jeremy Maitin-Shepard
Quoted 1 line

Both would work. One would eat 8-64MB of your RAM, permanently;

As I have stated in other messages, the kdump approach would not waste
any RAM permanently.

...

Quoted 4 lines

Immediately before jumping to the new kernel, the first X bytes (where
X
is the amount of memory the new kernel will get, typically 16MB or

Quoted 8 lines

64MB)
of physical memory are backed up into the arbitrary discontiguous pages
that are made available. This will not take very long, because copying
even 64MB of memory is extremely fast. Then the new kernel is free to
use the first X bytes of contiguous physical memory. Problem solved.

Ok, now let's look at my list again:

Quoted 1 line

(1) how to interact with acpi to enter into S4.

This was discussed.

Quoted 1 line

(2) how to identify which memory needs to be saved

We need to generate a list. We need it to fit in a compuatable size so
that we can free and allocate the pages before suspending IO in the first kernel.

One possibility is to use something like the kexec copy list. If we are imaging a small fraction of ram this is appropriate, but if we are doing dense saves we need something extent based. We should be able to
extend the list.

Quoted 1 line

(3) how to communicate where to save the memory

This is an intresting topic. The suspended kernel has most IO and disk
space. It also knows how much space is to be occupied by the kernel. So communicating a block map to the second kernel would be the obvious
choice. But the second kernel must be able to find the image to
restore it, and it must have drivers for the media. Also, this is not feasible for storing to nfs.

I think we will end up with several methods.

One would be supply a list of blocks, and implement a file system that reads the file by reading the scatter list from media. The restore kernel then only needs to read an anchor, and can build upon that until
the image is read into memory. Or do this in userspace.

Quoted 3 lines

I don't know how this compares to the current restore path. I wasn't
able to identify the code that creates the on disk structure in my 10 minute perusal of kernel/power/.

The structure is created at two levels.

Quoted 13 lines

First, the code in snapshot.c makes the image available to the code in swap.c
as a stream of pages. The first page is the header, followed by some pages
containing the PFNs of the page frames to which the image data pages are to be
restored, followed by the image data pages themselves (the ordering of the PFNs
must be the same as the ordering of data pages that correspond to them).
Still, the low-level image format only needs to be known by the restore code in
snapshot.c .

Ok sounds like this code could be reused. I'll look into it.

Quoted 8 lines
Quoted 5 lines

Second, the code in swap.c writes the image pages to a storage adding some
metadata making it possible to reproduce their original ordering during the
restore.

So you are allocating the blocks as you go ... and adding meta data along the way?

Something like this. I can't say how Nigel does it, though.

Quoted 5 lines
Quoted 3 lines

The fact that we use swap spaces as the storage is related to implementation
simplicity rather than anything else.

Ok ... this only supports uncompressed hibernation?

The in-kernel version doesn't support compression (again, this was a choice made to keep the code relatively simple), but the userland version supports compression (and image encryption).

Quoted 3 lines

The first kernel is going to specify (1) what to backup. It can specify (2) where to backup, although we have to be careful identify the device in a persistent way.

Yes, that seems doable.

Quoted 23 lines
Quoted 15 lines
Quoted 15 lines

A second method will be to supply a device and file that will be mounted by the save kernel, then unmounted and restored. This would require a partition that is not mounted or open by the suspended kernel
(or use nfs or a similar protocol that is designed for multiple client concurrent access).

A third method would be to allocate a file with the first kernel, and make sure the blocks are flushed to disk. The save and restore kernels
map the file system using a snapshot device. Writing would map the blocks and use the block offset to write to the real device using the method from the first option; reading could be done directly from the snapshot device.

Quoted 7 lines
Quoted 2 lines

The first and third option are dead on log based file systems (where the data is stored in the log).

All in all, we have three different and working implementation of the image-writing and image-reading code at our disposal. Why would you want to
break the open doors?

Quoted 4 lines

The problem I'm saying kexec solves is how to get the data to the device while most of the kernel is trying not do anything permanent.

If we can reuse existing code, great.

I think we can.

Quoted 10 lines
Quoted 9 lines
Quoted 3 lines
Quoted 1 line

(4) what state should devices be in when switching kernels

My proposal is either initialized and untouched or quiesced.

This is reasonable, but in general we also need to save some information
about the pre-hibernation state of devices, so that we can put them into the
same state, if reasonably possible, during the restore.

Quoted 5 lines

What state are you referring to?

Yes, there is state that the drivers have to store to ram, but this the same state they need to store when suspending to ram if the device can be powered off.

Yes.

Quoted 2 lines

Maybe we need to teach drivers to store more state, like remember that a hard drive was spun down.

I'm not sure about that.

Quoted 2 lines

So we may need a flag saying "we powered off", "we resumed from suspend".

There already is something like this.

Generally, we're going to have a special callback that will be used by the core after the restore, so the driver will always know what it's supposed to do.

Quoted 75 lines
Quoted 17 lines
Quoted 6 lines
Quoted 1 line

(5) the complicated setup required with the current patch

I think a few simple changes to kjump will make this much simpler. See
below.

Quoted 6 lines
Quoted 1 line

(6) what code restores the image

The save kernel, loaded at boot. People have suggested booting the
first kernel, and using current restore code. However, I think that
ignores that (1) we saved from a different kernel, so the backed up region will be restored to its backed up random pages,

This problem has already been solved.

Quoted 1 line

(2) the code was written to restore the same kernel,

Quoted 7 lines

Not exactly. In fact, the current implementation only relies on the tiny
portion of the restore code being in the same place in both kernels, but
we can change the code not to make this assumption (it'll be more complicated,
but that's perfectly doable).

If the save kernel is different from the run kernel (to make it smaller), its likely the image saving code will move. I view restoring from a different kernel than saving as an advanced feature.

Lets get resuming from the save kernel working first.

Quoted 35 lines
Quoted 3 lines

so the text and data will be replaced by identical text. Its much simpler
conceptually to use the same kernel to save and restore the image.

Here I agree. :-)

Quoted 29 lines

Simplifying kjump: the proposal for v3.

The current code is trying to use crash dump area as a safe, reserved
area to run the second kernel. However, that means that the kernel
has to be linked specially to run in the reserved area. I think we
need to finish separating kexec_jump from the other code paths.

(1) add a new command line argument that specifies the kexec_jump target area.

(2) add a kjump flag to the flags parameter, used by kexec_load. When
loading a jump kernel, it is loaded like a normal kernel, however, additional control pages are allocated to (a) save the kexec_jump target area (b) save the backed up region that is used by all kernels like crash dump, and (c) space for invoking relocate_new_kernel that will get its args from the execution entry point and will restore the kernel then call resume and suspend.

(3) replace jump_huf_pfn with two command line addresses that specify the (a) return point for after resume, and (b) the return point for
after image save. Actually these can be done in userspace; the
second
restore kernel can just specify the null copy list and the entry points
supplied by the suspended kernel. To do resume we also need (c) where to store resume address for the save kernel.

Quoted 6 lines
Quoted 3 lines

As a first stage of suspend and resume, we can save to dedicated partitions all memory (as supplied to crash_dump) that is not marked nosave and not part of the save kernel's image.

A little problem here: there are "nosave" areas that are not marked as nosave.

If crash_dump is going work the memory must exist.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

The fancy block lists and memory lists can be added later.

On the majority of systems that will work. On some of them it won't.

Ok .... well, my point is we can get started while we workout what the
list format is. If we decide to reuse the pfn lists above that may
come quickly.

I think it's generally reasonable (a) not to save the entire memory (like free RAM areas etc.) and (b) include the information of the original location of each data page in the image, this way or another.

This doesn't complicate things all that much.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#273 lore raw
Quoted 4 lines

The problem with FUSE is related to the fact that the freezer can't freeze uninterruptible tasks and we said that perhaps we might avoid it if FUSE was made freezing-aware. Still, no one has gone in this direction and I don't know of any plans to do that.

I thought we have fully explored this direction. Lots of emails, and an IRC session with Pavel. Conclusion:

- It can't be done without VFS surgery + adding various hacks to fuse

- VFS surgery for the sake of a working suspend is not realistic

Although removing the freezer seems the cleanest solution, I'm not saying the freezer can't be fixed up in the mean time.

Allowing tasks to remain in uninterruptible sleep seemed a nice way to get around the fuse issues. What was the problem with that patch? It was something that was supposed to have been tested in suspend2, wasn't it?

The other one (trying to wake up task, so that may make other tasks freezable) didn't seem such a good approach to me.

The theory is quite simple: while and after suspending devices, no tasks must be touching said devices.

The very cleanest way to do this is in the drivers. The very simplest way is the current freezer. But may be there are possibilities between these two extremes.

But I can almost guarantee you, that any attempt at fixing the issues though fuse will just result in an even bigger mess than what we currently have.

Miklos

#274 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines

The problem with FUSE is related to the fact that the freezer can't freeze uninterruptible tasks and we said that perhaps we might avoid it if FUSE was made freezing-aware. Still, no one has gone in this direction and I don't know of any plans to do that.

I thought we have fully explored this direction. Lots of emails, and an IRC session with Pavel. Conclusion:

- It can't be done without VFS surgery + adding various hacks to fuse

- VFS surgery for the sake of a working suspend is not realistic

Although removing the freezer seems the cleanest solution, I'm not saying the freezer can't be fixed up in the mean time.

Allowing tasks to remain in uninterruptible sleep seemed a nice way to get around the fuse issues. What was the problem with that patch? It was something that was supposed to have been tested in suspend2, wasn't it?

The other one (trying to wake up task, so that may make other tasks freezable) didn't seem such a good approach to me.

The theory is quite simple: while and after suspending devices, no tasks must be touching said devices.

The very cleanest way to do this is in the drivers. The very simplest way is the current freezer. But may be there are possibilities between these two extremes.

But I can almost guarantee you, that any attempt at fixing the issues though fuse will just result in an even bigger mess than what we currently have.

Miklos

#275 lore raw

Hi.

Quoted 7 lines · On Saturday 21 July 2007 21:44:32 Miklos Szeredi wrote:
Quoted 4 lines

The problem with FUSE is related to the fact that the freezer can't freeze uninterruptible tasks and we said that perhaps we might avoid it if FUSE was made freezing-aware. Still, no one has gone in this direction and I don't know of any plans to do that.

I thought we have fully explored this direction. Lots of emails, and an IRC session with Pavel. Conclusion:

What am I missing in the following suggested solution?

1) In the freezer code, we implement a new TIF_LATEFREEZE process flag, which, when set, causes a userspace process to be frozen with kernel threads instead of with userspace ones. When freezing, we freezing !TIF_LATEFREEZE, sync and then freeze TIF_LATEFREEZE and freezable kernel threads.

2) In the fuse code, the PID of the process that will do the work gets passed to the fuse kernel code when the mount is done. The kernel code sets the TIF_LATEFREEZE flag, and resets it on umount.

Sorry, but this is a hit-and-run email - I'm off to bed now.

Regards,

Nigel

#276 lore raw
In reply to Miklos Szeredi

Hi.

Quoted 7 lines · On Saturday 21 July 2007 21:44:32 Miklos Szeredi wrote:
Quoted 4 lines

The problem with FUSE is related to the fact that the freezer can't freeze uninterruptible tasks and we said that perhaps we might avoid it if FUSE was made freezing-aware. Still, no one has gone in this direction and I don't know of any plans to do that.

I thought we have fully explored this direction. Lots of emails, and an IRC session with Pavel. Conclusion:

What am I missing in the following suggested solution?

1) In the freezer code, we implement a new TIF_LATEFREEZE process flag, which, when set, causes a userspace process to be frozen with kernel threads instead of with userspace ones. When freezing, we freezing !TIF_LATEFREEZE, sync and then freeze TIF_LATEFREEZE and freezable kernel threads.

2) In the fuse code, the PID of the process that will do the work gets passed to the fuse kernel code when the mount is done. The kernel code sets the TIF_LATEFREEZE flag, and resets it on umount.

Sorry, but this is a hit-and-run email - I'm off to bed now.

Regards,

Nigel

#277 lore raw
Quoted 10 lines · Nigel Cunningham

What am I missing in the following suggested solution?

1) In the freezer code, we implement a new TIF_LATEFREEZE process flag, which, when set, causes a userspace process to be frozen with kernel threads instead of with userspace ones. When freezing, we freezing !TIF_LATEFREEZE, sync and then freeze TIF_LATEFREEZE and freezable kernel threads.

2) In the fuse code, the PID of the process that will do the work gets passed to the fuse kernel code when the mount is done. The kernel code sets the TIF_LATEFREEZE flag, and resets it on umount.

What happens when one FUSE filesystem makes use of another? You'll still end up with unfreezable processes, except that now you won't detect them until the LATEFREEZE stage.

Alan Stern

#278 lore raw
In reply to Nigel Cunningham
Quoted 10 lines · Nigel Cunningham

What am I missing in the following suggested solution?

1) In the freezer code, we implement a new TIF_LATEFREEZE process flag, which, when set, causes a userspace process to be frozen with kernel threads instead of with userspace ones. When freezing, we freezing !TIF_LATEFREEZE, sync and then freeze TIF_LATEFREEZE and freezable kernel threads.

2) In the fuse code, the PID of the process that will do the work gets passed to the fuse kernel code when the mount is done. The kernel code sets the TIF_LATEFREEZE flag, and resets it on umount.

What happens when one FUSE filesystem makes use of another? You'll still end up with unfreezable processes, except that now you won't detect them until the LATEFREEZE stage.

Alan Stern

#279 lore raw
In reply to Nigel Cunningham

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

A larger concern is that it seems that freezing FUSE processes at all _will_ generate deadlocks if a non-synchronous or memory-map-supporting filesystem is loopback mounted from a FUSE filesystem. In that case, if you attempt to sync or free memory once FUSE is frozen, you are sure to get a deadlock.

Signature · 1 line
Jeremy Maitin-Shepard
#280 lore raw
In reply to Nigel Cunningham

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

A larger concern is that it seems that freezing FUSE processes at all _will_ generate deadlocks if a non-synchronous or memory-map-supporting filesystem is loopback mounted from a FUSE filesystem. In that case, if you attempt to sync or free memory once FUSE is frozen, you are sure to get a deadlock.

Signature · 1 line
Jeremy Maitin-Shepard
#281 lore raw
Quoted 4 lines

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

It isn't all that unlikely. There's sshfs for example, that depends on a separate ssh process for transport.

Oh, there are also userspace network transports, like tun/tap, nfqueue, etc. They could block any network filesystem (not just fuse) if frozen first, making the freezer fail.

Hmm, wonder why this isn't affecting people with VPNs? Probably network mounts over VPN are rare, and ever rarer to have fs activity on them during suspend.

Anyway, I think it's long overdue to stop thinking about how to "fix" fuse, and concentrate on fixing the underlying problem instead ;)

Quoted 5 lines

A larger concern is that it seems that freezing FUSE processes at all _will_ generate deadlocks if a non-synchronous or memory-map-supporting filesystem is loopback mounted from a FUSE filesystem. In that case, if you attempt to sync or free memory once FUSE is frozen, you are sure to get a deadlock.

Well, it would deadlock, if

a) memory reclaim was synchronous, or
b) large part of the memory was used for dirty file data

I can't remember if (a) was ever true. And now the dirty ratio is 10% by default, so if we go OOM because that 10% can't be reclaimed, there is a more serious problem.

Swap over loop over fuse would be problematic, but that won't work for some time yet ;)

Miklos

#282 lore raw
Quoted 12 lines · Miklos Szeredi
Quoted 4 lines

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

It isn't all that unlikely. There's sshfs for example, that depends on a separate ssh process for transport.

Oh, there are also userspace network transports, like tun/tap, nfqueue, etc. They could block any network filesystem (not just fuse) if frozen first, making the freezer fail.

Quoted 6 lines

Hmm, wonder why this isn't affecting people with VPNs? Probably network mounts over VPN are rare, and ever rarer to have fs activity on them during suspend.

Anyway, I think it's long overdue to stop thinking about how to "fix" fuse, and concentrate on fixing the underlying problem instead ;)

To conclude this branch of the thread, I have a patch in the works that may help a bit with unfreezable FUSE filesystems and it only affects the freezer. I'll post it when 2.6.23-rc1 is out, because it's on top of some other patches that need to go first.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#283 lore raw

Hi!

Quoted 11 lines
Quoted 6 lines

Hmm, wonder why this isn't affecting people with VPNs? Probably network mounts over VPN are rare, and ever rarer to have fs activity on them during suspend.

Anyway, I think it's long overdue to stop thinking about how to "fix" fuse, and concentrate on fixing the underlying problem instead ;)

To conclude this branch of the thread, I have a patch in the works that may help a bit with unfreezable FUSE filesystems and it only affects the freezer. I'll post it when 2.6.23-rc1 is out, because it's on top of some other patches that need to go first.

I'm interested... which one is that?
Pavel

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

Hi!

Quoted 11 lines
Quoted 6 lines

Hmm, wonder why this isn't affecting people with VPNs? Probably network mounts over VPN are rare, and ever rarer to have fs activity on them during suspend.

Anyway, I think it's long overdue to stop thinking about how to "fix" fuse, and concentrate on fixing the underlying problem instead ;)

To conclude this branch of the thread, I have a patch in the works that may help a bit with unfreezable FUSE filesystems and it only affects the freezer. I'll post it when 2.6.23-rc1 is out, because it's on top of some other patches that need to go first.

I'm interested... which one is that?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#285 lore raw
Quoted 9 lines · Pavel Machek

Hi!

Quoted 7 lines
Quoted 6 lines

Hmm, wonder why this isn't affecting people with VPNs? Probably network mounts over VPN are rare, and ever rarer to have fs activity on them during suspend.

Anyway, I think it's long overdue to stop thinking about how to "fix" fuse, and concentrate on fixing the underlying problem instead ;)

Quoted 6 lines
Quoted 4 lines

To conclude this branch of the thread, I have a patch in the works that may help a bit with unfreezable FUSE filesystems and it only affects the freezer. I'll post it when 2.6.23-rc1 is out, because it's on top of some other patches that need to go first.

I'm interested... which one is that?

Appended, on top of this:
https://lists.linux-foundation.org/pipermail/linux-pm/2007-July/014521.html

Greetings,
Rafael

---
 kernel/power/process.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)
kernel/power/process.c +48 -1
Index: linux-2.6.23-rc1/kernel/power/process.c
===================================================================
@@ -30,6 +30,14 @@
  */
 #define MAX_WAITS 5
 
+/*
+ * If the freezing of tasks fails, we attempt to thaw tasks that have already
+ * been frozen to give a chance the other tasks to freeze, in case one or more
+ * of them are blocked by the frozen ones.  If this fails MAX_ATTEMPTS times
+ * in a row, we give up.
+ */
+#define MAX_ATTEMPTS 10
+
 #define FREEZER_KERNEL_THREADS 0
 #define FREEZER_USER_SPACE 1
 
@@ -192,14 +200,21 @@ static void cancel_freezing(struct task_
 static int try_to_freeze_tasks(int freeze_user_space)
 {
 	struct task_struct *g, *p;
-	unsigned int todo, waits;
+	unsigned int todo, waits, attempts;
 	unsigned long ret;
 	struct timeval start, end;
 	s64 elapsed_csecs64;
 	unsigned int elapsed_csecs;
+	char *tick = "-\\|/";
+
+	printk(" ");
+	attempts = 0;
 
 	do_gettimeofday(&start);
 
+ Repeat:
+	printk("\b%c", tick[attempts++ % 4]);
+
 	refrigerator_called = 0;
 	waits = 0;
 	do {
@@ -235,11 +250,43 @@ static int try_to_freeze_tasks(int freez
 		}
 	} while (todo);
 
+	if (todo && attempts <= MAX_ATTEMPTS) {
+		/*
+		 * Some tasks have not been able to freeze.  They might be stuck
+		 * in TASK_UNINTERRUPTIBLE waiting for the frozen tasks.  Try to
+		 * thaw the tasks that have frozen without clearing the freeze
+		 * requests of the remaining tasks and repeat.
+		 */
+		read_lock(&tasklist_lock);
+		do_each_thread(g, p) {
+			if (frozen(p)) {
+				p->flags &= ~PF_FROZEN;
+				wake_up_process(p);
+			}
+		} while_each_thread(g, p);
+		read_unlock(&tasklist_lock);
+
+		ret = wait_event_timeout(refrigerator_waitq,
+						refrigerator_called, TIMEOUT);
+		if (!ret) {
+			/*
+			 * There is a little hope that we will succeed, but at
+			 * least we want to know which tasks have not been
+			 * frozen.  Thus, we are going to repeat once.
+			 */
+			attempts = MAX_ATTEMPTS;
+		}
+
+		goto Repeat;
+	}
+
 	do_gettimeofday(&end);
 	elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
 	do_div(elapsed_csecs64, NSEC_PER_SEC / 100);
 	elapsed_csecs = elapsed_csecs64;
 
+	printk("\b");
+
 	if (todo) {
 		/* This does not unfreeze processes that are already frozen
 		 * (we have slightly ugly calling convention in that respect,
#286 lore raw
In reply to Pavel Machek
Quoted 9 lines · Pavel Machek

Hi!

Quoted 7 lines
Quoted 6 lines

Hmm, wonder why this isn't affecting people with VPNs? Probably network mounts over VPN are rare, and ever rarer to have fs activity on them during suspend.

Anyway, I think it's long overdue to stop thinking about how to "fix" fuse, and concentrate on fixing the underlying problem instead ;)

Quoted 6 lines
Quoted 4 lines

To conclude this branch of the thread, I have a patch in the works that may help a bit with unfreezable FUSE filesystems and it only affects the freezer. I'll post it when 2.6.23-rc1 is out, because it's on top of some other patches that need to go first.

I'm interested... which one is that?

Appended, on top of this:
https://lists.linux-foundation.org/pipermail/linux-pm/2007-July/014521.html

Greetings,
Rafael

---
 kernel/power/process.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)
kernel/power/process.c +48 -1
Index: linux-2.6.23-rc1/kernel/power/process.c
===================================================================
@@ -30,6 +30,14 @@
  */
 #define MAX_WAITS 5
 
+/*
+ * If the freezing of tasks fails, we attempt to thaw tasks that have already
+ * been frozen to give a chance the other tasks to freeze, in case one or more
+ * of them are blocked by the frozen ones.  If this fails MAX_ATTEMPTS times
+ * in a row, we give up.
+ */
+#define MAX_ATTEMPTS 10
+
 #define FREEZER_KERNEL_THREADS 0
 #define FREEZER_USER_SPACE 1
 
@@ -192,14 +200,21 @@ static void cancel_freezing(struct task_
 static int try_to_freeze_tasks(int freeze_user_space)
 {
 	struct task_struct *g, *p;
-	unsigned int todo, waits;
+	unsigned int todo, waits, attempts;
 	unsigned long ret;
 	struct timeval start, end;
 	s64 elapsed_csecs64;
 	unsigned int elapsed_csecs;
+	char *tick = "-\\|/";
+
+	printk(" ");
+	attempts = 0;
 
 	do_gettimeofday(&start);
 
+ Repeat:
+	printk("\b%c", tick[attempts++ % 4]);
+
 	refrigerator_called = 0;
 	waits = 0;
 	do {
@@ -235,11 +250,43 @@ static int try_to_freeze_tasks(int freez
 		}
 	} while (todo);
 
+	if (todo && attempts <= MAX_ATTEMPTS) {
+		/*
+		 * Some tasks have not been able to freeze.  They might be stuck
+		 * in TASK_UNINTERRUPTIBLE waiting for the frozen tasks.  Try to
+		 * thaw the tasks that have frozen without clearing the freeze
+		 * requests of the remaining tasks and repeat.
+		 */
+		read_lock(&tasklist_lock);
+		do_each_thread(g, p) {
+			if (frozen(p)) {
+				p->flags &= ~PF_FROZEN;
+				wake_up_process(p);
+			}
+		} while_each_thread(g, p);
+		read_unlock(&tasklist_lock);
+
+		ret = wait_event_timeout(refrigerator_waitq,
+						refrigerator_called, TIMEOUT);
+		if (!ret) {
+			/*
+			 * There is a little hope that we will succeed, but at
+			 * least we want to know which tasks have not been
+			 * frozen.  Thus, we are going to repeat once.
+			 */
+			attempts = MAX_ATTEMPTS;
+		}
+
+		goto Repeat;
+	}
+
 	do_gettimeofday(&end);
 	elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
 	do_div(elapsed_csecs64, NSEC_PER_SEC / 100);
 	elapsed_csecs = elapsed_csecs64;
 
+	printk("\b");
+
 	if (todo) {
 		/* This does not unfreeze processes that are already frozen
 		 * (we have slightly ugly calling convention in that respect,

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#287 lore raw
In reply to Pavel Machek
Quoted 9 lines · Pavel Machek

Hi!

Quoted 7 lines
Quoted 6 lines

Hmm, wonder why this isn't affecting people with VPNs? Probably network mounts over VPN are rare, and ever rarer to have fs activity on them during suspend.

Anyway, I think it's long overdue to stop thinking about how to "fix" fuse, and concentrate on fixing the underlying problem instead ;)

Quoted 6 lines
Quoted 4 lines

To conclude this branch of the thread, I have a patch in the works that may help a bit with unfreezable FUSE filesystems and it only affects the freezer. I'll post it when 2.6.23-rc1 is out, because it's on top of some other patches that need to go first.

I'm interested... which one is that?

Appended, on top of this:
https://lists.linux-foundation.org/pipermail/linux-pm/2007-July/014521.html

Greetings,
Rafael

---
 kernel/power/process.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)
kernel/power/process.c +48 -1
Index: linux-2.6.23-rc1/kernel/power/process.c
===================================================================
@@ -30,6 +30,14 @@
  */
 #define MAX_WAITS 5
 
+/*
+ * If the freezing of tasks fails, we attempt to thaw tasks that have already
+ * been frozen to give a chance the other tasks to freeze, in case one or more
+ * of them are blocked by the frozen ones.  If this fails MAX_ATTEMPTS times
+ * in a row, we give up.
+ */
+#define MAX_ATTEMPTS 10
+
 #define FREEZER_KERNEL_THREADS 0
 #define FREEZER_USER_SPACE 1
 
@@ -192,14 +200,21 @@ static void cancel_freezing(struct task_
 static int try_to_freeze_tasks(int freeze_user_space)
 {
 	struct task_struct *g, *p;
-	unsigned int todo, waits;
+	unsigned int todo, waits, attempts;
 	unsigned long ret;
 	struct timeval start, end;
 	s64 elapsed_csecs64;
 	unsigned int elapsed_csecs;
+	char *tick = "-\\|/";
+
+	printk(" ");
+	attempts = 0;
 
 	do_gettimeofday(&start);
 
+ Repeat:
+	printk("\b%c", tick[attempts++ % 4]);
+
 	refrigerator_called = 0;
 	waits = 0;
 	do {
@@ -235,11 +250,43 @@ static int try_to_freeze_tasks(int freez
 		}
 	} while (todo);
 
+	if (todo && attempts <= MAX_ATTEMPTS) {
+		/*
+		 * Some tasks have not been able to freeze.  They might be stuck
+		 * in TASK_UNINTERRUPTIBLE waiting for the frozen tasks.  Try to
+		 * thaw the tasks that have frozen without clearing the freeze
+		 * requests of the remaining tasks and repeat.
+		 */
+		read_lock(&tasklist_lock);
+		do_each_thread(g, p) {
+			if (frozen(p)) {
+				p->flags &= ~PF_FROZEN;
+				wake_up_process(p);
+			}
+		} while_each_thread(g, p);
+		read_unlock(&tasklist_lock);
+
+		ret = wait_event_timeout(refrigerator_waitq,
+						refrigerator_called, TIMEOUT);
+		if (!ret) {
+			/*
+			 * There is a little hope that we will succeed, but at
+			 * least we want to know which tasks have not been
+			 * frozen.  Thus, we are going to repeat once.
+			 */
+			attempts = MAX_ATTEMPTS;
+		}
+
+		goto Repeat;
+	}
+
 	do_gettimeofday(&end);
 	elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
 	do_div(elapsed_csecs64, NSEC_PER_SEC / 100);
 	elapsed_csecs = elapsed_csecs64;
 
+	printk("\b");
+
 	if (todo) {
 		/* This does not unfreeze processes that are already frozen
 		 * (we have slightly ugly calling convention in that respect,
#288 lore raw
In reply to Miklos Szeredi
Quoted 12 lines · Miklos Szeredi
Quoted 4 lines

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

It isn't all that unlikely. There's sshfs for example, that depends on a separate ssh process for transport.

Oh, there are also userspace network transports, like tun/tap, nfqueue, etc. They could block any network filesystem (not just fuse) if frozen first, making the freezer fail.

Quoted 6 lines

Hmm, wonder why this isn't affecting people with VPNs? Probably network mounts over VPN are rare, and ever rarer to have fs activity on them during suspend.

Anyway, I think it's long overdue to stop thinking about how to "fix" fuse, and concentrate on fixing the underlying problem instead ;)

To conclude this branch of the thread, I have a patch in the works that may help a bit with unfreezable FUSE filesystems and it only affects the freezer. I'll post it when 2.6.23-rc1 is out, because it's on top of some other patches that need to go first.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#289 lore raw
In reply to Miklos Szeredi

Hi.

Quoted 12 lines · On Sunday 22 July 2007 04:12:22 Miklos Szeredi wrote:
Quoted 4 lines

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

It isn't all that unlikely. There's sshfs for example, that depends on a separate ssh process for transport.

Oh, there are also userspace network transports, like tun/tap, nfqueue, etc. They could block any network filesystem (not just fuse) if frozen first, making the freezer fail.

Quoted 6 lines

Hmm, wonder why this isn't affecting people with VPNs? Probably network mounts over VPN are rare, and ever rarer to have fs activity on them during suspend.

Anyway, I think it's long overdue to stop thinking about how to "fix" fuse, and concentrate on fixing the underlying problem instead ;)

That's what I'm seeking to do :)

Quoted 10 lines
Quoted 5 lines

A larger concern is that it seems that freezing FUSE processes at all _will_ generate deadlocks if a non-synchronous or memory-map-supporting filesystem is loopback mounted from a FUSE filesystem. In that case, if you attempt to sync or free memory once FUSE is frozen, you are sure to get a deadlock.

Well, it would deadlock, if

a) memory reclaim was synchronous, or
b) large part of the memory was used for dirty file data

These are problems in normal operation, aren't they?

Quoted 6 lines

I can't remember if (a) was ever true. And now the dirty ratio is 10% by default, so if we go OOM because that 10% can't be reclaimed, there is a more serious problem.

Swap over loop over fuse would be problematic, but that won't work for some time yet ;)

Hopefully people will wake up to the problems with Fuse and get rid of it before then :|. Of course I don't really expect that to happen.

Nigel

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

Hi.

Quoted 12 lines · On Sunday 22 July 2007 04:12:22 Miklos Szeredi wrote:
Quoted 4 lines

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

It isn't all that unlikely. There's sshfs for example, that depends on a separate ssh process for transport.

Oh, there are also userspace network transports, like tun/tap, nfqueue, etc. They could block any network filesystem (not just fuse) if frozen first, making the freezer fail.

Quoted 6 lines

Hmm, wonder why this isn't affecting people with VPNs? Probably network mounts over VPN are rare, and ever rarer to have fs activity on them during suspend.

Anyway, I think it's long overdue to stop thinking about how to "fix" fuse, and concentrate on fixing the underlying problem instead ;)

That's what I'm seeking to do :)

Quoted 10 lines
Quoted 5 lines

A larger concern is that it seems that freezing FUSE processes at all _will_ generate deadlocks if a non-synchronous or memory-map-supporting filesystem is loopback mounted from a FUSE filesystem. In that case, if you attempt to sync or free memory once FUSE is frozen, you are sure to get a deadlock.

Well, it would deadlock, if

a) memory reclaim was synchronous, or
b) large part of the memory was used for dirty file data

These are problems in normal operation, aren't they?

Quoted 6 lines

I can't remember if (a) was ever true. And now the dirty ratio is 10% by default, so if we go OOM because that 10% can't be reclaimed, there is a more serious problem.

Swap over loop over fuse would be problematic, but that won't work for some time yet ;)

Hopefully people will wake up to the problems with Fuse and get rid of it before then :|. Of course I don't really expect that to happen.

Nigel

Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing
lists, wiki and bugzilla info.
#291 lore raw
In reply to Jeremy Maitin-Shepard

Hi.

Quoted 10 lines · On Sunday 22 July 2007 02:13:56 Jeremy Maitin-Shepard wrote:

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

A larger concern is that it seems that freezing FUSE processes at all _will_ generate deadlocks if a non-synchronous or memory-map-supporting filesystem is loopback mounted from a FUSE filesystem. In that case, if you attempt to sync or free memory once FUSE is frozen, you are sure to get a deadlock.

Ok. So then (in response to Alan too), how about keeping a tree of mounts, akin to the device tree, and working from the deepest nodes up? (In conjunction with what I already suggested)?

Regards,

Nigel

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

Hi.

Quoted 10 lines · On Sunday 22 July 2007 02:13:56 Jeremy Maitin-Shepard wrote:

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

A larger concern is that it seems that freezing FUSE processes at all _will_ generate deadlocks if a non-synchronous or memory-map-supporting filesystem is loopback mounted from a FUSE filesystem. In that case, if you attempt to sync or free memory once FUSE is frozen, you are sure to get a deadlock.

Quoted 3 lines

Ok. So then (in response to Alan too), how about keeping a tree of mounts, akin to the device tree, and working from the deepest nodes up? (In conjunction with what I already suggested)?

Face it, Nigel, this is a losing battle. You can try to come up with ever-more complex schemes to try and force FUSE into the freezer's framework, but it just won't fit. Or if it does, the next filesystem to come along will require an even more baroque type of special-case handling.

The general problem is that task A may be in an unfreezable state, waiting for task B to do something, while task B is already frozen. Since there's no reasonable way to determine that A really is waiting for B, you're just stuck. (To make matters worse, A may not even realize which task it is waiting for; it may know only that it's waiting for somebody to do something!) A and B could be user tasks, kernel threads, or one of each.

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

Alan Stern

#293 lore raw
In reply to Nigel Cunningham
Quoted 14 lines · Nigel Cunningham

Hi.

Quoted 10 lines · On Sunday 22 July 2007 02:13:56 Jeremy Maitin-Shepard wrote:

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

A larger concern is that it seems that freezing FUSE processes at all _will_ generate deadlocks if a non-synchronous or memory-map-supporting filesystem is loopback mounted from a FUSE filesystem. In that case, if you attempt to sync or free memory once FUSE is frozen, you are sure to get a deadlock.

Quoted 3 lines

Ok. So then (in response to Alan too), how about keeping a tree of mounts, akin to the device tree, and working from the deepest nodes up? (In conjunction with what I already suggested)?

Face it, Nigel, this is a losing battle. You can try to come up with ever-more complex schemes to try and force FUSE into the freezer's framework, but it just won't fit. Or if it does, the next filesystem to come along will require an even more baroque type of special-case handling.

The general problem is that task A may be in an unfreezable state, waiting for task B to do something, while task B is already frozen. Since there's no reasonable way to determine that A really is waiting for B, you're just stuck. (To make matters worse, A may not even realize which task it is waiting for; it may know only that it's waiting for somebody to do something!) A and B could be user tasks, kernel threads, or one of each.

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

Alan Stern

#294 lore raw
Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

Have we some proof, that this will untangle the freezing tasks in a limited time? Or will it just make the problem harder to trigger?

Miklos

#295 lore raw
Quoted 5 lines · Miklos Szeredi
Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

Have we some proof, that this will untangle the freezing tasks in a limited time? Or will it just make the problem harder to trigger?

Of course there's no proof. Just the opposite -- if things get hung up the first time, they might get hung up the second time. And the third...

But it ought to make the problem harder to trigger. For the present that's a worthwhile improvement.

Alan Stern

#296 lore raw
In reply to Miklos Szeredi
Quoted 5 lines · Miklos Szeredi
Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

Have we some proof, that this will untangle the freezing tasks in a limited time? Or will it just make the problem harder to trigger?

Of course there's no proof. Just the opposite -- if things get hung up the first time, they might get hung up the second time. And the third...

But it ought to make the problem harder to trigger. For the present that's a worthwhile improvement.

Alan Stern

#297 lore raw
Quoted 8 lines · Alan Stern
Quoted 5 lines · Miklos Szeredi
Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

Have we some proof, that this will untangle the freezing tasks in a limited time? Or will it just make the problem harder to trigger?

Quoted 6 lines

Of course there's no proof. Just the opposite -- if things get hung up the first time, they might get hung up the second time. And the third...

But it ought to make the problem harder to trigger. For the present that's a worthwhile improvement.

it gives the system more tries to find a spot in time where the deadlock doesn't happen, if you find one you can continue.

but even if things keep getting hung up, at least you are backing out of each try safely and can eventually tell the user "I give up, try shutting some things down and suspending again"

David Lang

#298 lore raw
In reply to Alan Stern

Hi Alan.

Quoted 20 lines · On Monday 23 July 2007 01:26:23 Alan Stern wrote:
Quoted 14 lines · Nigel Cunningham

Hi.

Quoted 10 lines · On Sunday 22 July 2007 02:13:56 Jeremy Maitin-Shepard wrote:

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

A larger concern is that it seems that freezing FUSE processes at all _will_ generate deadlocks if a non-synchronous or memory-map-supporting filesystem is loopback mounted from a FUSE filesystem. In that case, if you attempt to sync or free memory once FUSE is frozen, you are sure to get a deadlock.

Quoted 3 lines

Ok. So then (in response to Alan too), how about keeping a tree of mounts, akin to the device tree, and working from the deepest nodes up? (In conjunction with what I already suggested)?

Quoted 5 lines

Face it, Nigel, this is a losing battle. You can try to come up with ever-more complex schemes to try and force FUSE into the freezer's framework, but it just won't fit. Or if it does, the next filesystem to come along will require an even more baroque type of special-case handling.

It does seem to be a losing battle, but I'm wondering whether that's really because it's an intractable problem, or because people have given up on it before its time. We are talking about a computer system, so things should be predictable.

Quoted 7 lines

The general problem is that task A may be in an unfreezable state, waiting for task B to do something, while task B is already frozen. Since there's no reasonable way to determine that A really is waiting for B, you're just stuck. (To make matters worse, A may not even realize which task it is waiting for; it may know only that it's waiting for somebody to do something!) A and B could be user tasks, kernel threads, or one of each.

I guess I want to persist because all of these issues aren't utterly unsolvable. It's just that we don't have the infrastructure yet to figure out the solutions to these issues trivially. Take, for example, the locking issue. If we could call some function to say "What process holds this lock?", then task A could know that it's waiting on task B and put that information somewhere. We could then use the information to freeze task B before task A.

Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

That's what I'm questioning. Is there a more reliable way and we've just given up too quickly?

Regards,

Nigel

Signature · 5 lines
Nigel Cunningham
Christian Reformed Church of Cobden
103 Curdie Street, Cobden 3266, Victoria, Australia
Ph. +61 3 5595 1185 / +61 417 100 574
Communal Worship: 11 am Sunday.
#299 lore raw
In reply to Alan Stern

Hi Alan.

Quoted 20 lines · On Monday 23 July 2007 01:26:23 Alan Stern wrote:
Quoted 14 lines · Nigel Cunningham

Hi.

Quoted 10 lines · On Sunday 22 July 2007 02:13:56 Jeremy Maitin-Shepard wrote:

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

A larger concern is that it seems that freezing FUSE processes at all _will_ generate deadlocks if a non-synchronous or memory-map-supporting filesystem is loopback mounted from a FUSE filesystem. In that case, if you attempt to sync or free memory once FUSE is frozen, you are sure to get a deadlock.

Quoted 3 lines

Ok. So then (in response to Alan too), how about keeping a tree of mounts, akin to the device tree, and working from the deepest nodes up? (In conjunction with what I already suggested)?

Quoted 5 lines

Face it, Nigel, this is a losing battle. You can try to come up with ever-more complex schemes to try and force FUSE into the freezer's framework, but it just won't fit. Or if it does, the next filesystem to come along will require an even more baroque type of special-case handling.

It does seem to be a losing battle, but I'm wondering whether that's really because it's an intractable problem, or because people have given up on it before its time. We are talking about a computer system, so things should be predictable.

Quoted 7 lines

The general problem is that task A may be in an unfreezable state, waiting for task B to do something, while task B is already frozen. Since there's no reasonable way to determine that A really is waiting for B, you're just stuck. (To make matters worse, A may not even realize which task it is waiting for; it may know only that it's waiting for somebody to do something!) A and B could be user tasks, kernel threads, or one of each.

I guess I want to persist because all of these issues aren't utterly unsolvable. It's just that we don't have the infrastructure yet to figure out the solutions to these issues trivially. Take, for example, the locking issue. If we could call some function to say "What process holds this lock?", then task A could know that it's waiting on task B and put that information somewhere. We could then use the information to freeze task B before task A.

Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

That's what I'm questioning. Is there a more reliable way and we've just given up too quickly?

Regards,

Nigel

Signature · 5 lines
Nigel Cunningham
Christian Reformed Church of Cobden
103 Curdie Street, Cobden 3266, Victoria, Australia
Ph. +61 3 5595 1185 / +61 417 100 574
Communal Worship: 11 am Sunday.
#300 lore raw

Hi,

Quoted 50 lines · Nigel Cunningham

Hi Alan.

Quoted 20 lines · On Monday 23 July 2007 01:26:23 Alan Stern wrote:
Quoted 14 lines · Nigel Cunningham

Hi.

Quoted 10 lines · On Sunday 22 July 2007 02:13:56 Jeremy Maitin-Shepard wrote:

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

A larger concern is that it seems that freezing FUSE processes at all _will_ generate deadlocks if a non-synchronous or memory-map-supporting filesystem is loopback mounted from a FUSE filesystem. In that case, if you attempt to sync or free memory once FUSE is frozen, you are sure to get a deadlock.

Quoted 3 lines

Ok. So then (in response to Alan too), how about keeping a tree of mounts, akin to the device tree, and working from the deepest nodes up? (In conjunction with what I already suggested)?

Quoted 5 lines

Face it, Nigel, this is a losing battle. You can try to come up with ever-more complex schemes to try and force FUSE into the freezer's framework, but it just won't fit. Or if it does, the next filesystem to come along will require an even more baroque type of special-case handling.

It does seem to be a losing battle, but I'm wondering whether that's really because it's an intractable problem, or because people have given up on it before its time. We are talking about a computer system, so things should be predictable.

Quoted 7 lines

The general problem is that task A may be in an unfreezable state, waiting for task B to do something, while task B is already frozen. Since there's no reasonable way to determine that A really is waiting for B, you're just stuck. (To make matters worse, A may not even realize which task it is waiting for; it may know only that it's waiting for somebody to do something!) A and B could be user tasks, kernel threads, or one of each.

I guess I want to persist because all of these issues aren't utterly unsolvable. It's just that we don't have the infrastructure yet to figure out the solutions to these issues trivially. Take, for example, the locking issue. If we could call some function to say "What process holds this lock?", then task A could know that it's waiting on task B and put that information somewhere. We could then use the information to freeze task B before task A.

Quoted 5 lines
Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

That's what I'm questioning. Is there a more reliable way and we've just given up too quickly?

Well, there probably is one, but it likely would require us to make changes that wouldn't be accepted by some people and thus would never be merged.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#301 lore raw
Quoted 12 lines · On Monday 23 July 2007 09:09:21 Rafael J. Wysocki wrote:

Hi,

Quoted 9 lines · Nigel Cunningham

Hi Alan.

Quoted 6 lines · On Monday 23 July 2007 01:26:23 Alan Stern wrote:
Quoted 4 lines · Nigel Cunningham

Hi.

Quoted 1 line · On Sunday 22 July 2007 02:13:56 Jeremy Maitin-Shepard wrote:

It seems that you could still potentially get a failure to freeze if

one

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

FUSE process depends on another, and the one that is frozen second

just

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

happens to be waiting on the one that is frozen first when it is

frozen.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I admit that this situation is unlikely, and perhaps acceptable.

A larger concern is that it seems that freezing FUSE processes at

all

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

_will_ generate deadlocks if a non-synchronous or

memory-map-supporting

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

filesystem is loopback mounted from a FUSE filesystem. In that

case, if

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

you attempt to sync or free memory once FUSE is frozen, you are sure

to

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

get a deadlock.

Ok. So then (in response to Alan too), how about keeping a tree of

mounts,

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 2 lines

akin to the device tree, and working from the deepest nodes up? (In conjunction with what I already suggested)?

Face it, Nigel, this is a losing battle. You can try to come up with ever-more complex schemes to try and force FUSE into the freezer's framework, but it just won't fit. Or if it does, the next filesystem to come along will require an even more baroque type of special-case handling.

It does seem to be a losing battle, but I'm wondering whether that's

really

Quoted 2 lines
Quoted 2 lines

because it's an intractable problem, or because people have given up on it before its time. We are talking about a computer system, so things should

be

Quoted 10 lines
Quoted 10 lines

predictable.

Quoted 7 lines

The general problem is that task A may be in an unfreezable state, waiting for task B to do something, while task B is already frozen. Since there's no reasonable way to determine that A really is waiting for B, you're just stuck. (To make matters worse, A may not even realize which task it is waiting for; it may know only that it's waiting for somebody to do something!) A and B could be user tasks, kernel threads, or one of each.

Quoted 2 lines
Quoted 2 lines

I guess I want to persist because all of these issues aren't utterly unsolvable. It's just that we don't have the infrastructure yet to figure

out

Quoted 2 lines
Quoted 2 lines

the solutions to these issues trivially. Take, for example, the locking issue. If we could call some function to say "What process holds this

lock?",

Quoted 1 line
Quoted 1 line

then task A could know that it's waiting on task B and put that

information

Quoted 1 line
Quoted 1 line

somewhere. We could then use the information to freeze task B before task

A.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

That's what I'm questioning. Is there a more reliable way and we've just

given

Quoted 4 lines
Quoted 1 line

up too quickly?

Well, there probably is one, but it likely would require us to make changes that wouldn't be accepted by some people and thus would never be merged.

Well, doesn't that imply that we should at least look into what changes would be needed? If they wouldn't be accepted by some people, then either the objections would be reasonable or they wouldn't (and would hopefully be overridden). But we can't know if we don't try.

Regards,

Nigel

Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing
lists, wiki and bugzilla info.
#302 lore raw
In reply to Rafael J. Wysocki
Quoted 12 lines · On Monday 23 July 2007 09:09:21 Rafael J. Wysocki wrote:

Hi,

Quoted 9 lines · Nigel Cunningham

Hi Alan.

Quoted 6 lines · On Monday 23 July 2007 01:26:23 Alan Stern wrote:
Quoted 4 lines · Nigel Cunningham

Hi.

Quoted 1 line · On Sunday 22 July 2007 02:13:56 Jeremy Maitin-Shepard wrote:

It seems that you could still potentially get a failure to freeze if

one

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

FUSE process depends on another, and the one that is frozen second

just

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

happens to be waiting on the one that is frozen first when it is

frozen.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I admit that this situation is unlikely, and perhaps acceptable.

A larger concern is that it seems that freezing FUSE processes at

all

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

_will_ generate deadlocks if a non-synchronous or

memory-map-supporting

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

filesystem is loopback mounted from a FUSE filesystem. In that

case, if

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

you attempt to sync or free memory once FUSE is frozen, you are sure

to

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

get a deadlock.

Ok. So then (in response to Alan too), how about keeping a tree of

mounts,

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 2 lines

akin to the device tree, and working from the deepest nodes up? (In conjunction with what I already suggested)?

Face it, Nigel, this is a losing battle. You can try to come up with ever-more complex schemes to try and force FUSE into the freezer's framework, but it just won't fit. Or if it does, the next filesystem to come along will require an even more baroque type of special-case handling.

It does seem to be a losing battle, but I'm wondering whether that's

really

Quoted 2 lines
Quoted 2 lines

because it's an intractable problem, or because people have given up on it before its time. We are talking about a computer system, so things should

be

Quoted 10 lines
Quoted 10 lines

predictable.

Quoted 7 lines

The general problem is that task A may be in an unfreezable state, waiting for task B to do something, while task B is already frozen. Since there's no reasonable way to determine that A really is waiting for B, you're just stuck. (To make matters worse, A may not even realize which task it is waiting for; it may know only that it's waiting for somebody to do something!) A and B could be user tasks, kernel threads, or one of each.

Quoted 2 lines
Quoted 2 lines

I guess I want to persist because all of these issues aren't utterly unsolvable. It's just that we don't have the infrastructure yet to figure

out

Quoted 2 lines
Quoted 2 lines

the solutions to these issues trivially. Take, for example, the locking issue. If we could call some function to say "What process holds this

lock?",

Quoted 1 line
Quoted 1 line

then task A could know that it's waiting on task B and put that

information

Quoted 1 line
Quoted 1 line

somewhere. We could then use the information to freeze task B before task

A.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

That's what I'm questioning. Is there a more reliable way and we've just

given

Quoted 4 lines
Quoted 1 line

up too quickly?

Well, there probably is one, but it likely would require us to make changes that wouldn't be accepted by some people and thus would never be merged.

Well, doesn't that imply that we should at least look into what changes would be needed? If they wouldn't be accepted by some people, then either the objections would be reasonable or they wouldn't (and would hopefully be overridden). But we can't know if we don't try.

Regards,

Nigel

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

Hi,

Quoted 50 lines · Nigel Cunningham

Hi Alan.

Quoted 20 lines · On Monday 23 July 2007 01:26:23 Alan Stern wrote:
Quoted 14 lines · Nigel Cunningham

Hi.

Quoted 10 lines · On Sunday 22 July 2007 02:13:56 Jeremy Maitin-Shepard wrote:

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

A larger concern is that it seems that freezing FUSE processes at all _will_ generate deadlocks if a non-synchronous or memory-map-supporting filesystem is loopback mounted from a FUSE filesystem. In that case, if you attempt to sync or free memory once FUSE is frozen, you are sure to get a deadlock.

Quoted 3 lines

Ok. So then (in response to Alan too), how about keeping a tree of mounts, akin to the device tree, and working from the deepest nodes up? (In conjunction with what I already suggested)?

Quoted 5 lines

Face it, Nigel, this is a losing battle. You can try to come up with ever-more complex schemes to try and force FUSE into the freezer's framework, but it just won't fit. Or if it does, the next filesystem to come along will require an even more baroque type of special-case handling.

It does seem to be a losing battle, but I'm wondering whether that's really because it's an intractable problem, or because people have given up on it before its time. We are talking about a computer system, so things should be predictable.

Quoted 7 lines

The general problem is that task A may be in an unfreezable state, waiting for task B to do something, while task B is already frozen. Since there's no reasonable way to determine that A really is waiting for B, you're just stuck. (To make matters worse, A may not even realize which task it is waiting for; it may know only that it's waiting for somebody to do something!) A and B could be user tasks, kernel threads, or one of each.

I guess I want to persist because all of these issues aren't utterly unsolvable. It's just that we don't have the infrastructure yet to figure out the solutions to these issues trivially. Take, for example, the locking issue. If we could call some function to say "What process holds this lock?", then task A could know that it's waiting on task B and put that information somewhere. We could then use the information to freeze task B before task A.

Quoted 5 lines
Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

That's what I'm questioning. Is there a more reliable way and we've just given up too quickly?

Well, there probably is one, but it likely would require us to make changes that wouldn't be accepted by some people and thus would never be merged.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#304 lore raw
In reply to Nigel Cunningham
Quoted 3 lines · Nigel Cunningham

I guess I want to persist because all of these issues aren't utterly unsolvable. It's just that we don't have the infrastructure yet to figure out the solutions to these issues trivially. Take, for example,

Ever heard of the halting problem? :) It's not just a matter of infrastructure. You very quickly get into questions that are mathematically undecideable.

Quoted 4 lines

the locking issue. If we could call some function to say "What process holds this lock?", then task A could know that it's waiting on task B and put that information somewhere. We could then use the information to freeze task B before task A.

But how would that help? If task B holds the lock, then we can't freeze it until it's released the lock. Then the question is, what does task B need in order to get to the point where it releases the lock? And so on. It rapidly gets not just extremely messy, but actually impossible to compute in general.

Paul.

#305 lore raw
In reply to Nigel Cunningham
Quoted 3 lines · Nigel Cunningham

I guess I want to persist because all of these issues aren't utterly unsolvable. It's just that we don't have the infrastructure yet to figure out the solutions to these issues trivially. Take, for example,

Ever heard of the halting problem? :) It's not just a matter of infrastructure. You very quickly get into questions that are mathematically undecideable.

Quoted 4 lines

the locking issue. If we could call some function to say "What process holds this lock?", then task A could know that it's waiting on task B and put that information somewhere. We could then use the information to freeze task B before task A.

But how would that help? If task B holds the lock, then we can't freeze it until it's released the lock. Then the question is, what does task B need in order to get to the point where it releases the lock? And so on. It rapidly gets not just extremely messy, but actually impossible to compute in general.

Paul.

#306 lore raw

Hi.

Quoted 9 lines · On Monday 23 July 2007 10:04:43 Paul Mackerras wrote:
Quoted 3 lines · Nigel Cunningham

I guess I want to persist because all of these issues aren't utterly unsolvable. It's just that we don't have the infrastructure yet to figure out the solutions to these issues trivially. Take, for example,

Ever heard of the halting problem? :) It's not just a matter of infrastructure. You very quickly get into questions that are mathematically undecideable.

Is this the halting problem, though?

Quoted 10 lines
Quoted 4 lines

the locking issue. If we could call some function to say "What process holds this lock?", then task A could know that it's waiting on task B and put that information somewhere. We could then use the information to freeze task B before task A.

But how would that help? If task B holds the lock, then we can't freeze it until it's released the lock. Then the question is, what does task B need in order to get to the point where it releases the lock? And so on. It rapidly gets not just extremely messy, but actually impossible to compute in general.

Take a step back for a second.

The problem we're facing now is that we're getting some userspace threads, used in processing I/O, that are functioning as exceptions to the "freeze userspace, then freezeable kernel threads" rule. They are only exceptions because of that role in processing I/O - because they're de facto kernel threads. So, if we orient our thinking more in terms of I/O processing and less in terms of the userspace/kernelspace distinction, we'll have a solution:

1) Freeze processes that aren't fs related (ie stop them generating I/O).
2) Flush pending I/O.
3) Freeze filesystems in reverse order of dependency, the primary purpose being to stop them generating further I/O on their metadata.

Locks that are being held are only being held because work is being done. If we progressively focus on threads in terms of their create/process work dependencies, we'll see that the problem isn't at all intractable.

Regards,

Nigel

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

Hi.

Quoted 9 lines · On Monday 23 July 2007 10:04:43 Paul Mackerras wrote:
Quoted 3 lines · Nigel Cunningham

I guess I want to persist because all of these issues aren't utterly unsolvable. It's just that we don't have the infrastructure yet to figure out the solutions to these issues trivially. Take, for example,

Ever heard of the halting problem? :) It's not just a matter of infrastructure. You very quickly get into questions that are mathematically undecideable.

Is this the halting problem, though?

Quoted 10 lines
Quoted 4 lines

the locking issue. If we could call some function to say "What process holds this lock?", then task A could know that it's waiting on task B and put that information somewhere. We could then use the information to freeze task B before task A.

But how would that help? If task B holds the lock, then we can't freeze it until it's released the lock. Then the question is, what does task B need in order to get to the point where it releases the lock? And so on. It rapidly gets not just extremely messy, but actually impossible to compute in general.

Take a step back for a second.

The problem we're facing now is that we're getting some userspace threads, used in processing I/O, that are functioning as exceptions to the "freeze userspace, then freezeable kernel threads" rule. They are only exceptions because of that role in processing I/O - because they're de facto kernel threads. So, if we orient our thinking more in terms of I/O processing and less in terms of the userspace/kernelspace distinction, we'll have a solution:

1) Freeze processes that aren't fs related (ie stop them generating I/O).
2) Flush pending I/O.
3) Freeze filesystems in reverse order of dependency, the primary purpose being to stop them generating further I/O on their metadata.

Locks that are being held are only being held because work is being done. If we progressively focus on threads in terms of their create/process work dependencies, we'll see that the problem isn't at all intractable.

Regards,

Nigel

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

Take a step back for a second.

The problem we're facing now is that we're getting some userspace threads, used in processing I/O, that are functioning as exceptions to the "freeze userspace, then freezeable kernel threads" rule. They are only exceptions because of that role in processing I/O - because they're de facto kernel threads. So, if we orient our thinking more in terms of I/O processing and less in terms of the userspace/kernelspace distinction, we'll have a solution:

1) Freeze processes that aren't fs related (ie stop them generating I/O).

The problem here is that with things like FUSE, _every_ process is potentially fs related. Nothing prevents a FUSE thread from doing IPC with any other thread.

Quoted 7 lines

2) Flush pending I/O.
3) Freeze filesystems in reverse order of dependency, the primary purpose being to stop them generating further I/O on their metadata.

Locks that are being held are only being held because work is being done. If we progressively focus on threads in terms of their create/process work dependencies, we'll see that the problem isn't at all intractable.

As has been mentioned before, keeping track of all that dependency information would be very fragile and time-consuming.

Alan Stern

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

Take a step back for a second.

The problem we're facing now is that we're getting some userspace threads, used in processing I/O, that are functioning as exceptions to the "freeze userspace, then freezeable kernel threads" rule. They are only exceptions because of that role in processing I/O - because they're de facto kernel threads. So, if we orient our thinking more in terms of I/O processing and less in terms of the userspace/kernelspace distinction, we'll have a solution:

1) Freeze processes that aren't fs related (ie stop them generating I/O).

The problem here is that with things like FUSE, _every_ process is potentially fs related. Nothing prevents a FUSE thread from doing IPC with any other thread.

Quoted 7 lines

2) Flush pending I/O.
3) Freeze filesystems in reverse order of dependency, the primary purpose being to stop them generating further I/O on their metadata.

Locks that are being held are only being held because work is being done. If we progressively focus on threads in terms of their create/process work dependencies, we'll see that the problem isn't at all intractable.

As has been mentioned before, keeping track of all that dependency information would be very fragile and time-consuming.

Alan Stern

#310 lore raw

Hi.

Quoted 12 lines · On Tuesday 24 July 2007 01:23:15 Alan Stern wrote:
Quoted 10 lines · Nigel Cunningham

Take a step back for a second.

The problem we're facing now is that we're getting some userspace threads, used in processing I/O, that are functioning as exceptions to the "freeze userspace, then freezeable kernel threads" rule. They are only exceptions because of that role in processing I/O - because they're de facto kernel threads. So, if we orient our thinking more in terms of I/O processing and less in terms of the userspace/kernelspace distinction, we'll have a solution:

Quoted 5 lines
Quoted 1 line

1) Freeze processes that aren't fs related (ie stop them generating I/O).

The problem here is that with things like FUSE, _every_ process is potentially fs related. Nothing prevents a FUSE thread from doing IPC with any other thread.

Yes, but the fuse thread is going to know what other thread it's doing IPC with, so it can get that thread flagged too.

Quoted 5 lines
Quoted 5 lines

2) Flush pending I/O.
3) Freeze filesystems in reverse order of dependency, the primary purpose being to stop them generating further I/O on their metadata.

Locks that are being held are only being held because work is being done.

If

Quoted 5 lines
Quoted 2 lines

we progressively focus on threads in terms of their create/process work dependencies, we'll see that the problem isn't at all intractable.

As has been mentioned before, keeping track of all that dependency information would be very fragile and time-consuming.

I disagree. It's at least going to be less fragile and time-consuming then maintaining new/extra code for kexec.

Nigel

#311 lore raw
In reply to Alan Stern

Hi.

Quoted 12 lines · On Tuesday 24 July 2007 01:23:15 Alan Stern wrote:
Quoted 10 lines · Nigel Cunningham

Take a step back for a second.

The problem we're facing now is that we're getting some userspace threads, used in processing I/O, that are functioning as exceptions to the "freeze userspace, then freezeable kernel threads" rule. They are only exceptions because of that role in processing I/O - because they're de facto kernel threads. So, if we orient our thinking more in terms of I/O processing and less in terms of the userspace/kernelspace distinction, we'll have a solution:

Quoted 5 lines
Quoted 1 line

1) Freeze processes that aren't fs related (ie stop them generating I/O).

The problem here is that with things like FUSE, _every_ process is potentially fs related. Nothing prevents a FUSE thread from doing IPC with any other thread.

Yes, but the fuse thread is going to know what other thread it's doing IPC with, so it can get that thread flagged too.

Quoted 5 lines
Quoted 5 lines

2) Flush pending I/O.
3) Freeze filesystems in reverse order of dependency, the primary purpose being to stop them generating further I/O on their metadata.

Locks that are being held are only being held because work is being done.

If

Quoted 5 lines
Quoted 2 lines

we progressively focus on threads in terms of their create/process work dependencies, we'll see that the problem isn't at all intractable.

As has been mentioned before, keeping track of all that dependency information would be very fragile and time-consuming.

I disagree. It's at least going to be less fragile and time-consuming then maintaining new/extra code for kexec.

Nigel

#312 lore raw
Quoted 15 lines · Nigel Cunningham

Hi.

Quoted 12 lines · On Tuesday 24 July 2007 01:23:15 Alan Stern wrote:
Quoted 10 lines · Nigel Cunningham

Take a step back for a second.

The problem we're facing now is that we're getting some userspace threads, used in processing I/O, that are functioning as exceptions to the "freeze userspace, then freezeable kernel threads" rule. They are only exceptions because of that role in processing I/O - because they're de facto kernel threads. So, if we orient our thinking more in terms of I/O processing and less in terms of the userspace/kernelspace distinction, we'll have a solution:

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

1) Freeze processes that aren't fs related (ie stop them generating I/O).

The problem here is that with things like FUSE, _every_ process is potentially fs related. Nothing prevents a FUSE thread from doing IPC with any other thread.

Yes, but the fuse thread is going to know what other thread it's doing IPC with, so it can get that thread flagged too.

Yes, but that thread may do IPC with yet another one and so on.

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

2) Flush pending I/O.
3) Freeze filesystems in reverse order of dependency, the primary purpose being to stop them generating further I/O on their metadata.

Locks that are being held are only being held because work is being done.

If

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

we progressively focus on threads in terms of their create/process work dependencies, we'll see that the problem isn't at all intractable.

As has been mentioned before, keeping track of all that dependency information would be very fragile and time-consuming.

I disagree. It's at least going to be less fragile and time-consuming then maintaining new/extra code for kexec.

Well, I think the issue is real, so we need to find a solution (the simpler, the better) and that need not be related to kexec. ;-)

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#313 lore raw
In reply to Nigel Cunningham
Quoted 15 lines · Nigel Cunningham

Hi.

Quoted 12 lines · On Tuesday 24 July 2007 01:23:15 Alan Stern wrote:
Quoted 10 lines · Nigel Cunningham

Take a step back for a second.

The problem we're facing now is that we're getting some userspace threads, used in processing I/O, that are functioning as exceptions to the "freeze userspace, then freezeable kernel threads" rule. They are only exceptions because of that role in processing I/O - because they're de facto kernel threads. So, if we orient our thinking more in terms of I/O processing and less in terms of the userspace/kernelspace distinction, we'll have a solution:

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

1) Freeze processes that aren't fs related (ie stop them generating I/O).

The problem here is that with things like FUSE, _every_ process is potentially fs related. Nothing prevents a FUSE thread from doing IPC with any other thread.

Yes, but the fuse thread is going to know what other thread it's doing IPC with, so it can get that thread flagged too.

Yes, but that thread may do IPC with yet another one and so on.

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

2) Flush pending I/O.
3) Freeze filesystems in reverse order of dependency, the primary purpose being to stop them generating further I/O on their metadata.

Locks that are being held are only being held because work is being done.

If

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

we progressively focus on threads in terms of their create/process work dependencies, we'll see that the problem isn't at all intractable.

As has been mentioned before, keeping track of all that dependency information would be very fragile and time-consuming.

I disagree. It's at least going to be less fragile and time-consuming then maintaining new/extra code for kexec.

Well, I think the issue is real, so we need to find a solution (the simpler, the better) and that need not be related to kexec. ;-)

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#314 lore raw
In reply to Nigel Cunningham
Quoted 42 lines · Nigel Cunningham

Hi Alan.

Quoted 20 lines · On Monday 23 July 2007 01:26:23 Alan Stern wrote:
Quoted 14 lines · Nigel Cunningham

Hi.

Quoted 10 lines · On Sunday 22 July 2007 02:13:56 Jeremy Maitin-Shepard wrote:

It seems that you could still potentially get a failure to freeze if one FUSE process depends on another, and the one that is frozen second just happens to be waiting on the one that is frozen first when it is frozen. I admit that this situation is unlikely, and perhaps acceptable.

A larger concern is that it seems that freezing FUSE processes at all _will_ generate deadlocks if a non-synchronous or memory-map-supporting filesystem is loopback mounted from a FUSE filesystem. In that case, if you attempt to sync or free memory once FUSE is frozen, you are sure to get a deadlock.

Quoted 3 lines

Ok. So then (in response to Alan too), how about keeping a tree of mounts, akin to the device tree, and working from the deepest nodes up? (In conjunction with what I already suggested)?

Quoted 5 lines

Face it, Nigel, this is a losing battle. You can try to come up with ever-more complex schemes to try and force FUSE into the freezer's framework, but it just won't fit. Or if it does, the next filesystem to come along will require an even more baroque type of special-case handling.

It does seem to be a losing battle, but I'm wondering whether that's really because it's an intractable problem, or because people have given up on it before its time. We are talking about a computer system, so things should be predictable.

Quoted 7 lines

The general problem is that task A may be in an unfreezable state, waiting for task B to do something, while task B is already frozen. Since there's no reasonable way to determine that A really is waiting for B, you're just stuck. (To make matters worse, A may not even realize which task it is waiting for; it may know only that it's waiting for somebody to do something!) A and B could be user tasks, kernel threads, or one of each.

Quoted 7 lines

I guess I want to persist because all of these issues aren't utterly unsolvable. It's just that we don't have the infrastructure yet to figure out the solutions to these issues trivially. Take, for example, the locking issue. If we could call some function to say "What process holds this lock?", then task A could know that it's waiting on task B and put that information somewhere. We could then use the information to freeze task B before task A.

this sounds like the standard priority inversion problem taken to extremes. Ingo has been working this issue, but IIRC the problem is that tracking what owns the lock so that you can get that thing to run ends up being enough overhead that it's not acceptable in the general case.

David Lang

Quoted 10 lines
Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

That's what I'm questioning. Is there a more reliable way and we've just given up too quickly?

Regards,

Nigel

#315 lore raw
In reply to Nigel Cunningham
Quoted 5 lines
Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

That's what I'm questioning. Is there a more reliable way and we've just given up too quickly?

There obviously _are_ more reliable ways. A trivial one seems to be to just not require user tasks to finish syscalls.

Yeah, stopping user processes outside the kernel is convenient, but there's no fundamental reason why it is the only place where those tasks can be stopped.

And there are very fundamental reasons to _not_ require this. Not just in the fuse case, but in any case where a syscall requires another user task to run before it can be finished (e.g. NFS over OpenVPN).

Miklos

#316 lore raw
Quoted 6 lines · Miklos Szeredi
Quoted 5 lines
Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

That's what I'm questioning. Is there a more reliable way and we've just given up too quickly?

Quoted 6 lines

There obviously _are_ more reliable ways. A trivial one seems to be to just not require user tasks to finish syscalls.

Yeah, stopping user processes outside the kernel is convenient, but there's no fundamental reason why it is the only place where those tasks can be stopped.

The reason is that we want them to "park" in safe places, ie. where there are no locks held etc. Thus, these safe places need to be chosen somehow and since they are not marked throughout the code, we choose the obvious one. :-)

Quoted 4 lines

And there are very fundamental reasons to _not_ require this. Not just in the fuse case, but in any case where a syscall requires another user task to run before it can be finished (e.g. NFS over OpenVPN).

Yeah. Mark the safe places for us and we'll use them.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#317 lore raw
Quoted 10 lines · Miklos Szeredi
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

That's what I'm questioning. Is there a more reliable way and we've just given up too quickly?

There obviously _are_ more reliable ways. A trivial one seems to be to just not require user tasks to finish syscalls.

Quoted 8 lines
Quoted 3 lines

Yeah, stopping user processes outside the kernel is convenient, but there's no fundamental reason why it is the only place where those tasks can be stopped.

The reason is that we want them to "park" in safe places, ie. where there are no locks held etc. Thus, these safe places need to be chosen somehow and since they are not marked throughout the code, we choose the obvious one. :-)

Why shouldn't locks be held?

No locks which are required for suspend must be held, sure. But otherwise holding locks doesn't matter at all.

And I'm not saying that is trivial to do, but it might not be too hard either.

Rafael, can you please tell, what happened to that patch, that did not wait for tasks in uninterruptible sleep to be frozen?

That seemed like a magnificent approach compared to anything that has been proposed since.

Miklos

#318 lore raw
In reply to Rafael J. Wysocki
Quoted 10 lines · Miklos Szeredi
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

That's what I'm questioning. Is there a more reliable way and we've just given up too quickly?

There obviously _are_ more reliable ways. A trivial one seems to be to just not require user tasks to finish syscalls.

Quoted 8 lines
Quoted 3 lines

Yeah, stopping user processes outside the kernel is convenient, but there's no fundamental reason why it is the only place where those tasks can be stopped.

The reason is that we want them to "park" in safe places, ie. where there are no locks held etc. Thus, these safe places need to be chosen somehow and since they are not marked throughout the code, we choose the obvious one. :-)

Why shouldn't locks be held?

No locks which are required for suspend must be held, sure. But otherwise holding locks doesn't matter at all.

And I'm not saying that is trivial to do, but it might not be too hard either.

Rafael, can you please tell, what happened to that patch, that did not wait for tasks in uninterruptible sleep to be frozen?

That seemed like a magnificent approach compared to anything that has been proposed since.

Miklos

#319 lore raw
Quoted 24 lines · Miklos Szeredi
Quoted 10 lines · Miklos Szeredi
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

That's what I'm questioning. Is there a more reliable way and we've just given up too quickly?

There obviously _are_ more reliable ways. A trivial one seems to be to just not require user tasks to finish syscalls.

Quoted 8 lines
Quoted 3 lines

Yeah, stopping user processes outside the kernel is convenient, but there's no fundamental reason why it is the only place where those tasks can be stopped.

The reason is that we want them to "park" in safe places, ie. where there are no locks held etc. Thus, these safe places need to be chosen somehow and since they are not marked throughout the code, we choose the obvious one. :-)

Why shouldn't locks be held?

No locks which are required for suspend must be held, sure. But otherwise holding locks doesn't matter at all.

Quoted 8 lines

And I'm not saying that is trivial to do, but it might not be too hard either.

Rafael, can you please tell, what happened to that patch, that did not wait for tasks in uninterruptible sleep to be frozen?

That seemed like a magnificent approach compared to anything that has been proposed since.

Well, the freezer have failed to freeze tasks for a couple of times in my test setup and I've had a couple of hangs.

I have an idea how to improve it, but that still requires some pending freezer patches to go first.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#320 lore raw
In reply to Miklos Szeredi
Quoted 24 lines · Miklos Szeredi
Quoted 10 lines · Miklos Szeredi
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

The only thing to do is what Rafael has been working on: unfreeze things, hope the tasks sort themselves out, and try again.

That's what I'm questioning. Is there a more reliable way and we've just given up too quickly?

There obviously _are_ more reliable ways. A trivial one seems to be to just not require user tasks to finish syscalls.

Quoted 8 lines
Quoted 3 lines

Yeah, stopping user processes outside the kernel is convenient, but there's no fundamental reason why it is the only place where those tasks can be stopped.

The reason is that we want them to "park" in safe places, ie. where there are no locks held etc. Thus, these safe places need to be chosen somehow and since they are not marked throughout the code, we choose the obvious one. :-)

Why shouldn't locks be held?

No locks which are required for suspend must be held, sure. But otherwise holding locks doesn't matter at all.

Quoted 8 lines

And I'm not saying that is trivial to do, but it might not be too hard either.

Rafael, can you please tell, what happened to that patch, that did not wait for tasks in uninterruptible sleep to be frozen?

That seemed like a magnificent approach compared to anything that has been proposed since.

Well, the freezer have failed to freeze tasks for a couple of times in my test setup and I've had a couple of hangs.

I have an idea how to improve it, but that still requires some pending freezer patches to go first.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#321 lore raw
In reply to Miklos Szeredi

Am Montag 23 Juli 2007 schrieb Miklos Szeredi:

Quoted 9 lines
Quoted 4 lines

The reason is that we want them to "park" in safe places, ie. where there are no locks held etc.  Thus, these safe places need to be chosen somehow and since they are not marked throughout the code, we choose the obvious one. :-)

Why shouldn't locks be held?

No locks which are required for suspend must be held, sure.  But otherwise holding locks doesn't matter at all.

If you can provide a way to tell them apart, this would work.

Regards
Oliver

#322 lore raw
Quoted 11 lines
Quoted 9 lines
Quoted 4 lines

The reason is that we want them to "park" in safe places, ie. where there are no locks held etc.  Thus, these safe places need to be chosen somehow and since they are not marked throughout the code, we choose the obvious one. :-)

Why shouldn't locks be held?

No locks which are required for suspend must be held, sure.  But otherwise holding locks doesn't matter at all.

If you can provide a way to tell them apart, this would work.

Without some marking we can't tell obviously.

Are there many such locks? We can easily check by adding some debugging code to the lock primitives, to make them yell if they are used during suspend.

Miklos

#323 lore raw
Quoted 10 lines · Miklos Szeredi
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines

The reason is that we want them to "park" in safe places, ie. where there are no locks held etc.  Thus, these safe places need to be chosen somehow and since they are not marked throughout the code, we choose the obvious one. :-)

Why shouldn't locks be held?

No locks which are required for suspend must be held, sure.  But otherwise holding locks doesn't matter at all.

Quoted 7 lines
Quoted 1 line

If you can provide a way to tell them apart, this would work.

Without some marking we can't tell obviously.

Are there many such locks? We can easily check by adding some debugging code to the lock primitives, to make them yell if they are used during suspend.

This way we can only obtain information from systems that use hibernation quite often.

Alan has recently proposed to introduce "suspend locks" to be acquired during a suspend/hibernation and such that we can leave uninterruptible tasks that don't hold any of them.

Unfortunately, I have no link to his original message at hand.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#324 lore raw
Quoted 3 lines

Alan has recently proposed to introduce "suspend locks" to be acquired during a suspend/hibernation and such that we can leave uninterruptible tasks that don't hold any of them.

Sounds sane. A global rwsem could be acquired for read by drivers, and for write by suspend/hibernate. Just need to add it to all drivers that have PM, but that shouldn't need a heroic effort.

Miklos

#325 lore raw
In reply to Miklos Szeredi
Quoted 10 lines · Miklos Szeredi
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines

The reason is that we want them to "park" in safe places, ie. where there are no locks held etc.  Thus, these safe places need to be chosen somehow and since they are not marked throughout the code, we choose the obvious one. :-)

Why shouldn't locks be held?

No locks which are required for suspend must be held, sure.  But otherwise holding locks doesn't matter at all.

Quoted 7 lines
Quoted 1 line

If you can provide a way to tell them apart, this would work.

Without some marking we can't tell obviously.

Are there many such locks? We can easily check by adding some debugging code to the lock primitives, to make them yell if they are used during suspend.

This way we can only obtain information from systems that use hibernation quite often.

Alan has recently proposed to introduce "suspend locks" to be acquired during a suspend/hibernation and such that we can leave uninterruptible tasks that don't hold any of them.

Unfortunately, I have no link to his original message at hand.

Greetings,
Rafael

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

Am Montag 23 Juli 2007 schrieb Miklos Szeredi:

Quoted 5 lines
Quoted 4 lines

The reason is that we want them to "park" in safe places, ie. where there are no locks held etc.  Thus, these safe places need to be chosen somehow and since they are not marked throughout the code, we choose the obvious one. :-)

Quoted 6 lines
Quoted 4 lines

Why shouldn't locks be held?

No locks which are required for suspend must be held, sure.  But otherwise holding locks doesn't matter at all.

If you can provide a way to tell them apart, this would work.

can you just tell the driver to try and suspend and if it reports back that it fails back out of the suspend? or will the driver deadlock instead of reporting a failure if a lock is held.

David Lang

#327 lore raw
In reply to Oliver Neukum
Quoted 6 lines · Oliver Neukum

Am Montag 23 Juli 2007 schrieb Miklos Szeredi:

Quoted 5 lines
Quoted 4 lines

The reason is that we want them to "park" in safe places, ie. where there are no locks held etc.  Thus, these safe places need to be chosen somehow and since they are not marked throughout the code, we choose the obvious one. :-)

Quoted 6 lines
Quoted 4 lines

Why shouldn't locks be held?

No locks which are required for suspend must be held, sure.  But otherwise holding locks doesn't matter at all.

If you can provide a way to tell them apart, this would work.

can you just tell the driver to try and suspend and if it reports back that it fails back out of the suspend? or will the driver deadlock instead of reporting a failure if a lock is held.

David Lang

#328 lore raw
In reply to Miklos Szeredi

Am Montag 23 Juli 2007 schrieb Miklos Szeredi:

Quoted 9 lines
Quoted 4 lines

The reason is that we want them to "park" in safe places, ie. where there are no locks held etc.  Thus, these safe places need to be chosen somehow and since they are not marked throughout the code, we choose the obvious one. :-)

Why shouldn't locks be held?

No locks which are required for suspend must be held, sure.  But otherwise holding locks doesn't matter at all.

If you can provide a way to tell them apart, this would work.

Regards
Oliver

#329 lore raw
In reply to Nigel Cunningham

Hi!

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

The problem with FUSE is related to the fact that the freezer can't freeze uninterruptible tasks and we said that perhaps we might avoid it if FUSE was made freezing-aware. Still, no one has gone in this direction and I don't know of any plans to do that.

I thought we have fully explored this direction. Lots of emails, and an IRC session with Pavel. Conclusion:

Quoted 8 lines

What am I missing in the following suggested solution?

1) In the freezer code, we implement a new TIF_LATEFREEZE process flag, which, when set, causes a userspace process to be frozen with kernel threads instead of with userspace ones. When freezing, we freezing !TIF_LATEFREEZE, sync and then freeze TIF_LATEFREEZE and freezable kernel threads.

2) In the fuse code, the PID of the process that will do the work gets passed

The list of neccessary PIDs is not known to the kernel. FUSE servers may depend on another parts of userland.

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

Hi!

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

The problem with FUSE is related to the fact that the freezer can't freeze uninterruptible tasks and we said that perhaps we might avoid it if FUSE was made freezing-aware. Still, no one has gone in this direction and I don't know of any plans to do that.

I thought we have fully explored this direction. Lots of emails, and an IRC session with Pavel. Conclusion:

Quoted 8 lines

What am I missing in the following suggested solution?

1) In the freezer code, we implement a new TIF_LATEFREEZE process flag, which, when set, causes a userspace process to be frozen with kernel threads instead of with userspace ones. When freezing, we freezing !TIF_LATEFREEZE, sync and then freeze TIF_LATEFREEZE and freezable kernel threads.

2) In the fuse code, the PID of the process that will do the work gets passed

The list of neccessary PIDs is not known to the kernel. FUSE servers may depend on another parts of userland.

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

If you are wondering why you got this for the third time:

I didn't get the list right the first time, so when I didn't see it on the archive I made some small changes and sent it again. Then I retireved my incoming mail and found it had gone out, just incorrectly.

I hope this one makes it to the list. I'll reply to the comments shortly.

Hi. I've found this thread from the kjump thread on the kexec mailing list. I'll respond to that one later, but I wanted to respond to several messages in this thread. [Actually, there is a brief outline of a response near the bottom of this note]. I downloaded the archive to get message-ids and references, hopefully I don't break the threading badly.

First, my background is hardware and low level software. I wrote the initial ppc64 support for kexec. I try not to learn too much about x86 details, but have read this thread and the tutorial article mentioned in it. I've studied the suspend code at various times in the past but not in the last year. Several years I mused that kexec could be used restore the suspend image, but I was told that would not be swsupend.

Next: lets define what we are trying to solve with the kexec approach.

We can solve the case of getting the drivers to quiesce the hardware with requests from userspace suspended in queues. This is what the powermac suspend has been doing for years, and I think its agreed that it will be something similar if and when we remove the freezer. In the powermac code there are two notifications to drivers; in the first stage they can allocate memory and interrupts are enabled, in the second its copy enough device state to memory to restart the device.

The problem with all the current hybernate methods is how do we select what needs to be re-enabled to write the image to stable storage (be it disk, network, or other medium).

The kjump kexec proposal says after we have the io quiesced, we can jump to a totally new kernel, let it initialize the io it needs, and write the image. This has the advantage that there is no confusion as far as which requests should be service or not serviced by the driver and subsystem stacks. It also reuses all the drivers, which means we don't get untested code paths. It also has the advantage that we can use any complicated user stack to access a file system and run any desired access methods (eg encryption, raid, etc).

The currently identified problems under discussion include:
(1) how to interact with acpi to enter into S4.
(2) how to identify which memory needs to be saved
(3) how to communicate where to save the memory
(4) what state should devices be in when switching kernels
(5) the complicated setup required with the current patch
(6) what code restores the image

I'll now start with quotes from several articles in this thread and my responses.

Message-ID: <[email protected]>

Quoted 6 lines · Rafael J. Wysocki

(1) Upon entering the sleep state, which IMO can be done _after_ the image has been saved:
* figure out which devices can wake up
* put devices into low power states (wake-up devices are placed in
the Dx
states compatible with the wake capability, the others are powered

Quoted 8 lines

off)
* execute the _PTS global control method
* switch off the nonlocal CPUs (eg. nonboot CPUs on x86)
* execute the _GTS global control method
* set the GPE enable registers corresponding to the wake-up devices)
* make the platform enter S4 (there's a well defined procedure for
that)
I think that this should be done by the image-saving kernel.

Message-ID: <[email protected]>
On Tue Jul 17 13:35:52 2007, Jeremy Maitin-Shepard
expressed his agreement with this block but also confusion on the other blocks.

I strongly disagree.

(1) as has been pointed out, this requires the new kernel to understand all io devices in the first kernel.
(2) it requires both kernels to talk to ACPI. This is doomed to failure. How can the second kernel initialize ACPI? The platform thinks it has already been initialized. Do we plan to always undo all acpi initialization?

Quoted 7 lines

(2) Upon start-up (by which I mean what happens after the user has pressed the power button or something like that):
* check if the image is present (and valid) _without_ enabling ACPI
(we don't
do that now, but I see no reason for not doing it in the new
framework)
* if the image is present (and valid), load it

Quoted 8 lines

* turn on ACPI (unless already turned on by the BIOS, that is)
* execute the _BFS global control method
* execute the _WAK global control method
* continue
Here, the first two things should be done by the image-loading
kernel, but
the remaining operations have to be carried out by the restored
kernel.

Here I agree. The kernel to put the machine to execute the sleep is the one to execute the wakeup.

Here is my proposal. Instead of trying to both write the image and suspend, this all becomes much simpler if we limit the scope the work of the second kernel. Its purpose is to write the image. After that its done. The platform can be powered off if we are going to S5. However, to support suspend to ram and suspend to disk, we return to the first kernel.

This means that the first kernel will need to know why it got resumed. Was the system powered off, and this is the resume from the user wakeup? Or was it restarted because the image has been saved, and its now time to actually suspend until woken up? If you look at it, this is the same interface we have with the magic arch_suspend hook -- did we just suspend and its time to write the image, or did we just resume and its time to wake everything up.

I think this can be implemented easily by giving the image saving kernel two resume points: one for the image has been written, and one for we rebooted and have restored the image. I'm not familiar with ACPI. Perhaps we need a third to differentiate we read the image from S4 instead of from S5, but that information must be available to the OS because it needs that to know if it should resume from hibernate.

By making the split at image save and restore we have several advantages:

(1) the kernel always initializes with devices in the init or quiesced but active state.

(2) the kernel always resumes with devices in the init or quiesced but active state.

(3) the kjump save and restore kernel does not need to know how to suspend all devices in the platform.

(4) we have a merged path for suspend to disk, suspend to ram, and suspend to both.

(5) because of (4), we can implement sleep policys where we save the image to disk but try to stay in ram based on expected remaining battery life.

(6) we confine all platform (acpi) interaction to the main kernel

(7) we limit the knowledge needed in the second kernel. It needs to know how to do its job and then put the hardware back how it found it. Nothing more.

For the suspend to both and then woke up case, we simply need to invalidate the image before resuming normal kernel operation (so that a later power off and then boot doesn't resume from this stale point).

People have worried about how to boot and restore the kernel, and what to do if reading the image fails. They worry about needing memory hotplug or delayed acpi parsing. They are forgetting one thing. This kernel has support for kexec.

The restore or new boot is easily solved by having the bootloader from the bios always boot the restore kernel. It will boot with the same limited useable memory and no acpi support that it had to save to disk, it just runs a different initramfs. If the restore kernel userspace detects that there is no restore image, it simply loads the normal main kernel and initrd / initramfs and calls the normal kexec. The cost is the time to init the restore kernel, read the kernel with full drivers (vs reading it from the bootloader). If you want a boot menu, kboot (on sourceforge) has already been written.

Quoted 8 lines · Rafael J. Wysocki
Quoted 7 lines · On Tuesday, 17 July 2007 22:27, [email protected] wrote:
Quoted 5 lines · Alan Stern

But what about the freezer? The original reason for using kexec was to avoid the need for the freezer. With no freezer, while the original kernel is busy powering down its devices, user tasks will be free to carry out I/O -- which will make the memory snapshot inconsistent with the on-disk data structures.

Quoted 4 lines
Quoted 4 lines

no, user tasks just don't get scheduled during shutdown.

the big problem with the freezer isn't stopping anything from happening, it's _selectivly_ stopping things.

Agreed. Or rather, selectively not stopping and resuming things.

Quoted 6 lines

It's selectively stopping kernel threads, which is just about right. If you that _this_ is a main problem with the freezer, then think again.

Quoted 2 lines

with kexec you don't need to let any portion of the origional kernel or userspace operate so you don't have a problem.

Quoted 8 lines

In fact, the main problem with the freezer is that it is a coarse-grained solution. Therefore, what I believe we should do is to evolve in the directoin of more fine-grained solutions and gradually phase out the freezer.

The kexec-based approach is an attempt to replace one coarse-grained solution (the freezer) with even more coarse-grained solution (stopping the entire kernel with everything), which IMO doesn't address the main problem.

I think this addresses the problem. We do the same stop that suspend does, and don't try to figure out what fine pieces are needed. Instead we delclare no pieces are re-enabled. It's a bit harder than powermac because we have to fully quiesce devices; we can't cheat by leaving interrupts off. But once the drivers save the state of their devices and stop their queues, it should be easy to audit the paths to powerdown devices and call the platform suspend and ram wakeup paths.

Going back to the requirements document that started this thread:

Message-ID: <[email protected]>

Quoted 1 line · Rafael J. Wysocki

(1) Filesystems mounted before the hibernation are untouchable

This is because some file systems do a fsck or other activity even when mounted read only. For the kexec case, however, this should be "media open (including file systems mounted) by the hibernated system must not be written". As has been mentioned in the past, we should be able to use something like dm snapshot to allow fsck and the file system to see the cleaned copy while not actually writing the media.

In fact, I claim we can even overwrite a file using its block numbers.
The suspended kernel won't know about it and its buffers will be
stale. But if the meta data doesn't change, it just means that you can't read the suspend image file.

The kjump kernel must not retain any buffers if we reuse it.

Quoted 1 line

(2) Swap space in use before the hibernation must be handled with care

Yes. Actually, even though they have been used by the write-in-the kernel users, they will be among the most difficult devices to use for snapshots by a userspace second kernel. We have to communicate a list of blocks.

Quoted 1 line

(3) There are memory regions that must not be saved or restored

because they may not exist. This means that we must identify the memory to be saved and restored in a format to be passed between the kernel.

I'm worried about regions that are marked nosave because they hold data that someone thought should be preserved across restore. If its just the variables to read the image then we are ok.

Quoted 1 line

(4) The user should be able to limit the size of a hibernation image

This means the suspending kernel must arrange to reduce its active memory. The list of memory would be provided to the new kernel.

Quoted 1 line

(5) Hibernation should be transparent from the applications' point of view

People have pointed out they may want userspace to be aware of the suspend. I believed this can be done with /proc/apm emulation today or by other means; it seems that should be hooked up to dbus in some fashion.

Quoted 1 line

(6) State of devices from before hibernation should be restored, if possible

related to suspend should be transparent ... yes. This is a driver problem.

Quoted 3 lines

(7) On ACPI systems special platform-related actions have to be carried out at the right points, so that the platform works correctly after the
restore

I believe I have explained my suggestion.

Quoted 1 line

(8) Hibernation and restore should not be too slow

We control the added code. We are using full runtime drivers and will run at hardware speeds.

Quoted 1 line

(9) Hibernation framework should not be too difficult to set up

Ok the current patch is presently too difficult. But I think it will be much simpler with a few small changes.

As noted in another thread

Message-ID: <[email protected]>
Subject: [linux-pm] Re: hibernation/snapshot design

Quoted 4 lines · Jeremy Maitin-Shepard
Quoted 1 line

Both would work. One would eat 8-64MB of your RAM, permanently;

As I have stated in other messages, the kdump approach would not waste any RAM permanently.

...

Quoted 6 lines

Immediately before jumping to the new kernel, the first X bytes (where X is the amount of memory the new kernel will get, typically 16MB or 64MB) of physical memory are backed up into the arbitrary discontiguous pages that are made available. This will not take very long, because copying even 64MB of memory is extremely fast. Then the new kernel is free to use the first X bytes of contiguous physical memory. Problem solved.

Ok, now let's look at my list again:

Quoted 1 line

(1) how to interact with acpi to enter into S4.

This was discussed.

Quoted 1 line

(2) how to identify which memory needs to be saved

We need to generate a list. We need it to fit in a compuatable size so that we can free extra pages and allocate the list before suspending IO in the first kernel.

One possibility is to use something like the kexec copy list. If we are imaging a small fraction of ram this is appropriate, but if we are doing dense saves we need something extent based. We may enhance the list with page counts.

Quoted 1 line

(3) how to communicate where to save the memory

This is an intresting topic. The suspended kernel has most IO and disk space. It also knows how much space is to be occupied by the kernel. So communicating a block map to the second kernel would be the obvious choice. But the second kernel must be able to find the image to restore it, and it must have drivers for the media. Also, this is not feasible for storing to nfs.

I think we will end up with several methods.

One would be supply a list of blocks, and write to those blocks the list of blocks followed by the image contents. The restore kernel then only needs to know the starting block. It would read the anchor, and can build upon that until the image is read into memory. We could implement a file system, or do this in userspace.

I don't know how this compares to the current restore path. I wasn't able to identify the code that creates the on disk structure in my 10 minute perusal of kernel/power/.

A second method will be to supply a device and file that will be mounted by the save kernel, then unmounted and restored. This would require a partition that is not mounted or open by the suspended kernel (or use nfs or a similar protocol that is designed for multiple client concurrent access).

A third method would be to allocate a file with the first kernel, and make sure the blocks are flushed to disk. The save and restore kernels map the file system using a snapshot device. Writing would map the blocks and use the block offset to write to the real device using the method from the first option; reading could be done directly from the snapshot device.

The first and third option are dead on log based file systems (where the data is stored in the log).

Quoted 1 line

(4) what state should devices be in when switching kernels

My proposal is either initialized and untouched or quiesced. Not low power unless that is normal for the platform.

Quoted 1 line

(5) the complicated setup required with the current patch

I think a few simple changes to kjump will make this much simpler. See below.

Quoted 1 line

(6) what code restores the image

The save kernel, loaded at boot. People have suggested booting the first kernel, and using current restore code. However, I think that ignores that (1) we saved from a different kernel, so the backed up region will be restored to its backed up location in random pages, (2) the code was written to restore the same kernel, so the text and data will be replaced by identical text. Its much simpler conceptually to use the same kernel to save and restore the image. If we decide not to restore we can load and kexec the main kernel.

Simplifying kjump: the proposal for v3.

The current code is trying to use crash dump area as a safe, reserved area to run the second kernel. However, that means that the kernel has to be linked specially to run in the reserved area. I think we need to finish separating kexec_jump from the other code paths.

(1) add a new command line argument that specifies the kexec_jump target area (or just size?)

(2) add a kjump flag to the flags parameter, used by kexec_load. When loading a jump kernel, it is loaded like a normal kernel, however, additional control pages are allocated to (a) save this kenrel's use of the kexec_jump target area (b) save the backed up region that is used by all kernels like crash dump, and (c) space for invoking relocate_new_kernel that will get its args from the execution entry point and will restore the kernel then call resume and suspend.

(3) replace jump_huf_pfn with two command line addresses that specify the (a) return point for after resume, and (b) the return point for after image save. Actually these can be done in userspace; the second restore kernel can just specify the null copy list and the entry points supplied by the suspended kernel. To do resume we also need (c) where to store resume address for the save kernel.

The seperation should be whoever builds a scatter copy list builds the inverse list. This is why I propose simple jump entry points. I expect just a few instructions to establish arguments for the call to the exstinging relocate_new_kernel code.

As a first stage of suspend and resume, we can save to dedicated partitions all memory (as supplied to crash_dump) that is not marked nosave and not part of the save kernel's image. The fancy block lists and memory lists can be added later.

Mmaking these changes will allow us to use a normal kernel invoked with acpi=off apm=off mem=xxk as the save and restore kernel.

If we want to keep the second kernel booted, then we need to add a save area for the booted jump target. Note that the save and restore lists to relocate_new_kernel can be computed once and saved. Longer term we could implement sys_kexec_load(UNLOAD) that would retrieve the saved list back to application space to save to disk in a file. This means you could save the booted save kernel, it just couldn't have any shared storage open.

I'll try to expand on this in the jump v2 thread, but it may be days until I do.

milton

#332 lore raw
Quoted 10 lines · Milton Miller

Simplifying kjump: the proposal for v3.

The current code is trying to use crash dump area as a safe, reserved
area to run the second kernel. However, that means that the kernel
has to be linked specially to run in the reserved area. I think we
need to finish separating kexec_jump from the other code paths.

(1) add a new command line argument that specifies the kexec_jump target area (or just size?)

Quoted 7 lines

(2) add a kjump flag to the flags parameter, used by kexec_load. When
loading a jump kernel, it is loaded like a normal kernel, however, additional control pages are allocated to (a) save this kenrel's use of the kexec_jump target area (b) save the backed up region that is used by all kernels like crash dump, and (c) space for invoking relocate_new_kernel that will get its args from the execution entry point and will restore the kernel then call resume and suspend.

Backuping target memory before kexec and restoring it after kexec is planed feature for kexec jump. But I will work on image writing/reading first.

Quoted 6 lines

(3) replace jump_huf_pfn with two command line addresses that specify the (a) return point for after resume, and (b) the return point for
after image save. Actually these can be done in userspace; the second
restore kernel can just specify the null copy list and the entry points supplied by the suspended kernel. To do resume we also need (c) where to store resume address for the save kernel.

There is many free spaces in jump_buf_pfn page now. I think passing the needed information through jump_buf_pfn is more convenient than through kernel command line. That is, the jump_buf_pfn can be seen as a meta interface, which is passed to kexeced kernel though command line, while other information can be passed though jmp_buf_pfn.

Quoted 4 lines

The seperation should be whoever builds a scatter copy list builds the inverse list. This is why I propose simple jump entry points. I expect just a few instructions to establish arguments for the call to the exstinging relocate_new_kernel code.

If the "scatter copy" is replaced by "scatter swap", we need not the inverse list, and the state of kexeced kernel can be backuped too. There are "scatter copy" support in normal kexec implementation in "relocate_kernel".

Quoted 8 lines

As a first stage of suspend and resume, we can save to dedicated partitions all memory (as supplied to crash_dump) that is not marked
nosave and not part of the save kernel's image. The fancy block lists
and memory lists can be added later.

Mmaking these changes will allow us to use a normal kernel invoked with
acpi=off apm=off mem=xxk as the save and restore kernel.

Yes, I am working on this.

Quoted 7 lines

If we want to keep the second kernel booted, then we need to add a save
area for the booted jump target. Note that the save and restore lists
to relocate_new_kernel can be computed once and saved. Longer term we
could implement sys_kexec_load(UNLOAD) that would retrieve the saved
list back to application space to save to disk in a file. This means
you could save the booted save kernel, it just couldn't have any shared storage open.

Yes, this is also in plan. But with lower priority and will only be added if necessary.

Best Regards,
Huang Ying

#333 lore raw
Quoted 20 lines · Ying
Quoted 10 lines · Milton Miller

Simplifying kjump: the proposal for v3.

The current code is trying to use crash dump area as a safe, reserved
area to run the second kernel. However, that means that the kernel
has to be linked specially to run in the reserved area. I think we
need to finish separating kexec_jump from the other code paths.

(1) add a new command line argument that specifies the kexec_jump target area (or just size?)

Quoted 7 lines

(2) add a kjump flag to the flags parameter, used by kexec_load. When
loading a jump kernel, it is loaded like a normal kernel, however, additional control pages are allocated to (a) save this kenrel's use of the kexec_jump target area (b) save the backed up region that is used by all kernels like crash dump, and (c) space for invoking relocate_new_kernel that will get its args from the execution entry point and will restore the kernel then call resume and suspend.

Quoted 3 lines

Backuping target memory before kexec and restoring it after kexec is planed feature for kexec jump. But I will work on image writing/reading first.

if we can get a list of what memory is safe to backup/restore then the reading/writing of the image should be able to be done in userspace.

Quoted 20 lines
Quoted 6 lines

(3) replace jump_huf_pfn with two command line addresses that specify the (a) return point for after resume, and (b) the return point for
after image save. Actually these can be done in userspace; the second
restore kernel can just specify the null copy list and the entry points supplied by the suspended kernel. To do resume we also need (c) where to store resume address for the save kernel.

There is many free spaces in jump_buf_pfn page now. I think passing the needed information through jump_buf_pfn is more convenient than through kernel command line. That is, the jump_buf_pfn can be seen as a meta interface, which is passed to kexeced kernel though command line, while other information can be passed though jmp_buf_pfn.

Quoted 4 lines

The seperation should be whoever builds a scatter copy list builds the inverse list. This is why I propose simple jump entry points. I expect just a few instructions to establish arguments for the call to the exstinging relocate_new_kernel code.

Quoted 4 lines

If the "scatter copy" is replaced by "scatter swap", we need not the inverse list, and the state of kexeced kernel can be backuped too. There are "scatter copy" support in normal kexec implementation in "relocate_kernel".

what do you mean by "scatter swap"?

David Lang

#334 lore raw
Quoted 6 lines · On Fri, 2007-07-20 at 08:48 -0700, [email protected] wrote:
Quoted 3 lines

Backuping target memory before kexec and restoring it after kexec is planed feature for kexec jump. But I will work on image writing/reading first.

if we can get a list of what memory is safe to backup/restore then the reading/writing of the image should be able to be done in userspace.

The backup/restore here has nothing to do with the read/write of the image. It means instead of preserving memory for a new kernel like that of crash-dump, the memory for a new kernel is backupped before kexec and restored after kexec by the kexec kernel.

Quoted 6 lines
Quoted 4 lines

If the "scatter copy" is replaced by "scatter swap", we need not the inverse list, and the state of kexeced kernel can be backuped too. There are "scatter copy" support in normal kexec implementation in "relocate_kernel".

what do you mean by "scatter swap"

copy: dest=src
swap: tmp=dest; dest=src; src=tmp

If memory is swapped, no information is lost, both that of kexec kernel and kexeced kernel.

Best Regards,
Huang, Ying

#335 lore raw
In reply to [email protected]
Quoted 6 lines · On Fri, 2007-07-20 at 08:48 -0700, [email protected] wrote:
Quoted 3 lines

Backuping target memory before kexec and restoring it after kexec is planed feature for kexec jump. But I will work on image writing/reading first.

if we can get a list of what memory is safe to backup/restore then the reading/writing of the image should be able to be done in userspace.

The backup/restore here has nothing to do with the read/write of the image. It means instead of preserving memory for a new kernel like that of crash-dump, the memory for a new kernel is backupped before kexec and restored after kexec by the kexec kernel.

Quoted 6 lines
Quoted 4 lines

If the "scatter copy" is replaced by "scatter swap", we need not the inverse list, and the state of kexeced kernel can be backuped too. There are "scatter copy" support in normal kexec implementation in "relocate_kernel".

what do you mean by "scatter swap"

copy: dest=src
swap: tmp=dest; dest=src; src=tmp

If memory is swapped, no information is lost, both that of kexec kernel and kexeced kernel.

Best Regards,
Huang, Ying

#336 lore raw
Quoted 5 lines · Ying
Quoted 4 lines · On Fri, 2007-07-20 at 08:48 -0700, [email protected] wrote:
Quoted 3 lines

Backuping target memory before kexec and restoring it after kexec is planed feature for kexec jump. But I will work on image writing/reading first.

Quoted 7 lines
Quoted 2 lines

if we can get a list of what memory is safe to backup/restore then the reading/writing of the image should be able to be done in userspace.

The backup/restore here has nothing to do with the read/write of the image. It means instead of preserving memory for a new kernel like that of crash-dump, the memory for a new kernel is backupped before kexec and restored after kexec by the kexec kernel.

Ok, I see the miscommunication here. you are talking about freeing up memory for the second kernel instead of reserving it from boot time.

I'm talking about getting the second kernel a list of what memory pages it should write to the image

if we can get the info for the list I'm looking for we should be able to demonstrate the kexec based hibernate.

the change you are talking about in an enhancment that is useful after that point to save some memory.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

If the "scatter copy" is replaced by "scatter swap", we need not the inverse list, and the state of kexeced kernel can be backuped too. There are "scatter copy" support in normal kexec implementation in "relocate_kernel".

Quoted 7 lines
Quoted 1 line

what do you mean by "scatter swap"

copy: dest=src
swap: tmp=dest; dest=src; src=tmp

If memory is swapped, no information is lost, both that of kexec kernel and kexeced kernel.

I'm missing why you need to preserve this memory

if you are talking about memory that will be used by the second kernel when you kexec to it then you don't need to preserve it (since it will be overwritten by the second kernel). if you aren't talking about memory that will be used by the second kernel why do you need to move it?

David Lang

#337 lore raw
In reply to Huang, Ying
Quoted 5 lines · Ying
Quoted 4 lines · On Fri, 2007-07-20 at 08:48 -0700, [email protected] wrote:
Quoted 3 lines

Backuping target memory before kexec and restoring it after kexec is planed feature for kexec jump. But I will work on image writing/reading first.

Quoted 7 lines
Quoted 2 lines

if we can get a list of what memory is safe to backup/restore then the reading/writing of the image should be able to be done in userspace.

The backup/restore here has nothing to do with the read/write of the image. It means instead of preserving memory for a new kernel like that of crash-dump, the memory for a new kernel is backupped before kexec and restored after kexec by the kexec kernel.

Ok, I see the miscommunication here. you are talking about freeing up memory for the second kernel instead of reserving it from boot time.

I'm talking about getting the second kernel a list of what memory pages it should write to the image

if we can get the info for the list I'm looking for we should be able to demonstrate the kexec based hibernate.

the change you are talking about in an enhancment that is useful after that point to save some memory.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

If the "scatter copy" is replaced by "scatter swap", we need not the inverse list, and the state of kexeced kernel can be backuped too. There are "scatter copy" support in normal kexec implementation in "relocate_kernel".

Quoted 7 lines
Quoted 1 line

what do you mean by "scatter swap"

copy: dest=src
swap: tmp=dest; dest=src; src=tmp

If memory is swapped, no information is lost, both that of kexec kernel and kexeced kernel.

I'm missing why you need to preserve this memory

if you are talking about memory that will be used by the second kernel when you kexec to it then you don't need to preserve it (since it will be overwritten by the second kernel). if you aren't talking about memory that will be used by the second kernel why do you need to move it?

David Lang

#338 lore raw
In reply to Huang, Ying
Quoted 19 lines · Ying
Quoted 10 lines · Milton Miller

Simplifying kjump: the proposal for v3.

The current code is trying to use crash dump area as a safe, reserved
area to run the second kernel. However, that means that the kernel
has to be linked specially to run in the reserved area. I think we
need to finish separating kexec_jump from the other code paths.

(1) add a new command line argument that specifies the kexec_jump target area (or just size?)

Quoted 7 lines

(2) add a kjump flag to the flags parameter, used by kexec_load. When
loading a jump kernel, it is loaded like a normal kernel, however, additional control pages are allocated to (a) save this kenrel's use of the kexec_jump target area (b) save the backed up region that is used by all kernels like crash dump, and (c) space for invoking relocate_new_kernel that will get its args from the execution entry point and will restore the kernel then call resume and suspend.

Quoted 3 lines

Backuping target memory before kexec and restoring it after kexec is planed feature for kexec jump. But I will work on image writing/reading first.

Have you thought about using any existing code, when you're at it?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#339 lore raw
In reply to [email protected]
Quoted 55 lines · On Tuesday, 17 July 2007 22:27, [email protected] wrote:
Quoted 22 lines · Alan Stern
Quoted 8 lines · Rafael J. Wysocki

I'm afraid of one thing, though.

If we create a framework without ACPI (well, ACPI needs to be enabled in the kernel anyway for other reasons, like the ability to suspend to RAM) and then it turns out that we have to add some ACPI hooks to it, that might be difficult to do cleanly.

Thus, it seems reasonable to think of the ACPI handling in advance.

Absolutely. This needs to be done in such a way that it will work:

	On platforms without ACPI;

	On platforms with ACPI where we do a non-ACPI type of shutdown
	to whatever extent it is possible (or perhaps an ACPI-aware
	shutdown rather than change to S4);

	On platforms with ACPI where we do an ACPI-aware transition
	to S4.
Quoted 6 lines

Rafael, for those of us who aren't thoroughly familiar with all the ins and outs of the ACPI spec, could you please summarize a list of the ACPI calls needed in the second and third cases above? Indicate which ones need to be done from within the original kernel and which should be done from within a kexec'd hibernation kernel.

there was just a link on slashdot toa primer on the subject of power management

http://www.techarp.com/showarticle.aspx?artno=420

Quoted 7 lines

I'm still not entirely clear on how "suspend-to-both" ought to be handled. Presumably it will start off as a normal hibernation. But instead of shutting down, wouldn't the kexec'd kernel return to the original kernel? After all, the original kernel knows about all the devices and can put them into a low-power state, while the kexec'd kernel might not have sufficient information.

this is what I'm thinking, but the issue here is that the original kernel needs to go into suspend-to-ram mode instead of resuming operation. per the e-mail I got from Ying last night this should not be hard to implement.

Quoted 5 lines

But what about the freezer? The original reason for using kexec was to avoid the need for the freezer. With no freezer, while the original kernel is busy powering down its devices, user tasks will be free to carry out I/O -- which will make the memory snapshot inconsistent with the on-disk data structures.

Quoted 4 lines

no, user tasks just don't get scheduled during shutdown.

the big problem with the freezer isn't stopping anything from happening, it's _selectivly_ stopping things.

It's selectively stopping kernel threads, which is just about right. If you that _this_ is a main problem with the freezer, then think again.

Quoted 2 lines

with kexec you don't need to let any portion of the origional kernel or userspace operate so you don't have a problem.

In fact, the main problem with the freezer is that it is a coarse-grained solution. Therefore, what I believe we should do is to evolve in the directoin of more fine-grained solutions and gradually phase out the freezer.

The kexec-based approach is an attempt to replace one coarse-grained solution (the freezer) with even more coarse-grained solution (stopping the entire kernel with everything), which IMO doesn't address the main problem.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#340 lore raw
In reply to [email protected]
Quoted 7 lines · On Tue, 17 Jul 2007 [email protected] wrote:
Quoted 5 lines

But what about the freezer? The original reason for using kexec was to avoid the need for the freezer. With no freezer, while the original kernel is busy powering down its devices, user tasks will be free to carry out I/O -- which will make the memory snapshot inconsistent with the on-disk data structures.

no, user tasks just don't get scheduled during shutdown.

But a user task may be holding a lock which is needed for putting some device into low-power mode. It can't release that lock if it doesn't get scheduled.

Alan Stern

#341 lore raw
Quoted 8 lines · Alan Stern
Quoted 6 lines · On Tue, 17 Jul 2007 [email protected] wrote:
Quoted 5 lines

But what about the freezer? The original reason for using kexec was to avoid the need for the freezer. With no freezer, while the original kernel is busy powering down its devices, user tasks will be free to carry out I/O -- which will make the memory snapshot inconsistent with the on-disk data structures.

Quoted 5 lines
Quoted 1 line

no, user tasks just don't get scheduled during shutdown.

But a user task may be holding a lock which is needed for putting some device into low-power mode. It can't release that lock if it doesn't get scheduled.

then you can't suspend that box. if you schedule it, it could get another lock (or another process gets another lock)

if you can't power down or put hardware into low-power mode without the approval of userspace, you are in serious trouble.

David Lang

#342 lore raw
Quoted 16 lines · On Tue, 17 Jul 2007 [email protected] wrote:
Quoted 8 lines · Alan Stern
Quoted 6 lines · On Tue, 17 Jul 2007 [email protected] wrote:
Quoted 5 lines

But what about the freezer? The original reason for using kexec was to avoid the need for the freezer. With no freezer, while the original kernel is busy powering down its devices, user tasks will be free to carry out I/O -- which will make the memory snapshot inconsistent with the on-disk data structures.

Quoted 5 lines
Quoted 1 line

no, user tasks just don't get scheduled during shutdown.

But a user task may be holding a lock which is needed for putting some device into low-power mode. It can't release that lock if it doesn't get scheduled.

Quoted 5 lines

then you can't suspend that box. if you schedule it, it could get another lock (or another process gets another lock)

if you can't power down or put hardware into low-power mode without the approval of userspace, you are in serious trouble.

You don't seem to appreciate the issues involved here. Part of the justification for the freezer is that it doesn't need userspace approval and it freezes tasks at controlled points where they don't hold any locks.

Never mind. It seems clear that this approach will suffer the same drawback as the proposal for removing the freezer from the suspend-to-RAM pathway. Namely, device drivers will have to be changed to prevent user I/O requests from proceeding while devices are supposed to be quiescent or in a low-power state.

If a driver fails to handle this properly, its device could be reactivated in order to service a user request before the memory snapshot is made. This could easily ruin the snapshot.

Alan Stern

#343 lore raw
Quoted 29 lines · Alan Stern
Quoted 16 lines · On Tue, 17 Jul 2007 [email protected] wrote:
Quoted 8 lines · Alan Stern
Quoted 6 lines · On Tue, 17 Jul 2007 [email protected] wrote:
Quoted 5 lines

But what about the freezer? The original reason for using kexec was to avoid the need for the freezer. With no freezer, while the original kernel is busy powering down its devices, user tasks will be free to carry out I/O -- which will make the memory snapshot inconsistent with the on-disk data structures.

Quoted 5 lines
Quoted 1 line

no, user tasks just don't get scheduled during shutdown.

But a user task may be holding a lock which is needed for putting some device into low-power mode. It can't release that lock if it doesn't get scheduled.

Quoted 5 lines

then you can't suspend that box. if you schedule it, it could get another lock (or another process gets another lock)

if you can't power down or put hardware into low-power mode without the approval of userspace, you are in serious trouble.

You don't seem to appreciate the issues involved here. Part of the justification for the freezer is that it doesn't need userspace approval and it freezes tasks at controlled points where they don't hold any locks.

Quoted 5 lines

Never mind. It seems clear that this approach will suffer the same drawback as the proposal for removing the freezer from the suspend-to-RAM pathway. Namely, device drivers will have to be changed to prevent user I/O requests from proceeding while devices are supposed to be quiescent or in a low-power state.

I agree.

Quoted 3 lines

If a driver fails to handle this properly, its device could be reactivated in order to service a user request before the memory snapshot is made. This could easily ruin the snapshot.

That's why I've been saying for quite some time that we first need to take care of the drivers. :-)

IMO we've reached the point at which, whatever we want to do next, the drivers are in the way.

Greetings,
Rafael

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

Never mind. It seems clear that this approach will suffer the same drawback as the proposal for removing the freezer from the suspend-to-RAM pathway. Namely, device drivers will have to be changed to prevent user I/O requests from proceeding while devices are supposed to be quiescent or in a low-power state.

I agree.

Quoted 3 lines

If a driver fails to handle this properly, its device could be reactivated in order to service a user request before the memory snapshot is made. This could easily ruin the snapshot.

Quoted 5 lines

That's why I've been saying for quite some time that we first need to take care of the drivers. :-)

IMO we've reached the point at which, whatever we want to do next, the drivers are in the way.

Correct, but only if we want ACPI support. Granted, we need a separation of the hibernate/suspend PM functions, but in the absence of ACPI, all we need right now are dump/restore routines for the crashkernel.

Next, we should be looking into reducing the kexec'd kernel environment size, which currently, at 16MB, is way too big, and even at 1MB would be problematic for small systems.

So, ACPI should really be the least of our worries, and the reason why people are fixating on ACPI is probably because they have nothing else to fixate on. They probably haven't even tried the kexec patches to appreciate how easy the kexec approach is and how little interference APCI represents when suspending and resuming.

Thanks!

--
Al

#345 lore raw
In reply to Rafael J. Wysocki
Quoted 14 lines · Rafael J. Wysocki
Quoted 6 lines · Alan Stern

Never mind. It seems clear that this approach will suffer the same drawback as the proposal for removing the freezer from the suspend-to-RAM pathway. Namely, device drivers will have to be changed to prevent user I/O requests from proceeding while devices are supposed to be quiescent or in a low-power state.

I agree.

Quoted 3 lines

If a driver fails to handle this properly, its device could be reactivated in order to service a user request before the memory snapshot is made. This could easily ruin the snapshot.

Quoted 5 lines

That's why I've been saying for quite some time that we first need to take care of the drivers. :-)

IMO we've reached the point at which, whatever we want to do next, the drivers are in the way.

Correct, but only if we want ACPI support. Granted, we need a separation of the hibernate/suspend PM functions, but in the absence of ACPI, all we need right now are dump/restore routines for the crashkernel.

Next, we should be looking into reducing the kexec'd kernel environment size, which currently, at 16MB, is way too big, and even at 1MB would be problematic for small systems.

So, ACPI should really be the least of our worries, and the reason why people are fixating on ACPI is probably because they have nothing else to fixate on. They probably haven't even tried the kexec patches to appreciate how easy the kexec approach is and how little interference APCI represents when suspending and resuming.

Thanks!

--
Al

#346 lore raw
Quoted 15 lines · Al Boldi
Quoted 14 lines · Rafael J. Wysocki
Quoted 6 lines · Alan Stern

Never mind. It seems clear that this approach will suffer the same drawback as the proposal for removing the freezer from the suspend-to-RAM pathway. Namely, device drivers will have to be changed to prevent user I/O requests from proceeding while devices are supposed to be quiescent or in a low-power state.

I agree.

Quoted 3 lines

If a driver fails to handle this properly, its device could be reactivated in order to service a user request before the memory snapshot is made. This could easily ruin the snapshot.

Quoted 7 lines
Quoted 5 lines

That's why I've been saying for quite some time that we first need to take care of the drivers. :-)

IMO we've reached the point at which, whatever we want to do next, the drivers are in the way.

Correct, but only if we want ACPI support.

No, in general.

Quoted 3 lines

Granted, we need a separation of
the hibernate/suspend PM functions, but in the absence of ACPI, all we need right now are dump/restore routines for the crashkernel.

IMO you aren't right, but I guess there's no point in trying to convince you.

Quoted 7 lines

Next, we should be looking into reducing the kexec'd kernel environment size, which currently, at 16MB, is way too big, and even at 1MB would be problematic for small systems.

So, ACPI should really be the least of our worries, and the reason why people are fixating on ACPI is probably because they have nothing else to fixate on.

Yeah, right. Please read the $subject message again. And sorry, but IMO your previous replies to it haven't addressed any of the original points.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#347 lore raw
In reply to Al Boldi
Quoted 15 lines · Al Boldi
Quoted 14 lines · Rafael J. Wysocki
Quoted 6 lines · Alan Stern

Never mind. It seems clear that this approach will suffer the same drawback as the proposal for removing the freezer from the suspend-to-RAM pathway. Namely, device drivers will have to be changed to prevent user I/O requests from proceeding while devices are supposed to be quiescent or in a low-power state.

I agree.

Quoted 3 lines

If a driver fails to handle this properly, its device could be reactivated in order to service a user request before the memory snapshot is made. This could easily ruin the snapshot.

Quoted 7 lines
Quoted 5 lines

That's why I've been saying for quite some time that we first need to take care of the drivers. :-)

IMO we've reached the point at which, whatever we want to do next, the drivers are in the way.

Correct, but only if we want ACPI support.

No, in general.

Quoted 3 lines

Granted, we need a separation of
the hibernate/suspend PM functions, but in the absence of ACPI, all we need right now are dump/restore routines for the crashkernel.

IMO you aren't right, but I guess there's no point in trying to convince you.

Quoted 7 lines

Next, we should be looking into reducing the kexec'd kernel environment size, which currently, at 16MB, is way too big, and even at 1MB would be problematic for small systems.

So, ACPI should really be the least of our worries, and the reason why people are fixating on ACPI is probably because they have nothing else to fixate on.

Yeah, right. Please read the $subject message again. And sorry, but IMO your previous replies to it haven't addressed any of the original points.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#348 lore raw
In reply to Alan Stern
Quoted 29 lines · Alan Stern
Quoted 16 lines · On Tue, 17 Jul 2007 [email protected] wrote:
Quoted 8 lines · Alan Stern
Quoted 6 lines · On Tue, 17 Jul 2007 [email protected] wrote:
Quoted 5 lines

But what about the freezer? The original reason for using kexec was to avoid the need for the freezer. With no freezer, while the original kernel is busy powering down its devices, user tasks will be free to carry out I/O -- which will make the memory snapshot inconsistent with the on-disk data structures.

Quoted 5 lines
Quoted 1 line

no, user tasks just don't get scheduled during shutdown.

But a user task may be holding a lock which is needed for putting some device into low-power mode. It can't release that lock if it doesn't get scheduled.

Quoted 5 lines

then you can't suspend that box. if you schedule it, it could get another lock (or another process gets another lock)

if you can't power down or put hardware into low-power mode without the approval of userspace, you are in serious trouble.

You don't seem to appreciate the issues involved here. Part of the justification for the freezer is that it doesn't need userspace approval and it freezes tasks at controlled points where they don't hold any locks.

Quoted 5 lines

Never mind. It seems clear that this approach will suffer the same drawback as the proposal for removing the freezer from the suspend-to-RAM pathway. Namely, device drivers will have to be changed to prevent user I/O requests from proceeding while devices are supposed to be quiescent or in a low-power state.

I agree.

Quoted 3 lines

If a driver fails to handle this properly, its device could be reactivated in order to service a user request before the memory snapshot is made. This could easily ruin the snapshot.

That's why I've been saying for quite some time that we first need to take care of the drivers. :-)

IMO we've reached the point at which, whatever we want to do next, the drivers are in the way.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#349 lore raw
In reply to [email protected]
Quoted 7 lines · On Tue, 17 Jul 2007 [email protected] wrote:
Quoted 5 lines

But what about the freezer? The original reason for using kexec was to avoid the need for the freezer. With no freezer, while the original kernel is busy powering down its devices, user tasks will be free to carry out I/O -- which will make the memory snapshot inconsistent with the on-disk data structures.

no, user tasks just don't get scheduled during shutdown.

But a user task may be holding a lock which is needed for putting some device into low-power mode. It can't release that lock if it doesn't get scheduled.

Alan Stern

#350 lore raw
In reply to Alan Stern
Quoted 20 lines · Alan Stern
Quoted 14 lines · On Mon, 16 Jul 2007 [email protected] wrote:
Quoted 3 lines

I agree, it would be good to have a non-ACPI-specific hibernation mode, something which would look to ACPI like a normal shutdown. But I'm not so sure this is possible.

why would it not be possible?

I can't think of anything much more frustrating then thinking that I suspended a system and then discovering that becouse the battery went dead (a complete power loss) that the system wouldn't boot up properly. to me this would be a fairly common condition (when I'm mobile I use the machine until I am out of battery, then stop and it may be a long time (days) before I can charge the thing up again) this would not be a reliable suspend as far as I'm concerned.

Quoted 3 lines

for suspend-to-ram you have to worry about ACPI states and what you are doing with them, for suspend-to-disk you can ignore them and completely power the system off instead.

Quoted 6 lines

If the only problem with doing this would be lack of wakeup support then I'm all for it. There must be a lot of people who would like their computers to hibernate with power drain as close to 0 as possible and who don't care about remote wakeup. In fact they might even prefer not to have wakeup support, so the computer doesn't resume at unexpected times.

I'm afraid of one thing, though.

If we create a framework without ACPI (well, ACPI needs to be enabled in the kernel anyway for other reasons, like the ability to suspend to RAM) and then it turns out that we have to add some ACPI hooks to it, that might be difficult to do cleanly.

Thus, it seems reasonable to think of the ACPI handling in advance.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#351 lore raw
In reply to [email protected]

Hi!

Quoted 16 lines
Quoted 7 lines

Part of the problem here is that ACPI already has its own terminology, and you're trying to invent a new one instead of using the existing one.

I agree, it would be good to have a non-ACPI-specific hibernation mode, something which would look to ACPI like a normal shutdown. But I'm not so sure this is possible.

why would it not be possible?

Quoted 6 lines

You have to understand that the ACPI spec is weird and complex. The mere fact that you have written a system image to disk changes the way ACPI regards the shutdown procedure. Even though you may treat all the devices and the rest of the hardware exactly the same, it's a different operation as far as ACPI is concerned, with different requirements.

Quoted 6 lines
Quoted 2 lines

Yes, it's bizarre. Why do you think so many people have complained so vehemently about ACPI for all these years?

so let's act as if ACPI doesn't exist and make a suspend-to-disk that works without it and looks to ACPI like a complete power off/on cycle (but looks to the user like a suspend/resume cycle)

...if you act as if ACPI does not exist, you'll loose AC/battery power status upon resume, and maybe more, because ACPI handles that.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#352 lore raw
In reply to [email protected]
Quoted 92 lines · On Monday, 16 July 2007 00:42, [email protected] wrote:
Quoted 62 lines · Rafael J. Wysocki
Quoted 61 lines · On Sunday, 15 July 2007 22:13, [email protected] wrote:
Quoted 10 lines · Rafael J. Wysocki

Hi,

Since many alternative approaches to hibernation are now being considered and discussed, I thought it might be a good idea to list some things that in my not so humble opinion should be taken care of by any hibernation framework. They are listed below, not in any particular order, because I think they all are important. Still, I might have forgotten something, so everyone with experience in implementing hibernation, especially Pavel and Nigel, please check if the list is complete.

Quoted 8 lines

(1) Filesystems mounted before the hibernation are untouchable

When there's a memory snapshot, either in the form of a hibernation image, or in the form of the "old" kernel and processes available to the "new" kexeced kernel responsible for saving their memory, the filesystems mounted before the hibernation should not be accessed, even for reading, because that would cause their on-disk state to be inconsistent with the snapshot and might lead to a filesystem corruption.

AFAIK this is only the case with ext3, all other filesystems could be accessed read-only safely

this is arguably a bug with ext3 (and has been discussed as such), but right now the ext3 team has decided not to change this bahavior so hibernate needs to work around it. but don't mistake a work-around for a single (admittedly very popular) filesystem with a hard and fast directive.

Quoted 5 lines

(2) Swap space in use before the hibernation must be handled with care

If swap space is used for saving the memory snapshot, the snapshot-saving application (or kernel) must be careful enough not to overwrite swap pages that contain valid memory contents stored in there before the hibernation.

true, in fact, given that many distros and live-CD's autodetect swap partitions and consider them fair game, I would argue that the best thing to do would be to have the main system free up it's swap partitions before going into hibernation.

however, this could be a decision of the particular hibernate routines.

for the kexec approach the mapping of what swap pages are in use is one more chunk of data that needs to be assembled and made available through a defined interface.

Quoted 5 lines

(4) The user should be able to limit the size of a hibernation image

There are a couple of reasons of that. For example, the storage space used for saving the image may be smaller than the entire RAM or the user may want the image to be saved quickier.

it may make sense for this to be split into hard and soft limits.

if you try to save more then the storage space can hold you cannot continue, but if you are just a little over the arbatrary size limit that was set to make things fast you are better off saving things as-is then punting, going back to the system, trying to free more ram, and trying a hibernate again.

Quoted 8 lines
Quoted 5 lines

with the kexec approach the enforcment of these limits is also split into two sections.

when the hibernate command is given in the main kernel, it's userspace needs to follow some policy to decide how much (if any) memory to free.

How are you going to achieve this without (a) having hibernation-aware user space or (b) the freezer?

the hibernate command is a userspace command, but the fact that other things in userspace are running at the same time is exactly why this is only an estimate and best-effort as I said in the paragraph below.

Quoted 15 lines
Quoted 14 lines

but since the kexec command and the preporation of the devices can change the memory, the estimates done by the first kernel's userspace are just that, estimates.

Quoted 7 lines

(7) On ACPI systems special platform-related actions have to be carried out at the right points, so that the platform works correctly after the restore

The ACPI specification requires us to invoke some global ACPI methods during the hibernation and during the restore. Moreover, the ordering of code related to these ACPI methods may not be arbitrary (eg. some of them have to be executed after devices are put into low power states etc.).

for a pure hibernate mode, you will be powering off the box after saving the suspend image. why are there any special ACPI modes involved?

Quoted 7 lines
Quoted 4 lines

Because, for example, on my machine the status of power supply (present vs not present) is not updated correctly after the restore if ACPI callbacks aren't used during the hibernation. That's just experience and it's in line with the ACPI spec.

so if a machine is actually powered off the /dev/suspend process won't work?

No, it sort of works as usual, but after the restore the platform is not in the correct state.

Quoted 3 lines

remember that the system may run a different OS between the hibernate and the resume, makeing any assumptions about what state the hardware is in when you start the resume is a problem.

True, that's problematic.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#353 lore raw
In reply to [email protected]
Quoted 61 lines · On Sunday, 15 July 2007 22:13, [email protected] wrote:
Quoted 10 lines · Rafael J. Wysocki

Hi,

Since many alternative approaches to hibernation are now being considered and discussed, I thought it might be a good idea to list some things that in my not so humble opinion should be taken care of by any hibernation framework. They are listed below, not in any particular order, because I think they all are important. Still, I might have forgotten something, so everyone with experience in implementing hibernation, especially Pavel and Nigel, please check if the list is complete.

Quoted 8 lines

(1) Filesystems mounted before the hibernation are untouchable

When there's a memory snapshot, either in the form of a hibernation image, or in the form of the "old" kernel and processes available to the "new" kexeced kernel responsible for saving their memory, the filesystems mounted before the hibernation should not be accessed, even for reading, because that would cause their on-disk state to be inconsistent with the snapshot and might lead to a filesystem corruption.

AFAIK this is only the case with ext3, all other filesystems could be accessed read-only safely

this is arguably a bug with ext3 (and has been discussed as such), but right now the ext3 team has decided not to change this bahavior so hibernate needs to work around it. but don't mistake a work-around for a single (admittedly very popular) filesystem with a hard and fast directive.

Quoted 5 lines

(2) Swap space in use before the hibernation must be handled with care

If swap space is used for saving the memory snapshot, the snapshot-saving application (or kernel) must be careful enough not to overwrite swap pages that contain valid memory contents stored in there before the hibernation.

true, in fact, given that many distros and live-CD's autodetect swap partitions and consider them fair game, I would argue that the best thing to do would be to have the main system free up it's swap partitions before going into hibernation.

however, this could be a decision of the particular hibernate routines.

for the kexec approach the mapping of what swap pages are in use is one more chunk of data that needs to be assembled and made available through a defined interface.

Quoted 5 lines

(4) The user should be able to limit the size of a hibernation image

There are a couple of reasons of that. For example, the storage space used for saving the image may be smaller than the entire RAM or the user may want the image to be saved quickier.

it may make sense for this to be split into hard and soft limits.

if you try to save more then the storage space can hold you cannot continue, but if you are just a little over the arbatrary size limit that was set to make things fast you are better off saving things as-is then punting, going back to the system, trying to free more ram, and trying a hibernate again.

Quoted 5 lines

with the kexec approach the enforcment of these limits is also split into two sections.

when the hibernate command is given in the main kernel, it's userspace needs to follow some policy to decide how much (if any) memory to free.

How are you going to achieve this without (a) having hibernation-aware user space or (b) the freezer?

Quoted 17 lines

this could be anything from 'none, try and save all caches' to 'anything you can to minimize the amount of data to be saved, trash all caches' to something in between like 'try and free up enough memory to get the saved data below 1G, but save caches beyond that point'

then when the second kernel runs, it's userspace tools get the list of what memory should be saved that the main kernel handed to it, and then decides if this is acceptable (probably mostly the hard limits of 'can this work') and proceeds to save it somewhere.

but since the kexec command and the preporation of the devices can change the memory, the estimates done by the first kernel's userspace are just that, estimates.

Quoted 3 lines

(7) On ACPI systems special platform-related actions have to be carried out at the right points, so that the platform works correctly after the restore

Quoted 7 lines
Quoted 4 lines

The ACPI specification requires us to invoke some global ACPI methods during the hibernation and during the restore. Moreover, the ordering of code related to these ACPI methods may not be arbitrary (eg. some of them have to be executed after devices are put into low power states etc.).

for a pure hibernate mode, you will be powering off the box after saving the suspend image. why are there any special ACPI modes involved?

Because, for example, on my machine the status of power supply (present vs not present) is not updated correctly after the restore if ACPI callbacks aren't used during the hibernation. That's just experience and it's in line with the ACPI spec.

Quoted 5 lines

now, for suspend-to-ram you need to be aware of every possible power saving option you have and the cost of each of them, and here the ACPI modes are heavily used.

I think this is mixing suspend and hibernate still.

Yes, it is, but that's not we who's mixing. We just need to handle some systems built with ACPI in mind.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#354 lore raw
In reply to [email protected]
Quoted 9 lines · On Sun, 15 Jul 2007 [email protected] wrote:
Quoted 8 lines

(1) Filesystems mounted before the hibernation are untouchable

When there's a memory snapshot, either in the form of a hibernation image, or in the form of the "old" kernel and processes available to the "new" kexeced kernel responsible for saving their memory, the filesystems mounted before the hibernation should not be accessed, even for reading, because that would cause their on-disk state to be inconsistent with the snapshot and might lead to a filesystem corruption.

Quoted 8 lines

AFAIK this is only the case with ext3, all other filesystems could be accessed read-only safely

this is arguably a bug with ext3 (and has been discussed as such), but right now the ext3 team has decided not to change this bahavior so hibernate needs to work around it. but don't mistake a work-around for a single (admittedly very popular) filesystem with a hard and fast directive.

Isn't is possible to avoid this problem by mounting an ext3 filesystem as readonly ext2? Provided the filesystem isn't dirty it should be doable. (And provided the filesystem doesn't use any ext3 extensions that are incompatible with ext2.)

Alan Stern

#355 lore raw
In reply to [email protected]
Quoted 9 lines · On Sun, 15 Jul 2007 [email protected] wrote:
Quoted 8 lines

(1) Filesystems mounted before the hibernation are untouchable

When there's a memory snapshot, either in the form of a hibernation image, or in the form of the "old" kernel and processes available to the "new" kexeced kernel responsible for saving their memory, the filesystems mounted before the hibernation should not be accessed, even for reading, because that would cause their on-disk state to be inconsistent with the snapshot and might lead to a filesystem corruption.

Quoted 8 lines

AFAIK this is only the case with ext3, all other filesystems could be accessed read-only safely

this is arguably a bug with ext3 (and has been discussed as such), but right now the ext3 team has decided not to change this bahavior so hibernate needs to work around it. but don't mistake a work-around for a single (admittedly very popular) filesystem with a hard and fast directive.

Isn't is possible to avoid this problem by mounting an ext3 filesystem as readonly ext2? Provided the filesystem isn't dirty it should be doable. (And provided the filesystem doesn't use any ext3 extensions that are incompatible with ext2.)

Alan Stern

#356 lore raw
Quoted 20 lines · Alan Stern
Quoted 9 lines · On Sun, 15 Jul 2007 [email protected] wrote:
Quoted 8 lines

(1) Filesystems mounted before the hibernation are untouchable

When there's a memory snapshot, either in the form of a hibernation image, or in the form of the "old" kernel and processes available to the "new" kexeced kernel responsible for saving their memory, the filesystems mounted before the hibernation should not be accessed, even for reading, because that would cause their on-disk state to be inconsistent with the snapshot and might lead to a filesystem corruption.

Quoted 8 lines

AFAIK this is only the case with ext3, all other filesystems could be accessed read-only safely

this is arguably a bug with ext3 (and has been discussed as such), but right now the ext3 team has decided not to change this bahavior so hibernate needs to work around it. but don't mistake a work-around for a single (admittedly very popular) filesystem with a hard and fast directive.

Quoted 4 lines

Isn't is possible to avoid this problem by mounting an ext3 filesystem as readonly ext2? Provided the filesystem isn't dirty it should be doable. (And provided the filesystem doesn't use any ext3 extensions that are incompatible with ext2.)

from the last discussion I saw on the kernel mailing list, no. the act of mounting the ext3 filesystem as ext2 read-only will change it as the unsupported extentions get turned off (and I think the journal contents at least are lost as part of this)

David Lang

#357 lore raw

[email protected] writes:

[snip]

Quoted 9 lines
Quoted 4 lines

Isn't is possible to avoid this problem by mounting an ext3 filesystem as readonly ext2? Provided the filesystem isn't dirty it should be doable. (And provided the filesystem doesn't use any ext3 extensions that are incompatible with ext2.)

from the last discussion I saw on the kernel mailing list, no. the act of mounting the ext3 filesystem as ext2 read-only will change it as the unsupported extentions get turned off (and I think the journal contents at least are lost as part of this)

The fact of the matter is that it really doesn't matter whether mounting it read-only actually corrupts the data on disk or not. Regardless, it should not be done, because you are accessing a dirty filesystem that is still in use, and consequently there are no guarantees that either the metadata or the file contents are consistent. It isn't necessary for hibernation to be able to access mounted partitions anyway.

Signature · 1 line
Jeremy Maitin-Shepard
#358 lore raw
In reply to [email protected]

[email protected] writes:

[snip]

Quoted 9 lines
Quoted 4 lines

Isn't is possible to avoid this problem by mounting an ext3 filesystem as readonly ext2? Provided the filesystem isn't dirty it should be doable. (And provided the filesystem doesn't use any ext3 extensions that are incompatible with ext2.)

from the last discussion I saw on the kernel mailing list, no. the act of mounting the ext3 filesystem as ext2 read-only will change it as the unsupported extentions get turned off (and I think the journal contents at least are lost as part of this)

The fact of the matter is that it really doesn't matter whether mounting it read-only actually corrupts the data on disk or not. Regardless, it should not be done, because you are accessing a dirty filesystem that is still in use, and consequently there are no guarantees that either the metadata or the file contents are consistent. It isn't necessary for hibernation to be able to access mounted partitions anyway.

Signature · 1 line
Jeremy Maitin-Shepard
#359 lore raw
In reply to Rafael J. Wysocki

Hi,
I think a (10) is needed to be clear:

(10) This depends directly on (9)
Easy Userinterface for the average user, no one wants to edit several files and use a long commandline for a suspend (not all know about alias(P)), so keeping the effort to suspend your system low, please.(eg for my TuxOnIce i just type hibernate as root/ sudo hibernate as normal user and the suspend begin, the rest is automatically done by the configuration(for me this is shutting down my wireless interface)

Cornelius Riemenschneider

My source of power: www.humppa.com

#360 lore raw
In reply to Rafael J. Wysocki

Hi.

Quoted 3 lines · On Sunday 15 July 2007 22:33:32 Rafael J. Wysocki wrote:

Hi,

Since many alternative approaches to hibernation are now being considered

and

Quoted 1 line

discussed, I thought it might be a good idea to list some things that in my

not

Quoted 1 line

so humble opinion should be taken care of by any hibernation framework.

They

Quoted 8 lines

are listed below, not in any particular order, because I think they all are important. Still, I might have forgotten something, so everyone with experience in implementing hibernation, especially Pavel and Nigel, please check if the list is complete.

(1) Filesystems mounted before the hibernation are untouchable

When there's a memory snapshot, either in the form of a hibernation

image,

Quoted 2 lines

or in the form of the "old" kernel and processes available to the "new" kexeced kernel responsible for saving their memory, the filesystems

mounted

Quoted 2 lines

before the hibernation should not be accessed, even for reading, because that would cause their on-disk state to be inconsistent with the

snapshot

Quoted 5 lines

and might lead to a filesystem corruption.

(2) Swap space in use before the hibernation must be handled with care

If swap space is used for saving the memory snapshot, the

snapshot-saving

Quoted 1 line

application (or kernel) must be careful enough not to overwrite swap

pages

Quoted 1 line

that contain valid memory contents stored in there before the

hibernation.

Quoted 4 lines

(3) There are memory regions that must not be saved or restored

Some memory regions contain data that shouldn't be overwritten during

the

Quoted 3 lines

restore, because that might lead to the system not working correctly afterwards. Also, on some systems there are valid 'struct pages' structures that in fact corresond to memory holes and we should not

attempt

Quoted 8 lines

to save those pages.

(4) The user should be able to limit the size of a hibernation image

There are a couple of reasons of that. For example, the storage space used for saving the image may be smaller than the entire RAM or the user may want the image to be saved quickier.

Quoted 7 lines

(5) Hibernation should be transparent from the applications' point of view

Generally, applications should not notice that hibernation took place. [Note that I don't regard all processes as applications and I think that there may be processes which need to handle the hibernation in a special way.] Ideally, for example, if some audio is being played when a hibernation starts, the audio player should be able to continue playing

the

Quoted 9 lines

same audio after the restore from the point in which it has been interrupted by the hibernation. Also, the CPU affinities and similar settings requested by the applications before a hibernation should be binding after the restore.

(6) State of devices from before hibernation should be restored, if possible

If possible, during a restore devices should be brought back to the same state in which they were before the corresponding hibernation. Of

course

Quoted 6 lines

in some situations it might be impossible to do that (eg. the user connected the hibernated system to a different IP subnet and then restored), but as a general rule, we should do our best to restore the state of devices, which is directly related to point (5) above.

(7) On ACPI systems special platform-related actions have to be carried out

at

Quoted 4 lines

the right points, so that the platform works correctly after the restore

The ACPI specification requires us to invoke some global ACPI methods during the hibernation and during the restore. Moreover, the ordering

of

Quoted 2 lines

code related to these ACPI methods may not be arbitrary (eg. some of them have to be executed after devices are put into low power states

etc.).

Quoted 5 lines

(8) Hibernation and restore should not be too slow

In my opinion, if more than one minute is needed to hibernate the system with the help of certain hibernation framework, then this framework is

not

Quoted 1 line

very useful in practice. It might be useful to perform some special

tasks

Quoted 6 lines

(eg. moving a server to another place without taking it down), but it is not very useful, for example, to notebook users.

(9) Hibernation framework should not be too difficult to set up

It follows from my experience that if the users are required to do too

much

Quoted 3 lines

work to set up a hibernation framework, they will not use it as long as there are simpler alternatives (some of them will not use hibernation at all if it's too difficult to get to work). On the other hand, if the

users

Quoted 2 lines

are provided with a working hibernation framework by their distribution and they find it useful, they are not likely to use kernel.org kernels

if

Quoted 1 line

t's too difficult to replace the distribution kernel with a generic one

due

Quoted 5 lines

to the hibernation framework's requirements.

All of the existing hibernation frameworks have been written with the above points in mind and that's why they are what they are. In particular, the existence of the tasks freezer, hated by some people to the point of

insanity,

Quoted 4 lines

follows directly from points (1), (4) and (5).

In my opinion any hibernation framework that doesn't take the above requirements into account in any way will be a failure. Moreover, the

existing

Quoted 2 lines

frameworks fail to follow some of them too, so I consider all of these frameworks as a work in progress. For this reason, I will much more

appreciate

Quoted 3 lines

ideas allowing us to improve the existing frameworks in a more or less evolutionary way, then attempts to replace them all with something entirely new.

Sounds good to me. Nothing extra occurs immediately.

Regards,

Nigel

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

On Sun, Jul 15, 2007 at 02:33:32PM +0200, Rafael J. Wysocki wrote:

(snip)

Many of these assumptions are based on the assumption that we want to save a full image of RAM. I'm not convinced that this is true. The two things that we need are application state and hardware state. Application state can clearly be saved without kernel involvement (though restoring some of it may need some help from the kernel...), so hardware state is a more interesting question.

The obvious argument for saving the entirity of memory is that we have no mechanism for picking apart hardware state from any other part of the kernel. In reality, we're looking at implementing a set of hibernation operations anyway - it would be possible to utilise those to save as much state as needed. You also get fringe benefits, like being able to freeze a process that's accessing a piece of flaky hardware, swap the card out (assuming hotplug PCI), restore some amount of state and then let the process continue.

I appreciate that this suggestion sounds kind of fragile and complicated, but I think that's true of most descriptions of suspend to disk :) The main benefit is that it means we can use the hibernation infrastructure for other purposes (checkpointing, swapping hardware, that kind of thing) and reduce the damage caused by users doing seemingly reasonable things (like suspending Linux, booting Windows and then writing to a shared partition...).

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

On Sun, Jul 15, 2007 at 02:33:32PM +0200, Rafael J. Wysocki wrote:

(snip)

Many of these assumptions are based on the assumption that we want to save a full image of RAM. I'm not convinced that this is true. The two things that we need are application state and hardware state. Application state can clearly be saved without kernel involvement (though restoring some of it may need some help from the kernel...), so hardware state is a more interesting question.

The obvious argument for saving the entirity of memory is that we have no mechanism for picking apart hardware state from any other part of the kernel. In reality, we're looking at implementing a set of hibernation operations anyway - it would be possible to utilise those to save as much state as needed. You also get fringe benefits, like being able to freeze a process that's accessing a piece of flaky hardware, swap the card out (assuming hotplug PCI), restore some amount of state and then let the process continue.

I appreciate that this suggestion sounds kind of fragile and complicated, but I think that's true of most descriptions of suspend to disk :) The main benefit is that it means we can use the hibernation infrastructure for other purposes (checkpointing, swapping hardware, that kind of thing) and reduce the damage caused by users doing seemingly reasonable things (like suspending Linux, booting Windows and then writing to a shared partition...).

Signature · 1 line
Matthew Garrett | [email protected]
#363 lore raw
Quoted 10 lines · Matthew Garrett

On Sun, Jul 15, 2007 at 02:33:32PM +0200, Rafael J. Wysocki wrote:

(snip)

Many of these assumptions are based on the assumption that we want to save a full image of RAM. I'm not convinced that this is true. The two things that we need are application state and hardware state. Application state can clearly be saved without kernel involvement (though restoring some of it may need some help from the kernel...), so hardware state is a more interesting question.

one other reason for saving all the ram is that some people want to save all the system caches so that the machine is just as responsive immediatly after the resume as it was before the hibernate.

Quoted 9 lines

The obvious argument for saving the entirity of memory is that we have no mechanism for picking apart hardware state from any other part of the kernel. In reality, we're looking at implementing a set of hibernation operations anyway - it would be possible to utilise those to save as much state as needed. You also get fringe benefits, like being able to freeze a process that's accessing a piece of flaky hardware, swap the card out (assuming hotplug PCI), restore some amount of state and then let the process continue.

Quoted 7 lines

I appreciate that this suggestion sounds kind of fragile and complicated, but I think that's true of most descriptions of suspend to disk :) The main benefit is that it means we can use the hibernation infrastructure for other purposes (checkpointing, swapping hardware, that kind of thing) and reduce the damage caused by users doing seemingly reasonable things (like suspending Linux, booting Windows and then writing to a shared partition...).

I see the order being a little different.

if anyone implements a reliable checkpoint/restore of applications then that could be used as to pause specific applicaitons, move applications from one machine to another, move applications from one kernel to another, and as a side effect, as a form of hibernation when you are willing to loose your cache in favor of storing as little info as possible (since you wouldn't need to store the cache memory or any kernel memory/state)

David Lang