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: 13051556 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 C39BAC43217 for ; Mon, 21 Nov 2022 19:00:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5D876B007D; Mon, 21 Nov 2022 14:00:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E6CC8E0005; Mon, 21 Nov 2022 14:00:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85FC78E0002; Mon, 21 Nov 2022 14:00:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 734516B007D for ; Mon, 21 Nov 2022 14:00:56 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DEB73AB58A for ; Mon, 21 Nov 2022 19:00:55 +0000 (UTC) X-FDA: 80158366470.03.A8CD4E3 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by imf23.hostedemail.com (Postfix) with ESMTP id C73CC14000F for ; Mon, 21 Nov 2022 19:00:53 +0000 (UTC) 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669057254; a=rsa-sha256; cv=none; b=e0GaI25VdPmxM69c/e7O+2kkarpoc8jJgDgkqt9AxWbKt9l+FYrKRvmKVnBG3/WeUgEMRM mGOEMOL/VoJrGCaRCCzLzQJO576eQTgvq7ePcXyBsAy/UAeXbadeXrHUsKdSgRGmRSTJIE RkLlmxlf+7MSlwOTWy+Kbtu64AJlgLE= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=sberdevices.ru header.s=mail header.b=I12Ib1ec; dmarc=pass (policy=quarantine) header.from=sberdevices.ru; spf=pass (imf23.hostedemail.com: domain of AVRomanov@sberdevices.ru designates 45.89.227.171 as permitted sender) smtp.mailfrom=AVRomanov@sberdevices.ru ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669057254; 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=tnNz8FxhOymc0atH2o9EbaV/8E1YXEIwJHa+DOBrsk0=; b=ARGCSnHcETEcY0QhKH/gofQg3CH2B2aqvCluETJKtkk9nAGSCM3E3kR+DFVCqZq+lsFPrg oGS77FqHU/+6bU4N/4GDiRmwKwS8/6TLkeGu9Wzh1/jIzDj1LvESvwkukNoe5mFk9luKi1 wMEnwvgPWLkz4g4NluQ/dqgNP1dtVQQ= X-Stat-Signature: 1xepcdmcn63nks5q7smupdmgnixuukak X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C73CC14000F Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=sberdevices.ru header.s=mail header.b=I12Ib1ec; dmarc=pass (policy=quarantine) header.from=sberdevices.ru; spf=pass (imf23.hostedemail.com: domain of AVRomanov@sberdevices.ru designates 45.89.227.171 as permitted sender) smtp.mailfrom=AVRomanov@sberdevices.ru X-Rspam-User: X-HE-Tag: 1669057253-729000 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 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,