From patchwork Mon Sep 5 08:23:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965768 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE1D5ECAAA1 for ; Mon, 5 Sep 2022 08:23:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36216801C4; Mon, 5 Sep 2022 04:23:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 311D88D0050; Mon, 5 Sep 2022 04:23:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B281801C4; Mon, 5 Sep 2022 04:23:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0D9BD8D0050 for ; Mon, 5 Sep 2022 04:23:34 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D51881C6774 for ; Mon, 5 Sep 2022 08:23:33 +0000 (UTC) X-FDA: 79877342706.17.3E40857 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf05.hostedemail.com (Postfix) with ESMTP id 5584B100077 for ; Mon, 5 Sep 2022 08:23:33 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id h188so7480684pgc.12 for ; Mon, 05 Sep 2022 01:23:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=I2ruIR+eUek6TMRHPcruq5I+ZauP5l3LGhFsa5khFHo=; b=JiG1Df0pwfk7mK6N/jxlhWm0M0z0mOXOeoRBEvASwb6EK7YtuPkI27Rq2xglIN+VtU +nVGhLvH4eyFMuPrOUrCWi3Q1hC4JZwzuWyzurDbGKxw3A5IjHq87CMBf/gyrW7LU9bS lOjHkP/jU4+YyFYOFylSHrXH7goETnEgciETg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=I2ruIR+eUek6TMRHPcruq5I+ZauP5l3LGhFsa5khFHo=; b=xJrpcJCJrvagMyqaD9hEvJ0BPHOwYcmHAoXR1JuX96MiTHv5GrKMc/ixqkmo5ozMiu Mj1g5tFDD02KuzOaGH/+mRtPkYao0I3JCqiI62UmR2IXjELVpkOQHcLb4jEtj18RsEOy divsPtu5W9ymiRnodNhUApr8h4NlV5xvyy6d31NGOqTY0ockPKTobykDzQo97fc670pA 5v0FN7cSNRiB27seXOC2mXd8ozHpkWZVpmGuW+n+jvjGMiyN64DU4zplOAM/0nJCyVEq aei770CHf0WF1qH4W/PXAnJZDa3tFRzP5B4CFBf/LupJTdz/pk4NEkcJJWxuNeOM3HTi vzgg== X-Gm-Message-State: ACgBeo1B8drWpV4OJlapdNNoUvLEQrdsBTf+IsmI5FRGselJWhrPasb9 04h3KwiID9XP7/NFSMPfroQOfw== X-Google-Smtp-Source: AA6agR5xP0qb+Cdg/AttC8eGwZRrpPmdJkJKWBftIG6lIEfHEHnSH/0nD//J42SoXMOC441QvDUdBA== X-Received: by 2002:a62:ea14:0:b0:535:c678:8106 with SMTP id t20-20020a62ea14000000b00535c6788106mr49550293pfh.9.1662366212331; Mon, 05 Sep 2022 01:23:32 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id p14-20020a170902e74e00b001641b2d61d4sm6807093plf.30.2022.09.05.01.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:23:31 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH RFC 1/7] zram: Preparation for multi-zcomp support Date: Mon, 5 Sep 2022 17:23:17 +0900 Message-Id: <20220905082323.2742399-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905082323.2742399-1-senozhatsky@chromium.org> References: <20220905082323.2742399-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662366213; a=rsa-sha256; cv=none; b=c+riWTng+xKPZ68BVR8F8r6nEnHviaRq242YLMXNmheGd8PmyP0oDnWLqIvzeikW8FFjcG kZ9VU4Bi1ueHsM9Qhp5eeq6jCtc1f4vbePAUxDhtOksh7vOeheojFzzCyQyuNmczC+ohHb S8m+hIC9sFL7au2aGV7/Mc0UW44LNXY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=JiG1Df0p; spf=pass (imf05.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.177 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662366213; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=I2ruIR+eUek6TMRHPcruq5I+ZauP5l3LGhFsa5khFHo=; b=CmS8JAjQpdBWc7+ElgwB2+uKoxPsTkPYd9ITWoobRaI0jtBXo91ZjTc3ngAAVHnultRja4 2N0csvgQ2MPs1Nl+YlgFWUH6sgBoA3hEQbL/Cb490QTzqwPJoZpULF9XTMZiURgOKjrI+G 0d6LDaFZ63uGyOEzm8zH+6MQzFzKMHM= X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=JiG1Df0p; spf=pass (imf05.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.177 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam09 X-Stat-Signature: 59zxibgfboqipp4ktcpgouyem6e98scx X-Rspamd-Queue-Id: 5584B100077 X-HE-Tag: 1662366213-703562 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The patch turns compression streams and compressor algorithm name struct zram members into arrays, so that we can have multiple compression streams support (in the next patches). The patch uses a rather explicit API for compressor selection: - Get primary (default) compression stream zcomp_stream_get(zram->comps[ZRAM_PRIMARY_ZCOMP]) - Get secondary compression stream zcomp_stream_get(zram->comps[ZRAM_SECONDARY_ZCOMP]) We use similar API for compression streams put(). At this point we always have just one compression stream, since CONFIG_ZRAM_MULTI_COMP is not yet defined. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zcomp.c | 6 +-- drivers/block/zram/zcomp.h | 2 +- drivers/block/zram/zram_drv.c | 87 ++++++++++++++++++++++++----------- drivers/block/zram/zram_drv.h | 14 +++++- 4 files changed, 77 insertions(+), 32 deletions(-) diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index 0916de952e09..55af4efd7983 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -206,7 +206,7 @@ void zcomp_destroy(struct zcomp *comp) * case of allocation error, or any other error potentially * returned by zcomp_init(). */ -struct zcomp *zcomp_create(const char *compress) +struct zcomp *zcomp_create(const char *alg) { struct zcomp *comp; int error; @@ -216,14 +216,14 @@ struct zcomp *zcomp_create(const char *compress) * is not loaded yet. We must do it here, otherwise we are about to * call /sbin/modprobe under CPU hot-plug lock. */ - if (!zcomp_available_algorithm(compress)) + if (!zcomp_available_algorithm(alg)) return ERR_PTR(-EINVAL); comp = kzalloc(sizeof(struct zcomp), GFP_KERNEL); if (!comp) return ERR_PTR(-ENOMEM); - comp->name = compress; + comp->name = alg; error = zcomp_init(comp); if (error) { kfree(comp); diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h index 40f6420f4b2e..cdefdef93da8 100644 --- a/drivers/block/zram/zcomp.h +++ b/drivers/block/zram/zcomp.h @@ -27,7 +27,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 *comp); +struct zcomp *zcomp_create(const char *alg); 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 607f4634c27d..4ad1daa1283e 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1018,36 +1018,53 @@ static ssize_t comp_algorithm_show(struct device *dev, struct zram *zram = dev_to_zram(dev); down_read(&zram->init_lock); - sz = zcomp_available_show(zram->compressor, buf); + sz = zcomp_available_show(zram->comp_algs[ZRAM_PRIMARY_ZCOMP], buf); up_read(&zram->init_lock); return sz; } +static void comp_algorithm_set(struct zram *zram, u32 idx, const char *alg) +{ + /* Do not kfree() algs that we didn't allocate, IOW the default ones */ + if (zram->comp_algs[idx] != default_compressor) + kfree(zram->comp_algs[idx]); + zram->comp_algs[idx] = alg; +} + static ssize_t comp_algorithm_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct zram *zram = dev_to_zram(dev); - char compressor[ARRAY_SIZE(zram->compressor)]; + char *compressor; size_t sz; - strlcpy(compressor, buf, sizeof(compressor)); + sz = strlen(buf); + if (sz >= CRYPTO_MAX_ALG_NAME) + return -E2BIG; + + compressor = kstrdup(buf, GFP_KERNEL); + if (!compressor) + return -ENOMEM; + /* ignore trailing newline */ - sz = strlen(compressor); if (sz > 0 && compressor[sz - 1] == '\n') compressor[sz - 1] = 0x00; - if (!zcomp_available_algorithm(compressor)) + if (!zcomp_available_algorithm(compressor)) { + kfree(compressor); return -EINVAL; + } down_write(&zram->init_lock); if (init_done(zram)) { up_write(&zram->init_lock); + kfree(compressor); pr_info("Can't change algorithm for initialized device\n"); return -EBUSY; } - strcpy(zram->compressor, compressor); + comp_algorithm_set(zram, ZRAM_PRIMARY_ZCOMP, compressor); up_write(&zram->init_lock); return len; } @@ -1292,7 +1309,7 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, size = zram_get_obj_size(zram, index); if (size != PAGE_SIZE) - zstrm = zcomp_stream_get(zram->comp); + zstrm = zcomp_stream_get(zram->comps[ZRAM_PRIMARY_ZCOMP]); src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); if (size == PAGE_SIZE) { @@ -1304,7 +1321,7 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, dst = kmap_atomic(page); ret = zcomp_decompress(zstrm, src, size, dst); kunmap_atomic(dst); - zcomp_stream_put(zram->comp); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_ZCOMP]); } zs_unmap_object(zram->mem_pool, handle); zram_slot_unlock(zram, index); @@ -1371,13 +1388,13 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, kunmap_atomic(mem); compress_again: - zstrm = zcomp_stream_get(zram->comp); + zstrm = zcomp_stream_get(zram->comps[ZRAM_PRIMARY_ZCOMP]); src = kmap_atomic(page); ret = zcomp_compress(zstrm, src, &comp_len); kunmap_atomic(src); if (unlikely(ret)) { - zcomp_stream_put(zram->comp); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_ZCOMP]); pr_err("Compression failed! err=%d\n", ret); zs_free(zram->mem_pool, handle); return ret; @@ -1405,7 +1422,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, __GFP_HIGHMEM | __GFP_MOVABLE); if (IS_ERR((void *)handle)) { - zcomp_stream_put(zram->comp); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_ZCOMP]); atomic64_inc(&zram->stats.writestall); handle = zs_malloc(zram->mem_pool, comp_len, GFP_NOIO | __GFP_HIGHMEM | @@ -1422,14 +1439,14 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, * It is necessary that the dereferencing of the zstrm variable below * occurs correctly. */ - zstrm = zcomp_stream_get(zram->comp); + zstrm = zcomp_stream_get(zram->comps[ZRAM_PRIMARY_ZCOMP]); } alloced_pages = zs_get_total_pages(zram->mem_pool); update_used_max(zram, alloced_pages); if (zram->limit_pages && alloced_pages > zram->limit_pages) { - zcomp_stream_put(zram->comp); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_ZCOMP]); zs_free(zram->mem_pool, handle); return -ENOMEM; } @@ -1443,7 +1460,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, if (comp_len == PAGE_SIZE) kunmap_atomic(src); - zcomp_stream_put(zram->comp); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_ZCOMP]); zs_unmap_object(zram->mem_pool, handle); atomic64_add(comp_len, &zram->stats.compr_data_size); out: @@ -1718,6 +1735,20 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector, return ret; } +static void zram_destroy_comps(struct zram *zram) +{ + u32 idx; + + for (idx = 0; idx < ZRAM_MAX_ZCOMPS; idx++) { + struct zcomp *comp = zram->comps[idx]; + + zram->comps[idx] = NULL; + if (IS_ERR_OR_NULL(comp)) + continue; + zcomp_destroy(comp); + } +} + static void zram_reset_device(struct zram *zram) { down_write(&zram->init_lock); @@ -1735,11 +1766,11 @@ static void zram_reset_device(struct zram *zram) /* I/O operation under all of CPU are done so let's free */ zram_meta_free(zram, zram->disksize); zram->disksize = 0; + zram_destroy_comps(zram); memset(&zram->stats, 0, sizeof(zram->stats)); - zcomp_destroy(zram->comp); - zram->comp = NULL; reset_bdev(zram); + comp_algorithm_set(zram, ZRAM_PRIMARY_ZCOMP, default_compressor); up_write(&zram->init_lock); } @@ -1750,6 +1781,7 @@ static ssize_t disksize_store(struct device *dev, struct zcomp *comp; struct zram *zram = dev_to_zram(dev); int err; + u32 idx; disksize = memparse(buf, NULL); if (!disksize) @@ -1768,22 +1800,25 @@ static ssize_t disksize_store(struct device *dev, goto out_unlock; } - comp = zcomp_create(zram->compressor); - if (IS_ERR(comp)) { - pr_err("Cannot initialise %s compressing backend\n", - zram->compressor); - err = PTR_ERR(comp); - goto out_free_meta; - } + for (idx = 0; idx < ZRAM_MAX_ZCOMPS; idx++) { + comp = zcomp_create(zram->comp_algs[idx]); + if (IS_ERR(comp)) { + pr_err("Cannot initialise %s compressing backend\n", + zram->comp_algs[idx]); + err = PTR_ERR(comp); + goto out_free_comps; + } - zram->comp = comp; + zram->comps[idx] = comp; + } zram->disksize = disksize; set_capacity_and_notify(zram->disk, zram->disksize >> SECTOR_SHIFT); up_write(&zram->init_lock); return len; -out_free_meta: +out_free_comps: + zram_destroy_comps(zram); zram_meta_free(zram, disksize); out_unlock: up_write(&zram->init_lock); @@ -1979,7 +2014,7 @@ static int zram_add(void) if (ret) goto out_cleanup_disk; - strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor)); + zram->comp_algs[ZRAM_PRIMARY_ZCOMP] = default_compressor; zram_debugfs_register(zram); pr_info("Added device: %s\n", zram->disk->disk_name); diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index 80c3b43b4828..af3d6f6bfcff 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -90,10 +90,20 @@ struct zram_stats { #endif }; +#ifdef CONFIG_ZRAM_MULTI_COMP +#define ZRAM_PRIMARY_ZCOMP 0 +#define ZRAM_SECONDARY_ZCOMP 1 +#define ZRAM_MAX_ZCOMPS 2 +#else +#define ZRAM_PRIMARY_ZCOMP 0 +#define ZRAM_SECONDARY_ZCOMP 0 +#define ZRAM_MAX_ZCOMPS 1 +#endif + struct zram { struct zram_table_entry *table; struct zs_pool *mem_pool; - struct zcomp *comp; + struct zcomp *comps[ZRAM_MAX_ZCOMPS]; struct gendisk *disk; /* Prevent concurrent execution of device init */ struct rw_semaphore init_lock; @@ -108,7 +118,7 @@ struct zram { * we can store in a disk. */ u64 disksize; /* bytes */ - char compressor[CRYPTO_MAX_ALG_NAME]; + const char *comp_algs[ZRAM_MAX_ZCOMPS]; /* * zram is claimed so open request will be failed */ From patchwork Mon Sep 5 08:23:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39567C6FA89 for ; Mon, 5 Sep 2022 08:23:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8A19801C5; Mon, 5 Sep 2022 04:23:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C39E48D0050; Mon, 5 Sep 2022 04:23:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADA13801C5; Mon, 5 Sep 2022 04:23:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9F8CB8D0050 for ; Mon, 5 Sep 2022 04:23:36 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 645E8121881 for ; Mon, 5 Sep 2022 08:23:36 +0000 (UTC) X-FDA: 79877342832.29.B47D912 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf23.hostedemail.com (Postfix) with ESMTP id 17FFD140077 for ; Mon, 5 Sep 2022 08:23:35 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id x1-20020a17090ab00100b001fda21bbc90so11477572pjq.3 for ; Mon, 05 Sep 2022 01:23:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=osBqiJaYCcdSOMrgUz97U3jA0MdVQ300bRjV6yXUVIc=; b=Dj8l0GVOcH4FsUVnxL4tY09OuUF7plVKGT36GD2zseXqHCVAoWzqC2wyYGRnwKkNVu iBgy2FIh5hALHQRL0BZwivTaMCDPYseK+lZDWWS5Jzyy5wgDArZezc3vpw08Z1BCcI+N 9D4avvixlHeN3+YHVLR5hRRZkQnMwy742gYmU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=osBqiJaYCcdSOMrgUz97U3jA0MdVQ300bRjV6yXUVIc=; b=vwLRuB2j4p8pNYJ7wTQ9BE2/EnAgvtfZ1cMwX5G9Yk1hbZSP8mTjmdXpkSmD0uHjgx WzmLtRDEgPMvWeTrwsaeVxyZYw79M2Jfs70VJw2CamLhKQ1CrGUNDo2UeIZPX6kcGuWO gvKgsnGEVCV595+wIWVJe6bpaawL2ugbqPZCqa87O89ByqMrnuSlkHeAvXa26i/VoMKG 3WSAkQyQGS4N5tzqXkq2N73LL4wT/pELjjPz9eSzEzMRbi6p3evyoQfacLczXEEWhcAg O+xzA31bcCzCQOn+Uw+yUoF1EM/ESOdo2CFGJOr1D6Vu/XQ3mwjsrdvgee2zydQwvR31 DP5w== X-Gm-Message-State: ACgBeo2aQzVdz+wnwPr1rci0xHS7mvjl/qGlonQ2oOEzfrGiCZLG5U0O 3CygVKqGDAUvV/WTuII8a2tsrw== X-Google-Smtp-Source: AA6agR7g8dFTB0VArIVTxGYq1Z4Rv7IOKVS5+1nZdI6tf1siXXlu2O6JpvShJE42fy847+SkNmM3Zw== X-Received: by 2002:a17:90b:4f45:b0:1f5:6554:d555 with SMTP id pj5-20020a17090b4f4500b001f56554d555mr18729225pjb.226.1662366215186; Mon, 05 Sep 2022 01:23:35 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id p14-20020a170902e74e00b001641b2d61d4sm6807093plf.30.2022.09.05.01.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:23:34 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH RFC 2/7] zram: Add recompression algorithm sysfs knob Date: Mon, 5 Sep 2022 17:23:18 +0900 Message-Id: <20220905082323.2742399-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905082323.2742399-1-senozhatsky@chromium.org> References: <20220905082323.2742399-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Dj8l0GVO; spf=pass (imf23.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.49 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662366216; a=rsa-sha256; cv=none; b=nU4ar7SOuO4W7mLKexYrPiqhfWcEIudhzOFbnXTmotK5urN7MQppxKMJWdKq3mK75SSJ8G YQYm9CoPGWzBQHjxpwnq+S8DJfUWAR00Jwgc4iwwz4OMQW59CgyfEf0SRhyqr0EZhQxTPF /V23xCCrFtr9HLtvFQ/2coyCkQmEH7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662366216; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=osBqiJaYCcdSOMrgUz97U3jA0MdVQ300bRjV6yXUVIc=; b=limL1E+YpCP389+GI+umNxJF2h9Uu9SF088iP1ny7qr79YXrw5ZX14hkKvg4LH74khwDfo J4Uj/LM5lznywHeuvMZZdoNbMn4W9Tls9xhl4lkkyZAMv94FK9PYpSfVx95Wv1LbKCm1Eq bCpvBn/BhXslDlAkPAfi9DtEUwEn9HE= X-Rspamd-Server: rspam02 X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Dj8l0GVO; spf=pass (imf23.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.49 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Stat-Signature: qkfmoi56k7y69f6wueo8h9qabpxycij6 X-Rspamd-Queue-Id: 17FFD140077 X-HE-Tag: 1662366215-556701 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Introduce recomp_algorithm sysfs knob that controls secondary algorithm selection used for recompression. This device attribute works in a similar way with comp_algorithm attribute. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 111 +++++++++++++++++++++++++++------- 1 file changed, 90 insertions(+), 21 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 4ad1daa1283e..694c8c426cb2 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -41,7 +41,12 @@ static DEFINE_IDR(zram_index_idr); static DEFINE_MUTEX(zram_index_mutex); static int zram_major; -static const char *default_compressor = CONFIG_ZRAM_DEF_COMP; +static const char *default_comp_algs[ZRAM_MAX_ZCOMPS] = { + CONFIG_ZRAM_DEF_COMP, +#ifdef CONFIG_ZRAM_MULTI_COMP + "zstd", +#endif +}; /* Module params (documentation at end) */ static unsigned int num_devices = 1; @@ -1011,31 +1016,37 @@ static ssize_t max_comp_streams_store(struct device *dev, return len; } -static ssize_t comp_algorithm_show(struct device *dev, - struct device_attribute *attr, char *buf) +static void comp_algorithm_set(struct zram *zram, u32 idx, const char *alg) { - size_t sz; - struct zram *zram = dev_to_zram(dev); + bool default_alg = false; + int i; - down_read(&zram->init_lock); - sz = zcomp_available_show(zram->comp_algs[ZRAM_PRIMARY_ZCOMP], buf); - up_read(&zram->init_lock); + /* Do not kfree() algs that we didn't allocate, IOW the default ones */ + for (i = 0; i < ZRAM_MAX_ZCOMPS; i++) { + if (zram->comp_algs[idx] == default_comp_algs[i]) { + default_alg = true; + break; + } + } - return sz; + if (!default_alg) + kfree(zram->comp_algs[idx]); + zram->comp_algs[idx] = alg; } -static void comp_algorithm_set(struct zram *zram, u32 idx, const char *alg) +static ssize_t __comp_algorithm_show(struct zram *zram, u32 idx, char *buf) { - /* Do not kfree() algs that we didn't allocate, IOW the default ones */ - if (zram->comp_algs[idx] != default_compressor) - kfree(zram->comp_algs[idx]); - zram->comp_algs[idx] = alg; + ssize_t sz; + + down_read(&zram->init_lock); + sz = zcomp_available_show(zram->comp_algs[idx], buf); + up_read(&zram->init_lock); + + return sz; } -static ssize_t comp_algorithm_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) +static int __comp_algorithm_store(struct zram *zram, u32 idx, const char *buf) { - struct zram *zram = dev_to_zram(dev); char *compressor; size_t sz; @@ -1064,11 +1075,55 @@ static ssize_t comp_algorithm_store(struct device *dev, return -EBUSY; } - comp_algorithm_set(zram, ZRAM_PRIMARY_ZCOMP, compressor); + comp_algorithm_set(zram, idx, compressor); up_write(&zram->init_lock); - return len; + return 0; +} + +static ssize_t comp_algorithm_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct zram *zram = dev_to_zram(dev); + + return __comp_algorithm_show(zram, ZRAM_PRIMARY_ZCOMP, buf); +} + +static ssize_t comp_algorithm_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t len) +{ + struct zram *zram = dev_to_zram(dev); + int ret; + + ret = __comp_algorithm_store(zram, ZRAM_PRIMARY_ZCOMP, buf); + return ret ? ret : len; } +#ifdef CONFIG_ZRAM_MULTI_COMP +static ssize_t recomp_algorithm_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct zram *zram = dev_to_zram(dev); + + return __comp_algorithm_show(zram, ZRAM_SECONDARY_ZCOMP, buf); +} + +static ssize_t recomp_algorithm_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t len) +{ + struct zram *zram = dev_to_zram(dev); + int ret; + + ret = __comp_algorithm_store(zram, ZRAM_SECONDARY_ZCOMP, buf); + return ret ? ret : len; +} +#endif + static ssize_t compact_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { @@ -1770,7 +1825,11 @@ static void zram_reset_device(struct zram *zram) memset(&zram->stats, 0, sizeof(zram->stats)); reset_bdev(zram); - comp_algorithm_set(zram, ZRAM_PRIMARY_ZCOMP, default_compressor); + comp_algorithm_set(zram, ZRAM_PRIMARY_ZCOMP, + default_comp_algs[ZRAM_PRIMARY_ZCOMP]); + if (IS_ENABLED(CONFIG_ZRAM_MULTI_COMP)) + comp_algorithm_set(zram, ZRAM_SECONDARY_ZCOMP, + default_comp_algs[ZRAM_SECONDARY_ZCOMP]); up_write(&zram->init_lock); } @@ -1912,6 +1971,9 @@ static DEVICE_ATTR_WO(writeback); static DEVICE_ATTR_RW(writeback_limit); static DEVICE_ATTR_RW(writeback_limit_enable); #endif +#ifdef CONFIG_ZRAM_MULTI_COMP +static DEVICE_ATTR_RW(recomp_algorithm); +#endif static struct attribute *zram_disk_attrs[] = { &dev_attr_disksize.attr, @@ -1935,6 +1997,9 @@ static struct attribute *zram_disk_attrs[] = { &dev_attr_bd_stat.attr, #endif &dev_attr_debug_stat.attr, +#ifdef CONFIG_ZRAM_MULTI_COMP + &dev_attr_recomp_algorithm.attr, +#endif NULL, }; @@ -2014,7 +2079,11 @@ static int zram_add(void) if (ret) goto out_cleanup_disk; - zram->comp_algs[ZRAM_PRIMARY_ZCOMP] = default_compressor; + zram->comp_algs[ZRAM_PRIMARY_ZCOMP] = + default_comp_algs[ZRAM_PRIMARY_ZCOMP]; + if (IS_ENABLED(CONFIG_ZRAM_MULTI_COMP)) + zram->comp_algs[ZRAM_SECONDARY_ZCOMP] = + default_comp_algs[ZRAM_SECONDARY_ZCOMP]; zram_debugfs_register(zram); pr_info("Added device: %s\n", zram->disk->disk_name); From patchwork Mon Sep 5 08:23:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965770 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 717CBECAAA1 for ; Mon, 5 Sep 2022 08:23:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F0C5801C6; Mon, 5 Sep 2022 04:23:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A1268D0050; Mon, 5 Sep 2022 04:23:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5EC8801C6; Mon, 5 Sep 2022 04:23:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D6FC88D0050 for ; Mon, 5 Sep 2022 04:23:39 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A82CE160D11 for ; Mon, 5 Sep 2022 08:23:39 +0000 (UTC) X-FDA: 79877342958.08.1174097 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf10.hostedemail.com (Postfix) with ESMTP id 49EADC005D for ; Mon, 5 Sep 2022 08:23:39 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id fs14so2951963pjb.5 for ; Mon, 05 Sep 2022 01:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=MkTg5zDd6KOHOk4vuhlZ6bZv6q468yLoqf3LP8Ucpys=; b=aBW0CzvUuC+9cpiQKHMHT4SxOa0dqdX9qcC0OeaH2oTG9UqvrH0ukdB3JZ7lmnZaK1 VdAc05X22+fwuejVr/A6GdinKG1g1K1SBS7ez9ArjHcla+rPv8ipxo8Yi9oPbQwCQgJv UU9+00W+8lN1ehv0b8sc1WMusT8LsTHOLvdtI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=MkTg5zDd6KOHOk4vuhlZ6bZv6q468yLoqf3LP8Ucpys=; b=1oA5EeCfGafREu8x7BO/ad9Qju03JxS5xiwzVQOI4EPXeGvV0sJC/XDjsWirNyEDyP 904eA2kmg7ity6NNB2mru6VNRhGulvivD86UmsAKXlQFCQFQz4rd+Y8t+btlftv7QhWU Xtlt1/LQgk6xCUH//V3X1Q+lK8TElikFON2dLdpOnlSDPmReBZmgIu1hVI9mZwJTgs8r TQVrIYho2zw6GKPTax0C1BZgulDgUD0+trJrAXYbUGuPxw6SDD4YvrEbZ3HG4PSQdTaX VziPEJt2r2OnHVvlQRqvTVQFtW7rI0y4n1KgMuhqdg90S9Lm/IoPpwrLeVaz4WlP96of KcgA== X-Gm-Message-State: ACgBeo2/mkNgJNLMU+sSmlSQkRAhsPL5rhQBUL3lNCkbDyhW0NXXz0gu 1j0xpUBRB0+A2LeECmghg7p/Lg== X-Google-Smtp-Source: AA6agR4lNcvveVFlXXdtwEAmkiYZqSZRN9hbkPQmEKvUm6TBQRaHKnlN12fNUgikdMzmOnrz5ExqYg== X-Received: by 2002:a17:902:ab55:b0:176:8906:a3c5 with SMTP id ij21-20020a170902ab5500b001768906a3c5mr9869367plb.72.1662366217811; Mon, 05 Sep 2022 01:23:37 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id p14-20020a170902e74e00b001641b2d61d4sm6807093plf.30.2022.09.05.01.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:23:37 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH RFC 3/7] zram: Factor out WB and non-WB zram read functions Date: Mon, 5 Sep 2022 17:23:19 +0900 Message-Id: <20220905082323.2742399-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905082323.2742399-1-senozhatsky@chromium.org> References: <20220905082323.2742399-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662366219; a=rsa-sha256; cv=none; b=QQbXzp9YmPQd/zOKHdsVNUMUiVdBx9OVgkfbhHLFYHfl5y+m8qMiM2/8HHMvbxewdatZd6 oMY7B+lxuhlfL1Y7Aj7hTt8BYDW0SfFLIhlg7e7SrpcX3wGJlEBFNZ974mNm5q4VqBeoMk 7lIcAEJ6GDvVDSitMIAOeSKBA+RJV54= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=aBW0CzvU; spf=pass (imf10.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.50 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662366219; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MkTg5zDd6KOHOk4vuhlZ6bZv6q468yLoqf3LP8Ucpys=; b=AWAfVzoRlbOR9RrfMQoXe3B73LnW6OMFHuOqQO/44mxQ0UxS/cFirqn25mqH+MNVfSc9Fe syqZ+NOtS5KbaGtf/nBb/CojsXKZA7p9XKYo7wzbDEIZMwoVQSXA3pzEHdRqq3iCflNAAJ VwoerIDuXT9pnpI1q0yKumbEy1wvZ+U= Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=aBW0CzvU; spf=pass (imf10.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.50 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: uwuk8qpm9tyiamik4rbzjpbgx8yay4xt X-Rspamd-Queue-Id: 49EADC005D X-HE-Tag: 1662366219-926036 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We will use non-WB variant in ZRAM page recompression path. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 66 +++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 694c8c426cb2..de2970865b7b 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1325,8 +1325,33 @@ static void zram_free_page(struct zram *zram, size_t index) ~(1UL << ZRAM_LOCK | 1UL << ZRAM_UNDER_WB)); } -static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, - struct bio *bio, bool partial_io) +/* + * Reads a page from the writeback devices. Corresponding ZRAM slot + * should be unlocked. + */ +static int zram_read_from_writeback(struct zram *zram, + struct page *page, + u32 index, + struct bio *bio, + bool partial_io) +{ + struct bio_vec bvec; + + bvec.bv_page = page; + bvec.bv_len = PAGE_SIZE; + bvec.bv_offset = 0; + return read_from_bdev(zram, &bvec, + zram_get_element(zram, index), + bio, partial_io); +} + +/* + * Reads (decompresses if needed) a page from zspool (zsmalloc). + * Corresponding ZRAM slot should be locked. + */ +static int zram_read_from_zspool(struct zram *zram, + struct page *page, + u32 index) { struct zcomp_strm *zstrm; unsigned long handle; @@ -1334,20 +1359,6 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, void *src, *dst; int ret; - zram_slot_lock(zram, index); - if (zram_test_flag(zram, index, ZRAM_WB)) { - struct bio_vec bvec; - - zram_slot_unlock(zram, index); - - bvec.bv_page = page; - bvec.bv_len = PAGE_SIZE; - bvec.bv_offset = 0; - return read_from_bdev(zram, &bvec, - zram_get_element(zram, index), - bio, partial_io); - } - handle = zram_get_handle(zram, index); if (!handle || zram_test_flag(zram, index, ZRAM_SAME)) { unsigned long value; @@ -1357,7 +1368,6 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, mem = kmap_atomic(page); zram_fill_page(mem, PAGE_SIZE, value); kunmap_atomic(mem); - zram_slot_unlock(zram, index); return 0; } @@ -1379,7 +1389,25 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, zcomp_stream_put(zram->comps[ZRAM_PRIMARY_ZCOMP]); } zs_unmap_object(zram->mem_pool, handle); - zram_slot_unlock(zram, index); + return ret; +} + +static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, + struct bio *bio, bool partial_io) +{ + int ret; + + zram_slot_lock(zram, index); + if (!zram_test_flag(zram, index, ZRAM_WB)) { + /* Slot should be locked through out the function call */ + ret = zram_read_from_zspool(zram, page, index); + zram_slot_unlock(zram, index); + } else { + /* Slot should be unlocked before the function call */ + zram_slot_unlock(zram, index); + ret = zram_read_from_writeback(zram, page, index, bio, + partial_io); + } /* Should NEVER happen. Return bio error if it does. */ if (WARN_ON(ret)) @@ -1389,7 +1417,7 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, } static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, - u32 index, int offset, struct bio *bio) + u32 index, int offset, struct bio *bio) { int ret; struct page *page; From patchwork Mon Sep 5 08:23:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B910BECAAD5 for ; Mon, 5 Sep 2022 08:23:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5378F801C7; Mon, 5 Sep 2022 04:23:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C2EA8D0050; Mon, 5 Sep 2022 04:23:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3605D801C7; Mon, 5 Sep 2022 04:23:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 246C38D0050 for ; Mon, 5 Sep 2022 04:23:42 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id EBF77AB001 for ; Mon, 5 Sep 2022 08:23:41 +0000 (UTC) X-FDA: 79877343042.23.A14E1B9 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf02.hostedemail.com (Postfix) with ESMTP id 999B180072 for ; Mon, 5 Sep 2022 08:23:41 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id s206so7523162pgs.3 for ; Mon, 05 Sep 2022 01:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=apGSrKTgwETbH2CMEGMydpnHgs87JcMdkEf7eiEN8iQ=; b=VRDy1szZ9nnuVMFP2jEsr44BTUpa7HJpnUeDpWZYq4+kd5uGGaAsO0gGm3+j61YLP5 sf5jIAhuKTmgCnCDUdFfPsMP4tFGusfPPuzHyUwaKElCJNtSasBKAuFq4k5PrSQRfgLQ ii9eg8V8vwqGeczBZcWzrUDfERA+n2T6GEUbA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=apGSrKTgwETbH2CMEGMydpnHgs87JcMdkEf7eiEN8iQ=; b=LZ94HCAU64t4hVZzqCS1IsKNmZNkkL0lbImh3e7vPYybq9DHW3Y4Hoo+5FY2zNkyT4 2EKvUiyO6NIGN+bU9Guts4rw7acSVaNs5uTcl6y6g10slDqMgo5GlwO1+LMyTKPvlFcy +gRKARLG/gMdN/jMG6liUJyUypjpUdFppI4HivCHu0gcM5DcoN1ulw5vXQPHinvxAdt8 xkUY1QoNX5XpVEu9kAmbGt+7h/gO1YXaOIcqRs9VEd8SCF8LRMPjeFQh0psKvh/HNDd8 fA9F/kw8NvoMAxCW4MXjv3WEk0fH4zti+L8egEAOyntvSftS28AmDiSTzBzgGAOTPXDl omkw== X-Gm-Message-State: ACgBeo3pW4WPLqWOOwu2VBnqIdfcZvclY/hMWT9/skVf/duH2KLh7zUo rLEpWRSz0mk/3gcaviA+OGgvU896CdoJGA== X-Google-Smtp-Source: AA6agR5+1trg1E9uYHkTVeFZhTHW7WWvLhizMSoy0I3OoqZ93WSRvvMs+OfOOqN9ywMTHwWypooTrA== X-Received: by 2002:a63:f74c:0:b0:42b:77c2:ce7c with SMTP id f12-20020a63f74c000000b0042b77c2ce7cmr40708150pgk.473.1662366220625; Mon, 05 Sep 2022 01:23:40 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id p14-20020a170902e74e00b001641b2d61d4sm6807093plf.30.2022.09.05.01.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:23:40 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH RFC 4/7] zram: Introduce recompress sysfs knob Date: Mon, 5 Sep 2022 17:23:20 +0900 Message-Id: <20220905082323.2742399-5-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905082323.2742399-1-senozhatsky@chromium.org> References: <20220905082323.2742399-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662366221; a=rsa-sha256; cv=none; b=efywRDhYCxup3AagkyDL3DPOOadrl7P3DELAjF2PvE0JLvj100ifA6R+INt3epVdniLWfL KUYlKOtJMdMJHX+WlYn5L/jhBRW1hOyBBFdRZFgVreFnu5brPss5hCCo0l7nnfcyMX2UTD /WIBhDvnX7rniHbyGL3T4ajA9sdgX+s= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=VRDy1szZ; spf=pass (imf02.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.173 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662366221; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=apGSrKTgwETbH2CMEGMydpnHgs87JcMdkEf7eiEN8iQ=; b=66KNZqtC28XYuRU4ptAS9deIzxNyDBnN6/vCTNBzqVDs7BpM1z4I4HdwVUQvgsvdZqZRf+ REJqGCyHrGf3mMNsPHcuEZvMHzyCAIRn8h6a9tbNhaDQh7w8bXYlhMnFS+2VUVK8U8fRgd oPQc6uPvDKnZwpdo5FEBZQlBj13mSfQ= X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=VRDy1szZ; spf=pass (imf02.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.173 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam09 X-Stat-Signature: xa6c6c6i7emk1kk84jofuty37jj68e8w X-Rspamd-Queue-Id: 999B180072 X-HE-Tag: 1662366221-132466 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Allow zram to recompress (using secondary compression streams) pages. We support three modes: 1) IDLE pages recompression is activated by `idle` mode echo idle > /sys/block/zram0/recompress 2) Since there may be many idle pages user-space may pass a size watermark value and we will recompress IDLE pages only of equal or greater size: echo 888 > /sys/block/zram0/recompress 3) HUGE pages recompression is activated by `huge` mode echo huge > /sys/block/zram0/recompress 4) HUGE_IDLE pages recompression is activated by `huge_idle` mode echo huge_idle > /sys/block/zram0/recompress Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/Kconfig | 11 ++ drivers/block/zram/zram_drv.c | 191 +++++++++++++++++++++++++++++++++- drivers/block/zram/zram_drv.h | 1 + 3 files changed, 200 insertions(+), 3 deletions(-) diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index d4100b0c083e..81ae4b96ec1a 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -78,3 +78,14 @@ config ZRAM_MEMORY_TRACKING /sys/kernel/debug/zram/zramX/block_state. See Documentation/admin-guide/blockdev/zram.rst for more information. + +config ZRAM_MULTI_COMP + bool "Enable multiple per-CPU compression streams" + depends on ZRAM + help + This will enable per-CPU multi-compression streams, so that ZRAM + can re-compress IDLE pages, using a potentially slower but more + effective compression algorithm. + + echo TIMEOUT > /sys/block/zramX/idle + echo SIZE > /sys/block/zramX/recompress diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index de2970865b7b..386e49a13806 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1293,6 +1293,9 @@ static void zram_free_page(struct zram *zram, size_t index) atomic64_dec(&zram->stats.huge_pages); } + if (zram_test_flag(zram, index, ZRAM_RECOMP)) + zram_clear_flag(zram, index, ZRAM_RECOMP); + if (zram_test_flag(zram, index, ZRAM_WB)) { zram_clear_flag(zram, index, ZRAM_WB); free_block_bdev(zram, zram_get_element(zram, index)); @@ -1357,6 +1360,7 @@ static int zram_read_from_zspool(struct zram *zram, unsigned long handle; unsigned int size; void *src, *dst; + u32 idx; int ret; handle = zram_get_handle(zram, index); @@ -1373,8 +1377,13 @@ static int zram_read_from_zspool(struct zram *zram, size = zram_get_obj_size(zram, index); - if (size != PAGE_SIZE) - zstrm = zcomp_stream_get(zram->comps[ZRAM_PRIMARY_ZCOMP]); + if (size != PAGE_SIZE) { + idx = ZRAM_PRIMARY_ZCOMP; + if (zram_test_flag(zram, index, ZRAM_RECOMP)) + idx = ZRAM_SECONDARY_ZCOMP; + + zstrm = zcomp_stream_get(zram->comps[idx]); + } src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); if (size == PAGE_SIZE) { @@ -1386,7 +1395,7 @@ static int zram_read_from_zspool(struct zram *zram, dst = kmap_atomic(page); ret = zcomp_decompress(zstrm, src, size, dst); kunmap_atomic(dst); - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_ZCOMP]); + zcomp_stream_put(zram->comps[idx]); } zs_unmap_object(zram->mem_pool, handle); return ret; @@ -1612,6 +1621,180 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, return ret; } +#ifdef CONFIG_ZRAM_MULTI_COMP +/* + * This function will decompress (unless it's ZRAM_HUGE) the page and then + * attempt to compress it using secondary compression algorithm (which is + * potentially more effective). + * + * Corresponding ZRAM slot should be locked. + */ +static int zram_recompress(struct zram *zram, + u32 index, + struct page *page, + int size_watermark) +{ + unsigned long handle_prev; + unsigned long handle_next; + unsigned int comp_len_next; + unsigned int comp_len_prev; + struct zcomp_strm *zstrm; + void *src, *dst; + int ret; + + handle_prev = zram_get_handle(zram, index); + if (!handle_prev) + return -EINVAL; + + comp_len_prev = zram_get_obj_size(zram, index); + /* + * Do not recompress objects that are already "small enough". + */ + if (comp_len_prev < size_watermark) + return 0; + + ret = zram_read_from_zspool(zram, page, index); + if (ret) + return ret; + + zstrm = zcomp_stream_get(zram->comps[ZRAM_SECONDARY_ZCOMP]); + src = kmap_atomic(page); + ret = zcomp_compress(zstrm, src, &comp_len_next); + kunmap_atomic(src); + + /* + * Either a compression error or we failed to compressed the object + * in a way that will save us memory. Mark object as "recompressed" + * if it's huge, so that we don't try to recompress it again. Ideally + * we want to set some bit for all such objects, but we for now do so + * only for huge ones (we are out of bits in flags on 32-bit systems). + */ + if (comp_len_next >= huge_class_size || + comp_len_next >= comp_len_prev || + ret) { + if (zram_test_flag(zram, index, ZRAM_HUGE)) + zram_set_flag(zram, index, ZRAM_RECOMP); + zram_clear_flag(zram, index, ZRAM_IDLE); + zcomp_stream_put(zram->comps[ZRAM_SECONDARY_ZCOMP]); + return ret; + } + + /* + * No direct reclaim (slow path) for handle allocation and no + * re-compression attempt (unlike in __zram_bvec_write()) since + * we already stored that object in zsmalloc. If we cannot alloc + * memory then me bail out. + */ + handle_next = zs_malloc(zram->mem_pool, comp_len_next, + __GFP_KSWAPD_RECLAIM | + __GFP_NOWARN | + __GFP_HIGHMEM | + __GFP_MOVABLE); + if (IS_ERR((void *)handle_next)) { + zcomp_stream_put(zram->comps[ZRAM_SECONDARY_ZCOMP]); + return -ENOMEM; + } + + dst = zs_map_object(zram->mem_pool, handle_next, ZS_MM_WO); + memcpy(dst, zstrm->buffer, comp_len_next); + zcomp_stream_put(zram->comps[ZRAM_SECONDARY_ZCOMP]); + + zs_unmap_object(zram->mem_pool, handle_next); + + zram_free_page(zram, index); + zram_set_handle(zram, index, handle_next); + zram_set_obj_size(zram, index, comp_len_next); + + zram_set_flag(zram, index, ZRAM_RECOMP); + atomic64_add(comp_len_next, &zram->stats.compr_data_size); + atomic64_inc(&zram->stats.pages_stored); + + return 0; +} + +#define RECOMPRESS_IDLE (1 << 0) +#define RECOMPRESS_HUGE (1 << 1) + +static ssize_t recompress_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t len) +{ + struct zram *zram = dev_to_zram(dev); + unsigned long nr_pages = zram->disksize >> PAGE_SHIFT; + unsigned long index; + struct page *page; + ssize_t ret = 0; + int mode, size_watermark = 0; + + if (sysfs_streq(buf, "idle")) { + mode = RECOMPRESS_IDLE; + } else if (sysfs_streq(buf, "huge")) { + mode = RECOMPRESS_HUGE; + } else if (sysfs_streq(buf, "huge_idle")) { + mode = RECOMPRESS_IDLE | RECOMPRESS_HUGE; + } else { + /* + * We will re-compress only idle objects equal or greater + * in size than watermark. + */ + ret = kstrtoint(buf, 10, &size_watermark); + if (ret) + return ret; + mode = RECOMPRESS_IDLE; + } + + if (size_watermark > PAGE_SIZE) + return ret; + + down_read(&zram->init_lock); + if (!init_done(zram)) { + ret = -EINVAL; + goto release_init_lock; + } + + page = alloc_page(GFP_KERNEL); + if (!page) { + ret = -ENOMEM; + goto release_init_lock; + } + + for (index = 0; index < nr_pages; index++) { + zram_slot_lock(zram, index); + + if (!zram_allocated(zram, index)) + goto next; + + if (mode & RECOMPRESS_IDLE && + !zram_test_flag(zram, index, ZRAM_IDLE)) + goto next; + + if (mode & RECOMPRESS_HUGE && + !zram_test_flag(zram, index, ZRAM_HUGE)) + goto next; + + if (zram_test_flag(zram, index, ZRAM_WB) || + zram_test_flag(zram, index, ZRAM_UNDER_WB) || + zram_test_flag(zram, index, ZRAM_SAME) || + zram_test_flag(zram, index, ZRAM_RECOMP)) + goto next; + + ret = zram_recompress(zram, index, page, size_watermark); +next: + zram_slot_unlock(zram, index); + if (ret) + break; + } + + ret = len; + __free_page(page); + +release_init_lock: + up_read(&zram->init_lock); + return ret; +} +#endif + /* * zram_bio_discard - handler on discard request * @index: physical block index in PAGE_SIZE units @@ -2001,6 +2184,7 @@ static DEVICE_ATTR_RW(writeback_limit_enable); #endif #ifdef CONFIG_ZRAM_MULTI_COMP static DEVICE_ATTR_RW(recomp_algorithm); +static DEVICE_ATTR_WO(recompress); #endif static struct attribute *zram_disk_attrs[] = { @@ -2027,6 +2211,7 @@ static struct attribute *zram_disk_attrs[] = { &dev_attr_debug_stat.attr, #ifdef CONFIG_ZRAM_MULTI_COMP &dev_attr_recomp_algorithm.attr, + &dev_attr_recompress.attr, #endif NULL, }; diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index af3d6f6bfcff..b4eecef2a11f 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -50,6 +50,7 @@ enum zram_pageflags { ZRAM_UNDER_WB, /* page is under writeback */ ZRAM_HUGE, /* Incompressible page */ ZRAM_IDLE, /* not accessed page since last idle marking */ + ZRAM_RECOMP, /* page was recompressed */ __NR_ZRAM_PAGEFLAGS, }; From patchwork Mon Sep 5 08:23:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965772 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78DB6ECAAD5 for ; Mon, 5 Sep 2022 08:23:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2026B801C8; Mon, 5 Sep 2022 04:23:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B31F8D0050; Mon, 5 Sep 2022 04:23:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07A2E801C8; Mon, 5 Sep 2022 04:23:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EDB288D0050 for ; Mon, 5 Sep 2022 04:23:46 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C729AC02D9 for ; Mon, 5 Sep 2022 08:23:46 +0000 (UTC) X-FDA: 79877343252.17.DA92AC0 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf15.hostedemail.com (Postfix) with ESMTP id 8577DA0063 for ; Mon, 5 Sep 2022 08:23:46 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id f24so7873591plr.1 for ; Mon, 05 Sep 2022 01:23:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=ARMalt43cGQStsEP0fAYz16MOL60Ugpll7VhrHzWrN4=; b=AbhuZG4cLnD4jAtfo2ZO07aIOwcJJvwIZESzjpZ5Ee+82ZNdfngwPfiuw6v9PXi/eR /BxJ0orFnk5MpMZv+Y+LnbYJFKUzam+yFwSFhDCiAYDY6+eOU2UMsM9y+K0yq02gvGO5 3LeNv89oR7dUBGGFpFwPExYtdVrQijvYiu+Lo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=ARMalt43cGQStsEP0fAYz16MOL60Ugpll7VhrHzWrN4=; b=PVkNs1f7nGUp3uuOd2YntqDyZMy85Kyy4qT7f5LEhdZXv28nI9YMZ7Zwa4KRWijW0x n8qZ5Qx6lLz6NfN2V5fF4G9w1CXKElTB+m9vTkEhLpgjYLxsgHnpF5zt6iEHwUBbyHSA J5k/eyUrNiV3HzEUv0b2KoBw+cYZK1KeOfIinEHuHh8BbUuHOiCfEsS7mEiN5G2WRZ8y SIJxqxt3sv4CTx4hqMaeXlb+X8j7H45XiGDlLNDVB3kN4ClEcx2svld6SFqvhNE951c6 SlEuia8Jkak13PLP8xXbIW8F6qjm8/lRW1bgzb5+6x7qo343QKIcub/7b0i+kDCbwUU2 Br8Q== X-Gm-Message-State: ACgBeo1tcb0dBKUZF/3/uPPl2K3EMG3H0yuCOMHAaz87pnOp0m91J6fB TZQrxtne2pRsvCW80RRvN9N51Q== X-Google-Smtp-Source: AA6agR6MdV0jQOWw7gPUNPTuBQ7N8UC1YJh59UXImF2+oeIhZoDkkXTWCLMASpJ6FNqJ5k4s2QvS5A== X-Received: by 2002:a17:90b:1652:b0:1fd:eca8:d2be with SMTP id il18-20020a17090b165200b001fdeca8d2bemr18456213pjb.79.1662366225603; Mon, 05 Sep 2022 01:23:45 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id p14-20020a170902e74e00b001641b2d61d4sm6807093plf.30.2022.09.05.01.23.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:23:44 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH RFC 5/7] documentation: Add recompression documentation Date: Mon, 5 Sep 2022 17:23:21 +0900 Message-Id: <20220905082323.2742399-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905082323.2742399-1-senozhatsky@chromium.org> References: <20220905082323.2742399-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=AbhuZG4c; spf=pass (imf15.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.181 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662366226; a=rsa-sha256; cv=none; b=HH/Ba9FZF8NKTIYqSZQfFxByPgqfoRhwjh8q7W/BLSBJ3mffpCRzcF0VxQaw8EPSXuO+zG vps7pRNEBtVKIlyI95rfJUI1UbD1vTpTdXV2PJKRaQGvC9pey9MOOooFoYdOcMbZI+DM/M CKwfMSSVfLDtel7DEz0UdUoyrt/oT3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662366226; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ARMalt43cGQStsEP0fAYz16MOL60Ugpll7VhrHzWrN4=; b=SrXZhwozV6qfEZRiewa77xbKHTySG5GjL3Ak6ZNpD7LuihTyotJqg6PdY1vn+YEZPV4Seg VSeXu1RaC+BHqs5qg4//eshjIsnKgAyruMczOvZY2rTPaQl0nQAY37fs4wsxlSTNXn5zZ6 PyXi0MhRzjaKebzSIzgO9Bft5ikc0f4= X-Stat-Signature: ts46ajpcz1juopnxqua6nz83t1hebano X-Rspamd-Queue-Id: 8577DA0063 X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=AbhuZG4c; spf=pass (imf15.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.181 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam07 X-HE-Tag: 1662366226-624281 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Document user-space visible device attributes that are enabled by ZRAM_MULTI_COMP. Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/blockdev/zram.rst | 55 +++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index c73b16930449..88957fcb6ad7 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -401,6 +401,61 @@ budget in next setting is user's job. If admin wants to measure writeback count in a certain period, they could know it via /sys/block/zram0/bd_stat's 3rd column. +recompression +------------- + +With CONFIG_ZRAM_MULTI_COMP, zram can recompress idle/huge pages using +alternative (secondary) compression algorithm. The basic idea is that +alternative compression algorithm can provide better compression ratio +at a price of (potentially) slower compression/decompression speeds. +Alternative compression algorithm can, for example, be more successful +compressing huge pages (those that default algorithm failed to compress). +Another application is idle pages recompression - pages that are cold and +sit in the memory can be recompressed using more effective algorithm and, +hence, reduce zsmalloc memory usage. + +With CONFIG_ZRAM_MULTI_COMP, zram will setup two compression algorithms +per-CPU: primary and secondary ones. Primary zram compressor is explained +in "3) Select compression algorithm", the secondary algorithm is configured +in a similar way, using recomp_algorithm device attribute: + +Examples:: + + #show supported recompression algorithms + cat /sys/block/zramX/recomp_algorithm + zstd [lzo] + + #select zstd recompression algorithm + echo zstd > /sys/block/zramX/recomp_algorithm + +Another device attribute that CONFIG_ZRAM_MULTI_COMP enables is recompress, +which controls recompression: + +Examples:: + + #IDLE pages recompression is activated by `idle` mode + echo idle > /sys/block/zramX/recompress + + #HUGE pages recompression is activated by `huge` mode + echo huge > /sys/block/zram0/recompress + + #HUGE_IDLE pages recompression is activated by `huge_idle` mode + echo huge_idle > /sys/block/zramX/recompress + +The number of idle pages can be significant, so user-space can pass a size +watermark value to the recompress knob, to filter out idle pages for +recompression: zram will recompress only idle pages of equal or greater +size::: + + #recompress idle pages larger than 3000 bytes + echo 3000 > /sys/block/zramX/recompress + + #recompress idle pages larger than 2000 bytes + echo 2000 > /sys/block/zramX/recompress + +Recompression is mostly focused on idle pages (except for huge pages +recompression), so it works better in conjunction with memory tracking. + memory tracking =============== From patchwork Mon Sep 5 08:23:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3ECDDECAAA1 for ; Mon, 5 Sep 2022 08:23:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D9B07801C9; Mon, 5 Sep 2022 04:23:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D4ADC8D0050; Mon, 5 Sep 2022 04:23:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1371801C9; Mon, 5 Sep 2022 04:23:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B0D5E8D0050 for ; Mon, 5 Sep 2022 04:23:49 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 82F73805B0 for ; Mon, 5 Sep 2022 08:23:49 +0000 (UTC) X-FDA: 79877343378.23.4F70A6E Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf05.hostedemail.com (Postfix) with ESMTP id 297B4100072 for ; Mon, 5 Sep 2022 08:23:49 +0000 (UTC) Received: by mail-pf1-f178.google.com with SMTP id y136so3016917pfb.3 for ; Mon, 05 Sep 2022 01:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=/AdpGVT0N/8ncggFEAw2LdRk7MFt3IthPSmEwk0XZqA=; b=LiL4ic6qnwShH+vKAAfDpVgTQC0FxSPXFggKOMKQNFzrWxx/1FeDNFEhP9z1ZoIO2f Wd8EYKuaIk6ket1LJsvuXUY4AKFZe10HIuW6YGeD4RCNyM+xZjuqWjyZvTo7lmuz4JqP sL+P+IsNne+r1gmoWf77QeKPbpDCA0nP5YR4c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=/AdpGVT0N/8ncggFEAw2LdRk7MFt3IthPSmEwk0XZqA=; b=mLyGnSoUmOqwqYo4ru9f2ZF6rnvOq0IUMAN209iFbR6ogtF07D/bX4KhqLbmv/+eIN 8s1+lTqRpdrG00EyejUniuY+Oo6cJ0PdpPFC9kk9PQlRyS2B6qYQe/+sFY5FDdSX6NGK mLDTi6qDspddl4SRvRGTpCZDsmTv5eEvTzU6WfnEJTjoX83fl8ulvhW18SHz6jUjAkA7 ZkZj9VWtXcNNLhqstCkZ365/588mxNwM7HRiDwePeb7DtqgdcWjOBEWYhAW8JLKqlQ5W ixiaY73E+hMLD1qz/lD1XZZzmXh3/OL7cXLEfso928oWh4x1ra+5u39YYaQpBUUOotwm /dGw== X-Gm-Message-State: ACgBeo35Jf8dI7TT8GEws1+7vidomm5OsUHoA7ENrKes4QCH7otElwul al3VGKllF4ahbMJs2xB12+ZC1Q== X-Google-Smtp-Source: AA6agR4UZ885aB4mUVeDufZQeCtDSZclJbHMwybgeqEVVnMUNj3OcY1loqHdvf0STXrAMJAluHjgsA== X-Received: by 2002:a65:6c07:0:b0:41d:9ddd:4266 with SMTP id y7-20020a656c07000000b0041d9ddd4266mr40872332pgu.326.1662366228315; Mon, 05 Sep 2022 01:23:48 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id p14-20020a170902e74e00b001641b2d61d4sm6807093plf.30.2022.09.05.01.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:23:47 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH RFC 6/7] zram: Add recompression algorithm choice to Kconfig Date: Mon, 5 Sep 2022 17:23:22 +0900 Message-Id: <20220905082323.2742399-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905082323.2742399-1-senozhatsky@chromium.org> References: <20220905082323.2742399-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=LiL4ic6q; spf=pass (imf05.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.178 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662366229; a=rsa-sha256; cv=none; b=jgBTmnQWyzRgC83C5rQ/8S42N9Um3Mg8RJpUCkQriXGmU+iAL/KMYflKvoZbhDRYCOJkMw qJbYNAbXIYkVzoeT83Hw1/0kWEwfYQ9jqtvL7YgzjuqIciUh/+orKq0tx2MOctQJ3cbsZF eJIwCQ3bIT2KBIsl2xVOo5c6l5n7rLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662366229; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/AdpGVT0N/8ncggFEAw2LdRk7MFt3IthPSmEwk0XZqA=; b=4INgNqRAwtRTO1rTkTWy4LVoRqdiuVcjtJdmwFcRdHftosJgp6qjCVgABSFxM1sU4RCoD5 JZIysXQl9eAHH//QrFEvu+1Pf6FVQw9iE6+mVQNDyHV8PehQeVkjNR3ByTAa0SfxOuPDYR eqLVr1ncuY3ojrDFkl8S0zcC/zupFYM= X-Stat-Signature: g1oy9wozyc8uz513awtzg9fa5z5g6ifk X-Rspamd-Queue-Id: 297B4100072 X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=LiL4ic6q; spf=pass (imf05.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.178 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam07 X-HE-Tag: 1662366229-955807 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Make (secondary) recompression algorithm selectable just like we do it for the (primary) default one. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/Kconfig | 40 +++++++++++++++++++++++++++++++++++ drivers/block/zram/zram_drv.c | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index 81ae4b96ec1a..fc2d4d66c484 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -89,3 +89,43 @@ config ZRAM_MULTI_COMP echo TIMEOUT > /sys/block/zramX/idle echo SIZE > /sys/block/zramX/recompress + +choice + prompt "Default zram recompression algorithm" + default ZRAM_DEF_RECOMP_ZSTD + depends on ZRAM && ZRAM_MULTI_COMP + +config ZRAM_DEF_RECOMP_LZORLE + bool "lzo-rle" + depends on CRYPTO_LZO + +config ZRAM_DEF_RECOMP_ZSTD + bool "zstd" + depends on CRYPTO_ZSTD + +config ZRAM_DEF_RECOMP_LZ4 + bool "lz4" + depends on CRYPTO_LZ4 + +config ZRAM_DEF_RECOMP_LZO + bool "lzo" + depends on CRYPTO_LZO + +config ZRAM_DEF_RECOMP_LZ4HC + bool "lz4hc" + depends on CRYPTO_LZ4HC + +config ZRAM_DEF_RECOMP_842 + bool "842" + depends on CRYPTO_842 + +endchoice + +config ZRAM_DEF_RECOMP + string + default "lzo-rle" if ZRAM_DEF_RECOMP_LZORLE + default "zstd" if ZRAM_DEF_RECOMP_ZSTD + default "lz4" if ZRAM_DEF_RECOMP_LZ4 + default "lzo" if ZRAM_DEF_RECOMP_LZO + default "lz4hc" if ZRAM_DEF_RECOMP_LZ4HC + default "842" if ZRAM_DEF_RECOMP_842 diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 386e49a13806..8ed41514b8f0 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -44,7 +44,7 @@ static int zram_major; static const char *default_comp_algs[ZRAM_MAX_ZCOMPS] = { CONFIG_ZRAM_DEF_COMP, #ifdef CONFIG_ZRAM_MULTI_COMP - "zstd", + CONFIG_ZRAM_DEF_RECOMP, #endif }; From patchwork Mon Sep 5 08:23:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965774 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED391ECAAD5 for ; Mon, 5 Sep 2022 08:23:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 892A2801CA; Mon, 5 Sep 2022 04:23:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 841AE8D0050; Mon, 5 Sep 2022 04:23:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 709A0801CA; Mon, 5 Sep 2022 04:23:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5CFB68D0050 for ; Mon, 5 Sep 2022 04:23:52 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 339AEAC410 for ; Mon, 5 Sep 2022 08:23:52 +0000 (UTC) X-FDA: 79877343504.15.27986F2 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf11.hostedemail.com (Postfix) with ESMTP id DF82740061 for ; Mon, 5 Sep 2022 08:23:51 +0000 (UTC) Received: by mail-pf1-f178.google.com with SMTP id y127so7979871pfy.5 for ; Mon, 05 Sep 2022 01:23:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=E05eGk8Ts+47tHWXcyTeAoJzHa+CPKznHpzjFQelL1A=; b=acK8pXsPob7Y5s+Bg0YkKeVygfkxhsWVef1JJLtRM5ezbfg1jCdDeReYhs5vLFpc3+ 7C2+UY0wr24vSRkT3J9v1mb++EIgdgPbFzDQep88QpoFUDw9Mx7FNM1NK9g3unavDjvT ZwrREvj/gc8m4PHJNEjGYalq9yyae/RaZt7Mg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=E05eGk8Ts+47tHWXcyTeAoJzHa+CPKznHpzjFQelL1A=; b=l7sSvWRA1d81+OfT9kozAj0VWXPIAYIk2rRAAfGt+eFE/93qa4Wc44eiY2B0creZfo vspxkBPFzTfsTx2jriActp0hrmpaGqqFUvuNvTsDPbv8zjK6mp9aABff8UhTARO2oPZ7 ot+b87iJS7dudPMzowJlMR7bTxfeSSSiIb/v9l6mAT3jc+2PNskFZUT7CMK7WpRwpThB gCA5haQs6r2N3aN50CePHyEdh7PDfkign6BrJKhBnq0P4lxBThAuRNOad6QcJWPz8TXe /Vq7QMa9WJV24KpsiWEuwLaRr55W/D1GW1wK6qahIpIbvw7FzuLroiYIoCedFHQM7IRz 3iWg== X-Gm-Message-State: ACgBeo2IAqI3BP/N/MqDeugi6h+HfKYnX6BGagoOMDR6xuWRDA69M5Iw Qxq5i6BD9ZaXBpMYBzp/XEfdTg== X-Google-Smtp-Source: AA6agR7apkwdHRSEq/AOrRxCZYMadHNajCXFhmfCQuwClOVZjsqItLs1Hn/U6/65l19Q0gXR//E8EA== X-Received: by 2002:a63:d1f:0:b0:422:7774:1969 with SMTP id c31-20020a630d1f000000b0042277741969mr40307627pgl.88.1662366231066; Mon, 05 Sep 2022 01:23:51 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id p14-20020a170902e74e00b001641b2d61d4sm6807093plf.30.2022.09.05.01.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:23:50 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH RFC 7/7] zram: Add recompress flag to read_block_state() Date: Mon, 5 Sep 2022 17:23:23 +0900 Message-Id: <20220905082323.2742399-8-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905082323.2742399-1-senozhatsky@chromium.org> References: <20220905082323.2742399-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662366231; a=rsa-sha256; cv=none; b=iogesG8WeZ8qKZ7p6QcK1cQ2sg8afXsbDilYUqsOtrs3EllWl0Mf4MfZ7MDA0R03U58sAE jl/MjWcx1oCxFLBuoWty1FYobRcnLZg4RZaOo9ZZ9G+U9Wma7gUR1OssTQ3NPHN3VgwchA LVstdjCMqZJ0ZpXkTEZu0etWxDbU1IU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=acK8pXsP; spf=pass (imf11.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.178 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662366231; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=E05eGk8Ts+47tHWXcyTeAoJzHa+CPKznHpzjFQelL1A=; b=lPXglFqucUajrrDMqwzSRQlfjzITrh3apHcslEYILNSFLdOA1UollvI23DxWrCtxY+BOr+ X91B7i9eT7bBjLSdfGq9bCOw/tMwimbyIFh+v3hNRRbNPPhF0I93En+oZEHEVlahBLmx56 y61uim8JrpRxIF90ur1+PsTGDFUj8t4= Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=acK8pXsP; spf=pass (imf11.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.178 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam01 X-Rspam-User: X-Stat-Signature: porayzbuup8ef48iuocpkmbet4n15nbn X-Rspamd-Queue-Id: DF82740061 X-HE-Tag: 1662366231-63064 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add a new flag to zram block state that shows if the page was recompressed (using alternative compression algorithm). Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/blockdev/zram.rst | 9 ++++++--- drivers/block/zram/zram_drv.c | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index 88957fcb6ad7..70a3d0243b45 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -466,9 +466,10 @@ pages of the process with*pagemap. If you enable the feature, you could see block state via /sys/kernel/debug/zram/zram0/block_state". The output is as follows:: - 300 75.033841 .wh. - 301 63.806904 s... - 302 63.806919 ..hi + 300 75.033841 .wh.. + 301 63.806904 s.... + 302 63.806919 ..hi. + 303 62.801919 ....r First column zram's block index. @@ -485,6 +486,8 @@ Third column huge page i: idle page + r: + recompressed page (secondary compression algorithm) First line of above example says 300th block is accessed at 75.033841sec and the block's state is huge so it is written back to the backing diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 8ed41514b8f0..f3948abce2f7 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -936,13 +936,14 @@ static ssize_t read_block_state(struct file *file, char __user *buf, ts = ktime_to_timespec64(zram->table[index].ac_time); copied = snprintf(kbuf + written, count, - "%12zd %12lld.%06lu %c%c%c%c\n", + "%12zd %12lld.%06lu %c%c%c%c%c\n", index, (s64)ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC, zram_test_flag(zram, index, ZRAM_SAME) ? 's' : '.', zram_test_flag(zram, index, ZRAM_WB) ? 'w' : '.', zram_test_flag(zram, index, ZRAM_HUGE) ? 'h' : '.', - zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.'); + zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.', + zram_test_flag(zram, index, ZRAM_RECOMP) ? 'r' : '.'); if (count <= copied) { zram_slot_unlock(zram, index);