From patchwork Wed Oct 5 02:40:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12998838 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 E14EDC433F5 for ; Wed, 5 Oct 2022 02:40:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C8796B007B; Tue, 4 Oct 2022 22:40:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 779196B007D; Tue, 4 Oct 2022 22:40:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 640076B007E; Tue, 4 Oct 2022 22:40:36 -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 5295A6B007B for ; Tue, 4 Oct 2022 22:40:36 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1D52BA05C0 for ; Wed, 5 Oct 2022 02:40:36 +0000 (UTC) X-FDA: 79985342472.17.D867814 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf10.hostedemail.com (Postfix) with ESMTP id 8BD44C000B for ; Wed, 5 Oct 2022 02:40:35 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id 3so14230521pga.1 for ; Tue, 04 Oct 2022 19:40:35 -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=OE2FzWZV+eK+0K5lMxD8PaF7VIaG8/7NL+uSrdg3shk=; b=IYWm7+uiUJMlmGAxYUFbJ3Y2TQXm4KOiJQvfkQpRrYYY3E7rL+drqW7q86flsucQI+ D8O0A24NGkLEjU7Vsd2djdz6g1zvo8xNuVRfcW6JgcdLJYXBh+qzuLi/CKtYYlXQ74Qk zYPJZeeH/rjb4G2p0RPHLBjM5kFPujSiPtVF8= 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=OE2FzWZV+eK+0K5lMxD8PaF7VIaG8/7NL+uSrdg3shk=; b=p7SctaGrpVRYHBCiDJrD/TyrvmqKWy60bVwJO0gNahjrRilYA7WprqmO0U7ZcS+zyv EShuVzibmrwOCIBwqgp9PNta7w3RvYXkFVjRQFAEsidYVS0d2+eSq534IDJHWQATrwwh blk4Kg/8jFbhizPl3pSqx523BBxjVyZoN/a1/pnTMzNtDEw6oTQGIombT9mDR0xzreW4 guoBSq9X6dQX+ctuUSGiy44QjhCW6hMSZfMAVqnHje1sCzlnISg0RSVt9ejnUOUtlUFu Ib8vZjRTEDVV5RzTjxQ+U68LzZkf5Bn5OFDfJ/VWc3xIB+pejsjMpRXx2ASmIddyjWRF jzSQ== X-Gm-Message-State: ACrzQf1DnSo3CxyKU+K6KQ9ylbuNU5HPr48tHM93qvOVskw+ZY0zpoi6 oR2i1V9EXhf8o8lHUZBlvGeX3OmgPPxG0g== X-Google-Smtp-Source: AMsMyM7LvfXGCUBNVeyayt3p5M2B1olhIPbKqEPWsqDdIwx3njBFDBv51oEjFvZ0UTnMdcsvzhllhQ== X-Received: by 2002:a65:6908:0:b0:44e:1349:1108 with SMTP id s8-20020a656908000000b0044e13491108mr11473463pgq.180.1664937634586; Tue, 04 Oct 2022 19:40:34 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:a9d9:6396:ee12:8be8]) by smtp.gmail.com with ESMTPSA id a14-20020aa794ae000000b00561e010a309sm1673579pfl.19.2022.10.04.19.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 19:40:34 -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: [PATCHv2 5/8] documentation: Add recompression documentation Date: Wed, 5 Oct 2022 11:40:11 +0900 Message-Id: <20221005024014.22914-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221005024014.22914-1-senozhatsky@chromium.org> References: <20221005024014.22914-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664937635; a=rsa-sha256; cv=none; b=WtCTlPgW6QE1qXHPGaNAPI/niDaL+nHzOaRWU7dfkdl/zpey3OKcj8KXmP8OX+vDNoOqPb +Iu51P5zxLHtxxRw0g0mu3dRkYFFgxnkDd77c7eScC4YsvfrqIXVMeuTG8ruO09B9Ey+JR uq2wU0eEOyAQ4sA8iJbuMzpvrMtNTP0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=IYWm7+ui; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf10.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.170 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664937635; 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=OE2FzWZV+eK+0K5lMxD8PaF7VIaG8/7NL+uSrdg3shk=; b=ARFu/luzR+tgx/7ewwD5vFjD9SXzdn1SL+kyAnd4mTpP6phjYzyrRmue2+dZRmv5dVBYrf 33ytNrip6686eCj2KeiHQABmby/LT0tDXA57TDUPLMUUQ9qEzNHFtSD74jQq1yIHDJMKQl W6eLqp9ye2+BVM2mrCA6sAREtdoo0yc= X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=IYWm7+ui; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf10.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.170 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Stat-Signature: u63xgdxcsoi5nxkkmez1qqpg7u6zm987 X-Rspamd-Queue-Id: 8BD44C000B X-Rspamd-Server: rspam09 X-HE-Tag: 1664937635-571338 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 +++++++++++++++++++++ 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 aacabaefb0c7..077a0bc60b8d 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1622,9 +1622,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; @@ -1707,8 +1705,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;