From patchwork Wed Oct 26 11:29:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13020475 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 0D687C38A2D for ; Wed, 26 Oct 2022 11:30:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A48568E0003; Wed, 26 Oct 2022 07:30:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D1EA8E0001; Wed, 26 Oct 2022 07:30:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 872B88E0003; Wed, 26 Oct 2022 07:30:13 -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 72D9B8E0001 for ; Wed, 26 Oct 2022 07:30:13 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 41ACB1A0F84 for ; Wed, 26 Oct 2022 11:30:13 +0000 (UTC) X-FDA: 80062881906.19.041FA27 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by imf07.hostedemail.com (Postfix) with ESMTP id CDC644001A for ; Wed, 26 Oct 2022 11:30:12 +0000 (UTC) Received: by mail-pg1-f178.google.com with SMTP id e129so14463437pgc.9 for ; Wed, 26 Oct 2022 04:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9cCehdWYmf2oT/+c3VC1U3PDElTtgIhBCXz1ANz8y7s=; b=GhNKrg0OAEwZop9TkQkoF/GYEB52Wp+FIXuigMbvdSHs2wjHSdWGVy+2RWGpHitcRZ GGEFJKQi4EZOQyUw0VThpPDdexrgvdZenXB8pA6s3yQsqgoPQ3jA02EQjZ513REHymHw eHeOgtudRK/s72eVGFn75SujwAATGHhrMKr7U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9cCehdWYmf2oT/+c3VC1U3PDElTtgIhBCXz1ANz8y7s=; b=H/JBUcHFxUEu/XBRQUq+yCGKQ+GwlErPGuNTXH6wFnOFJabwJ1oifM/cRrGnMHWjuZ 2SZDu34+XMTqEnZW0DjcnJCqgSSdF2NzoQ6Z7ACyyHnclVSydILKhODY2MdS8Z4B3Ysh +OlTN/EElUtltcyoug8oGIAshT7biPVG5QV9HxS87hQC9i1o+4Z0EgbkDZl+iYylnEFV 8S5Y1mt4nSB1CYEpwY5fDM6hqtUJafpEISJAQA8zmLDXLW7BMY5BI1C/fDy9sKeqBbJY lLrxBZZc3pS5Gy+1DsOgsQ0Rzii+A8eV+r/xaN6LJhiVIwFM8E69BrlVnCJDMRN/IBRK rkvQ== X-Gm-Message-State: ACrzQf2uLzBXsWezXiiAoNRdx99U3QKw/o74oUvM6y5RgDoj+Jw9qBdr JCUc9jNrpozAbfjfb3gNx7pzaw== X-Google-Smtp-Source: AMsMyM7Q4/e+y7mw0PklcMKgFBOK8szlLFKFKA9a8e/xiHIZ2p93fMqJppuuw1/722a3mQ94k0Z3xA== X-Received: by 2002:a05:6a00:1688:b0:53b:4239:7c5c with SMTP id k8-20020a056a00168800b0053b42397c5cmr44419098pfc.81.1666783811869; Wed, 26 Oct 2022 04:30:11 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:749c:f7f5:1a8e:d0be]) by smtp.gmail.com with ESMTPSA id x127-20020a626385000000b005627868e27esm2814919pfb.127.2022.10.26.04.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 04:30:11 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexey Romanov , Sergey Senozhatsky Subject: [PATCHv2 1/9] zram: add size class equals check into recompression Date: Wed, 26 Oct 2022 20:29:25 +0900 Message-Id: <20221026112933.4122957-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog In-Reply-To: <20221026112933.4122957-1-senozhatsky@chromium.org> References: <20221026112933.4122957-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666783812; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9cCehdWYmf2oT/+c3VC1U3PDElTtgIhBCXz1ANz8y7s=; b=N1uVIr3ZIW5IxrU0VlIlS9TWTd4wJD2u6eexwxwIxDLuFE56cEEAob4ifPxZbI/6DYsS9p Vfu5yIwCKIt9t3kjL/C3v7/M1RgyBXk5HguTNf9LkQZDEuLiUg/Tsj2L9x0ZOqEvSwJqKr Bd4a0qTGe5zE9Ctro3GzCPvN8kwwgp8= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=GhNKrg0O; spf=pass (imf07.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.178 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666783812; a=rsa-sha256; cv=none; b=EIXY8ZMma/wEjkNT326mam5sQfy9dYg1RPa9WxctpjXTwpOeOeI19VoRhD3DayaR3dzRNI kl93eGbuNdp6X2q4evTI/d/myAf/keYkfeFXFjBQU+soq4Uh+aU2/BAO/6bDQoElDPY+UO O5XuJ37xqejyZlhYjJS4vlKpi3wYUuo= Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=GhNKrg0O; spf=pass (imf07.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.178 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Stat-Signature: bxdj78m6jatm3js7nfd7m3zejhjmwm3f X-Rspamd-Queue-Id: CDC644001A X-Rspamd-Server: rspam07 X-Rspam-User: X-HE-Tag: 1666783812-130340 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: From: Alexey Romanov 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 Reviewed-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 5 +++++ include/linux/zsmalloc.h | 2 ++ mm/zsmalloc.c | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 364323713393..fd31beb6491a 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_index_prev; + unsigned int class_index_next; 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_index_prev = zs_lookup_class_index(zram->mem_pool, comp_len_prev); + class_index_next = zs_lookup_class_index(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_index_next >= class_index_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..a48cd0ffe57d 100644 --- a/include/linux/zsmalloc.h +++ b/include/linux/zsmalloc.h @@ -55,5 +55,7 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle); unsigned long zs_get_total_pages(struct zs_pool *pool); unsigned long zs_compact(struct zs_pool *pool); +unsigned int zs_lookup_class_index(struct zs_pool *pool, unsigned int size); + void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats); #endif diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index d03941cace2c..065744b7e9d8 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1205,6 +1205,27 @@ static bool zspage_full(struct size_class *class, struct zspage *zspage) return get_zspage_inuse(zspage) == class->objs_per_zspage; } +/** + * zs_lookup_class_index() - Returns index of the zsmalloc &size_class + * that hold objects of the provided size. + * @pool: zsmalloc pool to use + * @size: object size + * + * Context: Any context. + * + * Return: the index of the zsmalloc &size_class that hold objects of the + * provided size. + */ +unsigned int zs_lookup_class_index(struct zs_pool *pool, unsigned int size) +{ + struct size_class *class; + + class = pool->size_class[get_size_class_index(size)]; + + return class->index; +} +EXPORT_SYMBOL_GPL(zs_lookup_class_index); + unsigned long zs_get_total_pages(struct zs_pool *pool) { return atomic_long_read(&pool->pages_allocated);