microsoft / microsoft/mimalloc
reuse free'd memory?
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 13.4k
- Forks
- 1.2k
- Avg merge
- 4d 45m
- Merged PRs (30d)
- 13
Description
I have a program that in a tight loop needs to allocate and deallocate blocks of memory (let's say of sizes (a,b,c) ), but they are the same in every iteration. I would have expected mimalloc to re-use previously allocated memory, but instead I see:
```
allocating Ptr{Nothing} @0x0000048b74020000
allocating Ptr{Nothing} @0x0000048b84020000
freeing Ptr{Float64} @0x0000048b84020000
allocating Ptr{Nothing} @0x0000048b94020000
allocating Ptr{Nothing} @0x0000048598020000
allocating Ptr{Nothing} @0x0000048bbc020000
freeing Ptr{Float64} @0x0000048bbc020000
freeing Ptr{Float64} @0x0000048598020000
freeing Ptr{Float64} @0x0000048b74020000
allocating Ptr{Nothing} @0x0000048be4020000
allocating Ptr{Nothing} @0x0000048598030500
allocating Ptr{Nothing} @0x0000048c0c020000
freeing Ptr{Float64} @0x0000048c0c020000
freeing Ptr{Float64} @0x0000048598030500
freeing Ptr{Float64} @0x0000048b94020000
allocating Ptr{Nothing} @0x0000048c34020000
allocating Ptr{Nothing} @0x0000048598020000
allocating Ptr{Nothing} @0x0000048c44020000
freeing Ptr{Float64} @0x0000048c44020000
freeing Ptr{Float64} @0x0000048598020000
freeing Ptr{Float64} @0x0000048be4020000
allocating Ptr{Nothing} @0x0000048598040000
freeing Ptr{Float64} @0x0000048c34020000
allocating Ptr{Nothing} @0x00000485984402c0
allocating Ptr{Nothing} @0x0000048598450000
freeing Ptr{Float64} @0x0000048598450000
freeing Ptr{Float64} @0x0000048598040000
freeing Ptr{Float64} @0x00000485984402c0
---
allocating Ptr{Nothing} @0x0000048c54020000
allocating Ptr{Nothing} @0x0000048c64020000
freeing Ptr{Float64} @0x0000048c64020000
allocating Ptr{Nothing} @0x0000048c74020000
allocating Ptr{Nothing} @0x0000048598020000
allocating Ptr{Nothing} @0x0000048c9c020000
freeing Ptr{Float64} @0x0000048c9c020000
freeing Ptr{Float64} @0x0000048598020000
freeing Ptr{Float64} @0x0000048c54020000
allocating Ptr{Nothing} @0x0000048cc4020000
allocating Ptr{Nothing} @0x0000048598030a00
allocating Ptr{Nothing} @0x0000048cec020000
freeing Ptr{Float64} @0x0000048cec020000
freeing Ptr{Float64} @0x0000048598030a00
freeing Ptr{Float64} @0x0000048c74020000
allocating Ptr{Nothing} @0x0000048d14020000
allocating Ptr{Nothing} @0x0000048598020000
allocating Ptr{Nothing} @0x0000048d24020000
freeing Ptr{Float64} @0x0000048d24020000
freeing Ptr{Float64} @0x0000048598020000
freeing Ptr{Float64} @0x0000048cc4020000
allocating Ptr{Nothing} @0x0000048598040000
freeing Ptr{Float64} @0x0000048d14020000
allocating Ptr{Nothing} @0x0000048598440300
allocating Ptr{Nothing} @0x0000048598450000
freeing Ptr{Float64} @0x0000048598450000
freeing Ptr{Float64} @0x0000048598040000
freeing Ptr{Float64} @0x0000048598440300
---
allocating Ptr{Nothing} @0x0000048d34020000
allocating Ptr{Nothing} @0x0000048d44020000
freeing Ptr{Float64} @0x0000048d44020000
allocating Ptr{Nothing} @0x0000048d54020000
allocating Ptr{Nothing} @0x0000048598020000
allocating Ptr{Nothing} @0x0000048d7c020000
freeing Ptr{Float64} @0x0000048d7c020000
freeing Ptr{Float64} @0x0000048598020000
freeing Ptr{Float64} @0x0000048d34020000
allocating Ptr{Nothing} @0x0000048da4020000
allocating Ptr{Nothing} @0x0000048598030a00
allocating Ptr{Nothing} @0x0000048dcc020000
freeing Ptr{Float64} @0x0000048dcc020000
freeing Ptr{Float64} @0x0000048598030a00
freeing Ptr{Float64} @0x0000048d54020000
allocating Ptr{Nothing} @0x0000048df4020000
allocating Ptr{Nothing} @0x0000048598020000
allocating Ptr{Nothing} @0x0000048e04020000
freeing Ptr{Float64} @0x0000048e04020000
freeing Ptr{Float64} @0x0000048598020000
freeing Ptr{Float64} @0x0000048da4020000
allocating Ptr{Nothing} @0x0000048598040000
freeing Ptr{Float64} @0x0000048df4020000
allocating Ptr{Nothing} @0x0000048598440380
allocating Ptr{Nothing} @0x0000048598450000
freeing Ptr{Float64} @0x0000048598450000
freeing Ptr{Float64} @0x0000048598040000
freeing Ptr{Float64} @0x0000048598440380
```
So despite allocating blocks that are of the same size as very recently free'd memory, mimalloc does not reuse it. Is this expected behaviour?
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
Start by reproducing the reported tight-loop allocation and deallocation pattern, using the sizes and pointer trace shown in the issue. Determine whether the differing addresses are expected allocator behavior, then document the conditions that explain the lack of reuse and any confirmed change needed; no files or tests are identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- operating-systems, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100