2006-10-31 03:42:51

by John Richard Moser

[permalink] [raw]
Subject: Suspend to disk: do we HAVE to use swap?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Something dumb came into my head, and the question is thus brought up
here: Do we HAVE to use swap for suspend to disk? How about the file
system?

[ Another thought I had here was where the word 'we' comes from; it
seems habitual. I'm not writing any of this code! ]

The first thought that came to my mind was: The file system may not be
in a stable state. If we don't use swap we're obviously using the FS;
so it has to be safe to mount. Simple solution: suspend to disk should
trigger the FS drivers to flush their state to disk and tie things off.
Thus when we begin suspend things are suspended; the drivers know that
the only files to be created are the ones the kernel will make; and it's
safe for us to allocate space and make files, because we can read them
later.

This brings another thought: If we use files, we have to do the above
so the disk can be mounted and read later. This means the disk can be
mounted read-write by a LiveCD or other OS or whatever between--safely.
So then, what do we do about changing files? Files open and mmap()'d
are a huge problem if someone messes with them; solutions for this I do
not have, perhaps store the page cache as well.

So another thought: What happens if we use the file system? The kernel
goes and gets.. what? Do we come up with the FS in read-only mode (from
an initrd or booting, either way) and have userspace tools tell the
kernel to resume from a given file?

And further, what if you change kernel versions? Can we embed the
kernel version in the suspend image and get the kexec framework to load
that? Have it bootstrap itself in and get to work resuming?

How about compressed images? Can the suspend image be compressed as
it's stored, decompressed as it's read?

And, of course, WHY would you use a file on the file system instead of
swap? This is probably the easiest and most straightforward question.
If you have 4 gigs of RAM, you might not want 4 gigs of swap. Maybe you
have 256M of swap and 1 gig of ram. Not much choice here.

Anyway, just random thoughts rolled out there in case anyone needs a
random seed.
- --
We will enslave their women, eat their children and rape their
cattle!
-- Bosc, Evil alien overlord from the fifth dimension
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIVAwUBRUbGNgs1xW0HCTEFAQLaog//Z6c1KdRQxlc0B2GpRJSuyblVLBNmwK9n
IPMN+HA6c7u3EAiKq2PVVFUA1mhL/cyfnabG/p23sBKjdwZTodBDxMFw9y/SXa4k
g36mXsXOopZrUXmOJi0y0T/L96+iEzwr5Z++sMaybB5E9tsXKJiXmMwtEjc+HbEj
MW+ZGHTKcGqtei8OunvLkKSlCt3aaqwMWc5j3CM1gRODyShfY/NOeJTbGZG3fERB
25Gfa/KbCQVrgnhbyAyX+BggBkKHaw4tl6ari529JidkE1eie1O1zO8TlMi+rRmb
BgO6uZDWtZUTgKN662uamVHN5RvYW0QC1AqCDljKibQYZrtkoMN6AHZv+rp0z0G/
CcIld8ywgMOjcKK+8jKtYi9UUqkxgqIRH1IidRGgI7GKZqAqt357b6HTA2UxL59D
Gp0Z3/GgJqZBnb71wZLob/eTDC6hRzEmj7LJYZS//dYEkgD5aSA1NLulYuFoDEp5
eIOctN5GsHw0Gq90m/Oy24qPdgrm9J9wTE4eAEPLam3WKjZa9yo5Woq4lALwOda9
exsYDWzXD/EXekVM648673igfnZvcqN9lGavpfwOJaAIaMYKPX55suk1Kp9ZbFVQ
Wl1cBGmQ1Dpnlf6M0BVLi3jyUsUJy2AH/hRGhIYL+r8DzlffNI5ibLuCyMfoKwge
jMx6FuzqBKk=
=hpQy
-----END PGP SIGNATURE-----


2006-10-31 06:18:12

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

On Tuesday, 31 October 2006 04:42, John Richard Moser wrote:
> Something dumb came into my head, and the question is thus brought up
> here: Do we HAVE to use swap for suspend to disk? How about the file
> system?

In short, we could use regular files for the suspend in the same way in which we
use them for swap. Namely, we could bmap() a file and create a map of it
(eg. with extents) that would be used for accessing the corresponding disk
sectors at the block device level. Then, to be able to read the image the
resume code would have to be provided with the number of the sector in which
the suspend image header is located.

However, we already have code that allows us to use swap files for the suspend
and turning a regular file into a swap file is as easy as running 'mkswap' and
'swapon' on it.

Greetings,
Rafael


--
You never change things by fighting the existing reality.
R. Buckminster Fuller

2006-10-31 06:31:52

by John Richard Moser

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Rafael J. Wysocki wrote:
> On Tuesday, 31 October 2006 04:42, John Richard Moser wrote:
>> Something dumb came into my head, and the question is thus brought up
>> here: Do we HAVE to use swap for suspend to disk? How about the file
>> system?
>
> In short, we could use regular files for the suspend in the same way in which we
> use them for swap. Namely, we could bmap() a file and create a map of it
> (eg. with extents) that would be used for accessing the corresponding disk
> sectors at the block device level. Then, to be able to read the image the
> resume code would have to be provided with the number of the sector in which
> the suspend image header is located.
>
> However, we already have code that allows us to use swap files for the suspend
> and turning a regular file into a swap file is as easy as running 'mkswap' and
> 'swapon' on it.

And the kernel can survive being loaded, mounting a file system
readonly, activating swapon on the swap file on the read-only file
system, and then resuming from it?

Also, the file system is consistent after a suspend to disk?

I believe I mentioned something about compressing the image as well...
>
> Greetings,
> Rafael
>
>

- --
We will enslave their women, eat their children and rape their
cattle!
-- Bosc, Evil alien overlord from the fifth dimension
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIVAwUBRUbt0gs1xW0HCTEFAQL4nA/+JA7j+FHtmXYl2w/RpN/mZ+EMam++ippS
ildPeg/EsjdFLrc2SjmsteaPfCGokbLdA6WHwa5Uq+JB1Itu4rBLPRzvhVftm01V
XcYfInILhRNCGeGujF4P/NMFQBOPjPl1UqC+H/yehsVtj0I73ZMRDrdtI62+KWGL
ekaGKHb5rC3D0mdFOg/7ycplFbTLJii5Szn2KeHjd6+88LKbySLKv9SMPe6bMPPb
rzmy9+dzy3X/mMnWckxKyf6jFYkOXsI0GeNe/gb6Ylnpr6qNPJCPrY3MLSFKHPOA
Z7jBdS3w+glQhO0dUcsDSd9waPeOZNWGoJbq1FJIOMUiOU7fkoHVH7CNGGT+MccH
Qb8QxGhZUec77LmBAEKzpTi4R40QlHJaNHVip0NtOrTTupg+3J7SfDcDZ9frCRWa
hAs0/0sZV8y3ADtCf2bEOijj7zeLWRwSjTkj4fhXqcxlhEk030mKroYkohBGPIli
oVxRZq7nG4nY+dgNAxDCzFkyOEP5ObVq6dy7JPHfGOdPjy3gJy8cL/Y/6HxvzZIj
apHJznqz5+Bi7hFjG80++n7AzsM3RYzdWAh2OlcDM/jgZu7BypsGZ9QMkqTj6eDk
/Q11y+aj5+x4iYL2r+YrYlkhS3TIi2SUud05e8f87Di6nXiJfKLoFq6D6enU3v9M
xJ5l88pMfkQ=
=fs+p
-----END PGP SIGNATURE-----

2006-10-31 06:40:43

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

On Tuesday, 31 October 2006 07:31, John Richard Moser wrote:
>
> Rafael J. Wysocki wrote:
> > On Tuesday, 31 October 2006 04:42, John Richard Moser wrote:
> >> Something dumb came into my head, and the question is thus brought up
> >> here: Do we HAVE to use swap for suspend to disk? How about the file
> >> system?
> >
> > In short, we could use regular files for the suspend in the same way in which we
> > use them for swap. Namely, we could bmap() a file and create a map of it
> > (eg. with extents) that would be used for accessing the corresponding disk
> > sectors at the block device level. Then, to be able to read the image the
> > resume code would have to be provided with the number of the sector in which
> > the suspend image header is located.
> >
> > However, we already have code that allows us to use swap files for the suspend
> > and turning a regular file into a swap file is as easy as running 'mkswap' and
> > 'swapon' on it.
>
> And the kernel can survive being loaded, mounting a file system
> readonly, activating swapon on the swap file on the read-only file
> system, and then resuming from it?

The swap file is not activated during the resume before the suspend image
is read from it. That's why we need the number of the sector in which the
suspend image header is located.

> Also, the file system is consistent after a suspend to disk?

Yes, it is.

> I believe I mentioned something about compressing the image as well...

If you need to compress the image during the suspend, please visit
eg. http://suspend.sf.net (it is recommended to use the latest CVS).

Greetings,
Rafael


--
You never change things by fighting the existing reality.
R. Buckminster Fuller

2006-10-31 13:49:05

by Alistair John Strachan

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

On Tuesday 31 October 2006 06:16, Rafael J. Wysocki wrote:
[snip]
> However, we already have code that allows us to use swap files for the
> suspend and turning a regular file into a swap file is as easy as running
> 'mkswap' and 'swapon' on it.

How is this feature enabled? I don't see it in 2.6.19-rc4.

--
Cheers,
Alistair.

Final year Computer Science undergraduate.
1F2 55 South Clerk Street, Edinburgh, UK.

2006-10-31 17:40:12

by Luca Tettamanti

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

Alistair John Strachan <[email protected]> ha scritto:
> On Tuesday 31 October 2006 06:16, Rafael J. Wysocki wrote:
> [snip]
>> However, we already have code that allows us to use swap files for the
>> suspend and turning a regular file into a swap file is as easy as running
>> 'mkswap' and 'swapon' on it.
>
> How is this feature enabled? I don't see it in 2.6.19-rc4.

Swap files have been supported for ages. suspend-to-swapfile is very
new, you need a -mm kernel and userspace suspend from CVS:
http://suspend.sf.net

Luca
--
"Sei l'unica donna della mia vita".
(Adamo)

2006-10-31 19:05:38

by Alistair John Strachan

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

On Tuesday 31 October 2006 17:40, Luca Tettamanti wrote:
> Alistair John Strachan <[email protected]> ha scritto:
> > On Tuesday 31 October 2006 06:16, Rafael J. Wysocki wrote:
> > [snip]
> >
> >> However, we already have code that allows us to use swap files for the
> >> suspend and turning a regular file into a swap file is as easy as
> >> running 'mkswap' and 'swapon' on it.
> >
> > How is this feature enabled? I don't see it in 2.6.19-rc4.
>
> Swap files have been supported for ages. suspend-to-swapfile is very
> new, you need a -mm kernel and userspace suspend from CVS:
> http://suspend.sf.net

I know, I use swap files, and not a partition. This has prevented me from
using suspend to disk "for ages". ;-)

