Skip to content
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

fix #4332: setting ZSTD_NBTHREADS=0 via environment variable #4334

Merged
merged 5 commits into from
Mar 11, 2025

Conversation

Cyan4973
Copy link
Contributor

Since v1.5.7, setting ZSTD_NBTHREADS=0 via environment variable doesn't work, due to a logic mistake in the initialization routine.
Reported in #4332, by JcKlomp.

@Cyan4973 Cyan4973 marked this pull request as ready for review March 10, 2025 17:05
@@ -10,7 +10,3 @@ zstd -T0 -f file -q ; zstd -t file.zst
zstd -T0 --auto-threads=logical -f file -q ; zstd -t file.zst
zstd -T0 --auto-threads=physical -f file -q ; zstd -t file.zst
zstd -T0 --jobsize=1M -f file -q ; zstd -t file.zst
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a test here that tests the environment variable works?

If we print the number of threads under some verbosity we could do something like:

ZSTD_NBTHREADS=0 zstd -f file -vv 2>&1 | grep "physical core(s) detected"
zstd -tq file.zst
ZSTD_NBTHREADS=4 zstd -f file -vv 2>&1 | grep "4 threads"
zstd -tq file.zst

Copy link
Contributor Author

@Cyan4973 Cyan4973 Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely,
I was considering to do it in another PR, in order to observe the test failure under current conditions, i.e. without the patch.
But I could also just add it to this PR as a follow up commit.

Comment on lines -1335 to -1337
if ((operation==zom_decompress) && (nbWorkers > 1)) {
DISPLAYLEVEL(2, "Warning : decompression does not support multi-threading\n");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added due to Issue #2918. This may be a useful warning to keep.

Copy link
Contributor Author

@Cyan4973 Cyan4973 Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue is, with current code,
there is nothing to tell that nbWorkers wasn't set.
Whether it's set via the environment variable, or via the core count detection, it's necessarily set to "some value".
There is no difference with a user setting this value manually via command line.

Therefore, on any modern system with >= 8 logical cores, nbWorkers >= 2, and consequently always triggers this warning.

This could be solved by adding yet another variable, which would track if nbWorkers was set explicitly, or if it happens to be set to a value >1 just as a consequence of automatic core count detection. We would also have to decide if setting nbWorkers via environment variable count or not to trigger this warning.

So it's a bit more work, a bit more questions, and specific to the topic of displaying a warning during decompression mode. It felt it could deserve its own PR for proper focus.

checks that ZSTD_NBTHREADS triggers the expected verbose message

Also: checked that the new test script fails on current `dev` branch, and is fixed by this branch
@Cyan4973
Copy link
Contributor Author

test added in this PR,
checked manually on dev branch (where it produces an error signal, as expected).

@Cyan4973 Cyan4973 force-pushed the fix4332 branch 15 times, most recently from 848a904 to 5907c45 Compare March 11, 2025 01:46
use an alias instead of a function

also: added more traces and updated version nb to v1.5.8
@Cyan4973
Copy link
Contributor Author

Cyan4973 commented Mar 11, 2025

In the process, fixed a latent limitation of the test shell script playTests.sh,
where was unable to pass environment variables (such as ZSTD_NBTHREADS) to zstd
specifically in FreeBSD environment (and possibly other *BSD).

@Cyan4973 Cyan4973 merged commit f9a6031 into facebook:dev Mar 11, 2025
101 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants