mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nigel Cunningham <nigel@suspend2.net>
To: linux-kernel@vger.kernel.org
Subject: [Suspend2][ 02/32] [Suspend2] Block io c file header.
Date: Tue, 27 Jun 2006 08:37:13 +1000	[thread overview]
Message-ID: <20060626223711.4376.6781.stgit@nigel.suspend2.net> (raw)
In-Reply-To: <20060626223706.4376.96042.stgit@nigel.suspend2.net>

kernel/power/suspend_block_io.c does all the hard work of getting the data
written to storage via bio routines. The swapwriter and filewriter are
really only allocators - this file implements completely asynchronous
submission of the I/O and cleanup on completion. All the writers need to do
is feed a list of bdevs and blocks on each bdev, and then the pages to be
written or read.

The io_info struct stores the data on each page in flight. As pages
progress through processing, their io_info structs move from the free list
to the submit_batch list if being batched, to the busy list when submitted
to the block layer, to the ready_for_cleanup list with the completion
function is called, to the free list after cleanup. Each list has its own
spinlock to reduce locking issues.

Readahead pages are used like a ring buffer.

The posn_save struct is used to record where the three parts of the image
begin, thereby allowing quick 'seeking' to the start of a pageset or the
start of the header.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

 kernel/power/suspend_block_io.c |  130 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 130 insertions(+), 0 deletions(-)

diff --git a/kernel/power/suspend_block_io.c b/kernel/power/suspend_block_io.c
new file mode 100644
index 0000000..94f1946
--- /dev/null
+++ b/kernel/power/suspend_block_io.c
@@ -0,0 +1,130 @@
+/*
+ * kernel/power/suspend_block_io.c
+ *
+ * Copyright 2004-2006 Nigel Cunningham <nigel@suspend2.net>
+ *
+ * Distributed under GPLv2.
+ * 
+ * This file contains block io functions for suspend2. These are
+ * used by the swapwriter and it is planned that they will also
+ * be used by the NFSwriter.
+ *
+ */
+
+#include <linux/blkdev.h>
+#include <linux/syscalls.h>
+#include <linux/suspend.h>
+
+#include "suspend2.h"
+#include "proc.h"
+#include "modules.h"
+#include "prepare_image.h"
+#include "block_io.h"
+#include "ui.h"
+
+/* Bits in struct io_info->flags */
+enum {
+	IO_AWAITING_READ,
+	IO_AWAITING_SUBMIT,
+	IO_AWAITING_CLEANUP,
+};
+
+#define MAX_OUTSTANDING_IO 2048
+
+/*
+ *
+ *     IO in progress information storage and helpers
+ *
+ */
+
+struct io_info {
+	struct bio *sys_struct;
+	sector_t block[MAX_BUF_PER_PAGE];
+	struct page *buffer_page;
+	struct page *data_page;
+	unsigned long flags;
+	struct block_device *dev;
+	struct list_head list;
+	int readahead_index;
+};
+
+/*
+ * submit_params
+ */
+struct submit_params {
+	swp_entry_t swap_address;
+	struct page *page;
+	struct block_device *dev;
+	sector_t block[MAX_BUF_PER_PAGE];
+	int readahead_index;
+	struct submit_params *next;
+	int printme;
+};
+
+/* Locks separated to allow better SMP support.
+ * An io_struct moves through the lists as follows.
+ * free -> submit_batch -> busy -> ready_for_cleanup -> free
+ */
+static LIST_HEAD(ioinfo_free);
+static DEFINE_SPINLOCK(ioinfo_free_lock);
+
+static LIST_HEAD(ioinfo_ready_for_cleanup);
+static DEFINE_SPINLOCK(ioinfo_ready_lock);
+
+static LIST_HEAD(ioinfo_submit_batch);
+static DEFINE_SPINLOCK(ioinfo_submit_lock);
+
+static LIST_HEAD(ioinfo_busy);
+static DEFINE_SPINLOCK(ioinfo_busy_lock);
+
+static atomic_t submit_batch;
+static int submit_batch_size = 64;
+static int submit_batched(void);
+
+/* [Max] number of I/O operations pending */
+static atomic_t outstanding_io;
+static int max_outstanding_io = 0;
+static atomic_t buffer_allocs, buffer_frees;
+
+/* [Max] number of pages used for above struct */
+static int infopages = 0;
+static int maxinfopages = 0;
+
+static int extra_page_forward = 0;
+
+static volatile unsigned long suspend_readahead_flags[
+	(MAX_OUTSTANDING_IO + BITS_PER_LONG - 1) / BITS_PER_LONG];
+static spinlock_t suspend_readahead_flags_lock = SPIN_LOCK_UNLOCKED;
+static struct page *suspend_readahead_pages[MAX_OUTSTANDING_IO];
+static int readahead_index, readahead_submit_index;
+
+static int current_stream;
+struct extent_iterate_saved_state suspend_writer_posn_save[3];
+
+/* Pointer to current entry being loaded/saved. */
+struct extent_iterate_state suspend_writer_posn;
+
+/* Not static, so that the allocators can setup and complete
+ * writing the header */
+char *suspend_writer_buffer;
+int suspend_writer_buffer_posn;
+
+int suspend_read_fd;
+
+static unsigned long nr_schedule_calls[8];
+
+static char *sch_caller[] = {
+	"get_io_info_struct #1    ",
+	"get_io_info_struct #2    ",
+	"get_io_info_struct #3    ",
+	"suspend_finish_all_io    ",
+	"wait_on_one_page         ",
+	"submit                   ",
+	"start_one                ",
+	"suspend_wait_on_readahead",
+};
+
+static struct suspend_bdev_info *suspend_devinfo;
+
+int suspend_header_bytes_used = 0;
+

