swsusp: specify available swap in bytes
Subsystems (2)
RFC PATCH 1/1 swsusp: specify available swap in bytes
Hi,
If the SNAPSHOT_AVAIL_SWAP ioctl returns the number of bytes, it will allow us to use the number as an input for the SNAPSHOT_SET_IMAGE_SIZE ioctl directly.
OTOH, to make SNAPSHOT_AVAIL_SWAP return the number of bytes we need to add the size of the image in bytes to the image header, but this really costs us nothing, because the header is page-aligned anyway.
The appended patch contains all the necessary changes.
Opinions welcome. :-)
Greetings,
Rafael
Documentation/power/userland-swsusp.txt | 16 ++++++---------- kernel/power/power.h | 1 + kernel/power/snapshot.c | 2 ++ kernel/power/user.c | 8 ++++---- 4 files changed, 13 insertions(+), 14 deletions(-)
Documentation/power/userland-swsusp.txt +6 -10
@@ -55,13 +55,9 @@ SNAPSHOT_SET_IMAGE_SIZE - set the prefer this number, but if it turns out to be impossible, the kernel will create the smallest image possible) -SNAPSHOT_AVAIL_SWAP - check the amount of available swap (the last argument - should be a pointer to an unsigned int variable that will contain - the result if the call is successful). The result is the number - of available swap pages, so it is architecture-dependent. It is - only to be compared with the number of the snapshot image pages - read from the image header (see below). It SHOULD NOT be used for - any other purpose. +SNAPSHOT_AVAIL_SWAP - check the amount of available swap in bytes (the last + argument should be a pointer to an unsigned int variable that will + contain the result if the call is successful). SNAPSHOT_GET_SWAP_PAGE - allocate a swap page from the resume partition (the last argument should be a pointer to a loff_t variable that
@@ -104,9 +100,9 @@ These utilities SHOULD NOT make any assu data within the snapshot image, except for the image header that MAY be assumed to start with an swsusp_info structure, as specified in kernel/power/power.h. This structure MAY be used by the userland utilities -to obtain some information about the snapshot image, such as the total -number of the image pages, including the metadata and the header itself, -contained in the .pages member of swsusp_info. +to obtain some information about the snapshot image, such as the size +of the snapshot image, including the metadata and the header itself, +contained in the .size member of swsusp_info. The snapshot image MUST be written to the kernel unaltered (ie. all of the image data, metadata and header MUST be written in _exactly_ the same amount, form
kernel/power/power.h +1 -0
@@ -16,6 +16,7 @@ struct swsusp_info {int cpus;unsigned long image_pages;unsigned long pages; +unsigned long size; } __attribute__((aligned(PAGE_SIZE)));
kernel/power/snapshot.c +2 -0
@@ -525,6 +525,8 @@ static void init_header(struct swsusp_in info->cpus =num_online_cpus (); info->image_pages = nr_copy_pages; info->pages = nr_copy_pages + nr_meta_pages +1 ; + info->size = info->pages; + info->size <<=PAGE_SHIFT ; }/**
kernel/power/user.c +4 -4
@@ -123,8 +123,7 @@ static int snapshot_ioctl(struct inode * {int error =0 ;struct snapshot_data *data; -loff_t offset; -unsigned int n; +loff_t offset, avail;if (_IOC_TYPE (cmd) !=SNAPSHOT_IOC_MAGIC )return -ENOTTY ;
@@ -214,8 +213,9 @@ static int snapshot_ioctl(struct inode *break ;case SNAPSHOT_AVAIL_SWAP : - n =count_swap_pages (data->swap,1 ); - error =put_user (n, (unsigned int __user *)arg); + avail =count_swap_pages (data->swap,1 ); + avail <<=PAGE_SHIFT ; + error =put_user (avail, (loff_t __user *)arg);break ;case SNAPSHOT_GET_SWAP_PAGE :
Quoted 5 lines · Rafael J. Wysocki
Hi,
If the
SNAPSHOT_AVAIL_SWAPioctl returns the number of bytes, it will allow us to use the number as an input for theSNAPSHOT_SET_IMAGE_SIZEioctl directly.
Quoted 7 lines
OTOH, to make
SNAPSHOT_AVAIL_SWAPreturn the number of bytes we need to add the size of the image in bytes to the image header, but this really costs us nothing, because the header is page-aligned anyway.The appended patch contains all the necessary changes.
Opinions welcome. :-)
ACK.
BTW that "make /sys/power/image_size be in bytes" perhaps should be merged to Linus, so that 2.6.16 has final version of userland interface. It is better to change it between -rc1 and final than between 2.6.16 and 2.6.17.
Thanks,
Pavel
Signature · 1 line
Thanks, Sharp!
Quoted 4 lines · Pavel Machek
BTW that "make
/sys/power/image_sizebe in bytes" perhaps should be merged to Linus, so that 2.6.16 has final version of userland interface. It is better to change it between -rc1 and final than between 2.6.16 and 2.6.17.
Yes, ASAP please. I am integrating support for this in an userspace application right now (first try with large image_size, as large as free swap suggests; if this fails retry with image_size = 0) so it would be nice if this went in before 2.6.16
Signature · 3 lines
Stefan Seyfried \ "I didn't want to write for pay. I QA / R&D Team Mobile Devices \ wanted to be paid for what I write." SUSE LINUX Products GmbH, Nürnberg \ -- Leonard Cohen
Quoted 11 lines · Stefan Seyfried
Quoted 4 lines · Pavel Machek
BTW that "make
/sys/power/image_sizebe in bytes" perhaps should be merged to Linus, so that 2.6.16 has final version of userland interface. It is better to change it between -rc1 and final than between 2.6.16 and 2.6.17.Yes, ASAP please. I am integrating support for this in an userspace application right now (first try with large
image_size, as large as free swap suggests; if this fails retry withimage_size= 0) so it would be nice if this went in before 2.6.16
I'll do my best.
Greetings,
Rafael