Bug#1012152: firmware-amd-graphics: All firmware are included in initrd even in dep mode
Package: firmware-amd-graphics
Version: 20210818-1
Severity: minor
Dear Maintainer,
Since the integration of built-in drivers in initramfs-tools (see
https://salsa.debian.org/kernel-team/initramfs-tools/-/merge_requests/35),
firmware files are also included with the corresponding kernel
module.
I don't know why, but it only hits my system (AMD Ryzen PRO 4750G)
since May,
7th with Linux 5.17.0. Before that, amdgpu was NOT included in the
initrd.
Now that it's included, it brings all firmwares for all AMD graphics
card,
making the initrd from 11MB to 38MB. This has 3 drawbacks for me:
1. Building initrd is longer, so updates that trigger this take
longer
2. Booting is also longer. It happens that even 1s faster matters to
me ;)
3. My /boot partition is too small (182MB, hard to increase due to
LUKS
partition after that), and I am hit by "no space left on device"
(see
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=972396)
But on top of this, I know that I don't need all those firmwares. In
fact,
amdgpu kindly reports which firmwares are loaded at start, so I made
a hook
that removes everything but the needed files (see attached).
Now for some benchmarks. First, initrd extraction.
hyperfine -N --warmup 3 "lsinitramfs -l
./initrd.img-5.17.0-3-amd64.nohook"
"lsinitramfs -l ./initrd.img-5.17.0-3-amd64.hook"
Benchmark 1: lsinitramfs -l ./initrd.img-5.17.0-3-amd64.nohook
Time (mean ± σ): 130.7 ms ± 4.4 ms [User: 69.4 ms, System: 100.3 ms]
Range (min … max): 125.2 ms … 146.1 ms 22 runs
Benchmark 2: lsinitramfs -l ./initrd.img-5.17.0-3-amd64.hook
Time (mean ± σ): 68.8 ms ± 1.2 ms [User: 34.9 ms, System: 53.5 ms]
Range (min … max): 66.9 ms … 72.2 ms 42 runs
Summary
'lsinitramfs -l ./initrd.img-5.17.0-3-amd64.hook' ran
1.90 ± 0.07 times faster than 'lsinitramfs -l
./initrd.img-5.17.0-3-amd64.nohook'
So extracting initramfs is 90% faster.
Updating the initrd is less obvious. I use LZ4 for compression on my
system,
with MODULES=dep
hyperfine "update-initramfs -u"
Benchmark 1: update-initramfs -u
Time (mean ± σ): 3.379 s ± 0.033 s [User: 2.856 s, System: 0.563 s]
Range (min … max): 3.341 s … 3.456 s 10 runs
Without the hook
hyperfine "update-initramfs -u"
Benchmark 1: update-initramfs -u
Time (mean ± σ): 4.175 s ± 0.048 s [User: 3.436 s, System: 0.738 s]
Range (min … max): 4.118 s … 4.261 s 10 runs
It is only 20% faster.
In the end, I am asking for code review in the hook I wrote. I know
I missed
some cases, because I am not used this part of the system.
-- System Information:
Debian Release: bookworm/sid
APT prefers unstable-debug
APT policy: (500, 'unstable-debug'), (500, 'unstable'), (1,
'experimental')
Architecture: amd64 (x86_64)
Kernel: Linux 5.17.0-3-amd64 (SMP w/16 CPU threads; PREEMPT)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8),
LANGUAGE not set
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
firmware-amd-graphics depends on no packages.
firmware-amd-graphics recommends no packages.
Versions of packages firmware-amd-graphics suggests:
ii initramfs-tools 0.141
-- no debconf information
#!/bin/sh
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
. /usr/share/initramfs-tools/hook-functions
FIRMWARES=$(dmesg | grep -oP 'amdgpu.*direct-loading firmware amdgpu/\K(.*bin)$')
if [ -z "$FIRMWARES" ]; then
exit 0
fi
echo "Removing all AMDGPU firware except $(echo $FIRMWARES | xargs echo)"
rm "$DESTDIR/usr/lib/firmware/amdgpu"/*
for firmware in $FIRMWARES; do
copy_file firmware "/lib/firmware/amdgpu/${firmware}"
done
Reply to: