Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2034834

Summary: Backport zstd from Linux 5.16
Product: Red Hat Enterprise Linux 9 Reporter: Neal Gompa <ngompa13>
Component: kernelAssignee: Vladislav Dronov <vdronov>
kernel sub component: Block Layer QA Contact: ChanghuiZhong <czhong>
Status: CLOSED ERRATA Docs Contact:
Severity: unspecified    
Priority: unspecified CC: bstinson, carl, davide, guazhang, jmoyer, jwboyer, michel, terrelln, vdronov
Version: CentOS StreamKeywords: FutureFeature, Triaged
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: kernel-5.14.0-45.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-05-17 15:43:49 UTC Type: Feature Request
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 2032758    
Bug Blocks:    

Description Neal Gompa 2021-12-22 10:00:49 UTC
Description of problem:
Upstream Linux 5.16 has a much newer zstd implementation that significantly improves the performance of zstd in the kernel, as well as had a lot of security work done on it (fuzzing, etc.). We should have this in the RHEL kernel, especially as we start using zstd for things (e.g. bug 2020132, bug 2032758, etc.)

Version-Release number of selected component (if applicable):
5.14.0-36.el9

Additional info:
Upstream PR descriptions:

* https://lore.kernel.org/linux-kernel/20211109013058.22224-1-nickrterrell@gmail.com/
* https://lore.kernel.org/linux-kernel/1F7E17E1-9B51-4D21-B7FB-9BD3BE4A199A@fb.com/

Comment 3 Vladislav Dronov 2021-12-28 01:43:22 UTC
a suggested action plan for testing: use zram disk with zstd compression

docs: https://www.kernel.org/doc/html/latest/admin-guide/blockdev/zram.html

### create one zram device
# modprobe zram num_devices=1

### check and set zstd compression 
# cat /sys/block/zram0/comp_algorithm 
lzo [lzo-rle] lz4 lz4hc 842 zstd 
# echo zstd > /sys/block/zram0/comp_algorithm
# cat /sys/block/zram0/comp_algorithm 
lzo lzo-rle lz4 lz4hc 842 [zstd] 

### set max ram usage = 256 Mbytes
# echo 256M > /sys/block/zram0/disksize

### write, read and test some data (/boot, for example)
# mke2fs -m 0 -b 4096 -O sparse_super -L zram /dev/zram0
# mount -o relatime,noexec,nosuid /dev/zram0 /mnt/zram
# cp -rp /boot /mnt/zram
# diff -rp /boot /mnt/zram/boot
< *** must be no output here *** >

### get funny stats
# awk '{ print "uncompressed size of data",$1,"\ncompressed size of data", $2, "\nmemory allocated for this disk", $3, "\nnumber of incompressible pages", $8 }' /sys/block/zram0/mm_stat
uncompressed size of data 185937920 
compressed size of data 163488509 
memory allocated for this disk 164663296 
number of incompressible pages 36615

### uncreate
# umount /mnt/zram
# rmmod zram

Comment 5 Neal Gompa 2022-01-14 02:05:39 UTC
Note that to test this, you'll need the MR for bug 2032758 to go with this.

Comment 6 ChanghuiZhong 2022-01-14 02:47:01 UTC
thanks Neal for the note,

hi Vladis,can you help to build a test kernel, including this two MR ?
https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/292
https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/262

Thanks

Comment 7 Vladislav Dronov 2022-01-14 15:14:58 UTC
thanks, Changhui, and i'm sorry for the mess, MRs 262 and 292 have to come together indeed.
i've build a kernel with MR 292 right on top of MR 262: this is a kernel from bz2032758#c11 (see [1]):

kernel-5.14.0-39.mrs_262_292.el9:
https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=42397520

initial test on my VM looks good:

# modprobe zram num_devices=1
# cat /sys/block/zram0/comp_algorithm 
lzo [lzo-rle] zstd 

could you please use this kernel for testing?

