From patchwork Mon Oct 24 12:09:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Romanov X-Patchwork-Id: 13017494 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 0DC06ECAAA1 for ; Mon, 24 Oct 2022 12:10:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3805E8E0002; Mon, 24 Oct 2022 08:10:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32FF98E0001; Mon, 24 Oct 2022 08:10:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21F518E0002; Mon, 24 Oct 2022 08:10:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1359F8E0001 for ; Mon, 24 Oct 2022 08:10:00 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D90B01C5C05 for ; Mon, 24 Oct 2022 12:09:59 +0000 (UTC) X-FDA: 80055724518.08.6C4A985 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by imf05.hostedemail.com (Postfix) with ESMTP id CB135100010 for ; Mon, 24 Oct 2022 12:09:58 +0000 (UTC) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id B59195FD16; Mon, 24 Oct 2022 15:09:56 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1666613396; bh=nc6jhUQNsZdri2+Q1s+EIKAfnFCelaJvCH3sqTAEXGY=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Iv4g2AL99+N/fY4E0QQ+qSvkSe/nM1P7XxD3e29zAJBA+K6CdlMdtXSf+dUAs0WEU U4mzdAYVxlqWFg4JNDQMlVJQvSVa0CP9ALDCZpOzd8AcJDpCgqUEZpDhgce9KEiAlA 28wWnyNgiwbJ4xX6NZtVrnQDa8e4yxoPkjGAbT5aqoYOXP241eoNxGX7b7l3kjBh6K OrCoMfxgrndrc48Y+k4ECcx24HJA8Fo+49Ro6et6DFYaOPdYFPU2wsLt21ILNlY8p+ 5+QfB6LJeO1/5hEHEs/QJL31qkq1MBd7/samW3WYr6dqoZbh9EjriYNW97QqelXE6n 9vaEIfmJybFYw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Mon, 24 Oct 2022 15:09:54 +0300 (MSK) From: Alexey Romanov To: , , , CC: , , , Alexey Romanov Subject: [PATCH v1] zram: add size class equals check into recompression Date: Mon, 24 Oct 2022 15:09:42 +0300 Message-ID: <20221024120942.13885-1-avromanov@sberdevices.ru> X-Mailer: git-send-email 2.33.0 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: 2022/10/24 07:24:00 #20510762 X-KSMG-AntiVirus-Status: Clean, skipped ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=sberdevices.ru header.s=mail header.b=Iv4g2AL9; spf=pass (imf05.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=1666613399; a=rsa-sha256; cv=none; b=jJ97OpImKDKnK3D07g3zTulrqKPB2vajVZB8gsxjsGU7PwH2JCSpKLX8lgkv0A1iF5ARbK N6P3DJQdSpV6qY1vdZg540EXyDsDww/0aiGDEXFqwW0Fem/uR3VtV6lujglddkX62en9Og DMr9q3BKpw9jEkCRuKKhZSdhBak3iUY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666613399; 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: references:dkim-signature; bh=nc6jhUQNsZdri2+Q1s+EIKAfnFCelaJvCH3sqTAEXGY=; b=j4dBCFtwv0sS3fUdXy13qBXap9+TBPDA688NiM/7XC8Rv6Te98qtiXGPtHE229xvY8pJOn LuZ1fhyNnO60mteUMEPYOBgjDrt91FWKb2YVlj+wIUwryO9ghX1bbNBAqOzFJQ8nAxiIox tC992wEfs0so4y+YHFKJ3ErZ+YfgV94= X-Stat-Signature: uk6k4nqsptb7fuaxkhrs8j9wm49onftt X-Rspamd-Queue-Id: CB135100010 X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=sberdevices.ru header.s=mail header.b=Iv4g2AL9; spf=pass (imf05.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 X-Rspamd-Server: rspam06 X-HE-Tag: 1666613398-363190 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: It makes no sense for us to recompress the object if it will be in the same size class. We anyway don't get any memory gain. But, at the same time, we get a CPU time overhead when inserting this object into zspage and decompressing it afterwards. Signed-off-by: Alexey Romanov --- drivers/block/zram/zram_drv.c | 5 +++++ include/linux/zsmalloc.h | 2 ++ mm/zsmalloc.c | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 364323713393..bf610cf6a09c 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1632,6 +1632,8 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, unsigned long handle_next; unsigned int comp_len_next; unsigned int comp_len_prev; + unsigned int class_size_next; + unsigned int class_size_prev; struct zcomp_strm *zstrm; void *src, *dst; int ret; @@ -1656,6 +1658,8 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, ret = zcomp_compress(zstrm, src, &comp_len_next); kunmap_atomic(src); + class_size_prev = zs_get_class_size(zram->mem_pool, comp_len_prev); + class_size_next = zs_get_class_size(zram->mem_pool, comp_len_next); /* * Either a compression error or we failed to compressed the object * in a way that will save us memory. Mark the object so that we @@ -1663,6 +1667,7 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, */ if (comp_len_next >= huge_class_size || comp_len_next >= comp_len_prev || + class_size_next == class_size_prev || ret) { zram_set_flag(zram, index, ZRAM_RECOMP_SKIP); zram_clear_flag(zram, index, ZRAM_IDLE); diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h index 2a430e713ce5..75dcbafd5f36 100644 --- a/include/linux/zsmalloc.h +++ b/include/linux/zsmalloc.h @@ -56,4 +56,6 @@ unsigned long zs_get_total_pages(struct zs_pool *pool); unsigned long zs_compact(struct zs_pool *pool); void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats); + +unsigned int zs_get_class_size(struct zs_pool *pool, unsigned int size); #endif diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index d03941cace2c..148451385445 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1205,6 +1205,26 @@ static bool zspage_full(struct size_class *class, struct zspage *zspage) return get_zspage_inuse(zspage) == class->objs_per_zspage; } +/** + * zs_get_class_size() - Returns the size (in bytes) of the + * zsmalloc &size_class into which the object with specified + * size will be inserted or already inserted. + * + * @pool: zsmalloc pool to use + * + * Context: Any context. + * + * Return: the size (in bytes) of the zsmalloc &size_class into which + * the object with specified size will be inserted. + */ +unsigned int zs_get_class_size(struct zs_pool *pool, unsigned int size) +{ + struct size_class *class = pool->size_class[get_size_class_index(size)]; + + return class->size; +} +EXPORT_SYMBOL_GPL(zs_get_class_size); + unsigned long zs_get_total_pages(struct zs_pool *pool) { return atomic_long_read(&pool->pages_allocated);