microsoft / microsoft/mimalloc

Negative current commited stat with purge_delay=0

Open
#1,141 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
13.4k
Forks
1.2k
Avg merge
4d 45m
Merged PRs (30d)
13

Description

Duplicate of #929 #1118, but I want to bump this issue up so it gains more attention. With `mi_option_purge_decommits=1` and `mi_option_purge_delay=0`, the current commited stat becomes negative after calling `mi_collect`. I first assumed that this is the current amount of memory that is not yet decommited (relative to total), but it doesn't add up. So its either a bug or an undocumented feature.

Running with latest master:

```c++
#include
#include
#include

int main() {
const int num_elements = 1000;
void* ptrs[num_elements];

mi_process_init();
mi_option_set(mi_option_purge_decommits, 1);
mi_option_set(mi_option_purge_delay, 0);
mi_option_set(mi_option_arena_reserve, 1024000); // 1GB

for (int i = 0; i < num_elements; i++) {
ptrs[i] = mi_malloc(50000);
}
for (int i = 0; i < num_elements; i++) {
mi_free(ptrs[i]);
}

mi_collect(true);

mi_stats_t stats;
mi_stats_get(sizeof(stats), &stats);
printf("%d mb", stats.committed.current / 1024 / 1024);
mi_stats_print_out(NULL, NULL);
}
```

```
[100%] Built target test
heap stats: peak total current block total#
reserved: 1.0 GiB 1.0 GiB 1.0 GiB
committed: 1.0 GiB 1.0 GiB -906.8 MiB
reset: 0
purged: 1.8 GiB
touched: 192.7 KiB 192.7 KiB -54.6 MiB
segments: 3 3 1 not all freed
-abandoned: 0 0 0 ok
-cached: 0 0 0 ok
pages: 0 0 -121 not all freed
-abandoned: 0 0 0 ok
-extended: 0
-retire: 0
arenas: 1
-rollback: 0
mmaps: 1
commits: 0
resets: 0
purges: 123
guarded: 0
threads: 0 0 0 ok
searches: 0.0 avg
numa nodes: 1
elapsed: 0.009 s
process: user: 0.000 s, system: 0.009 s, faults: 0, rss: 63.5 MiB, commit: 1.0 GiB
-906 mb%
```

```
pmap -x 77734 | grep -e "total \| RSS"
Address Kbytes RSS Dirty Mode Mapping
total kB 1051248 1868 220
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the minimal C reproducer with mi_option_purge_decommits, mi_option_purge_delay, mi_collect, and mi_stats_get, then compare the reported committed.current value with the printed mappings. Review the existing discussion in duplicate issues #929 and #1118; done means the committed statistic no longer becomes negative or its documented meaning explains the result.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.