[1]
$ git log
0f0dd1c8420c (HEAD -> zstd) lib: zstd: Don't add -O3 to cflags
62852e7bc46a lib: zstd: Don't inline functions in zstd_opt.c
4869198baf47 lib: zstd: Fix unused variable warning
87fe696e5bb5 lib: zstd: Add cast to silence clang's -Wbitwise-instead-of-logical
c4025efb937f MAINTAINERS: Add maintainer entry for zstd
9f7ae1f3c31b lib: zstd: Upgrade to latest upstream zstd version 1.4.10
45795b46b636 lib: zstd: Add decompress_sources.h for decompress_unzstd
9223f0a77d04 lib: zstd: Add kernel-specific API
7c1cfa2db9d0 redhat/configs: Add explicit values for ZRAM_DEF_COMP_LZ4* configs
d5b6434d7fc0 redhat/configs: Enable CONFIG_CRYPTO_ZSTD
ce680337a17f redhat/configs: Migrate defaults for ZRAM from pending-common to common
d27f92307dbf (tag: kernel-5.14.0-39.el9) [redhat] kernel-5.14.0-39.el9

Comment 8 Vladislav Dronov 2022-01-14 15:27:12 UTC
(In reply to Vladis Dronov from comment #3)
> a suggested action plan for testing: use zram disk with zstd compression

i need to make a change to the suggested testing plan in c#3. in the current
version we will be reading data from a page cache, not from zram disk, so
compare operation will always succeed.

can you please consider the following change in testing script:

...
### write some data (/boot, for example), un-mount and drop caches
# mkdir -p /mnt/zram
# mke2fs -m 0 -b 4096 -O sparse_super -L zram /dev/zram0
# mount -o relatime,noexec,nosuid /dev/zram0 /mnt/zram
# cp -rp /boot /mnt/zram
# umount /mnt/zram
# echo 3 > /proc/sys/vm/drop_caches

### test the data
# mount -o relatime,noexec,nosuid /dev/zram0 /mnt/zram
# diff -rp /boot /mnt/zram/boot
< *** must be no output here *** >

### clean up
# umount /mnt/zram
# rmdir /mnt/zram/
# rmmod zram

Comment 9 ChanghuiZhong 2022-01-17 09:48:30 UTC
Thanks to Vladis for rebuilding the new test kernel and modifying the test script.

Tested on 5.14.0-39.mrs_262_292.el9 with good results, 
zstd compression functionality has enabled, zstd smoke and zstd compression test passed.

# grep CONFIG_CRYPTO_ZSTD /boot/config-5.14.0-39.mrs_262_292.el9.x86_64
CONFIG_CRYPTO_ZSTD=m

# grep CONFIG_ZSTD_COMPRESS /boot/config-5.14.0-39.mrs_262_292.el9.x86_64
CONFIG_ZSTD_COMPRESS=m

:: [ 04:27:09 ] :: [  BEGIN   ] :: Running 'uname -a'
Linux storageqe-70.rhts.eng.pek2.redhat.com 5.14.0-39.mrs_262_292.el9.x86_64 #1 SMP PREEMPT Fri Jan 14 07:51:34 EST 2022 x86_64 x86_64 x86_64 GNU/Linux

::[04:27:09]::[BEGIN]:: Running 'cat /sys/block/zram0/comp_algorithm'
lzo lzo-rle [zstd]


::[04:27:11]::[BEGIN]:: Running 'diff -rp /boot /mnt/zram/boot'
:: [ 04:27:12 ] :: [ PASS ] :: Command 'diff -rp /boot /mnt/zram/boot' (Expected 0, got 0)


uncompressed size of data 261521408
compressed size of data 233442811
memory allocated for this disk 234971136
number of incompressible pages 52081

Comment 11 ChanghuiZhong 2022-01-24 09:37:02 UTC
Tested on kernel-5.14.0-47.el9,
zstd compression functionality has enabled, zstd smoke and zstd compression test passed
https://beaker.engineering.redhat.com/jobs/6216984

# grep CONFIG_CRYPTO_ZSTD /boot/config-5.14.0-47.el9.x86_64 
CONFIG_CRYPTO_ZSTD=m
# grep CONFIG_ZSTD_COMPRESS /boot/config-5.14.0-47.el9.x86_64 
CONFIG_ZSTD_COMPRESS=m

move to verified

Comment 14 errata-xmlrpc 2022-05-17 15:43:49 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (new packages: kernel), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:3907