From: Nigel Cunningham <nigel@suspend2.net>
To: linux-kernel@vger.kernel.org
To: linux-kernel@vger.kernel.org
Subject: [ 12/23] [Suspend2] Split freezing of threads according to whether user/kernelspace.
Date: Thu, 26 Jan 2006 13:45:51 +1000 [thread overview]
Message-ID: <20060126034551.3178.53576.stgit@localhost.localdomain> (raw)
In-Reply-To: <20060126034518.3178.55397.stgit@localhost.localdomain>
Split the freezing of threads according to whether they're userspace or
kernelspace threads. We use separate completion handlers, thereby allowing
for the possibility of thawing kernel space without thawing userspace.
This will be used to allow memory to be freed without it racing against
userspace.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/process.c | 71 +++++++++++++++++++++++++++++++++++-------------
1 files changed, 52 insertions(+), 19 deletions(-)
diff --git a/kernel/power/process.c b/kernel/power/process.c
index 444a163..a3aca9a 100644
--- a/kernel/power/process.c
+++ b/kernel/power/process.c
@@ -45,8 +45,11 @@
*/
#define TIMEOUT (6 * HZ)
-DECLARE_COMPLETION(thaw);
-static atomic_t nr_frozen;
+
+DECLARE_COMPLETION(kernelspace_thaw);
+DECLARE_COMPLETION(userspace_thaw);
+static atomic_t nr_userspace_frozen;
+static atomic_t nr_kernelspace_frozen;
struct frozen_fs
{
@@ -120,32 +123,62 @@ static int freezeable(struct task_struct
return 1;
}
+static void __freeze_process(struct completion *completion_handler,
+ atomic_t *nr_frozen)
+{
+ long save;
+
+ freezer_message("%s (%d) frozen.\n",
+ current->comm, current->pid);
+ save = current->state;
+
+ atomic_inc(nr_frozen);
+ wait_for_completion(completion_handler);
+ atomic_dec(nr_frozen);
+
+ current->state = save;
+ freezer_message("%s (%d) leaving freezer.\n",
+ current->comm, current->pid);
+}
+
/*
* Invoked by the task todo list notifier when the task to be
* frozen is running.
*/
static int freeze_process(struct notifier_block *nl, unsigned long x, void *v)
{
- /* Hmm, should we be allowed to suspend when there are realtime
- processes around? */
- long save;
- save = current->state;
- pr_debug("%s frozen\n", current->comm);
+ unsigned long flags;
+
+ might_sleep();
+
+ /* Locking to handle race against waking the process in
+ * freeze threads. */
+ spin_lock_irqsave(¤t->sighand->siglock, flags);
current->flags |= PF_FROZEN;
- notifier_chain_unregister(¤t->todo, nl);
- kfree(nl);
- freezer_message("=");
-
- spin_lock_irq(¤t->sighand->siglock);
- recalc_sigpending(); /* We sent fake signal, clean it up */
- atomic_inc(&nr_frozen);
- spin_unlock_irq(¤t->sighand->siglock);
- wait_for_completion(&thaw);
+ if (nl)
+ notifier_chain_unregister(¤t->todo, nl);
+
+ recalc_sigpending();
+ spin_unlock_irqrestore(¤t->sighand->siglock, flags);
+
+ if (nl)
+ kfree(nl);
+
+ if (test_freezer_state(FREEZER_ON)) {
+ if (current->mm)
+ __freeze_process(&userspace_thaw, &nr_userspace_frozen);
+ else
+ __freeze_process(&kernelspace_thaw,
+ &nr_kernelspace_frozen);
+ }
+
+ spin_lock_irqsave(¤t->sighand->siglock, flags);
+ recalc_sigpending();
+ spin_unlock_irqrestore(¤t->sighand->siglock, flags);
+
current->flags &= ~PF_FROZEN;
- atomic_dec(&nr_frozen);
- pr_debug("%s thawed\n", current->comm);
- current->state = save;
+
return 0;
}
--
Nigel Cunningham nigel at suspend2 dot net
next prev parent reply other threads:[~2006-01-26 3:55 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-26 3:45 [ 00/23] [Suspend2] Freezer Upgrade Patches Nigel Cunningham
2006-01-26 3:45 ` [ 01/23] [Suspend2] Make workqueues freezeable Nigel Cunningham
2006-01-26 23:17 ` Rafael J. Wysocki
2006-01-27 4:01 ` Nigel Cunningham
2006-01-26 3:45 ` [ 02/23] [Suspend2] Add new include/linux/freezer.h header Nigel Cunningham
2006-01-26 3:45 ` [ 03/23] [Suspend2] Allow a notifier to remove itself from the notifier list Nigel Cunningham
2006-01-26 3:45 ` [ 04/23] [Suspend2] Todo notifier for processes Nigel Cunningham
2006-01-26 3:45 ` [ 05/23] [Suspend2] Make the freezer use todo lists Nigel Cunningham
2006-01-26 3:45 ` [ 06/23] [Suspend2] Disable usermode helper invocations when the freezer is on Nigel Cunningham
2006-01-30 22:05 ` Rafael J. Wysocki
2006-01-31 3:24 ` Nigel Cunningham
2006-01-31 10:58 ` Rafael J. Wysocki
2006-01-31 23:21 ` Nigel Cunningham
2006-02-01 0:33 ` Rafael J. Wysocki
2006-01-26 3:45 ` [ 07/23] [Suspend2] Add which-to-thaw parameter to thaw_processes() calls Nigel Cunningham
2006-01-26 3:45 ` [ 08/23] [Suspend2] New freezer explanation for kernel/power/process.c Nigel Cunningham
2006-01-26 3:45 ` [ 09/23] [Suspend2] Quieten the freezer for normal operation Nigel Cunningham
2006-01-26 3:45 ` [ 10/23] [Suspend2] Add support for freezing filesystem bdevs Nigel Cunningham
2006-01-26 3:45 ` [ 11/23] [Suspend2] Modify freezeable for freezing kernel threads separately Nigel Cunningham
2006-01-26 3:45 ` Nigel Cunningham [this message]
2006-01-26 3:45 ` [ 13/23] [Suspend2] Add support for thawing just kernel threads or all threads Nigel Cunningham
2006-01-26 3:45 ` [ 14/23] [Suspend2] Helper for counting freezeable threads of a type Nigel Cunningham
2006-01-26 3:45 ` [ 15/23] [Suspend2] Helper for counting uninterruptible " Nigel Cunningham
2006-01-30 22:18 ` Rafael J. Wysocki
2006-01-30 22:25 ` Pavel Machek
2006-01-31 0:02 ` Rafael J. Wysocki
2006-01-31 9:27 ` [RFC/RFT] finally solve "swsusp fails with mysqld" problem Pavel Machek
2006-01-31 16:17 ` Rafael J. Wysocki
2006-01-31 21:29 ` Pavel Machek
2006-01-31 22:30 ` Rafael J. Wysocki
2006-01-31 5:42 ` [ 15/23] [Suspend2] Helper for counting uninterruptible threads of a type Nigel Cunningham
2006-01-26 3:45 ` [ 16/23] [Suspend2] Helper to signal all " Nigel Cunningham
2006-01-26 3:46 ` [ 17/23] [Suspend2] Helper to prod processes that should have frozen but haven't Nigel Cunningham
2006-01-26 3:46 ` [ 18/23] [Suspend2] Helper: Did we fail to freeze all threads of a type? Nigel Cunningham
2006-01-26 3:46 ` [ 19/23] [Suspend2] Freeze all threads of a type Nigel Cunningham
2006-01-26 3:46 ` [ 20/23] [Suspend2] Modify process.c includes and export freezer state Nigel Cunningham
2006-01-26 3:46 ` [ 21/23] [Suspend2] Remove unused DEBUG undef Nigel Cunningham
2006-01-26 3:46 ` [ 22/23] [Suspend2] Modify swsusp to thaw kernel threads while eating memory Nigel Cunningham
2006-01-26 3:46 ` [ 23/23] [Suspend2] Don't scan LRU while freezer is on Nigel Cunningham
2006-01-26 11:55 ` [ 00/23] [Suspend2] Freezer Upgrade Patches Pavel Machek
2006-01-26 21:49 ` Nigel Cunningham
2006-01-26 23:10 ` Rafael J. Wysocki
2006-01-27 4:04 ` Nigel Cunningham
2006-01-27 12:18 ` Rafael J. Wysocki
2006-01-27 19:20 ` Nigel Cunningham
2006-01-27 23:22 ` Pavel Machek
2006-01-30 5:54 ` Nigel Cunningham
2006-01-30 11:50 ` Pavel Machek
2006-01-30 7:53 ` Stefan Seyfried
2006-01-30 11:53 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060126034551.3178.53576.stgit@localhost.localdomain \
--to=nigel@suspend2.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.