Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1655322lqm; Fri, 3 May 2024 02:21:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX/96xuRxKdKgJOIwU6wOCbNrPwO06BdH4LvU9fL2s4RLZWEsB57MVNyAxdPFqpX9H4voIVJKnNXU0Iao08fJnoH6ZFrize7irtmysVEw== X-Google-Smtp-Source: AGHT+IEkvsEQ3dJnP0i4klEs9JaAUKTHt0utZVuUlGHwOt4Ok6NaVZXU2XYDiPPS3WK39S10D4pM X-Received: by 2002:a05:620a:13e8:b0:790:eb7d:dde with SMTP id h8-20020a05620a13e800b00790eb7d0ddemr1890913qkl.52.1714728077632; Fri, 03 May 2024 02:21:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714728077; cv=pass; d=google.com; s=arc-20160816; b=p9eN51DGVHRKyF+8DsMA7eF1CJKoqHVQUmhTMvd8yy13sI1riVYeHa3s+XypdV2uLl 9KuIyvDnu9Zza6DodgodSukbwphuCGxRG8VmlqDSkPIUTGQm4OzY40DTZM27Fw+BBIFG LfUO1/LutyyKRpptUbNLNK2LlFhqiZRXpkc9Kt2fy/Pla2rxgxuA0LiPS6U4m3Bnin9L PS8dKGe+TfecCqyqnwDTNGmb3hj/qdb+4Q+dLpdBaA2hkpaiOf4y9NHvxNGhvbjz5uco rEybCHnIf71asK6EsFtWqGhgU1JpLrSgCidDJO1yQhaOYlO1oD8feQQgRF5uYLmFS/DR DU5g== 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=iwRLVjXgWWLXjDVCb4fkeW1Vrz1sREosaV/gl6sSJuc=; fh=UKstJvjqAQ3P/Vkvglih02Z8FmmRnlaJbql9clnU9dw=; b=vanU6UKprtF4xdJN+veCVBuNSXkt6O8EKR5nUfkaJxh1bX9WV4h1JHU9spMwQPF/tj 3DV1mqUJyNSl13+PnT8Fq7m+mHL8WYazqyxZns5JlTvHfpVAwD2ndHQyE5cOzDXjit2G 5GkadJtDo7LjQZd8WiHH0mirJ7kcygXWm66bUkbFr7xku2EgB1K6r4gFaGyiJRRCWa5X H86mtRGTVBbHnvtbwkQ5GcyIXedUo5SfztNG6FoircSBwTmRVYxTxv3mqBFnwpWChleT DXS5q+zdiUpfoJT7JRMxFz+ws6HmFyO1AlZDBLrmpM9AOm2/WUWiaYeyODMIQKCG0mbH nHGw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="h+cVZ/BY"; 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-167449-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167449-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. [147.75.199.223]) by mx.google.com with ESMTPS id b18-20020a05620a0cd200b00792643eee75si2602521qkj.709.2024.05.03.02.21.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 02:21:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167449-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="h+cVZ/BY"; 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-167449-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167449-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 503831C21ADC for ; Fri, 3 May 2024 09:21:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9AA3115356A; Fri, 3 May 2024 09:19:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="h+cVZ/BY" Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (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 C1ABE1534E4 for ; Fri, 3 May 2024 09:18:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714727939; cv=none; b=hA7MDezZee5kqEWbUK6DXItrnB6H6Yl+5h8qJC3AcWJvjn76VdB8IPiIKcsqKsCZZdVl1025DGnqQg18GJ1BjVOC986KJ9H8ddi+B1J+UjRpYvf1WEn1YmvnTm0LtiH7MdZ17KMunbVzAr8fpRn9KN4/VsfRP+dLMHNbQXbT6y0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714727939; c=relaxed/simple; bh=YnP0vVSisRTPEbtmrXjJHIL3Jcyv7aP26RJXhVEmW+M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MQsBJguevUF5FU0iJUeByLG/DuiGldr/fE2uBHn9V8rmTDdMyWCgvaSebBftAH90NoVVr6R3Q1AmODUqAKtRpG7cfL6lEPVNXJWEOp+9FhuYunoWjRLpC06oAsCphK3WytfktbsVTFM5M4AOlAOYHArlEEdmc1KKVMAPO2FVhWc= 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=h+cVZ/BY; arc=none smtp.client-ip=209.85.210.41 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-ot1-f41.google.com with SMTP id 46e09a7af769-6ef88ce8701so1973976a34.2 for ; Fri, 03 May 2024 02:18:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714727937; x=1715332737; 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=iwRLVjXgWWLXjDVCb4fkeW1Vrz1sREosaV/gl6sSJuc=; b=h+cVZ/BYiXnQkt59fdEa86/jY1WHnN6aqmKIUGY6sxTGgn6cpfKcuOlm18rkKG8Q0P Muijzy6bTVBzW/6me4tTnufLMxyOQQBXr+Eovm7si8AdOBcWDyBf31AkH/cR1xsAaizV 0uXj3Skf38vw3ipk7cfTToXzNyjNXZcQyqurM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714727937; x=1715332737; 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=iwRLVjXgWWLXjDVCb4fkeW1Vrz1sREosaV/gl6sSJuc=; b=HERgRH0k2tOM+4yV2kRxEEJt5TGAjVwxrrbITCNJhexf95r2iNaqyRoUZMf0JgRd2E wfV7D4wAFsk1dsuvd9KQVNayJPI6hFlcAi4CJpUuUxE78j25EQ5zP9bPpULDUVnuBFUd QZMeZ477aq8aThxTEJ+WZQAyYwvbn2VWJsOaXA8T1o31Mpf07AkeX1hC+Eba4XiKmJNr Lo5oGnoFSRmViqY/mCqU88uByZZYFprSRJ4db/zmv9mdNBMiPExisw13VivlRVKqxrrE 8/cogm8xJq+sfVWQmEmVvAm/ZK23odl8wMOrYTR5xkonG75cixsbfLFiVd7Xuc7Loqum uewA== X-Gm-Message-State: AOJu0YwL1hE4la1UPJ2skpSd8ovnIAINfS7HqVIyg3AMpSbkvoIpas6Y B9bAxaKcOAxtjOn/JJOfKA9bHIxNx8OlP94dMBqCYl/CoO+pXWU4JaiXGvTbZQ== X-Received: by 2002:a05:6830:1494:b0:6ed:e67b:8699 with SMTP id s20-20020a056830149400b006ede67b8699mr2197582otq.18.1714727936860; Fri, 03 May 2024 02:18:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 02:18:56 -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 09/14] zram: introduce zcomp_config structure Date: Fri, 3 May 2024 18:17:34 +0900 Message-ID: <20240503091823.3616962-10-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 We will store a per-algorithm parameters there (compression level, dictionary, dictionary size, etc.). Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/backend_deflate.c | 9 ++++++--- drivers/block/zram/backend_lz4.c | 2 +- drivers/block/zram/backend_lz4hc.c | 10 ++++++---- drivers/block/zram/backend_lzo.c | 2 +- drivers/block/zram/backend_lzorle.c | 2 +- drivers/block/zram/backend_zstd.c | 8 ++++++-- drivers/block/zram/zcomp.c | 5 +++-- drivers/block/zram/zcomp.h | 14 ++++++++++++-- drivers/block/zram/zram_drv.c | 20 +++++++++++++++++++- drivers/block/zram/zram_drv.h | 1 + 10 files changed, 56 insertions(+), 17 deletions(-) diff --git a/drivers/block/zram/backend_deflate.c b/drivers/block/zram/backend_deflate.c index 949d402ea3dd..83c660adc722 100644 --- a/drivers/block/zram/backend_deflate.c +++ b/drivers/block/zram/backend_deflate.c @@ -32,7 +32,7 @@ static void deflate_destroy(void *ctx) kfree(zctx); } -static void *deflate_create(void) +static void *deflate_create(struct zcomp_config *config) { struct deflate_ctx *ctx; size_t sz; @@ -42,8 +42,11 @@ static void *deflate_create(void) if (!ctx) return NULL; - /* @FIXME: using a hardcoded Z_DEFAULT_COMPRESSION for now */ - ctx->level = Z_DEFAULT_COMPRESSION; + if (config->level != ZCOMP_CONFIG_NO_LEVEL) + ctx->level = config->level; + else + ctx->level = Z_DEFAULT_COMPRESSION; + sz = zlib_deflate_workspacesize(-DEFLATE_DEF_WINBITS, MAX_MEM_LEVEL); ctx->cctx.workspace = vzalloc(sz); if (!ctx->cctx.workspace) diff --git a/drivers/block/zram/backend_lz4.c b/drivers/block/zram/backend_lz4.c index 697592dbabe2..98d9c9274149 100644 --- a/drivers/block/zram/backend_lz4.c +++ b/drivers/block/zram/backend_lz4.c @@ -4,7 +4,7 @@ #include "backend_lz4.h" -static void *lz4_create(void) +static void *lz4_create(struct zcomp_config *config) { return vmalloc(LZ4_MEM_COMPRESS); } diff --git a/drivers/block/zram/backend_lz4hc.c b/drivers/block/zram/backend_lz4hc.c index 5c437623aa65..62721a7c82dc 100644 --- a/drivers/block/zram/backend_lz4hc.c +++ b/drivers/block/zram/backend_lz4hc.c @@ -18,7 +18,7 @@ static void lz4hc_destroy(void *ctx) kfree(zctx); } -static void *lz4hc_create(void) +static void *lz4hc_create(struct zcomp_config *config) { struct lz4hc_ctx *ctx; @@ -26,14 +26,16 @@ static void *lz4hc_create(void) if (!ctx) return NULL; + if (config->level != ZCOMP_CONFIG_NO_LEVEL) + ctx->level = config->level; + else + ctx->level = LZ4HC_DEFAULT_CLEVEL; + ctx->mem = vmalloc(LZ4HC_MEM_COMPRESS); if (!ctx->mem) { lz4hc_destroy(ctx); return NULL; } - - /* @FIXME: using a hardcoded LZ4HC_DEFAULT_CLEVEL for now */ - ctx->level = LZ4HC_DEFAULT_CLEVEL; return ctx; } diff --git a/drivers/block/zram/backend_lzo.c b/drivers/block/zram/backend_lzo.c index d9a003fbb360..c9ca18a2f993 100644 --- a/drivers/block/zram/backend_lzo.c +++ b/drivers/block/zram/backend_lzo.c @@ -6,7 +6,7 @@ #include "backend_lzo.h" -static void *lzo_create(void) +static void *lzo_create(struct zcomp_config *config) { return kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); } diff --git a/drivers/block/zram/backend_lzorle.c b/drivers/block/zram/backend_lzorle.c index 9bf1843021b0..b0937103b5fb 100644 --- a/drivers/block/zram/backend_lzorle.c +++ b/drivers/block/zram/backend_lzorle.c @@ -6,7 +6,7 @@ #include "backend_lzorle.h" -static void *lzorle_create(void) +static void *lzorle_create(struct zcomp_config *config) { return kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); } diff --git a/drivers/block/zram/backend_zstd.c b/drivers/block/zram/backend_zstd.c index 4a7734aa1a8a..b2fb94902bef 100644 --- a/drivers/block/zram/backend_zstd.c +++ b/drivers/block/zram/backend_zstd.c @@ -24,7 +24,7 @@ static void zstd_destroy(void *ctx) kfree(zctx); } -static void *zstd_create(void) +static void *zstd_create(struct zcomp_config *config) { zstd_parameters params; struct zstd_ctx *ctx; @@ -34,7 +34,11 @@ static void *zstd_create(void) if (!ctx) return NULL; - ctx->level = ZSTD_defaultCLevel(); + if (config->level != ZCOMP_CONFIG_NO_LEVEL) + ctx->level = config->level; + else + ctx->level = ZSTD_defaultCLevel(); + params = zstd_get_params(ctx->level, PAGE_SIZE); sz = zstd_cctx_workspace_bound(¶ms.cParams); ctx->cctx_mem = vzalloc(sz); diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index fdf06fc6b364..9e182eb52fe7 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -57,7 +57,7 @@ static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *zstrm) */ static int zcomp_strm_init(struct zcomp *comp, struct zcomp_strm *zstrm) { - zstrm->ctx = comp->backend->create_ctx(); + zstrm->ctx = comp->backend->create_ctx(comp->config); /* * allocate 2 pages. 1 for compressed data, plus 1 extra for the @@ -200,7 +200,7 @@ void zcomp_destroy(struct zcomp *comp) kfree(comp); } -struct zcomp *zcomp_create(const char *alg) +struct zcomp *zcomp_create(const char *alg, struct zcomp_config *config) { struct zcomp *comp; int error; @@ -217,6 +217,7 @@ struct zcomp *zcomp_create(const char *alg) if (!comp) return ERR_PTR(-ENOMEM); + comp->config = config; comp->backend = lookup_backend(alg); if (!comp->backend) { kfree(comp); diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h index 757b85017e23..345c78bc76db 100644 --- a/drivers/block/zram/zcomp.h +++ b/drivers/block/zram/zcomp.h @@ -5,6 +5,7 @@ #ifndef _ZCOMP_H_ #define _ZCOMP_H_ + #include struct zcomp_strm { @@ -15,6 +16,14 @@ struct zcomp_strm { void *ctx; }; +#define ZCOMP_CONFIG_NO_LEVEL INT_MIN + +struct zcomp_config { + s32 level; + size_t dict_sz; + void *dict; +}; + struct zcomp_backend { int (*compress)(void *ctx, const unsigned char *src, unsigned char *dst, size_t *dst_len); @@ -22,7 +31,7 @@ struct zcomp_backend { int (*decompress)(void *ctx, const unsigned char *src, size_t src_len, unsigned char *dst); - void *(*create_ctx)(void); + void *(*create_ctx)(struct zcomp_config *config); void (*destroy_ctx)(void *ctx); const char *name; @@ -32,6 +41,7 @@ struct zcomp_backend { struct zcomp { struct zcomp_strm __percpu *stream; struct zcomp_backend *backend; + struct zcomp_config *config; struct hlist_node node; }; @@ -40,7 +50,7 @@ int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node); ssize_t zcomp_available_show(const char *comp, char *buf); bool zcomp_available_algorithm(const char *comp); -struct zcomp *zcomp_create(const char *alg); +struct zcomp *zcomp_create(const char *alg, struct zcomp_config *config); void zcomp_destroy(struct zcomp *comp); struct zcomp_strm *zcomp_stream_get(struct zcomp *comp); diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 298ef0e97e03..6c36cd349431 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1994,6 +1994,20 @@ static void zram_slot_free_notify(struct block_device *bdev, zram_slot_unlock(zram, index); } +static void zram_reset_comp_configs(struct zram *zram) +{ + u32 prio; + + for (prio = 0; prio < ZRAM_MAX_COMPS; prio++) { + struct zcomp_config *config = &zram->configs[prio]; + + vfree(config->dict); + config->level = ZCOMP_CONFIG_NO_LEVEL; + config->dict_sz = 0; + config->dict = NULL; + } +} + static void zram_destroy_comps(struct zram *zram) { u32 prio; @@ -2007,6 +2021,8 @@ static void zram_destroy_comps(struct zram *zram) zcomp_destroy(comp); zram->num_active_comps--; } + + zram_reset_comp_configs(zram); } static void zram_reset_device(struct zram *zram) @@ -2064,7 +2080,8 @@ static ssize_t disksize_store(struct device *dev, if (!zram->comp_algs[prio]) continue; - comp = zcomp_create(zram->comp_algs[prio]); + comp = zcomp_create(zram->comp_algs[prio], + &zram->configs[prio]); if (IS_ERR(comp)) { pr_err("Cannot initialise %s compressing backend\n", zram->comp_algs[prio]); @@ -2271,6 +2288,7 @@ static int zram_add(void) if (ret) goto out_cleanup_disk; + zram_reset_comp_configs(zram); comp_algorithm_set(zram, ZRAM_PRIMARY_COMP, default_compressor); zram_debugfs_register(zram); diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index 37bf29f34d26..2c77f3bff166 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -107,6 +107,7 @@ struct zram { struct zram_table_entry *table; struct zs_pool *mem_pool; struct zcomp *comps[ZRAM_MAX_COMPS]; + struct zcomp_config configs[ZRAM_MAX_COMPS]; struct gendisk *disk; /* Prevent concurrent execution of device init */ struct rw_semaphore init_lock; -- 2.45.0.rc1.225.g2a3ae87e7f-goog