-
Notifications
You must be signed in to change notification settings - Fork 402
perf(dracut-functions.sh): optimise get_persistent_dev() #2003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
4f1262b
to
f9f4ab1
Compare
Head branch was pushed to by a user without write access
Admittedly, it only happened when I extended the stat cmdline to 175x its original size on my mid-sized system (lsblk is 31 devices with grep -v p and 92 without), but I had been worried about just blowing the stat environment block size. The contenders are: sget_persistent_dev() {
local _dev _pol
_dev=$(stat -L -c $'%t:%T' "$1" 2> /dev/null)
[ -z "$_dev" ] && return
if [[ -n $persistent_policy ]]; then
_pol="/dev/disk/${persistent_policy}/*"
else
_pol=
fi
# shellcheck disable=SC2086
stat -L -c $'%n\t%t:%T' \
$_pol \
/dev/mapper/* \
/dev/disk/by-uuid/* \
/dev/disk/by-label/* \
/dev/disk/by-partuuid/* \
/dev/disk/by-partlabel/* \
/dev/disk/by-id/* \
/dev/disk/by-path/* 2> /dev/null \
| awk -v_dev="$_dev" -vdfl="$1" '$0 ~ ("\t" _dev "$") {--NF; print; dfl=0; exit} END {if(dfl) print dfl}'
}
pget_persistent_dev() {
local _dev _pol
_dev=$(stat -L -c $'%t:%T' "$1" 2> /dev/null)
[ -z "$_dev" ] && return
if [[ -n $persistent_policy ]]; then
_pol="/dev/disk/${persistent_policy}/*"
else
_pol=
fi
# shellcheck disable=SC2086
printf '%s\0' \
$_pol \
/dev/mapper/* \
/dev/disk/by-uuid/* \
/dev/disk/by-label/* \
/dev/disk/by-partuuid/* \
/dev/disk/by-partlabel/* \
/dev/disk/by-id/* \
/dev/disk/by-path/* \
| xargs -0 stat -L -c $'%n\t%t:%T' 2> /dev/null \
| awk -v_dev="$_dev" -vdfl="$1" '$0 ~ ("\t" _dev "$") {--NF; print; dfl=0; exit} END {if(dfl) print dfl}'
}
fget_persistent_dev() {
local _dev _pol
_dev=$(stat -L -c $'%t:%T' "$1" 2> /dev/null)
[ -z "$_dev" ] && return
if [[ -n $persistent_policy ]]; then
_pol="/dev/disk/${persistent_policy}"
else
_pol=
fi
# shellcheck disable=SC2086
find \
$_pol \
/dev/mapper \
/dev/disk/by-uuid \
/dev/disk/by-label \
/dev/disk/by-partuuid \
/dev/disk/by-partlabel \
/dev/disk/by-id \
/dev/disk/by-path \
-print0 \
| xargs -0 stat -L -c $'%n\t%t:%T' 2> /dev/null \
| awk -v_dev="$_dev" -vdfl="$1" '$0 ~ ("\t" _dev "$") {--NF; print; dfl=0; exit} END {if(dfl) print dfl}'
} And the results:
Which I'd classify as "who the hell knows" because, really, who does, it's all roughly within jitter, so I've rebased and updated to use printf because I like it more and it avoids an exec. |
This shaves ~40ms (from ~50ms; average case, huge variance up to 700ms on the old one), and makes 99base go from real 0m0.350s user 0m0.250s sys 0m0.119s to real 0m0.216s user 0m0.162s sys 0m0.076s
This issue is being marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. If this is still an issue in the latest release of Dracut and you would like to keep it open please comment on this issue within the next 7 days. Thank you for your contributions. |
world's stinkiest bot 2022 (real) |
This issue is being marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. If this is still an issue in the latest release of Dracut and you would like to keep it open please comment on this issue within the next 7 days. Thank you for your contributions. |
so true botstie |
This issue is being marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. If this is still an issue in the latest release of Dracut and you would like to keep it open please comment on this issue within the next 7 days. Thank you for your contributions. |
oh no, cringe (dutch) |
99base install() goes from like
to like
on my system.
Microbenchmarks show (appx. an easy-average case):
For best case (this is the first device in the glob):
And for worst case (
/dev/zero
doesn't have a corresponding device blockdev in the glob):Or, in short:
In the cases that are run in the 99base setup, I saw baseline speeds of 40-50ms, and it's run like 3 times there for me. If you have a less weird (non-root-on-ZFS) or more weird (wide btrfs) setup you'll likely see a better improvement.
get_persistent_dev()
is only used inmodule-setup.sh
sChecklist