Robert P. J. Day | 1 Nov 2006 11:19
Picon

whether the placement of "volatile" makes a difference


  from the definition of an "atomic" variable in the linux kernel,
there are numerous arch-specific header files that define an atomic
variable in one of two ways:

  1) typedef struct { int counter; } atomic_t;
  2) typedef struct { volatile int counter; } atomic_t;

the purported need for the "volatile" type qualifier is to guarantee
that the (gcc) compiler doesn't try to do anything clever with code
generation, of course, which makes sense.

  the problem is that some architectures add the "volatile" qualifier,
while others don't.  but whether it's necessary isn't just related to
the architecture, is it?  wouldn't it be related to just the
properties of the compiler itself?

  second, even if an architecture didn't strictly *need* that
qualifier, would it hurt to have it there?  surely having an
unnecessary "volatile" qualifier couldn't break code that would
otherwise work, could it?  it would only prevent some possible
optimization, no?

  and, finally, in some of those header files, even if the typedef
doesn't use "volatile", some of the function definitions do:

static inline int atomic_add_return (int i, volatile atomic_t *v) {
                                            ^^^^^^^^

  i find this curious.  in this particular header file, while the
(Continue reading)

Prasanta Sadhukhan | 13 Nov 2006 14:31
Picon

max heap usage of a Linux process

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 <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Markus Rechberger | 13 Nov 2006 15:09
Picon

Re: max heap usage of a Linux process

Hi,

On 11/13/06, Prasanta Sadhukhan <Prasanta.Sadhukhan <at> 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 <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Christ, Bryan | 13 Nov 2006 16:30
Picon
Favicon

Re: max heap usage of a Linux process

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 <at> 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 <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Dan Gary | 13 Nov 2006 16:39
Picon

Re: max heap usage of a Linux process

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 <at> gmail.com> wrote:
> Hi,
>
> On 11/13/06, Prasanta Sadhukhan <Prasanta.Sadhukhan <at> 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 <at> 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 <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Markus Rechberger | 13 Nov 2006 16:59
Picon

Re: max heap usage of a Linux process

Hi,

On 11/13/06, Dan Gary <funkychunkymunky <at> 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);
(Continue reading)

Christ, Bryan | 13 Nov 2006 17:12
Picon
Favicon

Re: max heap usage of a Linux process

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 <at> 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(){
(Continue reading)

Prasanta Sadhukhan | 14 Nov 2006 07:26
Picon

Re: max heap usage of a Linux process

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 <at> gmail.com> wrote:
>
>> Hi,
>>
>> On 11/13/06, Prasanta Sadhukhan <Prasanta.Sadhukhan <at> 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
(Continue reading)

Glynn Clements | 14 Nov 2006 11:57

Re: max heap usage of a Linux process


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 <at> gclements.plus.com>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Prasanta Sadhukhan | 14 Nov 2006 12:30
Picon

Re: max heap usage of a Linux process

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?

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
(Continue reading)


Gmane