Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1654531lqm; Fri, 3 May 2024 02:19:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVy0T5WCGXWYiWVrbBMF93I7dbhvTzhi6mNewgQxGaqNWVfUjktD2h0zs9zuXIBAK15F7ux23AWHn4ai7W3NDczvyytVlTNK8TgIqQDdA== X-Google-Smtp-Source: AGHT+IEhiWprkud4bQxRZ4e7ERMunFIVRZli9AvfGQfY/ZZMkvzzk6a3L+TPQI+sBq3kGIyrxHwQ X-Received: by 2002:a05:622a:d:b0:43c:60ba:81ab with SMTP id x13-20020a05622a000d00b0043c60ba81abmr2189433qtw.28.1714727952798; Fri, 03 May 2024 02:19:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714727952; cv=pass; d=google.com; s=arc-20160816; b=FI8p/AeEVQlSwmBMxGEI6lGg20ADV4Q4ui7OS/7nJMPN/V6edejM1TvSVnq+hWfcQp 1JNKLsKkS54egaQCt/EcTLVrua/hehdM3LJJE+x1y1+q7RH+GK3F8BgcI+zXKAfahCxU PI29Vm0thftt01tcFzBFBmnF67rUQkg4lq1QPOvsRRYbC6IkP9BfIQHT4OGWyXe2tHLk anrBVLCVeGHVvlfC7s71cjbIRPjxSjnOjdT0lB9W3DFl3pEC6rvHyzgxBQHiexRQoPNA Z7GqiGdOd51fIVGtnhRDu7nbEoLM/YKjz03l7NYYk1OiDSx8UM8QIrmAZXfZzCnBEnNC EDbg== 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=rsYTiLxr0Q8ahUxAJy9KMUOYceFG4XaXgzEH0fKzHJw=; fh=UKstJvjqAQ3P/Vkvglih02Z8FmmRnlaJbql9clnU9dw=; b=eKUuUY9U7JrbPA7H2kLpcBQxr7QfFxDFPcigzYvcyAgizX4tueuWKns/vzgzH6NOEt ImmOYlpFbK+NY5LFWFQCSY7PjHmhyqpls6q7KAkxUt9qy8rZ4QiLKa4uWBPASS6/E5QG zEAc/c8pqH5MOZbDSUcEf9y8QfLYfXKwbLk4uXH4GFWFzxgbplS9qqS8ThST8ivjuepT 57dcdj3yhNdrkwpb5Sl0FnfMAksAeElnLe3cZ/LyYbJh/LK8Z983Fds2mb4uPNyb7EVl HSgQJk3igWYpFyvOLeQ5ryqO50rF8OwcefbQdx9dC+71QscwOn1c9CfeOt7kLpYrRGAe 59JA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="fuKCh0K/"; 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-167442-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167442-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a7-20020a05622a02c700b00436895b4ce1si2947285qtx.543.2024.05.03.02.19.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 02:19:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167442-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="fuKCh0K/"; 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-167442-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167442-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 647FD1C21899 for ; Fri, 3 May 2024 09:19:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E84A14F9F8; Fri, 3 May 2024 09:18:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fuKCh0K/" Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.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 AF38F14F9C6 for ; Fri, 3 May 2024 09:18:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714727923; cv=none; b=HqVYOQCNEqGm4Ee8WyJafPeiry+HcdAyYNnGTFpx0iRMaAk0tpNFiIHcArZ3ydnE4t13WGNcwv60ii8CkyPMf1obQpFnAqjjor1mEOFattDOI2BGfLLwlNChm6MyTSerO7yithZarqGXwT5K1WN9BJlhCrHTF466bLZ0MndgJ6Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714727923; c=relaxed/simple; bh=mEwa89al010i30vmHvrIanhFp5RXfZdT6uAc3nZPiu0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C6YytLTnW9+z8qRIH9CUWvvGbeGeKPncT1Hjm5KBLvDenvhfyJX6pcauNN7zX1PUQzHI5RDVeGjKhDzimyYES1QrGQIPqtfbOqnTd+q/joBLff+TJD4B7KAkqS2gEVDzcR9k79Bjw2LIOLP+JGiRblVlTbi/8Ghy40a2YN7x3DM= 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=fuKCh0K/; arc=none smtp.client-ip=209.85.210.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-pf1-f172.google.com with SMTP id d2e1a72fcca58-6f4178aec15so3007020b3a.0 for ; Fri, 03 May 2024 02:18:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714727921; x=1715332721; 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=rsYTiLxr0Q8ahUxAJy9KMUOYceFG4XaXgzEH0fKzHJw=; b=fuKCh0K/lgIHzQ5VG4Ncz+ZTmBx8JxzY6es3phvPtgVcu6HpcWdLpoAb9yMLAVcjI0 r4EUhKPYRTG3vMST4X3aYjUflVGiwL/n48DGKgo4JYwsqda+rk/ldj8JZYlyZZGzSf7+ m95b7YcjZQN8vOyB2pnxOMuI1lXdI8QdM4Hok= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714727921; x=1715332721; 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=rsYTiLxr0Q8ahUxAJy9KMUOYceFG4XaXgzEH0fKzHJw=; b=Hepy6UF86srXX59YOlrBxBL7cyfzX9zXwORZ38DhWQvOmIFEDdYPFGGq5McKg9JTkr AiX3dvzaByXEKvR58dC/CZ/P7tbSEOlzHYtgn52hLFdwyMcElN3IC7/eA/hoEL/q0DU8 jwVUyWvHKGIg58eB8XIN5c02smwhqlvIoo/kwXn6TBaY+5rw7sY5TMLRe99jegw5Eapa cUMeWy7UCUDUd7H2iTfLHW8JXF8GvTAueYO3hOgmF0TGUQuYmM/2AtFc0Ti8Yh48G0xf rRL4JVMNz5WVlkMZW4nOSWHCI58e6tI36oNcWMfGflVL6BaSwDuAyFcbqbH7GMQq+a4h DZbA== X-Gm-Message-State: AOJu0Yxd6kKtykD587PkQp7tDzZbRjogxvZbvAmp6qQSz0ecFh3Omdg5 +1AwCO3xjYL23r+xQ2aYEWrt81MfVSLFJwBU74w+Q60CIxVto6eg734LUrlnR+il+0IAa7rnmUk = X-Received: by 2002:a05:6a20:d493:b0:1af:363d:64f5 with SMTP id im19-20020a056a20d49300b001af363d64f5mr2379485pzb.39.1714727920866; Fri, 03 May 2024 02:18:40 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:dc60:24a3:e365:f27c]) by smtp.gmail.com with ESMTPSA id j6-20020aa78d06000000b006ecec1f4b08sm2621938pfe.118.2024.05.03.02.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 02:18:40 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Sergey Senozhatsky Subject: [PATCH 02/14] zram: add lzo and lzorle compression backends support Date: Fri, 3 May 2024 18:17:27 +0900 Message-ID: <20240503091823.3616962-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog In-Reply-To: <20240503091823.3616962-1-senozhatsky@chromium.org> References: <20240503091823.3616962-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 | 24 ++++++++++++++++ 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, 142 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..a1fe8b989ee2 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -14,8 +14,32 @@ 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 + default n + 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..d9a003fbb360 --- /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