Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3141058lqo; Wed, 15 May 2024 00:23:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXxkP3FaFkyINA4JOMIpjlg4KpKXmjRMiU1nMp8VvPuDU4nOQdZKwglLcUwpA1iQ1IMnPOFBVm0O83U+nFvYWG11CU7XC7QKnFMnZU47A== X-Google-Smtp-Source: AGHT+IHg2dxKj2/7jN9TBwdjCH/yurfkTXdFepC8RsyaTwJLwF5mWEVDsVtV19z4/r4sj+M5lJ+6 X-Received: by 2002:a05:6a00:c82:b0:6f4:4319:4cea with SMTP id d2e1a72fcca58-6f4e0387fe3mr26670001b3a.33.1715757811457; Wed, 15 May 2024 00:23:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715757811; cv=pass; d=google.com; s=arc-20160816; b=NWdkOs4bZjlrOM2DR4iI0QqhYiNwqqYb8I3hWn06ZQhvTJb7E+/OHohqIPunhuEi+O /7peDuRyl9XoUr2OBLCr/kMDh+2Kvdz1Ld+z3Vv9FLZSJHZfXulHx+2CUgE6McSPz/ko sYNPMV1/HRu6Y4mYr8K8wEs97KmwYJxXogKYf4TTU0V7GxD0sFCA7jQ1j+DQVtFfOf9q ILfZU7eqsQZqD1XzE0t98ikRLYonWP4mXxf2A/n4YsgQdbOO/nTGWAkB4sR4R4fbpCwu 0Yc9bt2wI7qtlnl9ttM4tek5YtAxwkCv9q6V7HgnH9IJG2xclB082/y6sBzroLEfLByB E8Jw== 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=R1BvSeNbTbBx82yan2V/RhWZavK2/Nwn3AwN6PoYkyI=; fh=UKstJvjqAQ3P/Vkvglih02Z8FmmRnlaJbql9clnU9dw=; b=H73TJWyTL4u4GcvwFKLalTA8Vb2odo7C18gjWS3lQrbfm79HDQJytfBzyGheK5uKCk Uwc8Q/Q6CCK6LfIKT+8g/lCe5mQZuzrOa4P72WP2b3afRlECQWwYKGWl6LCUrkGUoeXb 3uPRhiei0nzjolPZM+BPM/9VkG+VEckN53SAh6+q2KIT3LZtte90a3oy9RCB6L2i8aqZ ztcgWUeQmDfrVQaLMaxSvBAf9rR5Ui3M29wL4jevlljGzsQ6vVWUUDp9F3iX6SXQlld/ 2Ejm39N3+bc5vTj/DzBpCVMbCUoaR9vZ/4AUBD9W2z7OO0dnpsu3B1kc8B9Su5i3Sxtw pPEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lJ+dQfGo; 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-179559-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179559-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 41be03b00d2f7-63413d72d45si12809907a12.882.2024.05.15.00.23.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 00:23:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179559-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=lJ+dQfGo; 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-179559-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179559-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 5BA21B23609 for ; Wed, 15 May 2024 07:19:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18FBB5F84F; Wed, 15 May 2024 07:17:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="lJ+dQfGo" Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 7EEDA5BAC1 for ; Wed, 15 May 2024 07:17:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715757439; cv=none; b=dHYRL8u5UavhzOTuLUjySADW2zsYqhNMCI+08pgk/0fGFTbzNOqQhfCde5ItIHxEoCaTn2v10CYtAoIm783kumla1PobkQP9+BHAgb2VxXWCLWrNR1m6+dniRvKgSI7slQ9+KIq2QOr18oUYBEj2H7gqNPKCkFdkBmLaeZyGRzQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715757439; c=relaxed/simple; bh=a+rQHeyHWJr5E88fLAaNVtGpfAm1FcfbIk5kcHXBMNA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bgUSj7ViCeX77l3bsf8SD1kf1Zl93nLVESqYnRfaqZXQ2rU/S79w/YWmBoyjmSuL/tUVYF/tQinbLlNFhn4fy+nXOMXsrV835oAH0KVF6Nq4fWbyYsggu+yIrkop++KFRgiDUKJxWWzjkNDI2asPOy1WwHt+8Qur8GdVWBADMms= 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=lJ+dQfGo; arc=none smtp.client-ip=209.85.214.178 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-f178.google.com with SMTP id d9443c01a7336-1eb24e3a2d9so57050095ad.1 for ; Wed, 15 May 2024 00:17:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1715757437; x=1716362237; 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=R1BvSeNbTbBx82yan2V/RhWZavK2/Nwn3AwN6PoYkyI=; b=lJ+dQfGoknPf202DLVf0jTPVBcrR/7DNOXRUXwWsOokvW/u7EuVnY4BSJBtkugtJal W/vi8b/waDV2pZZdsTq7tQ1fwnxgBRQRpJa968Tx4lpkJ3N5/q2Bv0OFg1+r1G7gxSh9 mM55uHd8l3Ihr2n7khEHvDJUaZg0kBh6vCql0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715757437; x=1716362237; 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=R1BvSeNbTbBx82yan2V/RhWZavK2/Nwn3AwN6PoYkyI=; b=lCno1HyEB24RNXDjXG6U5DY7vRsbt1Z8+9K+X1weSC/l62hEG4HXzKLDXDNivjSVA2 qQYZglquu4MX/A+/Uz/OKYC5dwo6ddOxnm141rq+GE3h9zcc6lJSk3QWfTvSOzedp3QZ /jR/W4mD6+V1dH1SEQz/OQJ1AZxn5GvUuzD5i6wiK3W5/8F16aOlFcY5OFqIVV0YvtrO w7KFGs/v5g8zPjif6zF8M8f0tZfCcLkTQJBPqPdGNZL8yS1kyExTEaD1bdEhMcZ/1zjM HJ7nCXn91LCiUvLouGL3snDB7kvg43jKJEGlTTsIfnbH1ZAMUTh7c4qsdmzXmcY4U7Ws BQEA== X-Gm-Message-State: AOJu0Yz9dHFYGZ4xTXoB1ctoCQJAiCKv9AlFGmplRtCx60xOgBj3JgB7 MADiXFC7jxfnzNYfQ+2Pxs8efwoBS24WCgrjJGWNtiuN15WM/a8MPIMSNpY1bw== X-Received: by 2002:a17:902:e74a:b0:1e0:2977:9dfc with SMTP id d9443c01a7336-1ef43f4ea08mr235269795ad.55.1715757436880; Wed, 15 May 2024 00:17:16 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:111d:a618:3172:cd5b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c136d53sm110941605ad.254.2024.05.15.00.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 00:17:16 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 08/21] zram: add 842 compression backend support Date: Wed, 15 May 2024 16:12:45 +0900 Message-ID: <20240515071645.1788128-9-senozhatsky@chromium.org> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog In-Reply-To: <20240515071645.1788128-1-senozhatsky@chromium.org> References: <20240515071645.1788128-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 Add s/w 842 compression support. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/Kconfig | 11 ++++++ drivers/block/zram/Makefile | 1 + drivers/block/zram/backend_842.c | 68 ++++++++++++++++++++++++++++++++ drivers/block/zram/backend_842.h | 10 +++++ drivers/block/zram/zcomp.c | 4 ++ 5 files changed, 94 insertions(+) create mode 100644 drivers/block/zram/backend_842.c create mode 100644 drivers/block/zram/backend_842.h diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index 9dedd2edfb28..1e0e7e5910b8 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -44,6 +44,12 @@ config ZRAM_BACKEND_DEFLATE select ZLIB_DEFLATE select ZLIB_INFLATE +config ZRAM_BACKEND_842 + bool "842 compression support" + depends on ZRAM + select 842_COMPRESS + select 842_DECOMPRESS + choice prompt "Default zram compressor" default ZRAM_DEF_COMP_LZORLE @@ -73,6 +79,10 @@ config ZRAM_DEF_COMP_DEFLATE bool "deflate" depends on ZRAM_BACKEND_DEFLATE +config ZRAM_DEF_COMP_842 + bool "842" + depends on ZRAM_BACKEND_842 + endchoice config ZRAM_DEF_COMP @@ -83,6 +93,7 @@ config ZRAM_DEF_COMP default "lz4hc" if ZRAM_DEF_COMP_LZ4HC default "zstd" if ZRAM_DEF_COMP_ZSTD default "deflate" if ZRAM_DEF_COMP_DEFLATE + default "842" if ZRAM_DEF_COMP_842 default "unset-value" config ZRAM_WRITEBACK diff --git a/drivers/block/zram/Makefile b/drivers/block/zram/Makefile index 266430548437..0fdefd576691 100644 --- a/drivers/block/zram/Makefile +++ b/drivers/block/zram/Makefile @@ -7,5 +7,6 @@ zram-$(CONFIG_ZRAM_BACKEND_LZ4) += backend_lz4.o zram-$(CONFIG_ZRAM_BACKEND_LZ4HC) += backend_lz4hc.o zram-$(CONFIG_ZRAM_BACKEND_ZSTD) += backend_zstd.o zram-$(CONFIG_ZRAM_BACKEND_DEFLATE) += backend_deflate.o +zram-$(CONFIG_ZRAM_BACKEND_842) += backend_842.o obj-$(CONFIG_ZRAM) += zram.o diff --git a/drivers/block/zram/backend_842.c b/drivers/block/zram/backend_842.c new file mode 100644 index 000000000000..8ea7a230b890 --- /dev/null +++ b/drivers/block/zram/backend_842.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include +#include + +#include "backend_842.h" + +struct sw842_ctx { + void *mem; +}; + +static void destroy_842(void *ctx) +{ + struct sw842_ctx *zctx = ctx; + + kfree(zctx->mem); + kfree(zctx); +} + +static void *create_842(void) +{ + struct sw842_ctx *ctx; + + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return NULL; + + ctx->mem = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL); + if (!ctx->mem) + goto error; + + return ctx; + +error: + destroy_842(ctx); + return NULL; +} + +static int compress_842(void *ctx, const unsigned char *src, + unsigned char *dst, size_t *dst_len) +{ + struct sw842_ctx *zctx = ctx; + unsigned int dlen = *dst_len; + int ret; + + ret = sw842_compress(src, PAGE_SIZE, dst, &dlen, zctx->mem); + if (ret == 0) + *dst_len = dlen; + return ret; +} + +static int decompress_842(void *ctx, const unsigned char *src, size_t src_len, + unsigned char *dst) +{ + unsigned int dlen = PAGE_SIZE; + + return sw842_decompress(src, src_len, dst, &dlen); +} + +struct zcomp_backend backend_842 = { + .compress = compress_842, + .decompress = decompress_842, + .create_ctx = create_842, + .destroy_ctx = destroy_842, + .name = "842", +}; diff --git a/drivers/block/zram/backend_842.h b/drivers/block/zram/backend_842.h new file mode 100644 index 000000000000..c03a2396d7b2 --- /dev/null +++ b/drivers/block/zram/backend_842.h @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifndef __BACKEND_842_H__ +#define __BACKEND_842_H__ + +#include "zcomp.h" + +extern struct zcomp_backend backend_842; + +#endif /* __BACKEND_842_H__ */ diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index 9fc5477a6259..2a38126f4da3 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -21,6 +21,7 @@ #include "backend_lz4hc.h" #include "backend_zstd.h" #include "backend_deflate.h" +#include "backend_842.h" static struct zcomp_backend *backends[] = { #if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZO) @@ -38,6 +39,9 @@ static struct zcomp_backend *backends[] = { #endif #if IS_ENABLED(CONFIG_ZRAM_BACKEND_DEFLATE) &backend_deflate, +#endif +#if IS_ENABLED(CONFIG_ZRAM_BACKEND_842) + &backend_842, #endif NULL }; -- 2.45.0.rc1.225.g2a3ae87e7f-goog