Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Possible Duplicate:
Linux out of memory on VPS

In my Ubuntu 11.10 VPS, Before I run the jar file:

# free -m
             total       used       free     shared    buffers     cached
Mem:           256          5        250          0          0          0
-/+ buffers/cache:          5        250
Swap:            0          0          0

Run a jar file that limited to maximum of 32M memory:

java -Xms8m -Xmx32m -jar ./my.jar

Now the memory state as follows:

# free -m
             total       used       free     shared    buffers     cached
Mem:           256        155        100          0          0          0
-/+ buffers/cache:        155        100
Swap:            0          0          0

This jar occupied 150M memory.

And I can't run any other java command:

# java -version
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

# java -Xmx8m -version  
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

I want to know why the -Xmx parameter does not take effect?

How can I limit the jar file using the memory?

share|improve this question

marked as duplicate by Michael Hampton, John Gardeniers, Scott Pack, mdpc, jscott Dec 6 '12 at 0:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

It's not Java who used up all the memory, the system also consumes RAM to cache data (look at the cache output from free -m and top)

You're running Java (BLOATED software) on a 256MB RAM VPS without swap. Are you really really sure you want to go down this path?

share|improve this answer
    
I just run the java, then free-m, Not running other programs,and I got a crash log java.lang.OutOfMemoryError: requested 32756 bytes for ChunkPool::allocate. Out of swap space? –  Zenofo Dec 4 '12 at 11:16
    
Yes - like your free -m pointed out, the VPS has NO swap space at all, which is extremely silly. Call your VPS provider. –  pauska Dec 4 '12 at 11:17
    
Thanks @pauska ,You're right, But can I turn off java to use the swap? –  Zenofo Dec 4 '12 at 11:24

The -Xmx parameter defines the heap size, aka the memory you can allocate in the program. The java binary and the loaded jar file each needs additional space, naturally.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.