microsoft / microsoft/mimalloc

Negative numbers in the stats (v.2.24)

Open
#1,118 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

in our interactive server, the `mem` command will execute
```
size_t current = 0, peak = 0;
mi_process_info(nullptr, nullptr, nullptr, ¤t, &peak, nullptr, nullptr, nullptr);
```

and the `mem full` command does (pseudo-code)
```
ask each thread to execute:
mi_collect(false); mi_collect(true); mi_stats_merge();

return mi_stats_get_json
```

Here's a session, where we typed `mem, mem full, mem` all in a row (the server was running, but the entire test took less than 2 seconds).

```
# mem
{"current":"262270976", "peak":"1164668928", ...}
```

```
# mem full

[{
"version": 1,
"mimalloc_version": 224,
"process": {
"elapsed_msecs": 335944,
"user_msecs": 88246,
"system_msecs": 60148,
"page_faults": 3317,
"rss_current": 18446744073468309504, <====
"rss_peak": 1198329856,
"commit_current": 18446744073468309504, <====
"commit_peak": 979955712
},
"pages": { "total": 0, "peak": 0, "current": -14417 },
"reserved": { "total": 2554785792, "peak": 2554785792, "current": 2554785792 },
"committed": { "total": 1491464192, "peak": 979955712, "current": -241242112 }, <====
"reset": { "total": 0, "peak": 0, "current": 0 },
"purged": { "total": 1714290688, "peak": 1714290688, "current": 1714290688 },
"page_committed": { "total": 3145728, "peak": 1699856, "current": -2557365280 },
"pages_abandoned": { "total": 24, "peak": 24, "current": 8 },
"threads": { "total": 42, "peak": 37, "current": 37 },
"malloc_normal": { "total": 0, "peak": 0, "current": 0 },
"malloc_huge": { "total": 2262679552, "peak": 2262679552, "current": 2262679552 },
"malloc_requested": { "total": 0, "peak": 0, "current": 0 },
"mmap_calls": 40,
"commit_calls": 1447,
"reset_calls": 0,
"purge_calls": 1676,
"arena_count": 2,
"malloc_normal_count": 0,
"malloc_huge_count": 2450,
"malloc_guarded_count": 0,
"arena_rollback_count": 0,
"arena_purges": 25,
"pages_extended": 0,
"pages_retire": 0,
"page_searches": 0,
"segments": { "total": 51, "peak": 50, "current": 42 },
"segments_abandoned": { "total": 4, "peak": 4, "current": 1 },
...
"page_bins": [
{ "total": 0, "peak": 0, "current": 0, "block_size": 8, "page_size": 65536 },
{ "total": 0, "peak": 0, "current": -21, "block_size": 8, "page_size": 65536 },
{ "total": 0, "peak": 0, "current": -183, "block_size": 16, "page_size": 65536 },
{ "total": 0, "peak": 0, "current": 0, "block_size": 24, "page_size": 65536 },
{ "total": 0, "peak": 0, "current": -98, "block_size": 32, "page_size": 65536 },
...
]
}
```

```
# mem
{"current":"18446744072832557056", "peak":"1249579008"...}
```

so `current` was initially ok, it became negative after `mi_collect` (but we don't know if there is a causality relationship), and after it gets negative, it never resets.

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

Reproduce the reported sequence of `mem`, `mem full`, and `mem` in the interactive server. Start by tracing the paths through `mi_process_info`, `mi_collect`, `mi_stats_merge`, and `mi_stats_get_json`, comparing the counters before and after collection. Done means the reported current statistics no longer become negative or wrap to large unsigned values, with the behavior verified against the same sequence.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.