Bug 2122106

Summary: cryptsetup has much higher memory overhead in Workstation than in Everything or Cloud Base Image
Product: [Fedora] Fedora Reporter: Coiby <coxu>
Component: cryptsetupAssignee: Milan Broz <gmazyland>
Status: CLOSED EOL QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 35CC: agk, gmazyland, okozina
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-12-13 18:08:10 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Coiby 2022-08-29 07:17:32 UTC
Description of problem:

cryptsetup has much higher memory overhead in Workstation than in Everything or Cloud Base Image.  For example, in Workstation, "cryptsetup luksDump" consumes ~223MB whereas in Everything or cloud base image, it merely only consumes ~12.5MB. So does luksOpen/luksFormat or systemd-cryptsetup's attach.

Version-Release number of selected component (if applicable):

cryptsetup-libs-0:2.4.3-1.fc35

How reproducible:
always 

Steps to Reproduce:
1. Install Fedora Workstation or start Fedora-Workstation-Live-x86_64-35-1.2.iso in QEMU
2. Install time to collect memory consumption info
    dnf install install time
3. Prepare a LUKS encrypted image
    dd if=/dev/zero of=encrypted.img bs=1 count=0 seek=100M 
    /usr/sbin/cryptsetup luksFormat encrypted.img
4. Collect the memory consumption by "time -v"
    /usr/bin/time -v cryptsetup luksDump encrypted.img 2>&1 


Actual results:

The memory cost is ~220MB.

/usr/bin/time -v cryptsetup luksDump encrypted.img 2>&1 | grep "Maximum resident"
        Maximum resident set size (kbytes): 228136

Expected results:

The memory cost should be ~12MB.

Additional info:

1. If I get the list of installed software on Workstation (`rpm -qa --qf "%{NAME}\n" | sort > workstation_packages`) and install them on Everything or Cloud Base Image (`dnf install -y $(<workstation_packages) --skip-broken`), the memory overhead also becomes much higher.
2. This issue is not limited to F35. I can confirm it can be also reproduce on Fedora-Workstation-Live-x86_64-36-1.5.iso and Fedora-Workstation-Live-x86_64-Rawhide-20211019.n.0.iso.

Comment 1 Ondrej Kozina 2022-09-01 15:46:08 UTC
This is due to different default installed glibc packages related to locales. On cloud installation it does not install other locales (non US?) by default. Cryptsetup (up to future 2.6.0) locks all memory and triggers all locales being loaded in system memory. Anyway this will go away when upstream release with following patch is released: https://gitlab.com/cryptsetup/cryptsetup/-/commit/4b47091b85bcd768ca048dc59fad2bf7806ef1b1

Comment 2 Coiby 2022-09-02 10:33:57 UTC
(In reply to Ondrej Kozina from comment #1)
> This is due to different default installed glibc packages related to
> locales. On cloud installation it does not install other locales (non US?)
> by default. Cryptsetup (up to future 2.6.0) locks all memory and triggers
> all locales being loaded in system memory. Anyway this will go away when
> upstream release with following patch is released:
> https://gitlab.com/cryptsetup/cryptsetup/-/commit/
> 4b47091b85bcd768ca048dc59fad2bf7806ef1b1

Thanks for the explanation! Yes, glibc-all-langpacks the cause. I can confirm the overhead cost is significantly dropped for the the latest cryptsetup. For example, on aarch64, it drops from 255M to 7.2M for luksOpen.

Btw, what affects the memory overhead cost in the initrd environment? I notice, currently in intird, the overhead is much lower than in the real root envrioment (~50M vs. ~10M for luksOpen) and there is no libc.mo file in the initrid. And aarch64 is an exception,  in initrd and real root environment is more or less the same (~40M) whereas the latest cryptsetup only costs 7.2M  and 6.7M in real root environment and initrd respectively. Is this a for aarch64 cryptsetup?

Comment 3 Milan Broz 2022-11-24 13:00:00 UTC
Rawhide now contains cryptsetup-2.6.0~rc0-1.fc38 that does not use memlockall(), so the issue should be fixed there.

Comment 4 Ben Cotton 2022-11-29 19:00:24 UTC
This message is a reminder that Fedora Linux 35 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora Linux 35 on 2022-12-13.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
'version' of '35'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, change the 'version' 
to a later Fedora Linux version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora Linux 35 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora Linux, you are encouraged to change the 'version' to a later version
prior to this bug being closed.

Comment 5 Ben Cotton 2022-12-13 18:08:10 UTC
Fedora Linux 35 entered end-of-life (EOL) status on 2022-12-13.

Fedora Linux 35 is no longer maintained, which means that it
will not receive any further security or bug fix updates. As a result we
are closing this bug.

If you can reproduce this bug against a currently maintained version of Fedora Linux
please feel free to reopen this bug against that version. Note that the version
field may be hidden. Click the "Show advanced fields" button if you do not see
the version field.

If you are unable to reopen this bug, please file a new report against an
active release.

Thank you for reporting this bug and we are sorry it could not be fixed.