public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [Suspend2][ 00/13] Miscellaneous patches
@ 2006-06-27  4:42 Nigel Cunningham
  2006-06-27  4:42 ` [Suspend2][ 01/13] [Suspend2] Suspend2 version header Nigel Cunningham
                   ` (12 more replies)
  0 siblings, 13 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:42 UTC (permalink / raw)
  To: linux-kernel


These patches add a few files providing general files (version.h etc),
and patch files outside kernel/power to add boot time hooks for
resuming, reserve netlink socket numbers and such like.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Suspend2][ 01/13] [Suspend2] Suspend2 version header.
  2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
@ 2006-06-27  4:42 ` Nigel Cunningham
  2006-06-27  4:42 ` [Suspend2][ 02/13] [Suspend2] Boot time hooks Nigel Cunningham
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:42 UTC (permalink / raw)
  To: linux-kernel

Header declaring the suspend2 version.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/version.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/kernel/power/version.h b/kernel/power/version.h
new file mode 100644
index 0000000..4a8b6c4
--- /dev/null
+++ b/kernel/power/version.h
@@ -0,0 +1,10 @@
+/*
+ * kernel/power/version.h
+ *
+ * Copyright 2004-2006 Nigel Cunningham <nigel@suspend2.net>
+ *
+ * Distributed under GPLv2.
+ */
+
+#define SUSPEND_CORE_VERSION "2.2.6.1"
+#define name_suspend "Suspend2 " SUSPEND_CORE_VERSION ": "

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Suspend2][ 02/13] [Suspend2] Boot time hooks.
  2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
  2006-06-27  4:42 ` [Suspend2][ 01/13] [Suspend2] Suspend2 version header Nigel Cunningham
@ 2006-06-27  4:42 ` Nigel Cunningham
  2006-06-27  4:42 ` [Suspend2][ 03/13] [Suspend2] Add netlink socket numbers Nigel Cunningham
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:42 UTC (permalink / raw)
  To: linux-kernel

Hooks for checking whether to resume when booting.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 init/do_mounts.c        |   28 +++++++++++++++++++++++++---
 init/do_mounts_initrd.c |   10 +++++++++-
 init/main.c             |    4 +++-
 3 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/init/do_mounts.c b/init/do_mounts.c
index 21b3b8f..0cc9233 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -138,11 +138,16 @@ dev_t name_to_dev_t(char *name)
 	char s[32];
 	char *p;
 	dev_t res = 0;
-	int part;
+	int part, mount_result;
 
 #ifdef CONFIG_SYSFS
 	int mkdir_err = sys_mkdir("/sys", 0700);
-	if (sys_mount("sysfs", "/sys", "sysfs", 0, NULL) < 0)
+	/* 
+	 * When changing resume2 parameter for Software Suspend, sysfs may
+	 * already be mounted. 
+	 */
+	mount_result = sys_mount("sysfs", "/sys", "sysfs", 0, NULL);
+	if (mount_result < 0 && mount_result != -EBUSY)
 		goto out;
 #endif
 
@@ -194,7 +199,8 @@ dev_t name_to_dev_t(char *name)
 	res = try_name(s, part);
 done:
 #ifdef CONFIG_SYSFS
-	sys_umount("/sys", 0);
+	if (mount_result >= 0)
+		sys_umount("/sys", 0);
 out:
 	if (!mkdir_err)
 		sys_rmdir("/sys");
@@ -420,9 +426,25 @@ void __init prepare_namespace(void)
 
 	is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
 
+	/* Suspend2:
+	 * By this point, suspend_early_init has been called to initialise our
+	 * proc interface. If modules are built in, they have registered (all
+	 * of the above via late_initcalls).
+	 * 
+	 * We have not yet looked to see if an image exists, however. If we
+	 * have an initrd, it is expected that the user will have set it up
+	 * to echo > /proc/suspend2/do_resume and thus initiate any
+	 * resume. If they don't do that, we do it immediately after the initrd
+	 * is finished (major issues if they mount filesystems rw from the
+	 * initrd! - they are warned. If there's no usable initrd, we do our
+	 * check next.
+	 */
 	if (initrd_load())
 		goto out;
 
+	if (test_suspend_state(SUSPEND_RESUME_NOT_DONE))
+		suspend2_try_resume();
+	
 	if (is_floppy && rd_doload && rd_load_disk(0))
 		ROOT_DEV = Root_RAM0;
 
diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
index 405f903..9f8287f 100644
--- a/init/do_mounts_initrd.c
+++ b/init/do_mounts_initrd.c
@@ -7,6 +7,7 @@
 #include <linux/romfs_fs.h>
 #include <linux/initrd.h>
 #include <linux/sched.h>
+#include <linux/suspend.h>
 
 #include "do_mounts.h"
 
@@ -59,10 +60,17 @@ static void __init handle_initrd(void)
 	current->flags |= PF_NOFREEZE;
 	pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
 	if (pid > 0) {
-		while (pid != sys_wait4(-1, NULL, 0, NULL))
+		while (pid != sys_wait4(-1, NULL, 0, NULL)) {
 			yield();
+			try_to_freeze();
+		}
 	}
 
+	if (test_suspend_state(SUSPEND_RESUME_NOT_DONE))
+		printk(KERN_ERR "Suspend2: Initrd lacks echo > /proc/suspend2/do_resume.\n");
+	clear_suspend_state(SUSPEND_BOOT_TIME);
+	current->flags &= ~PF_NOFREEZE;
+
 	/* move initrd to rootfs' /old */
 	sys_fchdir(old_fd);
 	sys_mount("/", ".", NULL, MS_MOVE, NULL);
diff --git a/init/main.c b/init/main.c
index f715b9b..89e1ba3 100644
--- a/init/main.c
+++ b/init/main.c
@@ -681,7 +681,9 @@ static int init(void * unused)
 
 	/*
 	 * check if there is an early userspace init.  If yes, let it do all
-	 * the work
+	 * the work. For suspend2, we assume that it will do the right thing
+	 * with regard to trying to resume at the right place. When that
+	 * happens, the BOOT_TIME flag will be cleared.
 	 */
 
 	if (!ramdisk_execute_command)

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Suspend2][ 03/13] [Suspend2] Add netlink socket numbers.
  2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
  2006-06-27  4:42 ` [Suspend2][ 01/13] [Suspend2] Suspend2 version header Nigel Cunningham
  2006-06-27  4:42 ` [Suspend2][ 02/13] [Suspend2] Boot time hooks Nigel Cunningham
@ 2006-06-27  4:42 ` Nigel Cunningham
  2006-06-27  4:42 ` [Suspend2][ 04/13] [Suspend2] Follow page routine Nigel Cunningham
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:42 UTC (permalink / raw)
  To: linux-kernel

Reserve netlink socket numbers for use by Suspend2 userspace helpers.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 include/linux/netlink.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 87b8a57..50f282a 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -21,6 +21,8 @@
 #define NETLINK_DNRTMSG		14	/* DECnet routing messages */
 #define NETLINK_KOBJECT_UEVENT	15	/* Kernel messages to userspace */
 #define NETLINK_GENERIC		16
+#define NETLINK_SUSPEND2_USERUI	17	/* For suspend2's userui */
+#define NETLINK_SUSPEND2_USM	18	/* For suspend2's userui */
 
 #define MAX_LINKS 32		
 

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Suspend2][ 04/13] [Suspend2] Follow page routine.
  2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
                   ` (2 preceding siblings ...)
  2006-06-27  4:42 ` [Suspend2][ 03/13] [Suspend2] Add netlink socket numbers Nigel Cunningham
@ 2006-06-27  4:42 ` Nigel Cunningham
  2006-06-27  4:42 ` [Suspend2][ 05/13] [Suspend2] LRU paranoia patch Nigel Cunningham
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:42 UTC (permalink / raw)
  To: linux-kernel

This variant of the follow page routine is used by Suspend2 to find
existing pages that belong to a process without changing anything in the
process.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 mm/memory.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 0ec7bc6..1021043 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -958,6 +958,15 @@ no_page_table:
 	return page;
 }
 
+/*
+ * We want the address of the page for Suspend2 to mark as being in pageset1. 
+ */
+
+struct page *suspend2_follow_page(struct mm_struct *mm, unsigned long address)
+{
+	return follow_page(mm->mmap, address, 0);
+}
+
 int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
 		unsigned long start, int len, int write, int force,
 		struct page **pages, struct vm_area_struct **vmas)

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Suspend2][ 05/13] [Suspend2] LRU paranoia patch.
  2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
                   ` (3 preceding siblings ...)
  2006-06-27  4:42 ` [Suspend2][ 04/13] [Suspend2] Follow page routine Nigel Cunningham
@ 2006-06-27  4:42 ` Nigel Cunningham
  2006-06-27  4:42 ` [Suspend2][ 06/13] [Suspend2] Remove __nosave declarations in power.h Nigel Cunningham
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:42 UTC (permalink / raw)
  To: linux-kernel

Modify the Set/Clear LRU flag macros to also BUG_ON() when freezing is
complete, iff CONFIG_PM_DEBUG is enabled. The LRU is supposed to be static
before the atomic copy is made. This just helps verify that this is
happening.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 include/linux/page-flags.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index d276a4e..1e4d6a5 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -7,6 +7,7 @@
 
 #include <linux/percpu.h>
 #include <linux/cache.h>
+#include <linux/freezer.h> /* For Suspend2 LRU paranoid Set|ClearPageLRU definitions */
 #include <asm/pgtable.h>
 
 /*
@@ -255,9 +256,16 @@ extern void __mod_page_state_offset(unsi
 #define TestClearPageDirty(page) test_and_clear_bit(PG_dirty, &(page)->flags)
 
 #define PageLRU(page)		test_bit(PG_lru, &(page)->flags)
+
+#ifdef CONFIG_PM_DEBUG
 #define SetPageLRU(page)	set_bit(PG_lru, &(page)->flags)
 #define ClearPageLRU(page)	clear_bit(PG_lru, &(page)->flags)
 #define __ClearPageLRU(page)	__clear_bit(PG_lru, &(page)->flags)
+#else
+#define SetPageLRU(page)	do { BUG_ON(test_freezer_state(FREEZING_COMPLETE)); set_bit(PG_lru, &(page)->flags); } while(0)
+#define ClearPageLRU(page)	do { BUG_ON(test_freezer_state(FREEZING_COMPLETE)); clear_bit(PG_lru, &(page)->flags); } while(0)
+#define __ClearPageLRU(page)	do { BUG_ON(test_freezer_state(FREEZING_COMPLETE)); __clear_bit(PG_lru, &(page)->flags); } while(0)
+#endif
 
 #define PageActive(page)	test_bit(PG_active, &(page)->flags)
 #define SetPageActive(page)	set_bit(PG_active, &(page)->flags)

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Suspend2][ 06/13] [Suspend2] Remove __nosave declarations in power.h
  2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
                   ` (4 preceding siblings ...)
  2006-06-27  4:42 ` [Suspend2][ 05/13] [Suspend2] LRU paranoia patch Nigel Cunningham
@ 2006-06-27  4:42 ` Nigel Cunningham
  2006-06-27  4:42 ` [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia Nigel Cunningham
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:42 UTC (permalink / raw)
  To: linux-kernel

Remove __nosave_begin and __nosave_end declarations in kernel/power/power.h
as they conflict with the one in include/linux/suspend2.h.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/power.h |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/kernel/power/power.h b/kernel/power/power.h
index f06f12f..19e05eb 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -35,9 +35,6 @@ static struct subsys_attribute _name##_a
 
 extern struct subsystem power_subsys;
 
-/* References to section boundaries */
-extern const void __nosave_begin, __nosave_end;
-
 extern struct pbe *pagedir_nosave;
 
 /* Preferred image size in bytes (default 500 MB) */

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
  2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
                   ` (5 preceding siblings ...)
  2006-06-27  4:42 ` [Suspend2][ 06/13] [Suspend2] Remove __nosave declarations in power.h Nigel Cunningham
@ 2006-06-27  4:42 ` Nigel Cunningham
  2006-06-27  6:11   ` Nick Piggin
  2006-06-27  6:33   ` Paul Jackson
  2006-06-27  4:42 ` [Suspend2][ 08/13] [Suspend2] Powerpc support (needed?) Nigel Cunningham
                   ` (5 subsequent siblings)
  12 siblings, 2 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:42 UTC (permalink / raw)
  To: linux-kernel

