* [PATCH v3] hibernate: init image_size depend on totalram_pages
@ 2025-07-04 3:10 Li Jun
0 siblings, 0 replies; 5+ messages in thread
From: Li Jun @ 2025-07-04 3:10 UTC (permalink / raw)
To: rafael, pavel, len.brown, linux-pm, lijun01
Some automatically loaded applications greedily occupy
memory, when total memory is 8GB, the image_size is 3GB,
when total memory is 16GB, the image_size is 6GB, when
total memory is 32GB, the image_size is 12GB. some
of these applications,user may not use them. They occupy
a large amount of image space, resulting in S4 time of
over 100 seconds or even more. Limit the size of image_size
to control the time of hibernation and wake-up,making S4
more user-friendly.
Signed-off-by: Li Jun <lijun01@kylinos.cn>
---
kernel/power/snapshot.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 2af36cfe35cd..27ea4f398f22 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -135,10 +135,21 @@ void __init hibernate_reserved_size_init(void)
* try to create the smallest image possible.
*/
unsigned long image_size;
+#define MEM_8G (8 * 1024 * 1024)//KB
+#define MEM_8G_PAGES (MEM_8G / (PAGE_SIZE / 1024))
+#define MEM_16G_PAGES (2 * MEM_8G_PAGES)
+#define MEM_32G_PAGES (4 * MEM_8G_PAGES)
void __init hibernate_image_size_init(void)
{
- image_size = ((totalram_pages() * 2) / 5) * PAGE_SIZE;
+ if (totalram_pages() >= MEM_32G_PAGES)
+ image_size = ((totalram_pages() * 1) / 20) * PAGE_SIZE;
+ else if (totalram_pages() >= MEM_16G_PAGES)
+ image_size = ((totalram_pages() * 1) / 10) * PAGE_SIZE;
+ else if (totalram_pages() >= MEM_8G_PAGES)
+ image_size = ((totalram_pages() * 1) / 5) * PAGE_SIZE;
+ else
+ image_size = ((totalram_pages() * 2) / 5) * PAGE_SIZE;
}
/*
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3] hibernate: init image_size depend on totalram_pages
@ 2025-07-28 10:37 Li Jun
0 siblings, 0 replies; 5+ messages in thread
From: Li Jun @ 2025-07-28 10:37 UTC (permalink / raw)
To: lijun01, rafael, pavel, len.brown, linux-pm
Some automatically loaded applications greedily occupy
memory, when total memory is 8GB, the image_size is 3GB,
when total memory is 16GB, the image_size is 6GB, when
total memory is 32GB, the image_size is 12GB. some
of these applications,user may not use them. They occupy
a large amount of image space, resulting in S4 time of
over 100 seconds or even more. Limit the size of image_size
to control the time of hibernation and wake-up,making S4
more user-friendly.
Signed-off-by: Li Jun <lijun01@kylinos.cn>
---
kernel/power/snapshot.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 2af36cfe35cd..27ea4f398f22 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -135,10 +135,21 @@ void __init hibernate_reserved_size_init(void)
* try to create the smallest image possible.
*/
unsigned long image_size;
+#define MEM_8G (8 * 1024 * 1024)//KB
+#define MEM_8G_PAGES (MEM_8G / (PAGE_SIZE / 1024))
+#define MEM_16G_PAGES (2 * MEM_8G_PAGES)
+#define MEM_32G_PAGES (4 * MEM_8G_PAGES)
void __init hibernate_image_size_init(void)
{
- image_size = ((totalram_pages() * 2) / 5) * PAGE_SIZE;
+ if (totalram_pages() >= MEM_32G_PAGES)
+ image_size = ((totalram_pages() * 1) / 20) * PAGE_SIZE;
+ else if (totalram_pages() >= MEM_16G_PAGES)
+ image_size = ((totalram_pages() * 1) / 10) * PAGE_SIZE;
+ else if (totalram_pages() >= MEM_8G_PAGES)
+ image_size = ((totalram_pages() * 1) / 5) * PAGE_SIZE;
+ else
+ image_size = ((totalram_pages() * 2) / 5) * PAGE_SIZE;
}
/*
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3] hibernate: init image_size depend on totalram_pages
@ 2025-08-06 2:06 Li Jun
0 siblings, 0 replies; 5+ messages in thread
From: Li Jun @ 2025-08-06 2:06 UTC (permalink / raw)
To: rafael, pavel, len.brown, linux-pm, lijun01
Some automatically loaded applications greedily occupy
memory, when total memory is 8GB, the image_size is 3GB,
when total memory is 16GB, the image_size is 6GB, when
total memory is 32GB, the image_size is 12GB. some
of these applications,user may not use them. They occupy
a large amount of image space, resulting in S4 time of
over 100 seconds or even more. Limit the size of image_size
to control the time of hibernation and wake-up,making S4
more user-friendly.
First obtain the number of pages in 8GB of memory,
MEM_8G_PAGES,and then use 16GB and 32GB based on 8GB.
When the number of memory pages is greater than MEM_8G_PAGES,
the current physical memory will definitely be greater than 8G.
if it is 16GB, the current image_size will be initialized to 1/5
of the totalram_mages().
When the number of memory pages is greater than MEM_16G_PAGES,
the current physical memory will definitely be greater than 16GB.
if it is 32GB, the current image_size will be initialized to 1/10
of the totalram_mages().
When the number of memory pages is greater than MEM_32G_PAGES,
the current physical memory will definitely be greater than 32GB,
if it is 64GB, the currentimage_size will be initialized to 1/20
of the totalram_mages().
This way, when there are 16GB, 32GB or 64GB, the size of the
image size will be controlled to be slightly more than 3G.
Signed-off-by: Li Jun <lijun01@kylinos.cn>
---
kernel/power/snapshot.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 501df0676a61..9b11c74592e9 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -135,10 +135,21 @@ void __init hibernate_reserved_size_init(void)
* try to create the smallest image possible.
*/
unsigned long image_size;
+#define MEM_8G (8 * 1024 * 1024)//KB
+#define MEM_8G_PAGES (MEM_8G / (PAGE_SIZE / 1024))
+#define MEM_16G_PAGES (2 * MEM_8G_PAGES)
+#define MEM_32G_PAGES (4 * MEM_8G_PAGES)
void __init hibernate_image_size_init(void)
{
- image_size = ((totalram_pages() * 2) / 5) * PAGE_SIZE;
+ if (totalram_pages() >= MEM_32G_PAGES)
+ image_size = ((totalram_pages() * 1) / 20) * PAGE_SIZE;
+ else if (totalram_pages() >= MEM_16G_PAGES)
+ image_size = ((totalram_pages() * 1) / 10) * PAGE_SIZE;
+ else if (totalram_pages() >= MEM_8G_PAGES)
+ image_size = ((totalram_pages() * 1) / 5) * PAGE_SIZE;
+ else
+ image_size = ((totalram_pages() * 2) / 5) * PAGE_SIZE;
}
/*
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3] hibernate: init image_size depend on totalram_pages
@ 2025-08-20 1:33 Li Jun
2025-08-25 19:17 ` Rafael J. Wysocki
0 siblings, 1 reply; 5+ messages in thread
From: Li Jun @ 2025-08-20 1:33 UTC (permalink / raw)
To: rafael, linux-pm, lijun01
Some automatically loaded applications greedily occupy
memory, when total memory is 8GB, the image_size is 3GB,
when total memory is 16GB, the image_size is 6GB, when
total memory is 32GB, the image_size is 12GB. some
of these applications,user may not use them. They occupy
a large amount of image space, resulting in S4 time of
over 100 seconds or even more.When the users use s4 first,
they feel the awakening time is so long,they may not use S4
anymore. but s4 is so great beacause it can save power and
preserve the working environment, especially for moblile
devices.so limit the size of image_size to control the time
of hibernation and wake-up,making more users love S4.
First obtain the number of pages in 8GB of memory,
MEM_8G_PAGES,and then use 16GB and 32GB based on 8GB.
When the number of totalram_pages() is greater than MEM_8G_PAGES,
the current physical memory will definitely be greater than 8G.
if it is 16GB, the current image_size will be initialized to 1/5
of the totalram_pages().
When the number of totalram_pages() is greater than MEM_16G_PAGES,
the current physical memory will definitely be greater than 16GB.
if it is 32GB, the current image_size will be initialized to 1/10
of the totalram_pages().
When the number of totalram_pages() is greater than MEM_32G_PAGES,
the current physical memory will definitely be greater than 32GB,
if it is 64GB, the currentimage_size will be initialized to 1/20
of the totalram_mages().
This way, when there are 16GB, 32GB or 64GB, the size of the
image size will be controlled to be slightly more than 3G.Just
shrink more NR_SLAB_RECLAIMABLE, NR_ACTIVE_ANON, NR_INACTIVE_ANON,
NR_ACTIVE_FILE, NR_INACTIVE_FILE pages, S4 is still normal.
Signed-off-by: Li Jun <lijun01@kylinos.cn>
---
kernel/power/snapshot.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 501df0676a61..9b11c74592e9 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -135,10 +135,21 @@ void __init hibernate_reserved_size_init(void)
* try to create the smallest image possible.
*/
unsigned long image_size;
+#define MEM_8G (8 * 1024 * 1024)//KB
+#define MEM_8G_PAGES (MEM_8G / (PAGE_SIZE / 1024))
+#define MEM_16G_PAGES (2 * MEM_8G_PAGES)
+#define MEM_32G_PAGES (4 * MEM_8G_PAGES)
void __init hibernate_image_size_init(void)
{
- image_size = ((totalram_pages() * 2) / 5) * PAGE_SIZE;
+ if (totalram_pages() >= MEM_32G_PAGES)
+ image_size = ((totalram_pages() * 1) / 20) * PAGE_SIZE;
+ else if (totalram_pages() >= MEM_16G_PAGES)
+ image_size = ((totalram_pages() * 1) / 10) * PAGE_SIZE;
+ else if (totalram_pages() >= MEM_8G_PAGES)
+ image_size = ((totalram_pages() * 1) / 5) * PAGE_SIZE;
+ else
+ image_size = ((totalram_pages() * 2) / 5) * PAGE_SIZE;
}
/*
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3] hibernate: init image_size depend on totalram_pages
2025-08-20 1:33 [PATCH v3] hibernate: init image_size depend on totalram_pages Li Jun
@ 2025-08-25 19:17 ` Rafael J. Wysocki
0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2025-08-25 19:17 UTC (permalink / raw)
To: Li Jun; +Cc: rafael, linux-pm
On Wed, Aug 20, 2025 at 3:34 AM Li Jun <lijun01@kylinos.cn> wrote:
>
> Some automatically loaded applications greedily occupy
> memory, when total memory is 8GB, the image_size is 3GB,
> when total memory is 16GB, the image_size is 6GB, when
> total memory is 32GB, the image_size is 12GB. some
> of these applications,user may not use them. They occupy
> a large amount of image space, resulting in S4 time of
> over 100 seconds or even more.
You really need to give a real world example of the case in which this
patch makes a difference.
> When the users use s4 first,
> they feel the awakening time is so long,they may not use S4
> anymore. but s4 is so great beacause it can save power and
> preserve the working environment, especially for moblile
> devices.so limit the size of image_size to control the time
> of hibernation and wake-up,making more users love S4.
The above part of the changelog doesn't add useful information, so it
may be dropped.
> First obtain the number of pages in 8GB of memory,
> MEM_8G_PAGES,and then use 16GB and 32GB based on 8GB.
The above is also not really useful information.
> When the number of totalram_pages() is greater than MEM_8G_PAGES,
"When the total number of RAM pages is greater than MEM_8G_PAGES,"
> the current physical memory will definitely be greater than 8G.
> if it is 16GB, the current image_size will be initialized to 1/5
> of the totalram_pages().
> When the number of totalram_pages() is greater than MEM_16G_PAGES,
> the current physical memory will definitely be greater than 16GB.
> if it is 32GB, the current image_size will be initialized to 1/10
> of the totalram_pages().
> When the number of totalram_pages() is greater than MEM_32G_PAGES,
> the current physical memory will definitely be greater than 32GB,
> if it is 64GB, the currentimage_size will be initialized to 1/20
> of the totalram_mages().
> This way, when there are 16GB, 32GB or 64GB, the size of the
> image size will be controlled to be slightly more than 3G.Just
> shrink more NR_SLAB_RECLAIMABLE, NR_ACTIVE_ANON, NR_INACTIVE_ANON,
> NR_ACTIVE_FILE, NR_INACTIVE_FILE pages, S4 is still normal.
So overall, the idea is to always create hibernation images of
approximately the same size (by default) regardless of the actual RAM
size, to reduce the time needed to load the image on systems with
relatively large RAM.
However, if the memory is actually used by applications, this may
cause pages to be flushed to swap during the "shrinking" of memory and
then they will be faulted in wholesale during restore which will cause
the whole process to take more time (this processes uncompressed pages
one at a time).
So this approach really only works if applications allocate lots of
memory and then don't use it. How often does this happen in practice?
> Signed-off-by: Li Jun <lijun01@kylinos.cn>
> ---
> kernel/power/snapshot.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
> index 501df0676a61..9b11c74592e9 100644
> --- a/kernel/power/snapshot.c
> +++ b/kernel/power/snapshot.c
> @@ -135,10 +135,21 @@ void __init hibernate_reserved_size_init(void)
> * try to create the smallest image possible.
> */
> unsigned long image_size;
> +#define MEM_8G (8 * 1024 * 1024)//KB
> +#define MEM_8G_PAGES (MEM_8G / (PAGE_SIZE / 1024))
> +#define MEM_16G_PAGES (2 * MEM_8G_PAGES)
> +#define MEM_32G_PAGES (4 * MEM_8G_PAGES)
>
> void __init hibernate_image_size_init(void)
> {
> - image_size = ((totalram_pages() * 2) / 5) * PAGE_SIZE;
> + if (totalram_pages() >= MEM_32G_PAGES)
> + image_size = ((totalram_pages() * 1) / 20) * PAGE_SIZE;
What sense does it make to multiply totalram_pages() by 1?
> + else if (totalram_pages() >= MEM_16G_PAGES)
> + image_size = ((totalram_pages() * 1) / 10) * PAGE_SIZE;
> + else if (totalram_pages() >= MEM_8G_PAGES)
> + image_size = ((totalram_pages() * 1) / 5) * PAGE_SIZE;
> + else
> + image_size = ((totalram_pages() * 2) / 5) * PAGE_SIZE;
Regardless of the concerns above, it looks like the computation here
can be automated somehow? For instance, a loop can be used for
computing the number by which totalram_pages() is divided.
> }
>
> /*
> --
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-25 19:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-20 1:33 [PATCH v3] hibernate: init image_size depend on totalram_pages Li Jun
2025-08-25 19:17 ` Rafael J. Wysocki
-- strict thread matches above, loose matches on Subject: below --
2025-08-06 2:06 Li Jun
2025-07-28 10:37 Li Jun
2025-07-04 3:10 Li Jun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).