Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp334916lqo; Wed, 8 May 2024 00:46:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWnaCsPPPsjao3L/KyJDtOUA4nnHKfTxA08H2RpwZc8j6xznXF6mrjJZ2wpOrme3rf2R4IZVAEA5WhAEzFGoTkSijVcHP8D/tvLTythiQ== X-Google-Smtp-Source: AGHT+IFLavSqCof9aXb43qcIP70PPe5M/vKAHKzbiW5Kr1x/I9l2GyAB+00UwSqybY9TuYnhVtfT X-Received: by 2002:a05:6214:5093:b0:6a0:5446:dbc1 with SMTP id 6a1803df08f44-6a15143c60emr22266776d6.2.1715154373543; Wed, 08 May 2024 00:46:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715154373; cv=pass; d=google.com; s=arc-20160816; b=obK7+3l2keCBH65Ay0S1qzCar8v87b7cXfufsEuuuu/STfn7pSFf0bw6axhDTR6Fte f+edrnZbjz4b4OCOIq9XgbKCDrYV2BmHGfMgFXqqAGJRzpL9Q0fJ2qI5fxS3RHbRoP07 O0fx9jJDGpemNjQlQZtl7TA+BcQJkLwbaGLZxTxwSmqGi/zoxrw1Wo9H+XHjlGC+irFZ s0Csz3oyYpP/DxupgD2DfIIK4iD9hSMHu0rC5tswlH0p++F23sP8ebW5xwc+nYLlwdPT zi1UHxT4CoBFqQHADki7kbHCttQyGdn4rK7CoxTr2J1WPWOtxjdpsNFyK2XkJKRJG8LR W5Lg== 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=une8u6O58vSEqdMRQHIC0PiltZGgPobzLxkJ5Uf2uCM=; fh=UKstJvjqAQ3P/Vkvglih02Z8FmmRnlaJbql9clnU9dw=; b=j0vTu+r1xKK0daJj8iHhDtF2UxmvmFfUQzXYj8fspFEVB5T6foduJ21OPziJTAIdWQ FyBUjx+hXWil1nIgCD1AhopPOm4cv7+6Y2BQDzY6Cym2ZM8pEapwFYgFhGhhizgrmB9H 9lEm4l7aCYz7X61ghaV05N9n7Sj8iHckgPnvDwh6bK5RoieOQd1rlirunGgXmmFTZTse r/Vz5cUu4i2mLVOZJtI1+DRsYVwy6/5QwDAWAtA3hWwsYBSQRrB5mt259galpMCzgmWJ k7sJLy3mky2v+aXstahr9x1cRjfD/ni1/rvbCXSGCBEIFotFzYnKMCPghET1JPL+8al9 GMGQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PKiywfTP; 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-172843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172843-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 fo13-20020ad45f0d000000b006a0af70629asi13892156qvb.584.2024.05.08.00.46.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:46:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172843-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=PKiywfTP; 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-172843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172843-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 329D91C22425 for ; Wed, 8 May 2024 07:46:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4FE5E7441A; Wed, 8 May 2024 07:43:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="PKiywfTP" Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 0931671745 for ; Wed, 8 May 2024 07:43:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715154189; cv=none; b=CLznXy26+Dw0GFmelUbbitPRnZ3vi35ENJw3++XNeeT+9lVKq1MuJDgsCdpwm7fJovUmYhtTe/8FIuMV2Mtk+doEDb00p/Bx92TT8I7wIV5F4me1q0pmjzyb8HjoUSQXwvuoyJi4rtG1OIFvy4MHHMvyCmdqmult2HkVtap0V/Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715154189; c=relaxed/simple; bh=hqBaAu2Ha8Gh/abMg4Cg6golRoIbO9BVZYRoWaldmIQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EboNn0FWNHW8CUmLZhTJqD5bgObm2HR+BEgDUFvyqa/YpdlsaNp6+bD8L99Vf6Nt2wDd0D+b0eYv6QXw/t4KCfYYmdWw72TJVQpbs5HGE+K2D6UZlB1jXBMI5xgPMCC66I3QX9z3CISncSyWbA+LljLUZjdGT4wgrez/lt4vDXY= 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=PKiywfTP; arc=none smtp.client-ip=209.85.216.50 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-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2b27eec1eb1so2915544a91.0 for ; Wed, 08 May 2024 00:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1715154187; x=1715758987; 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=une8u6O58vSEqdMRQHIC0PiltZGgPobzLxkJ5Uf2uCM=; b=PKiywfTP7x35TLvZ5Wl70U3In2E6HROkPCFyFEd5xKwwGj7f/8sfEVVyrk/x2H9yyi d4Fu3xK7VxfPl3Ffj33ueCtkPgxnF0LVPquV9/C8jDa5MW1wUnzkTSRWq4YHvBYToBX/ Aa6i1W3uweqQdcvs4SiSWHbcPqtwDxU3Ag6oc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154187; x=1715758987; 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=une8u6O58vSEqdMRQHIC0PiltZGgPobzLxkJ5Uf2uCM=; b=vczfhzW6g7PXsS4Zhb0nRNR05YM3f/2RMvQ6yFLT9HwY7Hjw7Y5GpFDEV/fRlvxOim 1hSspdh/Jk6IGP+gtACFl4C3+VKyhW2GgTG1As5fmJ7nDg3WL2hnSE4/AD1cixbiyoLz laqqFn4JKI2pnp+MDOVyFkm684K4fpmEccB7ZbaXbPkqf3hMdVtbWof1/DAS9HTRC3Pb XunmmIUa2OqQEnzCo9kylhH9JXEYhggNTNpAkLL6wM880+h6fpTAJHDYq/ba8bIpuXbn btNdneBEJU39RzDQwsOzMxuRg2kO6vCj85/3UJV0UZjQyhCCfXHZkK2wfKURUoFII06r rLJA== X-Gm-Message-State: AOJu0YzWZD1BQ1XBLsSamG9mBz6w+KIqPXVPNm9uslFPats8CA5xulNW Haa8lx6+RHTj//SAT1aOY1/HNsBkx9W6dTDoWuQgOHBINbkoUMpQtUMahB6YhQ== X-Received: by 2002:a17:90a:aa81:b0:2b6:3792:ea4d with SMTP id 98e67ed59e1d1-2b637932ademr433346a91.5.1715154187479; Wed, 08 May 2024 00:43:07 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:ad4d:5f6c:6699:2da4]) by smtp.gmail.com with ESMTPSA id l5-20020a17090aec0500b002b328adaa40sm780011pjy.17.2024.05.08.00.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:43:07 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv3 13/19] zram: add support for dict comp config Date: Wed, 8 May 2024 16:42:06 +0900 Message-ID: <20240508074223.652784-14-senozhatsky@chromium.org> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog In-Reply-To: <20240508074223.652784-1-senozhatsky@chromium.org> References: <20240508074223.652784-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 Handle dict=path param so that we can read a pre-trained compression algorithm dictionary which we then pass to the backend configuration. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 54 ++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 89a2eb37e26c..863e4e125eaa 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "zram_drv.h" @@ -1013,9 +1014,35 @@ static int __comp_algorithm_store(struct zram *zram, u32 prio, const char *buf) return 0; } -static int comp_config_store(struct zram *zram, u32 prio, s32 level) +static void __reset_comp_config(struct zram *zram, u32 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 int comp_config_store(struct zram *zram, u32 prio, s32 level, + const char *dict_path) +{ + ssize_t sz = 0; + + __reset_comp_config(zram, prio); + + if (dict_path) { + sz = kernel_read_file_from_path(dict_path, 0, + &zram->configs[prio].dict, + INT_MAX, + NULL, + READING_POLICY); + if (sz < 0) + return -EINVAL; + } + zram->configs[prio].level = level; + zram->configs[prio].dict_sz = sz; return 0; } @@ -1035,7 +1062,7 @@ static ssize_t comp_algorithm_store(struct device *dev, { struct zram *zram = dev_to_zram(dev); char *args, *param, *val; - char *alg = NULL; + char *alg = NULL, *dict_path = NULL; s32 level = ZCOMP_CONFIG_NO_LEVEL; int ret; @@ -1063,12 +1090,17 @@ static ssize_t comp_algorithm_store(struct device *dev, return ret; continue; } + + if (!strcmp(param, "dict")) { + dict_path = val; + continue; + } } if (!alg) return -EINVAL; - ret = comp_config_store(zram, ZRAM_PRIMARY_COMP, level); + ret = comp_config_store(zram, ZRAM_PRIMARY_COMP, level, dict_path); if (!ret) ret = __comp_algorithm_store(zram, ZRAM_PRIMARY_COMP, alg); return ret ? ret : len; @@ -1102,7 +1134,7 @@ static ssize_t recomp_algorithm_store(struct device *dev, struct zram *zram = dev_to_zram(dev); int prio = ZRAM_SECONDARY_COMP; char *args, *param, *val; - char *alg = NULL; + char *alg = NULL, *dict_path = NULL; s32 level = ZCOMP_CONFIG_NO_LEVEL; int ret; @@ -1131,6 +1163,11 @@ static ssize_t recomp_algorithm_store(struct device *dev, return ret; continue; } + + if (!strcmp(param, "dict")) { + dict_path = val; + continue; + } } if (!alg) @@ -1139,7 +1176,7 @@ static ssize_t recomp_algorithm_store(struct device *dev, if (prio < ZRAM_SECONDARY_COMP || prio >= ZRAM_MAX_COMPS) return -EINVAL; - ret = comp_config_store(zram, prio, level); + ret = comp_config_store(zram, prio, level, dict_path); if (!ret) ret = __comp_algorithm_store(zram, prio, alg); return ret ? ret : len; @@ -2049,12 +2086,7 @@ 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; + __reset_comp_config(zram, prio); } } -- 2.45.0.rc1.225.g2a3ae87e7f-goog