From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Pavel Machek <pavel@suse.cz>
Cc: Nigel Cunningham <nigel@suspend2.net>, Linux PM <linux-pm@osdl.org>
Subject: [RFC][PATCH -mm][Experimental] swsusp: freeze userspace processes first
Date: Wed, 1 Feb 2006 01:41:52 +0100 [thread overview]
Message-ID: <200602010141.53974.rjw@sisk.pl> (raw)
[-- Attachment #1: Type: text/plain, Size: 6342 bytes --]
Hi,
This is an experimantal patch aimed at the "unable to freeze processes under
load" problem.
On my box the 2.6.16-rc1-mm4 kernel with this patch applied survives the
"dd if=/dev/hda of=/dev/null" test.
Please have a look.
Greetings,
Rafael
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
include/linux/kmod.h | 3 ++
include/linux/suspend.h | 4 +++
kernel/kmod.c | 23 +++++++++++++++++
kernel/power/process.c | 62 +++++++++++++++++++++++++++++++++++++++++-------
4 files changed, 83 insertions(+), 9 deletions(-)
Index: linux-2.6.16-rc1-mm4/kernel/power/process.c
===================================================================
--- linux-2.6.16-rc1-mm4.orig/kernel/power/process.c 2006-01-31 23:45:59.000000000 +0100
+++ linux-2.6.16-rc1-mm4/kernel/power/process.c 2006-02-01 01:12:14.000000000 +0100
@@ -12,12 +12,19 @@
#include <linux/interrupt.h>
#include <linux/suspend.h>
#include <linux/module.h>
+#include <linux/kmod.h>
+#include <linux/mutex.h>
/*
* Timeout for stopping processes
*/
#define TIMEOUT (6 * HZ)
+/* This is used to disable usermodehelper invocations while
+ * freeze_processes() is being executed
+ */
+int freezing_processes;
+DEFINE_MUTEX(freezer_lock);
static inline int freezeable(struct task_struct * p)
{
@@ -54,40 +61,77 @@ void refrigerator(void)
current->state = save;
}
+static inline void freeze_process(struct task_struct *p)
+{
+ unsigned long flags;
+
+ freeze(p);
+ spin_lock_irqsave(&p->sighand->siglock, flags);
+ signal_wake_up(p, 0);
+ spin_unlock_irqrestore(&p->sighand->siglock, flags);
+}
+
/* 0 = success, else # of processes that we failed to stop */
int freeze_processes(void)
{
- int todo;
+ int todo, nr_kernel, nr_user, user_frozen;
unsigned long start_time;
struct task_struct *g, *p;
unsigned long flags;
+ mutex_lock(&freezer_lock);
+ freezing_processes = 1;
+ mutex_unlock(&freezer_lock);
+ while (atomic_read(&usermodehelper_waiting))
+ schedule();
+
printk( "Stopping tasks: " );
start_time = jiffies;
+ user_frozen = 0;
do {
- todo = 0;
+ nr_kernel = 0;
+ nr_user = 0;
read_lock(&tasklist_lock);
do_each_thread(g, p) {
if (!freezeable(p))
continue;
if (frozen(p))
continue;
-
- freeze(p);
- spin_lock_irqsave(&p->sighand->siglock, flags);
- signal_wake_up(p, 0);
- spin_unlock_irqrestore(&p->sighand->siglock, flags);
- todo++;
+ if (p->mm) {
+ /* The task is a user-space one. Freeze it */
+ printk(" freezing %s\n", p->comm);
+ freeze_process(p);
+ nr_user++;
+ } else {
+ /* Freeze only if the user space is frozen */
+ if (user_frozen) {
+ printk(" freezing [%s]\n", p->comm);
+ freeze_process(p);
+ }
+ nr_kernel++;
+ }
} while_each_thread(g, p);
read_unlock(&tasklist_lock);
+ user_frozen = !nr_user;
+ todo = nr_user + nr_kernel;
yield(); /* Yield is okay here */
if (todo && time_after(jiffies, start_time + TIMEOUT)) {
printk( "\n" );
- printk(KERN_ERR " stopping tasks timed out (%d tasks remaining)\n", todo );
+ printk(KERN_ERR " stopping tasks timed out "
+ "after %d seconds (%d tasks remaining):\n",
+ TIMEOUT / HZ, todo);
+ do_each_thread(g, p) {
+ if (freezeable(p) && !frozen(p))
+ printk(KERN_ERR " %s\n", p->comm);
+ } while_each_thread(g, p);
break;
}
} while(todo);
+ mutex_lock(&freezer_lock);
+ freezing_processes = 0;
+ mutex_unlock(&freezer_lock);
+
/* This does not unfreeze processes that are already frozen
* (we have slightly ugly calling convention in that respect,
* and caller must call thaw_processes() if something fails),
Index: linux-2.6.16-rc1-mm4/kernel/kmod.c
===================================================================
--- linux-2.6.16-rc1-mm4.orig/kernel/kmod.c 2006-01-31 23:45:59.000000000 +0100
+++ linux-2.6.16-rc1-mm4/kernel/kmod.c 2006-02-01 00:20:10.000000000 +0100
@@ -36,6 +36,8 @@
#include <linux/mount.h>
#include <linux/kernel.h>
#include <linux/init.h>
+#include <linux/suspend.h>
+#include <linux/mutex.h>
#include <asm/uaccess.h>
extern int max_threads;
@@ -216,6 +218,10 @@ static void __call_usermodehelper(void *
complete(sub_info->complete);
}
+#ifdef CONFIG_SOFTWARE_SUSPEND
+atomic_t usermodehelper_waiting = ATOMIC_INIT(0);
+#endif
+
/**
* call_usermodehelper_keys - start a usermode application
* @path: pathname for the application
@@ -249,11 +255,28 @@ int call_usermodehelper_keys(char *path,
if (!khelper_wq)
return -EBUSY;
+#ifdef CONFIG_SOFTWARE_SUSPEND
+ mutex_lock(&freezer_lock);
+ if (freezing_processes) {
+ mutex_unlock(&freezer_lock);
+ return 0;
+ }
+ if (wait)
+ atomic_inc(&usermodehelper_waiting);
+ mutex_unlock(&freezer_lock);
+#endif
+
if (path[0] == '\0')
return 0;
queue_work(khelper_wq, &work);
wait_for_completion(&done);
+
+#ifdef CONFIG_SOFTWARE_SUSPEND
+ if (wait)
+ atomic_dec(&usermodehelper_waiting);
+#endif
+
return sub_info.retval;
}
EXPORT_SYMBOL(call_usermodehelper_keys);
Index: linux-2.6.16-rc1-mm4/include/linux/suspend.h
===================================================================
--- linux-2.6.16-rc1-mm4.orig/include/linux/suspend.h 2006-01-31 23:45:59.000000000 +0100
+++ linux-2.6.16-rc1-mm4/include/linux/suspend.h 2006-02-01 00:20:20.000000000 +0100
@@ -40,6 +40,10 @@ extern void drain_local_pages(void);
extern void mark_free_pages(struct zone *zone);
#ifdef CONFIG_PM
+struct mutex;
+extern struct mutex freezer_lock;
+extern int freezing_processes;
+
/* kernel/power/swsusp.c */
extern int software_suspend(void);
Index: linux-2.6.16-rc1-mm4/include/linux/kmod.h
===================================================================
--- linux-2.6.16-rc1-mm4.orig/include/linux/kmod.h 2006-01-31 23:45:59.000000000 +0100
+++ linux-2.6.16-rc1-mm4/include/linux/kmod.h 2006-02-01 00:06:19.000000000 +0100
@@ -23,6 +23,7 @@
#include <linux/config.h>
#include <linux/errno.h>
#include <linux/compiler.h>
+#include <asm/atomic.h>
#define KMOD_PATH_LEN 256
@@ -36,6 +37,8 @@ static inline int request_module(const c
#define try_then_request_module(x, mod...) ((x) ?: (request_module(mod), (x)))
+extern atomic_t usermodehelper_waiting;
+
struct key;
extern int call_usermodehelper_keys(char *path, char *argv[], char *envp[],
struct key *session_keyring, int wait);
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
next reply other threads:[~2006-02-01 0:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-01 0:41 Rafael J. Wysocki [this message]
2006-02-01 10:55 ` [RFC][PATCH -mm][Experimental] swsusp: freeze userspace processes first Pavel Machek
2006-02-01 11:18 ` Nigel Cunningham
2006-02-01 20:13 ` Rafael J. Wysocki
2006-02-01 11:47 ` Pavel Machek
2006-02-01 12:24 ` Nigel Cunningham
2006-02-01 12:49 ` Pavel Machek
2006-02-01 21:41 ` Nigel Cunningham
2006-02-01 23:57 ` Rafael J. Wysocki
2006-02-02 13:55 ` Rafael J. Wysocki
2006-02-02 15:08 ` Pavel Machek
2006-02-02 18:32 ` Rafael J. Wysocki
2006-02-04 21:26 ` Pavel Machek
2006-02-04 21:47 ` Rafael J. Wysocki
2006-02-01 22:19 ` 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=200602010141.53974.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=linux-pm@osdl.org \
--cc=nigel@suspend2.net \
--cc=pavel@suse.cz \
/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.