[Reprint] OutOfMemoryError series (6): Out of swap space?

OutOfMemoryError系列(6): Out of swap space?

https://blog.csdn.net/renfufei/article/details/78136638

 

This is the sixth article in this series, a list of related articles:

JVM startup parameter specifies the maximum memory limit. As  -Xmx well as other related startup parameters. If the total amount of memory used by the JVM exceed the available physical memory, the operating system will use virtual memory.

java.lang.outofmemoryerror swap

Error message  java.lang.OutOfMemoryError:? Out of swap space  show, swap space (swap space, virtual memory) deficiency, is due to physical memory and swap space is insufficient resulting in memory allocation failure.

Cause Analysis

If the native heap memory is exhausted, memory allocation, JVM will throw  java.lang.OutOfmemoryError:? Out of swap space  error message, this message tells the user requesting the operation failed to allocate memory.

Java process uses virtual memory before the error occurred. For  Java garbage collection  , this is difficult to cope with the scene. Even modern  GC algorithms  very advanced, but the virtual memory swap system caused delays, make  GC pause times  swelled to intolerable proportions.

Often the cause of the operating system level results in  java.lang.OutOfMemoryError:? Out of swap space  problems, such as:

  • Operating system swap space is too small.
  • A process on the machine swallowed up all the memory resources.

Of course, memory leaks may also be a local application (native leak) caused by, for example, a program / library continue to apply local memory, not to be released.

solution

There are several solutions to this problem.

The first, and easiest way to increase the size of virtual memory (swap space) for each operating system setup methods are not the same, such as Linux, you can use the following command set:

swapoff -a
dd if=/dev/zero of=swapfile bs=1024 count=655360 mkswap swapfile swapon swapfile

 

Which creates a 640MB size of the swapfile (swap file) and enable the file.

Because the garbage collector to clean up the entire memory space, so the virtual memory for Java GC is unbearable. When there is memory swapping, perform  garbage collection  of  pause time  will increase a hundred times, or even more, so it is best not to increase virtual memory.

If the program also allows environmental interference "bad neighbor effect", the JVM and other programs also compete computing resources and improve performance is to deploy a separate way to a dedicated server / virtual machine.

Most of the time, the only thing we can do is upgrade the server configuration, adding memory physical machine. Of course, the program can be optimized to reduce the amount of memory space, which means can be detected / code assignment by a large amount of memory heap Dump Analyzer.

Original link:  https://plumbr.eu/outofmemoryerror/out-of-swap-space

Translation Date: September 27, 2017

Translators:  anchor: http://blog.csdn.net/renfufei

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/12124668.html