microsoft / microsoft/mimalloc
Assertion failure in mi_collect(true)
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 13.4k
- Forks
- 1.2k
- Avg merge
- 4d 45m
- Merged PRs (30d)
- 13
Description
After #221 and enabling full debug I have one test failing:
```
#[test]
fn it_could_call_mimalloc() {
let x = mi_malloc(10);
mi_free(x);
mi_collect(true); // works with false
}
```
```
mimalloc: assertion failed: at "G:\Dev\FIDS\lib\Spreads.Native\rs\spreads-mimalloc-sys\mimalloc\src\segment.c":545, _mi_segment_thread_collect
assertion: "tld->pages_reset.first == NULL"
```
It works with `mi_collect(false)`.
Also related question. I have it in the test because after reading the docs on `mi_collect` I thought it might be useful, since freeing from a different thread is the default scenario (.NET Tasks/ThreadPool).
> **void mi_collect ( bool force )**
Eagerly free memory.
Parameters: force If true, aggressively return memory to the OS (can be expensive!)
Regular code should not have to call this function. It can be beneficial in very narrow circumstances; in particular, **_when a long running thread allocates a lot of blocks that are freed by other threads_** it may improve resource usage by calling this every once in a while.
If I call `mi_collect(true)` from some background lower-priority thread how much this call affects other worker threads? Will it block them or there is some lock-free algo?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failing Rust test that calls mi_collect(true), then inspect mimalloc/src/segment.c at the reported assertion in _mi_segment_thread_collect. Compare the behavior with mi_collect(false), determine why the assertion is reached, and document the impact of calling collection from another thread. Done means the failure is resolved or clearly diagnosed with coverage for the reported scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- backend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100