Rust bindings: MiMalloc::allocate should return actual usable size

Open Beginner friendly
#1,513 6 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
66/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
tooling

Research direction

Start in contrib/rust/src/allocator.rs around the allocate method that currently returns exactly layout.size(), and read the linked purpleprotocol nightly_allocator_api.rs for the pattern. Check how mimalloc exposes its usable-size function through the existing FFI bindings in the same crate, then return that value instead. Run cargo test in contrib/rust; done means the allocator reports the larger usable block while still satisfying the Allocator contract.

Written by the indexing model from the issue text.

Description

Connections

https://github.com/microsoft/mimalloc/issues/1405 - Support official Rust FFI bindings

Summary

The Rust bindings for mimalloc always return an allocation of exactly the requested size:

https://github.com/microsoft/mimalloc/blob/1d8fd85aa3abe719cd9c42c855f1fc27dbccf84d/contrib/rust/src/allocator.rs#L28-L36

However, the allocator API says:

The returned block may have a larger size than specified by layout.size()

As such, I'd propose doing something similar to what purpleprotocol's Rust bindings do:

https://github.com/purpleprotocol/mimalloc_rust/blob/a35cc759c071fd7bd586685048367839002b95dd/src/nightly_allocator_api.rs#L7-L36

This would help improve the performance of collection types (like Vec) by allowing them to use the full space of the allocation.

Dominant language
C
Stars
13.6k
Forks
1.2k
Avg merge
12h 35m
Merged PRs (30d)
18

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/mimalloc

All issues in microsoft/mimalloc

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.