From patchwork Tue Apr 18 06:25:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Romanov X-Patchwork-Id: 13215072 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12659C77B7C for ; Tue, 18 Apr 2023 06:25:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 241AF8E0006; Tue, 18 Apr 2023 02:25:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A1958E0002; Tue, 18 Apr 2023 02:25:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE77B8E0006; Tue, 18 Apr 2023 02:25:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D9CD38E0002 for ; Tue, 18 Apr 2023 02:25:19 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A91C7C0139 for ; Tue, 18 Apr 2023 06:25:19 +0000 (UTC) X-FDA: 80693524758.25.C43A94B Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by imf07.hostedemail.com (Postfix) with ESMTP id 684B240013 for ; Tue, 18 Apr 2023 06:25:17 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=sberdevices.ru header.s=mail header.b=Du1ijEM7; spf=pass (imf07.hostedemail.com: domain of AVRomanov@sberdevices.ru designates 45.89.227.171 as permitted sender) smtp.mailfrom=AVRomanov@sberdevices.ru; dmarc=pass (policy=quarantine) header.from=sberdevices.ru ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681799117; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nfgD8CjAt52uLbsRtpG0YlGKoerIw5fnKcSwfy+g/JE=; b=eQ34sNMAZ7C3WvxCFbKHZ2cQh+T1M40LkFrIwertkF8mIchyClJaRajzA7jndBAZDZO6xj iPsrEbi0cXSVixnFhXJzKpfGdW8Y9CAvNqdWjAT4dN9SLNJcK6eNU1i39yswZfQXclwfcg +2osBcis5Z1lcjsRcHJpOje1YQMwCjE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=sberdevices.ru header.s=mail header.b=Du1ijEM7; spf=pass (imf07.hostedemail.com: domain of AVRomanov@sberdevices.ru designates 45.89.227.171 as permitted sender) smtp.mailfrom=AVRomanov@sberdevices.ru; dmarc=pass (policy=quarantine) header.from=sberdevices.ru ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681799117; a=rsa-sha256; cv=none; b=fkNQtfe7YBK+ZzMU9hncjmSZGE1lNhuKFpI9XjZJZZSSwd6cEzCmyEX6YsaDvDzL+vckt/ o/aei9EAZ89q0hbh5BzYfnInW+/dAoYdUx3VF/l4hYuZ8PReUPBZ+x/HP2yIb/PYufECqF Ll+kHXGBNpu+qhQGFedQUjVkkyJ9gEU= Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 266405FD5B; Tue, 18 Apr 2023 09:25:15 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1681799115; bh=nfgD8CjAt52uLbsRtpG0YlGKoerIw5fnKcSwfy+g/JE=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Du1ijEM7jXPQlYLuCqUkwMDR9U6uHlm6GPfjO87RePxjdfiJ3HQcQMppmp9vOJMtF xxWMiFe5HXJ+lG5kzPeyi5gj8ZGjqGKoNtjfjzvqGESrMKLf2uhwaj4AN68AtkxZD+ NZvOVJx1Rwgnsc/pqJ9JXd9y55I3ivJkOHeOwp03gKMw6KteyWXpcX/UoVO5D7oDsu DSpS8ifEQvhW3Vg5pfxkgCMeCZ9ps3vSLX/fyIEbti8oxad6yNwA3Ag6Um9OOMLOfn 17xdFTei6ZJBk+cPmnXN/ZGWsmujHQwqIgJqlB+MRUmLSvo9dFHza6kce8z8LBEcOe BmtLDmjOOYRgQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Tue, 18 Apr 2023 09:25:15 +0300 (MSK) From: Alexey Romanov To: , , CC: , , , Alexey Romanov Subject: [RFC PATCH v1 4/5] zram: add fold sysfs knob Date: Tue, 18 Apr 2023 09:25:02 +0300 Message-ID: <20230418062503.62121-5-avromanov@sberdevices.ru> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230418062503.62121-1-avromanov@sberdevices.ru> References: <20230418062503.62121-1-avromanov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) 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: 2023/04/18 02:02:00 #21122658 X-KSMG-AntiVirus-Status: Clean, skipped X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 684B240013 X-Stat-Signature: w9fcmip6deni4zsc4fwaok4f7n4jfjrj X-Rspam-User: X-HE-Tag: 1681799117-327807 X-HE-Meta: U2Fsd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dXlJTWwgUFwylVA05hadSM3l+ZVYZIBsjCYDlMfeRpPg65wdMF7hpKvSzfmllo+3ARMDia6BY5eechj/rErS5rrgFTojts2GS0+By5tRWqpzedo6cmOOxS5u3QO2CotcS1RjQFvyDxGbFROWD1FrYyzBYRTsiSRtuiW1l0BtfYjIeBjPh+BHKHNx+5lcGlfN8jlmfVKJJsWozOBzOHM5ZR8NhB13Ps5NMASrbjRLE+kXCIrBvVfIjTn8/cVhClCyyFEHIV5R/WKR7+ESTHZYrieZGVq8g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Allow zram to fold identical zsmalloc objects into single one: echo 1 > /sys/block/zramX/fold Signed-off-by: Alexey Romanov --- drivers/block/zram/zram_drv.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index e290d6d97047..06a614d1643d 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1184,6 +1184,25 @@ static ssize_t compact_store(struct device *dev, return len; } +#ifdef CONFIG_ZSMALLOC_FOLD +static ssize_t fold_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t len) +{ + struct zram *zram = dev_to_zram(dev); + + down_read(&zram->init_lock); + if (!init_done(zram)) { + up_read(&zram->init_lock); + return -EINVAL; + } + + zs_fold(zram->mem_pool); + up_read(&zram->init_lock); + + return len; +} +#endif + static ssize_t io_stat_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -2313,6 +2332,9 @@ static DEVICE_ATTR_RW(writeback_limit_enable); static DEVICE_ATTR_RW(recomp_algorithm); static DEVICE_ATTR_WO(recompress); #endif +#ifdef CONFIG_ZSMALLOC_FOLD +static DEVICE_ATTR_WO(fold); +#endif static struct attribute *zram_disk_attrs[] = { &dev_attr_disksize.attr, @@ -2339,6 +2361,9 @@ static struct attribute *zram_disk_attrs[] = { #ifdef CONFIG_ZRAM_MULTI_COMP &dev_attr_recomp_algorithm.attr, &dev_attr_recompress.attr, +#endif +#ifdef CONFIG_ZSMALLOC_FOLD + &dev_attr_fold.attr, #endif NULL, };