Thaw userspace and kernel space separately.
Subsystems (3)
PATCH 1/1 Thaw userspace and kernel space separately.
Modify process thawing so that we can thaw kernel space without thawing userspace, and thaw kernelspace first. This will be useful in later patches, where I intend to get swsusp thawing kernel threads only before seeking to free memory.
include/linux/freezer.h +8 -1
@@ -1,5 +1,8 @@/* Freezer declarations */ +#define FREEZER_KERNEL_THREADS 0 +#define FREEZER_ALL_THREADS 1 +#ifdef CONFIG_PM /* * Check if a process has been frozen
@@ -57,7 +60,8 @@ static inline void frozen_process(structextern void refrigerator (void );extern int freeze_processes (void ); -extern void thaw_processes (void ); +#define thaw_processes () do { thaw_some_processes(FREEZER_ALL_THREADS); } while(0) +#define thaw_kernel_threads () do { thaw_some_processes(FREEZER_KERNEL_THREADS); } while(0)static inline int try_to_freeze (void ) {
@@ -67,6 +71,9 @@ static inline int try_to_freeze(void) } elsereturn 0 ; } + +extern void thaw_some_processes (int all); +#else static inline int frozen (struct task_struct *p) {return 0 ; }static inline int freezing (struct task_struct *p) {return 0 ; }
kernel/power/process.c +18 -7
@@ -153,18 +153,29 @@ int freeze_processes(void)return 0 ; } -void thaw_processes (void ) +void thaw_some_processes (int all) {struct task_struct *g, *p; +int pass =0 ;/* Pass 0 = Kernel space, 1 = Userspace */ printk ("Restarting tasks... " );read_lock (&tasklist_lock); - do_each_thread(g, p) { -if (!freezeable (p)) -continue ; -if (!thaw_process (p)) -printk (KERN_INFO "Strange, %s not stopped\n" , p->comm); - }while_each_thread (g, p); +do { + do_each_thread(g, p) { +/* +* is_user = 0 if kernel thread or borrowed mm, +* 1 otherwise. +*/ +int is_user = !!(p->mm && !(p->flags &PF_BORROWED_MM )); +if (!freezeable (p) || (is_user != pass)) +continue ; +if (!thaw_process (p)) +printk (KERN_INFO +"Strange, %s not stopped\n" , p->comm ); + }while_each_thread (g, p); + + pass++; + }while (pass <2 && all);read_unlock (&tasklist_lock);schedule ();
Quoted 4 lines · Nigel Cunningham
Modify process thawing so that we can thaw kernel space without thawing userspace, and thaw kernelspace first. This will be useful in later patches, where I intend to get swsusp thawing kernel threads only before seeking to free memory.
Please explain why you think it will be necessary/useful.
I remember a discussion about it some time ago that didn't indicate we would need/want to do this.
Greetings,
Rafael
Signature · 2 lines
You never change things by fighting the existing reality. R. Buckminster Fuller
Hi.
Quoted 10 lines · Rafael J. Wysocki
Quoted 4 lines · Nigel Cunningham
Modify process thawing so that we can thaw kernel space without thawing userspace, and thaw kernelspace first. This will be useful in later patches, where I intend to get swsusp thawing kernel threads only before seeking to free memory.
Please explain why you think it will be necessary/useful.
I remember a discussion about it some time ago that didn't indicate we would need/want to do this.
This is needed to make suspending faster and more reliable when the system is in a low memory situation. Imagine that you have a number of processes trying to allocate memory at the time you're trying to suspend. They want so much memory that when you come to prepare the image, you find that you need to free pages. But your swapfile is on ext3, and you've just frozen all processes, so any attempt to free memory could result in a deadlock while the vm tries to swap out pages using the frozen kjournald. So you need to thaw processes to free the memory. But thawing processes will start the processes allocating memory again, so you'll be fighting an uphill battle.
If you can only thaw the kernel threads, you can free memory without restarting userspace or deadlocking against a frozen kjournald.
Regards,
Nigel
Quoted 14 lines · Nigel Cunningham
Hi.
Quoted 10 lines · Rafael J. Wysocki
Quoted 4 lines · Nigel Cunningham
Modify process thawing so that we can thaw kernel space without thawing userspace, and thaw kernelspace first. This will be useful in later patches, where I intend to get swsusp thawing kernel threads only before seeking to free memory.
Please explain why you think it will be necessary/useful.
I remember a discussion about it some time ago that didn't indicate we would need/want to do this.
Quoted 8 lines
This is needed to make suspending faster and more reliable when the system is in a low memory situation. Imagine that you have a number of processes trying to allocate memory at the time you're trying to suspend. They want so much memory that when you come to prepare the image, you find that you need to free pages. But your swapfile is on ext3, and you've just frozen all processes, so any attempt to free memory could result in a deadlock while the vm tries to swap out pages using the frozen kjournald.
This is not true, sorry.
Swapfiles are handled at the block device level. The filesystem is only needed when you run swapon, to create swap extents that are used later to handle the swap file.
Greetings,
Rafael
Signature · 2 lines
You never change things by fighting the existing reality. R. Buckminster Fuller
Hi!
Quoted 6 lines
Modify process thawing so that we can thaw kernel space without thawing userspace, and thaw kernelspace first. This will be useful in later patches, where I intend to get swsusp thawing kernel threads only before seeking to free memory.
Signed-off-by Nigel Cunningham <[email protected]>
NAK. "May be useful in future" is not good reason to merge it now. (If you did not want it merged, just mark it so).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 26 lines · On Mon, 23 Oct 2006 22:00:11 +1000 Nigel Cunningham…
Hi.
Quoted 10 lines · Rafael J. Wysocki
Quoted 4 lines · Nigel Cunningham
Modify process thawing so that we can thaw kernel space without thawing userspace, and thaw kernelspace first. This will be useful in later patches, where I intend to get swsusp thawing kernel threads only before seeking to free memory.
Please explain why you think it will be necessary/useful.
I remember a discussion about it some time ago that didn't indicate we would need/want to do this.
This is needed to make suspending faster and more reliable when the system is in a low memory situation. Imagine that you have a number of processes trying to allocate memory at the time you're trying to suspend. They want so much memory that when you come to prepare the image, you find that you need to free pages. But your swapfile is on ext3, and you've just frozen all processes, so any attempt to free memory could result in a deadlock while the vm tries to swap out pages using the frozen kjournald. So you need to thaw processes to free the memory. But thawing processes will start the processes allocating memory again, so you'll be fighting an uphill battle.
Quoted 3 lines
If you can only thaw the kernel threads, you can free memory without restarting userspace or deadlocking against a frozen kjournald.
kjournald will not participate in writing to swapfiles.
The situation where we would need this feature is where the loop driver is involved in the path-to-disk. But I doubt if that's a thing we'd want to support.
otoh there may be other kernel threads which are a saner thing to have in the swapout path and which we do want to support. md_thread, perhaps?
Quoted 30 lines · Andrew Morton
Quoted 26 lines · On Mon, 23 Oct 2006 22:00:11 +1000 Nigel Cunningham…
Hi.
Quoted 10 lines · Rafael J. Wysocki
Quoted 4 lines · Nigel Cunningham
Modify process thawing so that we can thaw kernel space without thawing userspace, and thaw kernelspace first. This will be useful in later patches, where I intend to get swsusp thawing kernel threads only before seeking to free memory.
Please explain why you think it will be necessary/useful.
I remember a discussion about it some time ago that didn't indicate we would need/want to do this.
This is needed to make suspending faster and more reliable when the system is in a low memory situation. Imagine that you have a number of processes trying to allocate memory at the time you're trying to suspend. They want so much memory that when you come to prepare the image, you find that you need to free pages. But your swapfile is on ext3, and you've just frozen all processes, so any attempt to free memory could result in a deadlock while the vm tries to swap out pages using the frozen kjournald. So you need to thaw processes to free the memory. But thawing processes will start the processes allocating memory again, so you'll be fighting an uphill battle.
Quoted 3 lines
If you can only thaw the kernel threads, you can free memory without restarting userspace or deadlocking against a frozen kjournald.
Quoted 8 lines
kjournald will not participate in writing to swapfiles.
The situation where we would need this feature is where the loop driver is involved in the path-to-disk. But I doubt if that's a thing we'd want to support.
otoh there may be other kernel threads which are a saner thing to have in the swapout path and which we do want to support.
md_thread, perhaps?
md_thread needs some consideration I think. Having a swapfile on RAID is a legit thing and we should support that.
Signature · 2 lines
You never change things by fighting the existing reality. R. Buckminster Fuller
Quoted 10 lines · Andrew Morton
Quoted 4 lines · On Mon, 23 Oct 2006 22:00:11 +1000 Nigel Cunningham…
If you can only thaw the kernel threads, you can free memory without restarting userspace or deadlocking against a frozen kjournald.
kjournald will not participate in writing to swapfiles.
The situation where we would need this feature is where the loop driver is involved in the path-to-disk. But I doubt if that's a thing we'd want to support.
dm-crypt? that seems like a very important thing to support for suspend to disk.
-dean
Quoted 11 lines · Pavel Machek
Hi!
Quoted 6 lines
Modify process thawing so that we can thaw kernel space without thawing userspace, and thaw kernelspace first. This will be useful in later patches, where I intend to get swsusp thawing kernel threads only before seeking to free memory.
Signed-off-by Nigel Cunningham <[email protected]>NAK. "May be useful in future" is not good reason to merge it now. (If you did not want it merged, just mark it so).
I hope Nigel will keep working at it, since low memory machines like old laptops would benefit from suspend are a reality. It can be kept as a separate patch somewhere, like suspend2, which people can patch in to enhance the example code currently in the kernel.
Signature · 5 lines
Bill Davidsen <[email protected]> Obscure bug of 2004: BASH BUFFER OVERFLOW - if bash is being run by a normal user and is setuid root, with the "vi" line edit mode selected, and the character set is "big5," an off-by-one errors occurs during wildcard (glob) expansion.