From patchwork Tue Oct 18 04:55:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 3936 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1777638wrs; Mon, 17 Oct 2022 21:57:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5h7E4KsEcZPhX8NmbsMjy9Z7rIbq7yqRw+brSYp/Zmy5xYECZ9wFT03DVrignyz2Wf4miE X-Received: by 2002:a17:907:86a2:b0:791:910e:cce4 with SMTP id qa34-20020a17090786a200b00791910ecce4mr907178ejc.36.1666069044262; Mon, 17 Oct 2022 21:57:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666069044; cv=none; d=google.com; s=arc-20160816; b=IZR9G9+n1uoN9f2YoIeIHYsJTgIKaN6SR0gHfDsv+RAe+vhXeAPC1/3L5c6VZ2odZm CzilC1GxqH36MeKdRAGXvnsUrGlquNxPCUqkQ91ylnBdZ44trzfMHylE9vsUsk0d+6OT xMrxqARcmLJw8o7+DOrXiYXPX3jvjsP2+S2SinILH570qjbTbD7o+zLdxe2mJjCXOgvm WL7gaN4/IHEgStTpkx6yTqkR1Rz7Pqm7zpKCAbFsg7Tc4RjFIGLo1sw6+5S4dQRADSbP bXj6Vz6VY0R9JePe5Iin44aJTuNsyp6NwvD4xI7NvvL3yI+vFasKIEw0kSO6p/CFmpxB xL0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jrgty8apOrCiteWZXp6cJje3TbByVDrSP3kfA6Yguxs=; b=hx7jhd4/Y3ilpYqnBNbHriH5F8EActt7fRIjRnvVBmg27Oc7EYf5W4H9YKQSfCRMHx 6BiZ3XsHd9/6tx+dScQugMHTt2H7UKr1W+t08i49MknRoAsLfy4TB2OYvc/Kr0ji/A4p hoHp0wP6bI6j5V2Hpoxk70nVJF/es6m+pSaKOD2MV9/HvEbawm8vJH4yvjg2Pzaov+Ih fyH0cEcnWwL/cPxatzLRRns/TRo8/JToDY+Gq7n60Fo0IhVr7lSSA/ScJ4u+TEt/h6SV m9U67brYtlSQeoASSGpUs8Hvdowbuj1Opb+TzBY405FzI8Nr/RgPVju7X88sWy7ybIdg AjiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=A6PtYP4e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t9-20020a056402524900b0045bd677b3d5si12628765edd.342.2022.10.17.21.56.54; Mon, 17 Oct 2022 21:57:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=A6PtYP4e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230026AbiJREz6 (ORCPT + 99 others); Tue, 18 Oct 2022 00:55:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbiJREzq (ORCPT ); Tue, 18 Oct 2022 00:55:46 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBA2C95E61 for ; Mon, 17 Oct 2022 21:55:44 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id f23so12748629plr.6 for ; Mon, 17 Oct 2022 21:55:44 -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 :message-id:reply-to; bh=jrgty8apOrCiteWZXp6cJje3TbByVDrSP3kfA6Yguxs=; b=A6PtYP4e6nUYFbJ4+qL+YXYG9Y0rfnMuZPCpE8XkO0YwqAWChGhcGU4CmsYC9wXhXj qpDpEPhPy9anNRnlSo+n6LTO/jY0HDT26iB9XeTUJNMvOjmmd6watayZOx+r8Hbzh6Rf cYCxCOaQ31nZhNHAPdoFWY0ii+GqoLGKJW4jQ= 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:message-id:reply-to; bh=jrgty8apOrCiteWZXp6cJje3TbByVDrSP3kfA6Yguxs=; b=jpNqc/focSR5XaeL0yk/g90Bsr/qT9X9NFVY+BRqB86+GjSEElYy1q8GoKeG/VbdJU okUoJ2uhVODvZr/0aLNlwgt1jbkLu5k9TEzXuM5wS4RDPMEEzF9QZqwqt188+b9+jrJJ NaWCjDSSRtUTz/1uJpDFdYiFbcYbiRK+Su9EMoQuQPzFcA38u/Y9NTr7R+L5SdyDFU6w o5zj6+5UjQeQESzuN/ikhZPycMponT3N3PVcMYb6k/n8g+PpyhRiHJTSfVklSZqr7Xnr vnh5lDQqTaTSVdUoCHUQ/AuFmg4vB2mcjJgdC+jNb/3MxSO/7yjxEOn+iXCfa+n0xyzN IFXA== X-Gm-Message-State: ACrzQf1D5SX7ho/eKnskq8yc0xBUXRu/ut24JMz2g8Bv2/eTMhqZJEak NThGHf53lvOYdpsOhZwl1q47Li7uFpqKyw== X-Received: by 2002:a17:902:da86:b0:183:e2a9:63e6 with SMTP id j6-20020a170902da8600b00183e2a963e6mr1199250plx.105.1666068944372; Mon, 17 Oct 2022 21:55:44 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:17a9:73b0:c262:eccd]) by smtp.gmail.com with ESMTPSA id p4-20020a170902e74400b0017b69f99321sm7549220plf.219.2022.10.17.21.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 21:55:44 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv4 1/9] zram: Preparation for multi-zcomp support Date: Tue, 18 Oct 2022 13:55:25 +0900 Message-Id: <20221018045533.2396670-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018045533.2396670-1-senozhatsky@chromium.org> References: <20221018045533.2396670-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747000014627369273?= X-GMAIL-MSGID: =?utf-8?q?1747000014627369273?= 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 Tue Oct 18 04:55:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 3937 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1777652wrs; Mon, 17 Oct 2022 21:57:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7UiYiD+nzT+93XL+UoAHE5/I1TsoSfenV2+WG/wbikcWkjZjC0lBKpU46Jj4R7aP4dULdO X-Received: by 2002:a17:907:d9e:b0:78e:2ff7:72f4 with SMTP id go30-20020a1709070d9e00b0078e2ff772f4mr852457ejc.608.1666069049703; Mon, 17 Oct 2022 21:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666069049; cv=none; d=google.com; s=arc-20160816; b=Ahnam6ikXptzbm4hSjYPdQ9hBpWap/zztcGMLzEgXKRXhAvY+yAjVGqv9BMn3LAcN1 EOFIGLN4WOkGO9TJGTGsluIvn5lYyUYtfIoyTy/6xY7tH1pH71DIOpl0u690l0oda+J0 JXuq/dzkkJqIf7yi6bUonPDkeT296I6a80x8+Z4VtF/i7GkKp/uiybJuZJzF/Foj1FOK l+IgDMedibmyQtzbye9fEqUOcVN7oiETD8viCnPA14jlFWletVEAEzVB1zRtx1kg46+Y gqmNUMbpTspVb0wP9/oJk8QWwHlQn7FFI3VkFnlfybJm1zkQvtMLVWPI7oLwyE6aA0Fc EJXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JFk+eNUXynOg9IsBl0rempe5RZozp8YcQAw5rmNlx7E=; b=uw7Zygv6Gsrd80o/Ezkwlc69pDBypA8dY8+6gysxd8Y6w+gRSmNQFTBixw/ypv9H6l FMLcG41pcIMfZWqEYTPIuDSKpqC92UuX3Ud7QtozKGNj+srpqZNpUi0TkqCcx/hAojZ9 LLz7B7mKZARH3O/7199w21K+j07R8iBpUT1uV/9YrmF0UpigKcvULlY3aCx6wCOlodu/ LaQBVkFmBymvGNXbbIjY2faD7h3vccLUyhgK7boHjpuXqQu+aPR8U+4BVh7E5+y8osyB wzYx727qfGbl33AY8BGPmwhmQ5jIIyD0WfONnWbZihHpUMksLtF5reLXMssAbeIOk0rF PArg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iCGJlVBx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn12-20020a17090794cc00b0077912fb01ddsi12365257ejc.613.2022.10.17.21.57.04; Mon, 17 Oct 2022 21:57:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iCGJlVBx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230086AbiJRE4B (ORCPT + 99 others); Tue, 18 Oct 2022 00:56:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbiJREzs (ORCPT ); Tue, 18 Oct 2022 00:55:48 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52E6A45F7C for ; Mon, 17 Oct 2022 21:55:47 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id o17-20020a17090aac1100b0020d98b0c0f4so14860921pjq.4 for ; Mon, 17 Oct 2022 21:55:47 -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 :message-id:reply-to; bh=JFk+eNUXynOg9IsBl0rempe5RZozp8YcQAw5rmNlx7E=; b=iCGJlVBxWRXpUIMQsucXw6YsDvNwLojnvvHiyGxBI3A/0Gu/oRlJYCwhdk46CgBA65 G6Rw7zcaSq3YmH1fwtlCqV00WL7d4C9edtJW+4+FF8gYtdPa3nCAphCfMsd0+7AXr5+5 D+9Azge2plTkQRyHGI6hzyYkTVAtM2V+Jzlo0= 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:message-id:reply-to; bh=JFk+eNUXynOg9IsBl0rempe5RZozp8YcQAw5rmNlx7E=; b=UDjrEsxklTC+6BaRp/dlIQ76MaPDqsM65G4eozGhIx4HWi+bgMIoK16OVUNbFvVoGk fdMTGK9ao3+XFA7sd905eL4UWhNOVGG41uOG+9/pbwRM2xqBNKwhEnoxosjNx9QWjgsc NxhCNVjgEzkuH/q7ImN9mtRONHIRgGF6alt9Pj30ClTqRrOaJ8LoZ3iF6blz7eTQc1Di ZZg6ZHhg5+20kvrvOreIqT9mAHEznF7nVU5hOysUY5cjELyFttw1m9OfrKEqH9VeC4U0 OE2iDPFn0GdBe1FjZSPGBx2P4vDwpoU4Gujy//amecL/5fFv/0GYhYweMS+78CXV1GXT 9Pwg== X-Gm-Message-State: ACrzQf2EMbwpEOnwYrztPEDiWiVrfhyIdL63nZ2Nnc9pEIC5ftcBPsgl SJ5Mofg12gg8jZZDtm+aW96IAw== X-Received: by 2002:a17:903:124b:b0:179:da2f:2457 with SMTP id u11-20020a170903124b00b00179da2f2457mr1175806plh.156.1666068946825; Mon, 17 Oct 2022 21:55:46 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:17a9:73b0:c262:eccd]) by smtp.gmail.com with ESMTPSA id p4-20020a170902e74400b0017b69f99321sm7549220plf.219.2022.10.17.21.55.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 21:55:46 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv4 2/9] zram: Add recompression algorithm sysfs knob Date: Tue, 18 Oct 2022 13:55:26 +0900 Message-Id: <20221018045533.2396670-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018045533.2396670-1-senozhatsky@chromium.org> References: <20221018045533.2396670-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747000019558872330?= X-GMAIL-MSGID: =?utf-8?q?1747000019558872330?= 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 Tue Oct 18 04:55:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 3938 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1777703wrs; Mon, 17 Oct 2022 21:57:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7AltU/DeWTvhtbJ5F/EgsSeLHkJLTO8z4LJ+paWcwU4CSg39M4MTSvvZ/ZWA/tDsCxDFqh X-Received: by 2002:a17:907:2e19:b0:78e:11cc:3bc5 with SMTP id ig25-20020a1709072e1900b0078e11cc3bc5mr878255ejc.543.1666069072302; Mon, 17 Oct 2022 21:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666069072; cv=none; d=google.com; s=arc-20160816; b=L76SzV4u8XXpA05KYIgTbVZyz19WcSX89sJhhN9jqv3dd5pPqVYic97KidPVnEqJTN Nvebl+vr2ix5NUpaalGHVeeMhZTbgo09XJtKlJLPN6jeik+tq8CAGIiOPKlAGTRJjszQ 3VSGDVEC0yShVeKeRp9uj0SMhabFNVQHkh/ml6g8pc582fjlJR1i4Vm9yQmg0RFK97ho Ibfo53ft+Gt4ifNKg792gydNoIPGjRxKpQ75z4s8XxEsxbmi8oTCNdyfV6nlIeydP+iu WX5Oc1lPaLpceES2AmdR+Fj+rwAmlQvlZZezTL8a6x42kWX98ZMvlSg78xcin/C1UVlh ffHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lPOwozwW566MrhSDQ5Hik/2oBaG/MJdP0TGgYtIKPis=; b=AgDsXwC0by3JkXWpVCzQ6bL2Q/VokHf6NwzwLupH7RQ8dbosyyAPJWsUApB1B/tpnV 9N3PlsEvv9Au/6W5/X7NwDg/UsqAyV31APMRfqaulMqvYc5c+7HF1Fx31MLS9r1FuIKm PhLfrkeqoNSiH69pO7zUUiZwCCHPQc+xs3+WbvV2nN2is8FUWWe+4ACHT0KCQqbEkObL 6mo13q4bN5RpkDZPGfUZbFbP9uHyVxLDWQeb/NbbHL696krudgEyXQeNCaVBFqm4WkN+ BAEy2R7SAAzduHlYVXE1396mmXFUg2bsTscSKnUmRlu/x/G7vh46/F5sX4XaIyQPn3y3 j+RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YnRifkaN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp14-20020a170906c14e00b0078d5d4a6b64si9953266ejc.662.2022.10.17.21.57.09; Mon, 17 Oct 2022 21:57:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YnRifkaN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230112AbiJRE4H (ORCPT + 99 others); Tue, 18 Oct 2022 00:56:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229718AbiJREzv (ORCPT ); Tue, 18 Oct 2022 00:55:51 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E416C6525F for ; Mon, 17 Oct 2022 21:55:49 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id d7-20020a17090a2a4700b0020d268b1f02so16252218pjg.1 for ; Mon, 17 Oct 2022 21:55:49 -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 :message-id:reply-to; bh=lPOwozwW566MrhSDQ5Hik/2oBaG/MJdP0TGgYtIKPis=; b=YnRifkaNMN9xeU3dP05q8Ea3BFeTmAimQBXUIgaGkiE2mSiMswcN01xw+OrW2yPYCF OvIXJvFjayfS/j734H+93oHgzpWOVPR33IaJNC/+srLLlOZGNDfcMf0kZlVFSBcKh4MV dADJd8226DEIE85679/r2I8nGKw2AK68/UaEo= 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:message-id:reply-to; bh=lPOwozwW566MrhSDQ5Hik/2oBaG/MJdP0TGgYtIKPis=; b=3wecTXYPpgSKFeUuItCY7ZprOFecyn/IKah4f7Gay0xQrtP7LlvqgqEqvSVfY0VVh9 UmvgP5lYa5yXFqtyn2OssjlN75eYN6aIN9w1mFtiQLZD4xxNBsSidQ6NdAit8MPxKRLH j7vKTWRjaRmw08ZdWkLwiXZmHPSvFoTNL819bXEqPn58NdtnSuzqTmhVKyaVkdGtNL/w 2P3u2AS4WUl+pZJmTf4Pptc0M6uqKo3inB/GoZmrRuUOSbKyL9b47PRakAtWaYQ1X5DR dExIAtCcX0JRqHMdr/hY/tkHdjXwasHKL2vcyBEp+xT8GGBiGdMvJfq2ZjY9gmTKORG6 owVw== X-Gm-Message-State: ACrzQf3BLra82wJMCNy8WE8ngToogRmKp9HuZpQYWzx1GKrnybKk9vuG gP1Tdo4HaDeChvZA7dGsetIf4g== X-Received: by 2002:a17:902:c405:b0:181:83e4:490e with SMTP id k5-20020a170902c40500b0018183e4490emr1173860plk.4.1666068949191; Mon, 17 Oct 2022 21:55:49 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:17a9:73b0:c262:eccd]) by smtp.gmail.com with ESMTPSA id p4-20020a170902e74400b0017b69f99321sm7549220plf.219.2022.10.17.21.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 21:55:48 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv4 3/9] zram: Factor out WB and non-WB zram read functions Date: Tue, 18 Oct 2022 13:55:27 +0900 Message-Id: <20221018045533.2396670-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018045533.2396670-1-senozhatsky@chromium.org> References: <20221018045533.2396670-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747000043336352410?= X-GMAIL-MSGID: =?utf-8?q?1747000043336352410?= We will use non-WB variant in ZRAM page recompression path. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 73 ++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index a8ef3c0c3dae..94c62d7ea818 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1314,8 +1314,30 @@ 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; @@ -1323,23 +1345,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 +1354,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,17 +1375,40 @@ 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); + + /* A null bio means rw_page was used, we must fallback to bio */ + if (!bio) + return -EOPNOTSUPP; + + ret = zram_read_from_writeback(zram, page, index, bio, + partial_io); + } /* Should NEVER happen. Return bio error if it does. */ - if (WARN_ON(ret)) + if (WARN_ON(ret < 0)) pr_err("Decompression failed! err=%d, page=%u\n", ret, index); return ret; } 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 Tue Oct 18 04:55:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 3939 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1777712wrs; Mon, 17 Oct 2022 21:57:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Sjji14LPlyUVmSWz/1NDMuoQQuM7IFscAH4dihygVZs91ttP6hbTMJclr1CPvp8pqox+4 X-Received: by 2002:a17:907:e93:b0:78d:46ae:cf61 with SMTP id ho19-20020a1709070e9300b0078d46aecf61mr857254ejc.579.1666069075678; Mon, 17 Oct 2022 21:57:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666069075; cv=none; d=google.com; s=arc-20160816; b=FybrqTfFygjoP/lrkgFU+wG/wdnzzE2bUAeZCHRbsvSD8k4kmi2U3octZSmeeOEMvZ uouvBlED+stjhy23EwCSEb5A+NGh1ZQxRhA0isTtbfufTNjxmAvnHHVYGrbwX2idQL/o SrBo6xAUFmtMO+ojpbFfB9Apzc4s0UuG1HDunqzcWHBoaARtXLce5IGiMP8hbqOismB6 m+yG/g08N26KJ8uObfo7vKdLIGndjBt300ijZ/NoshU9ZV4UuWAOAxk+THkvPF4qSYGJ Y7Sa6n37bswJazlzXYSicnnG0cZBG06tuMGYVBgdHtdDPsKjowsWRfOFKkpqTfL70QUR N+4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KakqBjSQ6Ep6MOW9Qh1kHbwwQF5mRCkC8aIFa9DdqUw=; b=ovzDfe+ZZOEHUIJD0va7LHdI+pfyNVJmQaloNQ55OBBi5BtrGh/WXDx840kZzDVIn4 lxhqzuIDgE5HQDOx+9HaYoidhmpofQS2UMXGy7TX+51UzUW8y+3Qv/9sHf6BjpeixgQt 0Sh2GO7/vI4BWCJF3bV7bnx2iH9G+FkViP3MNDxvWPzLvVUeVS4WCGgH7jL1mWjtTlL9 O0MRrENrr3nfIOhDNIgYTLyGpKEclgYaBR3a9CCCEiV+y4nVc5vdoRfQSeTSb2G/nhpm BYjeUab/NLOcDAkHzSigZIce8HGkqZJCRWGK7p62cuYtzhzXS0Xi6G9Vgev1EVMNtj7O lxFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DX29os8z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w16-20020a05640234d000b00459c73bd1c6si12225550edc.550.2022.10.17.21.57.30; Mon, 17 Oct 2022 21:57:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DX29os8z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230136AbiJRE4O (ORCPT + 99 others); Tue, 18 Oct 2022 00:56:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbiJREzx (ORCPT ); Tue, 18 Oct 2022 00:55:53 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 610019C2E4 for ; Mon, 17 Oct 2022 21:55:52 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id h185so12310850pgc.10 for ; Mon, 17 Oct 2022 21:55:52 -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 :message-id:reply-to; bh=KakqBjSQ6Ep6MOW9Qh1kHbwwQF5mRCkC8aIFa9DdqUw=; b=DX29os8zmQ9tNTIbLain0oTGkNhWorNiLSIbcEIS9zUjBxum+HzT1PGjwzHnll2TuV MqPcv8tyqGOAFrrZccUSo2Z3xwIaCBZsW8BvoGjUzCcrBjkpSNgY2OtfvPvYIKlJBHpP C04ZJeFLG5EK2OFDtZAEPWZCQa/fCWdyAXVwA= 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:message-id:reply-to; bh=KakqBjSQ6Ep6MOW9Qh1kHbwwQF5mRCkC8aIFa9DdqUw=; b=jDbCeRWOcQO/bKqeZCyrJPBSc985tQNeigWVFt2sPPGCCdTLy23PzS1BCCM0O6bWmk Eon+GVaOvU1yR4JwXG79km5FVW03q1WLSUVMmcfJmeA0A2pdfMQBjy3fUcDE3W56O5Dq Qs9teuhz5ztFsXbvP5O4iWkYhbWdFK9WDAblmYjgUr7sol3gsznkWCUBz6+atP7pcDGh 5HEnoW/fK8Z8BHH47/TPqo+DUcbnVVw/1p4GRDSoQBI8yZaFiTLvt5qr9viYrKV5UFz5 w5I017zxzTFmuzBcy53HeVtDTzZWM8ZjtCF6y0cEKLGyeE+7zBHsgEQP792RBLx5r2Ge Nwig== X-Gm-Message-State: ACrzQf1weD1zFWaPJ6gm6G5wlvMNRKNx4l+9NE314lgZQOU2CyQxvUyB qyBmhArdB/fsckgMzHgxVFz8vw== X-Received: by 2002:a05:6a00:3249:b0:565:fc2c:ad79 with SMTP id bn9-20020a056a00324900b00565fc2cad79mr1332858pfb.72.1666068951586; Mon, 17 Oct 2022 21:55:51 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:17a9:73b0:c262:eccd]) by smtp.gmail.com with ESMTPSA id p4-20020a170902e74400b0017b69f99321sm7549220plf.219.2022.10.17.21.55.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 21:55:51 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv4 4/9] zram: Introduce recompress sysfs knob Date: Tue, 18 Oct 2022 13:55:28 +0900 Message-Id: <20221018045533.2396670-5-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018045533.2396670-1-senozhatsky@chromium.org> References: <20221018045533.2396670-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747000046935538185?= X-GMAIL-MSGID: =?utf-8?q?1747000046935538185?= 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 (in bytes) 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 | 15 +++ drivers/block/zram/zram_drv.c | 196 +++++++++++++++++++++++++++++++++- drivers/block/zram/zram_drv.h | 2 + 3 files changed, 210 insertions(+), 3 deletions(-) diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index d4100b0c083e..3e00656a6f8a 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -78,3 +78,18 @@ 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 + + SIZE (in bytes) parameter sets the object size watermark: idle + objects that are of a smaller size will not get recompressed. diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 94c62d7ea818..da11560ecf70 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)); @@ -1343,6 +1349,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); @@ -1359,8 +1366,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) { @@ -1372,7 +1384,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; @@ -1603,6 +1615,182 @@ 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 attempt 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 have stored that object in zsmalloc. If we cannot + * alloc memory for recompressed object then we bail out and + * simply keep the old (existing) object in zsmalloc. + */ + 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 PTR_ERR((void *)handle_next); + } + + 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; + 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 -EINVAL; + + 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; + } + + ret = len; + for (index = 0; index < nr_pages; index++) { + int err = 0; + + 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; + + err = zram_recompress(zram, index, page, size_watermark); +next: + zram_slot_unlock(zram, index); + if (err) { + ret = err; + break; + } + + cond_resched(); + } + + __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 @@ -1983,6 +2171,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[] = { @@ -2009,6 +2198,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 Tue Oct 18 04:55:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 3940 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1777720wrs; Mon, 17 Oct 2022 21:58:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5RfrshYkp4GNVnWlTTjB+W+bj31M/FE4h5bZO16RDawvtOp+bn+pTCB2fQpJE/jkSTB9Vi X-Received: by 2002:a17:907:c15:b0:78d:9c3c:fb8f with SMTP id ga21-20020a1709070c1500b0078d9c3cfb8fmr912524ejc.347.1666069080745; Mon, 17 Oct 2022 21:58:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666069080; cv=none; d=google.com; s=arc-20160816; b=IhqCuJG+2kRKFyU8yR5LwvInZij3JV3+sRtzt/xhGLSpaQgjzcIm0+FciLywSKb52r aL148LMnp7eJZNhmPyQni6taH11AbaZfcExcW2laJxjhn5X0VomPQfSwT6QoPYD7zEmX B+YU/KXyQyJ1VfY+szf8uo5jU3A3NT8/DSfr6U4UyYy2fKjIW0H1Cjo8PICIw4PT+j5a EKMdJZ886uGat2Az2CgKhDlEviRUCq5P+Tz1Ldj8hJAMniI36pTBp/uIB61+Zurs1+Q6 BP1B51OSGf3apeWtlNIXA3os1+rmpbfYGsLJWx+YKdMhq/j2JzJ6bia2H5usyNZU0BVB LGjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zqbNRdZv0AEZA2o65O/7d+PvuPWf+J/YFOhKZdVnIao=; b=QH7ghotOfr54GYmjlVjM3M4bH4BHvhOGkIrOrT/9T0ZTopTUXbxPGN8LudotJWAtYi bKVlJibZ7nRBzASpdXvlCB4pfesEqu+es9lHOdPCOZXQ+pXnIAacsNsLoMemWr6vxmME Fwi3UZyFs3AHe3vcqplHKHYw6j5mp0+7SRSu4ZTkrsn3y44WvYl9rynnZOgulutMLJz8 t6D7wX/ZaVcJalPtNdbnh6FtDzh0F5SK1Umx8gydDKcfYrHjSc5lbp1FQ9+ObsmTLQY2 FHTs5d0wmrKZ0WJwxahq/9OX4Hl+z3NnXkvGgD0BsxWn+/iCg/A38g9NsHh6iEwAU8Jd ag6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ds+HJ6GR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a21-20020a1709066d5500b00782933fe436si9280549ejt.965.2022.10.17.21.57.35; Mon, 17 Oct 2022 21:58:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ds+HJ6GR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230143AbiJRE4U (ORCPT + 99 others); Tue, 18 Oct 2022 00:56:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229943AbiJREzz (ORCPT ); Tue, 18 Oct 2022 00:55:55 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3647A0256 for ; Mon, 17 Oct 2022 21:55:54 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 129so12329364pgc.5 for ; Mon, 17 Oct 2022 21:55:54 -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 :message-id:reply-to; bh=zqbNRdZv0AEZA2o65O/7d+PvuPWf+J/YFOhKZdVnIao=; b=ds+HJ6GR0TTrsjhdVBePPTb+ZYdPlv5VzdAyfO5kycvLRMKU33bufTdI0konnlBlZM 2jNp8xV7OmYFzIYYik/sjHdf7RJiNFshnSc4wMS+NII79AKetCRjFskA10EFZ/6QjeS5 QQZnpbF4K4nH6Tm/zfaat/KILJuoWiu3I4ZG4= 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:message-id:reply-to; bh=zqbNRdZv0AEZA2o65O/7d+PvuPWf+J/YFOhKZdVnIao=; b=pRxDUrTNMDUsdtVj9pojf6akSsBL8ufzaAVVPyntw7pzwj6gHJiCvKq5hAIUg73XYd 6Zv0Xge7EnKtdJ18etzGardj7zJvWUlSu2BOFbqVTzFQrqCBKDaXf6g39ELaShMSBPPQ QyBo+NfvoF1TYMhW9Wect2eelYe4zano3wVkbzjc1MCeTf2EpQE4H+eGdgcgRd38RZTf KySzvNd7ceP5ufc30Mtx3iNCivMjo+GnPj4yM7ww0Lud56Vc9IwiZKOOQ3b0gdgQ6j1I 0jnfxek4nMcMTS+pxvDEjIEcUp+G/jS7EvLQqJMkHFGtBseiwkEKFXv62gMAp9ymm9KI BEEA== X-Gm-Message-State: ACrzQf1xwiS+MEKKfBOC9vE2lOglSzWlpM5wR2E9SLBhcOoUkTWHuy3W ejZMr3dfNWBSbMfZM1GTULAFxg== X-Received: by 2002:a05:6a00:1a92:b0:565:d5c0:f627 with SMTP id e18-20020a056a001a9200b00565d5c0f627mr1383823pfv.10.1666068953954; Mon, 17 Oct 2022 21:55:53 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:17a9:73b0:c262:eccd]) by smtp.gmail.com with ESMTPSA id p4-20020a170902e74400b0017b69f99321sm7549220plf.219.2022.10.17.21.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 21:55:53 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv4 5/9] documentation: Add recompression documentation Date: Tue, 18 Oct 2022 13:55:29 +0900 Message-Id: <20221018045533.2396670-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018045533.2396670-1-senozhatsky@chromium.org> References: <20221018045533.2396670-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747000052471654586?= X-GMAIL-MSGID: =?utf-8?q?1747000052471654586?= 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..c916c2b9da55 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 (in bytes) 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 Tue Oct 18 04:55:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 3941 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1777786wrs; Mon, 17 Oct 2022 21:58:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6G1ADMvY9vVwALyhYOYtwSnm/lS0/6hRF7ZUizIdmREGZR2ZTcK+d1JBOZRMfKx6TCJQtb X-Received: by 2002:a05:6402:1356:b0:459:3c9e:81d4 with SMTP id y22-20020a056402135600b004593c9e81d4mr974663edw.148.1666069093078; Mon, 17 Oct 2022 21:58:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666069093; cv=none; d=google.com; s=arc-20160816; b=sBtw2tCc5F93j0zDcgGgrLxKzZy3CaUfQ3NsA//eNTRCoy0EorlmYuBJ8VaSO5ZOI/ Cw0SDDNOt6oDAlnpWg9s+qBLP92imuSoJM7G8DLuR2bxnzvUOEXm9fIH6sgc6ppgxj28 H4X3JPsEoC3XJ08uMlfLN1Anx4DSypipaAPzzQV7jtmHArsjFpxBIm4OlMMBGze43niE rPRjxYV4A6/Jv/z4m9QPUTttG6a/mqwkFWWsHMWuszEPj3r/0riulkKgaw5uqrV7YD6Y /EGGMzAcnePUFR1CrgTzX5XkynCLgeb/yqbuTY/RdYuNSIQ0FZrhYFRQrOjpELXznImI LNBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=u6FdlTaAeoJZnsdClOVvKEq4lJg+XPWe1oKWdw8/hCk=; b=enoP3O1g4XdolmLUdS+/+EJwDxTx7dIX1ObINWYM9nbELlGLWH+GeDSiMVZL32PpX9 yaI5WH+FfBYnJeAsTaa3aaWovQ4foqdQy+SB7VEWDxNSNIssI5XygtxUlprJfyQDb0NM nI7g7a7Wxv1FFjXaoWE7X4LzWhx9EpAf1y2oWQQm94bejSMnNNZDiyZTmljXb9p++O6A 3xC+pBB6JwHIRS+n4z0nQOtFX57ZakZi629U7beD3FUmNyqry7S0KPJsME1B/qQqL2hQ 86mEFs9Fz8q/5y6wKAYpexjr9rfXil9R/UCY0UiW8Zz/n/QsXBK4YF3s9l63CnGpu53e zzAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mGht8IGE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he18-20020a1709073d9200b0078ca7bbf616si11672659ejc.746.2022.10.17.21.57.48; Mon, 17 Oct 2022 21:58:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mGht8IGE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230094AbiJRE4n (ORCPT + 99 others); Tue, 18 Oct 2022 00:56:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbiJRE4B (ORCPT ); Tue, 18 Oct 2022 00:56:01 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14CF4A02C0 for ; Mon, 17 Oct 2022 21:55:57 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id e129so12315121pgc.9 for ; Mon, 17 Oct 2022 21:55:57 -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 :message-id:reply-to; bh=u6FdlTaAeoJZnsdClOVvKEq4lJg+XPWe1oKWdw8/hCk=; b=mGht8IGExOGxSDdSigMACLR7r+oqEPBhqmdFZwzcCZbnhwEIwDlx8IUzwUJ2oNN4mf yI7zRshfGlUr4VjyEIYcQm9A+xqAcUqq0SHRcig+dl2PYPG/RiYazZ4zPKWAYc9FFzju 6vDXIdBf+phqB93FKQYUwUmhyALJr9U293+wA= 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:message-id:reply-to; bh=u6FdlTaAeoJZnsdClOVvKEq4lJg+XPWe1oKWdw8/hCk=; b=6q00BR2suOJifYFsWMFM8Ktm96gW+5lpXiIbbwxd0K2sD9md9r4uSadVMg53o+VO0a 0OoCYOASM3a6DmnFEtbmYB56I9mwYwhiVSFBANOh87u58VUKfI0YnAVv8ClEe7aFxwOI Lb9eOYGlmWy5PVWbzuCIUlkQzyyQpx0/hN71zw2AaUfYLj18ie50SMO4StXF02DNrE5H 66gLAp1Q+En+mLUEnxJC4796D9PGN7hOQXW4zF4zZ3PwoXEhD3piVVYjoHclN5yOLWOr XsL9igpexD13c9WZJqVYYKqj1mHdW8fcGJZY0UICWCEfx4+f6aZ5+bq4NMF+VXrYFDPF wKpA== X-Gm-Message-State: ACrzQf1OXPOxNgE49vD8qgkapKcIZAfiBuwDOrvQnj3QQM5kOcVZLypD YLonoAV+cYX53SkTwyESHvVRnw== X-Received: by 2002:a05:6a00:1ad0:b0:564:a791:42dc with SMTP id f16-20020a056a001ad000b00564a79142dcmr1116320pfv.50.1666068956740; Mon, 17 Oct 2022 21:55:56 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:17a9:73b0:c262:eccd]) by smtp.gmail.com with ESMTPSA id p4-20020a170902e74400b0017b69f99321sm7549220plf.219.2022.10.17.21.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 21:55:56 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv4 6/9] zram: Add recompression algorithm choice to Kconfig Date: Tue, 18 Oct 2022 13:55:30 +0900 Message-Id: <20221018045533.2396670-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018045533.2396670-1-senozhatsky@chromium.org> References: <20221018045533.2396670-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747000065555554181?= X-GMAIL-MSGID: =?utf-8?q?1747000065555554181?= 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 3e00656a6f8a..076a76cd1664 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -93,3 +93,43 @@ config ZRAM_MULTI_COMP SIZE (in bytes) parameter sets the object size watermark: idle objects that are of a smaller size will not get recompressed. + +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 da11560ecf70..1e9561217466 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 Tue Oct 18 04:55:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 3943 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1777985wrs; Mon, 17 Oct 2022 21:58:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM59WqmhSmPzFb99Ig4tTKRrjTD5WMb610HWrMZfqrbn24rMcR6sv9kMrFjTMgHnyhj2bB+l X-Received: by 2002:a17:907:7ba8:b0:78e:1b38:6b1b with SMTP id ne40-20020a1709077ba800b0078e1b386b1bmr868480ejc.626.1666069139397; Mon, 17 Oct 2022 21:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666069139; cv=none; d=google.com; s=arc-20160816; b=XmxdCDsVfT0byBmnEZkFdMQKXf07OfZZsCMdhnHy/5SiIN0Ov24ajyujkl1WpwKZv1 MACMeuQUBU1uNcCFAyH5rJHzIqD3iynEbph+f1zuY937yfIN6WOPOsOtptTwv1qmXiPb /HXYv6BIFEqrcyfCgGJvibM0HJx7vkth8hpOKiNDqc3sXCcxr2NfyflgAe2gHiaMGNo8 fXE8fjWnfdx0w0p7eRBAMLeqmatwRPRbYP1dp638wwL/D63xwMSRBFXv0YaodqBvlsMM gCSa7yB6+hBqztmZShmRobfUWWk6LvG73u6tJKHHbWlaEuV6058vmaIeMwmzIbdvKDSb fG7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xtQh7ZmjoyZo2F0qXeywbofevhcfT59MQNGpxOyNbx8=; b=NsSx2ea/Q8nOK1u1IH6JIy3l8GK+3cW3/GFDrbjfeSvV24yC5dm7D2JF6LTJRJWzKb x+csbhLfz1q+ekpmMdh5i7CMwNkuMXUXSr2p057YHB85eh7EcX7nF0oLLz786QzMa2V3 oCtg5rIsbqcGF4y03eFMv7FCJh0S0gZkEEPAz4ArsT+E+3VOe83uqKc1+Hw8rDLKVrE0 W1mXcdLB9R99uP96ynkJQrePRGBx87PMR7v6CHb212F6fJi38mFd+8pM+i6ufweLtztG P0YldItne3wRatGiOpIrSjMLc9VNRlnprZlTCsqXDWgYMLH9zDEIhXOUCY4Qgmm8vqeJ /Ogg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Ez9/9h1l"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ti5-20020a170907c20500b00787ad97302asi7616252ejc.863.2022.10.17.21.58.32; Mon, 17 Oct 2022 21:58:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Ez9/9h1l"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230118AbiJRE4r (ORCPT + 99 others); Tue, 18 Oct 2022 00:56:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229869AbiJRE4D (ORCPT ); Tue, 18 Oct 2022 00:56:03 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67DF3A220A for ; Mon, 17 Oct 2022 21:55:59 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id y191so13056696pfb.2 for ; Mon, 17 Oct 2022 21:55:59 -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 :message-id:reply-to; bh=xtQh7ZmjoyZo2F0qXeywbofevhcfT59MQNGpxOyNbx8=; b=Ez9/9h1lS/+dC1G6E7jdHeTIahEsqMGdrK+uwr+wyLQfJq+YLjzffrRXXk0guSR6Ye VzU5kwyeOgaqpli2PFTCX+fpqvNyEHxZoVc7VzgNecYXJnNNROFa4+6BvojEANHXNLHN Udu8/kOoLQRV0SokqX/ZR/orQ8KcP4PTdY21k= 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:message-id:reply-to; bh=xtQh7ZmjoyZo2F0qXeywbofevhcfT59MQNGpxOyNbx8=; b=CH9trWJhAo6hSop840Y6vivx5xop8jrgeJ3pOwASu3xaXjktllEcKdAGaz92nFn7HM dZ1DzFTgpIGPZAX0rBe5OOOsw7EETS44yNKpCLiLUfzjYsnXGc7CofPOLP/fL5xJNcRm dN9tV+tWE13pP5yuEUSE6DB3FTpNo+eP5aDszu5rM5TVkwQgiMA6zKP2KLk33d+CG/W6 fh3eJm4gV5un76D0wdDM17I6yPH71Sh3nCT4DHFjiIs4q3ERYyjugo6Takx2OfMGtLVa WTTC9spVuWGjZRHy9c7q54Fcy/PlbRsOSxLxXkIroCU+fDwpUjTTSUBzOMkrPHDDen0F jvmg== X-Gm-Message-State: ACrzQf2yf0vo0jVXZkhO7U8VpNWhwtj4zZXa12tRxPYTfJt5Mq/jLWW4 t+Fas6g7p1najzcfz2Ik/H4gPg== X-Received: by 2002:a05:6a00:1781:b0:561:7f7f:dc38 with SMTP id s1-20020a056a00178100b005617f7fdc38mr1384946pfg.42.1666068958685; Mon, 17 Oct 2022 21:55:58 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:17a9:73b0:c262:eccd]) by smtp.gmail.com with ESMTPSA id p4-20020a170902e74400b0017b69f99321sm7549220plf.219.2022.10.17.21.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 21:55:58 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv4 7/9] zram: Add recompress flag to read_block_state() Date: Tue, 18 Oct 2022 13:55:31 +0900 Message-Id: <20221018045533.2396670-8-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018045533.2396670-1-senozhatsky@chromium.org> References: <20221018045533.2396670-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747000113460775824?= X-GMAIL-MSGID: =?utf-8?q?1747000113460775824?= 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 c916c2b9da55..010fb05a5999 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 1e9561217466..5d760467e0bc 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 Tue Oct 18 04:55:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 3944 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1778367wrs; Mon, 17 Oct 2022 22:00:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM52M0e3VV2LJMxKeCAW17HcckJZauBcvru7dW1VKRBMxfkFv/mr+OFqXnhlOhhlInzH32dp X-Received: by 2002:a05:6a00:2307:b0:565:9079:b165 with SMTP id h7-20020a056a00230700b005659079b165mr1363693pfh.53.1666069233057; Mon, 17 Oct 2022 22:00:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666069233; cv=none; d=google.com; s=arc-20160816; b=FpjkK8vvv2jS/Bf42H08TIUBtIjFwKpU/xbOdKIzwdHnUuBd+njM4uDa1dVtcmqnJL LdH+hkr5TfCjZM6VpuBt32byHi+v5Tj+ayjndDHwpQsXty/k+1/fuhllkQEX2RcddyzL L+Xck31t07i9iZbPrict4sFjCttqScR/pFdY7H2LVnhdzrGmyEDVU1r1Ivde6HmQH3cR pRnQzIIG4o6mGfOMtNOXzsqsK+ZJ8sePamegljMUEOL7+eCLGKcOP5pytf+tsTpPJjtJ lUs1nyaOwHcbtHViJ7KBmIAnOzylYvvfh9re+CUKT3VfJzRNSPQzor5SdB0GeQxbPy39 MkPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=z6j2M3ywUHsS1+ykQ/OfNhi067lR0Bt99BN92Wk+zcw=; b=b2KPVQ988gYydK6A5c6YsMtDSMalkXB3xZVTWJQ/HP7guBvwQJLZJjfr0zv0vvfzfX 3+B4AkqEH/3zmE5vtSn71dmQfNBip7LqLKmUmEars+lqRTExa4BqIFQY54jhbBzEE3fT YT8+7HEGyVpQdRolf4weEOwZQZd7T12CChEQmxNXK+XN0uZaDQHHZb19N35QjzkcsJWr NGEXyG6w5cxVo4DHl9xhayRH9tJXVTuJuxMtR9LR4Dxni4qXpf1lHjaeNcq0ZWRVhEcM rf1doKkadrhPRDu+glo2ttpudWn5EU9TWaJrc1Nk7vV8gJQfz1I4jLPjNFAWY7FT9I6K V4Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=H4tQqYyG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n8-20020a63a508000000b0044d72a10ab0si15609628pgf.342.2022.10.17.22.00.19; Mon, 17 Oct 2022 22:00:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=H4tQqYyG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230268AbiJRE4x (ORCPT + 99 others); Tue, 18 Oct 2022 00:56:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbiJRE4H (ORCPT ); Tue, 18 Oct 2022 00:56:07 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6493A2AAE for ; Mon, 17 Oct 2022 21:56:01 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id h185so12311080pgc.10 for ; Mon, 17 Oct 2022 21:56:01 -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 :message-id:reply-to; bh=z6j2M3ywUHsS1+ykQ/OfNhi067lR0Bt99BN92Wk+zcw=; b=H4tQqYyGb10hilriYTv+DvIcK69suR/MknRv/uI/c7Sq8IVi/fkI5CgIYlaPZTn3R3 fcnApKLzJ2JC3QxaMOGgeKe9UHO+kkbWQ0logwCwtTSA1l45M7ttQfjxjlmDarqRhC/q +YH2hyuuTFmys4kuUH7wG9CPoEgVf6/DURZSo= 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:message-id:reply-to; bh=z6j2M3ywUHsS1+ykQ/OfNhi067lR0Bt99BN92Wk+zcw=; b=s5uiRztdyFh6JDyd40dx7FiK2xryZfvNxNa5yLUMZy2UuqQfMcPYn2C1pkgcv5j+K5 fcVfStp5WpoID7ok/iCugO47uLMnkvaG8rVUqWUao66aqgzNIvjLivH2K75g/jDw0DW8 EumFSBxUYmWPo1rqCm54PdTnGNJWJp+pujPYjnSI6xf5u8akFwbqTJAWXMoQhOWN9o3r m9NaJeKtBZ1vTwMOOUtwMsdm/rx/RstnOGRWsBq9+YgqLOK+LGBuS3qunx0BP8N6iYWr W1qB6iZvyfO/aQWegx3BpKayaGtbsKL5DxFuLShdZ1bWOQ4KZz1tFDBxyM9JQRRusFHx lLJA== X-Gm-Message-State: ACrzQf0dkoA2ONEkZM4oGGas5IrMsTk0s6TUNpyu/xS9XRUYtM/bQG9H 77Dm6rjB8IJLo84FY4D7+QSK5Q== X-Received: by 2002:a65:6849:0:b0:461:8779:2452 with SMTP id q9-20020a656849000000b0046187792452mr1089661pgt.383.1666068961162; Mon, 17 Oct 2022 21:56:01 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:17a9:73b0:c262:eccd]) by smtp.gmail.com with ESMTPSA id p4-20020a170902e74400b0017b69f99321sm7549220plf.219.2022.10.17.21.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 21:56:00 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv4 8/9] zram: Clarify writeback_store() comment Date: Tue, 18 Oct 2022 13:55:32 +0900 Message-Id: <20221018045533.2396670-9-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018045533.2396670-1-senozhatsky@chromium.org> References: <20221018045533.2396670-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747000212186742491?= X-GMAIL-MSGID: =?utf-8?q?1747000212186742491?= Re-phrase writeback BIO error comment. Reported-by: Andrew Morton Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 5d760467e0bc..6b56f6f2ce82 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -758,8 +758,12 @@ static ssize_t writeback_store(struct device *dev, zram_clear_flag(zram, index, ZRAM_IDLE); zram_slot_unlock(zram, index); /* - * Return last IO error unless every IO were - * not suceeded. + * BIO errors are not fatal, we continue and simply + * attempt to writeback the remaining objects (pages). + * At the same time we need to signal user-space that + * some writes (at least one, but also could be all of + * them) were not successful and we do so by returning + * the most recent BIO error. */ ret = err; continue; From patchwork Tue Oct 18 04:55:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 3945 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1778456wrs; Mon, 17 Oct 2022 22:00:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6QFmKDbU34y+FItlGWesFFemitabvgl3PTxAM8J9YLaPNtP1Ouyk0vGy3uF669eCk8vuqs X-Received: by 2002:a17:907:7b94:b0:731:1b11:c241 with SMTP id ne20-20020a1709077b9400b007311b11c241mr896210ejc.676.1666069248507; Mon, 17 Oct 2022 22:00:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666069248; cv=none; d=google.com; s=arc-20160816; b=HVkSFDTWtdnALL/0RCVZIyx/0Krna2bJDI4msaavDfZ6SZLOhiyy3hX6fgIP3V10v1 Rmt2Dtf8JEXfF2hYIxjVUwwx0FKHlnsb/QgZg1qq2unaS+n78wLOQy0EutJwqKm1j+Rz x03z6GfZxWrWqlB+v0mlvgcpUB8Jlb8/PJolT1gKwGEY20+aizOFZqavk8EqStWO5gGw RrxP1fXqOKZD5aiiLZCEE95k6RDbrnG78Rbn7fUHnwWiEP7q57+piiAaLb2V3gEmGMPJ mis6XQLpwkHbz2EfwC0zzfguYuQ73rxBz1yB6dbebtKf5LEsCSXI/pkcSRqLH4j8YL3s 1uNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5M5hW54OP3FcHBFbXUW0BvyRXPUP5sF32vTgPzuINJw=; b=Ex/rLSojJDToMnBW4QQnPEQjsdCml1U1cDLr/K8s1KQeniH3BD4cXQ/mVxfK4wkRCa oU1vt9oAX2EBHWAIl7I13SJ3CCsRsVYfHR2oRW3C7D+TaOiN7t9xzyCIKUmNeNw24k6M tBN/H0+NP4yzUGBVKFohpvNgQgtKCIXaWUjlA3b9CjcRBEzwZBQae5NAduZsAuBLYB18 uNWjzIFMQwdacffK9+h0wdR0FQQNY5P6w4PLv9d41sGkwawHFb8kIOGXsU4FyvQj7oOb qFrXi4/Un1nDvNDDc6SGVt6M6UEx0DhxrT6IVCCWbiLLN83/z2Iq/gV50TmYu3GsRLQw AxdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OpPjLqj+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs42-20020a1709072d2a00b0078dad42f75dsi11670066ejc.475.2022.10.17.22.00.23; Mon, 17 Oct 2022 22:00:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OpPjLqj+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229607AbiJRE5N (ORCPT + 99 others); Tue, 18 Oct 2022 00:57:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230162AbiJRE4c (ORCPT ); Tue, 18 Oct 2022 00:56:32 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E3DDA344A for ; Mon, 17 Oct 2022 21:56:06 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id c24so12738440pls.9 for ; Mon, 17 Oct 2022 21:56:05 -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 :message-id:reply-to; bh=5M5hW54OP3FcHBFbXUW0BvyRXPUP5sF32vTgPzuINJw=; b=OpPjLqj+j0EF5h4VtuAZp6f+eGdl/5fSvLw56hi7HO01ZV6gqL3LhfNt4tuqvbFZWL B9Zo2V1IhStyc8xGnpweJqdk5JOPtoGtNyRZvNKx+nA/GCWy7rPkstTlJfT4GGbEyOzL khin31KlV69YEer+c0KA1hT4XmJY8qBrHD7bg= 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:message-id:reply-to; bh=5M5hW54OP3FcHBFbXUW0BvyRXPUP5sF32vTgPzuINJw=; b=mSJf3fII1EzdyIqhmJCm1b5h3fZo7jkWmbPJjnQrG2wxPRQyXZBafUEUVD5/Lp9U6f Zp4T5u+7obVYrace19qMkzd6KQgYu4CaBZIneVEUaHXEbeB/5uyuCx8/GQN5vMHFwUNJ MDAgFnrn6M4O8HlN9k+1/Y2FLEzvTHdyMXvwl4E+tcjVbhxGOg2Yxx74ALst+KiBIao7 +6cNMI67zgzJoZFSsHqKMGNF9V/j9IVMdGZDk6fbFgBVtrR4ODg01SH6JFo/mSknDvNw GWek+I6KzwNl9wNKcd7gf1OqRwBOEd4ICm4PByUwPe0XvMmqa5KPBtdnwtqU8NOTcxep 1Zfg== X-Gm-Message-State: ACrzQf2n3RTG1f2NAhK10wQsVD1CrIl0/4MBosdvrhdUmFP0hCL7e9gO EWy/xNl8WsYNjGAmxSg896jCpw== X-Received: by 2002:a17:902:e5c3:b0:185:53ee:60e3 with SMTP id u3-20020a170902e5c300b0018553ee60e3mr1397002plf.71.1666068964804; Mon, 17 Oct 2022 21:56:04 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:17a9:73b0:c262:eccd]) by smtp.gmail.com with ESMTPSA id p4-20020a170902e74400b0017b69f99321sm7549220plf.219.2022.10.17.21.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 21:56:04 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv4 9/9] zram: Use IS_ERR_VALUE() to check for zs_malloc() errors Date: Tue, 18 Oct 2022 13:55:33 +0900 Message-Id: <20221018045533.2396670-10-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018045533.2396670-1-senozhatsky@chromium.org> References: <20221018045533.2396670-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747000228262054769?= X-GMAIL-MSGID: =?utf-8?q?1747000228262054769?= Avoid type casts that are needed for IS_ERR() and use IS_ERR_VALUE() instead. Suggested-by: Andrew Morton Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 6b56f6f2ce82..422e3cfd2ddc 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1506,19 +1506,19 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, * if we have a 'non-null' handle here then we are coming * from the slow path and handle has already been allocated. */ - if (IS_ERR((void *)handle)) + if (IS_ERR_VALUE(handle)) handle = zs_malloc(zram->mem_pool, comp_len, __GFP_KSWAPD_RECLAIM | __GFP_NOWARN | __GFP_HIGHMEM | __GFP_MOVABLE); - if (IS_ERR((void *)handle)) { + if (IS_ERR_VALUE(handle)) { 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 | __GFP_MOVABLE); - if (IS_ERR((void *)handle)) + if (IS_ERR_VALUE(handle)) return PTR_ERR((void *)handle); if (comp_len != PAGE_SIZE) @@ -1685,7 +1685,7 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, __GFP_NOWARN | __GFP_HIGHMEM | __GFP_MOVABLE); - if (IS_ERR((void *)handle_next)) { + if (IS_ERR_VALUE(handle_next)) { zcomp_stream_put(zram->comps[ZRAM_SECONDARY_ZCOMP]); return PTR_ERR((void *)handle_next); }