Home  >  Q&A  >  body text

jvm - 关于java -Xms参数的疑问

通过java -X看到java -Xms的解释

-Xms<size> set initial Java heap size

但我测试发现,
虽然我的机器内存只有1G,但通过 java -Xms3G -Xmx3G appname可以成功启动应用,那么这个分配机制是怎么的呢?

就是指定了-Xms 3G,但机器内存只有1G的情况下,是怎样分配内存的?

注:

# free -m|grep Swap
Swap:            0          0          0
伊谢尔伦伊谢尔伦2715 days ago471

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-04-18 10:23:06

    Because of the memory management mechanism of the operating system, each process will be allocated a virtual address space (corresponding to 32-bit systems, it is 4G virtual process address space). Some memory addresses in the virtual address space are mapped to actual physical memory. , when the memory required by the process is larger than the actual physical memory, some of its virtual memory addresses will be mapped to the disk. Due to the existence of this mechanism, the process seems to be able to use a larger memory than the actual physical memory. Memory space.

    For your question, JVM requires 3G of memory space, but the actual machine only has 1G. Therefore, the operating system will store the temporarily unused memory in the JVM process to the disk (ie Swap space). When the JVM needs to use another part of the memory When, the data in the disk is written to the memory through memory swap. Therefore, if it happens frequentlyMemory Swap, the program must be very slow.

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:23:06

    There is also virtual memory available.
    It won’t work if you reduce the virtual memory or disable it directly.

    reply
    0
  • Cancelreply