public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Move swap functions to kernel/power/swap.c.
@ 2009-09-28  4:09 Nigel Cunningham
  2009-09-29 20:24 ` Rafael J. Wysocki
  2009-10-02  3:52 ` Pavel Machek
  0 siblings, 2 replies; 5+ messages in thread
From: Nigel Cunningham @ 2009-09-28  4:09 UTC (permalink / raw)
  To: Rafael Wysocki, linux-pm, LKML

Move hibernation code's functions for allocating and freeing swap
from swsusp.c to swap.c, which is where you'd expect to find them.

Signed-off-by: Nigel Cunningham <nigel@tuxonice.net>
---
 kernel/power/swap.c   |  101 +++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/power/swsusp.c |  101 -------------------------------------------------
 2 files changed, 101 insertions(+), 101 deletions(-)

diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 8ba052c..ce2d8a7 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -39,6 +39,107 @@ struct swsusp_header {
 
 static struct swsusp_header *swsusp_header;
 
+/**
+ *	The following functions are used for tracing the allocated
+ *	swap pages, so that they can be freed in case of an error.
+ */
+
+struct swsusp_extent {
+	struct rb_node node;
+	unsigned long start;
+	unsigned long end;
+};
+
+static struct rb_root swsusp_extents = RB_ROOT;
+
+static int swsusp_extents_insert(unsigned long swap_offset)
+{
+	struct rb_node **new = &(swsusp_extents.rb_node);
+	struct rb_node *parent = NULL;
+	struct swsusp_extent *ext;
+
+	/* Figure out where to put the new node */
+	while (*new) {
+		ext = container_of(*new, struct swsusp_extent, node);
+		parent = *new;
+		if (swap_offset < ext->start) {
+			/* Try to merge */
+			if (swap_offset == ext->start - 1) {
+				ext->start--;
+				return 0;
+			}
+			new = &((*new)->rb_left);
+		} else if (swap_offset > ext->end) {
+			/* Try to merge */
+			if (swap_offset == ext->end + 1) {
+				ext->end++;
+				return 0;
+			}
+			new = &((*new)->rb_right);
+		} else {
+			/* It already is in the tree */
+			return -EINVAL;
+		}
+	}
+	/* Add the new node and rebalance the tree. */
+	ext = kzalloc(sizeof(struct swsusp_extent), GFP_KERNEL);
+	if (!ext)
+		return -ENOMEM;
+
+	ext->start = swap_offset;
+	ext->end = swap_offset;
+	rb_link_node(&ext->node, parent, new);
+	rb_insert_color(&ext->node, &swsusp_extents);
+	return 0;
+}
+
+/**
+ *	alloc_swapdev_block - allocate a swap page and register that it has
+ *	been allocated, so that it can be freed in case of an error.
+ */
+
+sector_t alloc_swapdev_block(int swap)
+{
+	unsigned long offset;
+
+	offset = swp_offset(get_swap_page_of_type(swap));
+	if (offset) {
+		if (swsusp_extents_insert(offset))
+			swap_free(swp_entry(swap, offset));
+		else
+			return swapdev_block(swap, offset);
+	}
+	return 0;
+}
+
+/**
+ *	free_all_swap_pages - free swap pages allocated for saving image data.
+ *	It also frees the extents used to register which swap entres had been
+ *	allocated.
+ */
+
+void free_all_swap_pages(int swap)
+{
+	struct rb_node *node;
+
+	while ((node = swsusp_extents.rb_node)) {
+		struct swsusp_extent *ext;
+		unsigned long offset;
+
+		ext = container_of(node, struct swsusp_extent, node);
+		rb_erase(node, &swsusp_extents);
+		for (offset = ext->start; offset <= ext->end; offset++)
+			swap_free(swp_entry(swap, offset));
+
+		kfree(ext);
+	}
+}
+
+int swsusp_swap_in_use(void)
+{
+	return (swsusp_extents.rb_node != NULL);
+}
+
 /*
  * General things
  */
diff --git a/kernel/power/swsusp.c b/kernel/power/swsusp.c
index 6a07f4d..57222d2 100644
--- a/kernel/power/swsusp.c
+++ b/kernel/power/swsusp.c
@@ -58,107 +58,6 @@
 int in_suspend __nosavedata = 0;
 
 /**
- *	The following functions are used for tracing the allocated
- *	swap pages, so that they can be freed in case of an error.
- */
-
-struct swsusp_extent {
-	struct rb_node node;
-	unsigned long start;
-	unsigned long end;
-};
-
-static struct rb_root swsusp_extents = RB_ROOT;
-
-static int swsusp_extents_insert(unsigned long swap_offset)
-{
-	struct rb_node **new = &(swsusp_extents.rb_node);
-	struct rb_node *parent = NULL;
-	struct swsusp_extent *ext;
-
-	/* Figure out where to put the new node */
-	while (*new) {
-		ext = container_of(*new, struct swsusp_extent, node);
-		parent = *new;
-		if (swap_offset < ext->start) {
-			/* Try to merge */
-			if (swap_offset == ext->start - 1) {
-				ext->start--;
-				return 0;
-			}
-			new = &((*new)->rb_left);
-		} else if (swap_offset > ext->end) {
-			/* Try to merge */
-			if (swap_offset == ext->end + 1) {
-				ext->end++;
-				return 0;
-			}
-			new = &((*new)->rb_right);
-		} else {
-			/* It already is in the tree */
-			return -EINVAL;
-		}
-	}
-	/* Add the new node and rebalance the tree. */
-	ext = kzalloc(sizeof(struct swsusp_extent), GFP_KERNEL);
-	if (!ext)
-		return -ENOMEM;
-
-	ext->start = swap_offset;
-	ext->end = swap_offset;
-	rb_link_node(&ext->node, parent, new);
-	rb_insert_color(&ext->node, &swsusp_extents);
-	return 0;
-}
-
-/**
- *	alloc_swapdev_block - allocate a swap page and register that it has
- *	been allocated, so that it can be freed in case of an error.
- */
-
-sector_t alloc_swapdev_block(int swap)
-{
-	unsigned long offset;
-
-	offset = swp_offset(get_swap_page_of_type(swap));
-	if (offset) {
-		if (swsusp_extents_insert(offset))
-			swap_free(swp_entry(swap, offset));
-		else
-			return swapdev_block(swap, offset);
-	}
-	return 0;
-}
-
-/**
- *	free_all_swap_pages - free swap pages allocated for saving image data.
- *	It also frees the extents used to register which swap entres had been
- *	allocated.
- */
-
-void free_all_swap_pages(int swap)
-{
-	struct rb_node *node;
-
-	while ((node = swsusp_extents.rb_node)) {
-		struct swsusp_extent *ext;
-		unsigned long offset;
-
-		ext = container_of(node, struct swsusp_extent, node);
-		rb_erase(node, &swsusp_extents);
-		for (offset = ext->start; offset <= ext->end; offset++)
-			swap_free(swp_entry(swap, offset));
-
-		kfree(ext);
-	}
-}
-
-int swsusp_swap_in_use(void)
-{
-	return (swsusp_extents.rb_node != NULL);
-}
-
-/**
  *	swsusp_show_speed - print the time elapsed between two events represented by
  *	@start and @stop
  *
-- 
1.6.3.3


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

* Re: [PATCH 1/2] Move swap functions to kernel/power/swap.c.
  2009-09-28  4:09 [PATCH 1/2] Move swap functions to kernel/power/swap.c Nigel Cunningham
@ 2009-09-29 20:24 ` Rafael J. Wysocki
  2009-10-01  1:28   ` [linux-pm] " Nigel Cunningham
  2009-10-02  3:52 ` Pavel Machek
  1 sibling, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2009-09-29 20:24 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: linux-pm, LKML

On Monday 28 September 2009, Nigel Cunningham wrote:
> Move hibernation code's functions for allocating and freeing swap
> from swsusp.c to swap.c, which is where you'd expect to find them.

Sorry for the delay.

Both patches look good, I'm going to add them to suspend-2.6/linux-next
in the next few days.

Thanks,
Rafael


> Signed-off-by: Nigel Cunningham <nigel@tuxonice.net>
> ---
>  kernel/power/swap.c   |  101 +++++++++++++++++++++++++++++++++++++++++++++++++
>  kernel/power/swsusp.c |  101 -------------------------------------------------
>  2 files changed, 101 insertions(+), 101 deletions(-)
> 
> diff --git a/kernel/power/swap.c b/kernel/power/swap.c
> index 8ba052c..ce2d8a7 100644
> --- a/kernel/power/swap.c
> +++ b/kernel/power/swap.c
> @@ -39,6 +39,107 @@ struct swsusp_header {
>  
>  static struct swsusp_header *swsusp_header;
>  
> +/**
> + *	The following functions are used for tracing the allocated
> + *	swap pages, so that they can be freed in case of an error.
> + */
> +
> +struct swsusp_extent {
> +	struct rb_node node;
> +	unsigned long start;
> +	unsigned long end;
> +};
> +
> +static struct rb_root swsusp_extents = RB_ROOT;
> +
> +static int swsusp_extents_insert(unsigned long swap_offset)
> +{
> +	struct rb_node **new = &(swsusp_extents.rb_node);
> +	struct rb_node *parent = NULL;
> +	struct swsusp_extent *ext;
> +
> +	/* Figure out where to put the new node */
> +	while (*new) {
> +		ext = container_of(*new, struct swsusp_extent, node);
> +		parent = *new;
> +		if (swap_offset < ext->start) {
> +			/* Try to merge */
> +			if (swap_offset == ext->start - 1) {
> +				ext->start--;
> +				return 0;
> +			}
> +			new = &((*new)->rb_left);
> +		} else if (swap_offset > ext->end) {
> +			/* Try to merge */
> +			if (swap_offset == ext->end + 1) {
> +				ext->end++;
> +				return 0;
> +			}
> +			new = &((*new)->rb_right);
> +		} else {
> +			/* It already is in the tree */
> +			return -EINVAL;
> +		}
> +	}
> +	/* Add the new node and rebalance the tree. */
> +	ext = kzalloc(sizeof(struct swsusp_extent), GFP_KERNEL);
> +	if (!ext)
> +		return -ENOMEM;
> +
> +	ext->start = swap_offset;
> +	ext->end = swap_offset;
> +	rb_link_node(&ext->node, parent, new);
> +	rb_insert_color(&ext->node, &swsusp_extents);
> +	return 0;
> +}
> +
> +/**
> + *	alloc_swapdev_block - allocate a swap page and register that it has
> + *	been allocated, so that it can be freed in case of an error.
> + */
> +
> +sector_t alloc_swapdev_block(int swap)
> +{
> +	unsigned long offset;
> +
> +	offset = swp_offset(get_swap_page_of_type(swap));
> +	if (offset) {
> +		if (swsusp_extents_insert(offset))
> +			swap_free(swp_entry(swap, offset));
> +		else
> +			return swapdev_block(swap, offset);
> +	}
> +	return 0;
> +}
> +
> +/**
> + *	free_all_swap_pages - free swap pages allocated for saving image data.
> + *	It also frees the extents used to register which swap entres had been
> + *	allocated.
> + */
> +
> +void free_all_swap_pages(int swap)
> +{
> +	struct rb_node *node;
> +
> +	while ((node = swsusp_extents.rb_node)) {
> +		struct swsusp_extent *ext;
> +		unsigned long offset;
> +
> +		ext = container_of(node, struct swsusp_extent, node);
> +		rb_erase(node, &swsusp_extents);
> +		for (offset = ext->start; offset <= ext->end; offset++)
> +			swap_free(swp_entry(swap, offset));
> +
> +		kfree(ext);
> +	}
> +}
> +
> +int swsusp_swap_in_use(void)
> +{
> +	return (swsusp_extents.rb_node != NULL);
> +}
> +
>  /*
>   * General things
>   */
> diff --git a/kernel/power/swsusp.c b/kernel/power/swsusp.c
> index 6a07f4d..57222d2 100644
> --- a/kernel/power/swsusp.c
> +++ b/kernel/power/swsusp.c
> @@ -58,107 +58,6 @@
>  int in_suspend __nosavedata = 0;
>  
>  /**
> - *	The following functions are used for tracing the allocated
> - *	swap pages, so that they can be freed in case of an error.
> - */
> -
> -struct swsusp_extent {
> -	struct rb_node node;
> -	unsigned long start;
> -	unsigned long end;
> -};
> -
> -static struct rb_root swsusp_extents = RB_ROOT;
> -
> -static int swsusp_extents_insert(unsigned long swap_offset)
> -{
> -	struct rb_node **new = &(swsusp_extents.rb_node);
> -	struct rb_node *parent = NULL;
> -	struct swsusp_extent *ext;
> -
> -	/* Figure out where to put the new node */
> -	while (*new) {
> -		ext = container_of(*new, struct swsusp_extent, node);
> -		parent = *new;
> -		if (swap_offset < ext->start) {
> -			/* Try to merge */
> -			if (swap_offset == ext->start - 1) {
> -				ext->start--;
> -				return 0;
> -			}
> -			new = &((*new)->rb_left);
> -		} else if (swap_offset > ext->end) {
> -			/* Try to merge */
> -			if (swap_offset == ext->end + 1) {
> -				ext->end++;
> -				return 0;
> -			}
> -			new = &((*new)->rb_right);
> -		} else {
> -			/* It already is in the tree */
> -			return -EINVAL;
> -		}
> -	}
> -	/* Add the new node and rebalance the tree. */
> -	ext = kzalloc(sizeof(struct swsusp_extent), GFP_KERNEL);
> -	if (!ext)
> -		return -ENOMEM;
> -
> -	ext->start = swap_offset;
> -	ext->end = swap_offset;
> -	rb_link_node(&ext->node, parent, new);
> -	rb_insert_color(&ext->node, &swsusp_extents);
> -	return 0;
> -}
> -
> -/**
> - *	alloc_swapdev_block - allocate a swap page and register that it has
> - *	been allocated, so that it can be freed in case of an error.
> - */
> -
> -sector_t alloc_swapdev_block(int swap)
> -{
> -	unsigned long offset;
> -
> -	offset = swp_offset(get_swap_page_of_type(swap));
> -	if (offset) {
> -		if (swsusp_extents_insert(offset))
> -			swap_free(swp_entry(swap, offset));
> -		else
> -			return swapdev_block(swap, offset);
> -	}
> -	return 0;
> -}
> -
> -/**
> - *	free_all_swap_pages - free swap pages allocated for saving image data.
> - *	It also frees the extents used to register which swap entres had been
> - *	allocated.
> - */
> -
> -void free_all_swap_pages(int swap)
> -{
> -	struct rb_node *node;
> -
> -	while ((node = swsusp_extents.rb_node)) {
> -		struct swsusp_extent *ext;
> -		unsigned long offset;
> -
> -		ext = container_of(node, struct swsusp_extent, node);
> -		rb_erase(node, &swsusp_extents);
> -		for (offset = ext->start; offset <= ext->end; offset++)
> -			swap_free(swp_entry(swap, offset));
> -
> -		kfree(ext);
> -	}
> -}
> -
> -int swsusp_swap_in_use(void)
> -{
> -	return (swsusp_extents.rb_node != NULL);
> -}
> -
> -/**
>   *	swsusp_show_speed - print the time elapsed between two events represented by
>   *	@start and @stop
>   *
> 


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

* Re: [linux-pm] [PATCH 1/2] Move swap functions to kernel/power/swap.c.
  2009-09-29 20:24 ` Rafael J. Wysocki
@ 2009-10-01  1:28   ` Nigel Cunningham
  2009-10-01 20:53     ` Rafael J. Wysocki
  0 siblings, 1 reply; 5+ messages in thread
From: Nigel Cunningham @ 2009-10-01  1:28 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: linux-pm, LKML

Hi.

Rafael J. Wysocki wrote:
> On Monday 28 September 2009, Nigel Cunningham wrote:
>> Move hibernation code's functions for allocating and freeing swap
>> from swsusp.c to swap.c, which is where you'd expect to find them.
> 
> Sorry for the delay.
> 
> Both patches look good, I'm going to add them to suspend-2.6/linux-next
> in the next few days.

Okay; thanks.

I have another patch for allocating the swap prior to starting to write 
the image (working towards removing the index pages and then adding 
readahead & compression). I know the preallocation patch works, but want 
to do a little more testing (make sure it's always calculating correctly 
how many pages are needed) before I send it.

Regards,

Nigel

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

* Re: [linux-pm] [PATCH 1/2] Move swap functions  to kernel/power/swap.c.
  2009-10-01  1:28   ` [linux-pm] " Nigel Cunningham
@ 2009-10-01 20:53     ` Rafael J. Wysocki
  0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2009-10-01 20:53 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: linux-pm, LKML

On Thursday 01 October 2009, Nigel Cunningham wrote:
> Hi.
> 
> Rafael J. Wysocki wrote:
> > On Monday 28 September 2009, Nigel Cunningham wrote:
> >> Move hibernation code's functions for allocating and freeing swap
> >> from swsusp.c to swap.c, which is where you'd expect to find them.
> > 
> > Sorry for the delay.
> > 
> > Both patches look good, I'm going to add them to suspend-2.6/linux-next
> > in the next few days.
> 
> Okay; thanks.
> 
> I have another patch for allocating the swap prior to starting to write 
> the image (working towards removing the index pages and then adding 
> readahead & compression). I know the preallocation patch works, but want 
> to do a little more testing (make sure it's always calculating correctly 
> how many pages are needed) before I send it.

Fine by me.

Thanks,
Rafael

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

* Re: [PATCH 1/2] Move swap functions to kernel/power/swap.c.
  2009-09-28  4:09 [PATCH 1/2] Move swap functions to kernel/power/swap.c Nigel Cunningham
  2009-09-29 20:24 ` Rafael J. Wysocki
@ 2009-10-02  3:52 ` Pavel Machek
  1 sibling, 0 replies; 5+ messages in thread
From: Pavel Machek @ 2009-10-02  3:52 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: Rafael Wysocki, linux-pm, LKML

On Mon 2009-09-28 14:09:29, Nigel Cunningham wrote:
> Move hibernation code's functions for allocating and freeing swap
> from swsusp.c to swap.c, which is where you'd expect to find them.

Please cc me on hibernation/suspend related patches.

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

end of thread, other threads:[~2009-10-02  6:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-28  4:09 [PATCH 1/2] Move swap functions to kernel/power/swap.c Nigel Cunningham
2009-09-29 20:24 ` Rafael J. Wysocki
2009-10-01  1:28   ` [linux-pm] " Nigel Cunningham
2009-10-01 20:53     ` Rafael J. Wysocki
2009-10-02  3:52 ` Pavel Machek

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