Is userspace suspend REQUIRED for this feature?

--
Cheers,
Alistair.

Final year Computer Science undergraduate.
1F2 55 South Clerk Street, Edinburgh, UK.

2006-10-31 19:21:23

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

On Tuesday, 31 October 2006 20:05, Alistair John Strachan wrote:
> On Tuesday 31 October 2006 17:40, Luca Tettamanti wrote:
> > Alistair John Strachan <[email protected]> ha scritto:
> > > On Tuesday 31 October 2006 06:16, Rafael J. Wysocki wrote:
> > > [snip]
> > >
> > >> However, we already have code that allows us to use swap files for the
> > >> suspend and turning a regular file into a swap file is as easy as
> > >> running 'mkswap' and 'swapon' on it.
> > >
> > > How is this feature enabled? I don't see it in 2.6.19-rc4.
> >
> > Swap files have been supported for ages. suspend-to-swapfile is very
> > new, you need a -mm kernel and userspace suspend from CVS:
> > http://suspend.sf.net
>
> I know, I use swap files, and not a partition. This has prevented me from
> using suspend to disk "for ages". ;-)
>
> Is userspace suspend REQUIRED for this feature?

No, but unfortunately one piece is still missing: You'll need to figure out
where your swap file's header is located.

However, if you apply the attached patch the kernel will tell you where it is
(after you do 'swapon' grep dmesg for 'swap' and use the value in the
'offset' field).

