Welcome to Soft32 Linux Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

jvm memory usage on Linux

 
   Soft32 Home -> Linux2 Arch -> Embeded RSS
Next:  RTLinux vs Embedded Linux  
Author Message
tlo

External


Since: Jul 17, 2007
Posts: 3



(Msg. 1) Posted: Tue Jul 17, 2007 3:21 pm
Post subject: jvm memory usage on Linux
Archived from groups: comp>lang>java>programmer, others (more info?)

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
Back to top
Login to vote
Knute Johnson

External


Since: Jul 17, 2007
Posts: 1



(Msg. 2) Posted: Tue Jul 17, 2007 3:21 pm
Post subject: Re: jvm memory usage on Linux [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 Smile. So I wouldn't worry about it
until you try running it for a few days.

--

Knute Johnson
email s/nospam/knute/
Back to top
Login to vote
Lew

External


Since: Jul 17, 2007
Posts: 2



(Msg. 3) Posted: Tue Jul 17, 2007 3:21 pm
Post subject: Re: jvm memory usage on Linux [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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
Back to top
Login to vote
tlo

External


Since: Jul 17, 2007
Posts: 3



(Msg. 4) Posted: Tue Jul 17, 2007 6:19 pm
Post subject: Re: jvm memory usage on Linux [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Knute Johnson <nospam.TakeThisOut@rabbitbrush.frazmtn.com> 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 Smile. 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
Back to top
Login to vote
tlo

External


Since: Jul 17, 2007
Posts: 3



(Msg. 5) Posted: Tue Jul 17, 2007 6:32 pm
Post subject: Re: jvm memory usage on Linux [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Lew <lew RemoveThis @lewscanon.nospam> 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
Back to top
Login to vote
Lew

External


Since: Jul 17, 2007
Posts: 2



(Msg. 6) Posted: Tue Jul 17, 2007 6:32 pm
Post subject: Re: jvm memory usage on Linux [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

tlo wrote:
> Lew <lew.RemoveThis@lewscanon.nospam> 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
Back to top
Login to vote
SadRed

External


Since: Jul 18, 2007
Posts: 1



(Msg. 7) Posted: Wed Jul 18, 2007 4:33 pm
Post subject: Re: jvm memory usage on Linux [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jul 18, 5:21 am, tlo <thomas_bagn....RemoveThis@hotmail.com> 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
Back to top
Login to vote
Bernhard_Müller

External


Since: Jul 22, 2007
Posts: 3



(Msg. 8) Posted: Sun Jul 22, 2007 3:43 pm
Post subject: Re: jvm memory usage on Linux [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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
Back to top
Login to vote
wimpunk

External


Since: Jul 23, 2007
Posts: 4



(Msg. 9) Posted: Mon Jul 23, 2007 5:30 am
Post subject: Re: jvm memory usage on Linux [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.
Back to top
Login to vote
Display posts from previous:   
Related Topics:
MONTAVISTA LINUX CONFIGURATION - i m using Xilinx ml310 with virtex2p on it the kernel version is linux-2.4.20_ml31 i want to enable video 4 linux and..

memory usage and mozilla suicide - Recently i have noticed that mozilla 1.6 with linux 2.4.20 gets killed often, after a few minutes. I guess that mozill...

help on memory usage ('top' and 'free' commands) - An annoying killing of processes has been occurring on my workstation recently: Mozilla stays unused from minutes to..

Bug#343411: vegastrike memory usage - Without texture compression, vegastrike ends up storing copies of all the textures uncompressed. This takes a _lot_ of...

Memory Usage in a IBM Server running RHEL 3 - The following is the top output from a IBM eServer 325 running on a AMD Opteron Server. The Server is running Red Hat..

Bug#403576: last-exit: High memory usage - Package: last-exit Version: 3.0-3 Severity: normal After a few minutes using last-exit, the memory usage jumps from..
       Soft32 Home -> Linux2 Arch -> Embeded All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Categories:
 Windows
 Linux
 Mac
 PDA


[ Contact us | Terms of Service/Privacy Policy ]