Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1238178lqh; Mon, 6 May 2024 01:00:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXLoR8cC+l3bptDxZlAZdRd/htMqSNviBrRKJWcoF2uepi6H/8avVa4HeJqxsTa3s+gy9/bqMk3SpXs8NjrRThONuMPD3R3pLzwHXJYDA== X-Google-Smtp-Source: AGHT+IEt2Ptsd3ymvYbaV7+WzLYlqoNaAADHWzu3OcLNKxfXfEfvoHtk+py1izelVdqDk5B0ym9I X-Received: by 2002:a17:903:183:b0:1ea:3798:e404 with SMTP id z3-20020a170903018300b001ea3798e404mr13587960plg.31.1714982455520; Mon, 06 May 2024 01:00:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714982455; cv=pass; d=google.com; s=arc-20160816; b=j802CDlhDwMmS1bROGgH5NkK0p/BLlcYbjCS9jINHhq0TSECPomujJyQcFW4jYpwBg j9CRyQaAGj9geFxyq/TeiWms0oTAmHVoPifbliTysxo0E86D0HN1P0B56HxdctnnTJFt zShibH28IhLkJwZj8e96JVEIUqxrnkyrVE0+J+u6gpHkKKGWIfJtUfQanRVXfGtmkgv7 GEQsRnJW/C3prCnh2YQ3EBobQrMS2g8cMBWTL6A3KXEK6DT0xUsisW7J/8ad8npgKz65 l1++uPDT5JprATBSccsxYTtUw2y1e7ee+9VuummHSerL0JxO8oilZCytkJxUTgrN+X5H uHhg== 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=EEH83ikFWbHDBUUzWu4h4KsSObV7EItvgFziqF5bCxw=; fh=UKstJvjqAQ3P/Vkvglih02Z8FmmRnlaJbql9clnU9dw=; b=VJdFD5vvwWTu6T6fcXz4r7//JDJ/cZiT9gVh//OB1e6uF7seq+h7nAkTzGEXbZ1Zyf N9LJeL/2cRuR8G69HNCEVaKSv5JMNGpJDObt8zzkPYxxmqIwAqKsOXYCG0tWsWv8LlDq 104uWKb3ykv+WLIMrQBDPk8/MYzQfX7YkYawVHy4oCmyb3mT/sm3Ze4qsjOVz+Aw6/32 kKNenFa7Uh8NlG+sc6poNri7cD2TxTqQxZyHgmyAKl6BRV1moU9IAkVhZQXFShE7vl9g 81Ov340RFXU8UrEjMi9YMBYk3pf9+c62TcR0YyZXK4XbGSAz76YgoYNdS1ZRUZ9mM8qs oOMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XkbjsdWa; 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-169451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169451-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 l21-20020a170902d35500b001ea26bf0919si7661013plk.467.2024.05.06.01.00.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 01:00:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169451-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=XkbjsdWa; 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-169451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169451-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 36E1AB20FDB for ; Mon, 6 May 2024 08:00:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F6FD142E77; Mon, 6 May 2024 07:59:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XkbjsdWa" Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 434371428FD for ; Mon, 6 May 2024 07:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714982346; cv=none; b=hIBb6LGZPrXlL55eEjuLzVUHVmIFI9eN0n/SF8vLG8XxAgbsYKVRJlLo5ZvK7FONokx0L2JlzVdUHkhb0mEjuXybIsQmXOS7XoWKEMjNBQ5fJMuXHfw5z+rbklM6ktuvflsOSdSDRuw4lpQ7BZ89BDLucGmMFxfqHJhSRM/vgdY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714982346; c=relaxed/simple; bh=kNJbXxfK8zdnskpjgM5oyiiq8zq2KQp2aiK9qKIm8Jk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HIcl5Heumx5DYuy2kcFhiJn5kXwqr368ef5wnr/e6tADmnadDXgefedaEwGK3e9CBr2ansHpwVXeTXdZuQbMCS4YkFsaWNQ79dUZcG+Ouf8/mc9oAi+Ng77bRZihW2FkCqkXDliK4x3AQkDukiAeLwLNHm1evrkLGJvPMlsmk6k= 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=XkbjsdWa; arc=none smtp.client-ip=209.85.214.172 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-f172.google.com with SMTP id d9443c01a7336-1ecddf96313so13319155ad.2 for ; Mon, 06 May 2024 00:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714982344; x=1715587144; 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=EEH83ikFWbHDBUUzWu4h4KsSObV7EItvgFziqF5bCxw=; b=XkbjsdWaI5kxkxIsPYMcVSotFcCqJRHDQuhAsAM1zhvrp6SiZxgh41SgUFPjD+8fOb lbWN4drWqJTZLsUt7PX62p51vTsDJqO5JjVZwCGTNQjKTwbXPyitoNSVcrIxgjx141vW ywzSZayTzvkYpIlAyWCDUxYuObsxDMPx9RXb4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714982344; x=1715587144; 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=EEH83ikFWbHDBUUzWu4h4KsSObV7EItvgFziqF5bCxw=; b=nWi3zLTntua08Noqm20rITzNcrm1i5ICvGkbOQZkiErgO6g/M3SxrzR7gFFlhAc3sF 5mUZSo7qkvZL+d/bknhGMQO909RAoslRx+os7Ywr2O+MPgMYlM9aFs1LWNduqz8rwYEf G1Yjy4TMuwsite4hX6g2JnZdnwqTXf1TWMiNI5ZTT9KJWnkQlVGGKoshwEDYTe5auodJ VBRsf6BfYsUlJxPHvjGOKjIRBVT7Sj4E6lNd/MwndClJK/DBktfQR1OHgb5ll3/Cbmw5 mxXS4lqPZDfU72SEqnaUPd9eXH9OlgQpL+x33+mfSl3kixomTvclKJxgDi8A/wqJyM2D OUrg== X-Gm-Message-State: AOJu0Yyzk3qzQnS2JyAl72edn/geoSDnliq9KgW8L0tD5qm+3JIWB72N aakHM7U2vQpSJV0Lodt3A8+tguvoh7tzZAZ+e1XFwZIuBikB92eAHswH/4vEUg== X-Received: by 2002:a17:902:d2cd:b0:1e3:e1d5:c680 with SMTP id n13-20020a170902d2cd00b001e3e1d5c680mr13775583plc.63.1714982344547; Mon, 06 May 2024 00:59:04 -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.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 00:59:04 -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 08/17] zram: add 842 compression backend support Date: Mon, 6 May 2024 16:58:21 +0900 Message-ID: <20240506075834.302472-9-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 | 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 91c07595d8b4..029827a6ddac 100644 --- a/drivers/block/zram/Makefile +++ b/drivers/block/zram/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_ZRAM_BACKEND_LZ4) += backend_lz4.o obj-$(CONFIG_ZRAM_BACKEND_LZ4HC) += backend_lz4hc.o obj-$(CONFIG_ZRAM_BACKEND_ZSTD) += backend_zstd.o obj-$(CONFIG_ZRAM_BACKEND_DEFLATE) += backend_deflate.o +obj-$(CONFIG_ZRAM_BACKEND_842) += backend_842.o zram-y := zcomp.o zram_drv.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