uucore: add allocation-failure handling - #14480
Conversation
Merging this PR will improve performance by 10.88%
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
|
Is there another tool prone to OOM aside from sort? Why doesn't it use |
Any allocating util can fall to this. |
|
GNU testsuite comparison: |
|
@sylvestre can you run the failing check? We're getting rate limited. |
|
Well that's a flaky CI run. |
|
I don't want to mask issues by this way which can be fixd by try_reserve. |
|
Can we patch uutils/coreutils to use different allocatior (e.g. mimalloc) easily at a fork after this PR was merged? |
This cannot be done if you use some struct like btreeset (see ptx for example) that do not allow for try_reserve. I could make it to be usable with mimalloc (or another one really) but it would become complicated. |
should be fixed at |
That would be blocked on rust-lang/rust#82766. |
Currently, an allocation failure in the utilities can bubble into Rust’s default failure path and panic or abort with a generic message.
memory allocation of ... bytes failed note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Aborted (core dumped) ./tsort /dev/fullstd::alloc::set_alloc_error_hook would allow uutils to customize allocation-failure handling, but it is still unstable and tracked in rust-lang/rust#51245.
This PR provides the stable equivalent by installing a wrapper around System.
It mimics gnu error behaviour, exiting with error code 1 like GNU coreutils.
this PR also provides for localisation, and
#[uucore::main(alloc_error_exit_code = N)]which supports custom shell return codes.
to simulate such an example, try