From mboxrd@z Thu Jan 1 00:00:00 1970 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 70F1CC4332F for ; Wed, 9 Nov 2022 11:51:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E033A8E0003; Wed, 9 Nov 2022 06:51:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DB4966B0078; Wed, 9 Nov 2022 06:51:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7D948E0003; Wed, 9 Nov 2022 06:51:47 -0500 (EST) 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 B7ECF6B0075 for ; Wed, 9 Nov 2022 06:51:47 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 97FA61414D6 for ; Wed, 9 Nov 2022 11:51:47 +0000 (UTC) X-FDA: 80113739454.22.1D70488 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf22.hostedemail.com (Postfix) with ESMTP id 40311C001E for ; Wed, 9 Nov 2022 11:51:47 +0000 (UTC) Received: by mail-pf1-f179.google.com with SMTP id q9so16463472pfg.5 for ; Wed, 09 Nov 2022 03:51:46 -0800 (PST) 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=78mZXjDUqjc2CGPH2b0kN46OixnL1hoGKm7bE9XBgUM=; b=IYn1pZPbT037tiskU40SdcUjr00Tb2lBA9rYT1D2KmHOqM8EdBQ1VdZg5ulYfsHP9S 6TKjKXb8ojMut+VZdnTW4d1VRfI7CfvfRNdt+nviVa7k35eGqRtMxtMJsHHgyGLW1otC FMK6emkiAqsGvvLekKvM1N8+He8/Dg8Ekinew= 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=78mZXjDUqjc2CGPH2b0kN46OixnL1hoGKm7bE9XBgUM=; b=0bckO0bxozWdGbiPCTkkLoTWUdrjf1AwN3kcYv3r4vTfepYlNDGQdaH3UKDQOnmNAd M2EfOPsaXNFo1yQcA5bUmsRqVDzpzwqrs/qtVWbeYM6Q17OBwDrECoSuL4jR7W/ygLtk GCuA3z0wgMGazrTKlMNmTfIoVIyDvhvWBIPvd5Eg2orSP9EdhQXoSCC++zHszfQMgGmD AXP8ZZ9+TGJMkSHhm0syDIQOzIiA3fbhNdziAFYx8w7k4bFTcwJG1fdsSVgVvqKgPesv 4vzazShQ/c4XwnuklttK8UeBLFfkHUSPy5WHdKi7lHf1JC1fIwGckRi3S4taTBz0zGYZ TbLw== X-Gm-Message-State: ACrzQf1x0sZhXsIbRuNiKbS42OCe66QE1kLTqiazbGVRrVfcU2gInkOj pjXjFVIm0YTeBUU9qPdN9RTtpQ== X-Google-Smtp-Source: AMsMyM4evVnWSvLkw+dSHbFX3CGE0wpnSBNFc155E+fkSbYY7z5M05e2ebLt+A3Ah2OBlfptSutn1w== X-Received: by 2002:a05:6a02:113:b0:43f:3554:ff9c with SMTP id bg19-20020a056a02011300b0043f3554ff9cmr52961284pgb.578.1667994683200; Wed, 09 Nov 2022 03:51:23 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:51:22 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 11/13] documentation: Add zram recompression documentation Date: Wed, 9 Nov 2022 20:50:45 +0900 Message-Id: <20221109115047.2921851-12-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-1-senozhatsky@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667994707; a=rsa-sha256; cv=none; b=Gh9ynqSimCD6zFoLt3yFtYYJTtLc8D53FOguMUwXqA7Rc65vgawOYN5Mxt+AR8zJBnS5Su Lxv4Wk4mX3TQkBCr87cnDjOPSe5KXYNnLII3Ov/rFNXBMeDul9yXxUHeU1/Bv+KZ9KGTVI ndi4nDox5h2BMGG8Adnmd3opWcxyg9I= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=IYn1pZPb; spf=pass (imf22.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=1667994707; 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=78mZXjDUqjc2CGPH2b0kN46OixnL1hoGKm7bE9XBgUM=; b=yrT87XxIZ/U1IV74bYtcl3NVU1eN+LLBwJyCr6e5uK2CACrGMgQObBLYClhkPfTqEqZBcD +BIdoHksqQMWh0R0sOky/6jWVoiXy9U7wrDSrrflWGqQZrR69clBA7iOc5ptzli0YwfWts W5Y5JWYVQ1M5N2MN6ZakewqAUb4S7UQ= Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=IYn1pZPb; spf=pass (imf22.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: rspam12 X-Rspam-User: X-Stat-Signature: woze1tbixgricmp9c8ze65j3xrm971ty X-Rspamd-Queue-Id: 40311C001E X-HE-Tag: 1667994707-257128 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 | 81 +++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index 177a142c3146..d898b7ace33d 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -401,6 +401,87 @@ 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 pages using alternative +(secondary) compression algorithms. 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 supports up to 4 compression algorithms: +one primary and up to 3 secondary ones. Primary zram compressor is explained +in "3) Select compression algorithm", secondary algorithms are configured +using recomp_algorithm device attribute. + +Example::: + + #show supported recompression algorithms + cat /sys/block/zramX/recomp_algorithm + #1: lzo lzo-rle lz4 lz4hc [zstd] + #2: lzo lzo-rle lz4 [lz4hc] zstd + +Alternative compression algorithms are sorted by priority. In the example +above, zstd is used as the first alternative algorithm, which has priority +of 1, while lz4hc is configured as a compression algorithm with priority 2. +Alternative compression algorithm's priority is provided during algorithms +configuration::: + + #select zstd recompression algorithm, priority 1 + echo "algo=zstd priority=1" > /sys/block/zramX/recomp_algorithm + + #select deflate recompression algorithm, priority 2 + echo "algo=deflate priority=2" > /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 "type=idle" > /sys/block/zramX/recompress + + #HUGE pages recompression is activated by `huge` mode + echo "type=huge" > /sys/block/zram0/recompress + + #HUGE_IDLE pages recompression is activated by `huge_idle` mode + echo "type=huge_idle" > /sys/block/zramX/recompress + +The number of idle pages can be significant, so user-space can pass a size +threshold (in bytes) to the recompress knob: zram will recompress only pages +of equal or greater size::: + + #recompress all pages larger than 3000 bytes + echo "threshold=3000" > /sys/block/zramX/recompress + + #recompress idle pages larger than 2000 bytes + echo "type=idle threshold=2000" > /sys/block/zramX/recompress + +Recompression of idle pages requires memory tracking. + +During re-compression for every page, that matches re-compression criteria, +ZRAM iterates the list of registered alternative compression algorithms in +order of their priorities. ZRAM stops either when re-compression was +successful (re-compressed object is smaller in size than the original one) +and matches re-compression criteria (e.g. size threshold) or when there are +no secondary algorithms left to try. If none of the secondary algorithms can +successfully re-compressed the page such a page is marked as incompressible, +so ZRAM will not attempt to re-compress it in the future. + +This re-compression behaviour, when it iterates through the list of +registered compression algorithms, increases our chances of finding the +algorithm that successfully compresses a particular page. Sometimes, however, +it is convenient (and sometimes even necessary) to limit recompression to +only one particular algorithm so that it will not try any other algorithms. +This can be achieved by providing a algo=NAME parameter::: + + #use zstd algorithm only (if registered) + echo "type=huge algo=zstd" > /sys/block/zramX/recompress + memory tracking =============== -- 2.38.1.431.g37b22c650d-goog