Adding support for tagging individual allocs

Open
#1,193 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
c

Research direction

Start by reviewing the existing new/malloc interfaces, allocation headers, deallocation path, and any tracking API mentioned in the issue. Decide how a thread-local tag would be assigned and retained without breaking current allocation interfaces. Done means the tagging design, metadata storage, deallocation behavior, and tracking statistics are specified and implemented with suitable validation.

Written by the indexing model from the issue text.

Description

Hi @daanx and others!

I was wondering if anyone has ever implemented, or extended mimalloc in ways that it can support tagging - e.g. maybe initially just a custom provided byte, or word, dword that marks the block in a way.

Now I know this comes with few gotchas - existing new/malloc interfaces do not have this, so it has to be a threadlocal "global" (not ideal), but that would be acceptable for our use case. We can have some RAII controlled scopes pushing and popping threadlocal tags.

Then later, through a tracking API we can expose some stats and have IMG1 tag used this amount of bytes, etc.

The nasty bit here, is that this would require reading bits from the header just before that memory block is going to be deallocated... unless some scheme to keep tags on the side.

More or less, something that mimics Microsoft's Kernel ExAllocatePoolXxx functions - https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-exallocatepool2

Just pondering on ideas, thoughts before diving in.

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

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.