Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6653132rwr; Tue, 2 May 2023 03:42:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5snu7c3NJ2RcSqP/kymG25ZskwnKg+xxEkkLkwFYDFykjEXQqOO1Ulzf5J3czH/LySwtUk X-Received: by 2002:a17:903:2287:b0:1a2:8940:6dbd with SMTP id b7-20020a170903228700b001a289406dbdmr20976809plh.45.1683024153847; Tue, 02 May 2023 03:42:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683024153; cv=none; d=google.com; s=arc-20160816; b=ZnAGvzI7harxH5WyGO45Z9YV+uLA6C4RnYcb+ausBX9zbU/nV97IiVs0jvmUsOWy0p HLcERfYZlbJwsPf/jjAkT2ihlu5lmT0xZ9JjvupxOB1+bLO08cJOmISF7DmJBBfSDLtw HnUYl49bwCt+en69J+RfeEWvO66sMPsS2nfM86VwnFNf1SPSwA4xCqlUhXhxEqmrfbke VsPaIW0fN3584EUSS8gU4TOf5kTdWTSo/xUoP6zVPdPeoshOSN+F4IzbEbwePXXo9Kua nsB0gwk5VRZ74oT9FlbGCLyMLY02011+hhgUlDdNnaJTJwNBw1deN5jNoJ8ieuy5/EBF zErg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature; bh=lHmQ9OUHChl15VP559Y0PqcWhHblA7lT610Z0d2GIMU=; b=xuhKzkOCpnvrEbmt2H5osFBt15dAfiTLgWkGme0YPRCyPAqKgzG+pX25C3cU7kEDC2 xNvgDaZbTa80b/+4WjU6mX580KbSs86JhZVc0pFMrPiDDtg0Z/7f0YCk0cHzGnpJk+mW TTebViD3XRXUAqObAfLpSVfB0hFHIkZ1264VPpBEHJO3Y0OmeijTcLLxaeTJY47ED2eC Zn2eMFhClzZv34TPfms8lvYw4o7N+8IBo3uNXFBO31RmiTwp3Nb5pg61m+wYhcbOS1X/ hxh9LItX0MlfOh5kG93FOHSKdwzBONofS6H+6oro35NNWMWX6mN5vfIIKl6EoPTAOysM ULeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=SaZmeuWB; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v185-20020a6389c2000000b0052069c10121si30328161pgd.633.2023.05.02.03.42.15; Tue, 02 May 2023 03:42: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=@sberdevices.ru header.s=mail header.b=SaZmeuWB; 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 S230004AbjEBKjV (ORCPT + 99 others); Tue, 2 May 2023 06:39:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233832AbjEBKjE (ORCPT ); Tue, 2 May 2023 06:39:04 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 043F359DE for ; Tue, 2 May 2023 03:38:06 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 0383A5FD31; Tue, 2 May 2023 13:38:04 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1683023884; bh=lHmQ9OUHChl15VP559Y0PqcWhHblA7lT610Z0d2GIMU=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=SaZmeuWBJh06+e+TW45ejq/DzpYw0zO97oEI4fssQVPICWlUFfsynapZmXy85eOcp k0b+OeX3Y+xeDSkA2DLNx6wnyLdL1XFFk9keU46HF7g8AtcqS5K/yR0WAHm24IYRYC LwSAn9NPLMbQhjeGGzP3bR/iw7k+P4Qk29xTK7WJ3PsgFKe2YmGStOxvOsCy3RB+te 75NmE3lkKz0dSiF3jB2CsRmd96Z8Knx0CiXlBUwJ36kgsommQCpHnScw4mwh3oEfVD R8XG2uav20ppZlzbj5vzougjyS944gh8LO+0l9AWDwAV6NzuSBOCWlXsncRsfF+o8H OBNUC91gq3mDA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Tue, 2 May 2023 13:38:02 +0300 (MSK) From: =?koi8-r?B?8s/Nwc7P1yDhzMXL08XKIPfB08nM2MXXyd4=?= To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "akpm@linux-foundation.org" CC: "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , kernel Subject: Re: [RFC PATCH v1 0/5] Introduce objects folding mechanism Thread-Topic: [RFC PATCH v1 0/5] Introduce objects folding mechanism Thread-Index: AQHZcb6HWf5sffHx/k6nmlw8gBQWuq9GroMA Date: Tue, 2 May 2023 10:38:02 +0000 Message-ID: <20230502103752.sb3mwkdqhdzxlt65@cab-wsm-0029881> References: <20230418062503.62121-1-avromanov@sberdevices.ru> In-Reply-To: <20230418062503.62121-1-avromanov@sberdevices.ru> Accept-Language: ru-RU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.0.25] Content-Type: text/plain; charset="koi8-r" Content-ID: <9DEC1EF139199848A543125A8622170A@sberdevices.ru> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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: 2023/05/02 09:07:00 #21205017 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_NONE, T_SCC_BODY_TEXT_LINE 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 Hello! On Tue, Apr 18, 2023 at 09:24:58AM +0300, Alexey Romanov wrote: > Hello! >=20 > This RFC series adds feature which allows fold identical > zsmalloc objects into a single one. >=20 > Based on ZRAM version: > https://lore.kernel.org/lkml/Y3w8%2Fq%2FHoSbqamoD@google.com/t/ >=20 > Let's imagine that 3 objects with the same content got into zsmalloc: >=20 > +----------------+ +----------------+ +----------------+ > | handle 1 | | handle 2 | | handle 3 | > +-------+--------+ +-------+--------+ +--------+-------+ > | | | > | | | > +-------v--------+ +-------v---------+ +--------v-------+ > |zsmalloc object| |zsmalloc object | |zsmalloc object| > ++--------------++ +-+-------------+-+ ++--------------++ > +--------------+ +-------------+ +--------------+ > | buffer: "abc"| |buffer: "abc"| | buffer: "abc"| > +--------------+ +-------------+ +--------------+ >=20 > As you can see, the data is duplicated. Fold mechanism saves > (after scanning objects) only one zsmalloc object. Here's > what happens after the scan and fold: >=20 > +----------------+ +----------------+ +----------------+ > | handle 1 | | handle 2 | | handle 3 | > +-------+--------+ +-------+--------+ +--------+-------+ > | | | > | | | > | +--------v---------+ | > +-----------> zsmalloc object <-----------+ > +--+-------------+-+ > +-------------+ > |buffer: "abc"| > +-------------+ >=20 > Thus, we reduced the amount of memory occupied by 3 times. >=20 > This mechanism doesn't affect the perf of the zsmalloc itself in > any way (maybe just a little bit on the zs_free() function). > In order to describe each such identical object, we (constantly) > need sizeof(fold_rbtree_node) bytes. Also, all struct size_class now > have new field struct rb_root fold_rbtree. >=20 > Testing on my system (8GB RAM + 1Gb ZRAM SWAP) showed that at high > loads, on average, when calling the fold mechanism, we can save > up to 15-20% of the memory usage. >=20 > This patch series adds a new sysfs node into ZRAM - trigger folding > and provides new field in mm_stat. This field shows how many pages > freed during folding: >=20 > $ cat /sys/block/zram0/mm_stat > 431452160 332984392 339894272 0 339894272 282 0 51374 51374 0 >=20 > $ echo 1 > /sys/block/zram0/fold >=20 > $ cat /sys/block/zram/mm_stat > 431452160 270376848 287301504 0 339894272 282 0 51374 51374 6593 >=20 > Alexey Romanov (5): > mm/zsmalloc: use ARRAY_SIZE in isolate_zspage() > mm/zsmalloc: get rid of PAGE_MASK > mm/zsmalloc: introduce objects folding mechanism > zram: add fold sysfs knob > zram: add pages_folded to stats >=20 > Documentation/admin-guide/blockdev/zram.rst | 2 + > drivers/block/zram/zram_drv.c | 30 +- > include/linux/zsmalloc.h | 4 + > mm/Kconfig | 9 + > mm/zsmalloc.c | 484 +++++++++++++++++++- > 5 files changed, 513 insertions(+), 16 deletions(-) >=20 > --=20 > 2.38.1 >=20 Really sorry for the noise, but could you comment on my patchset and results? We have moved away from the terms and concepts used in the patent we discussed in the ZRAM version, and I believe we can safely use these changes in zsmalloc. --=20 Thank you, Alexey=