Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp334312lqo; Wed, 8 May 2024 00:44:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUSPYVApfLdEdWzkMTx0FSvv7Hh7h+gVd56/VDMCrO+p5pG7PT3pwpXubokrSqrvdacrFpNRMHo1YdySaGnxoIek0sCwgbheqN46nv+FA== X-Google-Smtp-Source: AGHT+IG0eQU8+TQ3NKypJrp8erIRy44KSMzHn3YhLyjF8CHfDLahWTjE3tnKQy+XhdzFTH26Ykpa X-Received: by 2002:a05:6a20:3953:b0:1ab:82fe:910b with SMTP id adf61e73a8af0-1afc8dc86e0mr2337803637.58.1715154275834; Wed, 08 May 2024 00:44:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715154275; cv=pass; d=google.com; s=arc-20160816; b=ZRisGp4NDza9ketBAuyHdCABG60lTXyx8TN8huBYGvrZo5L2MR89oaqaQo/i0Gv1we zh06U0jTZ7DOIy9LFU286CApEfUMmuBlp435rqxV58bdVm5wuFvUlDHwkgNgn9WJaRze xqDtrICce9K2voqWsPS6Xo4Xo3l1cO7v7LOdobYzjadpavVMT/EKzDr5uMjGsKt1RTZd gdoD8CI+cQCcyx6JBJAyRJVedwhum7WlzLN20dZZdvfBJL/BujohDK9KgI8Olcpnm15D Sa1hm31VngzTAq6fmwZzy6Bzzc0rsjH93WbNC8LKrTQj+B/8zZxCQVvWxZAigNIU8qGV wjaQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=wUr6LRaWPPkzD2etszVDMza5JPEXKiMrJmq3EUCQIHI=; fh=UKstJvjqAQ3P/Vkvglih02Z8FmmRnlaJbql9clnU9dw=; b=OVLvfO+9jYud0c8EOYXkDcvXK9D1tzsQHFYucC2SogSnz+Sn79wZFX49RX1VZW7jJw 8J7kSvBeCa0h/DBSGrCZ10KsY6wK2GzVfszI7Wj5OvdwGW9YKDkI1H7OGR5KL7wxxftL ZVwpe1bfx9qPX4LgUKYEV9Zkzh34cHLJlCnXqqxMVv/3rBiI17yxOqux70libqPu3/ip U0dijaqm2nTXtJ06nsC1m+IbHrRdP23pAQX8d1/rGvCNRi52uILFozktRcuX6IXNskDn 3P5U9jOpchOBsYPJtEIs5gHhoQ+l7Yg0uSIx7vT1h+8oLC8i11NU7uuvRlX4nIJRnZS9 bPfg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=O00YgaVt; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-172832-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172832-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id gr24-20020a056a004d1800b006ed87019e44si11331176pfb.132.2024.05.08.00.44.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:44:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172832-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=O00YgaVt; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-172832-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172832-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 6D912B2338B for ; Wed, 8 May 2024 07:43:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBD3F3E49C; Wed, 8 May 2024 07:42:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="O00YgaVt" Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 694983B298 for ; Wed, 8 May 2024 07:42:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715154161; cv=none; b=h0VSuMMQ9VqvCddCXdY0wTEX2w9L2WR3eO7tRlmK2Mp1N2vneshE6s0fvy3oH8hwUj28aj/i97nPRsVthUkteuZN9FcR9MPzAG/Hl/zSc9xvFnMyxz1QQKBMOOY3rLvt4WRgKHV6sDvtqBo6sXk71W74KmFqgk69M2dyNaMLOBM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715154161; c=relaxed/simple; bh=fwqjI0oJhsJ6IWcPj2TUi+YtZmx3QQeidZjvgSy1/xc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o7D96n6G4itqUF9yXQ4MzRF74a92RX2pv5EouF+bQpLRCg/up94RmJbu3Aivw0xeWqgPLW7eN5+gA3hSUB/d9a8KqVZPmXD9IYC16qI0/xahIpARHWu9yKdSuIvtyp97yW25Nz6nky70aXfRBdtpzbQqHelmZ39APzpopDe5rus= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=O00YgaVt; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2b5f3e20615so1054718a91.1 for ; Wed, 08 May 2024 00:42:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1715154160; x=1715758960; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wUr6LRaWPPkzD2etszVDMza5JPEXKiMrJmq3EUCQIHI=; b=O00YgaVty94AsK17uKUCbD/JhgikEa8rc0N6DCZ8mnY5qKj6l/e5HC3Xov9iwHksMa 6kn4utRXVlizLXtKRFcm5A03l/Li14cq7SIzcrbGmQPyqsjyJxvokavyEhYPBvNe3bbS S9stMTj3B539NTDhJHgGTZyfe0WiCgqU+WXGs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154160; x=1715758960; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wUr6LRaWPPkzD2etszVDMza5JPEXKiMrJmq3EUCQIHI=; b=O/Gx0JFwE7XEuetxoHkWUowxV3mgzBXQ0c23pOOnzJ8J1bHB40kcPxcI1yhy3OCIT0 lKXlt7g1NYfVqA4sebLkQJOpgxGjdUD/ByhbHSqFYw+ud3XjtFACRQXSlxp3w6X1OsUx PP6qV3Ix33q6QNGQtf/vgHD9tAF2aph1utj+hiNhRsLV3eBQkhA+BB7c25zmqJyxtFVC 2LRKe1u55234C6DivmYM0+qpoMOk228ABdyuaa/3woHMJe4MKGYa0cjrZq/aSZmWAIV+ YEu/zIKTfAf+3qvv8LIh5ISkcQShN9F8uqAL5tWNKM5ZJSrbRvwsu8qHu2EmUcTNsZZx NatQ== X-Gm-Message-State: AOJu0Yyp4oG3pUn2g/2IaJrqCSCuWhvmgpkbzjp9bnVHKDA5jHTn8pv7 a/QHkZnowLfrIndY640iYQ+yakqjEO+CooKOaeM0KfIeV6095MjR9bFAQBG9qIhep3qmGj+W2Qc = X-Received: by 2002:a17:90b:891:b0:2b4:abc7:d64b with SMTP id 98e67ed59e1d1-2b6163a0616mr1809932a91.6.1715154159769; Wed, 08 May 2024 00:42:39 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:ad4d:5f6c:6699:2da4]) by smtp.gmail.com with ESMTPSA id l5-20020a17090aec0500b002b328adaa40sm780011pjy.17.2024.05.08.00.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:42:39 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv3 02/19] zram: add lzo and lzorle compression backends support Date: Wed, 8 May 2024 16:41:55 +0900 Message-ID: <20240508074223.652784-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog In-Reply-To: <20240508074223.652784-1-senozhatsky@chromium.org> References: <20240508074223.652784-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/Kconfig | 23 +++++++++++++++ drivers/block/zram/Makefile | 3 ++ drivers/block/zram/backend_lzo.c | 44 +++++++++++++++++++++++++++++ drivers/block/zram/backend_lzo.h | 10 +++++++ drivers/block/zram/backend_lzorle.c | 44 +++++++++++++++++++++++++++++ drivers/block/zram/backend_lzorle.h | 10 +++++++ drivers/block/zram/zcomp.c | 7 +++++ 7 files changed, 141 insertions(+) create mode 100644 drivers/block/zram/backend_lzo.c create mode 100644 drivers/block/zram/backend_lzo.h create mode 100644 drivers/block/zram/backend_lzorle.c create mode 100644 drivers/block/zram/backend_lzorle.h diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index 8ecb74f83a5e..5d329a887b12 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -14,8 +14,31 @@ config ZRAM See Documentation/admin-guide/blockdev/zram.rst for more information. +config ZRAM_BACKEND_LZO + bool "lzo and lzo-rle compression support" + depends on ZRAM + select LZO_COMPRESS + select LZO_DECOMPRESS + +choice + prompt "Default zram compressor" + default ZRAM_DEF_COMP_LZORLE + depends on ZRAM + +config ZRAM_DEF_COMP_LZORLE + bool "lzo-rle" + depends on ZRAM_BACKEND_LZO + +config ZRAM_DEF_COMP_LZO + bool "lzo" + depends on ZRAM_BACKEND_LZO + +endchoice + config ZRAM_DEF_COMP string + default "lzo-rle" if ZRAM_DEF_COMP_LZORLE + default "lzo" if ZRAM_DEF_COMP_LZO default "unset-value" config ZRAM_WRITEBACK diff --git a/drivers/block/zram/Makefile b/drivers/block/zram/Makefile index de9e457907b1..2dcbc9b75d91 100644 --- a/drivers/block/zram/Makefile +++ b/drivers/block/zram/Makefile @@ -1,4 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_ZRAM_BACKEND_LZO) += backend_lzorle.o backend_lzo.o + zram-y := zcomp.o zram_drv.o obj-$(CONFIG_ZRAM) += zram.o diff --git a/drivers/block/zram/backend_lzo.c b/drivers/block/zram/backend_lzo.c new file mode 100644 index 000000000000..b88b408964cd --- /dev/null +++ b/drivers/block/zram/backend_lzo.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include + +#include "backend_lzo.h" + +static void *lzo_create(void) +{ + return kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); +} + +static void lzo_destroy(void *ctx) +{ + kfree(ctx); +} + +static int lzo_compress(void *ctx, const unsigned char *src, + unsigned char *dst, size_t *dst_len) +{ + int ret; + + ret = lzo1x_1_compress(src, PAGE_SIZE, dst, dst_len, ctx); + return ret == LZO_E_OK ? 0 : ret; +} + +static int lzo_decompress(void *ctx, const unsigned char *src, size_t src_len, + unsigned char *dst) +{ + size_t dst_len = PAGE_SIZE; + int ret; + + ret = lzo1x_decompress_safe(src, src_len, dst, &dst_len); + return ret == LZO_E_OK ? 0 : ret; +} + +struct zcomp_backend backend_lzo = { + .compress = lzo_compress, + .decompress = lzo_decompress, + .create_ctx = lzo_create, + .destroy_ctx = lzo_destroy, + .name = "lzo", +}; diff --git a/drivers/block/zram/backend_lzo.h b/drivers/block/zram/backend_lzo.h new file mode 100644 index 000000000000..377ccb7389e2 --- /dev/null +++ b/drivers/block/zram/backend_lzo.h @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifndef __BACKEND_LZO_H__ +#define __BACKEND_LZO_H__ + +#include "zcomp.h" + +extern struct zcomp_backend backend_lzo; + +#endif /* __BACKEND_LZO_H__ */ diff --git a/drivers/block/zram/backend_lzorle.c b/drivers/block/zram/backend_lzorle.c new file mode 100644 index 000000000000..9bf1843021b0 --- /dev/null +++ b/drivers/block/zram/backend_lzorle.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include + +#include "backend_lzorle.h" + +static void *lzorle_create(void) +{ + return kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); +} + +static void lzorle_destroy(void *ctx) +{ + kfree(ctx); +} + +static int lzorle_compress(void *ctx, const unsigned char *src, + unsigned char *dst, size_t *dst_len) +{ + int ret; + + ret = lzorle1x_1_compress(src, PAGE_SIZE, dst, dst_len, ctx); + return ret == LZO_E_OK ? 0 : ret; +} + +static int lzorle_decompress(void *ctx, const unsigned char *src, + size_t src_len, unsigned char *dst) +{ + size_t dst_len = PAGE_SIZE; + int ret; + + ret = lzo1x_decompress_safe(src, src_len, dst, &dst_len); + return ret == LZO_E_OK ? 0 : ret; +} + +struct zcomp_backend backend_lzorle = { + .compress = lzorle_compress, + .decompress = lzorle_decompress, + .create_ctx = lzorle_create, + .destroy_ctx = lzorle_destroy, + .name = "lzo-rle", +}; diff --git a/drivers/block/zram/backend_lzorle.h b/drivers/block/zram/backend_lzorle.h new file mode 100644 index 000000000000..5c1db65a38a4 --- /dev/null +++ b/drivers/block/zram/backend_lzorle.h @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifndef __BACKEND_LZORLE_H__ +#define __BACKEND_LZORLE_H__ + +#include "zcomp.h" + +extern struct zcomp_backend backend_lzorle; + +#endif /* __BACKEND_LZORLE_H__ */ diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index 0d0d2e6dbaa9..58fb3ac91f4b 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -15,7 +15,14 @@ #include "zcomp.h" +#include "backend_lzo.h" +#include "backend_lzorle.h" + static struct zcomp_backend *backends[] = { +#if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZO) + &backend_lzorle, + &backend_lzo, +#endif NULL }; -- 2.45.0.rc1.225.g2a3ae87e7f-goog