LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 09-21-2007, 08:56 AM   #1
rolandofghent
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Rep: Reputation: 0
Java Linux Process memory footprint with and without -Xmx


I have questions about some strange behavior I am seeing with Java 5.0 on Linux.

First here is the environment:

Code:
[~]:> uname -a
	Linux xxxxxxxxxx 2.4.21-47.ELsmp #1 SMP Wed Jul 5 20:38:41 EDT 2006 i686 i686 i386 GNU/Linux

	[~]:> java -version
	java version "1.5.0_12"
	Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_12-b04)
	Java HotSpot(TM) Server VM (build 1.5.0_12-b04, mixed mode)
I wrote a very simple java program that just starts up and sleeps.

Wait.java:
Code:
	import java.lang.*;
	public class Wait{
	 public static void main(String args[]) throws Throwable{
	    Thread.sleep(100000);
	 }
	}
I run the program with no memory arguments:

Code:
	[~]:> java -classpath . Wait &
	[1] 30841
	[~]:> pmap 30841 | tail -1
	mapped: 1220332K    writeable/private: 1160336K    shared: 49468K
Note that pmap is showing me that it is using over 1 gig of memory. The java documentation says that if I don't specify a max heap size that the Max heap is 64 Megs. 1 gig of memory for a 64 Meg heap is a lot of overhead.

Top however, seems to be showing me that I am only using 10 megs.

Code:
	[~]:> top -bp 30841


	 08:44:00  up 187 days, 14:20, 12 users,  load average: 0.38, 0.69, 0.37
	1 processes: 1 sleeping, 0 running, 0 zombie, 0 stopped
	CPU states:  cpu    user    nice  system    irq  softirq  iowait    idle
		   total   13.6%    0.0%    3.9%   0.0%     0.0%    7.0%   75.3%
		   cpu00   16.9%    0.0%    3.7%   0.0%     0.0%    5.6%   73.5%
		   cpu01   11.2%    0.0%    2.8%   0.0%     0.0%    8.4%   77.5%
		   cpu02   11.2%    0.0%    2.8%   0.0%     0.0%    6.5%   79.4%
		   cpu03   15.0%    0.0%    6.6%   0.0%     0.0%    7.5%   70.7%
	Mem:  4101252k av, 3859028k used,  242224k free,       0k shrd,  145796k buff
			   2619760k actv,  545440k in_d,   65836k in_c
	Swap: 2048184k av,  594480k used, 1453704k free                 1726032k cached

	  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME CPU COMMAND
	30841 xxxxxxx   21   0 10336  10M  6408 S     0.0  0.2   0:00   0 java
Now I run the program with a 64 meg min and max heap.

Code:
	[~]:> java -classpath . -Xms64m -Xmx64m   Wait &
	[2] 30894
Then run pmap.

Code:
	[~]:> pmap 30894 | tail -1
	mapped: 256276K    writeable/private: 196280K    shared: 49468K
So it looks like it is using 196 megs. Which is fine because I know that there is overhead on top of the actual Heap size.

Then I run top on the process:

Code:
	[~]:> top -bp 30894

	 08:45:13  up 187 days, 14:21, 12 users,  load average: 0.26, 0.58, 0.36
	1 processes: 1 sleeping, 0 running, 0 zombie, 0 stopped
	CPU states:  cpu    user    nice  system    irq  softirq  iowait    idle
		   total    8.4%    0.0%    0.4%   0.2%     0.2%    7.4%   83.1%
		   cpu00    8.4%    0.0%    0.0%   0.9%     0.0%    6.5%   84.1%
		   cpu01    7.4%    0.0%    0.0%   0.0%     0.9%    7.4%   84.1%
		   cpu02    4.6%    0.0%    0.0%   0.0%     0.0%    8.4%   86.9%
		   cpu03   13.0%    0.0%    1.8%   0.0%     0.0%    7.4%   77.5%
	Mem:  4101252k av, 3904008k used,  197244k free,       0k shrd,  146224k buff
			   2657632k actv,  549712k in_d,   65836k in_c
	Swap: 2048184k av,  594480k used, 1453704k free                 1731604k cached

	  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME CPU COMMAND
	30894 xxxxxxx   21   0 10340  10M  6408 S     0.0  0.2   0:00   3 java
