Manoj Joseph wrote: > Hi, > > I am trying to programatically determine the heap usage of a process. > The idea is that when the heap grows beyond a point, the process gives > up some of the memory it has allocated. > > Looks like getrusage() won't help. > > I tried reading /proc/$$/psinfo. But that does not seem to be useful. > This is what I tried: > > prpsinfo_t ps; > > sprintf(proc,"/proc/%d/psinfo", getpid()); > for(i = 0; i < 100; i++) { > if ((fd = open(proc, O_RDONLY)) == -1) { > perror("open"); > exit(1); > } > if(read(fd, &ps, sizeof(ps)) == -1) { > perror("read"); > exit(2); > } > close(fd); > if( i == 0 || i == 99) > printf("%lu, %lu\n", ps.pr_rssize, ps.pr_byrssize); > > malloc(1024 * (i+1)); > } > > The output is like this: > bash-3.00# ./rss > 3561889832, 134509752 > 3561889832, 134509752 > > It does not show a change in pr_rssize. Is my understanding of pr_rssize > wrong? Any clue as to what might be wrong? >
The system malloc implementation doesn't return virtual memory to the OS. If an application stops referencing pages and physical memory is short, the OS will copy those pages to the swap device so that the physical memory is available for other applications to use. If your app wishes to directly manage it's use of memory, other techniques (mmap, libumem + large allocations, etc) will be needed. -= Bart -- Bart Smaalders Solaris Kernel Performance [EMAIL PROTECTED] http://blogs.sun.com/barts _______________________________________________ opensolaris-code mailing list opensolaris-code@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/opensolaris-code