Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1237542lqh; Mon, 6 May 2024 00:59:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWJENIUVf+AFOCjl+JWJqBdWN//gsPuhyD9trCqsjfHu4kABnre+WvAcyQg7KR+lZWwXeqM6ioJG0sCSUpSZwWQ/2xZyrNnoepF75yNTA== X-Google-Smtp-Source: AGHT+IGm1ZqTnPb4IyZa/D7V4k/2mKa3RXwte+rBwTfyYxVwOsPPOQwP3gPTEh/xOldKux0UgezU X-Received: by 2002:a05:6358:5401:b0:18d:7b30:eec1 with SMTP id u1-20020a056358540100b0018d7b30eec1mr12351473rwe.19.1714982381764; Mon, 06 May 2024 00:59:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714982381; cv=pass; d=google.com; s=arc-20160816; b=YGbdJp/1YvYPH9ASLKsEdQnQdMtxPgQBVVv2ocYRHm3MLRvladojkKMFSYBKhWIL9+ 2cMqNV4WVMtBUvHgbSudECYLteaD3HxrdIz5/rhrIonpxIfXMcp6EiMc2PA00XJk2Mkd 9uZK2+x3ThY3izFihauMrmpG2Wvn444Qu9ojh+jlbklBBCagX2S9fma1msjAZlTbbzz/ DPnIJZrF0NUIMER4cRLOqFPA/sNJK7tnNBoe4zmCUyalCx5MijkS8kx1sJy6Kvf8MqcE 07MOWhYgkLEC+PT7BEz9qOkPvdDDyif2Zpy5azFLNBLYgmZpAjXgcUq8lD8gavto9aZ8 kYOQ== 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=L0Mv4SfSCJauo53idmCn/OLKAxbFH5Nfryii/SoMokUvILGzMbe4+S3CP7aFX1vTAm 7c4aKxl7neWYJxT+4USAw+wQ7qQgFj2i0aiBPVCDMJVL2I5iwffLQmCgRjtHuYePiXPT tBiHfkcoQTazJ9wxtQAyp2DCxGHOUXucSlySoer1KlWnFV1l7qvZXlA26WWXh00CbAH9 qz7DrGXmVmGGtxt6FYfYPXcSXOeLWmiDRJaorDUv/uAZ5uzqbRk6F+YuH8S/VJkavXQ4 Stbdq16dkjt3srE59vX391zXmGekD69lmaf51lHu0qtdP3mj2OBCvrhUYsxFz3iPUb7c uANA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KzkdujRZ; 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-169445-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169445-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bz29-20020a056a02061d00b0061bdaec93aasi5692361pgb.519.2024.05.06.00.59.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 00:59:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169445-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KzkdujRZ; 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-169445-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169445-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 54128282395 for ; Mon, 6 May 2024 07:59:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBC481420BB; Mon, 6 May 2024 07:58:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="KzkdujRZ" Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 564791411FE for ; Mon, 6 May 2024 07:58:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714982331; cv=none; b=ixZbtVpdG1L8gCRDo5dFBZbYsWjjTD2cKrMaoUDbrkxPRppA3yYI3e/qv7/XaH1u+kXJQNfdIKFQ5SiUx9u2WiM1o49c4tNrD6PKaqDMGk1NIRbweSDysiz4JQxaKSys6pdUkHtNfpZWe5l8gfTwkNpnmcLiy4KBhCg9ccB0ulI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714982331; c=relaxed/simple; bh=fwqjI0oJhsJ6IWcPj2TUi+YtZmx3QQeidZjvgSy1/xc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sx8iB3+ZVWsg8Rh4sg6q1H70NwcLNEt6QpAEB9Ae/O/Hghvw6pkS++Cx12JJreJTJDrnutDBOEWSQ9/+Zs5axN1n8gB98i5iPN4Mu6XJZLjTXYOknrxnEUTpyJUTpVsr/0Sk5mz5nHr3BXEMcbCy9ANl1DrwPLz8kwddlQLFtS8= 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=KzkdujRZ; arc=none smtp.client-ip=209.85.214.179 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-pl1-f179.google.com with SMTP id d9443c01a7336-1e3f17c6491so8133415ad.2 for ; Mon, 06 May 2024 00:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714982329; x=1715587129; 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=KzkdujRZdmF//QoBITEX4jredBIYFBEWx7AIDoJOHaLAZyqU9eno5yKpVXu5v2MmvO v2wTXafGOnMweH6YcUijDKbID5n4ESrZn73QGQ3n/gG284fcAevQxsq5KX1KpqGOUiC8 e4T1Xt0bKMuXjsxdqsvazFCUgyzUzf9XIb8cA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714982329; x=1715587129; 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=XOgsztDPwx+Xe9Af29rxo4ZLkrVqzxpmcm3bO449gODVH4kaq/E196jBavlF1gqQAy 1J5bic/kkZJ4HHtF0JbUnCcknkM8EKWmct4/XTLhmmP91t0MA2bbYv1fN5WTbI5VwOVH FP65rIlBoCPsT6N0OjXS7RYOzLjGnaJ5vrTtU+SisizaYwTctEjAteY5cr+X9b/71zyo GWNNlQ/iQTp6YXqpEx82QHMsKZySXJhXuwGZC92hNk3sRNYoROZoTpcHkcXrhJL3bgzT KZJydGstca+MI/NisAP0/Pyp618Z1JUAcBAgDuidAqiaoCtFSvXyZZmR/EXhzkUln2I8 Y5Dw== X-Gm-Message-State: AOJu0YypQGjwVWZBz9dD27qM7v8zf1/nRHoXebNlLW3khuzvCOv3APwg pzkrYryvZKVsLF4nzlV6TTfVexnmWSga9o+IeGW0u43BUZm+WnxScoHsWSSXlg== X-Received: by 2002:a17:902:ecc5:b0:1eb:d7ce:1946 with SMTP id a5-20020a170902ecc500b001ebd7ce1946mr9742490plh.52.1714982329560; Mon, 06 May 2024 00:58:49 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:4e24:10c3:4b65:e126]) by smtp.gmail.com with ESMTPSA id h6-20020a170902f54600b001ec64b128dasm7633772plf.129.2024.05.06.00.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 00:58:49 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 02/17] zram: add lzo and lzorle compression backends support Date: Mon, 6 May 2024 16:58:15 +0900 Message-ID: <20240506075834.302472-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog In-Reply-To: <20240506075834.302472-1-senozhatsky@chromium.org> References: <20240506075834.302472-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