From: Nigel Cunningham <nigel@tuxonice.net>
To: "Rafael J. Wysocki" <rjw@sisk.pl>,
Linux PM <linux-pm@lists.linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>,
TuxOnIce-devel <tuxonice-devel@tuxonice.net>
Subject: [PATCH 11/21] Hibernation: Partial page I/O support.
Date: Wed, 2 Jun 2010 22:19:10 +1000 [thread overview]
Message-ID: <1275481160-31150-12-git-send-email-nigel@tuxonice.net> (raw)
In-Reply-To: <1275481160-31150-1-git-send-email-nigel@tuxonice.net>
Add functions that can be used for coalescing and splitting buffers
that are smaller than PAGE_SIZE. These functions provide no method
of determining where the boundaries of the smaller buffers are to
be found - that is the caller's problem.
Signed-off-by: Nigel Cunningham <nigel@tuxonice.net>
---
kernel/power/block_io.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++
kernel/power/block_io.h | 4 ++
2 files changed, 94 insertions(+), 0 deletions(-)
diff --git a/kernel/power/block_io.c b/kernel/power/block_io.c
index c449db2..0e57776 100644
--- a/kernel/power/block_io.c
+++ b/kernel/power/block_io.c
@@ -17,6 +17,11 @@
static struct bio *bio_chain;
+static char *hib_ppio_buffer;
+static int hib_ppio_buffer_posn;
+int hib_prepare_buffer(void);
+void hib_free_buffer(void);
+
/**
* submit - submit BIO request.
* @rw: READ or WRITE.
@@ -301,3 +306,88 @@ int swap_read_page(void *buf, int sync)
}
return error;
}
+
+/* Part Page I/O functions */
+static char *hib_ppio_buffer;
+static int hib_ppio_buffer_posn;
+
+int hib_prepare_buffer(void)
+{
+ hib_ppio_buffer = (char *)__get_free_page(__GFP_WAIT);
+ hib_ppio_buffer_posn = 0;
+ return hib_ppio_buffer ? 0 : -ENOMEM;
+}
+
+void hib_free_buffer(void)
+{
+ if (!hib_ppio_buffer)
+ return;
+
+ free_page((unsigned long) hib_ppio_buffer);
+ hib_ppio_buffer = NULL;
+}
+
+int hib_flush_write_buffer(void)
+{
+ return hib_ppio_buffer_posn ? swap_write_page(hib_ppio_buffer, 0) : 0;
+}
+
+int hib_write_buffer(char *buffer, int buffer_size)
+{
+ int bytes_left = buffer_size, result = 0;
+
+ while (bytes_left) {
+ char *from = buffer + buffer_size - bytes_left;
+ char *to = hib_ppio_buffer + hib_ppio_buffer_posn;
+ int capacity = PAGE_SIZE - hib_ppio_buffer_posn;
+
+ if (bytes_left <= capacity) {
+ memcpy(to, from, bytes_left);
+ hib_ppio_buffer_posn += bytes_left;
+ return 0;
+ }
+
+ /* Complete this page and start a new one */
+ memcpy(to, from, capacity);
+ bytes_left -= capacity;
+
+ result = swap_write_page(hib_ppio_buffer, 0);
+ if (result)
+ return result;
+
+ hib_ppio_buffer_posn = 0;
+ }
+
+ return 0;
+}
+
+int hib_read_buffer(char *buffer, int buffer_size)
+{
+ int bytes_left = buffer_size, result = 0;
+
+ while (bytes_left) {
+ char *to = buffer + buffer_size - bytes_left;
+ char *from = hib_ppio_buffer + hib_ppio_buffer_posn;
+ int capacity = PAGE_SIZE - hib_ppio_buffer_posn;
+
+ if (bytes_left <= capacity) {
+ memcpy(to, from, bytes_left);
+ hib_ppio_buffer_posn += bytes_left;
+ return 0;
+ }
+
+ /* Complete this page and start a new one */
+ memcpy(to, from, capacity);
+ bytes_left -= capacity;
+
+ result = swap_read_page(hib_ppio_buffer, 1);
+ if (result) {
+ printk("swap_read_page returned %d.\n", result);
+ return result;
+ }
+
+ hib_ppio_buffer_posn = 0;
+ }
+
+ return 0;
+}
diff --git a/kernel/power/block_io.h b/kernel/power/block_io.h
index 2f91d6d..ac378c5 100644
--- a/kernel/power/block_io.h
+++ b/kernel/power/block_io.h
@@ -21,3 +21,7 @@ int swap_write_page(void *buf, int sync);
int get_swap_reader(unsigned int *flags_p, sector_t first_page);
void release_swap_reader(void);
int swap_read_page(void *buf, int sync);
+int hib_flush_write_buffer(void);
+
+int hib_write_buffer(char *buffer, int len);
+int hib_read_buffer(char *buffer, int len);
--
1.7.0.4
next prev parent reply other threads:[~2010-06-02 12:22 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-02 12:18 Nigel's current for-rafael queue Nigel Cunningham
2010-06-02 12:19 ` [PATCH 01/21] Hibernation: Swap iteration functions Nigel Cunningham
2010-06-02 12:19 ` [PATCH 02/21] Hibernation: Move root_swap declaration Nigel Cunningham
2010-06-02 12:19 ` [PATCH 03/21] Hibernation: Add mass swap allocation routine Nigel Cunningham
2010-06-02 12:19 ` [PATCH 04/21] Hibernation: Switch to preallocating swap Nigel Cunningham
2010-06-02 12:19 ` [PATCH 05/21] Hiberation: Fix speed display Nigel Cunningham
2010-06-02 12:19 ` [PATCH 06/21] Hibernation: Generic extents support Nigel Cunningham
2010-06-02 12:19 ` [PATCH 07/21] Hibernation: Iterate over sectors not swap entries Nigel Cunningham
2010-06-02 12:19 ` [PATCH 08/21] Hibernation: Stop passing swap_map_handle struct Nigel Cunningham
2010-06-02 12:19 ` [PATCH 09/21] Hibernation: Stop passing bio_chain around Nigel Cunningham
2010-06-02 12:19 ` [PATCH 10/21] Hibernation: Move block i/o fns to block_io.c Nigel Cunningham
2010-06-02 12:19 ` Nigel Cunningham [this message]
2010-06-02 12:19 ` [PATCH 12/21] Hibernation: Extent save/load routines Nigel Cunningham
2010-06-02 12:19 ` [PATCH 13/21] Hibernation: Store block extents at start of image Nigel Cunningham
2010-06-02 12:19 ` [PATCH 14/21] Hibernation: Use block extents for reading image Nigel Cunningham
2010-06-02 12:19 ` [PATCH 15/21] Remove first_sector from swap_map_handle Nigel Cunningham
2010-06-02 12:19 ` [PATCH 16/21] Hibernation: Replace bio chain Nigel Cunningham
2010-06-02 12:19 ` [PATCH 17/21] Hibernation: Remove swap_map_pages Nigel Cunningham
2010-06-02 12:19 ` [PATCH 18/21] Hibernation: Remove wait_on_bio_chain result Nigel Cunningham
2010-06-02 12:19 ` [PATCH 19/21] Hibernation: Prepare for handle.cur removal Nigel Cunningham
2010-06-02 12:19 ` [PATCH 20/21] Hibernation: Remove swap_map structure Nigel Cunningham
2010-06-02 12:19 ` [PATCH 21/21] Hibernation: Remove now-empty routines Nigel Cunningham
2010-08-03 6:55 ` Nigel's current for-rafael queue Pavel Machek
2010-08-03 7:00 ` Nigel Cunningham
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=1275481160-31150-12-git-send-email-nigel@tuxonice.net \
--to=nigel@tuxonice.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@lists.linux-foundation.org \
--cc=rjw@sisk.pl \
--cc=tuxonice-devel@tuxonice.net \
/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;
as well as URLs for NNTP newsgroup(s).