microsoft / microsoft/mimalloc

Request to finish a TODO in code

Open
#659 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
13.4k
Forks
1.2k
Avg merge
4d 45m
Merged PRs (30d)
13

Description

Hi,

First thanks for the amazing work on mimalloc. I have a problem, we have a quite big workload, a server with 4TB of physical memory that we use by allocating millions of small malloc regions. We have a prune thread that frees objects in a LRU fashion. As we allocate in ~ 200 threads and free in a single one I notices I needed to call mi_collect(true) to force the prune to actually "free" the memory as most/all of it would have come from other threads heaps. That somewhat works, but the memory is not actually freed back to the server, so I would like to request if this todo in segment-cache.c is being worked on by someone, or could:

// decommit committed parts
// TODO: instead of decommit, we could also free to the OS?
mi_commit_mask_decommit(&slot->commit_mask, slot->p, MI_SEGMENT_SIZE, tld->stats);
mi_commit_mask_create_empty(&slot->decommit_mask);

We are in plans to moving all of this to be done by some form of garbage collector as we have no particular love for the object addresses and it would be fine to move and compact objects, but not for the short/middle term so having this feature can allow us to move this process from jemalloc to mimalloc.

ps: jemalloc also seems to use less committed memory, which on windows server is kinda important as windows needs a pagefile to let you overcommit memory (very silly in my view, but hasn't changed in the past 15 years so I think it won't change soon).

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start in segment-cache.c at the TODO around mi_commit_mask_decommit and mi_commit_mask_create_empty, then review how mi_collect(true) handles memory from other threads. Define and validate behavior that releases unused committed memory back to the operating system, especially for the reported Windows server workload.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
operating-systems, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.