1

I have ubuntu server where i have 8 GB of RAM. When i try to give the heap size as 8GB, my web server(weblogic) does not start. But if i increase the swap size to Size to 11 GB, webserver got started.

So my question is how i can allocate 8GB heap size to my web server (when ihave 8 GB RAM out of which 1 to 2 GB is required for OS) after increaing the swap size ?

trincot
  • 317,000
  • 35
  • 244
  • 286
emilly
  • 10,060
  • 33
  • 97
  • 172
  • Out of curiosity, what was your swap size before you increased it? – Austin Jan 18 '16 at 15:30
  • If you have a process with 8 GB of heap and only 11 GB of swap space, you are living life on the edge (unless this web server is the only thing that will run on the system. The entire virtual address space of a process has to be backed to disk (even if there is memory available). – user3344003 Jan 18 '16 at 23:14

1 Answers1

5

Do. Not. Do this.

Get more memory.

Java and Swap Do. Not. Mix. Java and Swap are like "Crossing the Streams" Bad.

Part of the Java heap will be swapped out, then Java will GC, which will thrash the box terribly, and still part of the heap will be swapped out, and Java will GC again.

Rinse and repeat until you finally kill -9 Weblogic.

Get more memory, or do without. Swap is not an option.

Addenda:

You machine has "Virtual Memory" (VM). By adding swap, you extend that VM. When you have more VM than actual memory, then the machine will "swap out" inactive memory pages to the swap space, and then "swap in" pages that want to be active from swap space in to RAM. If you have a bunch of idle processes that rarely need time, this isn't super terrible.

But Java magnifies the problem. When you run out of physical RAM, some of that RAM is swapped out to disk. When some of that RAM is Java heap, then you have a big problem when the garbage collector kicks in. Because, in general, the GC touches every page of the heap. That means that all of the heaps pages need to be "active", and thus, "swapped in".

But if they don't fit, then you have a problem like the 8 puzzle. Where you're shifting memory in and out from disk. This is called thrashing.

A swapped JVM heap that is GC is the text book case of worst case thrashing.

The machine is letting you allocate the extra memory because it thinks you have more, since your Virtual Memory (physical RAM + swap) is greater.

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
  • Hartungh can you alaborate more on your statement `Part of the Java heap will be swapped out, then Java will GC, which will thrash the box terribly, and still part of the heap will be swapped out, and Java will GC again........`. How GC will play role here ? Also I am not getting how I was able to allocate 8GB heap to process when total ram is only 8 GB ? – emilly Jan 18 '16 at 15:48
  • Thanks a lot @will Hartung – emilly Jan 28 '16 at 13:21