--
Nigel Cunningham		nigel at suspend2 dot net

  parent reply	other threads:[~2006-06-26 22:37 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-26 22:37 [Suspend2][ 00/32] Block i/o patches Nigel Cunningham
2006-06-26 22:37 ` [Suspend2][ 01/32] [Suspend2] Block I/O Header File Nigel Cunningham
2006-06-26 22:37 ` Nigel Cunningham [this message]
2006-06-26 22:37 ` [Suspend2][ 03/32] [Suspend2] Reset block io stats Nigel Cunningham
2006-06-26 22:37 ` [Suspend2][ 04/32] [Suspend2] Check the " Nigel Cunningham
2006-06-26 22:37 ` [Suspend2][ 05/32] [Suspend2] Cleanup one page Nigel Cunningham
2006-06-26 22:37 ` [Suspend2][ 06/32] [Suspend2] Cleanup some completed I/O Nigel Cunningham
2006-06-26 22:37 ` [Suspend2][ 07/32] [Suspend2] Wait for bio completion Nigel Cunningham
2006-06-26 22:37 ` [Suspend2][ 08/32] [Suspend2] Finish and cleanup all outstanding I/O Nigel Cunningham
2006-06-26 22:37 ` [Suspend2][ 09/32] [Suspend2] Wait on a particular page Nigel Cunningham
2006-06-26 22:37 ` [Suspend2][ 10/32] [Suspend2] Wait on readahead Nigel Cunningham
2006-06-26 22:37 ` [Suspend2][ 11/32] [Suspend2] Test whether readahead is ready Nigel Cunningham
2006-06-26 22:37 ` [Suspend2][ 12/32] [Suspend2] Prepare & cleanup readahead pages Nigel Cunningham
2006-06-26 22:37 ` [Suspend2][ 13/32] [Suspend2] Suspend bio completion Nigel Cunningham
2006-06-26 22:37 ` [Suspend2][ 14/32] [Suspend2] Submit io on a page Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 15/32] [Suspend2] Submit batched i/o Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 16/32] [Suspend2] Add page io to a batch Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 17/32] [Suspend2] Get an io_info struct Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 18/32] [Suspend2] Prepare to do i/o on a page Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 19/32] [Suspend2] Do " Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 20/32] [Suspend2] Return memory needed for block io Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 21/32] [Suspend2] Set device info Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 22/32] [Suspend2] Move forward extra blocks in a page Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 23/32] [Suspend2] Advance one page in the extent state Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 24/32] [Suspend2] Set extra page forward flag Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 25/32] [Suspend2] Do io on a page in the image proper Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 26/32] [Suspend2] Read a page of the image Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 27/32] [Suspend2] Init and cleanup routines for pageset i/o Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 28/32] [Suspend2] Write a page in the image proper Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 29/32] [Suspend2] Read or write a chunk of the header Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 30/32] [Suspend2] Finish writing an image header Nigel Cunningham
2006-06-26 22:38 ` [Suspend2][ 31/32] [Suspend2] Suspend block io ops Nigel Cunningham
2006-06-26 22:39 ` [Suspend2][ 32/32] [Suspend2] Module ops for the block i/o functions 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=20060626223711.4376.6781.stgit@nigel.suspend2.net \
    --to=nigel@suspend2.net \
    --cc=linux-kernel@vger.kernel.org \
    /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