Better xz compression

Borrowed from downstream, we can be a little bit smarter
on how we compress modules.
This commit is contained in:
Laura Abbott 2019-11-06 12:47:55 -05:00
parent d0a82f1e0f
commit dba7671694
2 changed files with 27 additions and 3 deletions

View File

@ -51,8 +51,6 @@ Summary: The Linux kernel
%if %{zipmodules} %if %{zipmodules}
%global zipsed -e 's/\.ko$/\.ko.xz/' %global zipsed -e 's/\.ko$/\.ko.xz/'
# for parallel xz processes, replace with 1 to go back to single process
%global zcpu `nproc --all`
%endif %endif
# define buildid .local # define buildid .local
@ -2070,7 +2068,7 @@ find Documentation -type d | xargs chmod u+w
fi \ fi \
fi \ fi \
if [ "%{zipmodules}" -eq "1" ]; then \ if [ "%{zipmodules}" -eq "1" ]; then \
find $RPM_BUILD_ROOT/lib/modules/ -type f -name '*.ko' | xargs -P%{zcpu} xz; \ find $RPM_BUILD_ROOT/lib/modules/ -type f -name '*.ko' | %{SOURCE79} %{?_smp_mflags}; \
fi \ fi \
%{nil} %{nil}

26
parallel_xz.sh Normal file → Executable file
View File

@ -0,0 +1,26 @@
#!/bin/sh
# Reads filenames on stdin, xz-compresses each in place.
# Not optimal for "compress relatively few, large files" scenario!
# How many xz's to run in parallel:
procgroup=""
while test "$#" != 0; do
# Get it from -jNUM
N="${1#-j}"
if test "$N" = "$1"; then
# Not -j<something> - warn and ignore
echo "parallel_xz: warning: unrecognized argument: '$1'"
else
procgroup="$N"
fi
shift
done
# If told to use only one cpu:
test "$procgroup" || exec xargs -r xz
test "$procgroup" = 1 && exec xargs -r xz
# xz has some startup cost. If files are really small,
# this cost might be significant. To combat this,
# process several files (in sequence) by each xz process via -n 16:
exec xargs -r -n 16 -P $procgroup xz