From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Andrew Morton <akpm@osdl.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Pavel Machek <pavel@ucw.cz>
Subject: [PATCH 3/3] swsusp: Fix alloc_pagedir
Date: Wed, 2 Aug 2006 18:57:34 +0200 [thread overview]
Message-ID: <200608021857.35042.rjw@sisk.pl> (raw)
In-Reply-To: <200608021842.21774.rjw@sisk.pl>
Get rid of the FIXME in kernel/power/snapshot.c#alloc_pagedir() and
simplify the functions called by it.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
kernel/power/snapshot.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
Index: linux-2.6.18-rc2-mm1/kernel/power/snapshot.c
===================================================================
--- linux-2.6.18-rc2-mm1.orig/kernel/power/snapshot.c 2006-08-01 22:15:41.000000000 +0200
+++ linux-2.6.18-rc2-mm1/kernel/power/snapshot.c 2006-08-01 22:24:57.000000000 +0200
@@ -316,12 +316,12 @@ static void free_pagedir(struct pbe *pbl
* fill_pb_page - Create a list of PBEs on a given memory page
*/
-static inline void fill_pb_page(struct pbe *pbpage)
+static inline void fill_pb_page(struct pbe *pbpage, unsigned int n)
{
struct pbe *p;
p = pbpage;
- pbpage += PB_PAGE_SKIP;
+ pbpage += n - 1;
do
p->next = p + 1;
while (++p < pbpage);
@@ -330,24 +330,26 @@ static inline void fill_pb_page(struct p
/**
* create_pbe_list - Create a list of PBEs on top of a given chain
* of memory pages allocated with alloc_pagedir()
+ *
+ * This function assumes that pages allocated by alloc_image_page() will
+ * always be zeroed.
*/
static inline void create_pbe_list(struct pbe *pblist, unsigned int nr_pages)
{
- struct pbe *pbpage, *p;
+ struct pbe *pbpage;
unsigned int num = PBES_PER_PAGE;
for_each_pb_page (pbpage, pblist) {
if (num >= nr_pages)
break;
- fill_pb_page(pbpage);
+ fill_pb_page(pbpage, PBES_PER_PAGE);
num += PBES_PER_PAGE;
}
if (pbpage) {
- for (num -= PBES_PER_PAGE - 1, p = pbpage; num < nr_pages; p++, num++)
- p->next = p + 1;
- p->next = NULL;
+ num -= PBES_PER_PAGE;
+ fill_pb_page(pbpage, nr_pages - num);
}
}
@@ -374,17 +376,17 @@ static struct pbe *alloc_pagedir(unsigne
return NULL;
pblist = alloc_image_page(gfp_mask, safe_needed);
- /* FIXME: rewrite this ugly loop */
- for (pbe = pblist, num = PBES_PER_PAGE; pbe && num < nr_pages;
- pbe = pbe->next, num += PBES_PER_PAGE) {
+ pbe = pblist;
+ for (num = PBES_PER_PAGE; num < nr_pages; num += PBES_PER_PAGE) {
+ if (!pbe) {
+ free_pagedir(pblist, 1);
+ return NULL;
+ }
pbe += PB_PAGE_SKIP;
pbe->next = alloc_image_page(gfp_mask, safe_needed);
+ pbe = pbe->next;
}
- if (!pbe) { /* get_zeroed_page() failed */
- free_pagedir(pblist, 1);
- pblist = NULL;
- } else
- create_pbe_list(pblist, nr_pages);
+ create_pbe_list(pblist, nr_pages);
return pblist;
}
next prev parent reply other threads:[~2006-08-02 17:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-02 16:42 [PATCH 0/3] swsusp cleanups Rafael J. Wysocki
2006-08-02 16:48 ` [PATCH 1/3] swsusp: Fix mark_free_pages Rafael J. Wysocki
2006-08-02 19:51 ` Dave Hansen
2006-08-02 20:12 ` Rafael J. Wysocki
2006-08-02 20:30 ` Pavel Machek
2006-08-02 20:48 ` Rafael J. Wysocki
2006-08-02 16:53 ` [PATCH 2/3] swsusp: Reorder memory-allocating functions Rafael J. Wysocki
2006-08-02 20:19 ` Pavel Machek
2006-08-02 16:57 ` Rafael J. Wysocki [this message]
2006-08-02 20:22 ` [PATCH 3/3] swsusp: Fix alloc_pagedir 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=200608021857.35042.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.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
Powered by JetHome