Please read Documentation/power/swsusp-and-swap-files.txt before you begin.

Greetings,
Rafael


--
You never change things by fighting the existing reality.
R. Buckminster Fuller


Attachments:
(No filename) (1.31 kB)
mm-print-offset-for-swap-files.patch (2.24 kB)
Download all attachments

2006-10-31 19:41:15

by John Richard Moser

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Rafael J. Wysocki wrote:
> On Tuesday, 31 October 2006 20:05, Alistair John Strachan wrote:
>> On Tuesday 31 October 2006 17:40, Luca Tettamanti wrote:
>>> Alistair John Strachan <[email protected]> ha scritto:
>>>> On Tuesday 31 October 2006 06:16, Rafael J. Wysocki wrote:
>>>> [snip]
>>>>
>>>>> However, we already have code that allows us to use swap files for the
>>>>> suspend and turning a regular file into a swap file is as easy as
>>>>> running 'mkswap' and 'swapon' on it.
>>>> How is this feature enabled? I don't see it in 2.6.19-rc4.
>>> Swap files have been supported for ages. suspend-to-swapfile is very
>>> new, you need a -mm kernel and userspace suspend from CVS:
>>> http://suspend.sf.net
>> I know, I use swap files, and not a partition. This has prevented me from
>> using suspend to disk "for ages". ;-)
>>
>> Is userspace suspend REQUIRED for this feature?
>
> No, but unfortunately one piece is still missing: You'll need to figure out
> where your swap file's header is located.
>
> However, if you apply the attached patch the kernel will tell you where it is
> (after you do 'swapon' grep dmesg for 'swap' and use the value in the
> 'offset' field).

Nobody has answered this one yet: Once you 'swapon' doesn't the kernel
have (require?) the swap file opened writable? Simple mode:

IS THIS NOT EXTREMELY DANGEROUS?

>
> Please read Documentation/power/swsusp-and-swap-files.txt before you begin.
>
> Greetings,
> Rafael
>
>
>
>
> ------------------------------------------------------------------------
>
> ---
> mm/swapfile.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> Index: linux-2.6.18-rc6-mm2/mm/swapfile.c
> ===================================================================
> --- linux-2.6.18-rc6-mm2.orig/mm/swapfile.c
> +++ linux-2.6.18-rc6-mm2/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;

- --
We will enslave their women, eat their children and rape their
cattle!
-- Bosc, Evil alien overlord from the fifth dimension
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIVAwUBRUem1Qs1xW0HCTEFAQJfoA//QUbG6qptY4D0BMqBqq/v6BZugVVznVvf
vGsmdh9vE8ZbeVYsXbLqA4twMziI+1FkH+1f2PyYahd1zSyEqqi9V1i7hLVL1U7b
7XTjvezU649IcxcbGvynJFvCmmFSfM4DiTQ5auyyhuxjzpAuZOdXq6q0RGMoYW0A
yKS8/6TZbqRqzjjuyiMs13MdgNlv7d6h4gVCKDbevoresexqcGfi4jWMugpcTvdA
0P4/H+TVK3duX2V7pJlnqqqS8rxyuUVMjnoRpC3wYN/NAJo8ZsS5/LBLQiTK/jp0
jUJUMXwQhQ5EV/h4X8cgXclfF2qslM3+x7XF5tgvgMBHY0WXFmVKLakFAYA06fQF
Re9eiAxpPDeOTmoH9ZaIUqsN7qhMMrqGQtGOvFl87n43p4uWfcOJUqzaz/fDhUNK
EvF4BdKcAfH4UivskHmZ8AgizUGhyiVrK/3ENN6YCcK2vj0UPiSq2jy/2l8Oe1Pe
Jq6C5GhlrgSR886I2FPaWwO314AADd7Y5tsgSyq/tBM6tNJC1avUtBaH3/c3MRhm
4kHux6Qbm/hbuzOzhrgCPgs52LaknXEM6OmYN105vn07D2FJA4pvYMvjDlWGEpCq
ESz42MQAMKFgtvztvQOGns4PqLc48en5//zOIVooV4z9pQ+2+NvxI2BsRa7xN2jw
B+66HoG4+Z8=
=+ete
-----END PGP SIGNATURE-----

2006-10-31 20:04:12

by Luca Tettamanti

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