Add paranoia to the page_alloc code to ensure we don't start page reclaim
during suspending.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 mm/page_alloc.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 253a450..838ae19 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -25,6 +25,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/suspend.h>
+#include <linux/freezer.h>
 #include <linux/pagevec.h>
 #include <linux/blkdev.h>
 #include <linux/slab.h>
@@ -37,6 +38,7 @@
 #include <linux/nodemask.h>
 #include <linux/vmalloc.h>
 #include <linux/mempolicy.h>
+#include "../kernel/power/pageflags.h"
 
 #include <asm/tlbflush.h>
 #include <asm/div64.h>
@@ -905,7 +907,8 @@ get_page_from_freelist(gfp_t gfp_mask, u
 			else
 				mark = (*z)->pages_high;
 			if (!zone_watermark_ok(*z, order, mark,
-				    classzone_idx, alloc_flags))
+				    classzone_idx, alloc_flags) &&
+			    likely(!test_freezer_state(FREEZER_ON)))
 				if (!zone_reclaim_mode ||
 				    !zone_reclaim(*z, gfp_mask, order))
 					continue;
@@ -950,10 +953,12 @@ restart:
 	if (page)
 		goto got_pg;
 
-	do {
-		if (cpuset_zone_allowed(*z, gfp_mask|__GFP_HARDWALL))
-			wakeup_kswapd(*z, order);
-	} while (*(++z));
+	if (likely(!test_freezer_state(FREEZER_ON))) {
+		do {
+			if (cpuset_zone_allowed(*z, gfp_mask|__GFP_HARDWALL))
+				wakeup_kswapd(*z, order);
+		} while (*(++z));
+	}
 
 	/*
 	 * OK, we're below the kswapd watermark and have kicked background
@@ -997,6 +1002,7 @@ nofail_alloc:
 			if (page)
 				goto got_pg;
 			if (gfp_mask & __GFP_NOFAIL) {
+				BUG_ON(unlikely(test_freezer_state(FREEZING_COMPLETE)));
 				blk_congestion_wait(WRITE, HZ/50);
 				goto nofail_alloc;
 			}
@@ -1009,6 +1015,8 @@ nofail_alloc:
 		goto nopage;
 
 rebalance:
+	BUG_ON(unlikely(test_freezer_state(FREEZER_ON)));
+
 	cond_resched();
 
 	/* We now go into synchronous reclaim */

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Suspend2][ 08/13] [Suspend2] Powerpc support (needed?)
  2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
                   ` (6 preceding siblings ...)
  2006-06-27  4:42 ` [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia Nigel Cunningham
@ 2006-06-27  4:42 ` Nigel Cunningham
  2006-06-27  4:42 ` [Suspend2][ 09/13] [Suspend2] Reset kswapd_max_order after resume Nigel Cunningham
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:42 UTC (permalink / raw)
  To: linux-kernel

Support for the powerpc. Originally merged as part of the suspend2
arch-specific code. I'm not sure if this is needed now that we use swsusp
code.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 drivers/macintosh/Kconfig     |    4 +
 drivers/macintosh/via-pmu.c   |    7 +++
 include/asm-ppc/cpu_context.h |  110 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 121 insertions(+), 0 deletions(-)

diff --git a/drivers/macintosh/Kconfig b/drivers/macintosh/Kconfig
index 12ad462..504e6a6 100644
--- a/drivers/macintosh/Kconfig
+++ b/drivers/macintosh/Kconfig
@@ -200,4 +200,8 @@ config ANSLCD
 	tristate "Support for ANS LCD display"
 	depends on ADB_CUDA && PPC_PMAC
 
+config SOFTWARE_REPLACE_SLEEP
+	bool "Using Software suspend replace broken sleep function"
+	depends on SUSPEND2
+
 endmenu
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index 0b5ff55..ec8d140 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -2654,6 +2654,13 @@ pmu_ioctl(struct inode * inode, struct f
 			return -EACCES;
 		if (sleep_in_progress)
 			return -EBUSY;
+#ifdef CONFIG_SOFTWARE_REPLACE_SLEEP
+		{
+		extern void suspend2_try_suspend(void);
+		suspend2_try_suspend();
+		return (0);
+		}
+#endif
 		sleep_in_progress = 1;
 		switch (pmu_kind) {
 		case PMU_OHARE_BASED:
diff --git a/include/asm-ppc/cpu_context.h b/include/asm-ppc/cpu_context.h
new file mode 100644
index 0000000..d449094
--- /dev/null
+++ b/include/asm-ppc/cpu_context.h
@@ -0,0 +1,110 @@
+/*
+ * Written by Hu Gang (hugang@soulinfo.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/adb.h>
+#include <linux/pmu.h>
+#include <asm/mmu_context.h>
+
+/* image of the saved processor states */
+struct saved_context {
+	u32 lr, cr, sp, r2;
+	u32 r[20]; /* r12 - r31 */                                                 
+	u32 sprg[4];
+	u32 msr, sdr1, tb1, tb2;
+} __attribute__((packed));
+
+inline static void __save_processor_state(struct saved_context *s)
+{
+	/*asm volatile ("mflr 0; stw 0,%0" : "=m" (s->lr));*/
+	asm volatile ("mfcr 0; stw 0,%0" : "=m" (s->cr));
+	asm volatile ("stw 1,%0" : "=m" (s->sp));
+	asm volatile ("stw 2,%0" : "=m" (s->r2));
+	asm volatile ("stmw 12,%0" : "=m" (s->r));
+
+	/* Save MSR & SDR1 */
+	asm volatile ("mfmsr 4; stw 4,%0" : "=m" (s->msr));
+	asm volatile ("mfsdr1 4; stw 4,%0": "=m" (s->sdr1));
+
+	/* Get a stable timebase and save it */
+	asm volatile ("1:\n"
+		      "mftbu 4;stw 4,%0\n"
+		      "mftb  5;stw 5,%1\n"
+		      "mftbu 3\n"
+		      "cmpw 3,4;\n"
+			  "bne 1b" : 
+			  "=m" (s->tb1),
+			  "=m" (s->tb2));
+		
+	/* Save SPRGs */
+	asm volatile ("mfsprg 4,0; stw 4,%0 " : "=m" (s->sprg[0]));
+	asm volatile ("mfsprg 4,1; stw 4,%0 " : "=m" (s->sprg[1]));
+	asm volatile ("mfsprg 4,2; stw 4,%0 " : "=m" (s->sprg[2]));
+	asm volatile ("mfsprg 4,3; stw 4,%0 " : "=m" (s->sprg[3]));
+}
+
+inline static void __restore_processor_state(struct saved_context *s)
+{
+	/* Restore the BATs, and SDR1 */
+	asm volatile ("lwz 4,%0; mtsdr1 4" : "=m" (s->sdr1));
+	/* asm volatile ("lwz 3,%0" : "=m" (saved_context.msr)); */
+
+	asm volatile ("lwz 4,%0; mtsprg 0,4": "=m" (s->sprg[0]));
+	asm volatile ("lwz 4,%0; mtsprg 1,4": "=m" (s->sprg[1]));
+	asm volatile ("lwz 4,%0; mtsprg 2,4": "=m" (s->sprg[2]));
+	asm volatile ("lwz 4,%0; mtsprg 3,4": "=m" (s->sprg[3]));
+
+	/* Restore TB */
+	asm volatile ("li 3,0; mttbl 3; \n"
+		      "lwz 3,%0\n; lwz 4,%1\n"
+		      "mttbu 3; mttbl 4" :
+		      "=m" (s->tb1),
+		      "=m" (s->tb2));
+
+	/* Restore the callee-saved registers and return */
+	asm volatile ("lmw 12,%0" : "=m" (s->r)); 
+	asm volatile ("lwz 2,%0" : "=m" (s->r2));
+	asm volatile ("lwz 1,%0" : "=m" (s->sp));
+	asm volatile ("lwz 0,%0; mtcr 0" : "=m" (s->cr));
+	
+	/* tell gcc that we clobbered all the registers... 
+	 * otherwise it might keep some addresses there. */
+	asm volatile ("" : : : "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31");
+	/*asm volatile ("lwz 0,%0; mtlr 0" : "=m" (s->lr));*/
+}
+
+static inline void save_context(void)
+{
+#ifdef CONFIG_ADB_PMU
+	printk("pmu suspend\n");
+	pmu_suspend();
+#endif
+}
+
+extern void enable_kernel_altivec(void);
+
+static inline void restore_context(void)
+{
+	printk("set context: <%p>\n", current);
+	set_context(current->active_mm->context,
+			current->active_mm->pgd);
+
+#ifdef CONFIG_ADB_PMU
+	printk("pmu_resume\n");
+	pmu_resume();
+#endif
+
+#ifdef CONFIG_ALTIVEC
+	if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC) {
+		printk("enable altivec\n");
+		enable_kernel_altivec();
+	}
+#endif
+	printk("enable fp\n");
+	enable_kernel_fp();
+}

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Suspend2][ 09/13] [Suspend2] Reset kswapd_max_order after resume.
  2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
                   ` (7 preceding siblings ...)
  2006-06-27  4:42 ` [Suspend2][ 08/13] [Suspend2] Powerpc support (needed?) Nigel Cunningham
@ 2006-06-27  4:42 ` Nigel Cunningham
  2006-06-27  4:43 ` [Suspend2][ 10/13] [Suspend2] Replace swsusp reboot hook Nigel Cunningham
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:42 UTC (permalink / raw)
  To: linux-kernel

Reset the kswapd_max_order value to zero after resume so that we don't get
a swap storm.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 mm/vmscan.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 440a733..b6a5a0d 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1244,7 +1244,8 @@ static int kswapd(void *p)
 	for ( ; ; ) {
 		unsigned long new_order;
 
-		try_to_freeze();
+		if (try_to_freeze())
+			pgdat->kswapd_max_order = 0;
 
 		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
 		new_order = pgdat->kswapd_max_order;

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Suspend2][ 10/13] [Suspend2] Replace swsusp reboot hook.
  2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
                   ` (8 preceding siblings ...)
  2006-06-27  4:42 ` [Suspend2][ 09/13] [Suspend2] Reset kswapd_max_order after resume Nigel Cunningham
@ 2006-06-27  4:43 ` Nigel Cunningham
  2006-06-27  4:43 ` [Suspend2][ 11/13] [Suspend2] snprintf_used function Nigel Cunningham
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:43 UTC (permalink / raw)
  To: linux-kernel

Replace the swsusp reboot hook with one for suspend2.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/sys.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index 0b6ec0e..aaf29e6 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -737,12 +737,12 @@ asmlinkage long sys_reboot(int magic1, i
 		unlock_kernel();
 		return -EINVAL;
 
-#ifdef CONFIG_SOFTWARE_SUSPEND
+#ifdef CONFIG_SUSPEND2
 	case LINUX_REBOOT_CMD_SW_SUSPEND:
 		{
-			int ret = software_suspend();
+			suspend2_try_suspend();
 			unlock_kernel();
-			return ret;
+			return 0;
 		}
 #endif
 

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Suspend2][ 11/13] [Suspend2] snprintf_used function
  2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
                   ` (9 preceding siblings ...)
  2006-06-27  4:43 ` [Suspend2][ 10/13] [Suspend2] Replace swsusp reboot hook Nigel Cunningham
@ 2006-06-27  4:43 ` Nigel Cunningham
  2006-06-27  4:43 ` [Suspend2][ 12/13] [Suspend2] Suspend2 common header Nigel Cunningham
  2006-06-27  4:43 ` [Suspend2][ 13/13] [Suspend2] Suspend2 include file Nigel Cunningham
  12 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:43 UTC (permalink / raw)
  To: linux-kernel

The normal snprintf function tells you how many characters would have been
appended to a buffer if it was large enough. For Suspend2, we want to know
how many characters were actually added. This variant of the routine does
that.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 include/linux/kernel.h |    2 ++
 lib/vsprintf.c         |   23 +++++++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index f4fc576..5e99865 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -108,6 +108,8 @@ extern int vsprintf(char *buf, const cha
 	__attribute__ ((format (printf, 2, 0)));
 extern int snprintf(char * buf, size_t size, const char * fmt, ...)
 	__attribute__ ((format (printf, 3, 4)));
+extern int snprintf_used(char *buffer, int buffer_size,
+		const char *fmt, ...);
 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 	__attribute__ ((format (printf, 3, 0)));
 extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index b07db5c..fccee2c 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -236,6 +236,29 @@ static char * number(char * buf, char * 
 	return buf;
 }
 
+/*
+ * vsnprintf_used
+ *
+ * Functionality    : Print a string with parameters to a buffer of a 
+ *                    limited size. Unlike vsnprintf, we return the number
+ *                    of bytes actually put in the buffer, not the number
+ *                    that would have been put in if it was big enough.
+ */
+int snprintf_used(char *buffer, int buffer_size, const char *fmt, ...)
+{
+	int result;
+	va_list args;
+
+	if (!buffer_size)
+		return 0;
+
+	va_start(args, fmt);
+	result = vsnprintf(buffer, buffer_size, fmt, args);
+	va_end(args);
+
+	return result > buffer_size ? buffer_size : result;
+}
+
 /**
  * vsnprintf - Format a string and place it in a buffer
  * @buf: The buffer to place the result into

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Suspend2][ 12/13] [Suspend2] Suspend2 common header.
  2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
                   ` (10 preceding siblings ...)
  2006-06-27  4:43 ` [Suspend2][ 11/13] [Suspend2] snprintf_used function Nigel Cunningham
@ 2006-06-27  4:43 ` Nigel Cunningham
  2006-06-27  4:43 ` [Suspend2][ 13/13] [Suspend2] Suspend2 include file Nigel Cunningham
  12 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:43 UTC (permalink / raw)
  To: linux-kernel

Declarations used by virtually all of the Suspend2 files, but which are not
needed externally. That is, debugging and result set/clear macros and the
enum for the result codes.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/suspend2_common.h |   45 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/kernel/power/suspend2_common.h b/kernel/power/suspend2_common.h
new file mode 100644
index 0000000..455250e
--- /dev/null
+++ b/kernel/power/suspend2_common.h
@@ -0,0 +1,45 @@
+/*
+ * kernel/power/suspend2_common.h
+ *
+ * Copyright (C) 2005-2006 Nigel Cunningham <nigel@suspend2.net>
+ *
+ * This file is released under the GPLv2.
+ *
+ * Routines for talking to a userspace program that manages storage.
+ *
+ * The kernel side:
+ * - starts the userspace program;
+ * - sends messages telling it when to open and close the connection;
+ * - tells it when to quit;
+ *
+ * The user space side:
+ * - passes messages regarding status;
+ *
+ */
+
+#ifdef CONFIG_PM_DEBUG
+#define set_debug_state(bit) (test_and_set_bit(bit, &suspend_debug_state))
+#define clear_debug_state(bit) (test_and_clear_bit(bit, &suspend_debug_state))
+#else
+#define set_debug_state(bit) (0)
+#define clear_debug_state(bit) (0)
+#endif
+
+#define set_result_state(bit) (test_and_set_bit(bit, &suspend_result))
+#define clear_result_state(bit) (test_and_clear_bit(bit, &suspend_result))
+
+enum {
+	SUSPEND_ABORT_REQUESTED = 1,
+	SUSPEND_NOSTORAGE_AVAILABLE,
+	SUSPEND_INSUFFICIENT_STORAGE,
+	SUSPEND_FREEZING_FAILED,
+	SUSPEND_UNEXPECTED_ALLOC,
+	SUSPEND_KEPT_IMAGE,
+	SUSPEND_WOULD_EAT_MEMORY,
+	SUSPEND_UNABLE_TO_FREE_ENOUGH_MEMORY,
+	SUSPEND_ENCRYPTION_SETUP_FAILED,
+	SUSPEND_PM_SEM,
+};
+
+extern unsigned int nr_suspends;
+extern char resume2_file[256];

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Suspend2][ 13/13] [Suspend2] Suspend2 include file
  2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
                   ` (11 preceding siblings ...)
  2006-06-27  4:43 ` [Suspend2][ 12/13] [Suspend2] Suspend2 common header Nigel Cunningham
@ 2006-06-27  4:43 ` Nigel Cunningham
  12 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  4:43 UTC (permalink / raw)
  To: linux-kernel

Add suspend2 header file.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 include/linux/suspend2.h |  190 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 190 insertions(+), 0 deletions(-)

diff --git a/include/linux/suspend2.h b/include/linux/suspend2.h
new file mode 100644
index 0000000..4f8568b
--- /dev/null
+++ b/include/linux/suspend2.h
@@ -0,0 +1,190 @@
+#ifndef _LINUX_SUSPEND2_H
+#define _LINUX_SUSPEND2_H
+
+#include <linux/dyn_pageflags.h>
+
+/* arch/i386/mm/init.c */
+extern char __nosave_begin, __nosave_end;
+
+#define SECTOR_SIZE 512
+
+/* kernel/power/main.c */
+extern unsigned long suspend_result;
+
+/* kernel/power/process.c */
+extern unsigned long suspend_debug_state;
+
+/* arch/i386/power/suspend2.c */
+extern unsigned long suspend_action;
+extern int suspend_io_time[2][2];
+
+extern dyn_pageflags_t pageset1_map;
+extern dyn_pageflags_t pageset1_copy_map;
+
+#ifdef CONFIG_PM_DEBUG
+#define test_debug_state(bit) (test_bit(bit, &suspend_debug_state))
+#else
+#define test_debug_state(bit) (0)
+#endif
+
+#define test_result_state(bit) (test_bit(bit, &suspend_result))
+
+/* 
+ * First status register - this is suspend's return code.
+ *
+ * All the rest are in kernel/power/suspend2_common.h
+ */
+#define SUSPEND_ABORTED			0
+
+/* Second status register - ditto */
+#define SUSPEND_RETRY_RESUME		0
+
+/* Debug sections  - if debugging compiled in */
+enum {
+	SUSPEND_ANY_SECTION,
+	SUSPEND_EAT_MEMORY,
+	SUSPEND_IO,
+	SUSPEND_HEADER,
+	SUSPEND_WRITER,
+	SUSPEND_MEMORY,
+};
+
+/* debugging levels. */
+#define SUSPEND_STATUS		0
+#define SUSPEND_ERROR		2
+#define SUSPEND_LOW	 	3
+#define SUSPEND_MEDIUM	 	4
+#define SUSPEND_HIGH	  	5
+#define SUSPEND_VERBOSE		6
+
+/* Configuration flags */
+enum {
+	SUSPEND_REBOOT,
+	SUSPEND_PAUSE,
+	SUSPEND_SLOW,
+	SUSPEND_LOGALL,
+	SUSPEND_CAN_CANCEL,
+	SUSPEND_KEEP_IMAGE,
+	SUSPEND_FREEZER_TEST,
+	SUSPEND_SINGLESTEP,
+	SUSPEND_PAUSE_NEAR_PAGESET_END,
+	SUSPEND_TEST_FILTER_SPEED,
+	SUSPEND_TEST_BIO,
+	SUSPEND_NO_PAGESET2,
+};
+
+#ifdef CONFIG_SUSPEND2
+#define test_action_state(bit) (test_bit(bit, &suspend_action))
+#define set_action_state(bit) (test_and_set_bit(bit, &suspend_action))
+#define clear_action_state(bit) (test_and_clear_bit(bit, &suspend_action))
+#else
+#define test_action_state(bit) (0)
+#endif
+
+extern void __suspend_message(unsigned long section, unsigned long level, int log_normally,
+		const char *fmt, ...);
+
+#ifdef CONFIG_PM_DEBUG
+#define suspend_message(sn, lev, log, fmt, a...) \
+do { \
+	if (test_debug_state(sn)) \
+		__suspend_message(sn, lev, log, fmt, ##a); \
+} while(0)
+#else /* CONFIG_PM_DEBUG */
+#define suspend_message(sn, lev, log, fmt, a...) \
+do { \
+	if (lev == 0) \
+		__suspend_message(sn, lev, log, fmt, ##a); \
+} while(0)
+#endif /* CONFIG_PM_DEBUG */
+  
+/* Suspend 2 */
+
+enum {
+	SUSPEND_CAN_SUSPEND,
+	SUSPEND_CAN_RESUME,
+	SUSPEND_RUNNING,
+	SUSPEND_RESUME_DEVICE_OK,
+	SUSPEND_NORESUME_SPECIFIED,
+	SUSPEND_SANITY_CHECK_PROMPT,
+	SUSPEND_PAGESET2_NOT_LOADED,
+	SUSPEND_CONTINUE_REQ,
+	SUSPEND_RESUMED_BEFORE,
+	SUSPEND_RESUME_NOT_DONE,
+	SUSPEND_BOOT_TIME,
+	SUSPEND_NOW_RESUMING,
+	SUSPEND_IGNORE_LOGLEVEL,
+	SUSPEND_TRYING_TO_RESUME,
+	SUSPEND_TRY_RESUME_RD,
+	SUSPEND_IGNORE_ROOTFS,
+};
+
+/* --------------------------------------------------------------------- */
+#ifdef CONFIG_SUSPEND2
+
+/* Used in init dir files */
+extern unsigned long suspend_state;
+
+extern void suspend2_try_resume(void);
+extern int suspend_early_boot_message 
+	(int can_erase_image, int default_answer, char *warning_reason, ...);
+extern unsigned long suspend_update_status (unsigned long value, unsigned long maximum,
+		const char *fmt, ...);
+extern void suspend_prepare_status (int clearbar, const char *fmt, ...);
+
+#define test_suspend_state(bit) \
+	(test_bit(bit, &suspend_state))
+
+#define clear_suspend_state(bit) \
+	(clear_bit(bit, &suspend_state))
+
+#define set_suspend_state(bit) \
+	(set_bit(bit, &suspend_state))
+
+extern void suspend2_try_suspend(void);
+
+/* --------------------------------------------------------------------- */
+#else
+/* --------------------------------------------------------------------- */
+
+#define suspend_state		(0)
+#define clear_suspend_state(bit)	do { } while (0)
+#define test_suspend_state(bit) 	(0)
+#define set_suspend_state(bit)		do { } while(0)
+
+#define suspend2_try_resume()			do { } while(0)
+static inline int suspend_early_boot_message(int a, int b, char *c, ...)	{ return 0; }
+static inline unsigned long suspend_update_status(unsigned long value, unsigned long maximum,
+		const char *fmt, ...)
+{
+	return maximum;
+}
+#define suspend_prepare_status(a, ...)  do { } while(0)
+
+#endif /* CONFIG_SUSPEND2 */
+
+#define test_and_set_suspend_state(bit) \
+	(test_and_set_bit(bit, &suspend_state))
+
+#define get_suspend_state()  (suspend_state)
+
+#define restore_suspend_state(saved_state) \
+	do { suspend_state = saved_state; } while(0)
+	
+#if defined(CONFIG_SUSPEND2) && defined(CONFIG_ACPI)
+#include <acpi/acpi.h>
+static inline int may_try_suspend2(u32 state)
+{
+	if (state == ACPI_STATE_S4) {
+		suspend2_try_suspend();
+		return 1;
+	}
+	return 0;
+}
+#else
+static inline int may_try_suspend2(u32 state)
+{
+	return 0;
+}
+#endif
+#endif /* _LINUX_SUSPEND2_H */

--
Nigel Cunningham		nigel at suspend2 dot net

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
  2006-06-27  4:42 ` [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia Nigel Cunningham
@ 2006-06-27  6:11   ` Nick Piggin
  2006-06-27  6:34     ` Nigel Cunningham
  2006-06-27  6:33   ` Paul Jackson
  1 sibling, 1 reply; 22+ messages in thread
From: Nick Piggin @ 2006-06-27  6:11 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: linux-kernel

Nigel Cunningham wrote:
> Add paranoia to the page_alloc code to ensure we don't start page reclaim
> during suspending.
> 

Nack. Set PF_MEMALLOC if you must.

> Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
> 
>  mm/page_alloc.c |   18 +++++++++++++-----
>  1 files changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 253a450..838ae19 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -25,6 +25,7 @@
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/suspend.h>
> +#include <linux/freezer.h>
>  #include <linux/pagevec.h>
>  #include <linux/blkdev.h>
>  #include <linux/slab.h>
> @@ -37,6 +38,7 @@
>  #include <linux/nodemask.h>
>  #include <linux/vmalloc.h>
>  #include <linux/mempolicy.h>
> +#include "../kernel/power/pageflags.h"
>  
>  #include <asm/tlbflush.h>
>  #include <asm/div64.h>
> @@ -905,7 +907,8 @@ get_page_from_freelist(gfp_t gfp_mask, u
>  			else
>  				mark = (*z)->pages_high;
>  			if (!zone_watermark_ok(*z, order, mark,
> -				    classzone_idx, alloc_flags))
> +				    classzone_idx, alloc_flags) &&
> +			    likely(!test_freezer_state(FREEZER_ON)))
>  				if (!zone_reclaim_mode ||
>  				    !zone_reclaim(*z, gfp_mask, order))
>  					continue;
> @@ -950,10 +953,12 @@ restart:
>  	if (page)
>  		goto got_pg;
>  
> -	do {
> -		if (cpuset_zone_allowed(*z, gfp_mask|__GFP_HARDWALL))
> -			wakeup_kswapd(*z, order);
> -	} while (*(++z));
> +	if (likely(!test_freezer_state(FREEZER_ON))) {
> +		do {
> +			if (cpuset_zone_allowed(*z, gfp_mask|__GFP_HARDWALL))
> +				wakeup_kswapd(*z, order);
> +		} while (*(++z));
> +	}
>  
>  	/*
>  	 * OK, we're below the kswapd watermark and have kicked background
> @@ -997,6 +1002,7 @@ nofail_alloc:
>  			if (page)
>  				goto got_pg;
>  			if (gfp_mask & __GFP_NOFAIL) {
> +				BUG_ON(unlikely(test_freezer_state(FREEZING_COMPLETE)));
>  				blk_congestion_wait(WRITE, HZ/50);
>  				goto nofail_alloc;
>  			}
> @@ -1009,6 +1015,8 @@ nofail_alloc:
>  		goto nopage;
>  
>  rebalance:
> +	BUG_ON(unlikely(test_freezer_state(FREEZER_ON)));
> +
>  	cond_resched();
>  
>  	/* We now go into synchronous reclaim */
> 
> --
> Nigel Cunningham		nigel at suspend2 dot net

-- 
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com 

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
  2006-06-27  4:42 ` [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia Nigel Cunningham
  2006-06-27  6:11   ` Nick Piggin
@ 2006-06-27  6:33   ` Paul Jackson
  2006-06-27  7:01     ` Nigel Cunningham
  1 sibling, 1 reply; 22+ messages in thread
From: Paul Jackson @ 2006-06-27  6:33 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: linux-kernel

Nigel wrote:
-	do {
-		if (cpuset_zone_allowed(*z, gfp_mask|__GFP_HARDWALL))
-			wakeup_kswapd(*z, order);
-	} while (*(++z));
+	if (likely(!test_freezer_state(FREEZER_ON))) {
+		do {
+			if (cpuset_zone_allowed(*z, gfp_mask|__GFP_HARDWALL))
+				wakeup_kswapd(*z, order);
+		} while (*(++z));
+	}


The cpuset_zone_allowed() check above was removed recently, thanks to 
a Chris Wright patch.  So the above patch won't apply to Linus's or
Andrew's current tree.

-- 
                  I won't rest till it's the best ...
                  Programmer, Linux Scalability
                  Paul Jackson <pj@sgi.com> 1.925.600.0401

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
  2006-06-27  6:11   ` Nick Piggin
@ 2006-06-27  6:34     ` Nigel Cunningham
  2006-06-29 16:22       ` Nick Piggin
  0 siblings, 1 reply; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  6:34 UTC (permalink / raw)
  To: Nick Piggin; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 565 bytes --]

Hi.

On Tuesday 27 June 2006 16:11, Nick Piggin wrote:
> Nigel Cunningham wrote:
> > Add paranoia to the page_alloc code to ensure we don't start page reclaim
> > during suspending.
>
> Nack. Set PF_MEMALLOC if you must.

That would work for the thread doing the suspending. What about other kernel 
threads that might run and allocate memory during the cycle because of 
$RANDOM_EVENT? We don't want them triggering memory freeing either.

Regards,

Nigel
-- 
See http://www.suspend2.net for Howtos, FAQs, mailing
lists, wiki and bugzilla info.

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
  2006-06-27  6:33   ` Paul Jackson
@ 2006-06-27  7:01     ` Nigel Cunningham
  0 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27  7:01 UTC (permalink / raw)
  To: Paul Jackson; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 777 bytes --]

Hi.

On Tuesday 27 June 2006 16:33, Paul Jackson wrote:
> Nigel wrote:
> -	do {
> -		if (cpuset_zone_allowed(*z, gfp_mask|__GFP_HARDWALL))
> -			wakeup_kswapd(*z, order);
> -	} while (*(++z));
> +	if (likely(!test_freezer_state(FREEZER_ON))) {
> +		do {
> +			if (cpuset_zone_allowed(*z, gfp_mask|__GFP_HARDWALL))
> +				wakeup_kswapd(*z, order);
> +		} while (*(++z));
> +	}
>
>
> The cpuset_zone_allowed() check above was removed recently, thanks to
> a Chris Wright patch.  So the above patch won't apply to Linus's or
> Andrew's current tree.

This is for 2.6.17. I'm just about to update my git tree. Sorry - forever 
playing catchup :)

Regards,

Nigel
-- 
See http://www.suspend2.net for Howtos, FAQs, mailing
lists, wiki and bugzilla info.

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
  2006-06-27  6:34     ` Nigel Cunningham
@ 2006-06-29 16:22       ` Nick Piggin
  2006-06-29 22:15         ` Nigel Cunningham
  2006-07-04 10:54         ` Nigel Cunningham
  0 siblings, 2 replies; 22+ messages in thread
From: Nick Piggin @ 2006-06-29 16:22 UTC (permalink / raw)
  To: nigel; +Cc: linux-kernel

Nigel Cunningham wrote:
> Hi.
> 
> On Tuesday 27 June 2006 16:11, Nick Piggin wrote:
> 
>>Nigel Cunningham wrote:
>>
>>>Add paranoia to the page_alloc code to ensure we don't start page reclaim
>>>during suspending.
>>
>>Nack. Set PF_MEMALLOC if you must.
> 
> 
> That would work for the thread doing the suspending. What about other kernel 
> threads that might run and allocate memory during the cycle because of 
> $RANDOM_EVENT? We don't want them triggering memory freeing either.

Haven't you suspended the other threads at this point?

What are the consequences of allocating memory?

-- 
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com 

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
  2006-06-29 16:22       ` Nick Piggin
@ 2006-06-29 22:15         ` Nigel Cunningham
  2006-07-04 10:54         ` Nigel Cunningham
  1 sibling, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-29 22:15 UTC (permalink / raw)
  To: Nick Piggin; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1510 bytes --]

Hi Nick.

On Friday 30 June 2006 02:22, Nick Piggin wrote:
> Nigel Cunningham wrote:
> > Hi.
> >
> > On Tuesday 27 June 2006 16:11, Nick Piggin wrote:
> >>Nigel Cunningham wrote:
> >>>Add paranoia to the page_alloc code to ensure we don't start page
> >>> reclaim during suspending.
> >>
> >>Nack. Set PF_MEMALLOC if you must.
> >
> > That would work for the thread doing the suspending. What about other
> > kernel threads that might run and allocate memory during the cycle
> > because of $RANDOM_EVENT? We don't want them triggering memory freeing
> > either.
>
> Haven't you suspended the other threads at this point?

Userspace is frozen, but kernel threads are still running. I'm therefore 
thinking of allocation of memory by drivers while we're writing the first 
part of the image (prior to the atomic copy).

> What are the consequences of allocating memory?

My concern isn't with them allocating any memory, but with the memory 
allocation routines trying to enter the vmscan.c routines to free memory. 
This would almost certainly free some of the LRU pages we're saving 
separately prior to the atomic copy, resulting in an inconsistent image and 
crashes and/or on disk corruption post resume. I've recently seen Rafael's 
code to take pages off the LRU, and realise that may be a better solution, 
but am not sure what adverse side effects it has.

Regards,

Nigel
-- 
See http://www.suspend2.net for Howtos, FAQs, mailing
lists, wiki and bugzilla info.

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
  2006-06-29 16:22       ` Nick Piggin
  2006-06-29 22:15         ` Nigel Cunningham
@ 2006-07-04 10:54         ` Nigel Cunningham
  2006-07-04 16:53           ` Nick Piggin
  1 sibling, 1 reply; 22+ messages in thread
From: Nigel Cunningham @ 2006-07-04 10:54 UTC (permalink / raw)
  To: Nick Piggin; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 852 bytes --]

