Freezer: Handle uninterruptible tasks
Quoted 6 lines · Rafael J. Wysocki
This patch makes the freezer skip uninterruptible user space tasks (ie. such that have an mm of their own) when counting the tasks to be frozen. As a result, these tasks have the
TIF_FREEZEandTIF_SIGPENDINGflags set, but the freezer doesn't wait for them to enter the refrigerator. Nevertheless, they will enter the refrigerator as soon as they change their state.
A small correction: they will enter the refrigerator on return to user-space. Actually, TASK_INTERRUPTIBLE doesn't mean the task actually sleeps. It could be running or preempted... I am a bit worried :)
Review
Quoted 3 lines
(quoted diff) +3
-0+static int freezer_should_skip(struct task_struct *p) +{ + return (has_mm(p) && (p->state | TASK_UNINTERRUPTIBLE));
^^^
I guess you meant "&", not "|".
Oleg.
Am Freitag, 6. Juli 2007 schrieb Oleg Nesterov:
Quoted 9 lines
Quoted 6 lines · Rafael J. Wysocki
This patch makes the freezer skip uninterruptible user space tasks (ie. such that have an mm of their own) when counting the tasks to be frozen. As a result, these tasks have the
TIF_FREEZEandTIF_SIGPENDINGflags set, but the freezer doesn't wait for them to enter the refrigerator. Nevertheless, they will enter the refrigerator as soon as they change their state.A small correction: they will enter the refrigerator on return to user-space.
That is too late. We would need them to go to sleep as soon as they are woken up. This does not matter if they are in uninterruptible sleep due to fuse deadlocking, as they won't be woken up, but it kills the other cases.
Regards
Oliver
Quoted 9 lines · Oliver Neukum
Am Freitag, 6. Juli 2007 schrieb Oleg Nesterov:
Quoted 8 lines
Quoted 6 lines · Rafael J. Wysocki
This patch makes the freezer skip uninterruptible user space tasks (ie. such that have an mm of their own) when counting the tasks to be frozen. As a result, these tasks have the
TIF_FREEZEandTIF_SIGPENDINGflags set, but the freezer doesn't wait for them to enter the refrigerator. Nevertheless, they will enter the refrigerator as soon as they change their state.
Quoted 5 lines
Quoted 1 line
A small correction: they will enter the refrigerator on return to user-space.
That is too late. We would need them to go to sleep as soon as they are woken up. This does not matter if they are in uninterruptible sleep due to fuse deadlocking, as they won't be woken up, but it kills the other cases.
I'm sorry I can't write anything more about that right now, I'll write more tomorrow.
For now, I can only say that I have reasons to believe that the other cases are not likely to "leak" through the freezer.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 16 lines · Rafael J. Wysocki
Quoted 9 lines · Oliver Neukum
Am Freitag, 6. Juli 2007 schrieb Oleg Nesterov:
Quoted 8 lines
Quoted 6 lines · Rafael J. Wysocki
This patch makes the freezer skip uninterruptible user space tasks (ie. such that have an mm of their own) when counting the tasks to be frozen. As a result, these tasks have the
TIF_FREEZEandTIF_SIGPENDINGflags set, but the freezer doesn't wait for them to enter the refrigerator. Nevertheless, they will enter the refrigerator as soon as they change their state.Quoted 5 lines
Quoted 1 line
A small correction: they will enter the refrigerator on return to user-space.
That is too late. We would need them to go to sleep as soon as they are woken up. This does not matter if they are in uninterruptible sleep due to fuse deadlocking, as they won't be woken up, but it kills the other cases.
Quoted 5 lines
I'm sorry I can't write anything more about that right now, I'll write more tomorrow.
For now, I can only say that I have reasons to believe that the other cases are not likely to "leak" through the freezer.
OK, sorry for the delay.
The first reason is that a similar approach had been used by suspend2 for quite some time without any visible adverse effects. Of course this is not a proof, but it means that the undesirable conditions are not easy to trigger (if at all possible).
Next, if an uninterruptible task A waits on a mutex (or semaphore), then there is a task B that holds it. This task may be a kernel thread or a user space process. In the latter case it may also be uninterruptible, but then we can consider that task instead of A, so assume that B is interruptible. In that case, however, B is also freezable, but before it's frozen, it must release the mutex. In that case A will become freezable before B is frozen and the freezer will have a chance to start to count A. Thus, in that case A won't "leak" through the freezer in the uninterruptible state.
Now, if B is a kernel thread, it might hold the mutex longer than the freezer is running, but it has to have a reason for that. Namely, I think that in practice this can only happen if the resource protected by the lock is unavailable. In that case, task A may potentially cause problems to happen if the resource becomes available during the suspend or resume at exactly the right moment (eg. when .suspend() that task A may interfere with is being executed). IMO, this is unlikely.
I think that this also applies to the situation in which an uninterruptible task waits for an event to occur (like a completion). Namely, if the event waited for by the task doesn't occur relatively quickly (like within a few scheduling cycles), then it's likely not to occur throughout the entire suspend/resume cycle.
This doesn't mean that no problems will happen no matter what, but at least they are much less likely to happend than in the case when we remove the freezer entirely without doing anything about the drivers before.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 9 lines · Oleg Nesterov
Quoted 6 lines · Rafael J. Wysocki
This patch makes the freezer skip uninterruptible user space tasks (ie. such that have an mm of their own) when counting the tasks to be frozen. As a result, these tasks have the
TIF_FREEZEandTIF_SIGPENDINGflags set, but the freezer doesn't wait for them to enter the refrigerator. Nevertheless, they will enter the refrigerator as soon as they change their state.A small correction: they will enter the refrigerator on return to user-space.
Yes, I should have written that explicitly.
Quoted 2 lines
Actually,
TASK_INTERRUPTIBLEdoesn't mean the task actually sleeps. It could be running or preempted... I am a bit worried :)
Fortunately, similar approach has been tested quite extensively by suspend2, IIRC. :-)
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+static int freezer_should_skip(struct task_struct *p) +{ + return (has_mm(p) && (p->state | TASK_UNINTERRUPTIBLE));^^^I guess you meant "&", not "|".
Yes, I've already spotted that, but thanks anyway.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Hi.
Quoted 4 lines · On Saturday 07 July 2007 08:56:21 Rafael J. Wysocki wrote:
Quoted 3 lines · Oleg Nesterov
Quoted 2 lines · Rafael J. Wysocki
This patch makes the freezer skip uninterruptible user space tasks (ie.
such
Quoted 1 line
Quoted 1 line
Quoted 1 line
that have an mm of their own) when counting the tasks to be frozen. As
a
Quoted 1 line
Quoted 1 line
Quoted 1 line
result, these tasks have the
TIF_FREEZEandTIF_SIGPENDINGflags set,
but the
Quoted 1 line
Quoted 1 line
Quoted 1 line
freezer doesn't wait for them to enter the refrigerator. Nevertheless,
they
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
will enter the refrigerator as soon as they change their state.
A small correction: they will enter the refrigerator on return to
user-space.
Quoted 4 lines
Yes, I should have written that explicitly.
Quoted 1 line
Actually,
TASK_INTERRUPTIBLEdoesn't mean the task actually sleeps. It
could
Quoted 4 lines
Quoted 1 line
be running or preempted... I am a bit worried :)
Fortunately, similar approach has been tested quite extensively by suspend2, IIRC. :-)
That's right. I used to signal TASK_UNINTERRUPTIBLE (I take it the INTERRUPTIBLE above is a typo) tasks, but ignore them when deciding whether freezing was successful.
I've since dropped those modifications, but only because I'm actively trying to get closer to mainline.
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.