Skip to contentSkip to conversation

swsusp: Add support for swap files

PATCH In review Rafael J. Wysocki 6 participants 34 messages Sep 20, 2006 – Sep 23, 2006

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover swsusp: Add support for swap files

Hi,

The following series of patches makes swsusp support swap files.

For now, it is only possible to suspend to a swap file using the in-kernel swsusp and the resume cannot be initiated from an initrd.

Greetings,
Rafael

Signature · 2 lines
You never change things by fighting the existing reality.
		R. Buckminster Fuller
#1 lore raw

PATCH 1/6 swsusp: Use device and offset to intentify swap areas

The Linux kernel handles swap files almost in the same way as it handles swap partitions and there are only two differences between these two types of swap areas:
(1) swap files need not be contiguous,
(2) the header of a swap file is not in the first block of the partition that holds it. From the swsusp's point of view (1) is not a problem, because it is already taken care of by the swap-handling code, but (2) has to be taken into consideration.

In principle the location of a swap file's header may be determined with the help of appropriate filesystem driver. Unfortunately, however, it requires the filesystem holding the swap file to be mounted, and if this filesystem is journaled, it cannot be mounted during a resume from disk. For this reason we need some other means by which swap areas can be identified.

For example, to identify a swap area we can use the partition that holds the area and the offset from the beginning of this partition at which the swap header is located.

The following patch allows swsusp to identify swap areas this way. It changes swap_type_of() so that it takes an additional argument representing an offset of the swap header within the partition represented by its first argument.

---
 include/linux/swap.h |    2 +-
 kernel/power/swap.c  |    2 +-
 kernel/power/user.c  |    5 +++--
 mm/swapfile.c        |   38 ++++++++++++++++++++++++++------------
 4 files changed, 31 insertions(+), 16 deletions(-)
