From patchwork Sun Oct 9 09:07:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13001948 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 67E5BC433F5 for ; Sun, 9 Oct 2022 09:07:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E818F6B0078; Sun, 9 Oct 2022 05:07:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E34CA6B007B; Sun, 9 Oct 2022 05:07:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD2CC6B007D; Sun, 9 Oct 2022 05:07:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B6BFE6B0078 for ; Sun, 9 Oct 2022 05:07:40 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7AA6DC0998 for ; Sun, 9 Oct 2022 09:07:40 +0000 (UTC) X-FDA: 80000833080.12.001B9F8 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf25.hostedemail.com (Postfix) with ESMTP id EE44BA0017 for ; Sun, 9 Oct 2022 09:07:39 +0000 (UTC) Received: by mail-pf1-f173.google.com with SMTP id p14so4110625pfq.5 for ; Sun, 09 Oct 2022 02:07:39 -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=OqM9mWTVfbPsXUXKnKUtd3WdYMNua/MWINqYRXykEKs=; b=RKbrhKqsTOg+IHSg3cwCrTY4ZG/+LpdneXqRPTBTZgcz5VO3HHb+9AxHDxUZ3Jb2gQ W9+FolOVoU5RPYyTNGMx8TF2g/qhCoAGnRJ1xhcEuqFdZ+9luHiMWlVruTmUYFSKhdIu PYKfmU+qpJwUkcvfrhZk58dMiWNXxIm3cM5kU= 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=OqM9mWTVfbPsXUXKnKUtd3WdYMNua/MWINqYRXykEKs=; b=P0TdbG4FcnCjq7aU/wXCU8UQWrW5KeaimTVkgzArvoRmx2PkrkyuUlEwQADbUJRswa r9rUo1yj/M4QEpHI8uqaVFLUoURFdMMY6WruE45bcihAvqy/0jrwo+e/98J3Ri5qAizA mI5Wjr4ks1DKyiaXgWJ9GETgiGwLeUaGUOwK6i424kO3vic2kOfvSngl6BvbW+SzgVFe f8DYkgIZDpqUaU3UxYiLVnynvRSHOObQmtCoALtykXCmKJIPV4BmewAV4WCFI5h9gF9W zBEnyVNDllztyMbr22lP1RuTuzjbk+dreJJoC0HuxYw5Fsd1Bk5DWq71V48xVLaaIfbt nxLA== X-Gm-Message-State: ACrzQf0VVA/WtWdJMoq6DyeGz40Zb4cdVuP1As8iW7gNZPDGbqIgzG/V IXaMSFAPxd8LiXDtDx4BNkitdGtdHFxTRA== X-Google-Smtp-Source: AMsMyM67guaiwP/QYUJO3S8X8Xt6xiCerRRailhF+6FA6YUQCxdLbbWRbAwLSAGadIpcgCrGmDFfEA== X-Received: by 2002:a63:90ca:0:b0:458:f28d:917e with SMTP id a193-20020a6390ca000000b00458f28d917emr11934116pge.201.1665306458975; Sun, 09 Oct 2022 02:07:38 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:8517:d51e:5fe9:9be7]) by smtp.gmail.com with ESMTPSA id q194-20020a632acb000000b00439d071c110sm4335148pgq.43.2022.10.09.02.07.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Oct 2022 02:07:38 -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: [PATCHv3 5/8] documentation: Add recompression documentation Date: Sun, 9 Oct 2022 18:07:17 +0900 Message-Id: <20221009090720.1040633-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221009090720.1040633-1-senozhatsky@chromium.org> References: <20221009090720.1040633-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=RKbrhKqs; spf=pass (imf25.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.173 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=1665306460; a=rsa-sha256; cv=none; b=OLBXP5L8srvheb/QKvgdMlmc2WcPGjWf2CB9a2SHblqpNfNgR/QLshTnAbY4Dw9Wgex77J AwTX6yOrSILWTpOTSNXSQPUZY24HEov/n3F0rn6vPt1M6ycX6eMaEzOefQ82Gcp9NAMJm/ ptevaT5XPH4C7DWLl/qNkKEPVcjApCA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665306460; 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=OqM9mWTVfbPsXUXKnKUtd3WdYMNua/MWINqYRXykEKs=; b=lpquKpSm0lQW4QMZ6jE1InR9ljF8OmK7BskRdvx+FLw4K586m5c+yhucecpO6O/UwTvKa4 ZCWiX1HSKX1TRm/KkDbtSNTwIDO/GOBifFaPGKzhzwQ5NcOuEyS1rfTJD0lfflECne+Zjy xaZin5LjulDAPrB1R5FjSQM1h381wFQ= X-Rspamd-Queue-Id: EE44BA0017 X-Rspam-User: Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=RKbrhKqs; spf=pass (imf25.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.173 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam10 X-Stat-Signature: wdaauem1i8ijsxjh7bxrm53ep8oczx8c X-HE-Tag: 1665306459-744150 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 Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/blockdev/zram.rst | 55 +++++++++++++++++++++ drivers/block/zram/zram_drv.c | 7 +-- 2 files changed, 57 insertions(+), 5 deletions(-) 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 =============== diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 12368e773f3d..143c33bd6783 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1623,9 +1623,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, * * Corresponding ZRAM slot should be locked. */ -static int zram_recompress(struct zram *zram, - u32 index, - struct page *page, +static int zram_recompress(struct zram *zram, u32 index, struct page *page, int size_watermark) { unsigned long handle_prev; @@ -1708,8 +1706,7 @@ static int zram_recompress(struct zram *zram, static ssize_t recompress_store(struct device *dev, struct device_attribute *attr, - const char *buf, - size_t len) + const char *buf, size_t len) { struct zram *zram = dev_to_zram(dev); unsigned long nr_pages = zram->disksize >> PAGE_SHIFT;