Hi Nick.

On Friday 30 June 2006 02:22, Nick Piggin wrote:
> Nigel Cunningham wrote:
> > Hi.
> >
> > On Tuesday 27 June 2006 16:11, Nick Piggin wrote:
> >>Nigel Cunningham wrote:
> >>>Add paranoia to the page_alloc code to ensure we don't start page
> >>> reclaim during suspending.
> >>
> >>Nack. Set PF_MEMALLOC if you must.
> >
> > That would work for the thread doing the suspending. What about other
> > kernel threads that might run and allocate memory during the cycle
> > because of $RANDOM_EVENT? We don't want them triggering memory freeing
> > either.
>
> Haven't you suspended the other threads at this point?
>
> What are the consequences of allocating memory?

Did you see my reply to these questions?

Regards,

Nigel
-- 
See http://www.suspend2.net for Howtos, FAQs, mailing
lists, wiki and bugzilla info.

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
  2006-07-04 10:54         ` Nigel Cunningham
@ 2006-07-04 16:53           ` Nick Piggin
  0 siblings, 0 replies; 22+ messages in thread
From: Nick Piggin @ 2006-07-04 16:53 UTC (permalink / raw)
  To: nigel; +Cc: linux-kernel

Nigel Cunningham wrote:

>>Haven't you suspended the other threads at this point?
>>
>>What are the consequences of allocating memory?
> 
> 
> Did you see my reply to these questions?

