linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Luigi Semenzato <semenzato@google.com>
To: James Morse <james.morse@arm.com>
Cc: Linux Memory Management List <linux-mm@kvack.org>,
	Bas Nowaira <bassem@google.com>, Geoff Pike <gpike@google.com>,
	 linux-pm@vger.kernel.org
Subject: Re: hibernation memory usage
Date: Tue, 8 Oct 2019 08:26:33 -0700	[thread overview]
Message-ID: <CAA25o9TpBm+LNwVccTaUng4vQ1Q9_Wz2QftGho7DG_+26CCYoA@mail.gmail.com> (raw)
In-Reply-To: <56319808-87dc-76ed-c1e0-9f60108e94a6@arm.com>

Thank you for your reply!

I understand the need for saving all state, not just process/task
state.  But for many of the systems that could benefit from
hibernation, the majority of RAM is taken by user processes (I am
thinking laptops).  It should be possible to copy their anonymous
pages to disk more or less directly, without making an extra copy like
it's done for all other pages.  I am not sure what happens with kernel
tasks, but they don't have anonymous pages (that I know).

I am curious to know how/if hibernation is currently used in practice.
It doesn't seem practical to require that user processes take less
than 50% of RAM at all times.  There may be special cases in which the
restriction can be achieved by terminating non-essential processes
before hibernating, but I don't know of any.

I would also like to know how much work it might take to avoid the
extra copy of the anonymous pages of frozen processes.

Thanks!

On Tue, Oct 8, 2019 at 3:33 AM James Morse <james.morse@arm.com> wrote:
>
> Hi Luigi,
>
> (CC: +linux-pm mailing list)
>
> On 03/10/2019 18:16, Luigi Semenzato wrote:
> > I am working on a project that uses hibernation, and we've noticed occasional failures
> > with "echo disk > /sys/power/state" returning ENOMEM.  I added some logging and noticed
> > that the failures seem to correlate with total anonymous pages being approximately 1/2 of
> > total RAM.  The allocation strategy isn't explicitly documented and the code is a bit
> > tricky (as usual), but I am getting the sense that a copy of the entire RAM in use is made
> > prior to saving it to disk.  Is it the case then that hibernation is guaranteed to fail if
> > anon memory is more than 50% of RAM?
>
> I'm pretty sure it is. If 50% of memory needs saving, you can't create a snapshot of it.
>
>
> > Since tasks are frozen, that memory cannot change> and the copy seems redundant (except it probably makes things simpler).
>
> Tasks aren't the only thing changing memory. Hibernate save/restores the entire system,
> including the kernel data and text. (what happens if a task is waiting for a syscall to
> complete?)
>
>
> Hibernate needs a snapshot of memory, and the disk drivers, block layer etc need to write
> to memory (and allocate it) in order to get their work done.
>
> To work with this, hibernate's create_image() stops secondary CPUs and suspends all
> devices. Now that only hibernate is running, it calls swsusp_arch_suspend() which then
> call swsusp_save(). This creates the snapshot of memory.
>
> Once this is done, devices are thawed, and hibernate() goes on to call swusp_write() to
> write the snapshot to disk. Finally, processes are thawed.
>
> (create_image() is called by hibernation_snapshot() from hibernate()).
>
>
> If you don't need to save/restore the kernel state, you might not need hibernate at all.
>
>
> Thanks,
>
> James


  reply	other threads:[~2019-10-08 15:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-03 17:16 Luigi Semenzato
2019-10-08 10:33 ` James Morse
2019-10-08 15:26   ` Luigi Semenzato [this message]
2019-10-08 15:39     ` Rafael J. Wysocki
2019-10-08 16:18       ` Luigi Semenzato
2019-10-08 20:10         ` Luigi Semenzato
2019-10-17 22:55           ` Luigi Semenzato
2019-10-19  1:49             ` Luigi Semenzato

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=CAA25o9TpBm+LNwVccTaUng4vQ1Q9_Wz2QftGho7DG_+26CCYoA@mail.gmail.com \
    --to=semenzato@google.com \
    --cc=bassem@google.com \
    --cc=gpike@google.com \
    --cc=james.morse@arm.com \
    --cc=linux-mm@kvack.org \
    --cc=linux-pm@vger.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