Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

zram: update recompression documentation

Emphasize usage of the `priority` parameter for recompression and explain
why `algo` parameter can lead to unexpected behavior and thus is not
recommended.

Link: https://lkml.kernel.org/r/20260311084312.1766036-5-senozhatsky@chromium.org
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Brian Geffon <bgeffon@google.com>
Cc: gao xu <gaoxu2@honor.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Minchan Kim <minchan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Sergey Senozhatsky and committed by
Andrew Morton
be5f13d9 5004a27e

+18 -22
+18 -22
Documentation/admin-guide/blockdev/zram.rst
··· 462 462 recompression 463 463 ------------- 464 464 465 - With CONFIG_ZRAM_MULTI_COMP, zram can recompress pages using alternative 465 + With `CONFIG_ZRAM_MULTI_COMP`, zram can recompress pages using alternative 466 466 (secondary) compression algorithms. The basic idea is that alternative 467 467 compression algorithm can provide better compression ratio at a price of 468 468 (potentially) slower compression/decompression speeds. Alternative compression ··· 471 471 recompression - pages that are cold and sit in the memory can be recompressed 472 472 using more effective algorithm and, hence, reduce zsmalloc memory usage. 473 473 474 - With CONFIG_ZRAM_MULTI_COMP, zram supports up to 4 compression algorithms: 474 + With `CONFIG_ZRAM_MULTI_COMP`, zram supports up to 4 compression algorithms: 475 475 one primary and up to 3 secondary ones. Primary zram compressor is explained 476 476 in "3) Select compression algorithm", secondary algorithms are configured 477 477 using recomp_algorithm device attribute. ··· 495 495 #select deflate recompression algorithm, priority 2 496 496 echo "algo=deflate priority=2" > /sys/block/zramX/recomp_algorithm 497 497 498 - Another device attribute that CONFIG_ZRAM_MULTI_COMP enables is recompress, 498 + Another device attribute that `CONFIG_ZRAM_MULTI_COMP` enables is `recompress`, 499 499 which controls recompression. 500 500 501 501 Examples::: 502 502 503 503 #IDLE pages recompression is activated by `idle` mode 504 - echo "type=idle" > /sys/block/zramX/recompress 504 + echo "type=idle priority=1" > /sys/block/zramX/recompress 505 505 506 506 #HUGE pages recompression is activated by `huge` mode 507 - echo "type=huge" > /sys/block/zram0/recompress 507 + echo "type=huge priority=2" > /sys/block/zram0/recompress 508 508 509 509 #HUGE_IDLE pages recompression is activated by `huge_idle` mode 510 - echo "type=huge_idle" > /sys/block/zramX/recompress 510 + echo "type=huge_idle priority=1" > /sys/block/zramX/recompress 511 511 512 512 The number of idle pages can be significant, so user-space can pass a size 513 513 threshold (in bytes) to the recompress knob: zram will recompress only pages 514 514 of equal or greater size::: 515 515 516 516 #recompress all pages larger than 3000 bytes 517 - echo "threshold=3000" > /sys/block/zramX/recompress 517 + echo "threshold=3000 priority=1" > /sys/block/zramX/recompress 518 518 519 519 #recompress idle pages larger than 2000 bytes 520 - echo "type=idle threshold=2000" > /sys/block/zramX/recompress 520 + echo "type=idle threshold=2000 priority=1" > \ 521 + /sys/block/zramX/recompress 521 522 522 523 It is also possible to limit the number of pages zram re-compression will 523 524 attempt to recompress::: 524 525 525 - echo "type=huge_idle max_pages=42" > /sys/block/zramX/recompress 526 + echo "type=huge_idle priority=1 max_pages=42" > \ 527 + /sys/block/zramX/recompress 528 + 529 + It is advised to always specify `priority` parameter. While it is also 530 + possible to specify `algo` parameter, so that `zram` will use algorithm's 531 + name to determine the priority, it is not recommended, since it can lead to 532 + unexpected results when the same algorithm is configured with different 533 + priorities (e.g. different parameters). `priority` is the only way to 534 + guarantee that the expected algorithm will be used. 526 535 527 536 During re-compression for every page, that matches re-compression criteria, 528 537 ZRAM iterates the list of registered alternative compression algorithms in ··· 541 532 no secondary algorithms left to try. If none of the secondary algorithms can 542 533 successfully re-compressed the page such a page is marked as incompressible, 543 534 so ZRAM will not attempt to re-compress it in the future. 544 - 545 - This re-compression behaviour, when it iterates through the list of 546 - registered compression algorithms, increases our chances of finding the 547 - algorithm that successfully compresses a particular page. Sometimes, however, 548 - it is convenient (and sometimes even necessary) to limit recompression to 549 - only one particular algorithm so that it will not try any other algorithms. 550 - This can be achieved by providing a `algo` or `priority` parameter::: 551 - 552 - #use zstd algorithm only (if registered) 553 - echo "type=huge algo=zstd" > /sys/block/zramX/recompress 554 - 555 - #use zstd algorithm only (if zstd was registered under priority 1) 556 - echo "type=huge priority=1" > /sys/block/zramX/recompress 557 535 558 536 memory tracking 559 537 ===============