program memory usage

Discussion in 'C Programming' started by Alessandro Basili, Sep 22, 2011.

  1. I'm facing a memory problem, since from time to time the memory usage of
    my program (shown with ps and/or top utilities) increases.

    I'm aware of the getrusage function from the GNU C library, but
    unfortunately the kernel we are using (linux 2.6) is not supporting the
    fields for memory usage in the rusage structure.

    Through some research I start to use the /proc file system and the statm
    file related to the pid of the running program.
    Now I have inserted throughout the program several calls to a function
    that prints the statistics from the statm file in order to isolate the
    increase of memory usage.

    Unfortunately the result points to a part of the program that does not
    have any hidden ambiguities related to memory usage, which is also
    confirmed by isolating it in a test program.

    What I would like to understand is if the system calls to update statm
    may be totally asynchronous with the current program flow (buffering,
    threading??) and if that is the case how can I get the usage of the
    memory reliably.

    Thanks for any suggestion.

    Al

    --
    A: Because it fouls the order in which people normally read text.
    Q: Why is top-posting such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alessandro Basili, Sep 22, 2011
    #1
    1. Advertising

  2. Alessandro Basili

    Eric Sosman Guest

    On 9/22/2011 8:08 AM, Alessandro Basili wrote:
    > I'm facing a memory problem, since from time to time the memory usage of
    > my program (shown with ps and/or top utilities) increases.
    >
    > I'm aware of the getrusage function from the GNU C library, but
    > unfortunately the kernel we are using (linux 2.6) is not supporting the
    > fields for memory usage in the rusage structure.
    >
    > Through some research I start to use the /proc file system and the statm
    > file related to the pid of the running program.
    > Now I have inserted throughout the program several calls to a function
    > that prints the statistics from the statm file in order to isolate the
    > increase of memory usage.
    >
    > Unfortunately the result points to a part of the program that does not
    > have any hidden ambiguities related to memory usage, which is also
    > confirmed by isolating it in a test program.
    >
    > What I would like to understand is if the system calls to update statm
    > may be totally asynchronous with the current program flow (buffering,
    > threading??) and if that is the case how can I get the usage of the
    > memory reliably.


    Try your question on a Linux or POSIX forum. None of the things
    you're asking about: getrusage, /proc, statm, threads, pids, ... are
    part of the C language or library, but are defined by the particular
    systems that provide them.

    --
    Eric Sosman
    d
     
    Eric Sosman, Sep 22, 2011
    #2
    1. Advertising

  3. Alessandro Basili

    Phil Carmody Guest

    Eric Sosman <> writes:
    > On 9/22/2011 8:08 AM, Alessandro Basili wrote:
    > > I'm facing a memory problem, since from time to time the memory usage of
    > > my program (shown with ps and/or top utilities) increases.
    > >
    > > I'm aware of the getrusage function from the GNU C library, but
    > > unfortunately the kernel we are using (linux 2.6) is not supporting the
    > > fields for memory usage in the rusage structure.
    > >
    > > Through some research I start to use the /proc file system and the statm
    > > file related to the pid of the running program.
    > > Now I have inserted throughout the program several calls to a function
    > > that prints the statistics from the statm file in order to isolate the
    > > increase of memory usage.
    > >
    > > Unfortunately the result points to a part of the program that does not
    > > have any hidden ambiguities related to memory usage, which is also
    > > confirmed by isolating it in a test program.
    > >
    > > What I would like to understand is if the system calls to update statm
    > > may be totally asynchronous with the current program flow (buffering,
    > > threading??) and if that is the case how can I get the usage of the
    > > memory reliably.

    >
    > Try your question on a Linux or POSIX forum. None of the things
    > you're asking about: getrusage, /proc, statm, threads, pids, ... are
    > part of the C language or library, but are defined by the particular
    > systems that provide them.


    If it smells like a leak, and looks like a leak, no matter what
    platform it's on, there's a good chance he's got a memory leak.
    So he should just grab the bull by the horns, and get a malloc
    debugger that can detect leaks. Of course, that will also be
    platform specific.

    And complaining that the kernel doesn't have certain features
    enabled is a bit lame - just recompile with them enabled. Booting
    your own kernel on any sane hardware is utterly trivial nowadays.

    Phil
    --
    "Religion is what keeps the poor from murdering the rich."
    -- Napoleon
     
    Phil Carmody, Sep 23, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. metfan
    Replies:
    2
    Views:
    4,853
    Robert Olofsson
    Oct 21, 2003
  2. hvt
    Replies:
    0
    Views:
    1,215
  3. hvt
    Replies:
    0
    Views:
    1,477
  4. Krist
    Replies:
    8
    Views:
    6,494
    Arne Vajhøj
    Feb 10, 2010
  5. MrsEntity
    Replies:
    20
    Views:
    482
Loading...

Share This Page