All of lore.kernel.org
 help / color / mirror / Atom feed
* max heap usage of a Linux process
@ 2006-11-13 13:31 Prasanta Sadhukhan
  2006-11-13 14:09 ` Markus Rechberger
  2006-11-13 15:30 ` Christ, Bryan
  0 siblings, 2 replies; 12+ messages in thread
From: Prasanta Sadhukhan @ 2006-11-13 13:31 UTC (permalink / raw)
  To: linux-c-programming

Hi,

Can anybody please tell how can I obtain the max. heap usage of a Linux
process?

Thx in advance
Prasanta


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: max heap usage of a Linux process
  2006-11-13 13:31 max heap usage of a Linux process Prasanta Sadhukhan
@ 2006-11-13 14:09 ` Markus Rechberger
  2006-11-13 15:39   ` Dan Gary
  2006-11-13 15:30 ` Christ, Bryan
  1 sibling, 1 reply; 12+ messages in thread
From: Markus Rechberger @ 2006-11-13 14:09 UTC (permalink / raw)
  To: Prasanta.Sadhukhan; +Cc: linux-c-programming

Hi,

On 11/13/06, Prasanta Sadhukhan <Prasanta.Sadhukhan@sun.com> wrote:
> Hi,
> 
> Can anybody please tell how can I obtain the max. heap usage of a Linux
> process?
> 

theoretically 3 GB (3/4 of 4gb - which are addressable by 32 bit) on a 32bit machine on a 64bit machine 3/4 of 16exabyte.

cheers,
Markus

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: max heap usage of a Linux process
  2006-11-13 13:31 max heap usage of a Linux process Prasanta Sadhukhan
  2006-11-13 14:09 ` Markus Rechberger
@ 2006-11-13 15:30 ` Christ, Bryan
  1 sibling, 0 replies; 12+ messages in thread
From: Christ, Bryan @ 2006-11-13 15:30 UTC (permalink / raw)
  To: Prasanta.Sadhukhan; +Cc: linux-c-programming

You should take a look at the man pages for getrlimit()

On Mon, 2006-11-13 at 19:01 +0530, Prasanta Sadhukhan wrote:
> Hi,
> 
> Can anybody please tell how can I obtain the max. heap usage of a Linux
> process?
> 
> Thx in advance
> Prasanta
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: max heap usage of a Linux process
  2006-11-13 14:09 ` Markus Rechberger
@ 2006-11-13 15:39   ` Dan Gary
  2006-11-13 15:59     ` Markus Rechberger
  2006-11-14  6:26     ` Prasanta Sadhukhan
  0 siblings, 2 replies; 12+ messages in thread
From: Dan Gary @ 2006-11-13 15:39 UTC (permalink / raw)
  To: linux-c-programming

unless parent is asking about malloc'd space, then mallinfo() or
malloc_stats() might be what they're looking for, memory profiling the
manual way, gotta love it

On 11/13/06, Markus Rechberger <mrechberger@gmail.com> wrote:
> Hi,
>
> On 11/13/06, Prasanta Sadhukhan <Prasanta.Sadhukhan@sun.com> wrote:
> > Hi,
> >
> > Can anybody please tell how can I obtain the max. heap usage of a Linux
> > process?
> >
>
> theoretically 3 GB (3/4 of 4gb - which are addressable by 32 bit) on a 32bit machine on a 64bit machine 3/4 of 16exabyte.
>
> cheers,
> Markus
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: max heap usage of a Linux process
  2006-11-13 15:39   ` Dan Gary
