linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Li Jun <lijun01@kylinos.cn>
To: rafael@kernel.org, pavel@ucw.cz, len.brown@intel.com,
	linux-pm@vger.kernel.org, lijun01@kylinos.cn
Subject: [PATCH v3] hibernate: init image_size depend on totalram_pages
Date: Wed,  6 Aug 2025 10:06:39 +0800	[thread overview]
Message-ID: <20250806020639.315687-1-lijun01@kylinos.cn> (raw)

  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


             reply	other threads:[~2025-08-06  2:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-06  2:06 Li Jun [this message]
  -- strict thread matches above, loose matches on Subject: below --
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
2025-07-28 10:37 Li Jun
2025-07-04  3:10 Li Jun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250806020639.315687-1-lijun01@kylinos.cn \
    --to=lijun01@kylinos.cn \
    --cc=len.brown@intel.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).