Best way to get an overview of system memory usage? - Linux

This is a discussion on Best way to get an overview of system memory usage? - Linux ; Hello. I have an embedded Linux system (CRIS arch) with only 16 MB of physical RAM. As we have already less than 1 mb of free memory left I want to investigate which processes use most memory. I know this ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Best way to get an overview of system memory usage?

  1. Best way to get an overview of system memory usage?

    Hello.

    I have an embedded Linux system (CRIS arch) with only 16 MB of physical
    RAM. As we have already less than 1 mb of free memory left I want to
    investigate which processes use most memory.

    I know this is not that easy because virtual memory is very different
    from physical memory (paging, shared pages, copy-on-write, etc..).

    It seems that /proc/nnn/maps is a good source of information that, when
    combined with the complete process list(!), tells me how the memory is
    fragmented on the system.

    It also shows what shared libraries a process uses and I want to separate
    this information from the private data of a process, i.e. know which libs
    are loaded, how much memory they take and what amout of dynamic memory
    each process needs for itself.

    My problem is that I don't know how to find out if the private data
    (device 00:00) is currently shared (in terms of paging) with another
    process.

    For example, the following code creates two processes that each have a 1
    MB buffer, but they both use just slightly more than 1 MB, not 2 MB:

    char* dummy = malloc(1*1024*1024);
    dummy[0]=1; // force allocation
    int child=fork();

    Ok, but the following code shows the same /proc/nnn/maps table even if I
    know that they both have their own physical memory (summing 2 MB):

    char* dummy = malloc(1*1024*1024);
    dummy[0]=1; // force allocation
    int child=fork();
    dummy[1] = child; // modify again

    Of course the memory range in maps is virtual memory and so both
    processes show the same range. I've been told that a user space program
    can't detect the physical address of a virtual memory because the pages
    may move around.

    So, how can I detect how much *physical* RAM a process really uses?

    Udo


  2. Re: Best way to get an overview of system memory usage?

    On Mon, 13 Nov 2006 11:23:07 -0600, Udo Giacomozzi wrote:

    > For example, the following code creates two processes that each have a 1
    > MB buffer, but they both use just slightly more than 1 MB, not 2 MB:
    >
    > char* dummy = malloc(1*1024*1024);
    > dummy[0]=1; // force allocation
    > int child=fork();


    At this point we have one copy of the allocated memory marked Copy on
    write. I am surprised that this shows a physical mapping for the whole MB,
    I would have expected a single physical page.

    > Ok, but the following code shows the same /proc/nnn/maps table even if I
    > know that they both have their own physical memory (summing 2 MB):
    >
    > char* dummy = malloc(1*1024*1024);
    > dummy[0]=1; // force allocation
    > int child=fork();
    > dummy[1] = child; // modify again


    Identical to the first case except that ONE PAGE in dummy is duplicated
    and each process gets its own copy of that page. Note that this is the
    same virtual page as touched the first time, so the VM maps will be
    similar. The VM system generally works at page granularity, not with
    entire objects.

    > Of course the memory range in maps is virtual memory and so both
    > processes show the same range. I've been told that a user space program
    > can't detect the physical address of a virtual memory because the pages
    > may move around.
    >
    > So, how can I detect how much *physical* RAM a process really uses?


    Top and look at the RSS and shared values. Note that this will not work
    for the X server as it mmaps the entire video card memory, and accounting
    for SHM segments is tricky.

    Does cat /proc//statm give you any help?

    Regards, Dan.

+ Reply to Thread