Skip to content

Commit

Permalink
PM: hibernate: add check of preallocate mem for image size pages
Browse files Browse the repository at this point in the history
Added a check on the return value of preallocate_image_highmem(). If
memory preallocate is insufficient, S4 cannot be done;

I am playing 4K video on a machine with AMD or other graphics card and
only 8GiB memory, and the kernel is not configured with CONFIG_HIGHMEM.
When doing the S4 test, the analysis found that when the pages get from
minimum_image_size() is large enough, The preallocate_image_memory() and
preallocate_image_highmem() calls failed to obtain enough memory. Add
the judgment that memory preallocate is insufficient;

"pages -= free_unnecessary_pages()" below will let pages to drop a lot,
so I wonder if it makes sense to add a judgment here.

Cc: stable@vger.kernel.org
Signed-off-by: xiongxin <xiongxin@kylinos.cn>
Signed-off-by: huanglei <huanglei@kylinos.cn>
  • Loading branch information
TGSP authored and intel-lab-lkp committed Nov 1, 2022
1 parent 1ae333b commit 1c27796
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion kernel/power/snapshot.c
Expand Up @@ -1738,6 +1738,7 @@ int hibernate_preallocate_memory(void)
struct zone *zone;
unsigned long saveable, size, max_size, count, highmem, pages = 0;
unsigned long alloc, save_highmem, pages_highmem, avail_normal;
unsigned long size_highmem;
ktime_t start, stop;
int error;

Expand Down Expand Up @@ -1863,7 +1864,13 @@ int hibernate_preallocate_memory(void)
pages_highmem += size;
alloc -= size;
size = preallocate_image_memory(alloc, avail_normal);
pages_highmem += preallocate_image_highmem(alloc - size);
size_highmem += preallocate_image_highmem(alloc - size);
if (size_highmem < (alloc - size)) {
pr_err("Image allocation is %lu pages short, exit\n",
alloc - size - pages_highmem);
goto err_out;
}
pages_highmem += size_highmem;
pages += pages_highmem + size;
}

Expand Down

0 comments on commit 1c27796

Please sign in to comment.