简体   繁体   English

Java,JVM和OS以及交换

[英]Java,JVM and OS and swap

I wonder if i start a java virtual machine with: 我想知道我是否使用以下方式启动Java虚拟机:

-Xms2048m -Xmx2048m -XX:PermSize=256m -XX:MaxPermSize=256m 
-XX:+UseParallelGC -XX:ParallelGCThreads=4 -XX:+UseParallelOldGC 
-XX:LargePageSizeInBytes=4m -XX:-BindGCTaskThreadsToCPUs 

So I start the server with -Xms equal to -Xmx I the java OS process will "hold" the memory from the OS for good ? 因此,我用-Xms等于-Xmx来启动服务器。我的Java OS进程是否会“保留”来自OS的内存? So this JVM will have 2GB for it and if the OS has it then it will allow the process to start otherwise no. 因此,此JVM将具有2GB的空间,如果操作系统具有该空间,则它将允许该进程启动,否则没有。

Is there a possibility that after the JVM start with 2GB to use the swap memory of the os ? 在JVM以2GB开头之后,是否有可能使用os的交换内存?

(so if it starts initially without using the swap memory) (因此,如果它最初启动时没有使用交换内存)

This will use about 2400 MB of virtual memory on start up. 启动时将使用约2400 MB的虚拟内存。 It never gives back the virtual memory. 它永远不会放弃虚拟内存。 It can give back the main memory but rarely does. 它可以归还主内存,但很少。

Is there a possibility that after the JVM start with 2GB to use the swap memory of the os ? 在JVM以2GB开头之后,是否有可能使用os的交换内存?

Technical yes, but in practice this is a very bad idea. 技术上可以,但是实际上这是一个非常糟糕的主意。 The GC when it is performed assumes it has random access to all the memory. 执行GC时,假定它具有对所有内存的随机访问权限。 If you JVM starts to swap it can halt for long periods of time (many minutes) and even hang the machine. 如果JVM开始交换,它可能会暂停很长时间(几分钟),甚至挂起计算机。

Given you can buy 32 GB for about $200, it's usually simpler to buy enough memory for your needs. 鉴于您可以200美元左右的价格购买32 GB,通常可以根据需要购买足够的内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM