From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1F30C4360C for ; Tue, 8 Oct 2019 10:33:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B44CE206C2 for ; Tue, 8 Oct 2019 10:33:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B44CE206C2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 07A828E0005; Tue, 8 Oct 2019 06:33:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 02BBE8E0003; Tue, 8 Oct 2019 06:33:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E81E38E0005; Tue, 8 Oct 2019 06:33:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id C10AD8E0003 for ; Tue, 8 Oct 2019 06:33:18 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 644E8181AC9BF for ; Tue, 8 Oct 2019 10:33:18 +0000 (UTC) X-FDA: 76020255276.11.shake21_73daa68b88248 X-HE-Tag: shake21_73daa68b88248 X-Filterd-Recvd-Size: 3124 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Oct 2019 10:33:15 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B8E3815BE; Tue, 8 Oct 2019 03:33:14 -0700 (PDT) Received: from [10.1.196.105] (eglon.cambridge.arm.com [10.1.196.105]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 10C173F6C4; Tue, 8 Oct 2019 03:33:13 -0700 (PDT) Subject: Re: hibernation memory usage To: Luigi Semenzato References: Cc: Linux Memory Management List , Bas Nowaira , Geoff Pike , linux-pm@vger.kernel.org From: James Morse Message-ID: <56319808-87dc-76ed-c1e0-9f60108e94a6@arm.com> Date: Tue, 8 Oct 2019 11:33:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 occa= sional failures > with "echo disk > /sys/power/state" returning ENOMEM.=C2=A0 I added som= e logging and noticed > that the failures seem to correlate with total anonymous pages being ap= proximately 1/2 of > total RAM.=C2=A0 The allocation strategy isn't explicitly documented an= d 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.=C2=A0 Is it the case then that hibernation = is guaranteed to fail if > anon memory is more than 50% of RAM?=20 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 r= edundant (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 fo= r a syscall to complete?) Hibernate needs a snapshot of memory, and the disk drivers, block layer e= tc 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 su= spends 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 sw= usp_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 hi= bernate at all. Thanks, James