3

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?

Koerr
  • 511
  • 1
  • 5
  • 11

2 Answers2

3

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.

Sven
  • 98,649
  • 14
  • 180
  • 226
1

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?

pauska
  • 19,620
  • 5
  • 57
  • 75
  • 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?` – Koerr Dec 04 '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 04 '12 at 11:17
  • Thanks @pauska ,You're right, But can I turn off java to use the swap? – Koerr Dec 04 '12 at 11:24