Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1657243lqm; Fri, 3 May 2024 02:27:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXhnLtTzLP0UC80Eh0qwwymnbg1S+MRqNHYoXkve3T4xOdTsEC03gO6o9ocGAaUn8t4yhrMT1W1YOQDW+C0u520tdJcWj3W4IkoDYVIlw== X-Google-Smtp-Source: AGHT+IETQCdQFYe5sjkQiwikYsm2n7TfEQmpAyWwjS2YIZSSQu00x616HoHh7OVSgioaGXH4MAVW X-Received: by 2002:a50:cccf:0:b0:572:47be:88a6 with SMTP id b15-20020a50cccf000000b0057247be88a6mr1149523edj.21.1714728434557; Fri, 03 May 2024 02:27:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714728434; cv=pass; d=google.com; s=arc-20160816; b=rlxoGGORCd4YzIuj6P3bGZzDjBeNBJGEiNWtBVDUsWpsazXWggmr83G9alFJW34v1I aIhKTHHbzU6BljO4RwcWrKedJ2Iwc6eK0+FYyLMpNO9l1Tphy7lozET7auFqlSDEcH44 lf3G9FZkHJZU0VIHSD6RA08wDoET3LOBENUxlsIpv3csYBwlZEY7EVKNsWorwYXxs/xY 6rr7NqBwqmcupV6x9WFa+EPbuRqtopGzzYykEpESS+5aNc2FTiqi9yx11bXLSTMpMoXg 6so214G1AqXQG1QfxFf8P88jc3HXmeWncjoHq3c81pvoqiiRg+xmCNl2y4G7NeBci5PN PC1g== 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=jVS3+TSlg0IqVrQHwIV1m7p4VAUVoaOGVLA7sdPdngs=; fh=UKstJvjqAQ3P/Vkvglih02Z8FmmRnlaJbql9clnU9dw=; b=AoVvdifekKNnrPeS/yd52bRxjhz0ZRg765Chpqv+ox9cKt3teL7C0zTakidwZ3MQs0 bogb5qJrNc1hurvSveZ7Qq61h5KrQRWa7ItGHed2Ij4eiaH4Ec8PxYp30OK4cNzBOV4r VEvpliCuIPDTR77vsYXmkIR0lzBwKoLUAKR2VN+W8bn8rfeTqnsj+Z+6NugqeUSvVpmk i6BVMlOCsTyZqV9wofBPoyre0Jj1E7HNCqxdL46dorUT8Kr3+TiiF1So8giOyjaGQll3 eQxS6dKQzYF/z5Ehj5YhSm32HgKu/8FSy5I8ljL1wHUJfqmZe5Svu7THmQiW2NBzqZTT gXng==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gvfitemo; 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-167443-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167443-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dg18-20020a0564021d1200b00572ad7452ffsi1149745edb.372.2024.05.03.02.27.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 02:27:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167443-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gvfitemo; 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-167443-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167443-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 am.mirrors.kernel.org (Postfix) with ESMTPS id F3B321F23BFF for ; Fri, 3 May 2024 09:19:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 38BEA1509A3; Fri, 3 May 2024 09:18:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="gvfitemo" Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 EB89214F9F2 for ; Fri, 3 May 2024 09:18:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714727925; cv=none; b=owjebyxXsIBas9oos5w+KtUQ8HN1Bgm6C8mfCpVNt5v4FNunBs+yRZuybp4HRm9UN0PoU26tsdJEazLJpZUAoZ6V95R9NLZkTcpTnlg6g+f3A0X1dMX3yH/Tnqp+CbVFEWgCTYnV5UFNwnskGuv7jfW+FwRj5gIa8VM3GrtJJ9o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714727925; c=relaxed/simple; bh=EKAT1WJh1EliVsTf5ivSjhdf0Ww0Lxw//zNfOlfD/R4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F1/XvIY+nWaGUNgKfnlN+HiwhMO5l0fBexJLVyaNYuSoa2SFiSBhdcpHp07trj49c0l4wml1yf/hFkoTKCuARZWHt6y85OszKrDZ0s1OCEj7GskhnW9DOqtpkAVfWvd3v7/QxFng9Iza06WB77juLfOl0MdqtH6QM2UudAOITPg= 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=gvfitemo; arc=none smtp.client-ip=209.85.210.175 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-f175.google.com with SMTP id d2e1a72fcca58-6ee12766586so2228481b3a.0 for ; Fri, 03 May 2024 02:18:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714727923; x=1715332723; 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=jVS3+TSlg0IqVrQHwIV1m7p4VAUVoaOGVLA7sdPdngs=; b=gvfitemoeBBMYIjFQz43cgxT49nmrxppM1yjkSPhjE23jj8KkvbI5LV9K/UW/hIhD8 /dvFGcY0OT+jGwn6f4+BfYfyh/VOdVTDxKMNE8FFNYry/ckxNwaNC5bVn/UMnQ6+VGJD DwowwjT1Rb+1kfZPG3Fw9KW1VbPRvi4sZNfOo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714727923; x=1715332723; 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=jVS3+TSlg0IqVrQHwIV1m7p4VAUVoaOGVLA7sdPdngs=; b=EVEuq+JUKBc+Rs05qPqEXY43jWiZ+DVvZEbFJTZwdg6rKFWypbQZw+zf7ov4bIaXdA +uXqE2lsJ1eA7D3935clXLY+DqPc7gFBf6KM4rEtkqdPHkTzlXrfLriwyd6ES9XKQtOE lJyDBT/PoGZFPCw7qEJcnFHTciUhQd1pijhg77bVjdTjwyEECO5AEkM040bt8B/Tnd7S czA/joT8FhMbR43wq+nvitNMKOwxAoe50RrVAxFpUnKAUMIzlYIdECG9ISn/+ptkTGIh kvkAse07URjd37UKv95TUa5BK3BIBHIqZgTAwJQan3J17PBFON9MK3YXX8WPyoha8HFr ZbJQ== X-Gm-Message-State: AOJu0YxGkXBFp7lrc7F1cMsP9uXw5O4p3+Ls/IsURAWy96idSjC0jNa2 AnX1jcMNwSHdMXuMO5kUFKPcwUjT+BlupeBjTvR+BOmlFbFpBlIYi/TsGIi/0w== X-Received: by 2002:a05:6a20:c91c:b0:1a9:509c:eba6 with SMTP id gx28-20020a056a20c91c00b001a9509ceba6mr2972873pzb.25.1714727923145; Fri, 03 May 2024 02:18:43 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 02:18:42 -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 03/14] zram: add lz4 compression backend support Date: Fri, 3 May 2024 18:17:28 +0900 Message-ID: <20240503091823.3616962-4-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 | 12 ++++++++ drivers/block/zram/Makefile | 1 + drivers/block/zram/backend_lz4.c | 47 ++++++++++++++++++++++++++++++++ drivers/block/zram/backend_lz4.h | 10 +++++++ drivers/block/zram/zcomp.c | 4 +++ 5 files changed, 74 insertions(+) create mode 100644 drivers/block/zram/backend_lz4.c create mode 100644 drivers/block/zram/backend_lz4.h diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index a1fe8b989ee2..02d20a30bf6c 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -21,6 +21,13 @@ config ZRAM_BACKEND_LZO select LZO_COMPRESS select LZO_DECOMPRESS +config ZRAM_BACKEND_LZ4 + bool "lz4 compression support" + depends on ZRAM + default n + select LZ4_COMPRESS + select LZ4_DECOMPRESS + choice prompt "Default zram compressor" default ZRAM_DEF_COMP_LZORLE @@ -34,12 +41,17 @@ config ZRAM_DEF_COMP_LZO bool "lzo" depends on ZRAM_BACKEND_LZO +config ZRAM_DEF_COMP_LZ4 + bool "lz4" + depends on ZRAM_BACKEND_LZ4 + endchoice config ZRAM_DEF_COMP string default "lzo-rle" if ZRAM_DEF_COMP_LZORLE default "lzo" if ZRAM_DEF_COMP_LZO + default "lz4" if ZRAM_DEF_COMP_LZ4 default "unset-value" config ZRAM_WRITEBACK diff --git a/drivers/block/zram/Makefile b/drivers/block/zram/Makefile index 2dcbc9b75d91..1be5d2657960 100644 --- a/drivers/block/zram/Makefile +++ b/drivers/block/zram/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_ZRAM_BACKEND_LZO) += backend_lzorle.o backend_lzo.o +obj-$(CONFIG_ZRAM_BACKEND_LZ4) += backend_lz4.o zram-y := zcomp.o zram_drv.o diff --git a/drivers/block/zram/backend_lz4.c b/drivers/block/zram/backend_lz4.c new file mode 100644 index 000000000000..697592dbabe2 --- /dev/null +++ b/drivers/block/zram/backend_lz4.c @@ -0,0 +1,47 @@ +#include +#include +#include + +#include "backend_lz4.h" + +static void *lz4_create(void) +{ + return vmalloc(LZ4_MEM_COMPRESS); +} + +static void lz4_destroy(void *ctx) +{ + vfree(ctx); +} + +static int lz4_compress(void *ctx, const unsigned char *src, + unsigned char *dst, size_t *dst_len) +{ + int ret; + + ret = LZ4_compress_default(src, dst, PAGE_SIZE, *dst_len, ctx); + if (!ret) + return -EINVAL; + *dst_len = ret; + return 0; +} + +static int lz4_decompress(void *ctx, const unsigned char *src, + size_t src_len, unsigned char *dst) +{ + int dst_len = PAGE_SIZE; + int ret; + + ret = LZ4_decompress_safe(src, dst, src_len, dst_len); + if (ret < 0) + return -EINVAL; + return 0; +} + +struct zcomp_backend backend_lz4 = { + .compress = lz4_compress, + .decompress = lz4_decompress, + .create_ctx = lz4_create, + .destroy_ctx = lz4_destroy, + .name = "lz4", +}; diff --git a/drivers/block/zram/backend_lz4.h b/drivers/block/zram/backend_lz4.h new file mode 100644 index 000000000000..a5fb5564835c --- /dev/null +++ b/drivers/block/zram/backend_lz4.h @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifndef __BACKEND_LZ4_H__ +#define __BACKEND_LZ4_H__ + +#include "zcomp.h" + +extern struct zcomp_backend backend_lz4; + +#endif /* __BACKEND_LZ4_H__ */ diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index 58fb3ac91f4b..902bdaf7e299 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -17,11 +17,15 @@ #include "backend_lzo.h" #include "backend_lzorle.h" +#include "backend_lz4.h" static struct zcomp_backend *backends[] = { #if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZO) &backend_lzorle, &backend_lzo, +#endif +#if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZ4) + &backend_lz4, #endif NULL }; -- 2.45.0.rc1.225.g2a3ae87e7f-goog