From: Pavel Machek <pavel@ucw.cz>
To: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: LKML <linux-kernel@vger.kernel.org>, linux-pm@osdl.org
Subject: Re: [RFC][PATCH 3/6] swsusp: introduce the swap map structure and interface functions
Date: Sun, 30 Oct 2005 01:20:31 +0200 [thread overview]
Message-ID: <20051029232031.GF14209@elf.ucw.cz> (raw)
In-Reply-To: <200510292232.35403.rjw@sisk.pl>
Hi!
> Index: linux-2.6.14-rc5-mm1/kernel/power/snapshot.c
> ===================================================================
> --- linux-2.6.14-rc5-mm1.orig/kernel/power/snapshot.c 2005-10-29 13:24:56.000000000 +0200
> +++ linux-2.6.14-rc5-mm1/kernel/power/snapshot.c 2005-10-29 14:11:17.000000000 +0200
> +
> +unsigned snapshot_pages_to_save(void)
> +{
> + return nr_copy_pages + nr_pb_pages;
> +}
> +
> +unsigned snapshot_image_pages(void)
> +{
> + return nr_copy_pages;
> +}
> +
> +static unsigned current_page = 0;
> +static struct pbe *current_pbe;
> +static struct pbe *current_pblist;
> +
> +void snapshot_send_init(void)
> +{
> + current_page = 0;
> + current_pbe = pagedir_nosave;
> + current_pblist = NULL;
> +}
> +
> +static void prepare_next_pb_page(unsigned long *buf)
> +{
> + struct pbe *p;
> + unsigned n;
> +
> + p = current_pbe;
> + for (n = 0; n < PAGE_SIZE/sizeof(long) && p; n++) {
> + buf[n] = p->orig_address;
> + p = p->next;
> + }
> + current_pbe = p;
> +}
> +
> +int snapshot_send_page(void *buf)
> +{
> + if (current_page >= nr_copy_pages + nr_pb_pages)
> + return -EINVAL;
> + if (current_page < nr_pb_pages) {
> + prepare_next_pb_page(buf);
> + if (!current_pbe)
> + current_pbe = pagedir_nosave;
> + } else {
> + memcpy(buf, (void *)current_pbe->address, PAGE_SIZE);
> + current_pbe = current_pbe->next;
> + }
> + current_page++;
> + return 0;
> +}
> +
> +int snapshot_recv_init(unsigned nr_pages, unsigned img_pages)
> +{
> + struct pbe *pblist;
> +
> + if (nr_pages <= img_pages)
> + return -EINVAL;
> + /* We have to create a PBE list here */
> + pblist = alloc_pagedir(img_pages);
> + if (!pblist)
> + return -ENOMEM;
> + create_pbe_list(pblist, img_pages);
> + current_pblist = pblist;
> + current_pbe = pblist;
> + current_page = 0;
> + nr_copy_pages = img_pages;
> + nr_pb_pages = nr_pages - img_pages;
> + return 0;
> +}
> +
> +static void load_next_pb_page(unsigned long *buf)
> +{
> + struct pbe *p;
> + unsigned n;
> +
> + p = current_pbe;
> + for (n = 0; n < PAGE_SIZE/sizeof(long) && p; n++) {
> + p->orig_address = buf[n];
> + p = p->next;
> + }
> + current_pbe = p;
> +}
> +
> +int snapshot_recv_page(void *buf)
> +{
> + if (!current_pblist ||
> + current_page >= nr_copy_pages + nr_pb_pages)
> + return -EINVAL;
> + if (current_page < nr_pb_pages) {
> + load_next_pb_page(buf);
> + if (!current_pbe) {
> + current_pblist = relocate_pbe_list(current_pblist);
> + if (!current_pblist) {
> + printk(KERN_ERR "\nswsusp: Not enough memory for relocating PBEs\n");
> + return -ENOMEM;
> + }
> + current_pbe = current_pblist;
> + }
> + } else {
> + current_pbe->address = get_safe_page(GFP_ATOMIC);
> + if (!current_pbe->address) {
> + printk(KERN_ERR "\nswsusp: Not enough memory for the image\n");
> + return -ENOMEM;
> + }
> + memcpy((void *)current_pbe->address, buf, PAGE_SIZE);
> + current_pbe = current_pbe->next;
> + }
> + current_page++;
> + return 0;
> +}
> +
> +int snapshot_finish(void)
> +{
> + if (current_pbe)
> + return -EINVAL;
> + current_page = 0;
> + if (current_pblist)
> + pagedir_nosave = current_pblist;
> + current_pblist = NULL;
> + return 0;
> +}
No, sorry, I don't like that. I like existing interface better. It
should be something like...
system_snapshot(), returns structure to save and nr_pages.
system_restore() takes struct pbe * (or something like that) and
nr_pages, and takes care.
snapshot_send_init()...snapshot_finish() interface is too complex in
my eyes, and will be hard to get right.
Pavel
--
Thanks, Sharp!
next prev parent reply other threads:[~2005-10-29 23:20 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-29 19:58 [RFC][PATCH 0/6] swsusp: rework swap handling Rafael J. Wysocki
2005-10-29 20:01 ` [RFC][PATCH 1/6] swsusp: rework swsusp_suspend Rafael J. Wysocki
2005-10-29 22:25 ` Pavel Machek
2005-10-29 20:06 ` [RFC][PATCH 2/6] swsusp: move snapshot-handling functions to snapshot.c Rafael J. Wysocki
2005-10-29 22:27 ` Pavel Machek
2005-10-29 20:32 ` [RFC][PATCH 3/6] swsusp: introduce the swap map structure and interface functions Rafael J. Wysocki
2005-10-29 22:57 ` Pavel Machek
2005-10-29 23:20 ` Pavel Machek [this message]
2005-10-29 20:36 ` [RFC][PATCH 4/6] swsusp: move swap check out of swsusp_suspend Rafael J. Wysocki
2005-10-29 23:21 ` Pavel Machek
2005-10-30 12:40 ` Rafael J. Wysocki
2005-10-30 11:46 ` Pavel Machek
2005-10-29 20:41 ` [RFC][PATCH 5/6] swsusp: move swap-handling functions to separate file Rafael J. Wysocki
2005-10-30 13:33 ` Pavel Machek
2005-10-29 20:46 ` [RFC][PATCH 6/6] swsusp: improve freeing of memory Rafael J. Wysocki
2005-10-29 23:05 ` [RFC][PATCH 0/6] swsusp: rework swap handling Pavel Machek
2005-10-30 12:17 ` 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=20051029232031.GF14209@elf.ucw.cz \
--to=pavel@ucw.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@osdl.org \
--cc=rjw@sisk.pl \
/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