Skip to content

Commit 8bc2973

Browse files
vnikhilprakashrafaeljw
authored andcommitted
PM: hibernate: Add support for LZ4 compression for hibernation
Extend the support for LZ4 compression to be used with hibernation. The main idea is that different compression algorithms have different characteristics and hibernation may benefit when it uses any of these algorithms: a default algorithm, having higher compression rate but is slower(compression/decompression) and a secondary algorithm, that is faster(compression/decompression) but has lower compression rate. LZ4 algorithm has better decompression speeds over LZO. This reduces the hibernation image restore time. As per test results: LZO LZ4 Size before Compression(bytes) 682696704 682393600 Size after Compression(bytes) 146502402 155993547 Decompression Rate 335.02 MB/s 501.05 MB/s Restore time 4.4s 3.8s LZO is the default compression algorithm used for hibernation. Enable CONFIG_HIBERNATION_COMP_LZ4 to set the default compressor as LZ4. Signed-off-by: Nikhil V <quic_nprakash@quicinc.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent a06c6f5 commit 8bc2973

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

kernel/power/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,16 @@ config HIBERNATION_COMP_LZO
101101
bool "lzo"
102102
depends on CRYPTO_LZO
103103

104+
config HIBERNATION_COMP_LZ4
105+
bool "lz4"
106+
depends on CRYPTO_LZ4
107+
104108
endchoice
105109

106110
config HIBERNATION_DEF_COMP
107111
string
108112
default "lzo" if HIBERNATION_COMP_LZO
113+
default "lz4" if HIBERNATION_COMP_LZ4
109114
help
110115
Default compressor to be used for hibernation.
111116

kernel/power/hibernate.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,9 @@ static int load_image_and_restore(void)
727727
return error;
728728
}
729729

730+
#define COMPRESSION_ALGO_LZO "lzo"
731+
#define COMPRESSION_ALGO_LZ4 "lz4"
732+
730733
/**
731734
* hibernate - Carry out system hibernation, including saving the image.
732735
*/
@@ -786,11 +789,24 @@ int hibernate(void)
786789

787790
if (hibernation_mode == HIBERNATION_PLATFORM)
788791
flags |= SF_PLATFORM_MODE;
789-
if (nocompress)
792+
if (nocompress) {
790793
flags |= SF_NOCOMPRESS_MODE;
791-
else
794+
} else {
792795
flags |= SF_CRC32_MODE;
793796

797+
/*
798+
* By default, LZO compression is enabled. Use SF_COMPRESSION_ALG_LZ4
799+
* to override this behaviour and use LZ4.
800+
*
801+
* Refer kernel/power/power.h for more details
802+
*/
803+
804+
if (!strcmp(hib_comp_algo, COMPRESSION_ALGO_LZ4))
805+
flags |= SF_COMPRESSION_ALG_LZ4;
806+
else
807+
flags |= SF_COMPRESSION_ALG_LZO;
808+
}
809+
794810
pm_pr_dbg("Writing hibernation image.\n");
795811
error = swsusp_write(flags);
796812
swsusp_free();
@@ -980,7 +996,10 @@ static int software_resume(void)
980996
* the algorithm support.
981997
*/
982998
if (!(swsusp_header_flags & SF_NOCOMPRESS_MODE)) {
983-
strscpy(hib_comp_algo, default_compressor, sizeof(hib_comp_algo));
999+
if (swsusp_header_flags & SF_COMPRESSION_ALG_LZ4)
1000+
strscpy(hib_comp_algo, COMPRESSION_ALGO_LZ4, sizeof(hib_comp_algo));
1001+
else
1002+
strscpy(hib_comp_algo, default_compressor, sizeof(hib_comp_algo));
9841003
if (crypto_has_comp(hib_comp_algo, 0, 0) != 1) {
9851004
pr_err("%s compression is not available\n", hib_comp_algo);
9861005
error = -EOPNOTSUPP;

kernel/power/power.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,25 @@ extern int swsusp_swap_in_use(void);
167167
* Flags that can be passed from the hibernatig hernel to the "boot" kernel in
168168
* the image header.
169169
*/
170+
#define SF_COMPRESSION_ALG_LZO 0 /* dummy, details given below */
170171
#define SF_PLATFORM_MODE 1
171172
#define SF_NOCOMPRESS_MODE 2
172173
#define SF_CRC32_MODE 4
173174
#define SF_HW_SIG 8
174175

176+
/*
177+
* Bit to indicate the compression algorithm to be used(for LZ4). The same
178+
* could be checked while saving/loading image to/from disk to use the
179+
* corresponding algorithms.
180+
*
181+
* By default, LZO compression is enabled if SF_CRC32_MODE is set. Use
182+
* SF_COMPRESSION_ALG_LZ4 to override this behaviour and use LZ4.
183+
*
184+
* SF_CRC32_MODE, SF_COMPRESSION_ALG_LZO(dummy) -> Compression, LZO
185+
* SF_CRC32_MODE, SF_COMPRESSION_ALG_LZ4 -> Compression, LZ4
186+
*/
187+
#define SF_COMPRESSION_ALG_LZ4 16
188+
175189
/* kernel/power/hibernate.c */
176190
int swsusp_check(bool exclusive);
177191
extern void swsusp_free(void);

0 commit comments

Comments
 (0)