3

I am running this code on AIX 6.1

while(true)
{
    int a = rand(); //generate a random integer value
    void* test = malloc(a*a); //allocate large chunk of memory block
    usleep(3000000); //sleep for 3 sec 
    free(test); // release memory block
}

using MALLOCTYPE=buckets My observation is Resident set size(real memory) and data section size for process is continuously increasing. This is check by command ps v PID pg sp value shown in topas for process is slowly increasing.

Can someone justify this behavior.

PankajM
  • 417
  • 2
  • 10
  • if you don't get an answer in a while, look at the AIX areas on ittoolbox.com. A lot of AIX gurus there. Good luck. – shellter Nov 08 '12 at 18:05
  • What is RAND_MAX on your platform? It's 2^31-1 on my system (non-AIX, though), which means `a*a` might be seriously large for a memory allocation. Regardless, in most C library implementations I've seen, just `free()`ing a memory block does not generally shrink the process virtual memory size, it just returns the block to the `malloc()`/`free()` allocator. So I would expect your heap to never be smaller than the largest allocation you've made so far. – twalberg Nov 08 '12 at 18:36
  • int max is 2^31-1 on my machine. I have 16 GB RAM and 500 MB page space. Memory allocation request in code is in the range of 1 MB to 1000 MB. Data segment size is increasing from 400 K. – PankajM Nov 08 '12 at 19:05

1 Answers1

1

On free, memory is not released to AIX os, but it is reserved for reuse. With MALLOCOPTIONS=disclaim, free releases memory back to AIX os and their is not increase in memory utilization. But with MALLOCOPTIONS=disclaim, CPU utilization is almost 2-3 times greater.

PankajM
  • 417
  • 2
  • 10