Skip to content

docs: a preloaded allocator conflicts with the bundled jemalloc - #2164

Merged
tmccombs merged 2 commits into
sharkdp:masterfrom
paoValle:fix/2121-mimalloc-ld-preload
Nov 1, 2026
Merged

tmccombs merged 2 commits into
sharkdp:masterfrom
paoValle:fix/2121-mimalloc-ld-preload

Conversation

@paoValle

@paoValle paoValle commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

fd links jemalloc through the use-jemalloc feature, which is enabled by default for some targets. Preloading another allocator (LD_PRELOAD=/usr/bin/mimalloc fd) makes the two disagree about which of them owns an allocation, and fd crashes. #2121 asked for either a normal run or a clear error; as tmccombs said there, fd cannot tell: the preloaded library is already the one answering by the time the first allocation happens.

So this documents the conflict in the troubleshooting section, next to the other "fd does something surprising" entries: the crash, why it cannot be detected from inside fd, and cargo build --release --no-default-features as the build that runs with a preloaded allocator.

I could not reproduce the crash here: jemalloc is disabled on macOS, which is why #2121 is Linux-only. What I did verify is that the documented build compiles and the binary it produces runs.

Closes #2121

AI disclosure

The README wording and this description were drafted with an AI coding assistant; the change is documentation only and I have read it.

@paoValle

Copy link
Copy Markdown
Contributor Author

Hi — a quick check on this docs change: is it something you'd want in? The branch builds and the checks are green (18 pass, 1 skipped). If there's no interest I'll go ahead and close it in ten days or so, no worries at all — I'd just rather keep my queue tidy than leave it sitting.

Comment thread README.md Outdated

### `fd` crashes when another memory allocator is preloaded

The Linux binaries link against jemalloc for speed, through the `use-jemalloc` feature that is on by

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Whether it is on by default or not depends on the platform it was compiled fore

Comment thread README.md
> LD_PRELOAD=/usr/bin/mimalloc fd
```

makes the two disagree about which of them owns an allocation, and `fd` crashes. `fd` cannot detect

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this is a little wordy. It's probably sufficient just to say that using LD_PRELOAD with a different allocation isn't supported, and suggest compiling without jemalloc if that is desired.

Comment thread README.md Outdated
> cargo build --release --no-default-features --features completions
```

The `completions` feature is listed separately because `--no-default-features` turns it off too.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

FWIW the completions feature isn't really needed unless you want to be able to run fd --gen-completions

The released Linux binaries link jemalloc through the `use-jemalloc` feature,
which is on by default but is only compiled in on some targets. Preloading
another allocator there makes the two disagree about which of them owns an
allocation, and fd crashes; that cannot be detected from inside fd, because the
preloaded library is already answering when fd runs its first allocation.

The troubleshooting section now says which targets, says it is unsupported, and
gives the build that runs with a preloaded allocator:
`cargo build --release --no-default-features`.

No changelog entry: this changes no behaviour, per CONTRIBUTING.

The README wording was drafted with an AI coding assistant.
@paoValle
paoValle force-pushed the fix/2121-mimalloc-ld-preload branch from a9bd193 to d920b76 Compare October 28, 2026 08:32
@paoValle

Copy link
Copy Markdown
Contributor Author

All three taken on d920b76, rebased onto b7a0a29.

  • :454 now names the targets instead of saying "on by default": jemalloc is compiled in everywhere but Windows, macOS, FreeBSD, OpenBSD, illumos, Android, 32-bit musl and riscv64 — the same list as the cfg on the global_allocator in src/main.rs.
  • :461 is down to the unsupported sentence plus the build hint.
  • :471 is gone: the command is now plain cargo build --release --no-default-features, since completions only matter if you want --gen-completions.

Comment thread README.md Outdated

The released Linux binaries use jemalloc, through the `use-jemalloc` feature. It is on by default, but
it is only compiled in on some targets: not on Windows, macOS, FreeBSD, OpenBSD, illumos, Android,
32-bit musl or riscv64. There, preloading a different allocator is not supported, for example

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The use of "There" here is unclear. Is it refering to the targets that are compiled with jemalloc, or that aren't?

Comment thread README.md Outdated
### `fd` crashes when another memory allocator is preloaded

The released Linux binaries use jemalloc, through the `use-jemalloc` feature. It is on by default, but
it is only compiled in on some targets: not on Windows, macOS, FreeBSD, OpenBSD, illumos, Android,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not sure about listing the targets that are excluded here. It has the potential to get out of date if the list is changed in Cargo.toml.

How about just saying that it is enabled by default for some targets.

The list goes stale as soon as the cfg in Cargo.toml changes, and "There"
did not say whether it meant the targets that have jemalloc or the ones
that do not.
@paoValle

Copy link
Copy Markdown
Contributor Author

Both taken in d44b655. The list of targets is gone — you are right that it drifts from Cargo.toml — and the sentence now says the feature is enabled by default for some targets, which also removes the vague "There". I updated the description as well: it still mentioned --features completions.

@tmccombs
tmccombs merged commit cc4e40f into sharkdp:master Nov 1, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] fd crashes when mimalloc is preloaded with LD_PRELOAD

2 participants