@ 2006-11-13 15:59     ` Markus Rechberger
  2006-11-13 16:12       ` Christ, Bryan
  2006-11-14  6:26     ` Prasanta Sadhukhan
  1 sibling, 1 reply; 12+ messages in thread
From: Markus Rechberger @ 2006-11-13 15:59 UTC (permalink / raw)
  To: Dan Gary; +Cc: linux-c-programming

Hi,

On 11/13/06, Dan Gary <funkychunkymunky@gmail.com> wrote:
> unless parent is asking about malloc'd space, then mallinfo() or
> malloc_stats() might be what they're looking for, memory profiling the
> manual way, gotta love it
>

interesting didn't know that..

though now I have a question about it ..

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>

int main(){
        char *foo;
        printf("total free space: %d\n",mallinfo().fordblks);
        foo=malloc(500000);
        if(foo){
                printf("successfully allocated!\n");
        } else {
                printf("error allocating!\n");
        }
        printf("arena: %d\n",mallinfo().arena);
        printf("ordblks: %d\n",mallinfo().ordblks);
        printf("max total allocated space: %d\n",mallinfo().usmblks);
        printf("total allocated space: %d\n",mallinfo().uordblks);
        printf("total free space: %d\n",mallinfo().fordblks);

        return 0;
}

outputs:
total free space: 0
successfully allocated!
arena: 0
ordblks: 1
max total allocated space: 0
total allocated space: 0
total free space: 0

If I allocate 50000bytes then it outputs:
total free space: 0
successfully allocated!
arena: 184320
ordblks: 1
max total allocated space: 0
total allocated space: 50008
total free space: 134312

does anyone have an explanation for that?

Markus

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: max heap usage of a Linux process
  2006-11-13 15:59     ` Markus Rechberger
@ 2006-11-13 16:12       ` Christ, Bryan
  0 siblings, 0 replies; 12+ messages in thread
From: Christ, Bryan @ 2006-11-13 16:12 UTC (permalink / raw)
  To: Markus Rechberger; +Cc: Dan Gary, linux-c-programming

If you want to know how much you are using, look at uordblks not
ordblks.  The allocator dishes out memory in chunks (not the same has
bytes requested via malloc() so there will most often be some
difference).  

See the GNU documentation at:
http://www.gnu.org/software/libc/manual/html_node/Statistics-of-Malloc.html#Statistics-of-Malloc

BTW, I think the chunk size will always be a multiple of page size (see
the man pages for getpagesize() -- but I haven't give it any thorough
investigation).  Perhaps someone on this list can confirm.

On Mon, 2006-11-13 at 16:59 +0100, Markus Rechberger wrote:
> Hi,
> 
> On 11/13/06, Dan Gary <funkychunkymunky@gmail.com> wrote:
> > unless parent is asking about malloc'd space, then mallinfo() or
> > malloc_stats() might be what they're looking for, memory profiling the
> > manual way, gotta love it
> >
> 
> interesting didn't know that..
> 
> though now I have a question about it ..
> 
> #include <malloc.h>
> #include <stdio.h>
> #include <stdlib.h>
> 
> int main(){
>         char *foo;
>         printf("total free space: %d\n",mallinfo().fordblks);
>         foo=malloc(500000);
>         if(foo){
>                 printf("successfully allocated!\n");
>         } else {
>                 printf("error allocating!\n");
>         }
>         printf("arena: %d\n",mallinfo().arena);
>         printf("ordblks: %d\n",mallinfo().ordblks);
>         printf("max total allocated space: %d\n",mallinfo().usmblks);
>         printf("total allocated space: %d\n",mallinfo().uordblks);
>         printf("total free space: %d\n",mallinfo().fordblks);
> 
>         return 0;
> }
> 
> outputs:
> total free space: 0
> successfully allocated!
> arena: 0
> ordblks: 1
> max total allocated space: 0
> total allocated space: 0
> total free space: 0
> 
> If I allocate 50000bytes then it outputs:
> total free space: 0
> successfully allocated!
> arena: 184320
> ordblks: 1
> max total allocated space: 0
> total allocated space: 50008
> total free space: 134312
> 
> does anyone have an explanation for that?
> 
> Markus
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: max heap usage of a Linux process
  2006-11-13 15:39   ` Dan Gary
  2006-11-13 15:59     ` Markus Rechberger
@ 2006-11-14  6:26     ` Prasanta Sadhukhan
  2006-11-14 10:57       ` Glynn Clements
  1 sibling, 1 reply; 12+ messages in thread
From: Prasanta Sadhukhan @ 2006-11-14  6:26 UTC (permalink / raw)
  To: Dan Gary; +Cc: linux-c-programming

Actually, I have the process-pid(s) and I want to find out 
programmatically, what's the max heap size that had been consumed by 
that process at any given moment(based on user command) from another 
process. It seems mallinfo().uordblks will give total occupied size of 
memory not the max heap size consumed. Also, how do I use malloc_stats()?

--Prasanta
Dan Gary wrote:

> unless parent is asking about malloc'd space, then mallinfo() or
> malloc_stats() might be what they're looking for, memory profiling the
> manual way, gotta love it
>
> On 11/13/06, Markus Rechberger <mrechberger@gmail.com> wrote:
>
>> Hi,
>>
>> On 11/13/06, Prasanta Sadhukhan <Prasanta.Sadhukhan@sun.com> wrote:
>> > Hi,
>> >
>> > Can anybody please tell how can I obtain the max. heap usage of a 
>> Linux
>> > process?
>> >
>>
>> theoretically 3 GB (3/4 of 4gb - which are addressable by 32 bit) on 
>> a 32bit machine on a 64bit machine 3/4 of 16exabyte.
>>
>> cheers,
>> Markus
>> -
>> To unsubscribe from this list: send the line "unsubscribe 
>> linux-c-programming" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
> -
> To unsubscribe from this list: send the line "unsubscribe 
> linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: max heap usage of a Linux process
  2006-11-14  6:26     ` Prasanta Sadhukhan
