我试图得到一个长时间运行的linux进程在短时间间隔内使用的最大内存量,例如:
resetmaxrss(); // hypothetical new command
void* foo = malloc(4096);
free(foo);
getrusage(...); // 'ru_maxrss' reports 4096 plus whatever else is alive
resetmaxrss();
void* bar = malloc(2048);
free(bar);
getrusage(...); // 'ru_maxrss' reports 2048 + whatever, *not* 4096
我发现并排除的选项:
其他选择,没有一个是好的:
- 投票。很容易错过我们的分配。
- 测试我们的代码。我们不能访问所有正在使用的内存分配器,所以这不会很优雅或直接。我也宁愿使用操作系统报告的值来保证准确性。
除了给Linux内核打补丁之外,还有什么方法可以做到这一点吗?
1条答案
按热度按时间wyyhbhjk1#
事实证明,自Linux 4.0以来,RSS峰值 * 可以 * 重置:
该HWM/峰值RSS可通过
/proc/[pid]/status
-〉VmHWM
或getrusage()
读取。补丁RFC