Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1238946lqh; Mon, 6 May 2024 01:02:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX6rjah1frBoaQUl+5takiDx5gfvIzn0RFq+5cXggigXA4ikG6JdYXgOOT1s0W6GMYgeCscdXk85NW8U/ILZ6Nv2XP/DuVYc5787CltlA== X-Google-Smtp-Source: AGHT+IGPIAUD8gs898c4McU+WPGQT91qhfwTsu7SC5dcvOrZCQjMOn7ty/pw0f+9EQnk4L/CJTYg X-Received: by 2002:a05:6a00:4b02:b0:6ea:b9a1:63d7 with SMTP id kq2-20020a056a004b0200b006eab9a163d7mr10575761pfb.10.1714982541044; Mon, 06 May 2024 01:02:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714982541; cv=pass; d=google.com; s=arc-20160816; b=VBCE5G14FOokYyl2pVsbx+HfHTSn3MPAlctYEDOoEcG+mP/OkIv0aYa+bsY6OtuVr0 ojXjp/MbzyKzPiGDdO/oSdYaefQGvutGqBXTfNGSOOtoZfyR9NriIaHpFjWL9PN3NhUS Bna4RyLYP70xMnUc3lYSIkNzkCSikZ6brxXpmr8CXbMW9UE1SQ1E5zNCivrhoFDJL2gc QRmYmh01cO4Ki9v2kNHCu5Y9rI3X8NUqsC8WAV7bAJD6JO35ms3+pllCMOsL2vRz3U54 so+g3d65WhDRAG/FY7rD6kjhwNpwAPAUgDNTNRj5MG9+kOjwcRz7urZY+SdmAzSaKA6j idJg== 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=Dn9SFzgpnV2Lro4fo84WFg11lsaNH03/vmgy8zCarpE2yYAysLo9DhQawiHb0iMFSK NsKJWN1HiebRGx0lGvpt9t/010SVPJuPJZJs4iupKQ75HZeKupu9OSeIyhuHzPfyOmel s+ASgQ25f5RjVAxaSf9BxCeLtCdNalXInJ2HjDp9XI5L1pm3gPB465Z5pZkZ0XSWaJ74 wEffZ+rYyWJNXTeMNbuivK1L2Uk69wYV+gjedFmYqrn170uOX3FPGOqtKCZ/pG2xsHME pFOjHbRd+OVV9hMv4KI2lvJsZ3JgVf/fZ81N2epjtZ/M7W/+jr5d+wPavXzO1zl6kBc5 S/nA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jOQqfVzV; 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-169456-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169456-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id r9-20020a63e509000000b0061cd65b4351si5358780pgh.868.2024.05.06.01.02.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 01:02:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169456-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jOQqfVzV; 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-169456-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169456-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4E162282071 for ; Mon, 6 May 2024 08:02:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB23A143884; Mon, 6 May 2024 07:59:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jOQqfVzV" Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 9F582143C62 for ; Mon, 6 May 2024 07:59:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714982359; cv=none; b=Cpx1Ya7llQYZqbKvrl8QHgRcM8jyvJYgCsFh358ARSbSozcmFYStrrOAs7HSbporNfime6pGHQkYpzomeKqRp+j7i1XvDKqXlzSGSd/ciINMoWX6IfqVKwRdn+gSoe3xIsz5ahY7BGsa8wWyrCbuRwMxqOnFmH8SiNcKr6YGduM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714982359; c=relaxed/simple; bh=hqBaAu2Ha8Gh/abMg4Cg6golRoIbO9BVZYRoWaldmIQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cA0FGHUxNVc7tDITlqdetlCckq6YCBL05YYk55oBws4mMyJvO+kC4zw0nyZVu6ie8bB86Mow3lxkNdp+H1hJNGaS4/u5DQzmSNXedOEnPCJOxqvyvduTTFoVaEgw2YCIx+pMmR2bxsdqiTGvtjRnThJxg4KKDFGfJE5xq018nS0= 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=jOQqfVzV; arc=none smtp.client-ip=209.85.214.180 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-pl1-f180.google.com with SMTP id d9443c01a7336-1e651a9f3ffso5218745ad.1 for ; Mon, 06 May 2024 00:59:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714982357; x=1715587157; 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=jOQqfVzVUh4iDEKhdp6pilQEjUoYGOGRLd3S5VuYwi9eK48/btkDhINpASI84yYWkN oZ6q3DJXvgpH0KZ3QmJcJJ4Fd1CPlYngX4puFcm/vDFHKemW+YjbJhXhRvP6hGZ6JzMe xUEaZVn06W9jq2sXc/Q1OoSptFTW5pvvt90Ts= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714982357; x=1715587157; 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=V8yBrr0YeAearVz3XTSyoKCisLIhIVUK2Kz2jiKG8fCkl9tUsSptG8GEHk9DFmZNKM Oi2+XBnpMKW87jcWBgVmsu93QkgglXt78Mu/XVBJsaG6IGJqzfg44YEskJf4GH9T+2SM GkHJdM5ay0q2yPv5eMgOg08+lq4uI+b7AlxlyDSUGzs2Kx2gQfDRMiMjx+IuCH85hQta Ic5CqtMTCmCAvOaHghtOQx9MyjH+gYTmylvQr1E7nv2FBXn+F70fNDVZsLuJxDpFg8JZ zI4x2kikGgp0IIdR3kF+bpuEZTtnz/0gS54pS7EvUF+MqzykHIHSNdzI2GSOsaU9Fdfd oAzw== X-Gm-Message-State: AOJu0YwdspJZ2dUUyy18wnBUfxFTQij9EtdwjFK/MKm8T52csSAF/xJy QmiLJh9j5dF2bAKzkcGID8Oev/UGiXD1OayuzeAmmKgsGSXtU9+5l4T0YjyGbQ== X-Received: by 2002:a17:902:c10c:b0:1e1:a54:1fe8 with SMTP id 12-20020a170902c10c00b001e10a541fe8mr9487138pli.53.1714982357067; Mon, 06 May 2024 00:59:17 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:4e24:10c3:4b65:e126]) by smtp.gmail.com with ESMTPSA id h6-20020a170902f54600b001ec64b128dasm7633772plf.129.2024.05.06.00.59.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 00:59:16 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 13/17] zram: add support for dict comp config Date: Mon, 6 May 2024 16:58:26 +0900 Message-ID: <20240506075834.302472-14-senozhatsky@chromium.org> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog In-Reply-To: <20240506075834.302472-1-senozhatsky@chromium.org> References: <20240506075834.302472-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