views:

239

answers:

2

I run the same process on a 32bit machine as on a 64bit machine with the same memory VM settings (-Xms1024m -Xmx1024m) and similar VM version (1.6.0_05 vs 1.6.0_16). However the virtual space used by the 64bit machine (as shown in top under "VIRT") is almost three times as big as that in 32bit!

I know 64bit VMs will use a little more memory for the larger references, but how can it be three times as big? Am I reading VIRT in top incorrectly?

Full data shown below, showing top and then the result of jmap -heap, first for 64bit, then for 32bit. Note the VIRT for 64bit is 3319m for 32bit is 1220m.

* 64bit *


  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
22534 agent     20   0 3319m 163m  14m S  4.7  2.0   0:04.28 java               

$ jmap -heap 22534
Attaching to process ID 22534, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 10.0-b19

using thread-local object allocation.
Parallel GC with 4 thread(s)

Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 1073741824 (1024.0MB)
   NewSize          = 2686976 (2.5625MB)
   MaxNewSize       = -65536 (-0.0625MB)
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 21757952 (20.75MB)
   MaxPermSize      = 88080384 (84.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 268500992 (256.0625MB)
   used     = 247066968 (235.62142181396484MB)
   free     = 21434024 (20.441078186035156MB)
   92.01715277089181% used
From Space:
   capacity = 44695552 (42.625MB)
   used     = 0 (0.0MB)
   free     = 44695552 (42.625MB)
   0.0% used
To Space:
   capacity = 44695552 (42.625MB)
   used     = 0 (0.0MB)
   free     = 44695552 (42.625MB)
   0.0% used
PS Old Generation
   capacity = 715849728 (682.6875MB)
   used     = 0 (0.0MB)
   free     = 715849728 (682.6875MB)
   0.0% used
PS Perm Generation
   capacity = 21757952 (20.75MB)
   used     = 16153928 (15.405586242675781MB)
   free     = 5604024 (5.344413757324219MB)
   74.24378912132907% used

* 32bit *

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
30168 agent     20   0 1220m 175m  12m S  0.0  2.2   0:13.43 java               

$ jmap -heap 30168
Attaching to process ID 30168, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 14.2-b01

using thread-local object allocation.
Parallel GC with 8 thread(s)

Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 1073741824 (1024.0MB)
   NewSize          = 1048576 (1.0MB)
   MaxNewSize       = 4294901760 (4095.9375MB)
   OldSize          = 4194304 (4.0MB)
   NewRatio         = 8
   SurvivorRatio    = 8
   PermSize         = 16777216 (16.0MB)
   MaxPermSize      = 67108864 (64.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 89522176 (85.375MB)
   used     = 80626352 (76.89128112792969MB)
   free     = 8895824 (8.483718872070312MB)
   90.0629940005033% used
From Space:
   capacity = 14876672 (14.1875MB)
   used     = 14876216 (14.187065124511719MB)
   free     = 456 (4.3487548828125E-4MB)
   99.99693479832048% used
To Space:
   capacity = 14876672 (14.1875MB)
   used     = 0 (0.0MB)
   free     = 14876672 (14.1875MB)
   0.0% used
PS Old Generation
   capacity = 954466304 (910.25MB)
   used     = 10598496 (10.107513427734375MB)
   free     = 943867808 (900.1424865722656MB)
   1.1104107034039412% used
PS Perm Generation
   capacity = 16777216 (16.0MB)
   used     = 11366448 (10.839889526367188MB)
   free     = 5410768 (5.1601104736328125MB)
   67.74930953979492% used

+2  A: 

Think of virtual space as memory that program will ever be able to use. It is not the memory it actually uses. On 64-bit OS virtual memory is virtually endless, there is no 2Gb limitation as in 32-bit, so developers are free to choose any virtual size. There is nothing to worry about. The RES is actual physical RAM used.

Slava Nadvorny
A: 

Not all of the memory settings are the same - in particular, look at MaxNewSize, which is negative in the 64bit version. Also, in 64bit, virtual memory is effectively limitless for programs written for today's computers, and it's not something to be concerned about. The actual memory usage of the 64bit VM is lower than 32bit.

DeadMG