public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Pavel Machek <pavel@ucw.cz>, Linux PM <linux-pm@osdl.org>
Subject: [RFC][PATCH -mm 5/5] swsusp: Introduce some helpful constants
Date: Wed, 9 Aug 2006 12:13:18 +0200	[thread overview]
Message-ID: <200608091213.18418.rjw@sisk.pl> (raw)
In-Reply-To: <200608091152.49094.rjw@sisk.pl>

Introduce some constants that hopefully will help improve the readability kernel/power/snapshot.c |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)

Index: linux-2.6.18-rc3-mm2/kernel/power/snapshot.c
===================================================================
--- linux-2.6.18-rc3-mm2.orig/kernel/power/snapshot.c
+++ linux-2.6.18-rc3-mm2/kernel/power/snapshot.c
@@ -57,6 +57,11 @@ static void *buffer;
  *	so that swsusp_free() can release it.
  */
 
+#define PG_ANY		0
+#define PG_SAFE		1
+#define PG_UNSAFE_CLEAR	1
+#define PG_UNSAFE_KEEP	0
+
 static unsigned int allocated_unsafe_pages;
 
 static void *get_image_page(gfp_t gfp_mask, int safe_needed)
@@ -357,7 +362,7 @@ create_memory_bm(struct memory_bitmap *b
 	zone_bm = create_zone_bm_list(nr, &ca);
 	bm->zone_bm_list = zone_bm;
 	if (!zone_bm) {
-		chain_free(&ca, 1);
+		chain_free(&ca, PG_UNSAFE_CLEAR);
 		return -ENOMEM;
 	}
 
@@ -410,7 +415,7 @@ create_memory_bm(struct memory_bitmap *b
 
 Free:
 	bm->p_list = ca.chain;
-	free_memory_bm(bm, 1);
+	free_memory_bm(bm, PG_UNSAFE_CLEAR);
 	return -ENOMEM;
 }
 
@@ -936,15 +941,15 @@ swsusp_alloc(struct memory_bitmap *orig_
 {
 	int error;
 
-	error = create_memory_bm(orig_bm, GFP_ATOMIC, 0);
+	error = create_memory_bm(orig_bm, GFP_ATOMIC, PG_ANY);
 	if (error)
 		goto Free;
 
-	error = create_memory_bm(copy_bm, GFP_ATOMIC, 0);
+	error = create_memory_bm(copy_bm, GFP_ATOMIC, PG_ANY);
 	if (error)
 		goto Free;
 
-	error = get_highmem_buffer(0);
+	error = get_highmem_buffer(PG_ANY);
 	if (error)
 		goto Free;
 
@@ -1078,7 +1083,7 @@ int snapshot_read_next(struct snapshot_h
 
 	if (!buffer) {
 		/* This makes the buffer be freed by swsusp_free() */
-		buffer = get_image_page(GFP_ATOMIC, 0);
+		buffer = get_image_page(GFP_ATOMIC, PG_ANY);
 		if (!buffer)
 			return -ENOMEM;
 	}
@@ -1299,10 +1304,10 @@ prepare_highmem_image(struct memory_bitm
 {
 	unsigned int to_alloc;
 
-	if (create_memory_bm(bm, GFP_ATOMIC, 1))
+	if (create_memory_bm(bm, GFP_ATOMIC, PG_SAFE))
 		return -ENOMEM;
 
-	if (get_highmem_buffer(1))
+	if (get_highmem_buffer(PG_SAFE))
 		return -ENOMEM;
 
 	to_alloc = count_free_highmem_pages();
@@ -1415,8 +1420,8 @@ static inline int last_highmem_page_copi
 
 static inline void free_highmem_data(void)
 {
-	free_memory_bm(safe_highmem_bm, 1);
-	free_image_page(buffer, 1);
+	free_memory_bm(safe_highmem_bm, PG_UNSAFE_CLEAR);
+	free_image_page(buffer, PG_UNSAFE_CLEAR);
 }
 #else
 static inline int get_safe_write_buffer(void) { return 0; }
@@ -1465,19 +1470,19 @@ prepare_image(struct memory_bitmap *new_
 	int error;
 
 	/* If there is no highmem, the buffer will not be necessary */
-	free_image_page(buffer, 1);
+	free_image_page(buffer, PG_UNSAFE_CLEAR);
 
 	nr_highmem = count_highmem_image_pages(bm);
 	error = mark_unsafe_pages(bm);
 	if (error)
 		goto Free;
 
-	error = create_memory_bm(new_bm, GFP_ATOMIC, 1);
+	error = create_memory_bm(new_bm, GFP_ATOMIC, PG_SAFE);
 	if (error)
 		goto Free;
 
 	duplicate_memory_bitmap(new_bm, bm);
-	free_memory_bm(bm, 0);
+	free_memory_bm(bm, PG_UNSAFE_KEEP);
 	if (nr_highmem > 0) {
 		error = prepare_highmem_image(bm, &nr_highmem);
 		if (error)
@@ -1494,7 +1499,7 @@ prepare_image(struct memory_bitmap *new_
 	nr_pages = nr_copy_pages - nr_highmem - allocated_unsafe_pages;
 	nr_pages = DIV_ROUND_UP(nr_pages, PBES_PER_LINKED_PAGE);
 	while (nr_pages > 0) {
-		lp = get_image_page(GFP_ATOMIC, 1);
+		lp = get_image_page(GFP_ATOMIC, PG_SAFE);
 		if (!lp) {
 			error = -ENOMEM;
 			goto Free;
@@ -1525,7 +1530,7 @@ prepare_image(struct memory_bitmap *new_
 	/* Free the reserved safe pages so that chain_alloc() can use them */
 	while (sp_list) {
 		lp = sp_list->next;
-		free_image_page(sp_list, 1);
+		free_image_page(sp_list, PG_UNSAFE_CLEAR);
 		sp_list = lp;
 	}
 	return 0;
@@ -1604,7 +1609,7 @@ int snapshot_write_next(struct snapshot_
 	if (handle->offset == 0) {
 		if (!buffer)
 			/* This makes the buffer be freed by swsusp_free() */
-			buffer = get_image_page(GFP_ATOMIC, 0);
+			buffer = get_image_page(GFP_ATOMIC, PG_ANY);
 
 		if (!buffer)
 			return -ENOMEM;
@@ -1618,7 +1623,7 @@ int snapshot_write_next(struct snapshot_
 			if (error)
 				return error;
 
-			error = create_memory_bm(&copy_bm, GFP_ATOMIC, 0);
+			error = create_memory_bm(&copy_bm, GFP_ATOMIC, PG_ANY);
 			if (error)
 				return error;
 
@@ -1668,7 +1673,7 @@ void snapshot_write_finalize(struct snap
 	copy_last_highmem_page();
 	/* Free only if we have loaded the image entirely */
 	if (handle->prev && handle->cur > nr_meta_pages + nr_copy_pages) {
-		free_memory_bm(&orig_bm, 1);
+		free_memory_bm(&orig_bm, PG_UNSAFE_CLEAR);
 		free_highmem_data();
 	}
 }
@@ -1710,7 +1715,7 @@ int restore_highmem(void)
 	struct highmem_pbe *pbe = highmem_pblist;
 	void *buf;
 
-	buf = get_image_page(GFP_ATOMIC, 1);
+	buf = get_image_page(GFP_ATOMIC, PG_SAFE);
 	if (!buf)
 		return -ENOMEM;
 
@@ -1718,7 +1723,7 @@ int restore_highmem(void)
 		swap_two_pages_data(pbe->copy_page, pbe->orig_page, buf);
 		pbe = pbe->next;
 	}
-	free_image_page(buf, 1);
+	free_image_page(buf, PG_UNSAFE_CLEAR);
 	return 0;
 }
 #endif /* CONFIG_HIGHMEM */

of the code.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---

  parent reply	other threads:[~2006-08-09 10:13 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-09  9:52 [RFC][PATCH -mm 0/5] swsusp: Fix handling of highmem Rafael J. Wysocki
2006-08-09  9:58 ` [RFC][PATCH -mm 1/5] swsusp: Introduce memory bitmaps Rafael J. Wysocki
2006-08-09 10:31   ` Pavel Machek
2006-08-09 10:57     ` Rafael J. Wysocki
2006-08-09 11:27       ` Pavel Machek
2006-08-09 11:36         ` Rafael J. Wysocki
2006-08-09 11:53           ` Pavel Machek
2006-08-09 12:11             ` Rafael J. Wysocki
2006-08-09 11:46   ` Pavel Machek
2006-08-09 12:02     ` Rafael J. Wysocki
2006-08-09 13:35       ` Pavel Machek
2006-08-09 10:04 ` [RFC][PATCH -mm 2/5] swsusp: Use memory bitmaps during resume Rafael J. Wysocki
2006-08-09 10:34   ` Pavel Machek
2006-08-09 11:04     ` Rafael J. Wysocki
2006-08-09 11:33       ` Pavel Machek
2006-08-09 11:51         ` Rafael J. Wysocki
2006-08-09 13:33           ` Pavel Machek
2006-08-09 11:49   ` Pavel Machek
2006-08-09 12:04     ` Rafael J. Wysocki
2006-08-09 12:10       ` Pavel Machek
2006-08-09 10:09 ` [RFC][PATCH -mm 3/5] swsusp: Fix handling of highmem Rafael J. Wysocki
2006-08-09 11:51   ` Pavel Machek
2006-08-09 12:07     ` Rafael J. Wysocki
2006-08-09 13:35       ` Pavel Machek
2006-08-09 10:11 ` [RFC][PATCH -mm 4/5] swsusp: Change the name of pagedir_nosave Rafael J. Wysocki
2006-08-09 10:35   ` Pavel Machek
2006-08-09 10:13 ` Rafael J. Wysocki [this message]
2006-08-09 10:36   ` [RFC][PATCH -mm 5/5] swsusp: Introduce some helpful constants Pavel Machek
2006-08-09 10:47 ` [RFC][PATCH -mm 0/5] swsusp: Fix handling of highmem Nigel Cunningham
2006-08-09 11:38   ` Pavel Machek
2006-08-09 11:52     ` Nigel Cunningham
2006-08-13 22:34       ` Pavel Machek

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=200608091213.18418.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@osdl.org \
    --cc=pavel@ucw.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox