Re: [PATCH v2] PM: HIBERNATION: skip the swap size check if thesnapshot image size is anticipative

From: Barry Song
Date: Thu Dec 15 2011 - 03:50:30 EST


Pavel ,Rafael, any feedback?
-barry

2011/11/25 Barry Song <Barry.Song@xxxxxxx>:
> From: Barry Song <baohua.song@xxxxxxx>
>
> Current swsusp requires swap partitions even larger than real saved pages
> based on the worst compression ratio:
> but for an embedded system, which has limited storage space, then it might
> can't give the large partition to save snapshot.
> In the another way, some embedded systems can definitely know the most size
> needed for snapshot since they run some specific application lists.
> So this patch provides the possibility for users to tell kernel even
> the system has a little snapshot partition, but it is still enough.
> For example, if the system need to save 120MB memory, origin swsusp will require
> a 130MB partition to save snapshot. but if users know 30MB is enough for them(
> compressed image will be less than 30MB), they just make a 30MB partition by
> echo 0 > /sys/power/check_swap_size
>
> Signed-off-by: Barry Song <Baohua.Song@xxxxxxx>
> Cc: Xiangzhen Ye <Xiangzhen.Ye@xxxxxxx>
> ---
> Â-v2:drop swap_enough bootargs and use /sys/power/check_swap_size node
>
> ÂDocumentation/power/interface.txt | Â Â5 +++++
> Âkernel/power/hibernate.c     Â|  22 ++++++++++++++++++++++
> Âkernel/power/power.h       Â|  Â2 ++
> Âkernel/power/swap.c        |  Â9 +++++++++
> Â4 files changed, 38 insertions(+), 0 deletions(-)
>
> diff --git a/Documentation/power/interface.txt b/Documentation/power/interface.txt
> index c537834..5e205f0 100644
> --- a/Documentation/power/interface.txt
> +++ b/Documentation/power/interface.txt
> @@ -47,6 +47,11 @@ Writing to this file will accept one of
> Â Â Â Â'testproc'
> Â Â Â Â'test'
>
> +/sys/power/check_swap_size controls whether we can skip checking the swap
> +partition size by worst compression ratio. If users know the swap partition
> +is enough for compressed snapshot, write 0 to /sys/power/check_swap_size.
> +It is useful for an embedded system with known running softwares.
> +
> Â/sys/power/image_size controls the size of the image created by
> Âthe suspend-to-disk mechanism. ÂIt can be written a string
> Ârepresenting a non-negative integer that will be used as an upper
> diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
> index 1c53f7f..5552473 100644
> --- a/kernel/power/hibernate.c
> +++ b/kernel/power/hibernate.c
> @@ -1024,11 +1024,33 @@ static ssize_t reserved_size_store(struct kobject *kobj,
>
> Âpower_attr(reserved_size);
>
> +static ssize_t check_swap_size_show(struct kobject *kobj, struct kobj_attribute *attr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âchar *buf)
> +{
> + Â Â Â return sprintf(buf, "%d\n", check_swap_size);
> +}
> +
> +static ssize_t check_swap_size_store(struct kobject *kobj, struct kobj_attribute *attr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â const char *buf, size_t n)
> +{
> + Â Â Â int check_size;
> +
> + Â Â Â if (sscanf(buf, "%d", &check_size) == 1) {
> + Â Â Â Â Â Â Â check_swap_size = check_size;
> + Â Â Â Â Â Â Â return n;
> + Â Â Â }
> +
> + Â Â Â return -EINVAL;
> +}
> +
> +power_attr(check_swap_size);
> +
> Âstatic struct attribute * g[] = {
> Â Â Â Â&disk_attr.attr,
> Â Â Â Â&resume_attr.attr,
> Â Â Â Â&image_size_attr.attr,
> Â Â Â Â&reserved_size_attr.attr,
> + Â Â Â &check_swap_size_attr.attr,
> Â Â Â ÂNULL,
> Â};
>
> diff --git a/kernel/power/power.h b/kernel/power/power.h
> index 23a2db1..4f0fa78 100644
> --- a/kernel/power/power.h
> +++ b/kernel/power/power.h
> @@ -74,6 +74,8 @@ static struct kobj_attribute _name##_attr = { \
>
> Â/* Preferred image size in bytes (default 500 MB) */
> Âextern unsigned long image_size;
> +/* If 0, skip checking whether the swap size is enough for compressed snapshot */
> +extern int check_swap_size;
> Â/* Size of memory reserved for drivers (default SPARE_PAGES x PAGE_SIZE) */
> Âextern unsigned long reserved_size;
> Âextern int in_suspend;
> diff --git a/kernel/power/swap.c b/kernel/power/swap.c
> index 11a594c..db90195 100644
> --- a/kernel/power/swap.c
> +++ b/kernel/power/swap.c
> @@ -37,6 +37,12 @@
> Â#define HIBERNATE_SIG Â"S1SUSPEND"
>
> Â/*
> + * if users know swap partitions are enough for compressed snapshots,
> + * echo 0 > /sys/power/check_swap_size
> + */
> +int check_swap_size = 1;
> +
> +/*
> Â* Â Â The swap map is a data structure used for keeping track of each page
> Â* Â Â written to a swap partition. ÂIt consists of many swap_map_page
> Â* Â Â structures that contain each an array of MAP_PAGE_ENTRIES swap entries.
> @@ -772,6 +778,9 @@ static int enough_swap(unsigned int nr_pages, unsigned int flags)
> Â Â Â Âunsigned int free_swap = count_swap_pages(root_swap, 1);
> Â Â Â Âunsigned int required;
>
> + Â Â Â if (!check_swap_size)
> + Â Â Â Â Â Â Â return 1;
> +
> Â Â Â Âpr_debug("PM: Free swap pages: %u\n", free_swap);
>
> Â Â Â Ârequired = PAGES_FOR_IO + ((flags & SF_NOCOMPRESS_MODE) ?
> --
> 1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/