|
Harald Hoyer |
f97365 |
From 986b12d391b8de6c820da1af9bfdb4153c340370 Mon Sep 17 00:00:00 2001
|
|
Harald Hoyer |
f97365 |
From: Kairui Song <kasong@redhat.com>
|
|
Harald Hoyer |
f97365 |
Date: Wed, 25 Jul 2018 16:47:37 +0800
|
|
Harald Hoyer |
f97365 |
Subject: [PATCH] lsinitrd: optimize performance when handling multiple files
|
|
Harald Hoyer |
f97365 |
|
|
Harald Hoyer |
f97365 |
Currently, when trying to unpack or print the content of multiple
|
|
Harald Hoyer |
f97365 |
files, lsinitrd will decompress the image and pipe the decompressed
|
|
Harald Hoyer |
f97365 |
content to cpio to retrive each file if the image is compressed.
|
|
Harald Hoyer |
f97365 |
Which mean if we want to extract 10 files the image will be decompressed
|
|
Harald Hoyer |
f97365 |
10 times, which is a waste of time.
|
|
Harald Hoyer |
f97365 |
|
|
Harald Hoyer |
f97365 |
This patch will let lsinitrd decompress the image file to a temp file
|
|
Harald Hoyer |
f97365 |
first if multiple file names are given, then cpio will read from the
|
|
Harald Hoyer |
f97365 |
decompressed temp file, which will speed up a lot.
|
|
Harald Hoyer |
f97365 |
|
|
Harald Hoyer |
f97365 |
Time consumption test for command:
|
|
Harald Hoyer |
f97365 |
`lsinitrd initramfs-4.16.15-300.fc28.x86_64.img \
|
|
Harald Hoyer |
f97365 |
usr/lib/dracut/build-parameter.txt \
|
|
Harald Hoyer |
f97365 |
usr/lib/dracut/modules.txt \
|
|
Harald Hoyer |
f97365 |
etc/machine-id \
|
|
Harald Hoyer |
f97365 |
etc/hostname \
|
|
Harald Hoyer |
f97365 |
usr/lib/udev/rules.d/99-systemd.rules`
|
|
Harald Hoyer |
f97365 |
|
|
Harald Hoyer |
f97365 |
Before the patch:
|
|
Harald Hoyer |
f97365 |
2.37user 0.33system 0:02.12elapsed
|
|
Harald Hoyer |
f97365 |
|
|
Harald Hoyer |
f97365 |
After the patch:
|
|
Harald Hoyer |
f97365 |
0.50user 0.42system 0:00.72elapsed
|
|
Harald Hoyer |
f97365 |
|
|
Harald Hoyer |
f97365 |
There would be a more significant time difference if we try to
|
|
Harald Hoyer |
f97365 |
extract more files.
|
|
Harald Hoyer |
f97365 |
---
|
|
Harald Hoyer |
f97365 |
lsinitrd.sh | 11 +++++++++++
|
|
Harald Hoyer |
f97365 |
1 file changed, 11 insertions(+)
|
|
Harald Hoyer |
f97365 |
|
|
Harald Hoyer |
f97365 |
diff --git a/lsinitrd.sh b/lsinitrd.sh
|
|
Harald Hoyer |
f97365 |
index 1b9a93b6..0cb89e9c 100755
|
|
Harald Hoyer |
f97365 |
--- a/lsinitrd.sh
|
|
Harald Hoyer |
f97365 |
+++ b/lsinitrd.sh
|
|
Harald Hoyer |
f97365 |
@@ -251,6 +251,17 @@ if [[ $SKIP ]]; then
|
|
Harald Hoyer |
f97365 |
CAT=skipcpio
|
|
Harald Hoyer |
f97365 |
fi
|
|
Harald Hoyer |
f97365 |
|
|
Harald Hoyer |
f97365 |
+if (( ${#filenames[@]} > 1 )); then
|
|
Harald Hoyer |
f97365 |
+ TMPFILE="$(mktemp -t --suffix=.cpio lsinitrd.XXXXXX)"
|
|
Harald Hoyer |
f97365 |
+ $CAT "$image" 2>/dev/null > $TMPFILE
|
|
Harald Hoyer |
f97365 |
+ trap "rm -f '$TMPFILE'" EXIT
|
|
Harald Hoyer |
f97365 |
+ pre_decompress()
|
|
Harald Hoyer |
f97365 |
+ {
|
|
Harald Hoyer |
f97365 |
+ cat $TMPFILE
|
|
Harald Hoyer |
f97365 |
+ }
|
|
Harald Hoyer |
f97365 |
+ CAT=pre_decompress
|
|
Harald Hoyer |
f97365 |
+fi
|
|
Harald Hoyer |
f97365 |
+
|
|
Harald Hoyer |
f97365 |
ret=0
|
|
Harald Hoyer |
f97365 |
|
|
Harald Hoyer |
f97365 |
if [[ -n "$unpack" ]]; then
|
|
Harald Hoyer |
f97365 |
|