public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@gmail.com>
To: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: linux-pm@lists.linux-foundation.org,
	Nigel Cunningham <ncunningham@crca.org.au>
Subject: Re: [RFC 09/15] PM / Hibernate: user, implement user_ops writer
Date: Wed, 21 Apr 2010 23:22:07 +0200	[thread overview]
Message-ID: <4BCF6C7F.7020807@gmail.com> (raw)
In-Reply-To: <201003312229.18142.rjw@sisk.pl>

[-- Attachment #1: Type: text/plain, Size: 1863 bytes --]

On 03/31/2010 10:29 PM, Rafael J. Wysocki wrote:
> On Wednesday 31 March 2010, Jiri Slaby wrote:
>> On 03/30/2010 10:50 PM, Rafael J. Wysocki wrote:
>>> So, I definitely would like to see numbers.
>>
>> With the patch attached, I get similar results for
>> uncompressed image -> user.c -> s2disk (compress+threads)
>> compressed image -> user.c -> s2disk (none of compress+threads)
>>
>> BUT note that there are differences in pages _copied_ in the "user.c ->
>> s2disk" phase. Compression was about 40 %. So in the former case 100000
>> pages went through and in the latter one only ~ 38000. So presumably
>> there will be savings if the pages are compressed in the kernel in the
>> save-image phase instead of in userspace.
>>
>> I'll test (after I hack that up) also the case of image compression when
>> saving the image and let you know.
>>
>> It was tested on a machine with openSUSE factory with init 5 with KDE 4.
>> The memory consumption was ~ 400M (100000 pages) after boot every time.
>> Hibernation lasted 12-13s in both cases.
> 
> So that's pretty much the same and I don't think feeding compressed images to
> s2disk is not worth the effort.  Let's assume s2disk will always receive a raw
> image (that will make it backwards compatible too).

Hi.

Yes, I did it solely for comparison purposes.

Now, with the patch attached (depending on either COMPRESS_IMAGE or
COMPRESS_IMAGE1 defined) I tried to compare compression while doing
atomic copy with compression done when image storage takes place. The
latter outperformed the former a bit. I did 8 measurements with the
setup same as above. The average for them is 9684.32 and 10855.07 stored
raw (uncompressed) pages per second. That is 4.5M/s more.

There is a sheet with the numbers at:
http://spreadsheets.google.com/ccc?key=0AvVn7xYA1DnodHFFYzg3Y2tpMUl5NFlURXRtR0xQdmc&hl=en

regards,
-- 
js

[-- Attachment #2: compress-image.patch --]
[-- Type: text/x-patch, Size: 3826 bytes --]

---
 kernel/power/snapshot.c |   80 +++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index ea7bd50..d702953 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -39,6 +39,7 @@
 
 static void *lzo_buf;
 static void *page_buf;
+static void *chunk_buf;
 struct timeval hib_start_time;
 
 static int swsusp_page_is_free(struct page *);
@@ -1339,8 +1340,12 @@ int hibernate_preallocate_memory(void)
 		page_buf = (void *)__get_free_pages(GFP_KERNEL,
 				get_order(lzo1x_worst_compress(PAGE_SIZE)));
 
+	if (!chunk_buf)
+		chunk_buf = (void *)__get_free_page(GFP_KERNEL);
+
 	BUG_ON(!lzo_buf);
 	BUG_ON(!page_buf);
+	BUG_ON(!chunk_buf);
 
 	printk(KERN_INFO "PM: Preallocating image memory... ");
 	do_gettimeofday(&start);
@@ -2333,6 +2338,73 @@ static int snapshot_image_loaded(struct snapshot_handle *handle)
 			handle->cur < nr_meta_pages + nr_copy_pages);
 }
 
+static void wwwrite(struct bio **bio, const char *buffer, int buffer_size)
+{
+	static unsigned long dst_page_pos;
+	int bytes_left = buffer_size;
+
+	while (bytes_left) {
+		const char *from = buffer + buffer_size - bytes_left;
+		char *to = chunk_buf + dst_page_pos;
+		int capacity = PAGE_SIZE - dst_page_pos;
+		int n;
+
+//		printk("%s: to=%p from=%p\n", __func__, to, from);
+		if (bytes_left <= capacity) {
+			for (n = 0; n < bytes_left; n++)
+				to[n] = from[n];
+			dst_page_pos += bytes_left;
+			return;
+		}
+
+		/* Complete this page and start a new one */
+		for (n = 0; n < capacity; n++)
+			to[n] = from[n];
+		bytes_left -= capacity;
+
+		BUG_ON(hibernate_io_ops->write_page(chunk_buf, bio));
+
+		dst_page_pos = 0;
+	}
+}
+
+#define COMPRESS_IMAGE1 1
+
+/* This is needed, because copy_page and memcpy are not usable for copying
+ * task structs.
+ */
+static unsigned long do_write_page(struct bio **bio,
+		const unsigned char *src)
+{
+//	static int first = true;
+#if COMPRESS_IMAGE1
+	size_t dst_len;
+	int ret;
+
+//	printk("%s: %p\n", __func__, page_buf);
+	ret = lzo1x_1_compress(src, PAGE_SIZE, page_buf, &dst_len, lzo_buf);
+	if (ret < 0) {
+		printk(KERN_EMERG "%s: compress failed: ret=%d dst_len=%zu\n",
+				__func__, ret, dst_len);
+		BUG();
+	}
+
+	wwwrite(bio, (char *)&dst_len, sizeof(dst_len));
+	wwwrite(bio, page_buf, dst_len);
+
+	return sizeof(dst_len) + dst_len;
+#else
+	wwwrite(bio, src, PAGE_SIZE);
+	return PAGE_SIZE;
+#endif
+
+/*	if (first) {
+		print_hex_dump_bytes("O:", DUMP_PREFIX_OFFSET, src, PAGE_SIZE);
+		printk(KERN_DEBUG "len=%zu\n", dst_len);
+		print_hex_dump_bytes("N:", DUMP_PREFIX_OFFSET, dst, dst_len);
+		first = false;
+	}*/
+}
 /**
  *	save_image - save the suspend image data
  */
