From patchwork Fri May 3 09:17:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13652524 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.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 B0CB114F9CC for ; Fri, 3 May 2024 09:18:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714727924; cv=none; b=kJF6yVNZs+O5UgI1uAtaG7WoEoh7h4ZuWdkD/g35WisKOIiGXu1GkMRd4b+9FDOwHeMv20tMIIkZzxR1g9uley/hFu4UFs7943f0swS84B82QX6m64ITX69GJeXW9b+aIZAsCav0iiOqOZG32ZKkuOEeoIy3z5d++EUpmArKGS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714727924; c=relaxed/simple; bh=mEwa89al010i30vmHvrIanhFp5RXfZdT6uAc3nZPiu0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y+i0vR8vrScroaE0s7bOX/zdmZgbASNKvGjyIQTCRYPhe/cST6dzQ7X6fzng4p22LkLJactSbp+4mY6CI9XOaHM04jn5gpV107NV0OwHXePQTS/gN4DDe3tu8ahzsj+SZsARPZ5FOa9HxH5AaQbSyApyGDvUxELIevJ73LHeJ0U= 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.215.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fuKCh0K/" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-5ce6b5e3c4eso5328000a12.2 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=Ip+OhsISlpl5iC2zzbtIPXKJCkoyLSIEqlsxoL7PVxduBEoKSlK6QIdYRIpbAaRCFx +ZYfwH4QHVrI1Pee7zG3+9gw3M2EwXXj3EmR9a0pd9n5Wiou+UhMkQr8mKdp5NrDJuAP 2Fx5a04+jmeYcadoiwbEc2humDSJ2kt7iWkXwHxkxsAJT9YwmgYcGxRmUorjKVs1SbNe Xxa6gPnWGQjYMFCjlADNmGShzq1I7qszKAiKdPSijsHHiN7lr6SKYemU5MtUfxJ+h/Rj 1VWz7+4jvfS96P3meH7gsxkEFBsHeT/GUVPJl1cMguwMPAxN1KdrrgHYf55F1/NbzxSr LxZg== X-Forwarded-Encrypted: i=1; AJvYcCXypn20CWvQQMWz7i3LE8f5hy8PMsmThATL4/6eedTSxrzJc32fiWfrO4oYsfkpopGvNh12hUcEcqWKsjmkqAxSqIlRFTyTt7PahsM= X-Gm-Message-State: AOJu0YyL1hKjChZ40Gvbg67YYYxFMRhQfyCKN1czFfNuPPT92Qx1DUjY QZOcVA28rh+prx5LewNFhXkKXAq/hDWyz740MLvml4/NyLu9e/TknckXhjfqFg== X-Google-Smtp-Source: AGHT+IGxiRB7vnvbkRHjvRHbvxxuWmfnDZ/iS/JstbN0VYZKn5HHEsL5Fm4jdS2OZ5SG/gAbZyIyLg== 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-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 };