Negative current commited stat with purge_delay=0

未关闭
#1,141 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
c

调研方向

首先使用 mi_option_purge_decommits、mi_option_purge_delay、mi_collect 和 mi_stats_get 运行最小 C 复现程序,然后将报告的 committed.current 值与打印出的映射进行比较。查看重复 issue #929 和 #1118 中现有的讨论;完成的标准是 committed 统计值不再变为负数,或者其文档化含义能够解释该结果。

由索引模型根据 Issue 内容生成。

描述

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:

#include <stdio.h>
#include <mimalloc.h>
#include <mimalloc-stats.h>

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
主要语言
C
星标
13.6k
派生
1.2k
平均合并
18 小时 12 分钟
30 天内合并 PR
20

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/mimalloc 的其他 Issue

查看 microsoft/mimalloc 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。