Skip to content

Adding support for tagging individual allocs #1193

@malkia

Description

@malkia

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions