-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
setup-hooks/strip: parallelise stripping #207101
Conversation
@@ -62,7 +62,12 @@ stripDirs() { | |||
if [ -n "${paths}" ]; then | |||
echo "stripping (with command $cmd and flags $stripFlags) in $paths" | |||
# Do not strip lib/debug. This is a directory used by setup-hooks/separate-debug-info.sh. | |||
find $paths -type f -a '!' -wholename "$prefix/lib/debug/*" -exec $cmd $stripFlags '{}' \; 2>/dev/null | |||
find $paths -type f -a '!' -path "$prefix/lib/debug/*" -print0 | | |||
xargs -r -0 -n1 -P "$NIX_BUILD_CORES" $cmd $stripFlags || exit_code=$? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified to just this, right?
xargs -r -0 -n1 -P "$NIX_BUILD_CORES" $cmd $stripFlags || [[ $? -eq 123 ]]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder even if we care about the exit code at all: do we care if all the files failed to strip? The old behavior did not:
$ find . -exec false \;; echo $?
0
I think we can || true
this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What Linus has here (and my suggestion also) does match the old behaviour. A 123 exit means that strip failed, and we are indeed ignoring that.
But any other error code from xargs means that xargs itself failed. We don't want to ignore that, as it likely means we're holding it wrong. Similarly, we weren't ignoring failures from find
itself before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't push
diff --git a/pkgs/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh
index 8ee212be686..675cf2310a4 100644
--- a/pkgs/build-support/setup-hooks/strip.sh
+++ b/pkgs/build-support/setup-hooks/strip.sh
@@ -63,11 +63,12 @@ stripDirs() {
echo "stripping (with command $cmd and flags $stripFlags) in $paths"
# Do not strip lib/debug. This is a directory used by setup-hooks/separate-debug-info.sh.
find $paths -type f -a '!' -path "$prefix/lib/debug/*" -print0 |
- xargs -r -0 -n1 -P "$NIX_BUILD_CORES" $cmd $stripFlags || exit_code=$?
- # xargs exits with status code 123 if some but not all of the
- # processes fail. We don't care if some of the files couldn't
- # be stripped, so ignore specifically this code.
- [[ "$exit_code" = 123 || -z "$exit_code" ]]
+ xargs -r -0 -n1 -P "$NIX_BUILD_CORES" $cmd $stripFlags || [[ $? -eq 123 ]]
+ # ^
+ # xargs exits with status code 123 if some but not all of the
+ # processes fail. We don't care if some of the files couldn't
+ # be stripped, so ignore specifically this code.
+
# 'strip' does not normally preserve archive index in .a files.
# This usually causes linking failures against static libs like:
# ld: ...-i686-w64-mingw32-stage-final-gcc-13.0.0-lib/i686-w64-mingw32/lib/libstdc++.dll.a:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally didn't apply this because I find it a little clearer and the comment feels less awkward this way, sorry I forgot to write that.
Do we have another 1-4% improvement a few lines below?:
|
@grahamc probably not, since there's a lot less to do:
We could do it as a matter of principle though. EDIT: we can probably make savings like this on |
d7fe17e
to
fcab4d4
Compare
Can we merge this or are there still things to do? 👀 |
@SuperSandro2000 I rebased it the other day and remove the extra parallelisation in hopes that that would make this mergeable as is :) I don't see any further things to address. |
This makes bootstrapping to GNU hello ~1-2% faster on an 8-core machine and ~3-4% faster on a 64-core machine.
fcab4d4
to
70945eb
Compare
Bisect claims that 70945eb
Might have something to do with multiple symlinks on the same binary. |
#244400 will print the error to make issues easier to debug |
Thank you! That prints the following error: extra-utils> stripping (with command and flags -s) in /nix/store/2gfapyy8nldpm7sj0mw88454fwzb995m-extra-utils/lib /nix/store/2gfapyy8nldpm7sj0mw88454fwzb995m-extra-utils/bin
extra-utils> find: 'standard output': Broken pipe
extra-utils> find: write error
extra-utils> xargs: option requires an argument -- 's'
extra-utils> Try 'xargs --help' for more information. It looks like |
|
@@ -62,7 +62,12 @@ stripDirs() { | |||
if [ -n "${paths}" ]; then | |||
echo "stripping (with command $cmd and flags $stripFlags) in $paths" | |||
# Do not strip lib/debug. This is a directory used by setup-hooks/separate-debug-info.sh. | |||
find $paths -type f -a '!' -wholename "$prefix/lib/debug/*" -exec $cmd $stripFlags '{}' \; 2>/dev/null | |||
find $paths -type f -a '!' -path "$prefix/lib/debug/*" -print0 | | |||
xargs -r -0 -n1 -P "$NIX_BUILD_CORES" $cmd $stripFlags 2>/dev/null || exit_code=$? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trofi maybe a -- before cmd is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to my PR, building.. nixosTests.systemd-boot.basic.config.nodes.machine.system.build.extraUtils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it fails with xargs: -s: No such file or directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha there's no $cmd
stripping (with command and flags -s) in
echo "stripping (with command $cmd and flags $stripFlags) in $paths"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On current master(3ec081d) it has the same issue
extra-utils> stripping (with command and flags -s) in
so this issue was just being ignored!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong evidence, but I have a suspiction that we still manage to run multiple I wonder if it would be safer to do |
I'll try to test the following locally and propose it if it does not break stuff: --- a/pkgs/build-support/setup-hooks/strip.sh
+++ b/pkgs/build-support/setup-hooks/strip.sh
@@ -68,6 +68,11 @@ stripDirs() {
striperr="$(mktemp 'striperr.XXXXXX')"
# Do not strip lib/debug. This is a directory used by setup-hooks/separate-debug-info.sh.
find $paths -type f -a '!' -path "$prefix/lib/debug/*" -print0 |
+ # Make sure we process files under symlinks only once. Otherwise
+ # 'strip` can corrupt files when writes to them in parallel:
+ # https://github.com/NixOS/nixpkgs/issues/246147#issuecomment-1657072039
+ xargs realpath | uniq |
+
xargs -r -0 -n1 -P "$NIX_BUILD_CORES" -- $cmd $stripFlags 2>"$striperr" || exit_code=$?
# xargs exits with status code 123 if some but not all of the
# processes fail. We don't care if some of the files couldn't |
Proposed the change as #246164 |
Description of changes
This makes bootstrapping to GNU hello ~1-2% faster on an 8-core machine and ~3-4% faster on a 64-core machine (unscientific comparison, total of 4 samples or something).
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)nixos/doc/manual/md-to-db.sh
to update generated release notes