Il Tue, Oct 31, 2006 at 02:41:11PM -0500, John Richard Moser ha scritto:
> Rafael J. Wysocki wrote:
> > On Tuesday, 31 October 2006 20:05, Alistair John Strachan wrote:
> >> On Tuesday 31 October 2006 17:40, Luca Tettamanti wrote:
> >>> Alistair John Strachan <[email protected]> ha scritto:
> >>>> On Tuesday 31 October 2006 06:16, Rafael J. Wysocki wrote:
> >>>> [snip]
> >>>>
> >>>>> However, we already have code that allows us to use swap files for the
> >>>>> suspend and turning a regular file into a swap file is as easy as
> >>>>> running 'mkswap' and 'swapon' on it.
> >>>> How is this feature enabled? I don't see it in 2.6.19-rc4.
> >>> Swap files have been supported for ages. suspend-to-swapfile is very
> >>> new, you need a -mm kernel and userspace suspend from CVS:
> >>> http://suspend.sf.net
> >> I know, I use swap files, and not a partition. This has prevented me from
> >> using suspend to disk "for ages". ;-)
> >>
> >> Is userspace suspend REQUIRED for this feature?
> >
> > No, but unfortunately one piece is still missing: You'll need to figure out
> > where your swap file's header is located.
> >
> > However, if you apply the attached patch the kernel will tell you where it is
> > (after you do 'swapon' grep dmesg for 'swap' and use the value in the
> > 'offset' field).
>
> Nobody has answered this one yet: Once you 'swapon' doesn't the kernel
> have (require?) the swap file opened writable? Simple mode:
>
> IS THIS NOT EXTREMELY DANGEROUS?

The trick is that the FS hosting the swapfile is *not* mounted at all;
you don't even activate the swap. resume process uses the block number
(better: the couple <devid, block>) to locate the swapfile.
The "ugly" part of this method is that the user has to figure out the
first block of the swapfile, since at resume time it's not possibile to
mount the fs (not even read only - journaled filesystems will blow up
due to journal replay) to search the swap area...

Luca
--
Windows /win'dohz/ n. : thirty-two bit extension and graphical shell to
a sixteen bit patch to an eight bit operating system originally coded
for a four bit microprocessor which was written by a two-bit company
that can't stand a bit of competition.

2006-10-31 20:15:25

by John Richard Moser

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Luca Tettamanti wrote:
> Il Tue, Oct 31, 2006 at 02:41:11PM -0500, John Richard Moser ha scritto:
>> Rafael J. Wysocki wrote:
>>> On Tuesday, 31 October 2006 20:05, Alistair John Strachan wrote:
>>>> On Tuesday 31 October 2006 17:40, Luca Tettamanti wrote:
>>>>> Alistair John Strachan <[email protected]> ha scritto:
>>>>>> On Tuesday 31 October 2006 06:16, Rafael J. Wysocki wrote:
>>>>>> [snip]
>>>>>>
>>>>>>> However, we already have code that allows us to use swap files for the
>>>>>>> suspend and turning a regular file into a swap file is as easy as
>>>>>>> running 'mkswap' and 'swapon' on it.
>>>>>> How is this feature enabled? I don't see it in 2.6.19-rc4.
>>>>> Swap files have been supported for ages. suspend-to-swapfile is very
>>>>> new, you need a -mm kernel and userspace suspend from CVS:
>>>>> http://suspend.sf.net
>>>> I know, I use swap files, and not a partition. This has prevented me from
>>>> using suspend to disk "for ages". ;-)
>>>>
>>>> Is userspace suspend REQUIRED for this feature?
>>> No, but unfortunately one piece is still missing: You'll need to figure out
>>> where your swap file's header is located.
>>>
>>> However, if you apply the attached patch the kernel will tell you where it is
>>> (after you do 'swapon' grep dmesg for 'swap' and use the value in the
>>> 'offset' field).
>> Nobody has answered this one yet: Once you 'swapon' doesn't the kernel
>> have (require?) the swap file opened writable? Simple mode:
>>
>> IS THIS NOT EXTREMELY DANGEROUS?
>
> The trick is that the FS hosting the swapfile is *not* mounted at all;
> you don't even activate the swap. resume process uses the block number
> (better: the couple <devid, block>) to locate the swapfile.
> The "ugly" part of this method is that the user has to figure out the
> first block of the swapfile, since at resume time it's not possibile to
> mount the fs (not even read only - journaled filesystems will blow up
> due to journal replay) to search the swap area...
>

Yes, I was referring to Wysoki's comment about using swapon to find it.
Although I guess you could look beforehand; but then if you move the
partition around on disk the block changes (and the kernel, on resume,
goes "BOY WHAT IS WRONG WITH YOU?!" because the partition table is
incorrect XD)

> Luca

- --
We will enslave their women, eat their children and rape their
cattle!
-- Bosc, Evil alien overlord from the fifth dimension
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIVAwUBRUeu1As1xW0HCTEFAQI9qBAAg8FWlQmueMKdr07bi2Q9YVgUO3+KZQwA
4fxpih3dgZvtWWjjvSTXNNVGySQQsonoLctn6pHBydKdpLHbpJs3qaLQ2e1/jcKi
YRDvZ3Gc0bi89W2odoMwBU4hLqY1ijKa+pujzU4pi29RoTaqWDvdw5KyTHMkZ4ib
x5kttdJ9MQ+o45JaYPzgAQ4pJnXORhqABY2IzG0jQdQb2+9YOY8dBwIMo8uzOQ4k
TU1x46xnPOEr54B1P/9gE9GCiDamjwg3x2o9HmhezQHvl5L88Yy7XOB7L8S9Tt0I
OUQYTBoiPjGXdgS1z6Q+qlgf8fN7OWIe3wpnQGf77GDIfVG4PxyptoEkptUf1UcK
7jNktJYTNJAP897uCNb9ZUySTQNKrj46/15UkQveNvh7lmqVu6J3MLlIZNED8liP
xuQliB/KzOylQ+VIbhBhiZI3kb2cGCmE09LWZUMSiI7Et+yN+TuvPE+Us5DkUfrf
J5QxXEg1tJnCprofBfL8sBpcfba4ccS373LIABZLZdGZZAy6bhch2ukDi1jM5dl+
9apv0YNxblXodT4z7fmfnXagdM/TzonH1G60YaP9vRJzmo5tv4/TNSK862MH+F+F
VJod+HTT/G5rT7gxsJpWSPG3L9gQV5OyKjFzElk8T+CBZl9mcf6ZxEuWo4LXnFgd
7RmzXNbGQBA=
=Drt3
-----END PGP SIGNATURE-----

2006-10-31 20:15:08

by Luca Tettamanti

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

Il Tue, Oct 31, 2006 at 08:19:37PM +0100, Rafael J. Wysocki ha scritto:
> On Tuesday, 31 October 2006 20:05, Alistair John Strachan wrote:
> > On Tuesday 31 October 2006 17:40, Luca Tettamanti wrote:
> > > Alistair John Strachan <[email protected]> ha scritto:
> > > > On Tuesday 31 October 2006 06:16, Rafael J. Wysocki wrote:
> > > > [snip]
> > > >
> > > >> However, we already have code that allows us to use swap files for the
> > > >> suspend and turning a regular file into a swap file is as easy as
> > > >> running 'mkswap' and 'swapon' on it.
> > > >
> > > > How is this feature enabled? I don't see it in 2.6.19-rc4.
> > >
> > > Swap files have been supported for ages. suspend-to-swapfile is very
> > > new, you need a -mm kernel and userspace suspend from CVS:
> > > http://suspend.sf.net
> >
> > I know, I use swap files, and not a partition. This has prevented me from
> > using suspend to disk "for ages". ;-)
> >
> > Is userspace suspend REQUIRED for this feature?
>
> No, but unfortunately one piece is still missing: You'll need to figure out
> where your swap file's header is located.
>
> However, if you apply the attached patch the kernel will tell you where it is
> (after you do 'swapon' grep dmesg for 'swap' and use the value in the
> 'offset' field).

Of course it's also possibile to use FIBMAP ioctl:

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/fs.h>

int main(int argc, char **argv) {
int block = 0;
int fd;

if (argc < 2)
return 1;

fd = open(argv[1], O_RDONLY);
if (fd < 0) {
perror("open()");
return 1;
}

if (ioctl(fd, FIBMAP, &block)) {
perror("ioctl()");
return 1;
}

close(fd);
printf("%d\n", block);

return 0;
}

Probably it's more script friendly (grepping dmesg? hmmm) ;)

Luca
--
Non sempre quello che viene dopo e` progresso.
Alessandro Manzoni

2006-10-31 21:20:09

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

On Tuesday, 31 October 2006 21:15, Luca Tettamanti wrote:
> Il Tue, Oct 31, 2006 at 08:19:37PM +0100, Rafael J. Wysocki ha scritto:
> > On Tuesday, 31 October 2006 20:05, Alistair John Strachan wrote:
> > > On Tuesday 31 October 2006 17:40, Luca Tettamanti wrote:
> > > > Alistair John Strachan <[email protected]> ha scritto:
> > > > > On Tuesday 31 October 2006 06:16, Rafael J. Wysocki wrote:
> > > > > [snip]
> > > > >
> > > > >> However, we already have code that allows us to use swap files for the
> > > > >> suspend and turning a regular file into a swap file is as easy as
> > > > >> running 'mkswap' and 'swapon' on it.
> > > > >
> > > > > How is this feature enabled? I don't see it in 2.6.19-rc4.
> > > >
> > > > Swap files have been supported for ages. suspend-to-swapfile is very
> > > > new, you need a -mm kernel and userspace suspend from CVS:
> > > > http://suspend.sf.net
> > >
> > > I know, I use swap files, and not a partition. This has prevented me from
> > > using suspend to disk "for ages". ;-)
> > >
> > > Is userspace suspend REQUIRED for this feature?
> >
> > No, but unfortunately one piece is still missing: You'll need to figure out
> > where your swap file's header is located.
> >
> > However, if you apply the attached patch the kernel will tell you where it is
> > (after you do 'swapon' grep dmesg for 'swap' and use the value in the
> > 'offset' field).
>
> Of course it's also possibile to use FIBMAP ioctl:
>
> #include <stdio.h>
> #include <fcntl.h>
> #include <unistd.h>
> #include <sys/ioctl.h>
> #include <linux/fs.h>
>
> int main(int argc, char **argv) {
> int block = 0;
> int fd;
>
> if (argc < 2)
> return 1;
>
> fd = open(argv[1], O_RDONLY);
> if (fd < 0) {
> perror("open()");
> return 1;
> }
>
> if (ioctl(fd, FIBMAP, &block)) {
> perror("ioctl()");
> return 1;
> }
>
> close(fd);
> printf("%d\n", block);
>
> return 0;
> }
>
> Probably it's more script friendly (grepping dmesg? hmmm) ;)

That's a bit more complicated, because you need to find a block which is
PAGE_SIZE big and express the number in PAGE_SIZE units.

Still it _is_ more script friendly and that's why the patch I sent hasn't been
applied.

Greetings,
Rafael


--
You never change things by fighting the existing reality.
R. Buckminster Fuller

2006-10-31 21:22:07

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

On Tuesday, 31 October 2006 21:15, John Richard Moser wrote:
>
> Luca Tettamanti wrote:
> > Il Tue, Oct 31, 2006 at 02:41:11PM -0500, John Richard Moser ha scritto:
> >> Rafael J. Wysocki wrote:
> >>> On Tuesday, 31 October 2006 20:05, Alistair John Strachan wrote:
> >>>> On Tuesday 31 October 2006 17:40, Luca Tettamanti wrote:
> >>>>> Alistair John Strachan <[email protected]> ha scritto:
> >>>>>> On Tuesday 31 October 2006 06:16, Rafael J. Wysocki wrote:
> >>>>>> [snip]
> >>>>>>
> >>>>>>> However, we already have code that allows us to use swap files for the
> >>>>>>> suspend and turning a regular file into a swap file is as easy as
> >>>>>>> running 'mkswap' and 'swapon' on it.
> >>>>>> How is this feature enabled? I don't see it in 2.6.19-rc4.
> >>>>> Swap files have been supported for ages. suspend-to-swapfile is very
> >>>>> new, you need a -mm kernel and userspace suspend from CVS:
> >>>>> http://suspend.sf.net
> >>>> I know, I use swap files, and not a partition. This has prevented me from
> >>>> using suspend to disk "for ages". ;-)
> >>>>
> >>>> Is userspace suspend REQUIRED for this feature?
> >>> No, but unfortunately one piece is still missing: You'll need to figure out
> >>> where your swap file's header is located.
> >>>
> >>> However, if you apply the attached patch the kernel will tell you where it is
> >>> (after you do 'swapon' grep dmesg for 'swap' and use the value in the
> >>> 'offset' field).
> >> Nobody has answered this one yet: Once you 'swapon' doesn't the kernel
> >> have (require?) the swap file opened writable? Simple mode:
> >>
> >> IS THIS NOT EXTREMELY DANGEROUS?
> >
> > The trick is that the FS hosting the swapfile is *not* mounted at all;
> > you don't even activate the swap. resume process uses the block number
> > (better: the couple <devid, block>) to locate the swapfile.
> > The "ugly" part of this method is that the user has to figure out the
> > first block of the swapfile, since at resume time it's not possibile to
> > mount the fs (not even read only - journaled filesystems will blow up
> > due to journal replay) to search the swap area...
> >
>
> Yes, I was referring to Wysoki's comment about using swapon to find it.
> Although I guess you could look beforehand; but then if you move the
> partition around on disk the block changes (and the kernel, on resume,
> goes "BOY WHAT IS WRONG WITH YOU?!" because the partition table is
> incorrect XD)

Well, if you change your partition table between the suspend and resume,
the resume will fail anyway (in the very best case).

Greetings,
Rafael


--
You never change things by fighting the existing reality.
R. Buckminster Fuller

2006-10-31 22:31:18

by Mike Lothian

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

Sorry but don't all these featues exist already in suspend2?

Available at http://www.suspend2.net/

It uses either swap of a file and also does compression

Mike

2006-10-31 22:51:51

by Luca Tettamanti

[permalink] [raw]
Subject: Re: Suspend to disk: do we HAVE to use swap?

On 10/31/06, Rafael J. Wysocki <[email protected]> wrote:
> On Tuesday, 31 October 2006 21:15, Luca Tettamanti wrote:
> > Il Tue, Oct 31, 2006 at 08:19:37PM +0100, Rafael J. Wysocki ha scritto:
> > > On Tuesday, 31 October 2006 20:05, Alistair John Strachan wrote:
> > > > On Tuesday 31 October 2006 17:40, Luca Tettamanti wrote:
> > > > > Alistair John Strachan <[email protected]> ha scritto:
> > > > > > On Tuesday 31 October 2006 06:16, Rafael J. Wysocki wrote:
> > > > > > [snip]
> > > > > >
> > > > > >> However, we already have code that allows us to use swap files for the
> > > > > >> suspend and turning a regular file into a swap file is as easy as
> > > > > >> running 'mkswap' and 'swapon' on it.
> > > > > >
> > > > > > How is this feature enabled? I don't see it in 2.6.19-rc4.
> > > > >
> > > > > Swap files have been supported for ages. suspend-to-swapfile is very
> > > > > new, you need a -mm kernel and userspace suspend from CVS:
> > > > > http://suspend.sf.net
> > > >
> > > > I know, I use swap files, and not a partition. This has prevented me from
> > > > using suspend to disk "for ages". ;-)
> > > >
> > > > Is userspace suspend REQUIRED for this feature?
> > >
> > > No, but unfortunately one piece is still missing: You'll need to figure out
> > > where your swap file's header is located.
> > >
> > > However, if you apply the attached patch the kernel will tell you where it is
> > > (after you do 'swapon' grep dmesg for 'swap' and use the value in the
> > > 'offset' field).
> >
> > Of course it's also possibile to use FIBMAP ioctl:
> >
> > #include <stdio.h>
> > #include <fcntl.h>
> > #include <unistd.h>
> > #include <sys/ioctl.h>
> > #include <linux/fs.h>
> >
> > int main(int argc, char **argv) {
> > int block = 0;
> > int fd;
> >
> > if (argc < 2)
> > return 1;
> >
> > fd = open(argv[1], O_RDONLY);
> > if (fd < 0) {
> > perror("open()");
> > return 1;
> > }
> >
> > if (ioctl(fd, FIBMAP, &block)) {
> > perror("ioctl()");
> > return 1;
> > }
> >
> > close(fd);
> > printf("%d\n", block);
> >
> > return 0;
> > }
> >
> > Probably it's more script friendly (grepping dmesg? hmmm) ;)
>
> That's a bit more complicated, because you need to find a block which is
> PAGE_SIZE big and express the number in PAGE_SIZE units.

Ah, I see. Finding a cluster of contiguous blocks is easy, but I'm
having troubles converting the block number to an offset from the
start of the device :s

Luca