Java seems to ignore -Xms and -Xmx options

I'd like to run a very simple bot written in java on my VPS. I want to limit jvm memory to let's say 10MB (I doubt it would need any more).

I'm running the bot with the following command:

java -Xms5M -Xmx10M -server -jar IrcBot.jar "/home/jbot"

But top shows that actual memory reserved for java is 144m (or am I interpreting things wrong here?).

13614 jbot 17 0 144m 16m 6740 S 0.0 3.2 0:00.20 java

Any ideas what can be wrong here?

Java version "1.6.0_20" Java(TM) SE Runtime Environment (build 1.6.0_20-b02) Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode)

BTW. I'm running CentOS - if it matters.

EDIT: Thank you for your answers.

I can't really accept any of them, since it turns out the problem lies within the language i choose to write the program, not the JVM itself.

Answers


-Xmx specifies the max Java heap allocation (-Xms specifies the min heap allocation). The Java process has its own overhead (the actual JVM etc), plus the loaded classes and the perm gen space (set via -XX:MaxPermSize=128m) sits outside of that value too.

Think of your heap allocation as simply Java's "internal working space", not the process as a whole.

Try experimenting and you'll see what I mean:

java -Xms512m -Xmx1024m ...

Also, try using a tool such as JConsole or JVisualVM (both are shipped with the Sun / Oracle JDK) and you'll be able to see graphical representations of the actual heap usage (and the settings you used to constrain the size).

Finally, as @Peter Lawrey very rightly states, the resident memory is the crucial figure here - in your case the JVM is only using 16 MiB RSS (according to 'top'). The shared / virtual allocation won't cause any issues as long as the JVM's heap isn't pushed into swap (non-RAM). Again, as I've stated in some of the comments, there are other JVM's available - "Java" is quite capable of running on low resource or embedded platforms.


Xmx is the max heap size, but besides that there's a few other things that the JVM needs to keep in memory: the stack, the classes, etc. For a brief introduction see this post about the JVM memory structure.


The JVM maps in shared libraries which are about 150m. The amount of virtual memory used is unlikely to be important to use if you are trying to minimise physical main memory.

The number you want to look at is the resident memory which is amount of physical main memory actually used (which is 16 MB)


Need Your Help

Working with cascading dropdownlist and textbox in mvc 2

jquery asp.net-mvc asp.net-mvc-2 drop-down-menu

I am trying to hide and unhide the textbox using dropdownlist , so for instance when 0 is selected from drop down, no textbox should appear on the view , but if 1 is selected from dropdownlist , one

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.