From patchwork Wed Oct 5 02:40:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12998834 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 98901C433F5 for ; Wed, 5 Oct 2022 02:40:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6E146B0073; Tue, 4 Oct 2022 22:40:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF5E46B0074; Tue, 4 Oct 2022 22:40:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B96858E0001; Tue, 4 Oct 2022 22:40:26 -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 A86BA6B0073 for ; Tue, 4 Oct 2022 22:40:26 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8359B1C66B1 for ; Wed, 5 Oct 2022 02:40:26 +0000 (UTC) X-FDA: 79985342052.25.614A41B Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf16.hostedemail.com (Postfix) with ESMTP id 1490C180014 for ; Wed, 5 Oct 2022 02:40:25 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id 78so14194772pgb.13 for ; Tue, 04 Oct 2022 19:40:25 -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=RN0/9ftrQEX77iPPbChQJHYVjybhF/OgEdl9wxmnkf4=; b=nQlfnrsaj0ac1FJKgPoHcP1gtXNfui8pyXYvooL/6jB5mikJ/wUfpeEjTZY7CcRr35 Fi2LEDpz/3Z0Pu026JAgJlVtjef1nCofyor/7Rb3gAjcenmdVTfXe3vvAxAf4dpeGlyg inaHhUIY5EG3pU5Hs04f+Ui8ibSv6LWk3YH3Q= 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=RN0/9ftrQEX77iPPbChQJHYVjybhF/OgEdl9wxmnkf4=; b=kCT5sQcHJNtgISKl8eGtzDai5gIucjE5zAB31MRHIy3dsTTucfbVvv91IxksZJjjf5 2oyMp3DU4Vv1fIRV3YhK433h5NRfiQ3bcEsk0vq9tPNWPlunIwpGmYnyTkC2MbEU1pS0 0c6toykFnGZHS1czZb0tqQIgAkPv5YbMMLb5agoDN3icJI6hjpc56pdUQmaBAjkBjBD0 9MCIMhu53axm32kTngUlu6TGEK123LzqIJWcC3oKC1QGzMxtKxQ8X1JPpsHpGU1bvaGw fYrn+MFVFHVhT/d87Q18LE8Z8l7aRHk3MBs4Gkj6jH7ArpPWOc7fPu+lPouhfEHEQex9 2IWw== X-Gm-Message-State: ACrzQf1X67HxLBrPfdbRgMsc8IK8lEVh+wGvgbZpGUqs7qOTJeOwcd3B yoJsjjAQQ3N1riBMzmBGUiPn1Q== X-Google-Smtp-Source: AMsMyM6a01BazGwgDzIKWc7xLCFsB4UevKtw/MTbCyGaQz/G72GLvZa3xsSvhW4Ar/31g2sfusl3sQ== X-Received: by 2002:a63:c1f:0:b0:41a:9b73:a89e with SMTP id b31-20020a630c1f000000b0041a9b73a89emr25503591pgl.342.1664937624880; Tue, 04 Oct 2022 19:40:24 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:a9d9:6396:ee12:8be8]) by smtp.gmail.com with ESMTPSA id a14-20020aa794ae000000b00561e010a309sm1673579pfl.19.2022.10.04.19.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 19:40:24 -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: [PATCHv2 1/8] zram: Preparation for multi-zcomp support Date: Wed, 5 Oct 2022 11:40:07 +0900 Message-Id: <20221005024014.22914-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221005024014.22914-1-senozhatsky@chromium.org> References: <20221005024014.22914-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664937626; a=rsa-sha256; cv=none; b=T7JUGapxbAV3a8CWufwfAATnr946C6Z1vJKX6GymmOOqxE0TeEq2m0n5eyl1vo7lMMuutm xnGXklm1z00itJMeA4gbinyjxOm5vL1686HxgwJaBEH9Qc9733bY4llQM7ncMMHffsxnoR ptkMmZbKMumA4dV5EixpKpyyWNiEQZA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=nQlfnrsa; spf=pass (imf16.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=1664937626; 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=RN0/9ftrQEX77iPPbChQJHYVjybhF/OgEdl9wxmnkf4=; b=o8HUHF+/Y7gFJaindryl+xEx9CcP7kqyh/yfj/VbUrfLF9Hck4xVuhiA9QSU9Dnq2lVJEP KN1uYw0kWeai+leYti62HpnnJGgCawC/V4FBNtWHcaoGIXcRA8r4XXVIaCzn55wZMaTavr s5eAoRo/00Jwd+ealX7JRJqiAlrGZ3Q= X-Rspamd-Server: rspam08 X-Rspam-User: X-Rspamd-Queue-Id: 1490C180014 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=nQlfnrsa; spf=pass (imf16.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-Stat-Signature: 8zqbdgrrk471t3fs7exj3zb33dhdkzu1 X-HE-Tag: 1664937625-572903 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 966aab902d19..770ea3489eb6 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1007,36 +1007,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; - strscpy(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; } @@ -1284,7 +1301,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) { @@ -1296,7 +1313,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); @@ -1363,13 +1380,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; @@ -1397,7 +1414,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 | @@ -1414,14 +1431,14 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, * zstrm buffer back. 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; } @@ -1435,7 +1452,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: @@ -1710,6 +1727,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); @@ -1727,11 +1758,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); } @@ -1742,6 +1773,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) @@ -1760,22 +1792,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); @@ -1962,7 +1997,7 @@ static int zram_add(void) if (ret) goto out_cleanup_disk; - strscpy(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 a2bda53020fd..4044ddbb2326 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -89,10 +89,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; @@ -107,7 +117,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 Wed Oct 5 02:40:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12998835 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 73C2FC433FE for ; Wed, 5 Oct 2022 02:40:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1136D6B0074; Tue, 4 Oct 2022 22:40:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09B966B0075; Tue, 4 Oct 2022 22:40:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA4286B0078; Tue, 4 Oct 2022 22:40:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D2AD76B0074 for ; Tue, 4 Oct 2022 22:40:28 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AB34A160269 for ; Wed, 5 Oct 2022 02:40:28 +0000 (UTC) X-FDA: 79985342136.22.46F23EF Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf19.hostedemail.com (Postfix) with ESMTP id 5EC331A000F for ; Wed, 5 Oct 2022 02:40:28 +0000 (UTC) Received: by mail-pj1-f51.google.com with SMTP id l1-20020a17090a72c100b0020a6949a66aso549611pjk.1 for ; Tue, 04 Oct 2022 19:40:28 -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=sxrqiw0cbhfXN4+OelLD9+srPRQcNc3GlNvIAj2f+tU=; b=HV8IJUnQDoiwZTXZ5eiz2LVPGf1EA5f1CvhynjntdMMrF16zWLnt2EojDvaSZmYba1 1cUzqjUQBpU9oPypv9Qj8Cu4FEPnUJ4Evt6I/swuCTrl2PApkGb1fu7EIEzw9GZoeMOM Nd5SnUMxfYJ4FbF6UbtiuaXsZ9gdJF5jA6mOc= 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=sxrqiw0cbhfXN4+OelLD9+srPRQcNc3GlNvIAj2f+tU=; b=UglrkvKXtWTE4WrM2xIN1/OsP/Ithvj09YlHhEEbYZpAEiasEemx0ypYyHCEhctH5n Iy6rDGXbKjDH0d0dZOePplVDQ/MMgMmwG8+jr7YYM/wm51H0mG0bjJZ155dxi3sc9J3k SFsrAYf3zqzN8EHCaoWaBIVzD5VDw/fg0DTy/0D828VKrBv9KbH96xtqmL6yVVAoUtEO 0ce4vFyAapmT4bIWnX4uumUjptyqP+rhx3LGabDZU9gUP6UtslwlBqs1qiR2ZK/xmyOL t62u+57BJ+c2Ml6UeKbkmY+bI/zHUxVCqroLeDVqWd+VXkCWaVhE45KqY0mY8qT4w7a3 FpWg== X-Gm-Message-State: ACrzQf1uGksvIlefwlC8iTBdfZcri64Y+Eeu97yWwmSAn1G1iRCZhW5U tj7spgkU1HXoEPGlrbSSISc6lA== X-Google-Smtp-Source: AMsMyM7OmmHVdIlXwVm3DBE3ptsb2m+ACItDCWP2lHwGtLGKCqidrtKsG/ABXgk+z7k3cMW7+WMcVQ== X-Received: by 2002:a17:903:230b:b0:17e:ca9:6b9 with SMTP id d11-20020a170903230b00b0017e0ca906b9mr17549320plh.146.1664937627411; Tue, 04 Oct 2022 19:40:27 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:a9d9:6396:ee12:8be8]) by smtp.gmail.com with ESMTPSA id a14-20020aa794ae000000b00561e010a309sm1673579pfl.19.2022.10.04.19.40.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 19:40:26 -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: [PATCHv2 2/8] zram: Add recompression algorithm sysfs knob Date: Wed, 5 Oct 2022 11:40:08 +0900 Message-Id: <20221005024014.22914-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221005024014.22914-1-senozhatsky@chromium.org> References: <20221005024014.22914-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664937628; 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=sxrqiw0cbhfXN4+OelLD9+srPRQcNc3GlNvIAj2f+tU=; b=lEKnyvXjFWB/4UV9zA1MBR7amtiwlWYPZr3AzP5lAtmpBLR83x+Ar5BcrKsH122RrZebaY 3BsAM7mQsUCqBC8lOlNaenIPH1jksTrbMT7eeVWmeuZogZvM59De95KJ3yYwzk0c2+mVPT r1NTk+eFgFwUJn0Hu70fDCme7tYR9tQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=HV8IJUnQ; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf19.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.51 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664937628; a=rsa-sha256; cv=none; b=QTkhBfyC9ud+colVvFjvTn6fN0jRNwXhpbTFVapgKlDip/xe8aR0cJxIVusW2EugMcoXnC w2LMsBnF3DZQ6+2Wr9Jbb+vvUlzaF8sabud7PP4vjAA9u5f4c58jTsH8T1EcdK8NxHILg5 dDu+vwXYPugp/OfSwliEOK6XJMOJ8OA= X-Rspamd-Queue-Id: 5EC331A000F Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=HV8IJUnQ; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf19.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.51 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Rspam-User: X-Rspamd-Server: rspam10 X-Stat-Signature: fkpemypax1hcnnxjtr79fhcufbj1xhcy X-HE-Tag: 1664937628-651208 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 770ea3489eb6..a8ef3c0c3dae 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; @@ -1000,31 +1005,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; @@ -1053,11 +1064,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) { @@ -1762,7 +1817,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); } @@ -1895,6 +1954,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, @@ -1918,6 +1980,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, }; @@ -1997,7 +2062,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 Wed Oct 5 02:40:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12998836 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 92283C433F5 for ; Wed, 5 Oct 2022 02:40:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24A9D6B0075; Tue, 4 Oct 2022 22:40:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F92A6B0078; Tue, 4 Oct 2022 22:40:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C19A6B007B; Tue, 4 Oct 2022 22:40:33 -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 F17626B0075 for ; Tue, 4 Oct 2022 22:40:32 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A4449120682 for ; Wed, 5 Oct 2022 02:40:32 +0000 (UTC) X-FDA: 79985342304.07.1AEB3A6 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf25.hostedemail.com (Postfix) with ESMTP id 0C701A0009 for ; Wed, 5 Oct 2022 02:40:30 +0000 (UTC) Received: by mail-pj1-f45.google.com with SMTP id o9-20020a17090a0a0900b0020ad4e758b3so539985pjo.4 for ; Tue, 04 Oct 2022 19:40:30 -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=+8HyA4g1G7SzaN6nxygfOgRk8GE0piuM7BVZrp+fZZ0=; b=iJZoZ988DbLfqFyS85LiqYK0iD0Jl5QFkdRZH/o20Tn4yzm1XYNlW1NvR8vRf6IVWb pRjXWrj+frDOYasSYToNs0l/W03Wt0QpzcH/Ya0mtEBpV4j42YFvVLcLyWZpMf9YkFJ7 Zs6v0x3YQ6L/TCAVKMbkXph43Miyvc2knSfbA= 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=+8HyA4g1G7SzaN6nxygfOgRk8GE0piuM7BVZrp+fZZ0=; b=ICWXi+7dua8tlUsCLgEwBd5o5Cep+ktoYJphP3AyzSrWNenmJKTpSiNNZtpDhiVKhe 7EEviq21xyNVAgq5pMgbEC4NOjih0vH03+IQpFtiUY+Uhf4twagivSr3yCY3Jb+tgpCx o8ags6P0oEs7vrmKp9m3tPzGwCYNBJXmZh28S5BuAGH3OGe5gWnZao2RX0AukxZZ5a/3 Z0RlXW1tSi/wrd3ABjLVKGYYovvJMHbj6Y0yz94zxOJUQAsd+JLBG8XZhu6hl2tCrtyQ /4dGIhEpt2HmtPJ8F1e6XQMaXycyDkjw0+1mQSFIOeJBqbZRX0ssuXYILWRzbSr4wIXz ctxQ== X-Gm-Message-State: ACrzQf1btc8t1TtRSS+cy9btz+gOhn/xR05mXX3r8r4HMNzqXEy20Ziu CZK5QEp5H4zRHmEHQen24w2JyA== X-Google-Smtp-Source: AMsMyM5PtNm+kNj458oT3nacLJb/Pc90yrx3l6fXrSCv72h7b3aeffHIBEIPGYclwk6h6GPHs0r6AA== X-Received: by 2002:a17:902:8541:b0:17f:6b27:7a75 with SMTP id d1-20020a170902854100b0017f6b277a75mr8912286plo.65.1664937629863; Tue, 04 Oct 2022 19:40:29 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:a9d9:6396:ee12:8be8]) by smtp.gmail.com with ESMTPSA id a14-20020aa794ae000000b00561e010a309sm1673579pfl.19.2022.10.04.19.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 19:40:29 -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: [PATCHv2 3/8] zram: Factor out WB and non-WB zram read functions Date: Wed, 5 Oct 2022 11:40:09 +0900 Message-Id: <20221005024014.22914-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221005024014.22914-1-senozhatsky@chromium.org> References: <20221005024014.22914-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664937631; 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=+8HyA4g1G7SzaN6nxygfOgRk8GE0piuM7BVZrp+fZZ0=; b=Hn/rKnR0mdFHgJZGyBMt1SxS9DJVrgp0IUOIYHmWQYSDsBc7LyjLdn96DgA5BDkKttUpAx eOBG4TNgBs1EaVxxy5atHpxFGpenQcu257fZbHQE8cbe6evaB7iRPu0p6Vr9fQ4tE++XaK kdkRMJs2f0yaym3oDrBkRnO8CWi8aSw= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=iJZoZ988; spf=pass (imf25.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.45 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=1664937631; a=rsa-sha256; cv=none; b=8kuIVZeP77FYuylgB+i17wfpkuek4Zc6TKanzRgHvdffSRlWKcj94uT+ekwe6KCpP/ECtO G9DWBHF1RrU/jAWWcovZ14M2YBOjURVnjOmFJhVRzH2CnLqmk9ft1P17axBwBOC91RLQMm YlFggtP0v27QuIM1t9D+qKf7sju4kyc= X-Stat-Signature: muy5gikk57nfq5cru6d65mitjjpmjk83 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0C701A0009 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=iJZoZ988; spf=pass (imf25.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.45 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspam-User: X-HE-Tag: 1664937630-982244 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 | 70 ++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index a8ef3c0c3dae..9ec60deeb186 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1314,8 +1314,34 @@ 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; + + /* A null bio means rw_page was used, we must fallback to bio */ + if (!bio) + return -EOPNOTSUPP; + + 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; @@ -1323,23 +1349,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); - /* A null bio means rw_page was used, we must fallback to bio */ - if (!bio) - return -EOPNOTSUPP; - - 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; @@ -1349,7 +1358,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; } @@ -1371,7 +1379,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)) @@ -1381,7 +1407,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 Wed Oct 5 02:40:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12998837 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 8BE54C4332F for ; Wed, 5 Oct 2022 02:40:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24A006B0078; Tue, 4 Oct 2022 22:40:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D4586B007B; Tue, 4 Oct 2022 22:40:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F197C6B007D; Tue, 4 Oct 2022 22:40:33 -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 E1C516B0078 for ; Tue, 4 Oct 2022 22:40:33 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 84F1C120682 for ; Wed, 5 Oct 2022 02:40:33 +0000 (UTC) X-FDA: 79985342346.30.AADC6C5 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf20.hostedemail.com (Postfix) with ESMTP id 34FA51C0026 for ; Wed, 5 Oct 2022 02:40:33 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id b2so9390712plc.7 for ; Tue, 04 Oct 2022 19:40:32 -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=2ldirlHW/bqumOOMqCAOQKJNqbk5ea09l+ng8hK5Jrw=; b=E0HioGtE495MshKKZWvw4odlvQR7s9Z5ne3/Km+M/hJQIfwWoHjTzRysM1AZ6xOHMR IBjnWL7aP60hidEnBsDjzroSi2fQSBRRvoV0L+fdbcd1ZJuLtLjE0OVl4MmhbKT0QZWW 9PA9tukgTAk+q3L7sczEH3rsRq//iNzu4/p5g= 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=2ldirlHW/bqumOOMqCAOQKJNqbk5ea09l+ng8hK5Jrw=; b=H3wIVGXCDmp7rCUkgHy4+TziubNWcdCYy6+3kkUT4xdAXSN6AO8Vz9WwkncT8qTz89 NgHnqqMY491JYwfTEqS7kos8QwbliJDZq7noWCeQOJJB3bbs8oOpirYZ0Ljj3M1jR/AK haIeE1nWZNB7Juj0GP3NzWgLgPntbHeQdR202Kj/kP/h4D5G/dYoPDYyU14W/sIaogIz y9nlL6po4rDDcCaJFsrXm7ooF5O4PEfTwLMDTUvmP2BHXJiFFEvb6JGzFyIBvwKlKtTR D+gjXy/P3Jxpxq2Kzu7JlWZOak6lP3IF100oAxqk6ScCYbI1jCgquzRn03/6FxHpbUbA /tHA== X-Gm-Message-State: ACrzQf39ARDVrD/HhQecNZT2d1X5GQhqmqoCLksu5kqTbulKU3sbMGB2 URt2L0bSlWUD5RiAt2Nx9RT8ig== X-Google-Smtp-Source: AMsMyM4e2jHH5e7/5+FrjgXccrWcGMZ+CGRT7W7wOetcAdt0ey0+KVLFKVaDficjROwIE+/bGMzOmA== X-Received: by 2002:a17:902:9684:b0:17e:71b2:bd16 with SMTP id n4-20020a170902968400b0017e71b2bd16mr16382234plp.163.1664937632242; Tue, 04 Oct 2022 19:40:32 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:a9d9:6396:ee12:8be8]) by smtp.gmail.com with ESMTPSA id a14-20020aa794ae000000b00561e010a309sm1673579pfl.19.2022.10.04.19.40.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 19:40: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: [PATCHv2 4/8] zram: Introduce recompress sysfs knob Date: Wed, 5 Oct 2022 11:40:10 +0900 Message-Id: <20221005024014.22914-5-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221005024014.22914-1-senozhatsky@chromium.org> References: <20221005024014.22914-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664937633; 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=2ldirlHW/bqumOOMqCAOQKJNqbk5ea09l+ng8hK5Jrw=; b=OJpHNJ/cZSVmSVVCm+A7+QPvhwkBjxN6vLhBjzUnC4rUZiibPaP2nwjkltCdZhWfqaoMy6 OZxsORSSCh4YikXpyZrQeV5MI7VS9wVsN5gusyujmuWk70dyoJB4EtWeX4COpYURcCvv72 036h7CCkOiRRhZRdeP6oxIBx+n1OYsk= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=E0HioGtE; spf=pass (imf20.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.176 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=1664937633; a=rsa-sha256; cv=none; b=EK0Ub8Uew2in8YFJOYPRafeg92WBB/N0JaAHLzslo/adsKf5cl/D5gN74ZegINXxMb0Qi5 e1wqcn3TRBEJT29OLZySE+HUmbpf8wNb//b4nnXL7GI84N7bYs5mY4Km/e6kcB8wNKP2Ky ns1BnT/5cFJPCqM0QoYC63XIYnMT+b4= X-Stat-Signature: 74dbmx5487u9igsd4yqwbco8cacdktzs X-Rspamd-Queue-Id: 34FA51C0026 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=E0HioGtE; spf=pass (imf20.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.176 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam07 X-Rspam-User: X-HE-Tag: 1664937633-643069 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 | 12 +++ drivers/block/zram/zram_drv.c | 192 +++++++++++++++++++++++++++++++++- drivers/block/zram/zram_drv.h | 2 + 3 files changed, 203 insertions(+), 3 deletions(-) diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index d4100b0c083e..7febf36e93eb 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -78,3 +78,15 @@ 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/huge pages, using a potentially slower but + more effective compression algorithm. Note, that IDLE page support + requires ZRAM_MEMORY_TRACKING. + + 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 9ec60deeb186..aacabaefb0c7 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1282,6 +1282,12 @@ 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_RECOMP_SKIP)) + zram_clear_flag(zram, index, ZRAM_RECOMP_SKIP); + if (zram_test_flag(zram, index, ZRAM_WB)) { zram_clear_flag(zram, index, ZRAM_WB); free_block_bdev(zram, zram_get_element(zram, index)); @@ -1347,6 +1353,7 @@ static int zram_read_from_zspool(struct zram *zram, struct page *page, unsigned long handle; unsigned int size; void *src, *dst; + u32 idx; int ret; handle = zram_get_handle(zram, index); @@ -1363,8 +1370,13 @@ static int zram_read_from_zspool(struct zram *zram, struct page *page, 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) { @@ -1376,7 +1388,7 @@ static int zram_read_from_zspool(struct zram *zram, struct page *page, 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; @@ -1602,6 +1614,178 @@ 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 the object so that we + * don't attemp to re-compress it again (RECOMP_SKIP). + */ + if (comp_len_next >= huge_class_size || + comp_len_next >= comp_len_prev || + ret) { + zram_set_flag(zram, index, ZRAM_RECOMP_SKIP); + 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) || + zram_test_flag(zram, index, ZRAM_RECOMP_SKIP)) + 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 @@ -1982,6 +2166,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[] = { @@ -2008,6 +2193,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 4044ddbb2326..09b9ceb5dfa3 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -49,6 +49,8 @@ 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 */ + ZRAM_RECOMP_SKIP, /* secondary algorithm cannot compress this page */ __NR_ZRAM_PAGEFLAGS, }; From patchwork Wed Oct 5 02:40:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12998838 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 E14EDC433F5 for ; Wed, 5 Oct 2022 02:40:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C8796B007B; Tue, 4 Oct 2022 22:40:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 779196B007D; Tue, 4 Oct 2022 22:40:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 640076B007E; Tue, 4 Oct 2022 22:40:36 -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 5295A6B007B for ; Tue, 4 Oct 2022 22:40:36 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1D52BA05C0 for ; Wed, 5 Oct 2022 02:40:36 +0000 (UTC) X-FDA: 79985342472.17.D867814 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf10.hostedemail.com (Postfix) with ESMTP id 8BD44C000B for ; Wed, 5 Oct 2022 02:40:35 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id 3so14230521pga.1 for ; Tue, 04 Oct 2022 19:40: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=OE2FzWZV+eK+0K5lMxD8PaF7VIaG8/7NL+uSrdg3shk=; b=IYWm7+uiUJMlmGAxYUFbJ3Y2TQXm4KOiJQvfkQpRrYYY3E7rL+drqW7q86flsucQI+ D8O0A24NGkLEjU7Vsd2djdz6g1zvo8xNuVRfcW6JgcdLJYXBh+qzuLi/CKtYYlXQ74Qk zYPJZeeH/rjb4G2p0RPHLBjM5kFPujSiPtVF8= 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=OE2FzWZV+eK+0K5lMxD8PaF7VIaG8/7NL+uSrdg3shk=; b=p7SctaGrpVRYHBCiDJrD/TyrvmqKWy60bVwJO0gNahjrRilYA7WprqmO0U7ZcS+zyv EShuVzibmrwOCIBwqgp9PNta7w3RvYXkFVjRQFAEsidYVS0d2+eSq534IDJHWQATrwwh blk4Kg/8jFbhizPl3pSqx523BBxjVyZoN/a1/pnTMzNtDEw6oTQGIombT9mDR0xzreW4 guoBSq9X6dQX+ctuUSGiy44QjhCW6hMSZfMAVqnHje1sCzlnISg0RSVt9ejnUOUtlUFu Ib8vZjRTEDVV5RzTjxQ+U68LzZkf5Bn5OFDfJ/VWc3xIB+pejsjMpRXx2ASmIddyjWRF jzSQ== X-Gm-Message-State: ACrzQf1DnSo3CxyKU+K6KQ9ylbuNU5HPr48tHM93qvOVskw+ZY0zpoi6 oR2i1V9EXhf8o8lHUZBlvGeX3OmgPPxG0g== X-Google-Smtp-Source: AMsMyM7LvfXGCUBNVeyayt3p5M2B1olhIPbKqEPWsqDdIwx3njBFDBv51oEjFvZ0UTnMdcsvzhllhQ== X-Received: by 2002:a65:6908:0:b0:44e:1349:1108 with SMTP id s8-20020a656908000000b0044e13491108mr11473463pgq.180.1664937634586; Tue, 04 Oct 2022 19:40:34 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:a9d9:6396:ee12:8be8]) by smtp.gmail.com with ESMTPSA id a14-20020aa794ae000000b00561e010a309sm1673579pfl.19.2022.10.04.19.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 19:40: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: [PATCHv2 5/8] documentation: Add recompression documentation Date: Wed, 5 Oct 2022 11:40:11 +0900 Message-Id: <20221005024014.22914-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221005024014.22914-1-senozhatsky@chromium.org> References: <20221005024014.22914-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664937635; a=rsa-sha256; cv=none; b=WtCTlPgW6QE1qXHPGaNAPI/niDaL+nHzOaRWU7dfkdl/zpey3OKcj8KXmP8OX+vDNoOqPb +Iu51P5zxLHtxxRw0g0mu3dRkYFFgxnkDd77c7eScC4YsvfrqIXVMeuTG8ruO09B9Ey+JR uq2wU0eEOyAQ4sA8iJbuMzpvrMtNTP0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=IYWm7+ui; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf10.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.170 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664937635; 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=OE2FzWZV+eK+0K5lMxD8PaF7VIaG8/7NL+uSrdg3shk=; b=ARFu/luzR+tgx/7ewwD5vFjD9SXzdn1SL+kyAnd4mTpP6phjYzyrRmue2+dZRmv5dVBYrf 33ytNrip6686eCj2KeiHQABmby/LT0tDXA57TDUPLMUUQ9qEzNHFtSD74jQq1yIHDJMKQl W6eLqp9ye2+BVM2mrCA6sAREtdoo0yc= X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=IYWm7+ui; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf10.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.170 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Stat-Signature: u63xgdxcsoi5nxkkmez1qqpg7u6zm987 X-Rspamd-Queue-Id: 8BD44C000B X-Rspamd-Server: rspam09 X-HE-Tag: 1664937635-571338 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 +++++++++++++++++++++ drivers/block/zram/zram_drv.c | 7 +-- 2 files changed, 57 insertions(+), 5 deletions(-) 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 =============== diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index aacabaefb0c7..077a0bc60b8d 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1622,9 +1622,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, * * Corresponding ZRAM slot should be locked. */ -static int zram_recompress(struct zram *zram, - u32 index, - struct page *page, +static int zram_recompress(struct zram *zram, u32 index, struct page *page, int size_watermark) { unsigned long handle_prev; @@ -1707,8 +1705,7 @@ static int zram_recompress(struct zram *zram, static ssize_t recompress_store(struct device *dev, struct device_attribute *attr, - const char *buf, - size_t len) + const char *buf, size_t len) { struct zram *zram = dev_to_zram(dev); unsigned long nr_pages = zram->disksize >> PAGE_SHIFT; From patchwork Wed Oct 5 02:40:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12998839 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 675E0C433F5 for ; Wed, 5 Oct 2022 02:40:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 027A36B007D; Tue, 4 Oct 2022 22:40:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF2946B007E; Tue, 4 Oct 2022 22:40:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D44506B0080; Tue, 4 Oct 2022 22:40:38 -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 BF71E6B007D for ; Tue, 4 Oct 2022 22:40:38 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 94F78160E5E for ; Wed, 5 Oct 2022 02:40:38 +0000 (UTC) X-FDA: 79985342556.25.3CB2CA1 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf06.hostedemail.com (Postfix) with ESMTP id 2F312180003 for ; Wed, 5 Oct 2022 02:40:37 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id i7-20020a17090a65c700b0020ad9666a86so540084pjs.0 for ; Tue, 04 Oct 2022 19:40:37 -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=XWoWvn6QLYmkZfKsLskYp8R1UWJ07QB0khsqO1xI030=; b=j9KV+AyeW0jwezvi5/7/uJWlhOJi/pvUDSLhxR2V+HoNvgDu2rKXYpM/RnnkoJ1D3r 2feDyqGE61vObJ5SyznPn+z9BypLv8OcLdJiHqiobO2nXUfYZ2ulMO00MrxBOUET2b7L 7JirWhoT/PetJ3qKcOXBnlXsKhCJe0WXcJqiw= 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=XWoWvn6QLYmkZfKsLskYp8R1UWJ07QB0khsqO1xI030=; b=nqC0QhOzJV4ZlJElN88kEiJHXiLvSlWCtkckZHVh3b62iuC8v1WU7B2qWQaAB8YXoj MYqtkBjwaIS4+RnDC6cMuHm02ZAK2OFSvpv8wiMM0aon8Lkux5plHopCneBYsL83gdcr 4Ixklfua6Nlv3UmexvoUZDYQczLBeKMS8jo6h0eud+AEjUAZZjXnhnCM+sC/R9sxAfOx 7nTPU9wwE+17Vb3+esDCabelaqv/owzUG4J2O/n9/2bPMnJQ9meSGOLdK0Xcwnm37Q+X ndfmZamjnzpN4Gv22+vJ0AsyLxrCgfRwUVraSrPQ29gChgjbLn5K5RR6wRa91umKQGbX 6dSQ== X-Gm-Message-State: ACrzQf08VKRCnAQJqLdIByJfyudf0JRuTxxw9Lzzr2+3RU4afOd87PAK ywVVVIzdwz4HCXyfLFLLv1DxDg== X-Google-Smtp-Source: AMsMyM7sTr5/lG0VbDXKXmsnvqJ4QLG7VodsT4AHL9ItMxEzciwN7QsvDq5BXnvrwAaOhOdYV7NqTg== X-Received: by 2002:a17:903:2684:b0:17b:7568:ffea with SMTP id jf4-20020a170903268400b0017b7568ffeamr29040217plb.128.1664937637205; Tue, 04 Oct 2022 19:40:37 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:a9d9:6396:ee12:8be8]) by smtp.gmail.com with ESMTPSA id a14-20020aa794ae000000b00561e010a309sm1673579pfl.19.2022.10.04.19.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 19:40:36 -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: [PATCHv2 6/8] zram: Add recompression algorithm choice to Kconfig Date: Wed, 5 Oct 2022 11:40:12 +0900 Message-Id: <20221005024014.22914-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221005024014.22914-1-senozhatsky@chromium.org> References: <20221005024014.22914-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664937638; a=rsa-sha256; cv=none; b=lniX0MuIf/c4pHElkd+ljTDHsOZm8cR1hqy72TZG/J+lSJk9b0Im453C61s05Y0mJr9DLv m7eP6tOqpDjSxrm5iTwJjIWt+n0lEkYhwmc1SOOEdRxBBlxHHO3LydBWH1Pco5UclwW1nN XQwqK2yOF3GF3aGcove9R979v+JVb20= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=j9KV+Aye; spf=pass (imf06.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=1664937638; 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=XWoWvn6QLYmkZfKsLskYp8R1UWJ07QB0khsqO1xI030=; b=SIwKyp2JqQKH2KUZR3Csw1tfY7g0jR4+DUvCsOsrm6hnJYl1ZfYnkKshYaUVViPV4LAEjE 57yJrOOnGp8W0l0GWMkFiGQhyE7uFLq0I/NN0epiINCuqxeI7xY/phvuINYtiFaMuvXoLP SzmzaIewEdQ567Vp+GvGE5WyRjLUbcQ= X-Rspamd-Server: rspam08 X-Rspam-User: X-Rspamd-Queue-Id: 2F312180003 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=j9KV+Aye; spf=pass (imf06.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-Stat-Signature: f3sfcr8rhg9ook5zrgiogaroaebsyz18 X-HE-Tag: 1664937637-135093 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 7febf36e93eb..442885ac72ca 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -90,3 +90,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 077a0bc60b8d..75fc89de21e3 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 Wed Oct 5 02:40:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12998840 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 C6BA1C433FE for ; Wed, 5 Oct 2022 02:40:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F6296B007E; Tue, 4 Oct 2022 22:40:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5559B6B0080; Tue, 4 Oct 2022 22:40:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D0706B0081; Tue, 4 Oct 2022 22:40:41 -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 28FF46B007E for ; Tue, 4 Oct 2022 22:40:41 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id ECFA41C66D1 for ; Wed, 5 Oct 2022 02:40:40 +0000 (UTC) X-FDA: 79985342640.05.39AE422 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf09.hostedemail.com (Postfix) with ESMTP id 9289B14000A for ; Wed, 5 Oct 2022 02:40:40 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id l1so1450455pld.13 for ; Tue, 04 Oct 2022 19:40:40 -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=UiMX+a/n3KparVTc03/3zOVAcxR5tnQKucP/xxLwQns=; b=RYDcpGwT8/kxYv0Gsha/XvT0x9/1XAcaUZ9pG1TRfNQLtLFe4bvDwRSYILJ5osgUwk y6Zsku43KObROnjD7CJgNi1RySn4Zaccyjr7YmbyL6JTKrxIYBwbH0sC7NxC4UXvIAmm VjziRJojHHa5UumFdZ7/roPTRpuGH1rIN86Ho= 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=UiMX+a/n3KparVTc03/3zOVAcxR5tnQKucP/xxLwQns=; b=5q/giiWIm1nMdku1TIlcm2P5CHgkIBeAfUWQiuv5JAFvixMvqLA/MYkK/nuSGZoVQt usU01M9WL76jrlnDbfAou565cKvESzWcMVurOk+gA+HXQ4m4wIhaDgveDjqj4cQ1mBPB oa47SffxwQqWf6BJM9cHEudIaxLuJnqkUPi2OL+k7f9Mew+vFkLHTiQkk3PBzatQgtn3 l503D2vHvn+3wNy2VLLzCnHqels2bhRuPl3kzMjj9CTU5aDyCC0Voq6a1+M/2S293+VL ve5wv0/damGNnblSN7cq8OR9SNe8W6vFnhFWrxgg1735yKv5VcouV4etwa7sYrHRgJzJ 9xaA== X-Gm-Message-State: ACrzQf2l9yEXxUTI9j8vG3maNKscObGcuYIff5LZtFfDvq+BWppA95Ei Qr4D+uee2FBfKs1UWfYBKFWrGQ== X-Google-Smtp-Source: AMsMyM6yf6VBk7LFFaROXCkL0h1+X6GqbusXc4YobK7Ck5Pu0fYLuRSJkHP/UIYXXG44c1pXIcGSMw== X-Received: by 2002:a17:90b:4c0b:b0:203:6d81:bb53 with SMTP id na11-20020a17090b4c0b00b002036d81bb53mr2744972pjb.3.1664937639678; Tue, 04 Oct 2022 19:40:39 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:a9d9:6396:ee12:8be8]) by smtp.gmail.com with ESMTPSA id a14-20020aa794ae000000b00561e010a309sm1673579pfl.19.2022.10.04.19.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 19:40:39 -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: [PATCHv2 7/8] zram: Add recompress flag to read_block_state() Date: Wed, 5 Oct 2022 11:40:13 +0900 Message-Id: <20221005024014.22914-8-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221005024014.22914-1-senozhatsky@chromium.org> References: <20221005024014.22914-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664937640; 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=UiMX+a/n3KparVTc03/3zOVAcxR5tnQKucP/xxLwQns=; b=His1N1oVcXy4omcDB7/ViZw8cYUyJdvzx7vQAFcTYnbmJWtL+4JqPprDqF+ElHsdEPajRs 6gFpJ49t4nNaDriT1mxYQsHWXC1W5qBe39TeDplEHxV15ZWYzT+kFoink2MCqeCWdOCS56 qV1E5MXl16FjL5PwVQB0SDTPubGFW5c= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=RYDcpGwT; spf=pass (imf09.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.175 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=1664937640; a=rsa-sha256; cv=none; b=YDavpD76OsiYuI7ZEQ0cTkuOOmrJDOEjJbPhNswtYZhpY3bvnXN+M2NSUUem9SoIOfbAF3 Tlunh3OZ0evbqt2QbAi0pmcsCasjXSmFUr2nbyQh3g1bzlnaesjYSHZQmVq/jFDU88Lb0k 3wbT8jSJUJGanFl3U9XtKjwnHLWMzFQ= X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=RYDcpGwT; spf=pass (imf09.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.175 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9289B14000A X-Stat-Signature: 9dmk1g8pjdpdx5jigxmkqgcouay6s965 X-HE-Tag: 1664937640-618942 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 75fc89de21e3..ce9413040ad4 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -925,13 +925,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); From patchwork Wed Oct 5 02:40:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12998841 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 2232AC433F5 for ; Wed, 5 Oct 2022 02:40:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B71F56B0080; Tue, 4 Oct 2022 22:40:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD2ED6B0082; Tue, 4 Oct 2022 22:40:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 959596B0080; Tue, 4 Oct 2022 22:40:43 -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 8179C6B0080 for ; Tue, 4 Oct 2022 22:40:43 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 574A51605BC for ; Wed, 5 Oct 2022 02:40:43 +0000 (UTC) X-FDA: 79985342766.18.7524FC3 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by imf05.hostedemail.com (Postfix) with ESMTP id F0C11100014 for ; Wed, 5 Oct 2022 02:40:42 +0000 (UTC) Received: by mail-pg1-f178.google.com with SMTP id j71so8068347pge.2 for ; Tue, 04 Oct 2022 19:40:42 -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=DN/b5T+8kphGI07HeDS7OSncXPJKUwL2fM68wERZKzg=; b=A5kGZyAc89qJ6kCK+avCVDOQG1rFYV91pRcMvTTasAf2EYsXRpQpjJUbxTIZWNYp/U tR3G2yINER6ubc6Bspe9CVNl7paAZ6+T+Y3aMg58w8aCubOInq9g1WosGIEw+NKywp79 pycw5By4BANOR5O+SdakZ0LlV2uX+3hYKKI1A= 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=DN/b5T+8kphGI07HeDS7OSncXPJKUwL2fM68wERZKzg=; b=o8Zv5INY1Qmz+UYdVRmsh1HONY4HV2/m4ofUDrb9DmooJD7TwpGxbHnC/DemnjpKWU K/TiR05IE/T0o0jndIWAFzX13lWfsyEdOofAz2vtOGOjxuUGdQSHHy1uz5sh8g+aAZ4E M6Ih2vlolv9higX4pE0uBbZjk6/LCpf7716+Tao49riAfvIy+kFNfDlIkEXUmkFUimWB /N5k0A/yvLWGIVj3xGvHADhhNZRFdwqE8EEkyGwQ6Y+/EK7fiEz6HzoZY1O2XI7PGRZv Ph58gQw0JZjaEJ1DVE5obKgjv74pcqWgiY352Rwndi8vv/MdRx4qpLGCn48+CZIH0vgl Qmlw== X-Gm-Message-State: ACrzQf124vXcU6/J4i5jSv9SgAXV9gsynjjEmZUBF8GiJNBNy3QD6jAh gpBJefuX3mM/t1o/c0W1RRLaHw== X-Google-Smtp-Source: AMsMyM4qnyp8LALoSSGOuSMXcvCq/sedhpFwnyOvLhb01JSAifeO2MfhxV2+H5u4J+CRxx8WwkrqAA== X-Received: by 2002:a63:2cc2:0:b0:41c:681d:60d2 with SMTP id s185-20020a632cc2000000b0041c681d60d2mr24659853pgs.502.1664937642099; Tue, 04 Oct 2022 19:40:42 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:a9d9:6396:ee12:8be8]) by smtp.gmail.com with ESMTPSA id a14-20020aa794ae000000b00561e010a309sm1673579pfl.19.2022.10.04.19.40.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 19:40:41 -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: [PATCHv2 8/8] zram: correct typos Date: Wed, 5 Oct 2022 11:40:14 +0900 Message-Id: <20221005024014.22914-9-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221005024014.22914-1-senozhatsky@chromium.org> References: <20221005024014.22914-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664937643; a=rsa-sha256; cv=none; b=SmTrP/d2xR3D0feZdDfQvnjNegwp2jJSen8DxBvbsJ8mkH1r4Jve8TEP0M4R42GI7GRHz4 HZnwDU0wZR43VDrLc2a9Vw/323AyO0A0LEHaVCSUEK+VyWSjbt2DsZ6D7PuRjuV5IE8wwJ TeQ+x0dZrRpGlwC6tuO1ViFrwwQFnus= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=A5kGZyAc; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf05.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.178 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664937643; 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=DN/b5T+8kphGI07HeDS7OSncXPJKUwL2fM68wERZKzg=; b=dvijfcDrOLjOMh6d0PYXoK65+72jbGQ2z7EiRjbqwYqnwhGPaGFTeoeQzmyyQBqxZU6dgH dxRgpOUMTp0hBmD6uY2mrh6IA6ZMPuXHXK2eECS6YX1hkSCGZRmEGJb0DtcvqQMWU46EvY GI00zTciZzOm34pAXtxTPxMCDlwWQ8c= X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=A5kGZyAc; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf05.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.178 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Stat-Signature: 1eowki5ijnbj76fjez1jdstkotkhtwj3 X-Rspamd-Queue-Id: F0C11100014 X-Rspamd-Server: rspam09 X-HE-Tag: 1664937642-963646 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: Trivial comment typos fixes. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index ce9413040ad4..9d54dbc72cb0 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -759,7 +759,7 @@ static ssize_t writeback_store(struct device *dev, zram_slot_unlock(zram, index); /* * Return last IO error unless every IO were - * not suceeded. + * not succeeded. */ ret = err; continue; @@ -1657,7 +1657,7 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, /* * Either a compression error or we failed to compressed the object * in a way that will save us memory. Mark the object so that we - * don't attemp to re-compress it again (RECOMP_SKIP). + * don't attempt to re-compress it again (RECOMP_SKIP). */ if (comp_len_next >= huge_class_size || comp_len_next >= comp_len_prev ||