shuf: Fix OOM crash for huge number ranges#5980
Merged
sylvestre merged 3 commits intouutils:mainfrom Feb 25, 2024
Merged
Conversation
Collaborator
Author
|
Fixes #1420. I can't believe I forgot to link that issue, that was the reason I was looking into |
c0069a5 to
c11ec11
Compare
Collaborator
Author
|
Changes since last push:
|
c11ec11 to
7707771
Compare
7707771 to
db893a0
Compare
Collaborator
Author
|
Changes since last push:
|
db893a0 to
d04c2d2
Compare
Collaborator
Author
|
Changes since last push:
|
This requires special handling, because we cannot always generate all possible strings beforehand, e.g. in the case of "-n 2 -i 0-2147483647".
d04c2d2 to
f79dc64
Compare
Collaborator
Author
|
Changes since last push:
EDIT: Nope, this definitely doesn't pass the |
f79dc64 to
f25b210
Compare
Collaborator
Author
|
Changes since last push:
Seemingly-relevant output of `test_with_pr_core_utils_tests`The timestamp is pretty much the exact time at which the CI action ran, so it seems absolutely reasonable that by pure chance the right and left sides ran at sliiightly different fractions of a second, and straddled the tick of a second. Given how busy the CI machines are, that seems reasonable to me. (many empty lines removed) |
Contributor
|
excellent, thanks |
This was referenced Feb 25, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gnu_shuf -n10 -r -i0-4294967295will run perfectly fine on virtually all platforms, and allocates only 2 MiB.uushuf -n10 -r -i0-4294967295immediately OOMs withmemory allocation of 103079215104 bytes failed, and probably needs at least 137 GiB of RAM and several hours if not weeks to actually work.This PR fixes this crash bug, by treating number ranges specially:
Vec<&[u8]>and the "number range" concepts.The "special implementation" is a really stupid approach. I'm sure this can be optimized further (e.g. bitsets?), but first let's get this working at all. Also note that this will fix a failure in one of the GNU shuf tests.
Furthermore, observe how much faster it becomes even for "small" numbers, here running
{shuf} -n5 -i1-{upper_limit_like_50k}:Raw `data.csv` of this graph, also zoomed out
All times measured by hyperfine using
hyperfine -N -w2 -L upperk 1,2,3,5,7,10,20,35,50,75,100,500 -L shuf "./gnu_shuf_9_4,./target/release_shuf_main_420dfe8a,./target/release_shuf_number_speed_g44877f96" --export-json shuf_hyperfine.json -- "{shuf} -i1-{upperk}000 -n5"I believe the column order is:
I can tidy up and share the script I wrote which generated the above CSV from the JSON, if you'd like.
This affects one benchmarks negatively, and two strongly positively:
Benchmark
-i 0-10000000 > /dev/nullbecomes 9-11 % slowerI believe this is an unavoidable trade-off between memory and speed. We could add another branch to just populate a
Vec<&[u8]>like in the old days if the range is small enough, but then we will bikeshed about where to draw the line. I'll leave this work to someone else.Benchmark
input.txt > /dev/nulldidn't change (as expected)Benchmark
-r -n 10000000 -i 0-1000 > /dev/nullbecomes 438 % fasterNew benchmark
-n 100 -i 1000-2000000000 > /dev/nullbecomes +Inf % faster