jvm memory usage on Linux

Discussion in 'Java' started by tlo, Jul 17, 2007.

  1. tlo

    tlo Guest

    Hi,

    I have a program where the main program runs a TimerTask every 10 sec. I have
    observed that the memory usage when running the commands " top" and "ps -aux"
    on the Linux box slowly increases. Over the time span of 3 hours Linux reports
    that the java process has grown approx 30kb. I have started the java process
    with the options -Xmx32M and -Xms32M (as it is running on a small hardware
    platfrom) and I can see that by using the Runtime.getRuntime() the jvm's memory
    usage looks fine:

    Total : 33357824
    Max : 33357824
    Free : 24832448
    Used : 8525376

    When looking at the top command following is displayed:
    PID USER STATUS RSS PPID %CPU %MEM COMMAND
    1544 root S 38180 1 0.0 32.2 java

    And the ps command:
    1544 root 38180 S java -Xmx32m -Xms32m main

    There are a couple of things that I don't understand:

    1. Why the Java process seems to increase in memory usage and it doesn't ever
    decrease again. The program needs to run 24/7 and I'm not sure if it will do
    this at the moment. Could this have something to do with Java program or could
    it be related to the JVM. I have tried it with Java 1.5 and Java 1.6 on Debain
    and another Linux distro with the same result.

    2. Why Linux reports the java process uses 38180kb, when I have limited the
    java heap to 32Mb.

    3. Why it increaes the memory when Java clealy have enough, is this maybe
    related to os resoures like files, sockets, etc?

    Any Help would be greatly appriciated.

    Thanks

    TLO
    tlo, Jul 17, 2007
    #1
    1. Advertising

  2. tlo wrote:
    > Hi,
    >
    > I have a program where the main program runs a TimerTask every 10 sec. I have
    > observed that the memory usage when running the commands " top" and "ps -aux"
    > on the Linux box slowly increases. Over the time span of 3 hours Linux reports
    > that the java process has grown approx 30kb. I have started the java process
    > with the options -Xmx32M and -Xms32M (as it is running on a small hardware
    > platfrom) and I can see that by using the Runtime.getRuntime() the jvm's memory
    > usage looks fine:
    >
    > Total : 33357824
    > Max : 33357824
    > Free : 24832448
    > Used : 8525376
    >
    > When looking at the top command following is displayed:
    > PID USER STATUS RSS PPID %CPU %MEM COMMAND
    > 1544 root S 38180 1 0.0 32.2 java
    >
    > And the ps command:
    > 1544 root 38180 S java -Xmx32m -Xms32m main
    >
    > There are a couple of things that I don't understand:
    >
    > 1. Why the Java process seems to increase in memory usage and it doesn't ever
    > decrease again. The program needs to run 24/7 and I'm not sure if it will do
    > this at the moment. Could this have something to do with Java program or could
    > it be related to the JVM. I have tried it with Java 1.5 and Java 1.6 on Debain
    > and another Linux distro with the same result.
    >
    > 2. Why Linux reports the java process uses 38180kb, when I have limited the
    > java heap to 32Mb.
    >
    > 3. Why it increaes the memory when Java clealy have enough, is this maybe
    > related to os resoures like files, sockets, etc?
    >
    > Any Help would be greatly appriciated.
    >
    > Thanks
    >
    > TLO
    >
    >
    >
    >
    >
    >
    >


    30 kilobytes isn't very much memory. The garbage collector will run
    when it needs to. You could set your JVM to use even less memory but
    enough so that your program will run and then you will most likely see
    the garbage collector run. Now of course this all assumes that you
    don't have some sort of memory leak :). So I wouldn't worry about it
    until you try running it for a few days.

    --

    Knute Johnson
    email s/nospam/knute/
    Knute Johnson, Jul 17, 2007
    #2
    1. Advertising

  3. tlo

    Lew Guest

    tlo wrote:
    >> 2. Why Linux reports the java process uses 38180kb, when I have
    >> limited the java heap to 32Mb.


    Because -Xmx only affects the heap, not the rest of the RAM used by the java
    process.

    --
    Lew
    Lew, Jul 18, 2007
    #3
  4. tlo

    tlo Guest

    Knute Johnson <> wrote:
    >tlo wrote:
    >> Hi,
    >>
    >> I have a program where the main program runs a TimerTask every 10 sec. I
    >>have
    >> observed that the memory usage when running the commands " top" and "ps
    >>-aux"
    >> on the Linux box slowly increases. Over the time span of 3 hours Linux
    >>reports
    >> that the java process has grown approx 30kb. I have started the java process
    >> with the options -Xmx32M and -Xms32M (as it is running on a small hardware
    >> platfrom) and I can see that by using the Runtime.getRuntime() the jvm's
    >>memory
    >> usage looks fine:
    >>
    >> Total : 33357824
    >> Max : 33357824
    >> Free : 24832448
    >> Used : 8525376
    >>
    >> When looking at the top command following is displayed:
    >> PID USER STATUS RSS PPID %CPU %MEM COMMAND
    >> 1544 root S 38180 1 0.0 32.2 java
    >>
    >> And the ps command:
    >> 1544 root 38180 S java -Xmx32m -Xms32m main
    >>
    >> There are a couple of things that I don't understand:
    >>
    >> 1. Why the Java process seems to increase in memory usage and it doesn't
    >>ever
    >> decrease again. The program needs to run 24/7 and I'm not sure if it will do
    >> this at the moment. Could this have something to do with Java program or
    >>could
    >> it be related to the JVM. I have tried it with Java 1.5 and Java 1.6 on
    >>Debain
    >> and another Linux distro with the same result.
    >>
    >> 2. Why Linux reports the java process uses 38180kb, when I have limited the
    >> java heap to 32Mb.
    >>
    >> 3. Why it increaes the memory when Java clealy have enough, is this maybe
    >> related to os resoures like files, sockets, etc?
    >>
    >> Any Help would be greatly appriciated.
    >>
    >> Thanks
    >>
    >> TLO
    >>
    >>
    >>
    >>
    >>
    >>
    >>

    >
    >30 kilobytes isn't very much memory. The garbage collector will run
    >when it needs to. You could set your JVM to use even less memory but
    >enough so that your program will run and then you will most likely see
    >the garbage collector run. Now of course this all assumes that you
    >don't have some sort of memory leak :). So I wouldn't worry about it
    >until you try running it for a few days.
    >
    >--
    >
    >Knute Johnson
    >email s/nospam/knute/



    Thanks for your advise. I didn't mention that I also have tried using a
    profiling tool and i could see that the garbage collector did run and that the
    memory within the jvm got garbage collected. However, I'm still not sure about
    the underlying operating system.

    I have also tried running a perl script on the /proc/<pid>/maps within linux,
    which lists the memory usage for the java process (found here
    http://tree.celinuxforum.org/CelfPubWiki/RuntimeMemoryMeasurement). When the
    memory usage increases, the following output from the perl script stays the
    same, which also could indicate that maybe meassuring the memory using top or
    ps isn't the bast way in linux. But I couldn't say that for sure.

    Backed by file:
    Executable r-x 15136
    Write/Exec (jump tables) rwx 9208
    RO data r-- 0
    Data rw- 0
    Unreadable --- 0
    Unknown 0
    Anonymous:
    Writable code (stack) rwx 159612
    Data (malloc, mmap) rw- 0
    RO data r-- 0
    Unreadable --- 772
    Unknown 8

    Do you have any hint to where I should consider looking for the memory leak?

    Thanks

    TLO
    tlo, Jul 18, 2007
    #4
  5. tlo

    tlo Guest

    Lew <> wrote:
    >tlo wrote:
    >>> 2. Why Linux reports the java process uses 38180kb, when I have
    >>> limited the java heap to 32Mb.

    >
    >Because -Xmx only affects the heap, not the rest of the RAM used by the java
    >process.
    >
    >--
    >Lew


    Hi Lew,

    Ok, that makes sense then. Also I assume that the jvm won't physically allocate
    the entire 32mb when it is initially started, for performance reasons, is that
    correct? Could this then have something to do with the constant increase, that
    the heap is less then 32 mb and when it grows new memory is allocated from the
    OS?

    Thanks

    TLO
    tlo, Jul 18, 2007
    #5
  6. tlo

    Lew Guest

    tlo wrote:
    > Lew <> wrote:
    >> tlo wrote:
    >>>> 2. Why Linux reports the java process uses 38180kb, when I have
    >>>> limited the java heap to 32Mb.

    >> Because -Xmx only affects the heap, not the rest of the RAM used by the java
    >> process.
    >>
    >> --
    >> Lew

    >
    > Hi Lew,
    >
    > Ok, that makes sense then. Also I assume that the jvm won't physically allocate
    > the entire 32mb when it is initially started, for performance reasons, is that correct?


    No.

    > Could this then have something to do with the constant increase, that
    > the heap is less then 32 mb and when it grows new memory is allocated from the
    > OS?


    You indicated that you're using java with the -Xms32M switch. That means that
    you start with 32MB of heap. It's supposed to allocate that entire amount
    right at the beginning.

    --
    Lew
    Lew, Jul 18, 2007
    #6
  7. tlo

    SadRed Guest

    On Jul 18, 5:21 am, tlo <> wrote:
    > Hi,
    >
    > I have a program where the main program runs a TimerTask every 10 sec. I have
    > observed that the memory usage when running the commands " top" and "ps -aux"
    > on the Linux box slowly increases. Over the time span of 3 hours Linux reports
    > that the java process has grown approx 30kb. I have started the java process
    > with the options -Xmx32M and -Xms32M (as it is running on a small hardware
    > platfrom) and I can see that by using the Runtime.getRuntime() the jvm's memory
    > usage looks fine:
    >
    > Total : 33357824
    > Max : 33357824
    > Free : 24832448
    > Used : 8525376
    >
    > When looking at the top command following is displayed:
    > PID USER STATUS RSS PPID %CPU %MEM COMMAND
    > 1544 root S 38180 1 0.0 32.2 java
    >
    > And the ps command:
    > 1544 root 38180 S java -Xmx32m -Xms32m main
    >
    > There are a couple of things that I don't understand:
    >
    > 1. Why the Java process seems to increase in memory usage and it doesn't ever
    > decrease again. The program needs to run 24/7 and I'm not sure if it will do
    > this at the moment. Could this have something to do with Java program or could
    > it be related to the JVM. I have tried it with Java 1.5 and Java 1.6 on Debain
    > and another Linux distro with the same result.
    >
    > 2. Why Linux reports the java process uses 38180kb, when I have limited the
    > java heap to 32Mb.
    >
    > 3. Why it increaes the memory when Java clealy have enough, is this maybe
    > related to os resoures like files, sockets, etc?
    >
    > Any Help would be greatly appriciated.
    >
    > Thanks
    >
    > TLO


    See http://mindprod.com/jgloss/sscce.html
    SadRed, Jul 19, 2007
    #7
  8. tlo wrote:
    > 1. Why the Java process seems to increase in memory usage and it doesn't ever
    > decrease again. The program needs to run 24/7 and I'm not sure if it will do
    > this at the moment. Could this have something to do with Java program or could
    > it be related to the JVM. I have tried it with Java 1.5 and Java 1.6 on Debain
    > and another Linux distro with the same result.


    seems unlikely the VM or the OS are to blame, i'd say;

    rather check lists, arrays, race conditions, native-interface calls and
    the like in your application. Probably some references never get
    released anymore, mem leaks are easier to avoid in J but not impossible.

    There should be some useful java profilers around, you can use them to
    check your heap.

    bm
    --
    Bernhard Mueller
    baernhard dot mueller at
    =?ISO-8859-1?Q?Bernhard_M=FCller?=, Jul 22, 2007
    #8
  9. tlo

    wimpunk Guest

    Bernhard Müller wrote:
    > tlo wrote:
    >> 1. Why the Java process seems to increase in memory usage and it
    >> doesn't ever decrease again. The program needs to run 24/7 and I'm not
    >> sure if it will do this at the moment. Could this have something to do
    >> with Java program or could it be related to the JVM. I have tried it
    >> with Java 1.5 and Java 1.6 on Debain and another Linux distro with the
    >> same result.

    >
    > seems unlikely the VM or the OS are to blame, i'd say;
    >
    > rather check lists, arrays, race conditions, native-interface calls and
    > the like in your application. Probably some references never get
    > released anymore, mem leaks are easier to avoid in J but not impossible.
    >
    > There should be some useful java profilers around, you can use them to
    > check your heap.
    >
    > bm


    There's a way to specify to your VM how much memory it may use. What
    you see is a quiet normal behaviour.
    wimpunk, Jul 23, 2007
    #9
    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,849
    Robert Olofsson
    Oct 21, 2003
  2. Soeren Gerlach
    Replies:
    0
    Views:
    443
    Soeren Gerlach
    Jul 15, 2004
  3. rony
    Replies:
    4
    Views:
    573
    Juha Laiho
    Jan 30, 2005
  4. hvt
    Replies:
    0
    Views:
    1,211
  5. tlo
    Replies:
    0
    Views:
    432
Loading...

Share This Page