@ 2006-11-14 10:57       ` Glynn Clements
  2006-11-14 11:30         ` Prasanta Sadhukhan
                           ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Glynn Clements @ 2006-11-14 10:57 UTC (permalink / raw)
  To: Prasanta Sadhukhan; +Cc: Dan Gary, linux-c-programming


Prasanta Sadhukhan wrote:

> Actually, I have the process-pid(s) and I want to find out 
> programmatically, what's the max heap size that had been consumed by 
> that process at any given moment(based on user command) from another 
> process.

Then you need to read the files in /proc/<pid>/*. There isn't a system
call to get resource usage for another process.

Note that you won't be able to determine how much of the allocated
heap is free or used; that information is internal to the process, and
isn't visible externally.

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: max heap usage of a Linux process
  2006-11-14 10:57       ` Glynn Clements
@ 2006-11-14 11:30         ` Prasanta Sadhukhan
  2006-11-14 14:36           ` Glynn Clements
  2006-11-14 11:39         ` Al Boldi
  2006-11-14 15:19         ` Christ, Bryan
  2 siblings, 1 reply; 12+ messages in thread
From: Prasanta Sadhukhan @ 2006-11-14 11:30 UTC (permalink / raw)
  To: Glynn Clements; +Cc: Dan Gary, linux-c-programming

Glynn Clements wrote:

>Prasanta Sadhukhan wrote:
>
>  
>
>>Actually, I have the process-pid(s) and I want to find out 
>>programmatically, what's the max heap size that had been consumed by 
>>that process at any given moment(based on user command) from another 
>>process.
>>    
>>
>
>Then you need to read the files in /proc/<pid>/*. There isn't a system
>call to get resource usage for another process.
>
>Note that you won't be able to determine how much of the allocated
>heap is free or used; that information is internal to the process, and
>isn't visible externally.
>
>  
>
thanks. Infact, I used /proc/<pid>/statm to find out total size, RSS and 
shared memory from 1st 3 entries. Don't know about the accuracy or not 
but that will do. But, this file does not tell about max. heap consumed 
by a process nor does /proc/pid/status and I am not able to decipher 
/proc/pid/stat. Does anyone knows how to interpret stat file?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: max heap usage of a Linux process
  2006-11-14 10:57       ` Glynn Clements
  2006-11-14 11:30         ` Prasanta Sadhukhan
@ 2006-11-14 11:39         ` Al Boldi
  2006-11-14 15:19         ` Christ, Bryan
  2 siblings, 0 replies; 12+ messages in thread
From: Al Boldi @ 2006-11-14 11:39 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-c-programming

Glynn Clements wrote:
> Prasanta Sadhukhan wrote:
> > Actually, I have the process-pid(s) and I want to find out
> > programmatically, what's the max heap size that had been consumed by
> > that process at any given moment(based on user command) from another
> > process.
>
> Then you need to read the files in /proc/<pid>/*. There isn't a system
> call to get resource usage for another process.

Wow, really?  Reading /proc/<pid>/* is pretty expensive, especially if you 
have to do it for 1000's of procs.

That's probably why top is such a cpu-hog.


Thanks!

--
Al



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: max heap usage of a Linux process
  2006-11-14 11:30         ` Prasanta Sadhukhan
@ 2006-11-14 14:36           ` Glynn Clements
  0 siblings, 0 replies; 12+ messages in thread
From: Glynn Clements @ 2006-11-14 14:36 UTC (permalink / raw)
  To: Prasanta Sadhukhan; +Cc: Dan Gary, linux-c-programming


Prasanta Sadhukhan wrote:

> > > Actually, I have the process-pid(s) and I want to find out 
> > > programmatically, what's the max heap size that had been consumed by 
> > > that process at any given moment(based on user command) from another 
> > > process.
> > 
> > Then you need to read the files in /proc/<pid>/*. There isn't a system
> > call to get resource usage for another process.
> > 
> > Note that you won't be able to determine how much of the allocated
> > heap is free or used; that information is internal to the process, and
> > isn't visible externally.
> 
> thanks. Infact, I used /proc/<pid>/statm to find out total size, RSS and 
> shared memory from 1st 3 entries. Don't know about the accuracy or not 
> but that will do. But, this file does not tell about max. heap consumed 
> by a process nor does /proc/pid/status and I am not able to decipher 
> /proc/pid/stat. Does anyone knows how to interpret stat file?

It's documented in the proc(5) manpage, but I don't think it records
the heap size separately.

Probably the best option is to look in /proc/<pid>/maps for writable
segments with zero for the device and inode numbers (i.e. anonymous
maps).

Also, note that glibc's malloc can use explicit anonymous mmap() to
obtain memory, as well as sbrk(), so there isn't a monolithic "heap"
in the traditional sense.

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: max heap usage of a Linux process
  2006-11-14 10:57       ` Glynn Clements
  2006-11-14 11:30         ` Prasanta Sadhukhan
  2006-11-14 11:39         ` Al Boldi
@ 2006-11-14 15:19         ` Christ, Bryan
  2 siblings, 0 replies; 12+ messages in thread
From: Christ, Bryan @ 2006-11-14 15:19 UTC (permalink / raw)
  To: Glynn Clements; +Cc: Prasanta Sadhukhan, Dan Gary, linux-c-programming

If you don't feel like reading proc or want to make things more
portable, use libgtop.

On Tue, 2006-11-14 at 10:57 +0000, Glynn Clements wrote:
> Prasanta Sadhukhan wrote:
> 
> > Actually, I have the process-pid(s) and I want to find out 
> > programmatically, what's the max heap size that had been consumed by 
> > that process at any given moment(based on user command) from another 
> > process.
> 
> Then you need to read the files in /proc/<pid>/*. There isn't a system
> call to get resource usage for another process.
> 
> Note that you won't be able to determine how much of the allocated
> heap is free or used; that information is internal to the process, and
> isn't visible externally.
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2006-11-14 15:19 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-13 13:31 max heap usage of a Linux process Prasanta Sadhukhan
2006-11-13 14:09 ` Markus Rechberger
2006-11-13 15:39   ` Dan Gary
2006-11-13 15:59     ` Markus Rechberger
2006-11-13 16:12       ` Christ, Bryan
2006-11-14  6:26     ` Prasanta Sadhukhan
2006-11-14 10:57       ` Glynn Clements
2006-11-14 11:30         ` Prasanta Sadhukhan
2006-11-14 14:36           ` Glynn Clements
2006-11-14 11:39         ` Al Boldi
2006-11-14 15:19         ` Christ, Bryan
2006-11-13 15:30 ` Christ, Bryan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.