Hi Nigel,

Yes I did, sorry I thought I replied but it seems not.

I do think taking the pages off the LRU, or otherwise pinning
them on it does sound like a better approach.

-- 
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com 

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2006-07-04 17:26 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-27  4:42 [Suspend2][ 00/13] Miscellaneous patches Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 01/13] [Suspend2] Suspend2 version header Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 02/13] [Suspend2] Boot time hooks Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 03/13] [Suspend2] Add netlink socket numbers Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 04/13] [Suspend2] Follow page routine Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 05/13] [Suspend2] LRU paranoia patch Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 06/13] [Suspend2] Remove __nosave declarations in power.h Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia Nigel Cunningham
2006-06-27  6:11   ` Nick Piggin
2006-06-27  6:34     ` Nigel Cunningham
2006-06-29 16:22       ` Nick Piggin
2006-06-29 22:15         ` Nigel Cunningham
2006-07-04 10:54         ` Nigel Cunningham
2006-07-04 16:53           ` Nick Piggin
2006-06-27  6:33   ` Paul Jackson
2006-06-27  7:01     ` Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 08/13] [Suspend2] Powerpc support (needed?) Nigel Cunningham
2006-06-27  4:42 ` [Suspend2][ 09/13] [Suspend2] Reset kswapd_max_order after resume Nigel Cunningham
2006-06-27  4:43 ` [Suspend2][ 10/13] [Suspend2] Replace swsusp reboot hook Nigel Cunningham
2006-06-27  4:43 ` [Suspend2][ 11/13] [Suspend2] snprintf_used function Nigel Cunningham
2006-06-27  4:43 ` [Suspend2][ 12/13] [Suspend2] Suspend2 common header Nigel Cunningham
2006-06-27  4:43 ` [Suspend2][ 13/13] [Suspend2] Suspend2 include file Nigel Cunningham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox