在AIX上,VSZ和RSS不断增加

VSZ and RSS kept increasing on AIX

本文关键字:RSS 不断增加 VSZ AIX      更新时间:2023-10-16

在AIX上运行我的应用程序时,我看到一个异常的内存使用模式…

我已经创建了一个简单的程序来malloc和自由复制相同的问题。

int main()
{
    int *ptr_one;
    // enter value as 0.
    // I wanted few secs fetch the PID of this statndlone process
    // and run 'ps -p <PID> -o "vsz rssize"'
    long a;
    scanf("%ld", &a);
    for(;;)
    {
        if(a < 10000000) a = a + 100;
        ptr_one = (int *)malloc(sizeof(int)*a);
        if (ptr_one == 0){
        printf("ERROR: Out of memoryn");
        return 1;
        }
        *ptr_one = 25;
        printf("%dn", *ptr_one);
        free(ptr_one);
    }
    return 0;
}
我使用下面的命令 捕获了这个程序的内存使用情况
ps -p $1 -o "vsz rssize" | tail -1  >> out.txt

图显示内存一直在增长,没有释放。这是泄漏的迹象,还是AIX上的正常内存行为?

进程的内存使用大小没有减少是完全正确的:虽然malloc可以为进程请求额外的内存,但free永远不会将其返回给系统。相反,释放的内存在以后的malloc调用中重用。