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 */