From patchwork Mon Nov 21 19:00:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Romanov X-Patchwork-Id: 23995 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1774835wrr; Mon, 21 Nov 2022 11:05:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf5hK4Gww+yqCHZ16S848rckbTUqe0lwWpvnM0QFsbtQuSqyDnk+/6/SACPJ5GBLty+MK9Ss X-Received: by 2002:a05:6402:14:b0:461:deed:6d20 with SMTP id d20-20020a056402001400b00461deed6d20mr18313375edu.55.1669057534953; Mon, 21 Nov 2022 11:05:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669057534; cv=none; d=google.com; s=arc-20160816; b=l4CoFUFdExb2TARZKxQnPAymKIOySWZXsg+yE5KMyeVpOpPxfaBlhkIdEtIhEZBkld Bc/OgpYbIRxDvNH71/Pu+jt1cmXR1OMA6oMv3Cm93GLlZdDCS5NHB5wotUnqlc4djtJt HZ86YhjgavAuea8CDvityqP5ORzbLsHoa3OPi6XB/B3mzlLbLL/ZHXNlCB6N2IV+x9e9 nRe4P8ePTNWkY/9hOoDXGzFzbgasN9TyMEROzpLeimAzjLczd3oFbJnQgVMoG33cLv5m enklmxlsMtGHt8AJX2doFqbzrUYcDT7tmziGugUnOMBQLuHdThRr2dMDWW3ASmKj1sAO XAPw== 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=kumGGf0n9GsE8elc+YiswTIrEmu/kdjc+b63/oj/1bM=; b=cdMPguAXxoI0aIKT4IpzB+KsS2rl/Xreui58xFIBM7GdmV7agFUz/UInSwSVBzY7PL UMX8wqrzRooCs870N/dyF6vaanI+4u8cRTaI+Sle/8N08Bje1XHKMU2X3S935BkAhRLg wEJkPFnzxo9AWNFZx7inv8cCMmxuBSrzuIYiQiDFTJfrqokscerrTAd/kuLX7GkTyX9t yJyn5slaX/2XgFpUXLgr2ck82wX4fZrIQVeXXFnU5R6jKK3RpCjWdm4h7ka+W3fkAhul 8vG5J23UVxQXAVmccv4MNCLreGXdIXuvtAtNkU78uWjBIn7FzyEhNQKFtV3WeryASAl9 bAvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=NmwRG5ye; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id la26-20020a170907781a00b0078d3ba4d567si7548978ejc.422.2022.11.21.11.05.00; Mon, 21 Nov 2022 11:05:34 -0800 (PST) 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=@sberdevices.ru header.s=mail header.b=NmwRG5ye; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230475AbiKUTBU (ORCPT + 99 others); Mon, 21 Nov 2022 14:01:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230419AbiKUTA6 (ORCPT ); Mon, 21 Nov 2022 14:00:58 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7830CFEAD for ; Mon, 21 Nov 2022 11:00:54 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id CEA685FD0A; Mon, 21 Nov 2022 22:00:51 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1669057251; bh=kumGGf0n9GsE8elc+YiswTIrEmu/kdjc+b63/oj/1bM=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=NmwRG5yeHoXLB+0ePEEpvQuFTvnvB8StL9Sbv0T9oaC6Nq3FMdSW1DrwmoNLO08a5 OrXEpCTqlMyJBaFdUxvnAQsigL6Zh41v1w1+AJYxrLNo5Yi5aE/4bVOjuFZ41QHDdY 2aAqD6gBDGrW0RzoCyHItJ5OIIufnNdd9omWo1oG85t+xCAUsfhFbzj2Qq8TXpc3o+ mFNQTjtA+lOidObN8lkj0Phyz0+sxZJpXc013CQknoSgMJcXpxGIX5jyxqKuhtVpIN 6ww9dPQyDjnaA6Or1WFWF4AWqAH1mfvfRz5xyjTPKHueqagLa9f88sCfFfQ50nyeTF 3ullvV+1ZafsA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Mon, 21 Nov 2022 22:00:51 +0300 (MSK) From: Alexey Romanov To: , , , CC: , , , , Alexey Romanov Subject: [RFC PATCH v1 1/4] zram: introduce merge identical pages mechanism Date: Mon, 21 Nov 2022 22:00:17 +0300 Message-ID: <20221121190020.66548-2-avromanov@sberdevices.ru> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20221121190020.66548-1-avromanov@sberdevices.ru> References: <20221121190020.66548-1-avromanov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2022/11/21 16:41:00 #20594217 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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?1750133673544177576?= X-GMAIL-MSGID: =?utf-8?q?1750133673544177576?= zram maps each page (struct page) to a zsmalloc object that contains a compressed buffer of that page's data. This fact generates data redundancy: for example, two identical pages will be store in compressed form in zsmalloc allocator twice. This patch adds a mechanism to scan zram_table_entry array and frees all identical objects in zsmalloc allocator, leaving only one. All zram_table_entry elements which reference this freed objects now refer to the same, not freed, object. To implement this mechanism, we sequentially scan the zram_table_entry array, counting the hash from the contents of the compressed pages (zsmalloc objects) and enter the index of the object into the hash table (hlist_head). If the hash matches, we remove the identical zsmalloc (zs_free) objects and update the link rbtree. Also, we can't just call zs_free() function during zram_free_page(). Before calling this function we have to make sure that no one else refers to this zsmalloc object. To implement the mechanism for merging identical compressed pages (zsmalloc objects), a rbtree is needed. The tree node key is a reference to the zsmalloc object (handle), and the value is the number of references to this object (atomic counter). This is necessary for data consistency so that we do not zs_free the object referenced by any element of the zram_table_entry array. Signed-off-by: Alexey Romanov --- drivers/block/zram/zram_drv.c | 278 +++++++++++++++++++++++++++++++++- drivers/block/zram/zram_drv.h | 6 + 2 files changed, 283 insertions(+), 1 deletion(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index e290d6d97047..716c2f72805e 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -33,12 +33,15 @@ #include #include #include +#include +#include #include "zram_drv.h" static DEFINE_IDR(zram_index_idr); /* idr index must be protected */ static DEFINE_MUTEX(zram_index_mutex); +static DEFINE_MUTEX(zram_rbtree_mutex); static int zram_major; static const char *default_compressor = CONFIG_ZRAM_DEF_COMP; @@ -57,6 +60,16 @@ static void zram_free_page(struct zram *zram, size_t index); static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, u32 index, int offset, struct bio *bio); +struct zram_rbtree_node { + struct rb_node node; + unsigned long key; + unsigned long cnt; +}; + +struct zram_hash_node { + unsigned long index; + struct hlist_node next; +}; static int zram_slot_trylock(struct zram *zram, u32 index) { @@ -1283,6 +1296,247 @@ static DEVICE_ATTR_RO(bd_stat); #endif static DEVICE_ATTR_RO(debug_stat); +static bool zram_rbtree_insert(struct rb_root *root, struct zram_rbtree_node *data) +{ + struct rb_node **new = &(root->rb_node), *parent = NULL; + struct zram_rbtree_node *this; + + while (*new) { + this = rb_entry(*new, struct zram_rbtree_node, node); + parent = *new; + if (data->key < this->key) + new = &((*new)->rb_left); + else if (data->key > this->key) + new = &((*new)->rb_right); + else + return false; + } + + rb_link_node(&data->node, parent, new); + rb_insert_color(&data->node, root); + return true; +} + +static struct zram_rbtree_node *zram_rbtree_search(struct rb_root *root, + unsigned long key) +{ + struct rb_node *node = root->rb_node; + struct zram_rbtree_node *data; + + while (node) { + data = rb_entry(node, struct zram_rbtree_node, node); + if (key < data->key) + node = node->rb_left; + else if (key > data->key) + node = node->rb_right; + else + return data; + } + + return NULL; +} + +static unsigned long zram_calc_hash(void *src, size_t len) +{ + return xxhash(src, len, 0); +} + +static int zram_cmp_obj_and_merge(struct zram *zram, struct hlist_head *htable, + size_t htable_size, size_t index) +{ + struct zram_rbtree_node *rb_node; + struct zram_hash_node *node; + unsigned long handle, cur_handle; + size_t obj_size; + char *src, *buf; + unsigned long hash; + int ret = 0; + + handle = zram_get_handle(zram, index); + if (!handle) + return ret; + + obj_size = zram_get_obj_size(zram, index); + buf = kmalloc(obj_size, GFP_KERNEL); + if (!buf) { + pr_err("Failed to allocate zs_map_object buffer\n"); + return -ENOMEM; + } + + src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); + memcpy(buf, src, obj_size); + zs_unmap_object(zram->mem_pool, handle); + hash = zram_calc_hash(buf, obj_size); + + mutex_lock(&zram_rbtree_mutex); + hlist_for_each_entry(node, &htable[hash % htable_size], next) { + int cmp; + + zram_slot_lock(zram, node->index); + + /* + * Page may change as the hash table is being formed, + * so the checks below are necessary. + */ + cur_handle = zram_get_handle(zram, node->index); + if (handle == cur_handle || + obj_size != zram_get_obj_size(zram, node->index)) { + zram_slot_unlock(zram, node->index); + continue; + } + + src = zs_map_object(zram->mem_pool, cur_handle, ZS_MM_RO); + cmp = memcmp(buf, src, obj_size); + zs_unmap_object(zram->mem_pool, cur_handle); + + if (!cmp) { + rb_node = zram_rbtree_search(&zram->sph_rbtree, handle); + + /* + * This check is necessary in order not to zs_free an object + * that someone already refers to. This situation is possible + * when with repeated calls to zram_do_scan(). For example: + * + * [slot0] [slot1] [slot2] [slot3] [slot4] + * [obj0] [obj1] [obj2] [obj3] [obj4] + * + * Let's imagine that obj2 and obj3 are equal, and we called + * zram_do_scan() function: + * + * [slot0] [slot1] [slot2] [slot3] [slot4] + * [obj0] [obj1] [obj2] [obj2] [obj4] + * + * Now, slot2 and slot3 refers to obj2 zsmalloc object. + * Time passed, now slot0 refres to obj0_n, which is equal + * to obj2: + * + * [slot0] [slot1] [slot2] [slot3] [slot4] + * [obj0_n] [obj1] [obj2] [obj2] [obj4] + * + * Now we call zram_do_scan() function again. We get to slot2, + * and we understand that obj2 and obj0_n hashes are the same. We + * try to zs_free(obj2), but slot3 also already refers to it. + * + * This is not correct! + */ + if (unlikely(rb_node)) + if (rb_node->cnt > 1) { + zram_slot_unlock(zram, node->index); + continue; + } + + zram_set_handle(zram, index, cur_handle); + zs_free(zram->mem_pool, handle); + + rb_node = zram_rbtree_search(&zram->sph_rbtree, cur_handle); + + if (!rb_node) { + rb_node = kzalloc(sizeof(struct zram_rbtree_node), + GFP_KERNEL); + if (!rb_node) { + pr_err("Failed to allocate rb_node\n"); + ret = -ENOMEM; + zram_slot_unlock(zram, node->index); + mutex_unlock(&zram_rbtree_mutex); + goto merged_or_err; + } + + rb_node->key = cur_handle; + /* Two slots refers to an zsmalloc object with cur_handle key */ + rb_node->cnt = 2; + zram_rbtree_insert(&zram->sph_rbtree, rb_node); + } else { + rb_node->cnt++; + } + + atomic64_sub(obj_size, &zram->stats.compr_data_size); + zram_set_flag(zram, index, ZRAM_MERGED); + zram_set_flag(zram, node->index, ZRAM_MERGED); + + zram_slot_unlock(zram, node->index); + mutex_unlock(&zram_rbtree_mutex); + goto merged_or_err; + } + + zram_slot_unlock(zram, node->index); + } + + mutex_unlock(&zram_rbtree_mutex); + + node = kmalloc(sizeof(struct zram_hash_node), GFP_KERNEL); + if (!node) { + ret = -ENOMEM; + goto merged_or_err; + } + + node->index = index; + hlist_add_head(&node->next, &htable[hash % htable_size]); + +merged_or_err: + kfree(buf); + return ret; +} + +static void zram_free_htable_entries(struct hlist_head *htable, + size_t htable_size) +{ + struct hlist_node *n; + struct zram_hash_node *node; + + hlist_for_each_entry_safe(node, n, htable, next) { + hlist_del(&node->next); + kfree(node); + } +} + +static int zram_do_scan(struct zram *zram) +{ + size_t num_pages = zram->disksize >> PAGE_SHIFT; + size_t htable_size = num_pages; + size_t index; + struct hlist_head *htable; + int i, ret = 0; + + htable = vzalloc(htable_size * sizeof(struct hlist_head)); + if (!htable) { + pr_err("Failed to allocate hash table\n"); + return -ENOMEM; + } + + for (i = 0; i < htable_size; i++) + INIT_HLIST_HEAD(&htable[i]); + + for (index = 0; index < num_pages; index++) { + zram_slot_lock(zram, index); + + if (!zram_allocated(zram, index)) { + zram_slot_unlock(zram, index); + continue; + } + + if (zram_test_flag(zram, index, ZRAM_UNDER_WB) || + zram_test_flag(zram, index, ZRAM_WB) || + zram_test_flag(zram, index, ZRAM_SAME)) { + zram_slot_unlock(zram, index); + continue; + } + + /* Ignore pages that have been recompressed */ + if (zram_get_priority(zram, index) != 0) + continue; + + ret = zram_cmp_obj_and_merge(zram, htable, htable_size, index); + zram_slot_unlock(zram, index); + if (ret != 0) + goto out; + } + +out: + zram_free_htable_entries(htable, htable_size); + vfree(htable); + return ret; +} + static void zram_meta_free(struct zram *zram, u64 disksize) { size_t num_pages = disksize >> PAGE_SHIFT; @@ -1324,6 +1578,7 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize) static void zram_free_page(struct zram *zram, size_t index) { unsigned long handle; + struct zram_rbtree_node *node; #ifdef CONFIG_ZRAM_MEMORY_TRACKING zram->table[index].ac_time = 0; @@ -1361,7 +1616,26 @@ static void zram_free_page(struct zram *zram, size_t index) if (!handle) return; - zs_free(zram->mem_pool, handle); + if (zram_test_flag(zram, index, ZRAM_MERGED)) { + zram_clear_flag(zram, index, ZRAM_MERGED); + mutex_lock(&zram_rbtree_mutex); + + node = zram_rbtree_search(&zram->sph_rbtree, handle); + BUG_ON(!node); + + node->cnt--; + if (node->cnt == 0) { + rb_erase(&node->node, &zram->sph_rbtree); + mutex_unlock(&zram_rbtree_mutex); + + zs_free(zram->mem_pool, handle); + kfree(node); + } else { + mutex_unlock(&zram_rbtree_mutex); + } + } else { + zs_free(zram->mem_pool, handle); + } atomic64_sub(zram_get_obj_size(zram, index), &zram->stats.compr_data_size); @@ -2421,6 +2695,8 @@ static int zram_add(void) comp_algorithm_set(zram, ZRAM_PRIMARY_COMP, default_compressor); + zram->sph_rbtree = RB_ROOT; + zram_debugfs_register(zram); pr_info("Added device: %s\n", zram->disk->disk_name); return device_id; diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index c5254626f051..4a7151c94523 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -56,6 +56,7 @@ enum zram_pageflags { ZRAM_COMP_PRIORITY_BIT1, /* First bit of comp priority index */ ZRAM_COMP_PRIORITY_BIT2, /* Second bit of comp priority index */ + ZRAM_MERGED, /* page was merged */ __NR_ZRAM_PAGEFLAGS, }; @@ -140,5 +141,10 @@ struct zram { #ifdef CONFIG_ZRAM_MEMORY_TRACKING struct dentry *debugfs_dir; #endif + /* + * This is same pages handle's rb tree, where the key is a handle + * to same pages and the value is a link counter + */ + struct rb_root sph_rbtree; }; #endif From patchwork Mon Nov 21 19:00:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Romanov X-Patchwork-Id: 23994 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1773765wrr; Mon, 21 Nov 2022 11:03:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ijT1xni7AOVVUgeLsYGdumCcWxB5lTC3lEjWWQw/z641ZMQ85/w4OQX59l0ptoRkpwACa X-Received: by 2002:a17:902:ca04:b0:188:f993:724a with SMTP id w4-20020a170902ca0400b00188f993724amr1830243pld.77.1669057422941; Mon, 21 Nov 2022 11:03:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669057422; cv=none; d=google.com; s=arc-20160816; b=k2p4YTjGX6XgsQF0c7stWbl+1mwDSBVdv9wZofOtdo3GiYNzj0FIPp2u18qNrHLkHq AEdbf+31kTjQokBw61VwXnbZB/0rpz8JDd/ZTsNkEmgqU/QG6GsGH0w8yWKwvNBn49Jb 9ctmajw4PcWuQLXQ5ZC88NL5Jft+5fHh/uLkpy36mKSefWcsGaCPAK9fBfXPMXoCRXAR C9VUiS3XlDM5N8BjKveAHoG48L7YWwtOqawQs533SNy14E0FUdlTX+TCtjm4gOnCPSRC gqNiPrHKURwsPh6AdlX0e6pn6uDqqk2p/MKfsAyPmzSEr6mMuLVtGzHXAffNCkAFiY86 uSyQ== 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=tnNz8FxhOymc0atH2o9EbaV/8E1YXEIwJHa+DOBrsk0=; b=NwPwHX8J7MyR1NBSaEndF4fYNosWntbZBxRa6KDpdcDzTtMtTcCbQo2h9fmMLdQcME eBG3PVhG+hg3Dg44VEM5BIl552o+78MzuKg+OnhUaW6o1S+RXB4PW6Y+2qFNnUxY90I7 Si23cJn2SrxCzn06w9VCL1DSFoZns/UQzO1u+gQX1RZ7NW+MWPdQpSPyALs8EmE2eSBZ 3vy0rqop/6FFEqtu+KGjkB9ki5GHqRmdwvmOTsJqoYyXRXyqy+NBkgc6kidCq4yEN2GQ DrU2AoylLzgds3IZwa19kOMi9ay07Jbx2K0p//N/yoc3yhk1i0gFXgHgtV5/SkwPjc6T WVGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=I12Ib1ec; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m16-20020a637110000000b0047763094aebsi4694788pgc.794.2022.11.21.11.03.25; Mon, 21 Nov 2022 11:03:42 -0800 (PST) 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=@sberdevices.ru header.s=mail header.b=I12Ib1ec; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230428AbiKUTBD (ORCPT + 99 others); Mon, 21 Nov 2022 14:01:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229836AbiKUTA6 (ORCPT ); Mon, 21 Nov 2022 14:00:58 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7BF9D0DE6 for ; Mon, 21 Nov 2022 11:00:54 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 5AAED5FD0C; Mon, 21 Nov 2022 22:00:52 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1669057252; bh=tnNz8FxhOymc0atH2o9EbaV/8E1YXEIwJHa+DOBrsk0=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=I12Ib1ec30kbpfYQQCRwwiW7QAiyVT8QqxkF4X20EtrTbol1AsCOdKuU7ZBVrx+zb 5LZJ10WNyFrLMOd+n+hzHmJrI2vxE5hjNubdX4Wb+78PKVvrEKc3uFBHhvGy7pGnUF Hvvt9a5tfWT0AxzFPYO6sqW5V3NUk83rVdnzCRsYVRqwrF3a7nK74UyMehvlRtBWlE OqYSX8Q4DrFyRFpGnWqxNLQgkfOLfMqoyYHM8ww1MCs39gbhwKA7hdFjHPio3ri86M eJPBa4VdeVZKFxh/M+/kDExUQ6lnKQA3YS5kIqCTFh+RyrIu7Z8JpMC8lHXCbvXYNU DFObnIRd8bBQQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Mon, 21 Nov 2022 22:00:52 +0300 (MSK) From: Alexey Romanov To: , , , CC: , , , , Alexey Romanov Subject: [RFC PATCH v1 2/4] zram: add merge sysfs knob Date: Mon, 21 Nov 2022 22:00:18 +0300 Message-ID: <20221121190020.66548-3-avromanov@sberdevices.ru> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20221121190020.66548-1-avromanov@sberdevices.ru> References: <20221121190020.66548-1-avromanov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2022/11/21 16:41:00 #20594217 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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?1750133556727381538?= X-GMAIL-MSGID: =?utf-8?q?1750133556727381538?= Allow zram to merge identical pages into signle one: echo 1 > /sys/block/zramX/merge Signed-off-by: Alexey Romanov --- drivers/block/zram/zram_drv.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 716c2f72805e..1dae3564cabd 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1197,6 +1197,30 @@ static ssize_t compact_store(struct device *dev, return len; } +static int zram_do_scan(struct zram *zram); + +static ssize_t merge_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t len) +{ + struct zram *zram = dev_to_zram(dev); + int ret; + + down_read(&zram->init_lock); + if (!init_done(zram)) { + up_read(&zram->init_lock); + return -EINVAL; + } + + ret = zram_do_scan(zram); + if (ret != 0) { + up_read(&zram->init_lock); + return -ENOMEM; + } + + up_read(&zram->init_lock); + return len; +} + static ssize_t io_stat_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -2569,6 +2593,7 @@ static const struct block_device_operations zram_devops = { }; static DEVICE_ATTR_WO(compact); +static DEVICE_ATTR_WO(merge); static DEVICE_ATTR_RW(disksize); static DEVICE_ATTR_RO(initstate); static DEVICE_ATTR_WO(reset); @@ -2609,6 +2634,7 @@ static struct attribute *zram_disk_attrs[] = { #ifdef CONFIG_ZRAM_WRITEBACK &dev_attr_bd_stat.attr, #endif + &dev_attr_merge.attr, &dev_attr_debug_stat.attr, #ifdef CONFIG_ZRAM_MULTI_COMP &dev_attr_recomp_algorithm.attr, From patchwork Mon Nov 21 19:00:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Romanov X-Patchwork-Id: 23996 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1775143wrr; Mon, 21 Nov 2022 11:06:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf46Y3O+crzAytJthvBL3bxiNezVWX+v0wPmd5BGZPgI7etyZxWrDUJoLHOCBnSQkS5gm6V/ X-Received: by 2002:a63:fc66:0:b0:477:49fe:2002 with SMTP id r38-20020a63fc66000000b0047749fe2002mr3492500pgk.512.1669057565929; Mon, 21 Nov 2022 11:06:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669057565; cv=none; d=google.com; s=arc-20160816; b=Ht1AjiXn7EED7DemBDsVfCtjc89NSUP+HOEGRKZ45DJ3z07FpIMUCPNiu8A/inO2yr OAVb4FbiCrjUKFhthQVIeIfMR234LAffpY92Dl6eAvq3OxG8Ng5rv5WkyY/+kkZSTsms d7K+yCymuC5L33z+GDYAsQCAZtB5jANGXHfPSmEspTs9Y0PoL4hhtFwDi5CiAdaFU2H+ fnQC4+Ikt2h/US7b/LvCwL0JhcPuPgi5Hs7F1F3ZKoehgJV0QMNFSac95tkhfDDJay6+ MxjUGmOzSG3BBhClztqs7ohkQbGZiL/PFSuSS3EdrckdzIqDxa2sdzxiTdndQeRkVlTj J2GA== 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=Jfq1zJpfwKhtf8+eQ9bbzdVEJsOxLM5Fr/rR0X8sckA=; b=HxcEqO1hTO7wL2hJnJ845KWjL+Nz1aOC172lcBoplxEdkzs6nqWdhre9BUzaEn5vEN ZgP+wP0W0yozy0tNzhqR8II4PpyzB1mjpF412HGOHHAMc56kl0pV0CTtxPFunkRnvptx gjTJFFMKlI5RXmGKnoqCRh+jVo3/sDUxLDhvJEdsmaS14xAeBwPG9QnUJ6lGzvgulAUs R6cZxgQcUcDv9fgLzAZ1VSe5lkGfTsfc2A5+JKUYGGExpBrk3FtyBtdnPBFgfk1X052V FJYTuaTuFRttMAQYK57IVm6dmf7+t6yfGWtiCuv7XAyIFGomnCHWXgljZhBuqTofFWxb 0N+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=OGtIXGZ7; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pg16-20020a17090b1e1000b002009ed52bf6si12967627pjb.19.2022.11.21.11.05.42; Mon, 21 Nov 2022 11:06:05 -0800 (PST) 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=@sberdevices.ru header.s=mail header.b=OGtIXGZ7; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229814AbiKUTBJ (ORCPT + 99 others); Mon, 21 Nov 2022 14:01:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230416AbiKUTA6 (ORCPT ); Mon, 21 Nov 2022 14:00:58 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12D07D14DE for ; Mon, 21 Nov 2022 11:00:55 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 685F35FD0B; Mon, 21 Nov 2022 22:00:53 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1669057253; bh=Jfq1zJpfwKhtf8+eQ9bbzdVEJsOxLM5Fr/rR0X8sckA=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=OGtIXGZ7jKOqoSNcA7M17LqsyQ/Qkt1PRc57ObvW2g1SEX9WCYomuEuOup16DXXUT JmcwD8OAYJpi4n6EgozgbVtASIUbgVi9D3+FJW2ei+s+17iPtElguhAaeClwCPXRHh LR57Q/ESeRfkkLsxvsHvbnMtCRMmzIGNf3Lnqzz+LUGqf+mgCJM57jfXyF5JEtbtzZ xjtRTUAg84mK+0fjqblfT1rG/eZqpEiXImtn2DIifMxNzApxvU+nUy/bnhbuCWknID glz0VTcrFOFlJHVXehQ2KMcgfWsIij3rf6iBQYcveVUosoZxz8W7dvhWzebT+jOjLm JmidHT7sC2Rvg== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Mon, 21 Nov 2022 22:00:53 +0300 (MSK) From: Alexey Romanov To: , , , CC: , , , , Alexey Romanov Subject: [RFC PATCH v1 3/4] zram: add pages_merged counter to mm_stat Date: Mon, 21 Nov 2022 22:00:19 +0300 Message-ID: <20221121190020.66548-4-avromanov@sberdevices.ru> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20221121190020.66548-1-avromanov@sberdevices.ru> References: <20221121190020.66548-1-avromanov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2022/11/21 16:41:00 #20594217 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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?1750133706172332753?= X-GMAIL-MSGID: =?utf-8?q?1750133706172332753?= This counter shows how many identical compressed pages have been processed by zram so far. Signed-off-by: Alexey Romanov --- Documentation/admin-guide/blockdev/zram.rst | 2 ++ drivers/block/zram/zram_drv.c | 8 ++++++-- drivers/block/zram/zram_drv.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index e4551579cb12..a1dd202efca1 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -209,6 +209,7 @@ compact WO trigger memory compaction debug_stat RO this file is used for zram debugging purposes backing_dev RW set up backend storage for zram to write out idle WO mark allocated slot as idle +merge WO trigger merge identical pages ====================== ====== =============================================== @@ -267,6 +268,7 @@ line of text and contains the following stats separated by whitespace: pages_compacted the number of pages freed during compaction huge_pages the number of incompressible pages huge_pages_since the number of incompressible pages since zram set up + pages_merged the number of identical pages merged into single one ================ ============================================================= File /sys/block/zram/bd_stat diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 1dae3564cabd..7a267b37e5db 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1260,7 +1260,7 @@ static ssize_t mm_stat_show(struct device *dev, max_used = atomic_long_read(&zram->stats.max_used_pages); ret = scnprintf(buf, PAGE_SIZE, - "%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu\n", + "%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu %8llu\n", orig_size << PAGE_SHIFT, (u64)atomic64_read(&zram->stats.compr_data_size), mem_used << PAGE_SHIFT, @@ -1269,7 +1269,8 @@ static ssize_t mm_stat_show(struct device *dev, (u64)atomic64_read(&zram->stats.same_pages), atomic_long_read(&pool_stats.pages_compacted), (u64)atomic64_read(&zram->stats.huge_pages), - (u64)atomic64_read(&zram->stats.huge_pages_since)); + (u64)atomic64_read(&zram->stats.huge_pages_since), + (u64)atomic64_read(&zram->stats.pages_merged)); up_read(&zram->init_lock); return ret; @@ -1473,6 +1474,7 @@ static int zram_cmp_obj_and_merge(struct zram *zram, struct hlist_head *htable, rb_node->cnt++; } + atomic64_inc(&zram->stats.pages_merged); atomic64_sub(obj_size, &zram->stats.compr_data_size); zram_set_flag(zram, index, ZRAM_MERGED); zram_set_flag(zram, node->index, ZRAM_MERGED); @@ -1657,6 +1659,8 @@ static void zram_free_page(struct zram *zram, size_t index) } else { mutex_unlock(&zram_rbtree_mutex); } + + atomic64_dec(&zram->stats.pages_merged); } else { zs_free(zram->mem_pool, handle); } diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index 4a7151c94523..2afdbf76a1aa 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -88,6 +88,7 @@ struct zram_stats { atomic_long_t max_used_pages; /* no. of maximum pages stored */ atomic64_t writestall; /* no. of write slow paths */ atomic64_t miss_free; /* no. of missed free */ + atomic64_t pages_merged; /* no. of pages, which merged into single one */ #ifdef CONFIG_ZRAM_WRITEBACK atomic64_t bd_count; /* no. of pages in backing device */ atomic64_t bd_reads; /* no. of reads from backing device */ From patchwork Mon Nov 21 19:00:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Romanov X-Patchwork-Id: 23997 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1775314wrr; Mon, 21 Nov 2022 11:06:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf6CAXuxG/kH/y/SYguyQl5e/ZVvkh4PKz5un88zBF58rryxR6RfB4sb2p9qcB5EJNVwRyeY X-Received: by 2002:aa7:8dd3:0:b0:573:4ae5:e475 with SMTP id j19-20020aa78dd3000000b005734ae5e475mr438850pfr.64.1669057580772; Mon, 21 Nov 2022 11:06:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669057580; cv=none; d=google.com; s=arc-20160816; b=DgukeeIU1d79C8tsV2AR90h3+89RDsaESd1nTGMYjvmcXw+Bhg+6BmODrxGRlZlndk ajC2H7xe3alPWkWxFMDDzpU70xebX51vohyyOTyh8Vi+tA3QMTFvR+zDzcH9edkQe/oa ceJgaNAKUFpoaBc8M5Y2dDkUaBLd0S2uW9yvS8JCwQRQ7aYp0G5uwKcEy8t+05U/tGv5 zLWgKYo893tmdxLiZ1TJy4uAatkbqv1+TXtSIn4avovnfdGmluO/tXA63JoV9woQutRi G+d1KSKEktXD5xZTXuzmwJZFFDhAsY38iXBSlHhbl/etDNRdDlXJtcjRUm25lDgzx+Z7 tuzA== 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=tTM44IR5Faf10C/P1nfxsNgdug0WyLlkFkfRmk6dQz8=; b=BqB9MYIkXOQ6vDtddq7tdqVy0dCm2KpafkzvYf/FtuBtWIQj7w8dIg1cUrUoI052uZ XQ/ZmBtIXUHo0bOfVk3sIZ5kBBN/UpPbdG20U7lSbl4y1RPhg2PI3TPL3PAopw+sDQiE nPqiMrMsCjPQQs1DIY5rN6Vqy7ApkmV+hbrL0gcacapTk0jxvrkuj9+a0FsMDIY7S0bL NNcijsdS/Rq4LBTheZXMe7YblT4qZo7f2bruO2E/oDlK2w1p/+nqG8Y72drVwbYa3Sdc NhiQ13NE0/XpYPE5aUden+lJ1LB1B/sbINgdC67/xGHoPutL8/aiJkU1IRXPkfIarbh+ BvoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=ZgPZzRvJ; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w185-20020a6382c2000000b00477328e3f17si9794362pgd.692.2022.11.21.11.05.52; Mon, 21 Nov 2022 11:06:20 -0800 (PST) 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=@sberdevices.ru header.s=mail header.b=ZgPZzRvJ; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230444AbiKUTBO (ORCPT + 99 others); Mon, 21 Nov 2022 14:01:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230425AbiKUTA6 (ORCPT ); Mon, 21 Nov 2022 14:00:58 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EDACCFE80 for ; Mon, 21 Nov 2022 11:00:56 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 6BD2B5FD0D; Mon, 21 Nov 2022 22:00:54 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1669057254; bh=tTM44IR5Faf10C/P1nfxsNgdug0WyLlkFkfRmk6dQz8=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ZgPZzRvJE29M4MUwixqY94klL086904XptaKyfBbZ2r0zNobazayO2F7pRoP9kY3F 5FUTHdEF2kVnf8QEJvqFG9CdwFShkARs239S88MgZl6Gucbb+ftJwCwrqHOkkTtBkG BPorMZxxQ4qQ3EQ3/Mz4jPfoTgpr0qQqUEUJf5M945USJXQ4EhhM0WHj7GvHweyxRa O/9jKeTOYMJLmAJSObuZn6LFGSL9oyx5LeBV/+ovuM/PhSF5x0i6QYWJskM2bnaw1U HMHzlu+XismWsdQN/V45vD5LFfjERfrHkLz/a6jT6n1ykjM8Zhu/AgwVmU+yEZwF3s JWihXUjKj9KJw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Mon, 21 Nov 2022 22:00:54 +0300 (MSK) From: Alexey Romanov To: , , , CC: , , , , Alexey Romanov Subject: [RFC PATCH v1 4/4] zram: recompression: add ZRAM_MERGED check Date: Mon, 21 Nov 2022 22:00:20 +0300 Message-ID: <20221121190020.66548-5-avromanov@sberdevices.ru> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20221121190020.66548-1-avromanov@sberdevices.ru> References: <20221121190020.66548-1-avromanov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2022/11/21 16:41:00 #20594217 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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?1750133721620870588?= X-GMAIL-MSGID: =?utf-8?q?1750133721620870588?= It is not possible to recompress merged pages in the current implementation. Although, in the future it is possible to add support for recompression of merged pages. Signed-off-by: Alexey Romanov --- drivers/block/zram/zram_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 7a267b37e5db..07661283ea15 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -2211,7 +2211,8 @@ static ssize_t recompress_store(struct device *dev, 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_INCOMPRESSIBLE)) + zram_test_flag(zram, index, ZRAM_INCOMPRESSIBLE) || + zram_test_flag(zram, index, ZRAM_MERGED)) goto next; err = zram_recompress(zram, index, page, threshold,