From patchwork Mon Sep 5 08:15:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965747 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 0A235C6FA89 for ; Mon, 5 Sep 2022 08:16:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86A0F801BA; Mon, 5 Sep 2022 04:16:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F2E1801B3; Mon, 5 Sep 2022 04:16:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66B59801BA; Mon, 5 Sep 2022 04:16:07 -0400 (EDT) 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 50D4A801B3 for ; Mon, 5 Sep 2022 04:16:07 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 28C9F120D74 for ; Mon, 5 Sep 2022 08:16:07 +0000 (UTC) X-FDA: 79877323974.11.713ACEB Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf05.hostedemail.com (Postfix) with ESMTP id DC89B100073 for ; Mon, 5 Sep 2022 08:16:06 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id m10-20020a17090a730a00b001fa986fd8eeso11507448pjk.0 for ; Mon, 05 Sep 2022 01:16:06 -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; bh=ARMalt43cGQStsEP0fAYz16MOL60Ugpll7VhrHzWrN4=; b=R+L49dA4rCLdsc7mxoe36IKYzPKwp674LNy6oPrFh7m3bvbFXZJam6MTSuP+TEv+7O RDt8LqRmhtESdpQ0NcPJVGt4LuFExGMVjIKpmk81fOLo0FOILv/2L9t/HMuwZ8gvsMXf YdXBbfIzzwwM4mV5+OYIRZqB74ePC76ye0OsY= 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; bh=ARMalt43cGQStsEP0fAYz16MOL60Ugpll7VhrHzWrN4=; b=oaUVzJ+0e9iIrNQk1O2Ny9k+1omkVVHrwWu5en6+dHi+B1pD1uXfzakL36Jq+TAOgJ VbP+EvP6MfO3uGu8TVib3lU0UtVmMy0qQ0tenRR/It/7O7e1/gGWTaH5hQiCU66FpSEv 7x3M7DbC8wIvSz1WHlWDqBtS5Dz+ykHrlxn0RNotj99qlEiPIToCRh3G5yfgPrrl9qo+ ii/dW+oAV1AoclGmuXbV3oO1ArAZZZY3DG5F9TXSYIJATxOYbK+5857b9NXqaqa8sLVZ UNZTkLSs2Zd6H+4srXCtXyO7+gJdx7C1fD5CJ28MAPo9/7ydxV/czyXsikzRXFQcFiRn WKLA== X-Gm-Message-State: ACgBeo1W9RTKW1gqhVyzpnM4O2fwucDxgxNHqg/CwcVAKWx5KuPiC63v jZ2Edb90TsSnvm11tMesnSfZ6Q== X-Google-Smtp-Source: AA6agR7FJso6bnfvHqRxrl2G7vqu3sL7hSJiUx3LVxSxhi7XTb8chbTy7Se1vSlNdxTZto4tDiFwiQ== X-Received: by 2002:a17:902:c949:b0:172:e3c3:bdeb with SMTP id i9-20020a170902c94900b00172e3c3bdebmr47860330pla.80.1662365765853; Mon, 05 Sep 2022 01:16:05 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id w12-20020aa79a0c000000b005363bc65bafsm7075864pfj.57.2022.09.05.01.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:16:05 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH 1/3] documentation: Add recompression documentation Date: Mon, 5 Sep 2022 17:15:43 +0900 Message-Id: <20220905081552.2740917-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905081552.2740917-1-senozhatsky@chromium.org> References: <20220905081552.2740917-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662365766; a=rsa-sha256; cv=none; b=CbcGE43LmvwIpVRiQdSn143s5vA4D6Lupm/tGh8TKAt0AR+feu8B088Z9/RrfdZ72VEcpm 8KoScIEptaDvB0M9PYhbKmxiXaktYPyouSXHrvUMcvwhgdXATN3h11qt/JOP6FZm6YGrW+ W8DOrCrSIwZHZArz+IS0ve3HRVFLn+4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=R+L49dA4; spf=pass (imf05.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.53 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662365766; 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=ARMalt43cGQStsEP0fAYz16MOL60Ugpll7VhrHzWrN4=; b=nN6EkgTuejbpkirWDs5ThjpeH5ar6Wrw863ck6zRNYSbFl86ynxT4VYsWE/zwVJyyzu4hz MpTGZFnhNjCZMOq4nAWBu3bWXTXqdjQotXyNSCcmWFWh/EsVlbM2T7fr5YcIxLoyaqozX4 +m1H0N8h4eexwUGSoMbqeU/43V9LyN8= X-Stat-Signature: 6jgp7g355hf55qmh1obinmf18mfwfbtp X-Rspamd-Queue-Id: DC89B100073 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=R+L49dA4; spf=pass (imf05.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.53 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1662365766-608407 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: Document user-space visible device attributes that are enabled by ZRAM_MULTI_COMP. Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/blockdev/zram.rst | 55 +++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index c73b16930449..88957fcb6ad7 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -401,6 +401,61 @@ budget in next setting is user's job. If admin wants to measure writeback count in a certain period, they could know it via /sys/block/zram0/bd_stat's 3rd column. +recompression +------------- + +With CONFIG_ZRAM_MULTI_COMP, zram can recompress idle/huge pages using +alternative (secondary) compression algorithm. The basic idea is that +alternative compression algorithm can provide better compression ratio +at a price of (potentially) slower compression/decompression speeds. +Alternative compression algorithm can, for example, be more successful +compressing huge pages (those that default algorithm failed to compress). +Another application is idle pages recompression - pages that are cold and +sit in the memory can be recompressed using more effective algorithm and, +hence, reduce zsmalloc memory usage. + +With CONFIG_ZRAM_MULTI_COMP, zram will setup two compression algorithms +per-CPU: primary and secondary ones. Primary zram compressor is explained +in "3) Select compression algorithm", the secondary algorithm is configured +in a similar way, using recomp_algorithm device attribute: + +Examples:: + + #show supported recompression algorithms + cat /sys/block/zramX/recomp_algorithm + zstd [lzo] + + #select zstd recompression algorithm + echo zstd > /sys/block/zramX/recomp_algorithm + +Another device attribute that CONFIG_ZRAM_MULTI_COMP enables is recompress, +which controls recompression: + +Examples:: + + #IDLE pages recompression is activated by `idle` mode + echo idle > /sys/block/zramX/recompress + + #HUGE pages recompression is activated by `huge` mode + echo huge > /sys/block/zram0/recompress + + #HUGE_IDLE pages recompression is activated by `huge_idle` mode + echo huge_idle > /sys/block/zramX/recompress + +The number of idle pages can be significant, so user-space can pass a size +watermark value to the recompress knob, to filter out idle pages for +recompression: zram will recompress only idle pages of equal or greater +size::: + + #recompress idle pages larger than 3000 bytes + echo 3000 > /sys/block/zramX/recompress + + #recompress idle pages larger than 2000 bytes + echo 2000 > /sys/block/zramX/recompress + +Recompression is mostly focused on idle pages (except for huge pages +recompression), so it works better in conjunction with memory tracking. + memory tracking =============== From patchwork Mon Sep 5 08:15:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965749 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 8579EECAAA1 for ; Mon, 5 Sep 2022 08:16:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D965801BC; Mon, 5 Sep 2022 04:16:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1624C801B3; Mon, 5 Sep 2022 04:16:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F1D9C801BC; Mon, 5 Sep 2022 04:16:14 -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 DE69B801B3 for ; Mon, 5 Sep 2022 04:16:14 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1F686121898 for ; Mon, 5 Sep 2022 08:16:13 +0000 (UTC) X-FDA: 79877324226.09.35030D3 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf27.hostedemail.com (Postfix) with ESMTP id CD6C1400AA for ; Mon, 5 Sep 2022 08:16:12 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id jm11so7773852plb.13 for ; Mon, 05 Sep 2022 01:16: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; bh=fBzy0HH3oP/NJNf66NH/BQ/hBL6aSkPOwubVif8FhBg=; b=g7ZLQz5Z/UHV+cJtofiH2bNHxfIGDDEbPms2i+63gWIQo9iEQyAbHkz2T63xkNd232 8HXFrR0soPJ/o36JPaLPBcmaa7Vd3YWV7WQT58naNwRYiytTnSSV3xbgOLXUZNYNacFI OgOIERWJrjBlsBwRdaLwSgka5CKVaWoBSNZl8= 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; bh=fBzy0HH3oP/NJNf66NH/BQ/hBL6aSkPOwubVif8FhBg=; b=oF58JSiBJj9+r++0Cg0VV5LPYZnkrrbIaZ/PYBfWAWi/BS5V0735fan0NTgIR7VuDm mEPJzPb6wccIXkmCT4dNx4xJzouun682CbcDxgguakX76mTGR3NY7CtcleqpGgdn4n/D TiCtjA/FSSEyCdMbue1vBdfZruREkM2EnkxJuEA45Khp742xudkwGf+gloeFoDZMS+CO 4U2ScfjnmToykEDOv1gTx8f/WbgF5By7B2WgBGDda5OI4OLZ044mL0pGvxwZ6soRPdFy WmoH+607eMir4zrpdngYLglKjqWRQFHFQ1AymZXgPK7RfxzJQesM2yjtyGCNbLlr9cfz HUiw== X-Gm-Message-State: ACgBeo2iCo9hCVZRhNXJUCXR2hEExH3dL12g2ierro6dEh5N34g9U0lE vELbPzrlopq/GCqcL+KZf3GBlQ== X-Google-Smtp-Source: AA6agR5A0zJxXzLe1uhfjaa6iSw5p5az5Rm6rkC00HQxMV7jvGbarLvaRVP5N167w0AAR8B/o/OXVw== X-Received: by 2002:a17:902:d2ce:b0:175:994:7778 with SMTP id n14-20020a170902d2ce00b0017509947778mr30962616plc.43.1662365771902; Mon, 05 Sep 2022 01:16:11 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id w12-20020aa79a0c000000b005363bc65bafsm7075864pfj.57.2022.09.05.01.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:16:11 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH 2/3] zram: Add recompression algorithm choice to Kconfig Date: Mon, 5 Sep 2022 17:15:45 +0900 Message-Id: <20220905081552.2740917-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905081552.2740917-1-senozhatsky@chromium.org> References: <20220905081552.2740917-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=g7ZLQz5Z; spf=pass (imf27.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.176 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=1662365772; a=rsa-sha256; cv=none; b=XGx8NlgPzfq8PJeyKtR6UWZd2/2MiyXerSXl3hFx9PpnoSgLOPkMWbgpbCOC/7N1Y0xxOF L1R2DeyICS5xb4jxCOU2MQx3enu4LwatCKnI5MAf5IWi25UjZhGrCllESYyjafRTnJwbF3 NeGHIiq3t/45lO4CpkPBRftar4SGZ5E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662365772; 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=fBzy0HH3oP/NJNf66NH/BQ/hBL6aSkPOwubVif8FhBg=; b=bk0SgzJq43yR7rdn0OLPqrXHo16UIoIM93TnUUbshoNsz0G3k4bqNDG11tCcOlbXC8gvqt rgFEao9g5Fc23tVwEaPCbl+nDNzO9N9C0zkixbBwZcia+jr4hv5E8oCu/E1QOtpDnFdAZn 7strEa2rK+Q3kFkwuqyVaX8YeMrGfn8= X-Rspamd-Server: rspam02 X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=g7ZLQz5Z; spf=pass (imf27.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.176 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Stat-Signature: w63d45wmugshcx5qotiw5qcs1ie8rxn6 X-Rspamd-Queue-Id: CD6C1400AA X-HE-Tag: 1662365772-413965 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: Make (secondary) recompression algorithm selectable just like we do it for the (primary) default one. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/Kconfig | 40 +++++++++++++++++++++++++++++++++++ drivers/block/zram/zram_drv.c | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index 81ae4b96ec1a..fc2d4d66c484 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -89,3 +89,43 @@ config ZRAM_MULTI_COMP echo TIMEOUT > /sys/block/zramX/idle echo SIZE > /sys/block/zramX/recompress + +choice + prompt "Default zram recompression algorithm" + default ZRAM_DEF_RECOMP_ZSTD + depends on ZRAM && ZRAM_MULTI_COMP + +config ZRAM_DEF_RECOMP_LZORLE + bool "lzo-rle" + depends on CRYPTO_LZO + +config ZRAM_DEF_RECOMP_ZSTD + bool "zstd" + depends on CRYPTO_ZSTD + +config ZRAM_DEF_RECOMP_LZ4 + bool "lz4" + depends on CRYPTO_LZ4 + +config ZRAM_DEF_RECOMP_LZO + bool "lzo" + depends on CRYPTO_LZO + +config ZRAM_DEF_RECOMP_LZ4HC + bool "lz4hc" + depends on CRYPTO_LZ4HC + +config ZRAM_DEF_RECOMP_842 + bool "842" + depends on CRYPTO_842 + +endchoice + +config ZRAM_DEF_RECOMP + string + default "lzo-rle" if ZRAM_DEF_RECOMP_LZORLE + default "zstd" if ZRAM_DEF_RECOMP_ZSTD + default "lz4" if ZRAM_DEF_RECOMP_LZ4 + default "lzo" if ZRAM_DEF_RECOMP_LZO + default "lz4hc" if ZRAM_DEF_RECOMP_LZ4HC + default "842" if ZRAM_DEF_RECOMP_842 diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 5f0181d9a69e..f144f31c3c4b 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -44,7 +44,7 @@ static int zram_major; static const char *default_comp_algs[ZRAM_MAX_ZCOMPS] = { CONFIG_ZRAM_DEF_COMP, #ifdef CONFIG_ZRAM_MULTI_COMP - "zstd", + CONFIG_ZRAM_DEF_RECOMP, #endif }; From patchwork Mon Sep 5 08:15:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965751 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 12CF5C6FA86 for ; Mon, 5 Sep 2022 08:16:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A672E801BE; Mon, 5 Sep 2022 04:16:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9EDBF801B3; Mon, 5 Sep 2022 04:16:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83F8F801BE; Mon, 5 Sep 2022 04:16:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6A320801B3 for ; Mon, 5 Sep 2022 04:16:18 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 42B3316024D for ; Mon, 5 Sep 2022 08:16:18 +0000 (UTC) X-FDA: 79877324436.10.ADE32AE Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf11.hostedemail.com (Postfix) with ESMTP id E94D040058 for ; Mon, 5 Sep 2022 08:16:17 +0000 (UTC) Received: by mail-pf1-f179.google.com with SMTP id y29so8006303pfq.0 for ; Mon, 05 Sep 2022 01:16:17 -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; bh=DNUOFwSGpdK+nnrxMG7S20eDsCufcwNG30HnXLUld24=; b=eH5yHC7E3boaNZSJoFGkpKwRTCJkbyHVEkXkQS6xSCqO+cZV0Y8cmWXp03lKyOj7oH d3fWNvodjlK85jXLZNTu43uTDK/eC2fzKm74+52vrd/DXXsl/mwsRxe03esHNX1aBavm ZhQ3qfdoU8OXQplyZFimzo5999MI//98slFvE= 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; bh=DNUOFwSGpdK+nnrxMG7S20eDsCufcwNG30HnXLUld24=; b=D8xPLKVHJw63CHl80B/pO1bwePCyJP1jnGxiFbuxVwdRlBnEq87b3B0fb1wvBvThSY FFjN4UHf6WiIxjpTMHt5Du81pliTsnxt7ldQIRNVWiii0A3RJ5/OIMrVNXm5BVavcZqh ovNC+aoYL5t9Q+igPMFf9i3EdGMSxQhN/RsZWg2KAm57iIo482GFfs15yNyr9ZtO5T/9 SWXqr73YifgMjuu6zHyWTK0hCb5pabgBB5d7nwT6UPdB5+5EoDGopNtIELEYLGFkP0SJ kp5e8BFVSa1ZGyoyxPtS0aFfyU07IvYitYVJhDU8Kfm+WwyN9Q5U7XVI5EQ2yHe1NXR/ ZVpg== X-Gm-Message-State: ACgBeo0P2SehuN+pacMtWXUEn1R91GEVfotJP6P3kq1EmQNV/Xck6CTq deFf/l0GVP+moJtXJPrLVPx+IQ== X-Google-Smtp-Source: AA6agR75YXRxs7K6WXZCwu9cFa53p0bnH4Ss1kJ8jGsE12knaZ8A2T65N2kxadwOs6l6K3OeXznNpw== X-Received: by 2002:a05:6a00:16c4:b0:535:890:d4a with SMTP id l4-20020a056a0016c400b0053508900d4amr49041501pfc.0.1662365777547; Mon, 05 Sep 2022 01:16:17 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id w12-20020aa79a0c000000b005363bc65bafsm7075864pfj.57.2022.09.05.01.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:16:16 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH 3/3] zram: Add recompress flag to read_block_state() Date: Mon, 5 Sep 2022 17:15:47 +0900 Message-Id: <20220905081552.2740917-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905081552.2740917-1-senozhatsky@chromium.org> References: <20220905081552.2740917-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662365777; a=rsa-sha256; cv=none; b=XCqKPT7VmPFRUIvclFuN2nclFeXQVZjHOGYkxFb/I02gAKxQOfymEJj/QGXsK1hMweDBYT vUc5mhduDk31PM13iWClPzkEw/0oV3akIF4/Bj7EXnAEGROis4Aiq/Vr98ADGJp/7Wy7Lk 3fXKey6WogIjiCOvtfz47zFC0bsVXHI= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=eH5yHC7E; spf=pass (imf11.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.179 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662365777; 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=DNUOFwSGpdK+nnrxMG7S20eDsCufcwNG30HnXLUld24=; b=wDh2qq58XnSLd+jiuhhbpW50A5mSVzb/5Lsq9Vv4tG6QDXyftKi1ep6wTUOq4EiuSQ/wtP 8ePWqVG/BQzD83Ed6gFetUuIDGovOUj4k9dbVO9i+2+ZjV9ZT0X4naxxlGVUqGlnruD29f 5tQFXKT9qBaLuCVrx5faOt1KZaJlS2A= X-Stat-Signature: hrz33pw9fheqbpkren71be6d9bxqts41 X-Rspamd-Queue-Id: E94D040058 X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=eH5yHC7E; spf=pass (imf11.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.179 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam01 X-HE-Tag: 1662365777-942616 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: Add a new flag to zram block state that shows if the page was recompressed (using alternative compression algorithm). Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/blockdev/zram.rst | 9 ++++++--- drivers/block/zram/zram_drv.c | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index 88957fcb6ad7..70a3d0243b45 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -466,9 +466,10 @@ pages of the process with*pagemap. If you enable the feature, you could see block state via /sys/kernel/debug/zram/zram0/block_state". The output is as follows:: - 300 75.033841 .wh. - 301 63.806904 s... - 302 63.806919 ..hi + 300 75.033841 .wh.. + 301 63.806904 s.... + 302 63.806919 ..hi. + 303 62.801919 ....r First column zram's block index. @@ -485,6 +486,8 @@ Third column huge page i: idle page + r: + recompressed page (secondary compression algorithm) First line of above example says 300th block is accessed at 75.033841sec and the block's state is huge so it is written back to the backing diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index f144f31c3c4b..791f798d356d 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -936,13 +936,14 @@ static ssize_t read_block_state(struct file *file, char __user *buf, ts = ktime_to_timespec64(zram->table[index].ac_time); copied = snprintf(kbuf + written, count, - "%12zd %12lld.%06lu %c%c%c%c\n", + "%12zd %12lld.%06lu %c%c%c%c%c\n", index, (s64)ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC, zram_test_flag(zram, index, ZRAM_SAME) ? 's' : '.', zram_test_flag(zram, index, ZRAM_WB) ? 'w' : '.', zram_test_flag(zram, index, ZRAM_HUGE) ? 'h' : '.', - zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.'); + zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.', + zram_test_flag(zram, index, ZRAM_RECOMP) ? 'r' : '.'); if (count <= copied) { zram_slot_unlock(zram, index); From patchwork Mon Sep 5 08:15:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965753 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 4B011ECAAD5 for ; Mon, 5 Sep 2022 08:16:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC09D801C0; Mon, 5 Sep 2022 04:16:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D49C6801B3; Mon, 5 Sep 2022 04:16:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9BF8801C0; Mon, 5 Sep 2022 04:16:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A5847801B3 for ; Mon, 5 Sep 2022 04:16:24 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 703D61C5D9D for ; Mon, 5 Sep 2022 08:16:24 +0000 (UTC) X-FDA: 79877324688.27.D85D6E6 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by imf14.hostedemail.com (Postfix) with ESMTP id 334E7100052 for ; Mon, 5 Sep 2022 08:16:24 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id b196so7495428pga.7 for ; Mon, 05 Sep 2022 01:16:23 -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; bh=apGSrKTgwETbH2CMEGMydpnHgs87JcMdkEf7eiEN8iQ=; b=UHiLRbvmr56hCocfhGGKjJpCVX0QmwXKnDK02ZfwGPiXbrffOhTCeCLMKNpR9/tYGN X3yaRX3dSDUu5HLs3OpqRGVnskUagYD2WNBKNj5vf5SlhMZttWoROgu0ZSCMWH0M/cgf SvFJoxTLExmSdSrU8YjuphWxZVJHzqbq7m4H8= 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; bh=apGSrKTgwETbH2CMEGMydpnHgs87JcMdkEf7eiEN8iQ=; b=xyjmfd1vm+JLU7Ug6YBoH9lbVztvKG85tZcnppdv2SWVTij5haMobI24vgNTRJIHky e4quSll313sXfpNszKDNlX1ZlYOiNLsyA/ZUdcwTfJ1OBc7dWeZ1AMLt3PjBBwX5o/47 /i8kNQjECk7CxAKkBTLkaKl5YyCld+KlOFYNv7URUKWtoM/K0pkL8WMCfUr3xQK6dp4L A/KJeiqwk20kAc4R51ngFdF1yWRG1rVigtzMo/6UucQqzelowxOGZJxHaUobW54KQQyh 4Vfq6sClN+CgGSxAhHbDRGEn/ykooK8dQ47kjyQbpuy/t4jNb2/MjzN+MgvO5pASWl2O /80g== X-Gm-Message-State: ACgBeo2cMX98TsMtnrTcWKHsnVe2uy8M+2iAyUFJqf3JmNM4DJphRLdj B6DNGMa053SocOLdmDPSfHHfLw== X-Google-Smtp-Source: AA6agR5FiXtZ9BmQX6KCmb1jFq9Sn1Jf93cqLIli9ZyWSjqB65afzwKK1weUMhLUAwMqp9lmZDgNPQ== X-Received: by 2002:a05:6a00:1907:b0:534:f2ef:e8fe with SMTP id y7-20020a056a00190700b00534f2efe8femr48844002pfi.65.1662365783216; Mon, 05 Sep 2022 01:16:23 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id w12-20020aa79a0c000000b005363bc65bafsm7075864pfj.57.2022.09.05.01.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:16:22 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH RFC 4/7] zram: Introduce recompress sysfs knob Date: Mon, 5 Sep 2022 17:15:49 +0900 Message-Id: <20220905081552.2740917-8-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905081552.2740917-1-senozhatsky@chromium.org> References: <20220905081552.2740917-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=UHiLRbvm; spf=pass (imf14.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.171 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=1662365784; a=rsa-sha256; cv=none; b=G7dGbAtlKeU6FK+PGeuO7xQcLZEy5M4FB1UOnUv8s+zYOkDgtwW7fTZeBuGfrK9gVUYqt+ uRGVt77Gm1sWTWj3fBThdFEUL7U33nFoYiMdJrR/XAtNnBLM5VftFyWqA6uMjV9a+32526 tA6zITpLCL8421kWRIr4lwvf+o1h6hk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662365784; 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=apGSrKTgwETbH2CMEGMydpnHgs87JcMdkEf7eiEN8iQ=; b=3n7Fu7DWmgZuk4M1jbkllU32HL91qXZtEI2u3ppQmaBCCkINpDKKiS4cKyZM6lF/hTb/CO 863HJcr6n03rFtISG+tzLp83XkxaIhGsvphWi2q7vmHyT5cVFv5M1+uaUQXTuN6fyYzbmX MY94T3ZUlRCq9jCsHtLmTkN6DUfz3vY= X-Stat-Signature: xa6c6c6i7emk1kk84jofuty37jj68e8w X-Rspamd-Queue-Id: 334E7100052 X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=UHiLRbvm; spf=pass (imf14.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.171 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam07 X-HE-Tag: 1662365784-858254 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 recompress (using secondary compression streams) pages. We support three modes: 1) IDLE pages recompression is activated by `idle` mode echo idle > /sys/block/zram0/recompress 2) Since there may be many idle pages user-space may pass a size watermark value and we will recompress IDLE pages only of equal or greater size: echo 888 > /sys/block/zram0/recompress 3) HUGE pages recompression is activated by `huge` mode echo huge > /sys/block/zram0/recompress 4) HUGE_IDLE pages recompression is activated by `huge_idle` mode echo huge_idle > /sys/block/zram0/recompress Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/Kconfig | 11 ++ drivers/block/zram/zram_drv.c | 191 +++++++++++++++++++++++++++++++++- drivers/block/zram/zram_drv.h | 1 + 3 files changed, 200 insertions(+), 3 deletions(-) diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index d4100b0c083e..81ae4b96ec1a 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -78,3 +78,14 @@ config ZRAM_MEMORY_TRACKING /sys/kernel/debug/zram/zramX/block_state. See Documentation/admin-guide/blockdev/zram.rst for more information. + +config ZRAM_MULTI_COMP + bool "Enable multiple per-CPU compression streams" + depends on ZRAM + help + This will enable per-CPU multi-compression streams, so that ZRAM + can re-compress IDLE pages, using a potentially slower but more + effective compression algorithm. + + echo TIMEOUT > /sys/block/zramX/idle + echo SIZE > /sys/block/zramX/recompress diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index de2970865b7b..386e49a13806 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1293,6 +1293,9 @@ static void zram_free_page(struct zram *zram, size_t index) atomic64_dec(&zram->stats.huge_pages); } + if (zram_test_flag(zram, index, ZRAM_RECOMP)) + zram_clear_flag(zram, index, ZRAM_RECOMP); + if (zram_test_flag(zram, index, ZRAM_WB)) { zram_clear_flag(zram, index, ZRAM_WB); free_block_bdev(zram, zram_get_element(zram, index)); @@ -1357,6 +1360,7 @@ static int zram_read_from_zspool(struct zram *zram, unsigned long handle; unsigned int size; void *src, *dst; + u32 idx; int ret; handle = zram_get_handle(zram, index); @@ -1373,8 +1377,13 @@ static int zram_read_from_zspool(struct zram *zram, size = zram_get_obj_size(zram, index); - if (size != PAGE_SIZE) - zstrm = zcomp_stream_get(zram->comps[ZRAM_PRIMARY_ZCOMP]); + if (size != PAGE_SIZE) { + idx = ZRAM_PRIMARY_ZCOMP; + if (zram_test_flag(zram, index, ZRAM_RECOMP)) + idx = ZRAM_SECONDARY_ZCOMP; + + zstrm = zcomp_stream_get(zram->comps[idx]); + } src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); if (size == PAGE_SIZE) { @@ -1386,7 +1395,7 @@ static int zram_read_from_zspool(struct zram *zram, dst = kmap_atomic(page); ret = zcomp_decompress(zstrm, src, size, dst); kunmap_atomic(dst); - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_ZCOMP]); + zcomp_stream_put(zram->comps[idx]); } zs_unmap_object(zram->mem_pool, handle); return ret; @@ -1612,6 +1621,180 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, return ret; } +#ifdef CONFIG_ZRAM_MULTI_COMP +/* + * This function will decompress (unless it's ZRAM_HUGE) the page and then + * attempt to compress it using secondary compression algorithm (which is + * potentially more effective). + * + * Corresponding ZRAM slot should be locked. + */ +static int zram_recompress(struct zram *zram, + u32 index, + struct page *page, + int size_watermark) +{ + unsigned long handle_prev; + unsigned long handle_next; + unsigned int comp_len_next; + unsigned int comp_len_prev; + struct zcomp_strm *zstrm; + void *src, *dst; + int ret; + + handle_prev = zram_get_handle(zram, index); + if (!handle_prev) + return -EINVAL; + + comp_len_prev = zram_get_obj_size(zram, index); + /* + * Do not recompress objects that are already "small enough". + */ + if (comp_len_prev < size_watermark) + return 0; + + ret = zram_read_from_zspool(zram, page, index); + if (ret) + return ret; + + zstrm = zcomp_stream_get(zram->comps[ZRAM_SECONDARY_ZCOMP]); + src = kmap_atomic(page); + ret = zcomp_compress(zstrm, src, &comp_len_next); + kunmap_atomic(src); + + /* + * Either a compression error or we failed to compressed the object + * in a way that will save us memory. Mark object as "recompressed" + * if it's huge, so that we don't try to recompress it again. Ideally + * we want to set some bit for all such objects, but we for now do so + * only for huge ones (we are out of bits in flags on 32-bit systems). + */ + if (comp_len_next >= huge_class_size || + comp_len_next >= comp_len_prev || + ret) { + if (zram_test_flag(zram, index, ZRAM_HUGE)) + zram_set_flag(zram, index, ZRAM_RECOMP); + zram_clear_flag(zram, index, ZRAM_IDLE); + zcomp_stream_put(zram->comps[ZRAM_SECONDARY_ZCOMP]); + return ret; + } + + /* + * No direct reclaim (slow path) for handle allocation and no + * re-compression attempt (unlike in __zram_bvec_write()) since + * we already stored that object in zsmalloc. If we cannot alloc + * memory then me bail out. + */ + handle_next = zs_malloc(zram->mem_pool, comp_len_next, + __GFP_KSWAPD_RECLAIM | + __GFP_NOWARN | + __GFP_HIGHMEM | + __GFP_MOVABLE); + if (IS_ERR((void *)handle_next)) { + zcomp_stream_put(zram->comps[ZRAM_SECONDARY_ZCOMP]); + return -ENOMEM; + } + + dst = zs_map_object(zram->mem_pool, handle_next, ZS_MM_WO); + memcpy(dst, zstrm->buffer, comp_len_next); + zcomp_stream_put(zram->comps[ZRAM_SECONDARY_ZCOMP]); + + zs_unmap_object(zram->mem_pool, handle_next); + + zram_free_page(zram, index); + zram_set_handle(zram, index, handle_next); + zram_set_obj_size(zram, index, comp_len_next); + + zram_set_flag(zram, index, ZRAM_RECOMP); + atomic64_add(comp_len_next, &zram->stats.compr_data_size); + atomic64_inc(&zram->stats.pages_stored); + + return 0; +} + +#define RECOMPRESS_IDLE (1 << 0) +#define RECOMPRESS_HUGE (1 << 1) + +static ssize_t recompress_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t len) +{ + struct zram *zram = dev_to_zram(dev); + unsigned long nr_pages = zram->disksize >> PAGE_SHIFT; + unsigned long index; + struct page *page; + ssize_t ret = 0; + int mode, size_watermark = 0; + + if (sysfs_streq(buf, "idle")) { + mode = RECOMPRESS_IDLE; + } else if (sysfs_streq(buf, "huge")) { + mode = RECOMPRESS_HUGE; + } else if (sysfs_streq(buf, "huge_idle")) { + mode = RECOMPRESS_IDLE | RECOMPRESS_HUGE; + } else { + /* + * We will re-compress only idle objects equal or greater + * in size than watermark. + */ + ret = kstrtoint(buf, 10, &size_watermark); + if (ret) + return ret; + mode = RECOMPRESS_IDLE; + } + + if (size_watermark > PAGE_SIZE) + return ret; + + down_read(&zram->init_lock); + if (!init_done(zram)) { + ret = -EINVAL; + goto release_init_lock; + } + + page = alloc_page(GFP_KERNEL); + if (!page) { + ret = -ENOMEM; + goto release_init_lock; + } + + for (index = 0; index < nr_pages; index++) { + zram_slot_lock(zram, index); + + if (!zram_allocated(zram, index)) + goto next; + + if (mode & RECOMPRESS_IDLE && + !zram_test_flag(zram, index, ZRAM_IDLE)) + goto next; + + if (mode & RECOMPRESS_HUGE && + !zram_test_flag(zram, index, ZRAM_HUGE)) + goto next; + + if (zram_test_flag(zram, index, ZRAM_WB) || + zram_test_flag(zram, index, ZRAM_UNDER_WB) || + zram_test_flag(zram, index, ZRAM_SAME) || + zram_test_flag(zram, index, ZRAM_RECOMP)) + goto next; + + ret = zram_recompress(zram, index, page, size_watermark); +next: + zram_slot_unlock(zram, index); + if (ret) + break; + } + + ret = len; + __free_page(page); + +release_init_lock: + up_read(&zram->init_lock); + return ret; +} +#endif + /* * zram_bio_discard - handler on discard request * @index: physical block index in PAGE_SIZE units @@ -2001,6 +2184,7 @@ static DEVICE_ATTR_RW(writeback_limit_enable); #endif #ifdef CONFIG_ZRAM_MULTI_COMP static DEVICE_ATTR_RW(recomp_algorithm); +static DEVICE_ATTR_WO(recompress); #endif static struct attribute *zram_disk_attrs[] = { @@ -2027,6 +2211,7 @@ static struct attribute *zram_disk_attrs[] = { &dev_attr_debug_stat.attr, #ifdef CONFIG_ZRAM_MULTI_COMP &dev_attr_recomp_algorithm.attr, + &dev_attr_recompress.attr, #endif NULL, }; diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index af3d6f6bfcff..b4eecef2a11f 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -50,6 +50,7 @@ enum zram_pageflags { ZRAM_UNDER_WB, /* page is under writeback */ ZRAM_HUGE, /* Incompressible page */ ZRAM_IDLE, /* not accessed page since last idle marking */ + ZRAM_RECOMP, /* page was recompressed */ __NR_ZRAM_PAGEFLAGS, }; From patchwork Mon Sep 5 08:15:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965754 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 0CDBEC6FA89 for ; Mon, 5 Sep 2022 08:16:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69465801C1; Mon, 5 Sep 2022 04:16:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61EDB801B3; Mon, 5 Sep 2022 04:16:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BD46801C1; Mon, 5 Sep 2022 04:16:27 -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 345AA801B3 for ; Mon, 5 Sep 2022 04:16:27 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0BCAAAB61E for ; Mon, 5 Sep 2022 08:16:27 +0000 (UTC) X-FDA: 79877324814.01.078C678 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf06.hostedemail.com (Postfix) with ESMTP id BF0E8180060 for ; Mon, 5 Sep 2022 08:16:26 +0000 (UTC) Received: by mail-pf1-f178.google.com with SMTP id y127so7964018pfy.5 for ; Mon, 05 Sep 2022 01:16:26 -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; bh=ARMalt43cGQStsEP0fAYz16MOL60Ugpll7VhrHzWrN4=; b=cQVKvubgWaoRbZYTjgiOV04EQaA+PJkhinoKlPFno51F4mzronmiF7U+mwYxvF4s3Q 5MM6S8ICClfNa3uBwdz8UY2mlEFwhSxCfGXTPdxqT8WWBu42rdP7LQcLzDKvyWW73kts Q8Wwk1DHyX5Ob0hWV2EYNohECRVz9LUuGJxkg= 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; bh=ARMalt43cGQStsEP0fAYz16MOL60Ugpll7VhrHzWrN4=; b=Rq1ObX3oe0aSRipXd1MwNQINT/uYcNezZr/G9M/ZCHoWvOtigtx+4M7KLmPQHafTzW dld/BPVMAuRHAD1aNoSC8klm+d56UELXtfQfHGuB+BzZr3pvw2feB64+lPBxV0/wgVxY sfX0FXNy2TNKMkPN9uK83Vhv6+y7FogE7TTK+EuLPyzLTnD2v0FEbbFC46WmcBeFBedT AvsNImoOtAU6k35u9baH0u+uz/qzOsW5reu3Ymb6ExE3d3GFOOZla3X7QG2vE6Ivd6AA SwNlUsH4FGyljlj+25XmiYOKQUz2OrH3kaCSXf+JvR+NtwFT1bC9kl/weuX/1eGSsOUs bmHg== X-Gm-Message-State: ACgBeo3Tzo1AXismrNzi/eh8Bxo/Gf9y3bSVMnZMVfKIHlKu3hIkdfYx 41AhztzgafjXu614Z9p5oUdjMA== X-Google-Smtp-Source: AA6agR6Y13UabkGj2Pw1xPeKlx9CcnBMiy4uG1v3LoUZbuUY3pNQYy723yfvhdQOcHQZVmLZNUpHkQ== X-Received: by 2002:a63:e317:0:b0:432:38c0:bde3 with SMTP id f23-20020a63e317000000b0043238c0bde3mr10927879pgh.567.1662365785944; Mon, 05 Sep 2022 01:16:25 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id w12-20020aa79a0c000000b005363bc65bafsm7075864pfj.57.2022.09.05.01.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:16:25 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH RFC 5/7] documentation: Add recompression documentation Date: Mon, 5 Sep 2022 17:15:50 +0900 Message-Id: <20220905081552.2740917-9-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905081552.2740917-1-senozhatsky@chromium.org> References: <20220905081552.2740917-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=1662365786; 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=ARMalt43cGQStsEP0fAYz16MOL60Ugpll7VhrHzWrN4=; b=c5PmU9G1qPXBEkAqfdXGZ3byMU1QzgO+Mm+AUQgGAkVjesSAxWzBHJEyVUl+1MbmyZcS3I +9w7iedf5FBThET8XytFJYdmR7+ExMQV5GigOeIOipD3+LEGvGhY5WzUmNxcyow9peQrtn SCZ+6nGPKhctYOqhjviDdyYQmQvLu/E= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=cQVKvubg; spf=pass (imf06.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.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=1662365786; a=rsa-sha256; cv=none; b=poiAEquvLiofOqpAdnwCIrO+q8cxkkM++E8Oj5XqapuSKTpg4HQhkzIKRqPV9iK2X6OKrB N4tSD9Ks2JSuRuFzcyv8qqPZ4C66no0wb6OBkxtYVh2hnxYoRFlVK+iS8W2A8oBpk7S8Bq RGzdvZNjzG2rlfi5HhfbsYCgK9NtTPo= X-Rspam-User: X-Stat-Signature: ts46ajpcz1juopnxqua6nz83t1hebano X-Rspamd-Queue-Id: BF0E8180060 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=cQVKvubg; spf=pass (imf06.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.178 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam04 X-HE-Tag: 1662365786-964623 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: Document user-space visible device attributes that are enabled by ZRAM_MULTI_COMP. Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/blockdev/zram.rst | 55 +++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index c73b16930449..88957fcb6ad7 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -401,6 +401,61 @@ budget in next setting is user's job. If admin wants to measure writeback count in a certain period, they could know it via /sys/block/zram0/bd_stat's 3rd column. +recompression +------------- + +With CONFIG_ZRAM_MULTI_COMP, zram can recompress idle/huge pages using +alternative (secondary) compression algorithm. The basic idea is that +alternative compression algorithm can provide better compression ratio +at a price of (potentially) slower compression/decompression speeds. +Alternative compression algorithm can, for example, be more successful +compressing huge pages (those that default algorithm failed to compress). +Another application is idle pages recompression - pages that are cold and +sit in the memory can be recompressed using more effective algorithm and, +hence, reduce zsmalloc memory usage. + +With CONFIG_ZRAM_MULTI_COMP, zram will setup two compression algorithms +per-CPU: primary and secondary ones. Primary zram compressor is explained +in "3) Select compression algorithm", the secondary algorithm is configured +in a similar way, using recomp_algorithm device attribute: + +Examples:: + + #show supported recompression algorithms + cat /sys/block/zramX/recomp_algorithm + zstd [lzo] + + #select zstd recompression algorithm + echo zstd > /sys/block/zramX/recomp_algorithm + +Another device attribute that CONFIG_ZRAM_MULTI_COMP enables is recompress, +which controls recompression: + +Examples:: + + #IDLE pages recompression is activated by `idle` mode + echo idle > /sys/block/zramX/recompress + + #HUGE pages recompression is activated by `huge` mode + echo huge > /sys/block/zram0/recompress + + #HUGE_IDLE pages recompression is activated by `huge_idle` mode + echo huge_idle > /sys/block/zramX/recompress + +The number of idle pages can be significant, so user-space can pass a size +watermark value to the recompress knob, to filter out idle pages for +recompression: zram will recompress only idle pages of equal or greater +size::: + + #recompress idle pages larger than 3000 bytes + echo 3000 > /sys/block/zramX/recompress + + #recompress idle pages larger than 2000 bytes + echo 2000 > /sys/block/zramX/recompress + +Recompression is mostly focused on idle pages (except for huge pages +recompression), so it works better in conjunction with memory tracking. + memory tracking =============== From patchwork Mon Sep 5 08:15:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965755 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 B97B1C6FA86 for ; Mon, 5 Sep 2022 08:16:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42343801C2; Mon, 5 Sep 2022 04:16:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D370801B3; Mon, 5 Sep 2022 04:16:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24BD4801C2; Mon, 5 Sep 2022 04:16:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 10E0F801B3 for ; Mon, 5 Sep 2022 04:16:30 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E118014042A for ; Mon, 5 Sep 2022 08:16:29 +0000 (UTC) X-FDA: 79877324898.15.77EBA55 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf17.hostedemail.com (Postfix) with ESMTP id 8F05140062 for ; Mon, 5 Sep 2022 08:16:29 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id l3so7788273plb.10 for ; Mon, 05 Sep 2022 01:16:29 -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; bh=/AdpGVT0N/8ncggFEAw2LdRk7MFt3IthPSmEwk0XZqA=; b=Hw2je1UG8XBw4S6KF2eztarDlGqDR7b6mYLkyxsePPDKfXtIzSyxOrRsC6suIVuFd1 PXhuVKumBnRA+eXRMjTZJYC5M7lGz+HLTNrfyUmbGTig+61BjAs1cc8AVLVBEgCT5G1j isnAh3f2NDdAhhXALa85JKduwraI3xY/CxgU8= 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; bh=/AdpGVT0N/8ncggFEAw2LdRk7MFt3IthPSmEwk0XZqA=; b=RypzcriIhUM0x4fcofgKtOwwEIC3FRzE6m5663T4FfKZyagHmKaMGxmJruyAf8acOS Q6OrQpLt1HmCSB2T9b0OwSaGjgPvVsswlev5nX7VbBKq+6p4qxQQDeFwiWEFLS4SCA+4 cOYHmW4w7D7KpdPl79HWZB+ATIvRfcE+nUpOJLWb5wh9ujijS0zmETyKvtwVm0YaNJlZ haMCtN3yD7PPPzQLKvi/0dR7yEeEQbt5Bcfv4TmQdyvAYVyyo6fvbjRe6NkhGEINe0vB mOBvF1Y+oSKn1qk4uBlBytnoA2HbnI64EDrAmW9sPs1UNZ7GMlusCEh5BwoXdydrA4A2 HepQ== X-Gm-Message-State: ACgBeo0kA/XW4DM8K8srSZJxP/a7nzPYEnHUIUcz0eVbnGYOaHD4C2eS 7hic5e6HwWd9NLG0msUtrMHwOQ== X-Google-Smtp-Source: AA6agR4niiO1u8IFNIJZJRvYw1HVm7TuxwF5Dj8VtySPmiKR9n2jVVoA+BZnoNvLqcrPIjdizmJkZw== X-Received: by 2002:a17:902:c40a:b0:174:7d05:97cd with SMTP id k10-20020a170902c40a00b001747d0597cdmr41363380plk.34.1662365788696; Mon, 05 Sep 2022 01:16:28 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id w12-20020aa79a0c000000b005363bc65bafsm7075864pfj.57.2022.09.05.01.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:16:28 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH RFC 6/7] zram: Add recompression algorithm choice to Kconfig Date: Mon, 5 Sep 2022 17:15:51 +0900 Message-Id: <20220905081552.2740917-10-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905081552.2740917-1-senozhatsky@chromium.org> References: <20220905081552.2740917-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Hw2je1UG; spf=pass (imf17.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.176 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=1662365789; a=rsa-sha256; cv=none; b=P+a4RM8qFzQFVvW4mE4+WqhH2M8a6w/J3ZOrxfoOm8asLjry5ZyGVhTmAkGOFWHspjeubj lr+cQEbk7Nahh8HcBzu6TjklfJMBueIXtm7Ehzr+QZiVYxGqRBSqSsQ14b5Q4EGA2tSjrk fGkUE7uNP1p5xj3Pz6fdGlHhZxh6uP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662365789; 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=/AdpGVT0N/8ncggFEAw2LdRk7MFt3IthPSmEwk0XZqA=; b=WG9+tlJbBRKYcnSnC7j79w0h5dm0Dh6quaRQuViFIqZtJWhiLioyYPZM7MN/5skGVAzjag cM8v53L5oMR+r1pNFPAuCZiRaaw+jH7EVRdG7mn7ioil+RT5WmRlLctNIHkV7H+9vnHXb4 YOpZExrfGuAtCqoTafP9S/f+G19W7CU= Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Hw2je1UG; spf=pass (imf17.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.176 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam06 X-Stat-Signature: g1oy9wozyc8uz513awtzg9fa5z5g6ifk X-Rspam-User: X-Rspamd-Queue-Id: 8F05140062 X-HE-Tag: 1662365789-660076 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: Make (secondary) recompression algorithm selectable just like we do it for the (primary) default one. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/Kconfig | 40 +++++++++++++++++++++++++++++++++++ drivers/block/zram/zram_drv.c | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index 81ae4b96ec1a..fc2d4d66c484 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -89,3 +89,43 @@ config ZRAM_MULTI_COMP echo TIMEOUT > /sys/block/zramX/idle echo SIZE > /sys/block/zramX/recompress + +choice + prompt "Default zram recompression algorithm" + default ZRAM_DEF_RECOMP_ZSTD + depends on ZRAM && ZRAM_MULTI_COMP + +config ZRAM_DEF_RECOMP_LZORLE + bool "lzo-rle" + depends on CRYPTO_LZO + +config ZRAM_DEF_RECOMP_ZSTD + bool "zstd" + depends on CRYPTO_ZSTD + +config ZRAM_DEF_RECOMP_LZ4 + bool "lz4" + depends on CRYPTO_LZ4 + +config ZRAM_DEF_RECOMP_LZO + bool "lzo" + depends on CRYPTO_LZO + +config ZRAM_DEF_RECOMP_LZ4HC + bool "lz4hc" + depends on CRYPTO_LZ4HC + +config ZRAM_DEF_RECOMP_842 + bool "842" + depends on CRYPTO_842 + +endchoice + +config ZRAM_DEF_RECOMP + string + default "lzo-rle" if ZRAM_DEF_RECOMP_LZORLE + default "zstd" if ZRAM_DEF_RECOMP_ZSTD + default "lz4" if ZRAM_DEF_RECOMP_LZ4 + default "lzo" if ZRAM_DEF_RECOMP_LZO + default "lz4hc" if ZRAM_DEF_RECOMP_LZ4HC + default "842" if ZRAM_DEF_RECOMP_842 diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 386e49a13806..8ed41514b8f0 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -44,7 +44,7 @@ static int zram_major; static const char *default_comp_algs[ZRAM_MAX_ZCOMPS] = { CONFIG_ZRAM_DEF_COMP, #ifdef CONFIG_ZRAM_MULTI_COMP - "zstd", + CONFIG_ZRAM_DEF_RECOMP, #endif }; From patchwork Mon Sep 5 08:15:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12965756 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 88B64ECAAD5 for ; Mon, 5 Sep 2022 08:16:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24E58801C3; Mon, 5 Sep 2022 04:16:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D7E6801B3; Mon, 5 Sep 2022 04:16:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07739801C3; Mon, 5 Sep 2022 04:16:33 -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 E3A5B801B3 for ; Mon, 5 Sep 2022 04:16:32 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BEE9E80A5F for ; Mon, 5 Sep 2022 08:16:32 +0000 (UTC) X-FDA: 79877325024.09.013E4B7 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf11.hostedemail.com (Postfix) with ESMTP id 5D2A240058 for ; Mon, 5 Sep 2022 08:16:32 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id m10-20020a17090a730a00b001fa986fd8eeso11508591pjk.0 for ; Mon, 05 Sep 2022 01:16:32 -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; bh=E05eGk8Ts+47tHWXcyTeAoJzHa+CPKznHpzjFQelL1A=; b=hMS+IdYeixaOeejH5EwOkVTb7PSDps8WRjK2zDsDcvJagB44S5pczLIA0n7xt4fWkF y7fQyebX8JoLNjuppKKvDKTSDodtB/M2YUQEmIt38THD7x0Xn8C76iEZuQNdT552aia3 asNk2qfqEbclqbbGAYcB2fgt4+f6tZDmr0vlM= 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; bh=E05eGk8Ts+47tHWXcyTeAoJzHa+CPKznHpzjFQelL1A=; b=BOP6p0rziACfcp1hxGiaGi6KfnuLZY4aLHVRKW5KpjjtnrmBlo3hHX+/SP2jGqbfAL hwaw/2aiQMlh1MWCs0QUPHBVirqD+hzEvRl1vk26/Pe7rwnOTmTS0bUIj9TvzFRGLw6P cxMuYAVMgKtEnMF1AkAng9MOpKe5BrVT6hGy7ARWD9UFWVzHkYF98omDu3BCvB7NVmyk 0lk84T/RTqlYRU3UrTV/YLaVf7vP9YtaU98//F4EfG7DFRSM7C8EpC0tgRqSdIC1uYt1 O/uTN7pI42DXmkLnozQbmzsaUWjNpDlhHflhkmYc1nCAuRJUeGHuhKSS6qQjuXjH68we 3riA== X-Gm-Message-State: ACgBeo3fkzre+SFeDzA35Y6mzx4++PjTkmAA75BbgImof8VqcP7kKWBP iFDfNsIjKl21QHfWR1etMKRC4w== X-Google-Smtp-Source: AA6agR4p0z+bcR3JUyMiCUus7SiZk2eqFN83s+Wa8NeayAXFyNRr4Yegge5viZfyXgvXyX7C4DNfyw== X-Received: by 2002:a17:90b:30d0:b0:200:22a4:bfcf with SMTP id hi16-20020a17090b30d000b0020022a4bfcfmr10363568pjb.181.1662365791490; Mon, 05 Sep 2022 01:16:31 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:71e2:8444:42d9:4bb0]) by smtp.gmail.com with ESMTPSA id w12-20020aa79a0c000000b005363bc65bafsm7075864pfj.57.2022.09.05.01.16.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 01:16:30 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH RFC 7/7] zram: Add recompress flag to read_block_state() Date: Mon, 5 Sep 2022 17:15:52 +0900 Message-Id: <20220905081552.2740917-11-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220905081552.2740917-1-senozhatsky@chromium.org> References: <20220905081552.2740917-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662365792; a=rsa-sha256; cv=none; b=oHLQJ9SLfgSCOjYqwXwBe4ls0I4rheLUdYwiHpcr2Mh3DTJGwOT19f1wwtmzZlqBC1BR/+ XrJILdvAV43h8nThdt63z1n/EokN2B4yqmy/wLwsPWldEE6Igw/z0F1cyhVGBMpLY7HQzn rTEnOKYLDZtr+4uBl+4t0+gZEbReq6o= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=hMS+IdYe; spf=pass (imf11.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.46 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662365792; 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=E05eGk8Ts+47tHWXcyTeAoJzHa+CPKznHpzjFQelL1A=; b=2zFFisamfDpb4HQV2DIDl77UWzCiyTrSKXNVGc68RaFppAwNcY3ioUX9nU0PLA5m8rebT3 oAOkybHtLqjJvgL57/Yii6gEt5eET317msEvnOi6pkd1VZWzyUpL627frzaCAmw1urDzZ7 G8I7EOWF5+iAA3RegZYjGAYg3exdS2w= X-Rspam-User: X-Stat-Signature: porayzbuup8ef48iuocpkmbet4n15nbn X-Rspamd-Queue-Id: 5D2A240058 X-Rspamd-Server: rspam10 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=hMS+IdYe; spf=pass (imf11.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.46 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-HE-Tag: 1662365792-822708 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: Add a new flag to zram block state that shows if the page was recompressed (using alternative compression algorithm). Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/blockdev/zram.rst | 9 ++++++--- drivers/block/zram/zram_drv.c | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index 88957fcb6ad7..70a3d0243b45 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -466,9 +466,10 @@ pages of the process with*pagemap. If you enable the feature, you could see block state via /sys/kernel/debug/zram/zram0/block_state". The output is as follows:: - 300 75.033841 .wh. - 301 63.806904 s... - 302 63.806919 ..hi + 300 75.033841 .wh.. + 301 63.806904 s.... + 302 63.806919 ..hi. + 303 62.801919 ....r First column zram's block index. @@ -485,6 +486,8 @@ Third column huge page i: idle page + r: + recompressed page (secondary compression algorithm) First line of above example says 300th block is accessed at 75.033841sec and the block's state is huge so it is written back to the backing diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 8ed41514b8f0..f3948abce2f7 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -936,13 +936,14 @@ static ssize_t read_block_state(struct file *file, char __user *buf, ts = ktime_to_timespec64(zram->table[index].ac_time); copied = snprintf(kbuf + written, count, - "%12zd %12lld.%06lu %c%c%c%c\n", + "%12zd %12lld.%06lu %c%c%c%c%c\n", index, (s64)ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC, zram_test_flag(zram, index, ZRAM_SAME) ? 's' : '.', zram_test_flag(zram, index, ZRAM_WB) ? 'w' : '.', zram_test_flag(zram, index, ZRAM_HUGE) ? 'h' : '.', - zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.'); + zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.', + zram_test_flag(zram, index, ZRAM_RECOMP) ? 'r' : '.'); if (count <= copied) { zram_slot_unlock(zram, index);