Skip to content

Commit 5545d56

Browse files
qianfengrongrafaeljw
authored andcommitted
PM: hibernate: Use vmalloc_array() and vcalloc() to improve code
Remove array_size() calls and replace vmalloc() and vzalloc() with vmalloc_array() and vcalloc() respectively to simplify the code in save_compressed_image() and load_compressed_image(). vmalloc_array() is also optimized better, resulting in less instructions being used, and vmalloc_array() handling overhead is lower [1]. Link: https://lore.kernel.org/lkml/abc66ec5-85a4-47e1-9759-2f60ab111971@vivo.com/ [1] Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com> Link: https://patch.msgid.link/20250817083636.53872-1-rongqianfeng@vivo.com [ rjw: Changelog edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent e246518 commit 5545d56

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

kernel/power/swap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ static int save_compressed_image(struct swap_map_handle *handle,
712712
goto out_clean;
713713
}
714714

715-
data = vzalloc(array_size(nr_threads, sizeof(*data)));
715+
data = vcalloc(nr_threads, sizeof(*data));
716716
if (!data) {
717717
pr_err("Failed to allocate %s data\n", hib_comp_algo);
718718
ret = -ENOMEM;
@@ -1225,14 +1225,14 @@ static int load_compressed_image(struct swap_map_handle *handle,
12251225
nr_threads = num_online_cpus() - 1;
12261226
nr_threads = clamp_val(nr_threads, 1, CMP_THREADS);
12271227

1228-
page = vmalloc(array_size(CMP_MAX_RD_PAGES, sizeof(*page)));
1228+
page = vmalloc_array(CMP_MAX_RD_PAGES, sizeof(*page));
12291229
if (!page) {
12301230
pr_err("Failed to allocate %s page\n", hib_comp_algo);
12311231
ret = -ENOMEM;
12321232
goto out_clean;
12331233
}
12341234

1235-
data = vzalloc(array_size(nr_threads, sizeof(*data)));
1235+
data = vcalloc(nr_threads, sizeof(*data));
12361236
if (!data) {
12371237
pr_err("Failed to allocate %s data\n", hib_comp_algo);
12381238
ret = -ENOMEM;

0 commit comments

Comments
 (0)