power: clarify limitations of hibernation
Subsystems (3)
PATCH 1/1 power: clarify limitations of hibernation
Entering hibernation (suspend-to-disk) will fail if the kernel cannot allocate enough memory to create a snapshot of all pages in use; i.e., if memory in use is over 1/2 of total RAM. This patch makes this limitation clearer in the documentation. Without it, users may assume that hibernation can replace suspend-to-RAM when in fact its functionality is more limited.
--- Documentation/admin-guide/pm/sleep-states.rst | 18 +++++++++++++++++- kernel/power/snapshot.c | 16 +++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-)
Documentation/admin-guide/pm/sleep-states.rst +17 -1
@@ -112,7 +112,9 @@ Hibernation This state (also referred to as Suspend-to-Disk or STD) offers the greatest energy savings and can be used even in the absence of low-level platform support for system suspend. However, it requires some low-level code for resuming the -system to be present for the underlying CPU architecture. +system to be present for the underlying CPU architecture. Additionally, the +current implementation can enter the hibernation state only when memory +pressure is low (see "Limitations" below). Hibernation is significantly different from any of the system suspend variants. It takes three system state changes to put it into hibernation and two system
@@ -149,6 +151,20 @@ Hibernation is supported if the :c:macro:`CONFIG_HIBERNATION` kernel configuration option is set. However, this option can only be set if support for the given CPU architecture includes the low-level code for system resume. +Limitations of Hibernation +========================== + +When entering hibernation, the kernel tries to allocate a chunk of memory large +enough to contain a copy of all pages in use, to use it for the system +snapshot. If the allocation fails, the system cannot hibernate and the +operation fails with ENOMEM. This will happen, for instance, when the total +amount of anonymous pages (process data) exceeds 1/2 of total RAM. + +One possible workaround (besides terminating enough processes) is to force +excess anonymous pages out to swap before hibernating. This can be achieved +with memcgroups, by lowering memory usage limits with ``echo <new limit> > +/dev/cgroup/memory/<group>/memory.mem.usage_in_bytes``. However, the latter +operation is not guaranteed to succeed. Basic ``sysfs`` Interfaces for System Suspend and Hibernation =============================================================
kernel/power/snapshot.c +11 -5
@@ -1698,16 +1698,20 @@ int hibernate_preallocate_memory(void)ktime_t start, stop;int error; -pr_info ("Preallocating image memory... " ); +pr_info ("Preallocating hibernation image memory\n" ); start =ktime_get (); error =memory_bm_create (&orig_bm,GFP_IMAGE ,PG_ANY ); -if (error) +if (error) { +pr_err ("Cannot allocate original bitmap\n" ); goto err_out; + } error =memory_bm_create (©_bm,GFP_IMAGE ,PG_ANY ); -if (error) +if (error) { +pr_err ("Cannot allocate copy bitmap\n" ); goto err_out; + } alloc_normal =0 ; alloc_highmem =0 ;
@@ -1797,8 +1801,11 @@ int hibernate_preallocate_memory(void) alloc -= pages; pages += pages_highmem; pages_highmem =preallocate_image_highmem (alloc); -if (pages_highmem < alloc) +if (pages_highmem < alloc) { +pr_err ("image allocation is %lu pages short\n" , + alloc - pages_highmem); goto err_out; + } pages += pages_highmem;/* * size is the desired number of saveable pages to leave in
@@ -1835,7 +1842,6 @@ int hibernate_preallocate_memory(void)return 0 ; err_out: -pr_cont ("\n" );swsusp_free ();return -ENOMEM ; }
Signature · 1 line
2.24.0.432.g9d3f5f5b63-goog
Any comments on this?
I'd like to point out that this isn't just a righteous nitpick. I've seen decisions being taken based on the reasonable assumption that hibernation can be used under the same circumstances as suspend-to-RAM. These decisions involved serious time and money. Things may have moved differently with a clearer understanding of these limitations. It does us (Linux) no good to omit these warnings.
Quoted 102 lines · Luigi Semenzato
Entering hibernation (suspend-to-disk) will fail if the kernel cannot allocate enough memory to create a snapshot of all pages in use; i.e., if memory in use is over 1/2 of total RAM. This patch makes this limitation clearer in the documentation. Without it, users may assume that hibernation can replace suspend-to-RAM when in fact its functionality is more limited.
Signed-off-by Luigi Semenzato <[email protected]>--- Documentation/admin-guide/pm/sleep-states.rst | 18 +++++++++++++++++- kernel/power/snapshot.c | 16 +++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-)Documentation/admin-guide/pm/sleep-states.rst +17
-1@@ -112,7 +112,9 @@ Hibernation This state (also referred to as Suspend-to-Disk or STD) offers the greatest energy savings and can be used even in the absence of low-level platform support for system suspend. However, it requires some low-level code for resuming the -system to be present for the underlying CPU architecture. +system to be present for the underlying CPU architecture. Additionally, the +current implementation can enter the hibernation state only when memory +pressure is low (see "Limitations" below). Hibernation is significantly different from any of the system suspend variants. It takes three system state changes to put it into hibernation and two system@@ -149,6 +151,20 @@ Hibernation is supported if the :c:macro:`CONFIG_HIBERNATION` kernel configuration option is set. However, this option can only be set if support for the given CPU architecture includes the low-level code for system resume. +Limitations of Hibernation +========================== + +When entering hibernation, the kernel tries to allocate a chunk of memory large +enough to contain a copy of all pages in use, to use it for the system +snapshot. If the allocation fails, the system cannot hibernate and the +operation fails with ENOMEM. This will happen, for instance, when the total +amount of anonymous pages (process data) exceeds 1/2 of total RAM. + +One possible workaround (besides terminating enough processes) is to force +excess anonymous pages out to swap before hibernating. This can be achieved +with memcgroups, by lowering memory usage limits with ``echo <new limit> > +/dev/cgroup/memory/<group>/memory.mem.usage_in_bytes``. However, the latter +operation is not guaranteed to succeed. Basic ``sysfs`` Interfaces for System Suspend and Hibernation =============================================================kernel/power/snapshot.c +11
-6@@ -1698,16 +1698,20 @@ int hibernate_preallocate_memory(void)ktime_t start, stop;int error; -pr_info ("Preallocating image memory... " ); +pr_info ("Preallocating hibernation image memory\n" ); start =ktime_get (); error =memory_bm_create (&orig_bm,GFP_IMAGE ,PG_ANY ); -if (error) +if (error) { +pr_err ("Cannot allocate original bitmap\n" ); goto err_out; + } error =memory_bm_create (©_bm,GFP_IMAGE ,PG_ANY ); -if (error) +if (error) { +pr_err ("Cannot allocate copy bitmap\n" ); goto err_out; + } alloc_normal =0 ; alloc_highmem =0 ;@@ -1797,8 +1801,11 @@ int hibernate_preallocate_memory(void) alloc -= pages; pages += pages_highmem; pages_highmem =preallocate_image_highmem (alloc); -if (pages_highmem < alloc) +if (pages_highmem < alloc) { +pr_err ("image allocation is %lu pages short\n" , + alloc - pages_highmem); goto err_out; + } pages += pages_highmem;/* * size is the desired number of saveable pages to leave in @@ -1835,7 +1842,6 @@ int hibernate_preallocate_memory(void)return 0 ; err_out: -pr_cont ("\n" );swsusp_free ();return -ENOMEM ; } --2.24.0.432.g9d3f5f5b63-goog
Rafael J. Wysocki
maintainerQuoted 2 lines · Luigi Semenzato
Any comments on this?
Nothing fundamental.
I would prefer two patches, though, one adding the messages to snapshot.c and the other to update the documentation.
Quoted 6 lines
I'd like to point out that this isn't just a righteous nitpick. I've seen decisions being taken based on the reasonable assumption that hibernation can be used under the same circumstances as suspend-to-RAM. These decisions involved serious time and money. Things may have moved differently with a clearer understanding of these limitations. It does us (Linux) no good to omit these warnings.
Fair enough.
Quoted 103 lines · Luigi Semenzato
Quoted 102 lines
Entering hibernation (suspend-to-disk) will fail if the kernel cannot allocate enough memory to create a snapshot of all pages in use; i.e., if memory in use is over 1/2 of total RAM. This patch makes this limitation clearer in the documentation. Without it, users may assume that hibernation can replace suspend-to-RAM when in fact its functionality is more limited.
Signed-off-by Luigi Semenzato <[email protected]>--- Documentation/admin-guide/pm/sleep-states.rst | 18 +++++++++++++++++- kernel/power/snapshot.c | 16 +++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-)Documentation/admin-guide/pm/sleep-states.rst +17
-1@@ -112,7 +112,9 @@ Hibernation This state (also referred to as Suspend-to-Disk or STD) offers the greatest energy savings and can be used even in the absence of low-level platform support for system suspend. However, it requires some low-level code for resuming the -system to be present for the underlying CPU architecture. +system to be present for the underlying CPU architecture. Additionally, the +current implementation can enter the hibernation state only when memory +pressure is low (see "Limitations" below). Hibernation is significantly different from any of the system suspend variants. It takes three system state changes to put it into hibernation and two system@@ -149,6 +151,20 @@ Hibernation is supported if the :c:macro:`CONFIG_HIBERNATION` kernel configuration option is set. However, this option can only be set if support for the given CPU architecture includes the low-level code for system resume. +Limitations of Hibernation +========================== + +When entering hibernation, the kernel tries to allocate a chunk of memory large +enough to contain a copy of all pages in use, to use it for the system +snapshot. If the allocation fails, the system cannot hibernate and the +operation fails with ENOMEM. This will happen, for instance, when the total +amount of anonymous pages (process data) exceeds 1/2 of total RAM. + +One possible workaround (besides terminating enough processes) is to force +excess anonymous pages out to swap before hibernating. This can be achieved +with memcgroups, by lowering memory usage limits with ``echo <new limit> > +/dev/cgroup/memory/<group>/memory.mem.usage_in_bytes``. However, the latter +operation is not guaranteed to succeed. Basic ``sysfs`` Interfaces for System Suspend and Hibernation =============================================================kernel/power/snapshot.c +11
-6@@ -1698,16 +1698,20 @@ int hibernate_preallocate_memory(void)ktime_t start, stop;int error; -pr_info ("Preallocating image memory... " ); +pr_info ("Preallocating hibernation image memory\n" ); start =ktime_get (); error =memory_bm_create (&orig_bm,GFP_IMAGE ,PG_ANY ); -if (error) +if (error) { +pr_err ("Cannot allocate original bitmap\n" ); goto err_out; + } error =memory_bm_create (©_bm,GFP_IMAGE ,PG_ANY ); -if (error) +if (error) { +pr_err ("Cannot allocate copy bitmap\n" ); goto err_out; + } alloc_normal =0 ; alloc_highmem =0 ;@@ -1797,8 +1801,11 @@ int hibernate_preallocate_memory(void) alloc -= pages; pages += pages_highmem; pages_highmem =preallocate_image_highmem (alloc); -if (pages_highmem < alloc) +if (pages_highmem < alloc) { +pr_err ("image allocation is %lu pages short\n" , + alloc - pages_highmem); goto err_out; + } pages += pages_highmem;/* * size is the desired number of saveable pages to leave in @@ -1835,7 +1842,6 @@ int hibernate_preallocate_memory(void)return 0 ; err_out: -pr_cont ("\n" );swsusp_free ();return -ENOMEM ; } --2.24.0.432.g9d3f5f5b63-goog
Thanks. I'll split it into two then.
Quoted 122 lines · Rafael J. Wysocki
Quoted 2 lines · Luigi Semenzato
Any comments on this?
Nothing fundamental.
I would prefer two patches, though, one adding the messages to
snapshot.cand the other to update the documentation.Quoted 6 lines
I'd like to point out that this isn't just a righteous nitpick. I've seen decisions being taken based on the reasonable assumption that hibernation can be used under the same circumstances as suspend-to-RAM. These decisions involved serious time and money. Things may have moved differently with a clearer understanding of these limitations. It does us (Linux) no good to omit these warnings.
Fair enough.
Quoted 103 lines · Luigi Semenzato
Quoted 102 lines
Entering hibernation (suspend-to-disk) will fail if the kernel cannot allocate enough memory to create a snapshot of all pages in use; i.e., if memory in use is over 1/2 of total RAM. This patch makes this limitation clearer in the documentation. Without it, users may assume that hibernation can replace suspend-to-RAM when in fact its functionality is more limited.
Signed-off-by Luigi Semenzato <[email protected]>--- Documentation/admin-guide/pm/sleep-states.rst | 18 +++++++++++++++++- kernel/power/snapshot.c | 16 +++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-)Documentation/admin-guide/pm/sleep-states.rst +17
-1@@ -112,7 +112,9 @@ Hibernation This state (also referred to as Suspend-to-Disk or STD) offers the greatest energy savings and can be used even in the absence of low-level platform support for system suspend. However, it requires some low-level code for resuming the -system to be present for the underlying CPU architecture. +system to be present for the underlying CPU architecture. Additionally, the +current implementation can enter the hibernation state only when memory +pressure is low (see "Limitations" below). Hibernation is significantly different from any of the system suspend variants. It takes three system state changes to put it into hibernation and two system@@ -149,6 +151,20 @@ Hibernation is supported if the :c:macro:`CONFIG_HIBERNATION` kernel configuration option is set. However, this option can only be set if support for the given CPU architecture includes the low-level code for system resume. +Limitations of Hibernation +========================== + +When entering hibernation, the kernel tries to allocate a chunk of memory large +enough to contain a copy of all pages in use, to use it for the system +snapshot. If the allocation fails, the system cannot hibernate and the +operation fails with ENOMEM. This will happen, for instance, when the total +amount of anonymous pages (process data) exceeds 1/2 of total RAM. + +One possible workaround (besides terminating enough processes) is to force +excess anonymous pages out to swap before hibernating. This can be achieved +with memcgroups, by lowering memory usage limits with ``echo <new limit> > +/dev/cgroup/memory/<group>/memory.mem.usage_in_bytes``. However, the latter +operation is not guaranteed to succeed. Basic ``sysfs`` Interfaces for System Suspend and Hibernation =============================================================kernel/power/snapshot.c +11
-6@@ -1698,16 +1698,20 @@ int hibernate_preallocate_memory(void)ktime_t start, stop;int error; -pr_info ("Preallocating image memory... " ); +pr_info ("Preallocating hibernation image memory\n" ); start =ktime_get (); error =memory_bm_create (&orig_bm,GFP_IMAGE ,PG_ANY ); -if (error) +if (error) { +pr_err ("Cannot allocate original bitmap\n" ); goto err_out; + } error =memory_bm_create (©_bm,GFP_IMAGE ,PG_ANY ); -if (error) +if (error) { +pr_err ("Cannot allocate copy bitmap\n" ); goto err_out; + } alloc_normal =0 ; alloc_highmem =0 ;@@ -1797,8 +1801,11 @@ int hibernate_preallocate_memory(void) alloc -= pages; pages += pages_highmem; pages_highmem =preallocate_image_highmem (alloc); -if (pages_highmem < alloc) +if (pages_highmem < alloc) { +pr_err ("image allocation is %lu pages short\n" , + alloc - pages_highmem); goto err_out; + } pages += pages_highmem;/* * size is the desired number of saveable pages to leave in @@ -1835,7 +1842,6 @@ int hibernate_preallocate_memory(void)return 0 ; err_out: -pr_cont ("\n" );swsusp_free ();return -ENOMEM ; } --2.24.0.432.g9d3f5f5b63-goog