From patchwork Wed Oct 4 09:30:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikhil V X-Patchwork-Id: 148203 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6359:6f87:b0:13f:353d:d1ed with SMTP id tl7csp2493893rwb; Wed, 4 Oct 2023 02:32:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQjZliL1A9YigCOTyE6yE1a7OrNnC1QFjSD2D6ijyj4u5EPJFUvMc8/fYG14T7JWl4amFE X-Received: by 2002:a05:6358:7e07:b0:134:e301:2c21 with SMTP id o7-20020a0563587e0700b00134e3012c21mr1879639rwm.15.1696411921840; Wed, 04 Oct 2023 02:32:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696411921; cv=none; d=google.com; s=arc-20160816; b=V9s9e3hAUy6SCjo6+AHz1u6j/m44TMLaFboWTfJ6ijzaux/bJzdND/E8OhRZ59GznJ E9dZyhU+T5CCQq9il8/vZitE4FwqrLw5J5a+v4TJzCQYaRSLugCZ7jj7e1GdFdgjrN9I 432iiG9j1zkKtpLCN5O6/cJdV3Z2SdbJKi+vn7n5KbMoWkcl/WhN0+jRK2kYCGOVqIal 39XDCgES46aDiT0EF1I+g/WSIOgLYRqc5wdm6QfFEqVRdvmHxqYhfJ9AHsJ9S0Enhuhy BhXi8lwOB3xCMZDo98h3CT5PBjCf+bWF3Wn+wVc8aJs2qxO+1OXaDp4rOk98K2c3cGEM 58jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=wnEVueqW2Ie782jPnN6bTnl8JvpCkXT/HqBAzXopZdM=; fh=RT22Jop1RotagAIZ6bzZKPGHo7RKiQKoN+d0YCMamJ8=; b=n7wZBdrdi+o4SQ+H27TPpTO6rl68Hm+UKGeQiSKZDndW17RZ9mXjyJFNMY+3e+N6PN q7tLtvYKg/IIwOwF7v1aTa9MDL7eBnp4wJUvCVF1R9zcSXr3/n9ZYT480lkggv6lEsQs 36Hj65MJ5EtmlZoA239CJ92EgO5Vt1avxiWUzQvt9RsUQZPiIJ5/LXEuLWGw8Xo6RKCP wufPtLggO+HqfljV9W+pVY7M8j7cmDnCsFFMK5Npnks33WIhpkEfR/cg6jj5Pe0Hn1p/ xZ7TaKTBvgZonZdeA808biRrwxCz6uBICnJk/QoAY7Y5NIlHN57P+KwQ5jOgbVeIw7vs ohaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=JH2p20iA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id p5-20020a17090a74c500b00263eb5054fdsi1151181pjl.32.2023.10.04.02.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 02:32:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=JH2p20iA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D39FB81E9A7C; Wed, 4 Oct 2023 02:32:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242012AbjJDJb4 (ORCPT + 18 others); Wed, 4 Oct 2023 05:31:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242032AbjJDJbx (ORCPT ); Wed, 4 Oct 2023 05:31:53 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D830E8; Wed, 4 Oct 2023 02:31:44 -0700 (PDT) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3949OQud029334; Wed, 4 Oct 2023 09:31:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=wnEVueqW2Ie782jPnN6bTnl8JvpCkXT/HqBAzXopZdM=; b=JH2p20iAI1ElQfxVH1L+WywkPIOaGFZWCPEBOfALgcsMtq6cITQs4LDqZquEBR68q88T kxHNTbyciqfFiuugLr2A5eJO2LUA3Pau7HVDIHzUmwE8/cvRqCSuYaiR9ZnsjWrcCWHY wcg255nwpfFSGJrLbr6+nZrf7AT+ZA1PCjEiT+I9uap9IwvCEzMIF4/iJYl6j/RuCIXc MXrEggHFqKy2dCRwROgOPpKeIYEJxsjd9mW2InnKaY3ybl9YoEVLQroj5t/MFZTO30hW GGg9qW5lIdp9U0/vTE7BaNzvkIjAQvdbUIkZoKC3dPm0sLz8DlcHZdrGdNzfCxTOgecE WA== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tgbjkkf70-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Oct 2023 09:31:24 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3949VNYm023177 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 4 Oct 2023 09:31:23 GMT Received: from hu-nprakash-blr.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Wed, 4 Oct 2023 02:31:16 -0700 From: Nikhil V To: "Rafael J. Wysocki" , Len Brown , Pavel Machek CC: Nikhil V , Jonathan Corbet , Catalin Marinas , Peter Zijlstra , Tejun Heo , Randy Dunlap , "Paul E. McKenney" , "Steven Rostedt (Google)" , , , , , , , , , Subject: [PATCH 3/4] PM: hibernate: Add support for LZ4 compression for hibernation Date: Wed, 4 Oct 2023 15:00:16 +0530 Message-ID: <9e1927dfca073afd71e0db24c81a1846a9748f52.1696410298.git.quic_nprakash@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: M-fkFfWTRyC3JVQ89Uj1-CqE8oXAaX6O X-Proofpoint-GUID: M-fkFfWTRyC3JVQ89Uj1-CqE8oXAaX6O X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-04_01,2023-10-02_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310040067 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 04 Oct 2023 02:32:00 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778816827325067547 X-GMAIL-MSGID: 1778816827325067547 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 --- kernel/power/Kconfig | 5 +++++ kernel/power/hibernate.c | 25 ++++++++++++++++++++++--- kernel/power/power.h | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig index bc449d05c23d..03e2cd652f20 100644 --- a/kernel/power/Kconfig +++ b/kernel/power/Kconfig @@ -100,11 +100,16 @@ config HIBERNATION_COMP_LZO bool "lzo" depends on CRYPTO_LZO +config HIBERNATION_COMP_LZ4 + bool "lz4" + depends on CRYPTO_LZ4 + endchoice config HIBERNATION_DEF_COMP string default "lzo" if HIBERNATION_COMP_LZO + default "lz4" if HIBERNATION_COMP_LZ4 help Default compressor to be used for hibernation. diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index ed9901b75333..87be8cda9b9b 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -721,6 +721,9 @@ static int load_image_and_restore(bool snapshot_test) return error; } +#define COMPRESSION_ALGO_LZO "lzo" +#define COMPRESSION_ALGO_LZ4 "lz4" + /** * hibernate - Carry out system hibernation, including saving the image. */ @@ -780,11 +783,24 @@ int hibernate(void) if (hibernation_mode == HIBERNATION_PLATFORM) flags |= SF_PLATFORM_MODE; - if (nocompress) + if (nocompress) { flags |= SF_NOCOMPRESS_MODE; - else + } else { flags |= SF_CRC32_MODE; + /* + * By default, LZO compression is enabled. Use SF_COMPRESSION_ALG_LZ4 + * to override this behaviour and use LZ4. + * + * Refer kernel/power/power.h for more details + */ + + if (!strcmp(hib_comp_algo, COMPRESSION_ALGO_LZ4)) + flags |= SF_COMPRESSION_ALG_LZ4; + else + flags |= SF_COMPRESSION_ALG_LZO; + } + pm_pr_dbg("Writing hibernation image.\n"); error = swsusp_write(flags); swsusp_free(); @@ -974,7 +990,10 @@ static int software_resume(void) * the algorithm support. */ if (!(swsusp_header_flags & SF_NOCOMPRESS_MODE)) { - strscpy(hib_comp_algo, default_compressor, sizeof(hib_comp_algo)); + if (swsusp_header_flags & SF_COMPRESSION_ALG_LZ4) + strscpy(hib_comp_algo, COMPRESSION_ALGO_LZ4, sizeof(hib_comp_algo)); + else + strscpy(hib_comp_algo, default_compressor, sizeof(hib_comp_algo)); if (crypto_has_comp(hib_comp_algo, 0, 0) != 1) { pr_err("%s compression is not available\n", hib_comp_algo); error = -EOPNOTSUPP; diff --git a/kernel/power/power.h b/kernel/power/power.h index d9bf10d92546..026d40e0972a 100644 --- a/kernel/power/power.h +++ b/kernel/power/power.h @@ -167,11 +167,25 @@ extern int swsusp_swap_in_use(void); * Flags that can be passed from the hibernatig hernel to the "boot" kernel in * the image header. */ +#define SF_COMPRESSION_ALG_LZO 0 /* dummy, details given below */ #define SF_PLATFORM_MODE 1 #define SF_NOCOMPRESS_MODE 2 #define SF_CRC32_MODE 4 #define SF_HW_SIG 8 +/* + * Bit to indicate the compression algorithm to be used(for LZ4). The same + * could be checked while saving/loading image to/from disk to use the + * corresponding algorithms. + * + * By default, LZO compression is enabled if SF_CRC32_MODE is set. Use + * SF_COMPRESSION_ALG_LZ4 to override this behaviour and use LZ4. + * + * SF_CRC32_MODE, SF_COMPRESSION_ALG_LZO(dummy) -> Compression, LZO + * SF_CRC32_MODE, SF_COMPRESSION_ALG_LZ4 -> Compression, LZ4 + */ +#define SF_COMPRESSION_ALG_LZ4 16 + /* kernel/power/hibernate.c */ int swsusp_check(bool exclusive); extern void swsusp_free(void);