mm/swapfile.c +26 -12
Index: linux-2.6.18-rc7-mm1/mm/swapfile.c
===================================================================
@@ -427,34 +427,48 @@ void free_swap_and_cache(swp_entry_t ent
 
 #ifdef CONFIG_SOFTWARE_SUSPEND
 /*
- * Find the swap type that corresponds to given device (if any)
+ * Find the swap type that corresponds to given device (if any).
  *
- * This is needed for software suspend and is done in such a way that inode
- * aliasing is allowed.
+ * @offset - number of the PAGE_SIZE-sized block of the device, starting
+ * from 0, in which the swap header is expected to be located.
+ *
+ * This is needed for the suspend to disk (aka swsusp).
  */
-int swap_type_of(dev_t device)
+int swap_type_of(dev_t device, sector_t offset)
 {
+	struct block_device *bdev = NULL;
 	int i;
 
+	if (device)
+		bdev = bdget(device);
+
 	spin_lock(&swap_lock);
 	for (i = 0; i < nr_swapfiles; i++) {
-		struct inode *inode;
+		struct swap_info_struct *sis = swap_info + i;
 
-		if (!(swap_info[i].flags & SWP_WRITEOK))
+		if (!(sis->flags & SWP_WRITEOK))
 			continue;
 
-		if (!device) {
+		if (!bdev) {
 			spin_unlock(&swap_lock);
 			return i;
 		}
-		inode = swap_info[i].swap_file->f_dentry->d_inode;
-		if (S_ISBLK(inode->i_mode) &&
-		    device == MKDEV(imajor(inode), iminor(inode))) {
-			spin_unlock(&swap_lock);
-			return i;
+		if (bdev == sis->bdev) {
+			struct swap_extent *se;
+
+			se = list_entry(sis->extent_list.next,
+					struct swap_extent, list);
+			if (se->start_block == offset) {
+				spin_unlock(&swap_lock);
+				bdput(bdev);
+				return i;
+			}
 		}
 	}
 	spin_unlock(&swap_lock);
+	if (bdev)
+		bdput(bdev);
+
 	return -ENODEV;
 }
 
include/linux/swap.h +1 -1
Index: linux-2.6.18-rc7-mm1/include/linux/swap.h
===================================================================
@@ -249,7 +249,7 @@ extern int swap_duplicate(swp_entry_t);
 extern int valid_swaphandles(swp_entry_t, unsigned long *);
 extern void swap_free(swp_entry_t);
 extern void free_swap_and_cache(swp_entry_t);
-extern int swap_type_of(dev_t);
+extern int swap_type_of(dev_t, sector_t);
 extern unsigned int count_swap_pages(int, int);
 extern sector_t map_swap_page(struct swap_info_struct *, pgoff_t);
 extern struct swap_info_struct *get_swap_info_struct(unsigned);
kernel/power/swap.c +1 -1
Index: linux-2.6.18-rc7-mm1/kernel/power/swap.c
===================================================================
@@ -74,7 +74,7 @@ static int mark_swapfiles(swp_entry_t st
 
 static int swsusp_swap_check(void) /* This is called before saving image */
 {
-	int res = swap_type_of(swsusp_resume_device);
+	int res = swap_type_of(swsusp_resume_device, 0);
 
 	if (res >= 0) {
 		root_swap = res;
kernel/power/user.c +3 -2
Index: linux-2.6.18-rc7-mm1/kernel/power/user.c
===================================================================
@@ -54,7 +54,8 @@ static int snapshot_open(struct inode *i
 	filp->private_data = data;
 	memset(&data->handle, 0, sizeof(struct snapshot_handle));
 	if ((filp->f_flags & O_ACCMODE) == O_RDONLY) {
-		data->swap = swsusp_resume_device ? swap_type_of(swsusp_resume_device) : -1;
+		data->swap = swsusp_resume_device ?
+				swap_type_of(swsusp_resume_device, 0) : -1;
 		data->mode = O_RDONLY;
 	} else {
 		data->swap = -1;
@@ -264,7 +265,7 @@ static int snapshot_ioctl(struct inode *
 			 * so we need to recode them
 			 */
 			if (old_decode_dev(arg)) {
-				data->swap = swap_type_of(old_decode_dev(arg));
+				data->swap = swap_type_of(old_decode_dev(arg), 0);
 				if (data->swap < 0)
 					error = -ENODEV;
 			} else {
#2 lore raw

Re: [PATCH -mm 1/6] swsusp: Use device and offset to intentify swap areas

Hi!

Quoted 19 lines

The Linux kernel handles swap files almost in the same way as it handles swap partitions and there are only two differences between these two types of swap areas:
(1) swap files need not be contiguous,
(2) the header of a swap file is not in the first block of the partition that holds it. From the swsusp's point of view (1) is not a problem, because it is already taken care of by the swap-handling code, but (2) has to be taken into consideration.

In principle the location of a swap file's header may be determined with the help of appropriate filesystem driver. Unfortunately, however, it requires the filesystem holding the swap file to be mounted, and if this filesystem is journaled, it cannot be mounted during a resume from disk. For this reason we need some other means by which swap areas can be identified.

For example, to identify a swap area we can use the partition that holds the area and the offset from the beginning of this partition at which the swap header is located.

Quoted 5 lines

The following patch allows swsusp to identify swap areas this way. It changes swap_type_of() so that it takes an additional argument representing an offset of the swap header within the partition represented by its first argument.

ACK.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#3 lore raw

PATCH 2/6 swsusp: Rearrange swap-handling code

In reply to Rafael J. Wysocki

Rearrange the code in kernel/power/swap.c so that the next patch is more readable.

[This patch only moves the existing code.]

---
 kernel/power/swap.c |  219 ++++++++++++++++++++++++++--------------------------
 1 file changed, 111 insertions(+), 108 deletions(-)
kernel/power/swap.c +111 -108
Index: linux-2.6.18-rc7-mm1/kernel/power/swap.c
===================================================================
@@ -41,10 +41,120 @@ static struct swsusp_header {
 } __attribute__((packed, aligned(PAGE_SIZE))) swsusp_header;
 
 /*
- * Saving part...
+ * General things
  */
 
 static unsigned short root_swap = 0xffff;
+static struct block_device *resume_bdev;
+
+/**
+ *	submit - submit BIO request.
+ *	@rw:	READ or WRITE.
+ *	@off	physical offset of page.
+ *	@page:	page we're reading or writing.
+ *	@bio_chain: list of pending biod (for async reading)
+ *
+ *	Straight from the textbook - allocate and initialize the bio.
+ *	If we're reading, make sure the page is marked as dirty.
+ *	Then submit it and, if @bio_chain == NULL, wait.
+ */
+static int submit(int rw, pgoff_t page_off, struct page *page,
+			struct bio **bio_chain)
+{
+	struct bio *bio;
+
+	bio = bio_alloc(GFP_ATOMIC, 1);
+	if (!bio)
+		return -ENOMEM;
+	bio->bi_sector = page_off * (PAGE_SIZE >> 9);
+	bio->bi_bdev = resume_bdev;
+	bio->bi_end_io = end_swap_bio_read;
+
+	if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
+		printk("swsusp: ERROR: adding page to bio at %ld\n", page_off);
+		bio_put(bio);
+		return -EFAULT;
+	}
+
+	lock_page(page);
+	bio_get(bio);
+
+	if (bio_chain == NULL) {
+		submit_bio(rw | (1 << BIO_RW_SYNC), bio);
+		wait_on_page_locked(page);
+		if (rw == READ)
+			bio_set_pages_dirty(bio);
+		bio_put(bio);
+	} else {
+		get_page(page);
+		bio->bi_private = *bio_chain;
+		*bio_chain = bio;
+		submit_bio(rw | (1 << BIO_RW_SYNC), bio);
+	}
+	return 0;
+}
+
+static int bio_read_page(pgoff_t page_off, void *addr, struct bio **bio_chain)
+{
+	return submit(READ, page_off, virt_to_page(addr), bio_chain);
+}
+
+static int bio_write_page(pgoff_t page_off, void *addr)
+{
+	return submit(WRITE, page_off, virt_to_page(addr), NULL);
+}
+
+static int wait_on_bio_chain(struct bio **bio_chain)
+{
+	struct bio *bio;
+	struct bio *next_bio;
+	int ret = 0;
+
+	if (bio_chain == NULL)
+		return 0;
+
+	bio = *bio_chain;
+	if (bio == NULL)
+		return 0;
+	while (bio) {
+		struct page *page;
+
+		next_bio = bio->bi_private;
+		page = bio->bi_io_vec[0].bv_page;
+		wait_on_page_locked(page);
+		if (!PageUptodate(page) || PageError(page))
+			ret = -EIO;
+		put_page(page);
+		bio_put(bio);
+		bio = next_bio;
+	}
+	*bio_chain = NULL;
+	return ret;
+}
+
+static void show_speed(struct timeval *start, struct timeval *stop,
+			unsigned nr_pages, char *msg)
+{
+	s64 elapsed_centisecs64;
+	int centisecs;
+	int k;
+	int kps;
+
+	elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
+	do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
+	centisecs = elapsed_centisecs64;
+	if (centisecs == 0)
+		centisecs = 1;	/* avoid div-by-zero */
+	k = nr_pages * (PAGE_SIZE / 1024);
+	kps = (k * 100) / centisecs;
+	printk("%s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n", msg, k,
+			centisecs / 100, centisecs % 100,
+			kps / 1000, (kps % 1000) / 10);
+}
+
+/*
+ * Saving part
+ */
 
 static int mark_swapfiles(swp_entry_t start)
 {
@@ -166,26 +276,6 @@ static void release_swap_writer(struct s
 	handle->bitmap = NULL;
 }
 
-static void show_speed(struct timeval *start, struct timeval *stop,
-			unsigned nr_pages, char *msg)
-{
-	s64 elapsed_centisecs64;
-	int centisecs;
-	int k;
-	int kps;
-
-	elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
-	do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
-	centisecs = elapsed_centisecs64;
-	if (centisecs == 0)
-		centisecs = 1;	/* avoid div-by-zero */
-	k = nr_pages * (PAGE_SIZE / 1024);
-	kps = (k * 100) / centisecs;
-	printk("%s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n", msg, k,
-			centisecs / 100, centisecs % 100,
-			kps / 1000, (kps % 1000) / 10);
-}
-
 static int get_swap_writer(struct swap_map_handle *handle)
 {
 	handle->cur = (struct swap_map_page *)get_zeroed_page(GFP_KERNEL);
@@ -205,34 +295,6 @@ static int get_swap_writer(struct swap_m
 	return 0;
 }
 
-static int wait_on_bio_chain(struct bio **bio_chain)
-{
-	struct bio *bio;
-	struct bio *next_bio;
-	int ret = 0;
-
-	if (bio_chain == NULL)
-		return 0;
-
-	bio = *bio_chain;
-	if (bio == NULL)
-		return 0;
-	while (bio) {
-		struct page *page;
-
-		next_bio = bio->bi_private;
-		page = bio->bi_io_vec[0].bv_page;
-		wait_on_page_locked(page);
-		if (!PageUptodate(page) || PageError(page))
-			ret = -EIO;
-		put_page(page);
-		bio_put(bio);
-		bio = next_bio;
-	}
-	*bio_chain = NULL;
-	return ret;
-}
-
 static int swap_write_page(struct swap_map_handle *handle, void *buf,
 				struct bio **bio_chain)
 {
@@ -384,65 +446,6 @@ int swsusp_write(void)
 	return error;
 }
 
-static struct block_device *resume_bdev;
-
-/**
- *	submit - submit BIO request.
- *	@rw:	READ or WRITE.
- *	@off	physical offset of page.
- *	@page:	page we're reading or writing.
- *	@bio_chain: list of pending biod (for async reading)
- *
- *	Straight from the textbook - allocate and initialize the bio.
- *	If we're reading, make sure the page is marked as dirty.
- *	Then submit it and, if @bio_chain == NULL, wait.
- */
-static int submit(int rw, pgoff_t page_off, struct page *page,
-			struct bio **bio_chain)
-{
-	struct bio *bio;
-
-	bio = bio_alloc(GFP_ATOMIC, 1);
-	if (!bio)
-		return -ENOMEM;
-	bio->bi_sector = page_off * (PAGE_SIZE >> 9);
-	bio->bi_bdev = resume_bdev;
-	bio->bi_end_io = end_swap_bio_read;
-
-	if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
-		printk("swsusp: ERROR: adding page to bio at %ld\n", page_off);
-		bio_put(bio);
-		return -EFAULT;
-	}
-
-	lock_page(page);
-	bio_get(bio);
-
-	if (bio_chain == NULL) {
-		submit_bio(rw | (1 << BIO_RW_SYNC), bio);
-		wait_on_page_locked(page);
-		if (rw == READ)
-			bio_set_pages_dirty(bio);
-		bio_put(bio);
-	} else {
-		get_page(page);
-		bio->bi_private = *bio_chain;
-		*bio_chain = bio;
-		submit_bio(rw | (1 << BIO_RW_SYNC), bio);
-	}
-	return 0;
-}
-
-static int bio_read_page(pgoff_t page_off, void *addr, struct bio **bio_chain)
-{
-	return submit(READ, page_off, virt_to_page(addr), bio_chain);
-}
-
-static int bio_write_page(pgoff_t page_off, void *addr)
-{
-	return submit(WRITE, page_off, virt_to_page(addr), NULL);
-}
-
 /**
  *	The following functions allow us to read data using a swap map
  *	in a file-alike way
#4 lore raw

Re: [PATCH -mm 2/6] swsusp: Rearrange swap-handling code

Quoted 6 lines · Rafael J. Wysocki

Rearrange the code in kernel/power/swap.c so that the next patch is more readable.

[This patch only moves the existing code.]

ACK.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#5 lore raw

PATCH 3/6 swsusp: Use block device offsets to identify swap locations

In reply to Rafael J. Wysocki

Make swsusp use block device offsets instead of swap offsets to identify swap locations and make it use the same code paths for writing as well as for reading data.

This allows us to use the same code for handling swap files and swap partitions and to simplify the code, eg. by dropping rw_swap_page_sync().

---
 include/linux/swap.h  |    3 -
 kernel/power/power.h  |    2 
 kernel/power/swap.c   |  128 +++++++++++++++++++++++++-------------------------
 kernel/power/swsusp.c |   10 +--
 kernel/power/user.c   |    2 
 mm/page_io.c          |   45 -----------------
 mm/swapfile.c         |   17 ++++++
 7 files changed, 91 insertions(+), 116 deletions(-)
include/linux/swap.h +1 -2
Index: linux-2.6.18-rc7-mm1/include/linux/swap.h
===================================================================
@@ -219,8 +219,6 @@ extern void swap_unplug_io_fn(struct bac
 /* linux/mm/page_io.c */
 extern int swap_readpage(struct file *, struct page *);
 extern int swap_writepage(struct page *page, struct writeback_control *wbc);
-extern int rw_swap_page_sync(int rw, swp_entry_t entry, struct page *page,
-				struct bio **bio_chain);
 extern int end_swap_bio_read(struct bio *bio, unsigned int bytes_done, int err);
 
 /* linux/mm/swap_state.c */
@@ -252,6 +250,7 @@ extern void free_swap_and_cache(swp_entr
 extern int swap_type_of(dev_t, sector_t);
 extern unsigned int count_swap_pages(int, int);
 extern sector_t map_swap_page(struct swap_info_struct *, pgoff_t);
+extern sector_t swapdev_block(int, pgoff_t);
 extern struct swap_info_struct *get_swap_info_struct(unsigned);
 extern int can_share_swap_page(struct page *);
 extern int remove_exclusive_swap_page(struct page *);
mm/swapfile.c +17 -0
Index: linux-2.6.18-rc7-mm1/mm/swapfile.c
===================================================================
@@ -945,6 +945,23 @@ sector_t map_swap_page(struct swap_info_
 	}
 }
 
+#ifdef CONFIG_SOFTWARE_SUSPEND
+/*
+ * Get the (PAGE_SIZE) block corrsponding to given offset on the swapdev
+ * corrsponding to given index in swap_info (swap type).
+ */
+sector_t swapdev_block(int swap_type, pgoff_t offset)
+{
+	struct swap_info_struct *sis;
+
+	if (swap_type >= nr_swapfiles)
+		return 0;
+
+	sis = swap_info + swap_type;
+	return (sis->flags & SWP_WRITEOK) ? map_swap_page(sis, offset) : 0;
+}
+#endif /* CONFIG_SOFTWARE_SUSPEND */
+
 /*
  * Free all of a swapdev's extent information
  */
kernel/power/power.h +1 -1
Index: linux-2.6.18-rc7-mm1/kernel/power/power.h
===================================================================
@@ -141,7 +141,7 @@ struct bitmap_page {
 
 extern void free_bitmap(struct bitmap_page *bitmap);
 extern struct bitmap_page *alloc_bitmap(unsigned int nr_bits);
-extern unsigned long alloc_swap_page(int swap, struct bitmap_page *bitmap);
+extern loff_t alloc_swapdev_block(int swap, struct bitmap_page *bitmap);
 extern void free_all_swap_pages(int swap, struct bitmap_page *bitmap);
 
 extern int swsusp_check(void);
kernel/power/swsusp.c +5 -5
Index: linux-2.6.18-rc7-mm1/kernel/power/swsusp.c
===================================================================
@@ -134,18 +134,18 @@ static int bitmap_set(struct bitmap_page
 	return 0;
 }
 
-unsigned long alloc_swap_page(int swap, struct bitmap_page *bitmap)
+loff_t alloc_swapdev_block(int swap, struct bitmap_page *bitmap)
 {
 	unsigned long offset;
 
 	offset = swp_offset(get_swap_page_of_type(swap));
 	if (offset) {
-		if (bitmap_set(bitmap, offset)) {
+		if (bitmap_set(bitmap, offset))
 			swap_free(swp_entry(swap, offset));
-			offset = 0;
-		}
+		else
+			return swapdev_block(swap, offset);
 	}
-	return offset;
+	return 0;
 }
 
 void free_all_swap_pages(int swap, struct bitmap_page *bitmap)
kernel/power/user.c +1 -1
Index: linux-2.6.18-rc7-mm1/kernel/power/user.c
===================================================================
@@ -239,7 +239,7 @@ static int snapshot_ioctl(struct inode *
 				break;
 			}
 		}
-		offset = alloc_swap_page(data->swap, data->bitmap);
+		offset = alloc_swapdev_block(data->swap, data->bitmap);
 		if (offset) {
 			offset <<= PAGE_SHIFT;
 			error = put_user(offset, (loff_t __user *)arg);
kernel/power/swap.c +66 -62

265 lines not on this page · raw message

mm/page_io.c +0 -45

48 lines not on this page · raw message

#6 lore raw

Re: [PATCH -mm 3/6] swsusp: Use block device offsets to identify swap locations

Hi!

Quoted 8 lines

Make swsusp use block device offsets instead of swap offsets to identify swap locations and make it use the same code paths for writing as well as for reading data.

This allows us to use the same code for handling swap files and swap partitions and to simplify the code, eg. by dropping rw_swap_page_sync().

ACK. You may want to fix the comments, but that's probably separate patch.

mm/swapfile.c sector_t map_swap_page(struct swap_info_ · line 950

Quoted 11 lines

Index: linux-2.6.18-rc7-mm1/mm/swapfile.c
===================================================================

mm/swapfile.c +3 -0
@@ -945,6 +945,23 @@ sector_t map_swap_page(struct swap_info_
 	}
 }
 
+#ifdef CONFIG_SOFTWARE_SUSPEND
+/*
+ * Get the (PAGE_SIZE) block corrsponding to given offset on the swapdev

corresponding?

mm/swapfile.c sector_t map_swap_page(struct swap_info_ · line 951

Quoted 1 line
mm/swapfile.c +1 -0
+ * corrsponding to given index in swap_info (swap type).

here too...

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#7 lore raw

Re: [PATCH -mm 3/6] swsusp: Use block device offsets to identify swap locations

Quoted 29 lines · Pavel Machek

Hi!

Quoted 8 lines

Make swsusp use block device offsets instead of swap offsets to identify swap locations and make it use the same code paths for writing as well as for reading data.

This allows us to use the same code for handling swap files and swap partitions and to simplify the code, eg. by dropping rw_swap_page_sync().

ACK. You may want to fix the comments, but that's probably separate patch.

mm/swapfile.c sector_t map_swap_page(struct swap_info_ · line 950

Quoted 11 lines

Index: linux-2.6.18-rc7-mm1/mm/swapfile.c
===================================================================

mm/swapfile.c +3 -0
@@ -945,6 +945,23 @@ sector_t map_swap_page(struct swap_info_
 	}
 }
 
+#ifdef CONFIG_SOFTWARE_SUSPEND
+/*
+ * Get the (PAGE_SIZE) block corrsponding to given offset on the swapdev

corresponding?

Quoted 3 lines

mm/swapfile.c sector_t map_swap_page(struct swap_info_ · line 951

Quoted 1 line
mm/swapfile.c +1 -0
+ * corrsponding to given index in swap_info (swap type).

here too...

Ouch, thanks.

I think I'll repost the whole series if Andrew doesn't pick it up, because I made a typo in the name of the first patch (shame, shame).

Greetings,
Rafael

Signature · 2 lines
You never change things by fighting the existing reality.
		R. Buckminster Fuller
#8 lore raw

PATCH 4/6 swsusp: Add resume_offset command line parameter

In reply to Rafael J. Wysocki

Add the kernel command line parameter "resume_offset=" allowing us to specify the offset, in <PAGE_SIZE> units, from the beginning of the partition pointed to by the "resume=" parameter at which the swap header is located.

---
kernel/power/disk.c | 15 +++++++++++++++

 kernel/power/power.h |    1 +
 kernel/power/swap.c  |   15 ++++++++++-----
 3 files changed, 26 insertions(+), 5 deletions(-)
kernel/power/disk.c +15 -0
Index: linux-2.6.18-rc7-mm1/kernel/power/disk.c
===================================================================
@@ -27,6 +27,7 @@
 static int noresume = 0;
 char resume_file[256] = CONFIG_PM_STD_PARTITION;
 dev_t swsusp_resume_device;
+sector_t swsusp_resume_block;
 
 /**
  *	power_down - Shut machine down for hibernate.
@@ -404,6 +405,19 @@ static int __init resume_setup(char *str
 	return 1;
 }
 
+static int __init resume_offset_setup(char *str)
+{
+	loff_t offset;
+
+	if (noresume)
+		return 1;
+
+	if (sscanf(str, "%llu", &offset) == 1)
+		swsusp_resume_block = offset;
+
+	return 1;
+}
+
 static int __init noresume_setup(char *str)
 {
 	noresume = 1;
@@ -411,4 +425,5 @@ static int __init noresume_setup(char *s
 }
 
 __setup("noresume", noresume_setup);
+__setup("resume_offset=", resume_offset_setup);
 __setup("resume=", resume_setup);
kernel/power/power.h +1 -0
Index: linux-2.6.18-rc7-mm1/kernel/power/power.h
===================================================================
@@ -42,6 +42,7 @@ extern const void __nosave_begin, __nosa
 extern unsigned long image_size;
 extern int in_suspend;
 extern dev_t swsusp_resume_device;
+extern sector_t swsusp_resume_block;
 
 extern asmlinkage int swsusp_arch_suspend(void);
 extern asmlinkage int swsusp_arch_resume(void);
kernel/power/swap.c +10 -5
Index: linux-2.6.18-rc7-mm1/kernel/power/swap.c
===================================================================
@@ -160,13 +160,14 @@ static int mark_swapfiles(loff_t start)
 {
 	int error;
 
-	bio_read_page(0, &swsusp_header, NULL);
+	bio_read_page(swsusp_resume_block, &swsusp_header, NULL);
 	if (!memcmp("SWAP-SPACE",swsusp_header.sig, 10) ||
 	    !memcmp("SWAPSPACE2",swsusp_header.sig, 10)) {
 		memcpy(swsusp_header.orig_sig,swsusp_header.sig, 10);
 		memcpy(swsusp_header.sig,SWSUSP_SIG, 10);
 		swsusp_header.image = start;
-		error = bio_write_page(0, &swsusp_header, NULL);
+		error = bio_write_page(swsusp_resume_block,
+					&swsusp_header, NULL);
 	} else {
 		printk(KERN_ERR "swsusp: Swap header not found!\n");
 		error = -ENODEV;
@@ -183,7 +184,7 @@ static int swsusp_swap_check(void) /* Th
 {
 	int res;
 
-	res = swap_type_of(swsusp_resume_device, 0);
+	res = swap_type_of(swsusp_resume_device, swsusp_resume_block);
 	if (res < 0)
 		return res;
 
@@ -606,12 +607,16 @@ int swsusp_check(void)
 	if (!IS_ERR(resume_bdev)) {
 		set_blocksize(resume_bdev, PAGE_SIZE);
 		memset(&swsusp_header, 0, sizeof(swsusp_header));
-		if ((error = bio_read_page(0, &swsusp_header, NULL)))
+		error = bio_read_page(swsusp_resume_block,
+					&swsusp_header, NULL);
+		if (error)
 			return error;
+
 		if (!memcmp(SWSUSP_SIG, swsusp_header.sig, 10)) {
 			memcpy(swsusp_header.sig, swsusp_header.orig_sig, 10);
 			/* Reset swap signature now */
-			error = bio_write_page(0, &swsusp_header, NULL);
+			error = bio_write_page(swsusp_resume_block,
+						&swsusp_header, NULL);
 		} else {
 			return -EINVAL;
 		}
#9 lore raw

Re: [PATCH -mm 4/6] swsusp: Add resume_offset command line parameter

Hi!

Quoted 5 lines

Add the kernel command line parameter "resume_offset=" allowing us to specify the offset, in <PAGE_SIZE> units, from the beginning of the partition pointed to by the "resume=" parameter at which the swap header is located.

Okay, I'd prefer not to add aditional features to in-kernel swsusp, but this is just not big enough to reject.

ACK.

(What is the solution for uswsusp?)
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#10 lore raw

Re: [PATCH -mm 4/6] swsusp: Add resume_offset command line parameter

Quoted 6 lines · Pavel Machek

Hi!

Quoted 4 lines

Add the kernel command line parameter "resume_offset=" allowing us to specify the offset, in <PAGE_SIZE> units, from the beginning of the partition pointed to by the "resume=" parameter at which the swap header is located.

Quoted 8 lines
Quoted 1 line

Okay, I'd prefer not to add aditional features to in-kernel swsusp, but this is just not big enough to reject.

ACK.

(What is the solution for uswsusp?)

We need an additional ioctl to set both the swap partition and "resume offset" at a time (the one we currently have allows us only to set the partition and I don't want to change it because of the backwards compatibility, but I think I'll change its name ;-) ).

I'd like to add this ioctl along with the one needed to support the "platform" method of powering off, because it will require some similar documentation changes (most importantly, the description of the interface in Documentation/ABI which I'd like to add once and not to tamper with afterwards).

Greetings,
Rafael

Signature · 2 lines
You never change things by fighting the existing reality.
		R. Buckminster Fuller
#11 lore raw

Re: [PATCH -mm 4/6] swsusp: Add resume_offset command line parameter

Hi!

Quoted 18 lines
Quoted 4 lines
Quoted 4 lines

Add the kernel command line parameter "resume_offset=" allowing us to specify the offset, in <PAGE_SIZE> units, from the beginning of the partition pointed to by the "resume=" parameter at which the swap header is located.

Quoted 8 lines
Quoted 1 line

Okay, I'd prefer not to add aditional features to in-kernel swsusp, but this is just not big enough to reject.

ACK.

(What is the solution for uswsusp?)

We need an additional ioctl to set both the swap partition and "resume offset" at a time (the one we currently have allows us only to set the partition and I don't want to change it because of the backwards compatibility, but I think I'll change its name ;-) ).

Quoted 5 lines

I'd like to add this ioctl along with the one needed to support the "platform" method of powering off, because it will require some similar documentation changes (most importantly, the description of the interface in Documentation/ABI which I'd like to add once and not to tamper with afterwards).

Ok, agreed.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#12 lore raw

PATCH 5/6 mm: Print first block offset for swap areas

In reply to Rafael J. Wysocki

In order to use a swap file with swsusp we need to know the offset at which its swap header is located. However, the swap header is always located in the first block of the swap file and it's quite easy to make sys_swapon() print the offset of the swap file's (or swap partition's) first block.

---
 mm/swapfile.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
mm/swapfile.c +10 -5
Index: linux-2.6.18-rc7-mm1/mm/swapfile.c
===================================================================
@@ -1047,7 +1047,8 @@ add_swap_extent(struct swap_info_struct 
  * This is extremely effective.  The average number of iterations in
  * map_swap_page() has been measured at about 0.3 per page.  - akpm.
  */
-static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span)
+static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span,
+                              sector_t *start)
 {
 	struct inode *inode;
 	unsigned blocks_per_page;
@@ -1060,6 +1061,7 @@ static int setup_swap_extents(struct swa
 	int nr_extents = 0;
 	int ret;
 
+	*start = 0;
 	inode = sis->swap_file->f_mapping->host;
 	if (S_ISBLK(inode->i_mode)) {
 		ret = add_swap_extent(sis, 0, sis->max, 0);
@@ -1114,6 +1116,8 @@ static int setup_swap_extents(struct swa
 				lowest_block = first_block;
 			if (first_block > highest_block)
 				highest_block = first_block;
+		} else {
+			*start = first_block;
 		}
 
 		/*
@@ -1407,7 +1411,7 @@ asmlinkage long sys_swapon(const char __
 	int swap_header_version;
 	unsigned int nr_good_pages = 0;
 	int nr_extents = 0;
-	sector_t span;
+	sector_t span, start;
 	unsigned long maxpages = 1;
 	int swapfilesize;
 	unsigned short *swap_map;
@@ -1608,7 +1612,7 @@ asmlinkage long sys_swapon(const char __
 		p->swap_map[0] = SWAP_MAP_BAD;
 		p->max = maxpages;
 		p->pages = nr_good_pages;
-		nr_extents = setup_swap_extents(p, &span);
+		nr_extents = setup_swap_extents(p, &span, &start);
 		if (nr_extents < 0) {
 			error = nr_extents;
 			goto bad_swap;
@@ -1628,9 +1632,10 @@ asmlinkage long sys_swapon(const char __
 	total_swap_pages += nr_good_pages;
 
 	printk(KERN_INFO "Adding %uk swap on %s.  "
-			"Priority:%d extents:%d across:%lluk\n",
+			"Priority:%d extents:%d across:%lluk offset:%llu\n",
 		nr_good_pages<<(PAGE_SHIFT-10), name, p->prio,
-		nr_extents, (unsigned long long)span<<(PAGE_SHIFT-10));
+		nr_extents, (unsigned long long)span<<(PAGE_SHIFT-10),
+		(unsigned long long)start);
 
 	/* insert swap space into swap_list: */
 	prev = -1;
#13 lore raw

Re: [PATCH -mm 5/6] mm: Print first block offset for swap areas

Quoted 6 lines · Rafael J. Wysocki

In order to use a swap file with swsusp we need to know the offset at which its swap header is located. However, the swap header is always located in the first block of the swap file and it's quite easy to make sys_swapon() print the offset of the swap file's (or swap partition's) first block.

ACK.

(main point of this is that it changes user-visible printk, but that's probably okay, and way better than changing /proc files...)
Pavel

Quoted 13 lines
mm/swapfile.c +3 -2
@@ -1628,9 +1632,10 @@ asmlinkage long sys_swapon(const char __
 	total_swap_pages += nr_good_pages;
 
 	printk(KERN_INFO "Adding %uk swap on %s.  "
-			"Priority:%d extents:%d across:%lluk\n",
+			"Priority:%d extents:%d across:%lluk offset:%llu\n",
 		nr_good_pages<<(PAGE_SHIFT-10), name, p->prio,
-		nr_extents, (unsigned long long)span<<(PAGE_SHIFT-10));
+		nr_extents, (unsigned long long)span<<(PAGE_SHIFT-10),
+		(unsigned long long)start);
 
 	/* insert swap space into swap_list: */
 	prev = -1;
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#14 lore raw

Re: [PATCH -mm 5/6] mm: Print first block offset for swap areas

Quoted 6 lines · Pavel Machek
Quoted 5 lines · Rafael J. Wysocki

In order to use a swap file with swsusp we need to know the offset at which its swap header is located. However, the swap header is always located in the first block of the swap file and it's quite easy to make sys_swapon() print the offset of the swap file's (or swap partition's) first block.

Quoted 6 lines
Quoted 1 line

ACK.

(main point of this is that it changes user-visible printk, but that's probably okay, and way better than changing /proc files...)

As a user-interface, "read the number from dmesg that swapon printk'd and add that to your boot command line" is pretty damned awful. It means that it's next to impossible for a distro installer to support suspend-to-swapfile. It's also incredibly fragile to rely on that file always remaining in that part of the disk.

Dave

#15 lore raw

Re: [PATCH -mm 5/6] mm: Print first block offset for swap areas

Quoted 9 lines · Dave Jones
Quoted 8 lines · Pavel Machek
Quoted 6 lines · Rafael J. Wysocki

In order to use a swap file with swsusp we need to know the offset at which its swap header is located. However, the swap header is always located in the first block of the swap file and it's quite easy to make sys_swapon() print the offset of the swap file's (or swap partition's) first block.

Quoted 7 lines
Quoted 4 lines

ACK.

(main point of this is that it changes user-visible printk, but that's probably okay, and way better than changing /proc files...)

As a user-interface, "read the number from dmesg that swapon printk'd and add that to your boot command line" is pretty damned awful.

Yes, it is. However, the only solution I've invented so far is to print that number in /proc/swaps, but that would be changing the kernel-user interface quite badly ...

Quoted 2 lines

It means that it's next to impossible for a distro installer to support suspend-to-swapfile.

Not necessarily. After creating the swap file the installer can bmap it and figure out the offset from there (it will require some rescaling, but the code for that is in mm/swapfile.c).

Quoted 2 lines

It's also incredibly fragile to rely on that file always remaining in that part of the disk.

Well, if you don't delete it, it'll stay there. ;-)

The entire problem is we can't use file names during resume, because we can't mount filesystems at that time, so we need to represent the swap header's location in a filesystem-independent way.

Greetings,
Rafael

Signature · 2 lines
You never change things by fighting the existing reality.
		R. Buckminster Fuller
#16 lore raw

Re: [PATCH -mm 5/6] mm: Print first block offset for swap areas

Quoted 3 lines

The entire problem is we can't use file names during resume, because we can't mount filesystems at that time, so we need to represent the swap header's location in a filesystem-independent way.

grub reads files without mounting the filesystem. And it has to find the entire file, not just the beginning. Maybe swsusp could use that technique? If not the in-kernel one, surely the userland version could.

Jason

#17 lore raw

Re: [PATCH -mm 5/6] mm: Print first block offset for swap areas

Quoted 8 lines · Jason Lunz
Quoted 3 lines

The entire problem is we can't use file names during resume, because we can't mount filesystems at that time, so we need to represent the swap header's location in a filesystem-independent way.

grub reads files without mounting the filesystem. And it has to find the entire file, not just the beginning. Maybe swsusp could use that technique? If not the in-kernel one, surely the userland version could.

This is filesystem-dependent. AFAICT not all filesystems are supported by GRUB.

Greetings,
Rafael

Signature · 2 lines
You never change things by fighting the existing reality.
		R. Buckminster Fuller
#18 lore raw

Re: [PATCH -mm 5/6] mm: Print first block offset for swap areas

Quoted 2 lines · Rafael J. Wysocki

This is filesystem-dependent. AFAICT not all filesystems are supported by GRUB.

of course, but it shows the technique is viable. Grub is widespread, and if it's good enough for so many x86 users to boot with then the same approach ought to be adequate for resume, no?

Jason

#19 lore raw

Re: [PATCH -mm 5/6] mm: Print first block offset for swap areas

Quoted 7 lines · Jason Lunz
Quoted 2 lines · Rafael J. Wysocki

This is filesystem-dependent. AFAICT not all filesystems are supported by GRUB.

of course, but it shows the technique is viable. Grub is widespread, and if it's good enough for so many x86 users to boot with then the same approach ought to be adequate for resume, no?

Well, most people "solve" this by having their boot partition on ext2, no?

Anyway, yes, you can do libext2 magic... in uswsusp..

Or you can just patch "real_read_only" mode to journalling filesystem. That should be easy enough, and that patch would be welcome for other reasons (data recovery), too. Please do it :-).
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#20 lore raw

Re: [PATCH -mm 5/6] mm: Print first block offset for swap areas

Quoted 2 lines

Well, most people "solve" this by having their boot partition on ext2, no?

my grub appears to handle ext2/3, reiser3, xfs, jfs, fat, and minix.

Quoted 1 line

Anyway, yes, you can do libext2 magic... in uswsusp..

a hybrid approach might work, with grub-like support for common filesystems and the ability to specify the resume_offset on the kernel command line as a fallback.

Jason

#21 lore raw

Re: [PATCH -mm 5/6] mm: Print first block offset for swap areas

Quoted 9 lines · Jason Lunz
Quoted 2 lines

Well, most people "solve" this by having their boot partition on ext2, no?

my grub appears to handle ext2/3, reiser3, xfs, jfs, fat, and minix.

Quoted 1 line

Anyway, yes, you can do libext2 magic... in uswsusp..

a hybrid approach might work, with grub-like support for common filesystems and the ability to specify the resume_offset on the kernel command line as a fallback.

Let's do "realreadonly" instead. It is right thing to do.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#22 lore raw

Re: [PATCH -mm 5/6] mm: Print first block offset for swap areas

In reply to Jason Lunz
Quoted 7 lines · Jason Lunz
Quoted 2 lines · Rafael J. Wysocki

This is filesystem-dependent. AFAICT not all filesystems are supported by GRUB.

of course, but it shows the technique is viable. Grub is widespread, and if it's good enough for so many x86 users to boot with then the same approach ought to be adequate for resume, no?

Well, I'd like to avoid making _any_ assumptions regarding the partition on which the "resume" swap file is located.

Also I think we can implement a simpler approach (ie. one that requires less code changes in both the kernel and userland) first and then look for a "nicer" one.

Greetings,
Rafael

Signature · 2 lines
You never change things by fighting the existing reality.
		R. Buckminster Fuller
#23 lore raw

Re: [PATCH -mm 5/6] mm: Print first block offset for swap areas

Hi!

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

This is filesystem-dependent. AFAICT not all filesystems are supported by GRUB.

of course, but it shows the technique is viable. Grub is widespread, and if it's good enough for so many x86 users to boot with then the same approach ought to be adequate for resume, no?

Quoted 6 lines

Well, I'd like to avoid making _any_ assumptions regarding the partition on which the "resume" swap file is located.

Also I think we can implement a simpler approach (ie. one that requires less code changes in both the kernel and userland) first and then look for a "nicer" one.

Agreed.

(And someone else can create those "realreadonly" patches in the meantime.)
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#24 lore raw

PATCH 6/6 swsusp: Document support for swap files

In reply to Rafael J. Wysocki

Document the "resume_offset=" command line parameter as well as the way in which swap files are supported by swsusp.

---
 Documentation/kernel-parameters.txt           |    6 +++
 Documentation/power/swsusp-and-swap-files.txt |   46 ++++++++++++++++++++++++++
 Documentation/power/swsusp.txt                |   20 +++--------
 3 files changed, 58 insertions(+), 14 deletions(-)
Documentation/kernel-parameters.txt +6 -0
Index: linux-2.6.18-rc7-mm1/Documentation/kernel-parameters.txt
===================================================================
@@ -1370,6 +1370,12 @@ and is between 256 and 4096 characters. 
 	resume=		[SWSUSP]
 			Specify the partition device for software suspend
 
+	resume_offset=	[SWSUSP]
+			Specify the offset from the beginning of the partition
+			given by "resume=" at which the swap header is located,
+			in <PAGE_SIZE> units (needed only for swap files).
+			See  Documentation/power/swsusp-and-swap-files.txt
+
 	rhash_entries=	[KNL,NET]
 			Set number of hash buckets for route cache
 
Documentation/power/swsusp-and-swap-files.txt new file +46 -0

46 lines not on this page · raw message

Documentation/power/swsusp.txt +5 -13
Index: linux-2.6.18-rc7-mm1/Documentation/power/swsusp.txt
===================================================================
@@ -297,20 +297,12 @@ system is shut down or suspended. Additi
 suspend image to prevent sensitive data from being stolen after
 resume.
 
-Q: Why can't we suspend to a swap file?
+Q: Can I suspend to a swap file?
 
-A: Because accessing swap file needs the filesystem mounted, and
-filesystem might do something wrong (like replaying the journal)
-during mount.
-
-There are few ways to get that fixed:
-
-1) Probably could be solved by modifying every filesystem to support
-some kind of "really read-only!" option. Patches welcome.
-
-2) suspend2 gets around that by storing absolute positions in on-disk
-image (and blocksize), with resume parameter pointing directly to
-suspend header.
+A: Generally, yes, you can.  However, it requires you to use the "resume=" and
+"resume_offset=" kernel command line parameters, so the resume from a swap file
+cannot be initiated from an initrd or initramfs image.  See
+swsusp-and-swap-files.txt for details.
 
 Q: Is there a maximum system RAM size that is supported by swsusp?
 
#25 lore raw

Re: [PATCH -mm 6/6] swsusp: Document support for swap files

Hi!

Quoted 4 lines

Document the "resume_offset=" command line parameter as well as the way in which swap files are supported by swsusp.

ACK and thanks!
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#26 lore raw
In reply to Rafael J. Wysocki

Hi.

Quoted 6 lines · Rafael J. Wysocki

Hi,

The following series of patches makes swsusp support swap files.

For now, it is only possible to suspend to a swap file using the in-kernel swsusp and the resume cannot be initiated from an initrd.

I'm trying to understand 'resume cannot be initiated from an initrd'. Does that mean if you want to use this functionality, you have to have everything needed compiled in to the kernel, and it's not compatible with LVM and so on?

Regards,

Nigel

#27 lore raw
Quoted 7 lines · Nigel Cunningham

Hi.

Quoted 4 lines · Rafael J. Wysocki

Hi,

The following series of patches makes swsusp support swap files.

Quoted 7 lines
Quoted 2 lines

For now, it is only possible to suspend to a swap file using the in-kernel swsusp and the resume cannot be initiated from an initrd.

I'm trying to understand 'resume cannot be initiated from an initrd'. Does that mean if you want to use this functionality, you have to have everything needed compiled in to the kernel, and it's not compatible with LVM and so on?

Not in this version of patch; for resume from initrd, ioctl() interface needs to be added (*).
Pavel
(*) Actually.. of course resume from file from initrd is possible *now*, probably without this patch series, but that would be bmap and doing it by hand from userland.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#28 lore raw
Quoted 11 lines · Pavel Machek
Quoted 10 lines · Nigel Cunningham

Hi.

Quoted 6 lines · Rafael J. Wysocki

Hi,

The following series of patches makes swsusp support swap files.

For now, it is only possible to suspend to a swap file using the in-kernel swsusp and the resume cannot be initiated from an initrd.

Quoted 7 lines
Quoted 4 lines

I'm trying to understand 'resume cannot be initiated from an initrd'. Does that mean if you want to use this functionality, you have to have everything needed compiled in to the kernel, and it's not compatible with LVM and so on?

Not in this version of patch; for resume from initrd, ioctl() interface needs to be added (*).

Yup. This is not technically impossible, but the patches don't add an interface needed for this purpose.

Initially I thought of a sysfs-based one, but it didn't seem to be a good solution. I'm going to add an ioctl() to /dev/snapshot that will allow us to set the "resume offset" from an application.

Quoted 4 lines

Pavel
(*) Actually.. of course resume from file from initrd is possible *now*, probably without this patch series, but that would be bmap and doing it by hand from userland.

Well, not from a swap file. To use a swap file for suspending we need a kernel to tell us which page "slots" are available to us (otherwise we could overwrite some swapped-out pages).

We could use a regular (non-swap) file like this but that would require us to use some dangerous code (ie. one that writes directly to blocks belonging to certain file bypassing the filesystem). IMHO this isn't worth it, provided the kernel's swap-handling code can do this for us and is known to work. ;-)

Greetings,
Rafael

Signature · 2 lines
You never change things by fighting the existing reality.
		R. Buckminster Fuller
#29 lore raw

Hi.

Quoted 32 lines · Rafael J. Wysocki
Quoted 11 lines · Pavel Machek
Quoted 10 lines · Nigel Cunningham

Hi.

Quoted 6 lines · Rafael J. Wysocki

Hi,

The following series of patches makes swsusp support swap files.

For now, it is only possible to suspend to a swap file using the in-kernel swsusp and the resume cannot be initiated from an initrd.

Quoted 7 lines
Quoted 4 lines

I'm trying to understand 'resume cannot be initiated from an initrd'. Does that mean if you want to use this functionality, you have to have everything needed compiled in to the kernel, and it's not compatible with LVM and so on?

Not in this version of patch; for resume from initrd, ioctl() interface needs to be added (*).

Yup. This is not technically impossible, but the patches don't add an interface needed for this purpose.

Initially I thought of a sysfs-based one, but it didn't seem to be a good solution. I'm going to add an ioctl() to /dev/snapshot that will allow us to set the "resume offset" from an application.
problem I not

Quoted 4 lines

Pavel
(*) Actually.. of course resume from file from initrd is possible *now*, probably without this patch series, but that would be bmap and doing it by hand from userland.

Quoted 8 lines

Well, not from a swap file. To use a swap file for suspending we need a kernel to tell us which page "slots" are available to us (otherwise we could overwrite some swapped-out pages).

We could use a regular (non-swap) file like this but that would require us to use some dangerous code (ie. one that writes directly to blocks belonging to certain file bypassing the filesystem). IMHO this isn't worth it, provided the kernel's swap-handling code can do this for us and is known to work. ;-)

It's not that dangerous once you debug it. This is what Suspend2 does - all I/O is done using bmapping and bios with direct sector numbers, regardless of where you're reading from/writing to. The main difficulty I saw was with XFS, where the device block size and filesystem block size can differ, but even then, it's just a matter of making sure you get the right one in the right place.

I would encourage you in this direction because it also adds way more flexibility. If swap is a thing of the past, the only reason for people to have swap space now is to suspend to disk. If you can write to a swap file, they don't need a swap partition and more. If you can write to an ordinary file, they can know that even if they are in a low memory situation and swap is being used, there's no race condition between freeing up memory to meet the conditions for suspending to disk, and allocating storage for writing the actual image.

Regards,

Nigel

#30 lore raw

Hi,

Quoted 39 lines · Nigel Cunningham

Hi.

Quoted 36 lines · Rafael J. Wysocki
Quoted 11 lines · Pavel Machek
Quoted 10 lines · Nigel Cunningham

Hi.

Quoted 6 lines · Rafael J. Wysocki

Hi,

The following series of patches makes swsusp support swap files.

For now, it is only possible to suspend to a swap file using the in-kernel swsusp and the resume cannot be initiated from an initrd.

Quoted 7 lines
Quoted 4 lines

I'm trying to understand 'resume cannot be initiated from an initrd'. Does that mean if you want to use this functionality, you have to have everything needed compiled in to the kernel, and it's not compatible with LVM and so on?

Not in this version of patch; for resume from initrd, ioctl() interface needs to be added (*).

Yup. This is not technically impossible, but the patches don't add an interface needed for this purpose.

Initially I thought of a sysfs-based one, but it didn't seem to be a good solution. I'm going to add an ioctl() to /dev/snapshot that will allow us to set the "resume offset" from an application.
problem I not

Quoted 4 lines

Pavel
(*) Actually.. of course resume from file from initrd is possible *now*, probably without this patch series, but that would be bmap and doing it by hand from userland.

Well, not from a swap file. To use a swap file for suspending we need a kernel to tell us which page "slots" are available to us (otherwise we could overwrite some swapped-out pages).

Quoted 6 lines
Quoted 4 lines

We could use a regular (non-swap) file like this but that would require us to use some dangerous code (ie. one that writes directly to blocks belonging to certain file bypassing the filesystem). IMHO this isn't worth it, provided the kernel's swap-handling code can do this for us and is known to work. ;-)

It's not that dangerous once you debug it.

Certainly. Still, let me repeat: if there is some code that does pretty much the same and has _already_ been debugged, I prefer using it to writing some new code, debugging it etc.

Quoted 11 lines

This is what Suspend2 does -
all I/O is done using bmapping and bios with direct sector numbers, regardless of where you're reading from/writing to. The main difficulty I saw was with XFS, where the device block size and filesystem block size can differ, but even then, it's just a matter of making sure you get the right one in the right place.

I would encourage you in this direction because it also adds way more flexibility. If swap is a thing of the past, the only reason for people to have swap space now is to suspend to disk. If you can write to a swap file, they don't need a swap partition and more.

Obviously. That's what the patches are for. :-)

Quoted 5 lines

If you can write to an
ordinary file, they can know that even if they are in a low memory situation and swap is being used, there's no race condition between freeing up memory to meet the conditions for suspending to disk, and allocating storage for writing the actual image.

Well, I wouldn't call that a race condition.

By using an ordinary file to save the suspend image, you effectively divide the whole storage needed for suspending in two independent parts. Still the sum of these two parts has to be sufficient to save the total amount of data that cannot be discarded residing in memory before the suspend. IMO it doesn't really matter if this storage is divided or not, because to total size of it has to be sufficient regardless.

Greetings,
Rafael

Signature · 2 lines
You never change things by fighting the existing reality.
		R. Buckminster Fuller
#31 lore raw

Hi.

Quoted 10 lines · Rafael J. Wysocki
Quoted 6 lines
Quoted 4 lines

We could use a regular (non-swap) file like this but that would require us to use some dangerous code (ie. one that writes directly to blocks belonging to certain file bypassing the filesystem). IMHO this isn't worth it, provided the kernel's swap-handling code can do this for us and is known to work. ;-)

It's not that dangerous once you debug it.

Certainly. Still, let me repeat: if there is some code that does pretty much the same and has _already_ been debugged, I prefer using it to writing some new code, debugging it etc.

Look at Suspend2 then. I know you won't want it in exactly that form, but it's there and have been tested and debugged.

Quoted 14 lines
Quoted 11 lines

This is what Suspend2 does -
all I/O is done using bmapping and bios with direct sector numbers, regardless of where you're reading from/writing to. The main difficulty I saw was with XFS, where the device block size and filesystem block size can differ, but even then, it's just a matter of making sure you get the right one in the right place.

I would encourage you in this direction because it also adds way more flexibility. If swap is a thing of the past, the only reason for people to have swap space now is to suspend to disk. If you can write to a swap file, they don't need a swap partition and more.

Obviously. That's what the patches are for. :-)

Quoted 7 lines
Quoted 5 lines

If you can write to an
ordinary file, they can know that even if they are in a low memory situation and swap is being used, there's no race condition between freeing up memory to meet the conditions for suspending to disk, and allocating storage for writing the actual image.

Well, I wouldn't call that a race condition.

You want to write the image to swap (any kind) but you need to use swap to free up enough memory so that you can make the image and write it. But wait, in freeing enough memory, you reduced the amount of swap available for your image, so now you need to free more...

Quoted 6 lines

By using an ordinary file to save the suspend image, you effectively divide the whole storage needed for suspending in two independent parts. Still the sum of these two parts has to be sufficient to save the total amount of data that cannot be discarded residing in memory before the suspend. IMO it doesn't really matter if this storage is divided or not, because to total size of it has to be sufficient regardless.

You're forgetting, I think, that for Suspend2, we're not usually swapping anything out. It would only be under very unusual memory load that we'd be swapping memory out, and that would only be after caches were discarded, which would probably address the situation itself. There's therefore no division of the image.

Regards,

Nigel

#32 lore raw

Hi!

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

We could use a regular (non-swap) file like this but that would require us to use some dangerous code (ie. one that writes directly to blocks belonging to certain file bypassing the filesystem). IMHO this isn't worth it, provided the kernel's swap-handling code can do this for us and is known to work. ;-)

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

It's not that dangerous once you debug it.

Certainly. Still, let me repeat: if there is some code that does pretty much the same and has _already_ been debugged, I prefer using it to writing some new code, debugging it etc.

Look at Suspend2 then. I know you won't want it in exactly that form, but it's there and have been tested and debugged.

Well, but any testing/debugging would have to be invalidated for a merge, sorry. suspend2 has diverged too much.

"normal files" are not big priority for us, and you could probably do them in userland just now.... Anyway, diff -u for kernel or preferably for uswsusp parts would be welcome.

Telling us how much suspend2 rocks with each and every mail... is not that welcome.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#33 lore raw

Hi.

Quoted 19 lines · Pavel Machek

Hi!

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

We could use a regular (non-swap) file like this but that would require us to use some dangerous code (ie. one that writes directly to blocks belonging to certain file bypassing the filesystem). IMHO this isn't worth it, provided the kernel's swap-handling code can do this for us and is known to work. ;-)

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

It's not that dangerous once you debug it.

Certainly. Still, let me repeat: if there is some code that does pretty much the same and has _already_ been debugged, I prefer using it to writing some new code, debugging it etc.

Look at Suspend2 then. I know you won't want it in exactly that form, but it's there and have been tested and debugged.

Well, but any testing/debugging would have to be invalidated for a merge, sorry. suspend2 has diverged too much.

Quoted 6 lines

"normal files" are not big priority for us, and you could probably do them in userland just now.... Anyway, diff -u for kernel or preferably for uswsusp parts would be welcome.

Telling us how much suspend2 rocks with each and every mail... is not that welcome.

That's not what I was doing. I was saying that Rafael could, if he wanted, at least look at how Suspend2 has done it and use that (if he thinks its helpful) as a basis for improving or whatever. If he does essentially the same thing for swsusp, he could again look at suspend2 loops etc to help in double checking his algorithm and so on.

Regards,

Nigel