@@ -2340,6 +2412,7 @@ static int snapshot_image_loaded(struct snapshot_handle *handle)
 static int save_image(struct snapshot_handle *snapshot,
                       unsigned int nr_to_write)
 {
+	unsigned long whole = 0;
 	unsigned int m;
 	int ret;
 	int nr_pages;
@@ -2360,9 +2433,10 @@ static int save_image(struct snapshot_handle *snapshot,
 		ret = snapshot_read_next(snapshot);
 		if (ret <= 0)
 			break;
-		ret = hibernate_io_ops->write_page(data_of(*snapshot), &bio);
+		whole += do_write_page(&bio, data_of(*snapshot));
+/*		ret = hibernate_io_ops->write_page(data_of(*snapshot), &bio);
 		if (ret)
-			break;
+			break;*/
 		if (!(nr_pages % m))
 			printk(KERN_CONT "\b\b\b\b%3d%%", nr_pages / m);
 		nr_pages++;
@@ -2372,7 +2446,7 @@ static int save_image(struct snapshot_handle *snapshot,
 	if (!ret)
 		ret = err2;
 	if (!ret)
-		printk(KERN_CONT "\b\b\b\bdone\n");
+		printk(KERN_CONT "\b\b\b\bdone\n%lu of %d\n", DIV_ROUND_UP(whole, PAGE_SIZE), nr_pages);
 	else
 		printk(KERN_CONT "\n");
 	swsusp_show_speed(&start, &stop, nr_to_write, "Wrote");
-- 
1.7.0.3


[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



  reply	other threads:[~2010-04-21 21:22 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-23 16:17 [RFC 01/15] FS: libfs, implement simple_write_to_buffer Jiri Slaby
2010-03-23 16:17 ` [RFC 02/15] PM / Hibernate: snapshot cleanup Jiri Slaby
2010-03-23 16:17 ` [RFC 03/15] PM / Hibernate: separate block_io Jiri Slaby
2010-03-23 16:17 ` [RFC 04/15] PM / Hibernate: move the first_sector out of swsusp_write Jiri Slaby
2010-03-23 16:17 ` [RFC 05/15] PM / Hibernate: group swap ops Jiri Slaby
2010-03-23 16:17 ` [RFC 06/15] PM / Hibernate: swap, remove swap_map_handle usages Jiri Slaby
2010-03-23 16:17 ` [RFC 07/15] PM / Hibernate: add sws_modules_ops Jiri Slaby
2010-03-23 16:17 ` [RFC 08/15] PM / Hibernate: add user module_ops Jiri Slaby
2010-03-25 22:07   ` Rafael J. Wysocki
     [not found]   ` <201003252307.15232.rjw@sisk.pl>
2010-03-26  9:43     ` Jiri Slaby
2010-03-23 16:17 ` [RFC 09/15] PM / Hibernate: user, implement user_ops writer Jiri Slaby
2010-03-23 16:17 ` [RFC 10/15] PM / Hibernate: user, implement user_ops reader Jiri Slaby
2010-03-23 16:17 ` [RFC 11/15] PM / Hibernate: add chunk i/o support Jiri Slaby
2010-03-23 16:17 ` [RFC 12/15] PM / Hibernate: split snapshot_read_next Jiri Slaby
2010-03-23 16:17 ` [RFC 13/15] PM / Hibernate: split snapshot_write_next Jiri Slaby
2010-03-23 16:17 ` [RFC 14/15] PM / Hibernate: dealign swsusp_info Jiri Slaby
2010-03-23 16:17 ` [RFC 15/15] PM / Hibernate: move non-swap code to snapshot.c Jiri Slaby
2010-03-23 21:51 ` [RFC 01/15] FS: libfs, implement simple_write_to_buffer Rafael J. Wysocki
2010-03-23 22:09 ` Nigel Cunningham
     [not found] ` <1269361063-3341-2-git-send-email-jslaby@suse.cz>
2010-03-24 20:29   ` [RFC 02/15] PM / Hibernate: snapshot cleanup Pavel Machek
2010-03-24 22:35   ` Rafael J. Wysocki
2010-03-25  5:29   ` Pavel Machek
     [not found] ` <1269361063-3341-3-git-send-email-jslaby@suse.cz>
2010-03-24 20:30   ` [RFC 03/15] PM / Hibernate: separate block_io Pavel Machek
     [not found]   ` <20100324203021.GE5798@elf.ucw.cz>
2010-03-24 21:22     ` Jiri Slaby
     [not found]     ` <4BAA829F.7060207@gmail.com>
2010-03-24 22:58       ` Nigel Cunningham
     [not found]       ` <4BAA98FC.9040302@crca.org.au>
2010-03-25  2:35         ` Nigel Cunningham
2010-03-25 14:29         ` Pavel Machek
     [not found]         ` <4BAACC0A.2040009@crca.org.au>
2010-03-25 20:12           ` Rafael J. Wysocki
     [not found]           ` <201003252112.25204.rjw@sisk.pl>
2010-03-25 20:13             ` Nigel Cunningham
     [not found]             ` <4BABC3D1.1050104@crca.org.au>
2010-03-25 20:33               ` Rafael J. Wysocki
     [not found]               ` <201003252133.50206.rjw@sisk.pl>
2010-03-25 20:36                 ` Nigel Cunningham
2010-03-29 13:30             ` Pavel Machek
     [not found] ` <1269361063-3341-4-git-send-email-jslaby@suse.cz>
2010-03-24 20:31   ` [RFC 04/15] PM / Hibernate: move the first_sector out of swsusp_write Pavel Machek
     [not found]   ` <20100324203125.GF5798@elf.ucw.cz>
2010-03-25 21:26     ` Rafael J. Wysocki
     [not found] ` <1269361063-3341-6-git-send-email-jslaby@suse.cz>
2010-03-24 20:33   ` [RFC 06/15] PM / Hibernate: swap, remove swap_map_handle usages Pavel Machek
     [not found]   ` <20100324203329.GG5798@elf.ucw.cz>
2010-03-24 21:29     ` Jiri Slaby
     [not found]     ` <4BAA842A.6060906@gmail.com>
2010-03-25 21:35       ` Rafael J. Wysocki
     [not found] ` <1269361063-3341-7-git-send-email-jslaby@suse.cz>
2010-03-24 20:36   ` [RFC 07/15] PM / Hibernate: add sws_modules_ops Pavel Machek
     [not found]   ` <20100324203634.GH5798@elf.ucw.cz>
2010-03-24 21:31     ` Jiri Slaby
2010-03-25 22:02   ` Rafael J. Wysocki
     [not found] ` <1269361063-3341-9-git-send-email-jslaby@suse.cz>
2010-03-24 20:42   ` [RFC 09/15] PM / Hibernate: user, implement user_ops writer Pavel Machek
     [not found]   ` <20100324204259.GA6423@elf.ucw.cz>
2010-03-24 21:40     ` Jiri Slaby
     [not found]     ` <4BAA86E8.5090108@gmail.com>
2010-03-25 21:36       ` Pavel Machek
2010-03-25 22:14       ` Rafael J. Wysocki
     [not found]       ` <201003252314.33256.rjw@sisk.pl>
2010-03-26  9:34         ` Jiri Slaby
     [not found]         ` <4BAC7FC3.50405@gmail.com>
2010-03-26 22:04           ` Rafael J. Wysocki
2010-03-27  7:02           ` Pavel Machek
     [not found]           ` <201003262304.32118.rjw@sisk.pl>
2010-03-29 15:33             ` Jiri Slaby
     [not found]             ` <4BB0C840.7030802@gmail.com>
2010-03-29 22:09               ` Rafael J. Wysocki
2010-03-30  1:14                 ` Nigel Cunningham
2010-03-30 21:03                   ` Rafael J. Wysocki
2010-03-31  2:31                     ` Nigel Cunningham
2010-03-31 14:47                       ` Pavel Machek
2010-03-31 21:01                         ` Nigel Cunningham
2010-03-31 20:25                       ` Rafael J. Wysocki
2010-03-31 21:06                         ` Nigel Cunningham
2010-03-31 21:36                           ` Rafael J. Wysocki
2010-04-04 23:08                             ` Nigel Cunningham
2010-04-04 23:13                               ` Rafael J. Wysocki
2010-03-31 21:54                           ` Nigel Cunningham
2010-03-30  8:59                 ` Jiri Slaby
2010-03-30 20:50                   ` Rafael J. Wysocki
2010-03-31 14:41                     ` Jiri Slaby
2010-03-31 20:29                       ` Rafael J. Wysocki
2010-04-21 21:22                         ` Jiri Slaby [this message]
2010-04-22  3:43                           ` Rafael J. Wysocki
2010-03-24 22:13 ` [RFC 01/15] FS: libfs, implement simple_write_to_buffer Rafael J. Wysocki
     [not found] ` <1269361063-3341-10-git-send-email-jslaby@suse.cz>
2010-03-25  5:30   ` what the patches do Re: [RFC 10/15] PM / Hibernate: user, implement user_ops reader Pavel Machek
     [not found]   ` <20100325053003.GB12935@elf.ucw.cz>
2010-03-25  5:42     ` Nigel Cunningham
     [not found]     ` <4BAAF7DA.30506@crca.org.au>
2010-03-25  6:12       ` Nigel Cunningham
2010-03-25 20:14       ` Rafael J. Wysocki
     [not found]       ` <201003252114.36605.rjw@sisk.pl>
2010-03-25 20:21         ` Nigel Cunningham
     [not found]         ` <4BABC5B6.2070301@crca.org.au>
2010-03-25 20:29           ` Rafael J. Wysocki
     [not found]           ` <201003252129.10224.rjw@sisk.pl>
2010-03-25 20:35             ` Nigel Cunningham
     [not found]             ` <4BABC926.8060203@crca.org.au>
2010-03-25 21:13               ` Rafael J. Wysocki
2010-03-25 21:26             ` Pavel Machek
     [not found]             ` <20100325212656.GD22902@elf.ucw.cz>
2010-03-25 21:49               ` Nigel Cunningham
     [not found]               ` <4BABDA59.8070107@crca.org.au>
2010-04-02  6:36                 ` Pavel Machek
     [not found]                 ` <20100402063644.GA14941@atrey.karlin.mff.cuni.cz>
2010-04-02 17:03                   ` Rafael J. Wysocki
2010-03-25 22:21     ` Rafael J. Wysocki
     [not found] ` <1269361063-3341-5-git-send-email-jslaby@suse.cz>
2010-03-25 21:28   ` [RFC 05/15] PM / Hibernate: group swap ops Rafael J. Wysocki
     [not found] ` <1269361063-3341-11-git-send-email-jslaby@suse.cz>
2010-03-25 22:38   ` [RFC 11/15] PM / Hibernate: add chunk i/o support Rafael J. Wysocki
     [not found]   ` <201003252338.48513.rjw@sisk.pl>
2010-03-26  9:09     ` Jiri Slaby
     [not found]     ` <4BAC79B4.4040200@gmail.com>
2010-03-26 10:02       ` Nigel Cunningham
     [not found] ` <1269361063-3341-12-git-send-email-jslaby@suse.cz>
2010-03-25 22:44   ` [RFC 12/15] PM / Hibernate: split snapshot_read_next Rafael J. Wysocki
     [not found] ` <1269361063-3341-13-git-send-email-jslaby@suse.cz>
2010-03-25 22:46   ` [RFC 13/15] PM / Hibernate: split snapshot_write_next Rafael J. Wysocki
     [not found] ` <1269361063-3341-14-git-send-email-jslaby@suse.cz>
2010-03-25 22:46   ` [RFC 14/15] PM / Hibernate: dealign swsusp_info Rafael J. Wysocki
     [not found] ` <1269361063-3341-15-git-send-email-jslaby@suse.cz>
2010-03-25 22:50   ` [RFC 15/15] PM / Hibernate: move non-swap code to snapshot.c Rafael J. Wysocki

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=4BCF6C7F.7020807@gmail.com \
    --to=jirislaby@gmail.com \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=ncunningham@crca.org.au \
    --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