And it shows me that I am using 10 megs.

So what is going on here?

1) Why is top and pmap showing different values between the SIZE (top) and the writeable/private (pmap) ?
2) if the value in pmap is correct, why if I don't specify the max heap is it not taking the document default value?:

From the Java documentation:

Quote:
-Xmxn Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB.
 
Old 09-22-2007, 06:36 PM   #2
timothyb89
Member
 
Registered: Jul 2006
Location: Colorado, USA
Distribution: openSuSE 11.4
Posts: 118

Rep: Reputation: 15
two things:
#1: You could be wasting memory importing java.lang.*, and, even so, its imported by default anyway.

Assume, for clarity, that kB = kilobyte and kb = kilobit, and mB = megabyte and mb is megabyte.
#2: pmap is returning a value in kilobits, not kilobytes.
Its not *actually* 191.67 MBs- if you want MBs then its really 23.96 MB.
So from that, we should be able to deduce that top is giving us our usage value in kilobytes. Hopefully that should explain why the numbers were so different ;-)

(Note: 8 bits=1 byte, so kb/8 = kB. )

More info:
http://en.wikipedia.org/wiki/Byte
http://en.wikipedia.org/wiki/Bit
 
Old 09-26-2007, 12:17 PM   #3
rolandofghent
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by timothyb89 View Post
two things:
#2: pmap is returning a value in kilobits, not kilobytes.
Its not *actually* 191.67 MBs- if you want MBs then its really 23.96 MB.
So from that, we should be able to deduce that top is giving us our usage value in kilobytes. Hopefully that should explain why the numbers were so different ;-)

(Note: 8 bits=1 byte, so kb/8 = kB. )

More info:
http://en.wikipedia.org/wiki/Byte
http://en.wikipedia.org/wiki/Bit
Ok, so it is is kilobits instead of bytes.

But why is pmap showing 23.96 MB and Top is showing 10 MB?

Joe
 
Old 09-26-2007, 06:09 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,502

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Quote:
Originally Posted by timothyb89 View Post
two things:
#1: You could be wasting memory importing java.lang.*, and, even so, its imported by default anyway.
I'm afraid you are contradicting yourself here. If it's imported by default which is indeed true, how could importing it explicitly waste memory ?
Anyway, the import statement in java has no visible effect on the resulting application memory footprint. It is mostly a source code terseness convenience.
Quote:
Assume, for clarity, that kB = kilobyte and kb = kilobit, and mB = megabyte and mb is megabyte.
m is the ISO prefix for milli so mB would be millibyte and mb millibit (one thousandth of a bit ...) , shoud these units exist
One should use uppercase M to mean Mega.
Quote:
#2: pmap is returning a value in kilobits, not kilobytes.
I sorry but this is incorrect.
pmap is certainly returning values in bytes so these Ks are kiloBytes.
 
Old 09-27-2007, 07:55 AM   #5
rolandofghent
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jlliagre View Post
pmap is certainly returning values in bytes so these Ks are kiloBytes.
So can you answer my Question #1? Why is the value shown for Top different than what is shown for pmap?

Thanks,

Joe
 
Old 09-27-2007, 09:08 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,502

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
There can be many reasons, including you are comparing java heap size, physical, virtual and possibly multiply times mapped memory.

I can't tell much more as you only show pmap last output line.
 
  


Reply

Tags
heap, java, top


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kernel memory footprint and analysis. unreal128 Linux - General 2 09-09-2007 03:29 PM
Java process memory space 32/64 Woody Benot Red Hat 0 06-06-2007 04:07 AM
LXer: Reduce your Linux memory footprint LXer Syndicated Linux News 0 02-03-2007 01:33 AM
small memory footprint grcunningham Linux - Software 1 05-26-2004 08:38 AM
Help!!!: TCP code size/memory usage / footprint bichettelinux Linux - Networking 3 07-13-2003 05:31 PM


All times are GMT -5. The time now is 12:11 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration